Authored by chenchao

fix :recycle appraise process before deliver 2 buyer

... ... @@ -17,6 +17,7 @@ import javax.annotation.Resource;
import com.google.common.collect.Sets;
import com.yohobuy.ufo.model.enums.InboxBusinessTypeEnum;
import com.yohobuy.ufo.model.order.common.*;
import com.yohobuy.ufo.model.order.constants.DepositOutTypeEnum;
import com.yohobuy.ufo.model.order.vo.AddressInfo;
import com.yohoufo.common.utils.Functions;
import com.yohoufo.dal.order.*;
... ... @@ -25,6 +26,7 @@ import com.yohoufo.order.service.*;
import com.yohoufo.order.service.listener.BuyerOrderChangeEvent;
import com.yohoufo.order.service.seller.orderMeta.SellerAddressService;
import com.yohoufo.order.utils.NamedThreadFactory;
import com.yohoufo.order.utils.OrderAssist;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
... ... @@ -203,6 +205,12 @@ public class AppraiseService {
@Autowired
private AppraiseOrderGoodsMapper appraiseOrderGoodsMapper;
@Autowired
private BuyerOrderAssistant buyerOrderAssistant;
@Autowired
private IBuyerOrderMetaService buyerOrderMetaService;
/**
* 触发物流
*/
... ... @@ -261,21 +269,50 @@ public class AppraiseService {
LOGGER.warn("deliveryGoodsToBuyer getOrderInfo order not exist, orderCode is {}", orderCode);
throw new ServiceException(ServiceError.ORDER_NULL);
}
String depositCode = buyerOrderMetaService.getDepositCode(buyerOrder.getUid(), orderCode);
boolean isDeliverByDepositGoods = StringUtils.isNotBlank(depositCode);
boolean isDeliveredBySeller = OrderStatus.SELLER_SEND_OUT.getCode() == buyerOrder.getStatus().intValue();
boolean isWaitingRecycleAppraise = isDeliverByDepositGoods && isDeliveredBySeller;
//重新走鉴定流程的
if (isWaitingRecycleAppraise){
LOGGER.info("deliveryGoodsToBuyer isWaitingRecycleAppraise orderCode {}", orderCode);
setDepositStatusOfDeliverByDepositGoods(orderCode);
return;
}
// 寄存订单 或者闪购的库存
if(BuyerOrderUtils.isDeposit(buyerOrder)){
deliveryDepositGoodsToBuyer(appraiseExpressInfoBo, buyerOrder);
} else {
deliveryNonDepositGoodsToBuyer(appraiseExpressInfoBo, buyerOrder);
}
//设置寄存状态为已发货 寄存订单 或者闪购的库存 需要修改仓库记录的发货状态
setDepositStatus(orderCode);
}
private void setDepositStatusOfDeliverByDepositGoods(Long orderCode){
StorageDeposit deposit = storageDepositMapper.selectByOrderCode(orderCode);
if(null == deposit) {
LOGGER.warn("setDepositStatusOfDeliverByDepositGoods StorageDeposit is null, orderCode {}", orderCode);
return;
}
boolean isWaitingDeliverDepositGoods = deposit.getOutType() == DepositOutTypeEnum.OUTTYPE_DEPOSIT_CHANGE_TO_IN_STOCK.getCode();
if (!isWaitingDeliverDepositGoods){
LOGGER.warn("setDepositStatusOfDeliverByDepositGoods StorageDeposit isWaitingDeliverDepositGoods false, orderCode {}", orderCode);
return;
}
LOGGER.info("setDepositStatusOfDeliverByDepositGoods ready 2 update deposit status, orderCode {}", orderCode);
int num = storageDepositMapper.updateStorageStatusEx(deposit.getDepositCode(), StorageDepositStatusEnum.HAS_OUT.getCode(), StorageDepositStatusEnum.WAITING_OUT.getCode(), null);
if (num>0){
cleanCache(deposit);
}
}
private void setDepositStatus(Long orderCode) {
StorageDeposit deposit = storageDepositMapper.selectByOrderCode(orderCode);
if(null == deposit) {
return;
}
... ... @@ -285,16 +322,20 @@ public class AppraiseService {
int num = storageDepositMapper.updateStorageStatusEx(deposit.getDepositCode(), StorageDepositStatusEnum.HAS_OUT.getCode(), StorageDepositStatusEnum.WAITING_OUT.getCode(), null);
if(num > 0) {
LOGGER.info("method setDepositStatus end, orderCode is {}", orderCode);
//清缓存
ufoServiceCaller.call("ufo.deposit.clearOrderCache", deposit.getOwnerUid(), deposit.getDepositCode()); // 清理库存详情缓存
ufoServiceCaller.call("ufo.deposit.clearUserDeposit", deposit.getOwnerUid(), deposit.getDepositCode());
cleanCache(deposit);
//发mq,延迟7天设置状态为已完成
LOGGER.info("start send storageDeposit mq,topic is {}, depositCode is {}", TopicConstants.DEPOSIT_FINISH_DELIVERY, deposit.getDepositCode());
yhProducer.send(TopicConstants.DEPOSIT_FINISH_DELIVERY, deposit, null, 7 * 24 * 60);
}
}
private void cleanCache(StorageDeposit deposit){
ufoServiceCaller.call("ufo.deposit.clearOrderCache", deposit.getOwnerUid(), deposit.getDepositCode()); // 清理库存详情缓存
ufoServiceCaller.call("ufo.deposit.clearUserDeposit", deposit.getOwnerUid(), deposit.getDepositCode());
}
private void deliveryDepositGoodsToBuyer(AppraiseExpressInfoBo appraiseExpressInfoBo, BuyerOrder buyerOrder) {
if(buyerOrder.getStatus() == OrderStatus.DONE.getCode()){
expressInfoService.deliverGoods(buyerOrder.getUid(),
... ... @@ -618,7 +659,8 @@ public class AppraiseService {
}
}
if (appraiseOrder.getAttributes() == OrderAttributes.DEPOSITE.getCode()) { // 鉴定寄存的订单,需要同步修改寄存表的状态
if (appraiseOrder.getAttributes() == OrderAttributes.DEPOSITE.getCode()) {
// 鉴定寄存的订单,需要同步修改寄存表的状态
setDepositStatus(orderCode);
}
... ...