Authored by tanling

申请寄存-初版

... ... @@ -40,7 +40,7 @@
where buyer_order_code = #{buyerOrderCode,jdbcType=INTEGER}
</select>
<select id="selectByUidAndTransferType" resultMap="BaseResultMap" parameterType="java.lang.Long" >
<select id="selectByUidAndTransferType" resultType="java.lang.Integer" parameterType="java.lang.Integer" >
select
count(1)
from orders_pay_transfer
... ...
package com.yohoufo.order.common;
public enum TradeType {
deposit_rebate(4, "返利"),
compensateIncome(3, "补偿款"),
goods_income(2, "货款"),
guarantee_cash(1, "保证金");
int code;
... ...
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){
... ...
... ... @@ -107,70 +107,6 @@ public class AppraiseOrderService extends AbsGoodsServiceOrderService implements
@Autowired
OrdersPayTransferMapper ordersPayTransferMapper;
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();
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(new BigDecimal(alipayTransferChancelSelector.getDepositRebateAmount())); // 一单返40元
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);
}
});
// });
}
public AppraiseOrderComputeResp compute(AppraiseOrderComputeReq req){
logger.info("in AppraiseOrderService.compute req {}", req);
... ...
... ... @@ -21,6 +21,7 @@ import com.yohoufo.dal.order.*;
import com.yohoufo.dal.order.model.*;
import com.yohoufo.order.common.BillTradeStatus;
import com.yohoufo.order.common.HbfqEnum;
import com.yohoufo.order.common.TradeType;
import com.yohoufo.order.common.TransferCase;
import com.yohoufo.order.constants.RefundContant;
import com.yohoufo.order.model.PayQueryBo;
... ... @@ -1409,7 +1410,11 @@ public class PaymentServiceImpl implements IPaymentService {
record.setUserType(targetUserType.getCode());
record.setPayType(1);
// 如果[全部货款->卖家],否则[补偿款->卖家或买家] 2:货款;3:补偿款
record.setTradeType(transferCase == TransferCase.ALL_GOODS_MONEY_TO_SELLER ? 2 : 3);
if (transferCase == TransferCase.DEPOSIT_REBATE_TO_USER){
record.setTradeType(TradeType.deposit_rebate.getCode()); // 返利
}else{
record.setTradeType(transferCase == TransferCase.ALL_GOODS_MONEY_TO_SELLER ? TradeType.goods_income.getCode() : TradeType.compensateIncome.getCode());
}
record.setIncomeOutcome(1);
record.setTradeStatus(BillTradeStatus.NEW.getCode());
record.setCreateTime(now);
... ...