Authored by chenchao

add compensate deposit goods when buyer cancel order of use deposit goods replace

  1 +package com.yohoufo.order.event;
  2 +
  3 +import lombok.Getter;
  4 +import lombok.Setter;
  5 +import lombok.ToString;
  6 +
  7 +import java.util.function.Function;
  8 +@ToString(of = {"uid", "depositCode"})
  9 +public class DepositGoodsCompensateAsyncEvent extends AsyncEvent {
  10 + @Getter@Setter
  11 + private int uid;
  12 + @Getter@Setter
  13 + private String depositCode;
  14 +
  15 + public DepositGoodsCompensateAsyncEvent(Function<DepositGoodsCompensateAsyncEvent,Integer> function) {
  16 + super(function);
  17 + }
  18 +
  19 + @Override
  20 + AsyncEvent getAsyncEvent() {
  21 + return this;
  22 + }
  23 +}
@@ -32,4 +32,6 @@ public interface IBuyerOrderMetaService { @@ -32,4 +32,6 @@ public interface IBuyerOrderMetaService {
32 * @return 32 * @return
33 */ 33 */
34 int saveDepositCode(String depositCode, int uid, long orderCode); 34 int saveDepositCode(String depositCode, int uid, long orderCode);
  35 +
  36 + String getDepositCode(int uid, Long orderCode);
35 } 37 }
@@ -28,9 +28,12 @@ import com.yohoufo.order.model.dto.BuyerPenaltyCalResult; @@ -28,9 +28,12 @@ import com.yohoufo.order.model.dto.BuyerPenaltyCalResult;
28 import com.yohoufo.order.model.request.PaymentRequest; 28 import com.yohoufo.order.model.request.PaymentRequest;
29 import com.yohoufo.order.model.request.TranseferCellNode; 29 import com.yohoufo.order.model.request.TranseferCellNode;
30 import com.yohoufo.order.model.request.TransferMoneyRequest; 30 import com.yohoufo.order.model.request.TransferMoneyRequest;
  31 +import com.yohoufo.order.service.DepositService;
  32 +import com.yohoufo.order.service.IBuyerOrderMetaService;
31 import com.yohoufo.order.service.cache.CacheCleaner; 33 import com.yohoufo.order.service.cache.CacheCleaner;
32 import com.yohoufo.order.service.cache.CacheKeyBuilder; 34 import com.yohoufo.order.service.cache.CacheKeyBuilder;
33 import com.yohoufo.order.service.concurrent.ThreadPoolFactory; 35 import com.yohoufo.order.service.concurrent.ThreadPoolFactory;
  36 +import com.yohoufo.order.service.deposit.DepositOrderService;
