Authored by chenchao

change cal config

@@ -25,7 +25,6 @@ import com.yohoufo.order.model.dto.BuyerPenaltyCalResult; @@ -25,7 +25,6 @@ import com.yohoufo.order.model.dto.BuyerPenaltyCalResult;
25 import com.yohoufo.order.model.request.PaymentRequest; 25 import com.yohoufo.order.model.request.PaymentRequest;
26 import com.yohoufo.order.model.request.TranseferCellNode; 26 import com.yohoufo.order.model.request.TranseferCellNode;
27 import com.yohoufo.order.model.request.TransferMoneyRequest; 27 import com.yohoufo.order.model.request.TransferMoneyRequest;
28 -import com.yohoufo.order.service.IPaymentService;  
29 import com.yohoufo.order.service.cache.CacheCleaner; 28 import com.yohoufo.order.service.cache.CacheCleaner;
30 import com.yohoufo.order.service.cache.CacheKeyBuilder; 29 import com.yohoufo.order.service.cache.CacheKeyBuilder;
31 import com.yohoufo.order.service.concurrent.ThreadPoolFactory; 30 import com.yohoufo.order.service.concurrent.ThreadPoolFactory;
@@ -38,7 +37,6 @@ import org.slf4j.Logger; @@ -38,7 +37,6 @@ import org.slf4j.Logger;
38 import org.springframework.beans.factory.annotation.Autowired; 37 import org.springframework.beans.factory.annotation.Autowired;
39 import org.springframework.stereotype.Service; 38 import org.springframework.stereotype.Service;
40 39
41 -import javax.annotation.Resource;  
42 import java.math.BigDecimal; 40 import java.math.BigDecimal;
43 import java.util.Arrays; 41 import java.util.Arrays;
44 import java.util.Collection; 42 import java.util.Collection;
@@ -53,9 +51,6 @@ import java.util.concurrent.Future; @@ -53,9 +51,6 @@ import java.util.concurrent.Future;
53 public class BuyerOrderCancelService { 51 public class BuyerOrderCancelService {
54 private Logger logger = LoggerUtils.getOrderCloseLogger(); 52 private Logger logger = LoggerUtils.getOrderCloseLogger();
55 53
56 - @Resource(name = "orderDynamicConfig")  
57 - private OrderDynamicConfig orderDynamicConfig;  
58 -  
59 @Autowired 54 @Autowired
60 private BuyerOrderMapper buyerOrderMapper; 55 private BuyerOrderMapper buyerOrderMapper;
61 56
@@ -197,19 +192,34 @@ public class BuyerOrderCancelService { @@ -197,19 +192,34 @@ public class BuyerOrderCancelService {
197 return mfee; 192 return mfee;
198 } 193 }
199 194
  195 + private BuyerPenaltyCalResult getBuyerPenaltyCalResult(BuyerOrder buyerOrder){
  196 + Integer buyerUid = buyerOrder.getUid();
  197 + Long orderCode = buyerOrder.getOrderCode();
  198 + OrderStatus orderStatus = OrderStatus.getOrderStatus(buyerOrder.getStatus());
  199 + BigDecimal orderActualAmount = buyerOrder.getAmount();
  200 + BigDecimal shipFee = buyerOrder.getShipFee();
  201 + OrderAttributes orderAttributes = OrderAttributes.getOrderAttributes(buyerOrder.getAttributes());
  202 + //TODO try catch to record fail transfer
  203 + BuyerPenaltyCalResult bpcr = calBuyerPenalty(buyerUid, orderCode, orderStatus, orderActualAmount, shipFee, orderAttributes);
  204 + return bpcr;
  205 + }
200 206
201 - public void cancel(BeforeSellerDeliverEvent bsdEvent){  
202 - OrderDynamicConfig.BuyerCancelCompensateNode compensate = orderDynamicConfig.getBeforeSellerDeliverBCCN();  
203 - logger.info("in buyer cancel BeforeSellerDeliver, event {} compensate {}", bsdEvent, compensate);  
204 207
205 - //买家实付金额(货款+运费)小于赔偿金的额度,不够赔偿的,则不允许取消  
206 - if(bsdEvent.getAmount()==null||bsdEvent.getAmount().compareTo(compensate.getBuyerCompensateMoney()) < 0){  
207 - logger.warn("in buyer cancel BeforeSellerDeliver not allow cancel cause of buyer amount lower than BuyerCompensateMoney, event {} compensate {}", bsdEvent, compensate);  
208 - throw new com.yohoufo.common.exception.UfoServiceException(400,"买家赔偿金低于商品售价,不允许取消");  
209 - } 208 + public void cancel(BeforeSellerDeliverEvent bsdEvent){
210 int buyerUid = bsdEvent.getBuyerUid(); 209 int buyerUid = bsdEvent.getBuyerUid();
211 int sellerUid = bsdEvent.getSellerUid(); 210 int sellerUid = bsdEvent.getSellerUid();
212 long orderCode = bsdEvent.getOrderCode(); 211 long orderCode = bsdEvent.getOrderCode();
  212 + BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCode(orderCode);
  213 + logger.info("in buyer cancel BeforeSellerDeliver begin buyerOrderMapper.selectByOrderCode, buyerUid {}, orderCode {}, skup {} buyerOrder {}",
  214 + buyerUid, orderCode, buyerOrder );
  215 + BuyerPenaltyCalResult bpcr = getBuyerPenaltyCalResult(buyerOrder);
  216 + logger.info("in buyer cancel BeforeSellerDeliver, event {} BuyerPenaltyCalResult {}", bsdEvent, bpcr);
  217 + //买家实付金额(货款+运费)小于赔偿金的额度,不够赔偿的,则不允许取消
  218 + if(bsdEvent.getAmount()==null||bsdEvent.getAmount().compareTo(bpcr.getPenaltyAmount()) < 0){
  219 + logger.warn("in buyer cancel BeforeSellerDeliver not allow cancel cause of buyer amount lower than BuyerCompensateMoney, event {} compensate {}", bsdEvent, bpcr);
  220 + throw new com.yohoufo.common.exception.UfoServiceException(400,"买家赔偿金低于商品售价,不允许取消");
  221 + }
  222 +
213 OrderStatus target = bsdEvent.getTarget(); 223 OrderStatus target = bsdEvent.getTarget();
214 OrderStatus expected = bsdEvent.getExpected(); 224 OrderStatus expected = bsdEvent.getExpected();
215 int currentTime = DateUtil.getCurrentTimeSecond(); 225 int currentTime = DateUtil.getCurrentTimeSecond();
@@ -230,14 +240,14 @@ public class BuyerOrderCancelService { @@ -230,14 +240,14 @@ public class BuyerOrderCancelService {
230 sellerOrderMapper.updateBySkups(soc, Arrays.asList(skup)); 240 sellerOrderMapper.updateBySkups(soc, Arrays.asList(skup));
231 SellerOrderGoods psog = sellerOrderGoodsMapper.selectByPrimaryKey(skup); 241 SellerOrderGoods psog = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
232 inBoxFacade.buyerCancelBeforeSellerDeliver(buyerUid, orderCode, 242 inBoxFacade.buyerCancelBeforeSellerDeliver(buyerUid, orderCode,
233 - compensate.getBuyerCompensateMoney().toPlainString(), psog); 243 + bpcr.getPenaltyAmount().toPlainString(), psog);
234 //TODO 整个过程异步去执行(考虑退费依赖订单状态) 244 //TODO 整个过程异步去执行(考虑退费依赖订单状态)
235 //(退费)退保证金给卖家 245 //(退费)退保证金给卖家
236 //(转账)瓜分指定赔偿款给卖家和平台 246 //(转账)瓜分指定赔偿款给卖家和平台
237 TransferCase transferCase = TransferCase.BUYER_CANCEL_BEFORE_SELLER_DELIVER; 247 TransferCase transferCase = TransferCase.BUYER_CANCEL_BEFORE_SELLER_DELIVER;
238 //(退费)扣除赔偿款,计算剩余的货款,退给买家 248 //(退费)扣除赔偿款,计算剩余的货款,退给买家
239 - BuyerCancelAfterProcessTask bcapt = new BuyerCancelAfterProcessTask(buyerUid, orderCode, skup,  
240 - compensate, transferCase); 249 + BuyerCancelAfterProcessTask bcapt = new BuyerCancelAfterProcessTask(buyerOrder, skup,
  250 + bpcr, transferCase);
241 bcapt.setSwdType(SellerWalletDetail.Type.BUYER_CANCEL_NO_DELIVERY); 251 bcapt.setSwdType(SellerWalletDetail.Type.BUYER_CANCEL_NO_DELIVERY);
242 Future<PayRefundBo> future = ThreadPoolFactory.getBuyerCancelThreadPool().submit(bcapt); 252 Future<PayRefundBo> future = ThreadPoolFactory.getBuyerCancelThreadPool().submit(bcapt);
243 253
@@ -252,25 +262,28 @@ public class BuyerOrderCancelService { @@ -252,25 +262,28 @@ public class BuyerOrderCancelService {
252 EventBusPublisher.publishEvent(event); 262 EventBusPublisher.publishEvent(event);
253 263
254 logger.info("use one thread to execute buyer cancel BeforeSellerDeliver buyerUid {}, orderCode {}, skup {}, compensate {}, transferCase {}", 264 logger.info("use one thread to execute buyer cancel BeforeSellerDeliver buyerUid {}, orderCode {}, skup {}, compensate {}, transferCase {}",
255 - buyerUid, orderCode, skup, compensate, transferCase); 265 + buyerUid, orderCode, skup, bpcr, transferCase);
256 } 266 }
257 } 267 }
258 268
259 269
260 public void cancel(BeforeDepotReceiveEvent bdrEvent){ 270 public void cancel(BeforeDepotReceiveEvent bdrEvent){
261 - OrderDynamicConfig.BuyerCancelCompensateNode compensate = orderDynamicConfig.getBeforeDepotReceiveBCCN();  
262 - logger.info("in buyer cancel BeforeDepotReceive, event {} compensate {}", bdrEvent, compensate);  
263 - 271 + int buyerUid = bdrEvent.getBuyerUid();
  272 + int sellerUid = bdrEvent.getSellerUid();
  273 + long orderCode = bdrEvent.getOrderCode();
  274 + BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCode(orderCode);
  275 + logger.info("in buyer cancel BeforeDepotReceive begin buyerOrderMapper.selectByOrderCode, buyerUid {}, orderCode {}, skup {} buyerOrder {}",
  276 + buyerUid, orderCode, buyerOrder );
  277 + BuyerPenaltyCalResult bpcr = getBuyerPenaltyCalResult(buyerOrder);
  278 + logger.info("in buyer cancel BeforeDepotReceive, event {} compensate {}", bdrEvent, bpcr);
264 //买家实付金额(货款+运费)小于赔偿金的额度,不够赔偿的,则不允许取消 279 //买家实付金额(货款+运费)小于赔偿金的额度,不够赔偿的,则不允许取消
265 - if(bdrEvent.getAmount()==null||bdrEvent.getAmount().compareTo(compensate.getBuyerCompensateMoney()) < 0){  
266 - logger.warn("in buyer cancel BeforeDepotReceive not allow cancel cause of buyer amount lower than BuyerCompensateMoney, event {} compensate {}", bdrEvent, compensate); 280 + if(bdrEvent.getAmount()==null||bdrEvent.getAmount().compareTo(bpcr.getPenaltyAmount()) < 0){
  281 + logger.warn("in buyer cancel BeforeDepotReceive not allow cancel cause of buyer amount lower than BuyerCompensateMoney, event {} compensate {}", bdrEvent, bpcr);
267 throw new com.yohoufo.common.exception.UfoServiceException(400,"买家赔偿金低于商品售价,不允许取消"); 282 throw new com.yohoufo.common.exception.UfoServiceException(400,"买家赔偿金低于商品售价,不允许取消");
268 } 283 }
269 OrderStatus target = bdrEvent.getTarget(); 284 OrderStatus target = bdrEvent.getTarget();
270 OrderStatus expected = bdrEvent.getExpected(); 285 OrderStatus expected = bdrEvent.getExpected();
271 - int buyerUid = bdrEvent.getBuyerUid();  
272 - int sellerUid = bdrEvent.getSellerUid();  
273 - long orderCode = bdrEvent.getOrderCode(); 286 +
274 int currentTime = DateUtil.getCurrentTimeSecond(); 287 int currentTime = DateUtil.getCurrentTimeSecond();
275 int rows = buyerOrderMapper.updateStatusByOrderCode(orderCode, buyerUid, expected.getCode(), target.getCode(), currentTime); 288 int rows = buyerOrderMapper.updateStatusByOrderCode(orderCode, buyerUid, expected.getCode(), target.getCode(), currentTime);
276 if (rows>0) { 289 if (rows>0) {
@@ -290,14 +303,14 @@ public class BuyerOrderCancelService { @@ -290,14 +303,14 @@ public class BuyerOrderCancelService {
290 sellerOrderMapper.updateBySkups(soc, Arrays.asList(skup)); 303 sellerOrderMapper.updateBySkups(soc, Arrays.asList(skup));
291 SellerOrderGoods psog = sellerOrderGoodsMapper.selectByPrimaryKey(skup); 304 SellerOrderGoods psog = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
292 inBoxFacade.buyerCancelBeforeDepotReceive(buyerUid, orderCode, 305 inBoxFacade.buyerCancelBeforeDepotReceive(buyerUid, orderCode,
293 - compensate.getBuyerCompensateMoney().toPlainString(), psog); 306 + bpcr.getPenaltyAmount().toPlainString(), psog);
294 //整个过程异步去执行(考虑退费依赖订单状态) 307 //整个过程异步去执行(考虑退费依赖订单状态)
295 //(退费)退保证金给卖家 308 //(退费)退保证金给卖家
296 //(转账)瓜分指定赔偿款给卖家和平台 309 //(转账)瓜分指定赔偿款给卖家和平台
297 //(退费)扣除赔偿款,计算剩余的货款,退给买家 310 //(退费)扣除赔偿款,计算剩余的货款,退给买家
298 TransferCase transferCase = TransferCase.BUYER_CANCEL_BEFORE_DEPOT_RECEIVE; 311 TransferCase transferCase = TransferCase.BUYER_CANCEL_BEFORE_DEPOT_RECEIVE;
299 - BuyerCancelAfterProcessTask bcapt = new BuyerCancelAfterProcessTask(buyerUid, orderCode, skup,  
300 - compensate, transferCase); 312 + BuyerCancelAfterProcessTask bcapt = new BuyerCancelAfterProcessTask(buyerOrder, skup,
  313 + bpcr, transferCase);
301 bcapt.setSwdType(SellerWalletDetail.Type.BUYER_CANCEL_DELIVERY); 314 bcapt.setSwdType(SellerWalletDetail.Type.BUYER_CANCEL_DELIVERY);
302 Future<PayRefundBo> future = ThreadPoolFactory.getBuyerCancelThreadPool().submit(bcapt); 315 Future<PayRefundBo> future = ThreadPoolFactory.getBuyerCancelThreadPool().submit(bcapt);
303 316
@@ -312,7 +325,7 @@ public class BuyerOrderCancelService { @@ -312,7 +325,7 @@ public class BuyerOrderCancelService {
312 EventBusPublisher.publishEvent(event); 325 EventBusPublisher.publishEvent(event);
313 326
314 logger.info("use one thread to execute buyer cancel BeforeDepotReceive buyerUid {}, orderCode {}, skup {}, compensate {}, transferCase {}", 327 logger.info("use one thread to execute buyer cancel BeforeDepotReceive buyerUid {}, orderCode {}, skup {}, compensate {}, transferCase {}",
315 - buyerUid, orderCode, skup, compensate, transferCase); 328 + buyerUid, orderCode, skup, bpcr, transferCase);
316 } 329 }
317 } 330 }
318 331
@@ -320,18 +333,18 @@ public class BuyerOrderCancelService { @@ -320,18 +333,18 @@ public class BuyerOrderCancelService {
320 int buyerUid; 333 int buyerUid;
321 long orderCode; 334 long orderCode;
322 int skup; 335 int skup;
323 - OrderDynamicConfig.BuyerCancelCompensateNode compensate; 336 + BuyerPenaltyCalResult bpcr;
  337 + BuyerOrder buyerOrder;
324 TransferCase transferCase; 338 TransferCase transferCase;
325 339
326 @Setter 340 @Setter
327 SellerWalletDetail.Type swdType; 341 SellerWalletDetail.Type swdType;
328 342
329 - public BuyerCancelAfterProcessTask(int buyerUid, long orderCode, int skup, OrderDynamicConfig.  
330 - BuyerCancelCompensateNode compensate, TransferCase transferCase) {  
331 - this.buyerUid = buyerUid;  
332 - this.orderCode = orderCode; 343 + public BuyerCancelAfterProcessTask(BuyerOrder buyerOrder, int skup, BuyerPenaltyCalResult bpcr, TransferCase transferCase) {
  344 + this.buyerUid = buyerOrder.getUid();
  345 + this.orderCode = buyerOrder.getOrderCode();
333 this.skup = skup; 346 this.skup = skup;
334 - this.compensate = compensate; 347 + this.bpcr = bpcr;
335 this.transferCase = transferCase; 348 this.transferCase = transferCase;
336 } 349 }
337 350
@@ -421,7 +434,7 @@ public class BuyerOrderCancelService { @@ -421,7 +434,7 @@ public class BuyerOrderCancelService {
421 // 整个过程异步去执行(考虑退费依赖订单状态) 434 // 整个过程异步去执行(考虑退费依赖订单状态)
422 //(退费)退保证金给卖家 435 //(退费)退保证金给卖家
423 logger.info("in BuyerCancelAfterProcessTask call buyerUid {}, orderCode {}, skup {}, transferCase {}, compensate {}", 436 logger.info("in BuyerCancelAfterProcessTask call buyerUid {}, orderCode {}, skup {}, transferCase {}, compensate {}",
424 - buyerUid, orderCode, skup, transferCase, compensate); 437 + buyerUid, orderCode, skup, transferCase, bpcr);
425 PayRefundBo prb = null; 438 PayRefundBo prb = null;
426 try { 439 try {
427 SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(skup); 440 SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(skup);
@@ -430,23 +443,14 @@ public class BuyerOrderCancelService { @@ -430,23 +443,14 @@ public class BuyerOrderCancelService {
430 prb = refundSellerEarnestMoney(sellerOrder); 443 prb = refundSellerEarnestMoney(sellerOrder);
431 444
432 //(转账)瓜分指定赔偿款给卖家和平台 445 //(转账)瓜分指定赔偿款给卖家和平台
433 - BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCode(orderCode);  
434 - logger.info("in BuyerCancelAfterProcessTask call begin buyerOrderMapper.selectByOrderCode, buyerUid {}, orderCode {}, skup {} buyerOrder {}",  
435 - buyerUid, orderCode, skup, buyerOrder );  
436 - OrderStatus orderStatus = OrderStatus.getOrderStatus(buyerOrder.getStatus());  
437 - BigDecimal orderActualAmount = buyerOrder.getAmount();  
438 - BigDecimal shipFee = buyerOrder.getShipFee();  
439 - OrderAttributes orderAttributes = OrderAttributes.getOrderAttributes(buyerOrder.getAttributes());  
440 - //TODO try catch to record fail transfer  
441 - BuyerPenaltyCalResult bpcr = calBuyerPenalty(buyerUid, orderCode, orderStatus, orderActualAmount, shipFee, orderAttributes);  
442 transferPenalty(bpcr); 446 transferPenalty(bpcr);
443 //(退费)扣除赔偿款,计算剩余的货款,退给买家 447 //(退费)扣除赔偿款,计算剩余的货款,退给买家
444 refundLeftOrderAmount(bpcr, buyerOrder); 448 refundLeftOrderAmount(bpcr, buyerOrder);
445 logger.info("out BuyerCancelAfterProcessTask call buyerUid {}, orderCode {}, skup {}, transferCase {}, compensate {}", 449 logger.info("out BuyerCancelAfterProcessTask call buyerUid {}, orderCode {}, skup {}, transferCase {}, compensate {}",
446 - buyerUid, orderCode, skup, transferCase, compensate); 450 + buyerUid, orderCode, skup, transferCase, bpcr);
447 }catch (Exception ex){ 451 }catch (Exception ex){
448 logger.info("occur error BuyerCancelAfterProcessTask call buyerUid {}, orderCode {}, skup {}, transferCase {}, compensate {}", 452 logger.info("occur error BuyerCancelAfterProcessTask call buyerUid {}, orderCode {}, skup {}, transferCase {}, compensate {}",
449 - buyerUid, orderCode, skup, transferCase, compensate, ex); 453 + buyerUid, orderCode, skup, transferCase, bpcr, ex);
450 } 454 }
451 return prb; 455 return prb;
452 } 456 }
@@ -2,15 +2,18 @@ redis: @@ -2,15 +2,18 @@ redis:
2 gwNoSyncRedis : 2 gwNoSyncRedis :
3 servers: 3 servers:
4 - 192.168.102.45:6379 4 - 192.168.102.45:6379
  5 + auth: redis9646
5 gwRecoveryRedis : 6 gwRecoveryRedis :
6 servers: 7 servers:
7 - 192.168.102.45:6379 8 - 192.168.102.45:6379
  9 + auth: redis9646
8 # cleanMq: 10 # cleanMq:
9 # addresses: 11 # addresses:
10 # ${rabbit.cacheclean.producer.host} 12 # ${rabbit.cacheclean.producer.host}
11 yohoNoSyncRedis : 13 yohoNoSyncRedis :
12 servers: 14 servers:
13 - 192.168.102.45:6379 15 - 192.168.102.45:6379
  16 + auth: redis9646
14 # cleanMq: 17 # cleanMq:
15 # addresses: 18 # addresses:
16 # 192.168.102.45:5672 19 # 192.168.102.45:5672