|
|
package com.yohoufo.order.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
|
|
|
import com.yoho.error.ServiceError;
|
|
|
import com.yoho.error.exception.ServiceException;
|
|
|
import com.yohobuy.ufo.model.ProductInfo;
|
|
|
import com.yohobuy.ufo.model.order.bo.AppraiseOrderGoodsBo;
|
|
|
import com.yohobuy.ufo.model.order.bo.OrderInfo;
|
|
|
import com.yohobuy.ufo.model.order.common.AppraiseOrderStatus;
|
|
|
import com.yohobuy.ufo.model.order.common.EnumExpressType;
|
|
|
import com.yohobuy.ufo.model.order.common.OrderAttributes;
|
|
|
import com.yohobuy.ufo.model.order.common.OrderCodeType;
|
|
|
import com.yohobuy.ufo.model.order.req.*;
|
|
|
import com.yohobuy.ufo.model.order.resp.*;
|
|
|
import com.yohobuy.ufo.model.order.vo.AddressInfo;
|
|
|
import com.yohoufo.common.exception.UfoServiceException;
|
|
|
import com.yohoufo.common.lock.RedisLock;
|
|
|
import com.yohoufo.common.lock.RedisLockFactory;
|
|
|
import com.yohoufo.common.utils.AddressUtil;
|
|
|
import com.yohoufo.common.utils.BigDecimalHelper;
|
|
|
import com.yohoufo.common.utils.DateUtil;
|
|
|
import com.yohoufo.dal.order.AppraiseOrderGoodsMapper;
|
|
|
import com.yohoufo.dal.order.AppraiseOrderMapper;
|
|
|
import com.yohoufo.dal.order.AppraiseOrderMetaMapper;
|
|
|
import com.yohoufo.dal.order.OrdersPayTransferMapper;
|
|
|
import com.yohoufo.dal.order.*;
|
|
|
import com.yohoufo.dal.order.model.*;
|
|
|
import com.yohoufo.order.common.ClientType;
|
|
|
import com.yohoufo.order.constants.MetaKey;
|
|
|
import com.yohoufo.order.convert.AppraiseOrderGoodsConvertor;
|
|
|
import com.yohoufo.order.model.dto.AppraiseOrderContext;
|
|
|
import com.yohoufo.order.model.response.AppraiseAddressResp;
|
|
|
import com.yohoufo.order.service.IExpressInfoService;
|
|
|
import com.yohoufo.order.service.IGoodsService;
|
|
|
import com.yohoufo.order.service.handler.GoodsServiceRefundHandler;
|
|
|
import com.yohoufo.order.service.handler.transfer.TransferChancelSelector;
|
|
|
import com.yohoufo.order.service.proxy.InBoxFacade;
|
|
|
import com.yohoufo.order.service.proxy.ProductProxyService;
|
|
|
import com.yohoufo.order.service.proxy.UserProxyService;
|
...
|
...
|
@@ -43,13 +45,13 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import static com.yohoufo.order.utils.ServiceExceptions.throwServiceExceptionIf;
|
|
|
|
|
|
@Service
|
|
|
public class AppraiseOrderService extends AbsGoodsServiceOrderService implements IGoodsService {
|
|
|
private final Logger logger = LoggerUtils.getBuyerOrderLogger();
|
...
|
...
|
@@ -88,7 +90,7 @@ public class AppraiseOrderService extends AbsGoodsServiceOrderService implements |
|
|
OrderCodeGenerator orderCodeGenerator;
|
|
|
|
|
|
@Autowired
|
|
|
private TransferChancelSelector transferChancelSelector;
|
|
|
private ExpressRecordMapper expressRecordMapper;
|
|
|
|
|
|
@Autowired
|
|
|
TransferService transferService;
|
...
|
...
|
@@ -96,6 +98,15 @@ public class AppraiseOrderService extends AbsGoodsServiceOrderService implements |
|
|
@Autowired
|
|
|
OrdersPayTransferMapper ordersPayTransferMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private AppraiseAddressService appraiseAddressService;
|
|
|
|
|
|
@Autowired
|
|
|
private AppraiseOrderAddressService appraiseOrderAddressService;
|
|
|
|
|
|
@Autowired
|
|
|
private RedisLockFactory redisLockFactory;
|
|
|
|
|
|
|
|
|
public AppraiseOrderComputeResp compute(AppraiseOrderComputeReq req){
|
|
|
logger.info("in AppraiseOrderService.compute req {}", req);
|
...
|
...
|
@@ -452,4 +463,66 @@ public class AppraiseOrderService extends AbsGoodsServiceOrderService implements |
|
|
inBoxFacade.paidAppraiseOrderNotice(orderInfo.getUid(), orderInfo.getOrderCode(), targetStatus);
|
|
|
}
|
|
|
|
|
|
|
|
|
public void updateWaybillCode(AppraiseOrderWaybillUpdateReq req){
|
|
|
Long orderCode = req.getOrderCode();
|
|
|
String waybillCode = req.getSellerWaybillCode();
|
|
|
if (Objects.isNull(orderCode) || orderCode<=0L || StringUtils.isBlank(waybillCode)){
|
|
|
logger.warn("appraise order updateWaybillCode params of req illegal, req {}", req);
|
|
|
throw new UfoServiceException(400, "请求参数不合法");
|
|
|
}
|
|
|
|
|
|
//
|
|
|
AppraiseOrder pao = appraiseOrderMapper.selectByOrderCode(orderCode);
|
|
|
if (Objects.isNull(pao)){
|
|
|
logger.warn("appraise order updateWaybillCode order not exist, req {}", req);
|
|
|
throw new UfoServiceException(400, "订单不存在");
|
|
|
}
|
|
|
Integer status = pao.getStatus();
|
|
|
if (status.equals(AppraiseOrderStatus.SELLER_SEND_OUT.getCode()) ){
|
|
|
RedisKeyBuilder redisLockKey = RedisKeyBuilder.newInstance()
|
|
|
.appendFixed("ufo:order:lock:appraiseOrder:updateWaybillCode:")
|
|
|
.appendVar(orderCode);
|
|
|
RedisLock lock = redisLockFactory.newLock(redisLockKey, 5, TimeUnit.SECONDS);
|
|
|
throwServiceExceptionIf(!lock.tryLock(), "正在修改快递记录中");
|
|
|
try{
|
|
|
doUpdateWaybill(req, pao);
|
|
|
}finally {
|
|
|
lock.unlock();
|
|
|
}
|
|
|
}else{
|
|
|
logger.warn("updateWaybillCode status of order not match ,req {} status {}", req, status);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
private void doUpdateWaybill(AppraiseOrderWaybillUpdateReq req, AppraiseOrder pao){
|
|
|
Long orderCode = req.getOrderCode();
|
|
|
String changedWaybillCode = req.getSellerWaybillCode().trim();
|
|
|
final EnumExpressType teet = EnumExpressType.EXPRESS_TYPE_1;
|
|
|
ExpressRecord record = expressRecordMapper.selectByOrderCodeAndExpressType(orderCode, teet.getCode());
|
|
|
if (Objects.isNull(record)){
|
|
|
logger.warn("appraise order updateWaybillCode ExpressRecord not exist, req {}", req);
|
|
|
throw new UfoServiceException(400, "快递记录不存在");
|
|
|
}
|
|
|
if (record.getWaybillCode().trim().equalsIgnoreCase(changedWaybillCode)){
|
|
|
logger.warn("appraise order updateWaybillCode waybillCode not change, req {}", req);
|
|
|
throw new UfoServiceException(400, "快递单号没有变化");
|
|
|
}
|
|
|
|
|
|
int rows = expressRecordMapper.updateWaybillCode(orderCode, pao.getUid(), teet.getCode(), changedWaybillCode);
|
|
|
if (rows>0){
|
|
|
|
|
|
String depotMobile = appraiseAddressService.optInitAddressByDepotNum(record.getDepotNum())
|
|
|
.map(AppraiseAddressResp::getMobile)
|
|
|
.orElse(null);
|
|
|
AddressInfo noHiddenAddress = appraiseOrderAddressService.getNoHiddenAddressInfo(orderCode);
|
|
|
String sellerMobile = Optional.ofNullable(noHiddenAddress)
|
|
|
.map(AddressInfo::getMobile)
|
|
|
.orElse(null);
|
|
|
|
|
|
List<String> mobiles = Lists.newArrayList(sellerMobile, depotMobile);
|
|
|
expressInfoService.triggerExpressMQ(pao.getUid(), record.getLogisticsType(), orderCode, changedWaybillCode, mobiles);
|
|
|
}
|
|
|
}
|
|
|
} |
...
|
...
|
|