Showing
5 changed files
with
108 additions
and
67 deletions
@@ -40,7 +40,7 @@ | @@ -40,7 +40,7 @@ | ||
40 | where buyer_order_code = #{buyerOrderCode,jdbcType=INTEGER} | 40 | where buyer_order_code = #{buyerOrderCode,jdbcType=INTEGER} |
41 | </select> | 41 | </select> |
42 | 42 | ||
43 | - <select id="selectByUidAndTransferType" resultMap="BaseResultMap" parameterType="java.lang.Long" > | 43 | + <select id="selectByUidAndTransferType" resultType="java.lang.Integer" parameterType="java.lang.Integer" > |
44 | select | 44 | select |
45 | count(1) | 45 | count(1) |
46 | from orders_pay_transfer | 46 | from orders_pay_transfer |
1 | package com.yohoufo.order.common; | 1 | package com.yohoufo.order.common; |
2 | 2 | ||
3 | public enum TradeType { | 3 | public enum TradeType { |
4 | + deposit_rebate(4, "返利"), | ||
4 | compensateIncome(3, "补偿款"), | 5 | compensateIncome(3, "补偿款"), |
5 | goods_income(2, "货款"), | 6 | goods_income(2, "货款"), |
6 | guarantee_cash(1, "保证金"); | 7 | guarantee_cash(1, "保证金"); |
7 | 8 | ||
9 | + | ||
8 | int code; | 10 | int code; |
9 | 11 | ||
10 | 12 |
1 | package com.yohoufo.order.service.impl; | 1 | package com.yohoufo.order.service.impl; |
2 | 2 | ||
3 | import com.yohobuy.ufo.model.order.common.AppraiseOrderStatus; | 3 | import com.yohobuy.ufo.model.order.common.AppraiseOrderStatus; |
4 | +import com.yohobuy.ufo.model.order.common.OrderAttributes; | ||
5 | +import com.yohobuy.ufo.model.order.common.OrderCodeType; | ||
4 | import com.yohobuy.ufo.model.order.req.DeliverToDepotReq; | 6 | import com.yohobuy.ufo.model.order.req.DeliverToDepotReq; |
5 | import com.yohoufo.common.utils.DateUtil; | 7 | import com.yohoufo.common.utils.DateUtil; |
6 | import com.yohoufo.dal.order.AppraiseOrderGoodsMapper; | 8 | import com.yohoufo.dal.order.AppraiseOrderGoodsMapper; |
7 | import com.yohoufo.dal.order.AppraiseOrderMapper; | 9 | import com.yohoufo.dal.order.AppraiseOrderMapper; |
10 | +import com.yohoufo.dal.order.OrdersPayTransferMapper; | ||
8 | import com.yohoufo.dal.order.model.AppraiseOrder; | 11 | import com.yohoufo.dal.order.model.AppraiseOrder; |
9 | import com.yohoufo.dal.order.model.AppraiseOrderGoods; | 12 | import com.yohoufo.dal.order.model.AppraiseOrderGoods; |
13 | +import com.yohoufo.dal.order.model.SellerWalletDetail; | ||
14 | +import com.yohoufo.order.common.TransferCase; | ||
15 | +import com.yohoufo.order.constants.AlarmConfig; | ||
16 | +import com.yohoufo.order.model.request.TranseferCellNode; | ||
17 | +import com.yohoufo.order.model.request.TransferMoneyRequest; | ||
10 | import com.yohoufo.order.service.IGoodsService; | 18 | import com.yohoufo.order.service.IGoodsService; |
19 | +import com.yohoufo.order.service.handler.transfer.AlipayTransferChancelSelector; | ||
11 | import com.yohoufo.order.service.proxy.OrderStatusFlowService; | 20 | import com.yohoufo.order.service.proxy.OrderStatusFlowService; |
21 | +import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator; | ||
12 | import com.yohoufo.order.utils.LoggerUtils; | 22 | import com.yohoufo.order.utils.LoggerUtils; |
23 | +import com.yohoufo.order.utils.NamedThreadFactory; | ||
24 | +import org.apache.commons.collections.CollectionUtils; | ||
13 | import org.slf4j.Logger; | 25 | import org.slf4j.Logger; |
14 | import org.springframework.beans.factory.annotation.Autowired; | 26 | import org.springframework.beans.factory.annotation.Autowired; |
15 | 27 | ||
28 | +import java.math.BigDecimal; | ||
29 | +import java.util.List; | ||
30 | +import java.util.concurrent.ArrayBlockingQueue; | ||
31 | +import java.util.concurrent.ExecutorService; | ||
32 | +import java.util.concurrent.ThreadPoolExecutor; | ||
33 | +import java.util.concurrent.TimeUnit; | ||
34 | +import java.util.stream.Collectors; | ||
35 | + | ||
16 | public abstract class AbsGoodsServiceOrderService implements IGoodsService { | 36 | public abstract class AbsGoodsServiceOrderService implements IGoodsService { |
17 | private final Logger logger = LoggerUtils.getSellerOrderLogger(); | 37 | private final Logger logger = LoggerUtils.getSellerOrderLogger(); |
18 | @Autowired | 38 | @Autowired |
@@ -22,7 +42,85 @@ public abstract class AbsGoodsServiceOrderService implements IGoodsService { | @@ -22,7 +42,85 @@ public abstract class AbsGoodsServiceOrderService implements IGoodsService { | ||
22 | private OrderStatusFlowService orderStatusFlowService; | 42 | private OrderStatusFlowService orderStatusFlowService; |
23 | 43 | ||
24 | @Autowired | 44 | @Autowired |
25 | - private AppraiseOrderGoodsMapper appraiseOrderGoodsMapper; | 45 | + OrderCodeGenerator orderCodeGenerator; |
46 | + | ||
47 | + @Autowired | ||
48 | + private AlipayTransferChancelSelector alipayTransferChancelSelector; | ||
49 | + | ||
50 | + @Autowired | ||
51 | + TransferService transferService; | ||
52 | + | ||
53 | + @Autowired | ||
54 | + OrdersPayTransferMapper ordersPayTransferMapper; | ||
55 | + | ||
56 | + @Autowired | ||
57 | + AppraiseOrderGoodsMapper appraiseOrderGoodsMapper; | ||
58 | + | ||
59 | + private ExecutorService executorService = new ThreadPoolExecutor(5, 10, 60, TimeUnit.SECONDS, | ||
60 | + new ArrayBlockingQueue<>(1000), | ||
61 | + NamedThreadFactory.newThreadFactory("appraise")); | ||
62 | + | ||
63 | + /** | ||
64 | + * 申请寄存返利 | ||
65 | + * @param orderCodeList | ||
66 | + */ | ||
67 | + public void depositRebate(List<Long> orderCodeList){ | ||
68 | + | ||
69 | + logger.info("depositRebate param is {}", orderCodeList); | ||
70 | + | ||
71 | + if (CollectionUtils.isEmpty(orderCodeList)){ | ||
72 | + return; | ||
73 | + } | ||
74 | + | ||
75 | + // 过滤1: 通过code过滤出来 goods_service的订单号 | ||
76 | + List<Long> goodServiceOrderLists = orderCodeList.stream() | ||
77 | + .filter(orderCode -> orderCodeGenerator.expId(orderCode).getType() == OrderCodeType.GOODS_SERVICE.getType()) | ||
78 | + .collect(Collectors.toList()); | ||
79 | + | ||
80 | + // 过滤2: 通过查表 appaise_order & attribute | ||
81 | + List<AppraiseOrder> appraiseOrderList = appraiseOrderMapper.selectByOrderCodeList(goodServiceOrderLists); | ||
82 | + | ||
83 | + if (CollectionUtils.isEmpty(appraiseOrderList)){ | ||
84 | + return; | ||
85 | + } | ||
86 | + List<AppraiseOrder> depositCodeList = appraiseOrderList.stream() | ||
87 | + .filter(appraiseOrder -> appraiseOrder.getAttributes() == OrderAttributes.DEPOSITE.getCode()) | ||
88 | + .collect(Collectors.toList()); | ||
89 | + | ||
90 | + executorService.execute(() -> { | ||
91 | + // 只返4单 | ||
92 | + int DEFAULT_REBATE_CNT = alipayTransferChancelSelector.getDepositRebateOrderCnt(); | ||
93 | + BigDecimal rebate = new BigDecimal(alipayTransferChancelSelector.getDepositRebateAmount()); | ||
94 | + | ||
95 | + depositCodeList.stream().forEach(depositCode -> { | ||
96 | + | ||
97 | + int rebateCnt = ordersPayTransferMapper.selectByUidAndTransferType(depositCode.getUid(), TransferCase.DEPOSIT_REBATE_TO_USER.getCode()); | ||
98 | + logger.info("rebate transfer cnt {}, uid {}", rebateCnt, depositCode.getUid()); | ||
99 | + if (rebateCnt < DEFAULT_REBATE_CNT){ | ||
100 | + TransferCase transferCase = TransferCase.DEPOSIT_REBATE_TO_USER; | ||
101 | + TranseferCellNode transeferCellNode = new TranseferCellNode(); | ||
102 | + transeferCellNode.setUid(depositCode.getUid()); | ||
103 | + transeferCellNode.setAmount(rebate.setScale(2,BigDecimal.ROUND_HALF_DOWN)); | ||
104 | + | ||
105 | + TransferMoneyRequest tmReq = TransferMoneyRequest.builder() | ||
106 | + .sellerUid(depositCode.getUid()) | ||
107 | + .buyerOrderCode(depositCode.getOrderCode()) | ||
108 | + .type(transferCase.getCode()) | ||
109 | + .transferCase(transferCase) | ||
110 | + .transeferCellNode(transeferCellNode) | ||
111 | + .swdType(SellerWalletDetail.Type.DEPOSIT_REBATE) | ||
112 | + .alarmConfig(AlarmConfig.DEPOSIT_REBATE_FAIL) // 打款失败的时候警告 | ||
113 | + .build(); | ||
114 | + | ||
115 | + transferService.transfer(tmReq); | ||
116 | + } | ||
117 | + | ||
118 | + }); | ||
119 | + | ||
120 | + }); | ||
121 | + | ||
122 | + } | ||
123 | + | ||
26 | 124 | ||
27 | @Override | 125 | @Override |
28 | public int deliver2Depot(DeliverToDepotReq req){ | 126 | public int deliver2Depot(DeliverToDepotReq req){ |
@@ -107,70 +107,6 @@ public class AppraiseOrderService extends AbsGoodsServiceOrderService implements | @@ -107,70 +107,6 @@ public class AppraiseOrderService extends AbsGoodsServiceOrderService implements | ||
107 | @Autowired | 107 | @Autowired |
108 | OrdersPayTransferMapper ordersPayTransferMapper; | 108 | OrdersPayTransferMapper ordersPayTransferMapper; |
109 | 109 | ||
110 | - private ExecutorService executorService = new ThreadPoolExecutor(5, 10, 60, TimeUnit.SECONDS, | ||
111 | - new ArrayBlockingQueue<>(1000), | ||
112 | - NamedThreadFactory.newThreadFactory("appraise")); | ||
113 | - | ||
114 | - /** | ||
115 | - * 申请寄存返利 | ||
116 | - * @param orderCodeList | ||
117 | - */ | ||
118 | - public void depositRebate(List<Long> orderCodeList){ | ||
119 | - | ||
120 | - logger.info("depositRebate param is {}", orderCodeList); | ||
121 | - | ||
122 | - if (CollectionUtils.isEmpty(orderCodeList)){ | ||
123 | - return; | ||
124 | - } | ||
125 | - | ||
126 | - // 过滤1: 通过code过滤出来 goods_service的订单号 | ||
127 | - List<Long> goodServiceOrderLists = orderCodeList.stream() | ||
128 | - .filter(orderCode -> orderCodeGenerator.expId(orderCode).getType() == OrderCodeType.GOODS_SERVICE.getType()) | ||
129 | - .collect(Collectors.toList()); | ||
130 | - | ||
131 | - // 过滤2: 通过查表 appaise_order & attribute | ||
132 | - List<AppraiseOrder> appraiseOrderList = appraiseOrderMapper.selectByOrderCodeList(goodServiceOrderLists); | ||
133 | - | ||
134 | - if (CollectionUtils.isEmpty(appraiseOrderList)){ | ||
135 | - return; | ||
136 | - } | ||
137 | - List<AppraiseOrder> depositCodeList = appraiseOrderList.stream() | ||
138 | - .filter(appraiseOrder -> appraiseOrder.getAttributes() == OrderAttributes.DEPOSITE.getCode()) | ||
139 | - .collect(Collectors.toList()); | ||
140 | - | ||
141 | -// executorService.execute(() -> { | ||
142 | - | ||
143 | - // 只返4单 | ||
144 | - int DEFAULT_REBATE_CNT = alipayTransferChancelSelector.getDepositRebateOrderCnt(); | ||
145 | - depositCodeList.stream().forEach(depositCode -> { | ||
146 | - | ||
147 | - int rebateCnt = ordersPayTransferMapper.selectByUidAndTransferType(depositCode.getUid(),TransferCase.DEPOSIT_REBATE_TO_USER.getCode()); | ||
148 | - logger.info("rebate transfer cnt {}, uid {}", rebateCnt, depositCode.getUid()); | ||
149 | - if (rebateCnt < DEFAULT_REBATE_CNT){ | ||
150 | - TransferCase transferCase = TransferCase.DEPOSIT_REBATE_TO_USER; | ||
151 | - TranseferCellNode transeferCellNode = new TranseferCellNode(); | ||
152 | - transeferCellNode.setUid(depositCode.getUid()); | ||
153 | - transeferCellNode.setAmount(new BigDecimal(alipayTransferChancelSelector.getDepositRebateAmount())); // 一单返40元 | ||
154 | - | ||
155 | - TransferMoneyRequest tmReq = TransferMoneyRequest.builder() | ||
156 | - .sellerUid(depositCode.getUid()) | ||
157 | - .buyerOrderCode(depositCode.getOrderCode()) | ||
158 | - .type(transferCase.getCode()) | ||
159 | - .transferCase(transferCase) | ||
160 | - .transeferCellNode(transeferCellNode) | ||
161 | - .swdType(SellerWalletDetail.Type.DEPOSIT_REBATE) | ||
162 | - .alarmConfig(AlarmConfig.DEPOSIT_REBATE_FAIL) // 打款失败的时候警告 | ||
163 | - .build(); | ||
164 | - | ||
165 | - transferService.transfer(tmReq); | ||
166 | - } | ||
167 | - | ||
168 | - }); | ||
169 | - | ||
170 | -// }); | ||
171 | - | ||
172 | - } | ||
173 | - | ||
174 | 110 | ||
175 | public AppraiseOrderComputeResp compute(AppraiseOrderComputeReq req){ | 111 | public AppraiseOrderComputeResp compute(AppraiseOrderComputeReq req){ |
176 | logger.info("in AppraiseOrderService.compute req {}", req); | 112 | logger.info("in AppraiseOrderService.compute req {}", req); |
@@ -21,6 +21,7 @@ import com.yohoufo.dal.order.*; | @@ -21,6 +21,7 @@ import com.yohoufo.dal.order.*; | ||
21 | import com.yohoufo.dal.order.model.*; | 21 | import com.yohoufo.dal.order.model.*; |
22 | import com.yohoufo.order.common.BillTradeStatus; | 22 | import com.yohoufo.order.common.BillTradeStatus; |
23 | import com.yohoufo.order.common.HbfqEnum; | 23 | import com.yohoufo.order.common.HbfqEnum; |
24 | +import com.yohoufo.order.common.TradeType; | ||
24 | import com.yohoufo.order.common.TransferCase; | 25 | import com.yohoufo.order.common.TransferCase; |
25 | import com.yohoufo.order.constants.RefundContant; | 26 | import com.yohoufo.order.constants.RefundContant; |
26 | import com.yohoufo.order.model.PayQueryBo; | 27 | import com.yohoufo.order.model.PayQueryBo; |
@@ -1409,7 +1410,11 @@ public class PaymentServiceImpl implements IPaymentService { | @@ -1409,7 +1410,11 @@ public class PaymentServiceImpl implements IPaymentService { | ||
1409 | record.setUserType(targetUserType.getCode()); | 1410 | record.setUserType(targetUserType.getCode()); |
1410 | record.setPayType(1); | 1411 | record.setPayType(1); |
1411 | // 如果[全部货款->卖家],否则[补偿款->卖家或买家] 2:货款;3:补偿款 | 1412 | // 如果[全部货款->卖家],否则[补偿款->卖家或买家] 2:货款;3:补偿款 |
1412 | - record.setTradeType(transferCase == TransferCase.ALL_GOODS_MONEY_TO_SELLER ? 2 : 3); | 1413 | + if (transferCase == TransferCase.DEPOSIT_REBATE_TO_USER){ |
1414 | + record.setTradeType(TradeType.deposit_rebate.getCode()); // 返利 | ||
1415 | + }else{ | ||
1416 | + record.setTradeType(transferCase == TransferCase.ALL_GOODS_MONEY_TO_SELLER ? TradeType.goods_income.getCode() : TradeType.compensateIncome.getCode()); | ||
1417 | + } | ||
1413 | record.setIncomeOutcome(1); | 1418 | record.setIncomeOutcome(1); |
1414 | record.setTradeStatus(BillTradeStatus.NEW.getCode()); | 1419 | record.setTradeStatus(BillTradeStatus.NEW.getCode()); |
1415 | record.setCreateTime(now); | 1420 | record.setCreateTime(now); |
-
Please register or login to post a comment