Authored by chenchao

add waybill update

... ... @@ -42,4 +42,9 @@ public interface ExpressRecordMapper {
* @return
*/
int updateDeptNoByOrder(@Param("orderCodeList") List<Long> orderCodeList, @Param("expressType") Integer expressType, @Param("depotNum") Integer depotNum);
int updateWaybillCode(@Param("orderCode") Long orderCode,
@Param("uid") Integer uid,
@Param("expressType") Integer expressType,
@Param("waybillCode") String waybillCode);
}
\ No newline at end of file
... ...
... ... @@ -60,4 +60,9 @@
</foreach>
and express_type = #{expressType, jdbcType=INTEGER}
</update>
<update id="updateWaybillCode">
update express_record set waybill_code=#{waybillCode}
where order_code=#{orderCode} and uid=#{uid} and express_type=#{expressType}
</update>
</mapper>
\ No newline at end of file
... ...
package com.yohoufo.order.controller;
import com.yoho.core.rest.annotation.ServiceDesc;
import com.yohobuy.ufo.model.order.req.AppraiseOrderWaybillUpdateReq;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.order.service.impl.AppraiseOrderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/erp/appraiseOrder")
@ServiceDesc("appraiseOrder")
public class ErpAppraiseOrderController {
private final Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private AppraiseOrderService appraiseOrderService;
@RequestMapping("/updateWaybillCode")
public ApiResponse updateWaybillCode(@RequestBody AppraiseOrderWaybillUpdateReq req){
logger.info("in updateWaybillCode Of AppraiseOrder req {}", req);
appraiseOrderService.updateWaybillCode(req);
return new ApiResponse.ApiResponseBuilder().code(200).message("修改快递单号成功").build();
}
}
... ...
package com.yohoufo.order.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.yohobuy.ufo.model.order.vo.AddressInfo;
import com.yohoufo.dal.order.AppraiseOrderMetaMapper;
import com.yohoufo.dal.order.model.AppraiseOrderMeta;
import com.yohoufo.order.constants.MetaKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;
@Service
public class AppraiseOrderAddressService {
private final Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private AppraiseOrderMetaMapper appraiseOrderMetaMapper;
public AddressInfo getNoHiddenAddressInfo(Long orderCode){
final String key = MetaKey.RECALL_ADDRESS;
List<AppraiseOrderMeta> aomAddressList = appraiseOrderMetaMapper.selectByOrderCodeMetaKeys(orderCode, Lists.newArrayList(key));
return Optional.ofNullable(aomAddressList)
.map(appraiseOrderMetas -> appraiseOrderMetas.get(0))
.map(appraiseOrderMeta -> JSONObject.parseObject(appraiseOrderMeta.getMetaValue(),AddressInfo.class))
.orElse(null);
}
}
... ...
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);
}
}
}
... ...
... ... @@ -593,7 +593,11 @@ public class ExpressInfoServiceImpl implements IExpressInfoService {
}
@Override
public void triggerExpressMQ(Integer uid, Integer expressCompanyId, Long orderCode, String wayBillCode, List<String> mobiles) {
public void triggerExpressMQ(Integer uid,
Integer expressCompanyId,
Long orderCode,
String wayBillCode,
List<String> mobiles) {
// 发送mq获取物流信息
sendExpressMQ(uid, expressCompanyId, orderCode, wayBillCode, mobiles);
LOGGER.info("triggerExpressMQ end ! send express to erp ");
... ...