34 import com.yohoufo.order.service.handler.BuyerCancelCompensateComputeHandler; 37 import com.yohoufo.order.service.handler.BuyerCancelCompensateComputeHandler;
35 import com.yohoufo.order.service.handler.RefundEarnestMoneyHandler; 38 import com.yohoufo.order.service.handler.RefundEarnestMoneyHandler;
36 import com.yohoufo.order.service.handler.RefundGoodsMoneyHandler; 39 import com.yohoufo.order.service.handler.RefundGoodsMoneyHandler;
@@ -140,6 +143,12 @@ public class BuyerOrderCancelService { @@ -140,6 +143,12 @@ public class BuyerOrderCancelService {
140 @Resource(name = "tradeMqProducer") 143 @Resource(name = "tradeMqProducer")
141 private YhProducer tradeMqProducer; 144 private YhProducer tradeMqProducer;
142 145
  146 + @Autowired
  147 + private DepositService depositService;
  148 +
  149 + @Autowired
  150 + private IBuyerOrderMetaService buyerOrderMetaService;
  151 +
143 public void cancel(BeforeSellerDeliverEvent bsdEvent){ 152 public void cancel(BeforeSellerDeliverEvent bsdEvent){
144 int buyerUid = bsdEvent.getBuyerUid(); 153 int buyerUid = bsdEvent.getBuyerUid();
145 int sellerUid = bsdEvent.getSellerUid(); 154 int sellerUid = bsdEvent.getSellerUid();
@@ -353,11 +362,30 @@ public class BuyerOrderCancelService { @@ -353,11 +362,30 @@ public class BuyerOrderCancelService {
353 EventBusPublisher.publishEvent(new UfoInfluxdbEvent(new UfoInfluxdbVo.Builder().setMeasurement(InfluxdbMeasurementEnum.MEASUREMENT_ORDER_CANCEL) 362 EventBusPublisher.publishEvent(new UfoInfluxdbEvent(new UfoInfluxdbVo.Builder().setMeasurement(InfluxdbMeasurementEnum.MEASUREMENT_ORDER_CANCEL)
354 .addInitField(InfluxdbFieldEnum.FIELD_COUNT).build())); // 统计取消订单的次数 363 .addInitField(InfluxdbFieldEnum.FIELD_COUNT).build())); // 统计取消订单的次数
355 364
  365 + //
  366 + String depositCode = buyerOrderMetaService.getDepositCode(buyerUid, orderCode);
  367 + if (StringUtils.isNotBlank(depositCode)){
  368 + logger.info("cancel buyer order Before Depot Receive trigger DepositGoodsCompensateAsyncEvent orderCode {} depositCode {}", orderCode, depositCode);
  369 + triggerDepositGoodsCompensateAsyncEvent(sellerUid, depositCode);
  370 + }
356 logger.info("use one thread to execute buyer cancel BeforeDepotReceive buyerUid {}, orderCode {}, skup {}, compensate {}, transferCase {}", 371 logger.info("use one thread to execute buyer cancel BeforeDepotReceive buyerUid {}, orderCode {}, skup {}, compensate {}, transferCase {}",
357 buyerUid, orderCode, skup, bpcr, transferCase); 372 buyerUid, orderCode, skup, bpcr, transferCase);
358 } 373 }
359 } 374 }
360 375
  376 + private int compensateDepositGoods(DepositGoodsCompensateAsyncEvent event){
  377 + logger.info("cancel buyer order compensateDepositGoods, event {}", event);
  378 + return depositService.updateDepositAfterCancelBuy(event.getUid(), event.getDepositCode());
  379 + }
  380 +
  381 + private void triggerDepositGoodsCompensateAsyncEvent(int sellerUid, String depositCode){
  382 + logger.info("trigger DepositGoodsCompensateAsyncEvent sellerUid {} depositCode {}", sellerUid, depositCode);
  383 + DepositGoodsCompensateAsyncEvent asyncEvent
  384 + = new DepositGoodsCompensateAsyncEvent(this::compensateDepositGoods);
  385 + asyncEvent.setUid(sellerUid);
  386 + asyncEvent.setDepositCode(depositCode);
  387 + EventBusPublisher.publishEvent(asyncEvent);
  388 + }
361 389
362 public void clearanceFail(long orderCode, String failReason, ClearanceFailType failType){ 390 public void clearanceFail(long orderCode, String failReason, ClearanceFailType failType){
363 new ClearanceFailModel(orderCode, failReason, failType).invoke().cancel(); 391 new ClearanceFailModel(orderCode, failReason, failType).invoke().cancel();
@@ -23,6 +23,7 @@ import org.springframework.stereotype.Service; @@ -23,6 +23,7 @@ import org.springframework.stereotype.Service;
23 23
24 import java.util.Arrays; 24 import java.util.Arrays;
25 import java.util.Objects; 25 import java.util.Objects;
  26 +import java.util.Optional;
26 27
27 @Service 28 @Service
28 public class BuyerOrderMetaServiceImpl implements IBuyerOrderMetaService { 29 public class BuyerOrderMetaServiceImpl implements IBuyerOrderMetaService {
@@ -173,6 +174,10 @@ public class BuyerOrderMetaServiceImpl implements IBuyerOrderMetaService { @@ -173,6 +174,10 @@ public class BuyerOrderMetaServiceImpl implements IBuyerOrderMetaService {
173 return buyerOrderMetaMapper.insert(buyerOrderMeta); 174 return buyerOrderMetaMapper.insert(buyerOrderMeta);
174 } 175 }
175 176
176 - 177 + @Override
  178 + public String getDepositCode(int uid, Long orderCode){
  179 + BuyerOrderMeta buyerOrderMeta = buyerOrderMetaMapper.selectByMetaKey(uid, orderCode, MetaKey.DEPOSIT_CODE);
  180 + return Optional.ofNullable(buyerOrderMeta).map(BuyerOrderMeta::getMetaValue).orElse(null);
  181 + }
177 182
178 } 183 }
@@ -814,8 +814,9 @@ public class DepositServiceImpl implements DepositService { @@ -814,8 +814,9 @@ public class DepositServiceImpl implements DepositService {
814 return storageDepositMapper.updateStorageStatus(deposit.getId(), StorageDepositStatusEnum.WAITING_QUERY.getCode(), 0, DepositOutTypeEnum.OUTTYPE_DEPOSIT_CHANGE_TO_IN_STOCK.getCode(), uid); 814 return storageDepositMapper.updateStorageStatus(deposit.getId(), StorageDepositStatusEnum.WAITING_QUERY.getCode(), 0, DepositOutTypeEnum.OUTTYPE_DEPOSIT_CHANGE_TO_IN_STOCK.getCode(), uid);
815 } 815 }
816 816
817 - @Autowired 817 + @Override
818 public int updateDepositAfterCancelBuy(Integer uid, String depositCode) { 818 public int updateDepositAfterCancelBuy(Integer uid, String depositCode) {
  819 +
819 return 0; 820 return 0;
820 } 821 }
821 822
@@ -37,7 +37,7 @@ hystrix.threadpool.default.maxQueueSize=50000 @@ -37,7 +37,7 @@ hystrix.threadpool.default.maxQueueSize=50000
37 hystrix.threadpool.default.queueSizeRejectionThreshold=45000 37 hystrix.threadpool.default.queueSizeRejectionThreshold=45000
38 38
39 #zookeeper address 39 #zookeeper address
40 -zkAddress=192.168.102.45:2181 40 +zkAddress=192.168.104.201:2181
41 #zkAddress=192.168.102.45:2181 41 #zkAddress=192.168.102.45:2181
42 # web context 42 # web context
43 web.context=ufo-gateway 43 web.context=ufo-gateway