|
|
package com.yohoufo.order.service.impl;
|
|
|
|
|
|
import com.yohobuy.ufo.model.order.common.AppraiseOrderStatus;
|
|
|
import com.yohobuy.ufo.model.order.common.OrderAttributes;
|
|
|
import com.yohobuy.ufo.model.order.common.OrderCodeType;
|
|
|
import com.yohobuy.ufo.model.order.req.DeliverToDepotReq;
|
|
|
import com.yohoufo.common.utils.DateUtil;
|
|
|
import com.yohoufo.dal.order.AppraiseOrderGoodsMapper;
|
|
|
import com.yohoufo.dal.order.AppraiseOrderMapper;
|
|
|
import com.yohoufo.dal.order.OrdersPayTransferMapper;
|
|
|
import com.yohoufo.dal.order.model.AppraiseOrder;
|
|
|
import com.yohoufo.dal.order.model.AppraiseOrderGoods;
|
|
|
import com.yohoufo.dal.order.model.SellerWalletDetail;
|
|
|
import com.yohoufo.order.common.TransferCase;
|
|
|
import com.yohoufo.order.constants.AlarmConfig;
|
|
|
import com.yohoufo.order.model.request.TranseferCellNode;
|
|
|
import com.yohoufo.order.model.request.TransferMoneyRequest;
|
|
|
import com.yohoufo.order.service.IGoodsService;
|
|
|
import com.yohoufo.order.service.handler.transfer.AlipayTransferChancelSelector;
|
|
|
import com.yohoufo.order.service.proxy.OrderStatusFlowService;
|
|
|
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
|
|
|
import com.yohoufo.order.utils.LoggerUtils;
|
|
|
import com.yohoufo.order.utils.NamedThreadFactory;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.List;
|
|
|
import java.util.concurrent.ArrayBlockingQueue;
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
import java.util.concurrent.ThreadPoolExecutor;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
public abstract class AbsGoodsServiceOrderService implements IGoodsService {
|
|
|
private final Logger logger = LoggerUtils.getSellerOrderLogger();
|
|
|
@Autowired
|
...
|
...
|
@@ -22,7 +42,85 @@ public abstract class AbsGoodsServiceOrderService implements IGoodsService { |
|
|
private OrderStatusFlowService orderStatusFlowService;
|
|
|
|
|
|
@Autowired
|
|
|
private AppraiseOrderGoodsMapper appraiseOrderGoodsMapper;
|
|
|
OrderCodeGenerator orderCodeGenerator;
|
|
|
|
|
|
@Autowired
|
|
|
private AlipayTransferChancelSelector alipayTransferChancelSelector;
|
|
|
|
|
|
@Autowired
|
|
|
TransferService transferService;
|
|
|
|
|
|
@Autowired
|
|
|
OrdersPayTransferMapper ordersPayTransferMapper;
|
|
|
|
|
|
@Autowired
|
|
|
AppraiseOrderGoodsMapper appraiseOrderGoodsMapper;
|
|
|
|
|
|
private ExecutorService executorService = new ThreadPoolExecutor(5, 10, 60, TimeUnit.SECONDS,
|
|
|
new ArrayBlockingQueue<>(1000),
|
|
|
NamedThreadFactory.newThreadFactory("appraise"));
|
|
|
|
|
|
/**
|
|
|
* 申请寄存返利
|
|
|
* @param orderCodeList
|
|
|
*/
|
|
|
public void depositRebate(List<Long> orderCodeList){
|
|
|
|
|
|
logger.info("depositRebate param is {}", orderCodeList);
|
|
|
|
|
|
if (CollectionUtils.isEmpty(orderCodeList)){
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
// 过滤1: 通过code过滤出来 goods_service的订单号
|
|
|
List<Long> goodServiceOrderLists = orderCodeList.stream()
|
|
|
.filter(orderCode -> orderCodeGenerator.expId(orderCode).getType() == OrderCodeType.GOODS_SERVICE.getType())
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
// 过滤2: 通过查表 appaise_order & attribute
|
|
|
List<AppraiseOrder> appraiseOrderList = appraiseOrderMapper.selectByOrderCodeList(goodServiceOrderLists);
|
|
|
|
|
|
if (CollectionUtils.isEmpty(appraiseOrderList)){
|
|
|
return;
|
|
|
}
|
|
|
List<AppraiseOrder> depositCodeList = appraiseOrderList.stream()
|
|
|
.filter(appraiseOrder -> appraiseOrder.getAttributes() == OrderAttributes.DEPOSITE.getCode())
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
executorService.execute(() -> {
|
|
|
// 只返4单
|
|
|
int DEFAULT_REBATE_CNT = alipayTransferChancelSelector.getDepositRebateOrderCnt();
|
|
|
BigDecimal rebate = new BigDecimal(alipayTransferChancelSelector.getDepositRebateAmount());
|
|
|
|
|
|
depositCodeList.stream().forEach(depositCode -> {
|
|
|
|
|
|
int rebateCnt = ordersPayTransferMapper.selectByUidAndTransferType(depositCode.getUid(), TransferCase.DEPOSIT_REBATE_TO_USER.getCode());
|
|
|
logger.info("rebate transfer cnt {}, uid {}", rebateCnt, depositCode.getUid());
|
|
|
if (rebateCnt < DEFAULT_REBATE_CNT){
|
|
|
TransferCase transferCase = TransferCase.DEPOSIT_REBATE_TO_USER;
|
|
|
TranseferCellNode transeferCellNode = new TranseferCellNode();
|
|
|
transeferCellNode.setUid(depositCode.getUid());
|
|
|
transeferCellNode.setAmount(rebate.setScale(2,BigDecimal.ROUND_HALF_DOWN));
|
|
|
|
|
|
TransferMoneyRequest tmReq = TransferMoneyRequest.builder()
|
|
|
.sellerUid(depositCode.getUid())
|
|
|
.buyerOrderCode(depositCode.getOrderCode())
|
|
|
.type(transferCase.getCode())
|
|
|
.transferCase(transferCase)
|
|
|
.transeferCellNode(transeferCellNode)
|
|
|
.swdType(SellerWalletDetail.Type.DEPOSIT_REBATE)
|
|
|
.alarmConfig(AlarmConfig.DEPOSIT_REBATE_FAIL) // 打款失败的时候警告
|
|
|
.build();
|
|
|
|
|
|
transferService.transfer(tmReq);
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@Override
|
|
|
public int deliver2Depot(DeliverToDepotReq req){
|
...
|
...
|
|