Authored by chenchao

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

package com.yohoufo.order.event;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import java.util.function.Function;
@ToString(of = {"uid", "depositCode"})
public class DepositGoodsCompensateAsyncEvent extends AsyncEvent {
@Getter@Setter
private int uid;
@Getter@Setter
private String depositCode;
public DepositGoodsCompensateAsyncEvent(Function<DepositGoodsCompensateAsyncEvent,Integer> function) {
super(function);
}
@Override
AsyncEvent getAsyncEvent() {
return this;
}
}
... ...
... ... @@ -32,4 +32,6 @@ public interface IBuyerOrderMetaService {
* @return
*/
int saveDepositCode(String depositCode, int uid, long orderCode);
String getDepositCode(int uid, Long orderCode);
}
... ...
... ... @@ -28,9 +28,12 @@ import com.yohoufo.order.model.dto.BuyerPenaltyCalResult;
import com.yohoufo.order.model.request.PaymentRequest;
import com.yohoufo.order.model.request.TranseferCellNode;
import com.yohoufo.order.model.request.TransferMoneyRequest;
import com.yohoufo.order.service.DepositService;
import com.yohoufo.order.service.IBuyerOrderMetaService;
import com.yohoufo.order.service.cache.CacheCleaner;
import com.yohoufo.order.service.cache.CacheKeyBuilder;
import com.yohoufo.order.service.concurrent.ThreadPoolFactory;
import com.yohoufo.order.service.deposit.DepositOrderService;
import com.yohoufo.order.service.handler.BuyerCancelCompensateComputeHandler;
import com.yohoufo.order.service.handler.RefundEarnestMoneyHandler;
import com.yohoufo.order.service.handler.RefundGoodsMoneyHandler;
... ... @@ -140,6 +143,12 @@ public class BuyerOrderCancelService {
@Resource(name = "tradeMqProducer")
private YhProducer tradeMqProducer;
@Autowired
private DepositService depositService;
@Autowired
private IBuyerOrderMetaService buyerOrderMetaService;
public void cancel(BeforeSellerDeliverEvent bsdEvent){
int buyerUid = bsdEvent.getBuyerUid();
int sellerUid = bsdEvent.getSellerUid();
... ... @@ -353,11 +362,30 @@ public class BuyerOrderCancelService {
EventBusPublisher.publishEvent(new UfoInfluxdbEvent(new UfoInfluxdbVo.Builder().setMeasurement(InfluxdbMeasurementEnum.MEASUREMENT_ORDER_CANCEL)
.addInitField(InfluxdbFieldEnum.FIELD_COUNT).build())); // 统计取消订单的次数
//
String depositCode = buyerOrderMetaService.getDepositCode(buyerUid, orderCode);
if (StringUtils.isNotBlank(depositCode)){
logger.info("cancel buyer order Before Depot Receive trigger DepositGoodsCompensateAsyncEvent orderCode {} depositCode {}", orderCode, depositCode);
triggerDepositGoodsCompensateAsyncEvent(sellerUid, depositCode);
}
logger.info("use one thread to execute buyer cancel BeforeDepotReceive buyerUid {}, orderCode {}, skup {}, compensate {}, transferCase {}",
buyerUid, orderCode, skup, bpcr, transferCase);
}
}
private int compensateDepositGoods(DepositGoodsCompensateAsyncEvent event){
logger.info("cancel buyer order compensateDepositGoods, event {}", event);
return depositService.updateDepositAfterCancelBuy(event.getUid(), event.getDepositCode());
}
private void triggerDepositGoodsCompensateAsyncEvent(int sellerUid, String depositCode){
logger.info("trigger DepositGoodsCompensateAsyncEvent sellerUid {} depositCode {}", sellerUid, depositCode);
DepositGoodsCompensateAsyncEvent asyncEvent
= new DepositGoodsCompensateAsyncEvent(this::compensateDepositGoods);
asyncEvent.setUid(sellerUid);
asyncEvent.setDepositCode(depositCode);
EventBusPublisher.publishEvent(asyncEvent);
}
public void clearanceFail(long orderCode, String failReason, ClearanceFailType failType){
new ClearanceFailModel(orderCode, failReason, failType).invoke().cancel();
... ...
... ... @@ -23,6 +23,7 @@ import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.Objects;
import java.util.Optional;
@Service
public class BuyerOrderMetaServiceImpl implements IBuyerOrderMetaService {
... ... @@ -173,6 +174,10 @@ public class BuyerOrderMetaServiceImpl implements IBuyerOrderMetaService {
return buyerOrderMetaMapper.insert(buyerOrderMeta);
}
@Override
public String getDepositCode(int uid, Long orderCode){
BuyerOrderMeta buyerOrderMeta = buyerOrderMetaMapper.selectByMetaKey(uid, orderCode, MetaKey.DEPOSIT_CODE);
return Optional.ofNullable(buyerOrderMeta).map(BuyerOrderMeta::getMetaValue).orElse(null);
}
}
... ...
... ... @@ -814,8 +814,9 @@ public class DepositServiceImpl implements DepositService {
return storageDepositMapper.updateStorageStatus(deposit.getId(), StorageDepositStatusEnum.WAITING_QUERY.getCode(), 0, DepositOutTypeEnum.OUTTYPE_DEPOSIT_CHANGE_TO_IN_STOCK.getCode(), uid);
}
@Autowired
@Override
public int updateDepositAfterCancelBuy(Integer uid, String depositCode) {
return 0;
}
... ...
... ... @@ -37,7 +37,7 @@ hystrix.threadpool.default.maxQueueSize=50000
hystrix.threadpool.default.queueSizeRejectionThreshold=45000
#zookeeper address
zkAddress=192.168.102.45:2181
zkAddress=192.168.104.201:2181
#zkAddress=192.168.102.45:2181
# web context
web.context=ufo-gateway
... ...