|
|
@@ -24,6 +24,7 @@ import com.yc.ship.module.product.enums.VoyageStockLogTypeEnum;
|
|
|
import com.yc.ship.module.product.enums.YesOrNoEnum;
|
|
|
import com.yc.ship.module.product.framework.lock.ProductRedisKeyConstants;
|
|
|
import com.yc.ship.module.product.service.voyagestockdistribute.VoyageStockDistributeNewService;
|
|
|
+import com.yc.ship.module.product.utils.ProductRedisUtils;
|
|
|
import com.yc.ship.module.resource.api.room.RoomApi;
|
|
|
import com.yc.ship.module.trade.enums.TradeOrderStatusEnum;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
@@ -66,6 +67,9 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
@Resource
|
|
|
private RedissonClient redissonClient;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private ProductRedisUtils productRedisUtils;
|
|
|
+
|
|
|
@Resource
|
|
|
private VoyageStockRoomUsedMapper voyageStockRoomUsedMapper;
|
|
|
|
|
|
@@ -124,8 +128,8 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
if (Objects.equals(type, DistributorOrStoreEnum.DISTRIBUTOR.getValue())) {//分销商下单,当前阶段不考虑门店下单
|
|
|
//分销商下单只扣分销商库存,默认是OTA,默认OTC只能门店下单
|
|
|
//初定扣分销商库存
|
|
|
- preCancelReduceStockDistributor(reqDTO.getOrderId(), reqDTO.getType());
|
|
|
preCancelReduceStockDistributor(reqDTO.getOldOrderId(), reqDTO.getType());
|
|
|
+ preCancelReduceStockDistributor(reqDTO.getOrderId(), reqDTO.getType());
|
|
|
}
|
|
|
} finally {
|
|
|
if (lock.isHeldByCurrentThread() && lock.isLocked()) {
|
|
|
@@ -209,6 +213,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
stockDO.setCanSellNum(stockDO.getCanSellNum().add(totalNum)); //退回可售库存
|
|
|
stockDO.setBookNum(stockDO.getBookNum().subtract(totalNum)); // 减去已预订数量
|
|
|
voyageStockMapper.updateById(stockDO);//更新航次总库存
|
|
|
+ productRedisUtils.set(ProductRedisKeyConstants.STOCK_TOTAL_REDIS_KEY_PREFIX + voyageId, stockDO);
|
|
|
//删除航次库存操作记录
|
|
|
voyageStockLogMapper.deleteById(voyageStockLogDO);
|
|
|
} else {
|
|
|
@@ -235,6 +240,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
item.setVirtualNum(item.getVirtualNum().add(VirtualNumMap.get(key)));
|
|
|
});
|
|
|
voyageStockDetailMapper.updateBatch(stockDetailList);
|
|
|
+ productRedisUtils.set(ProductRedisKeyConstants.STOCK_DETAIL_REDIS_KEY_PREFIX + voyageId, stockDetailList);
|
|
|
|
|
|
Integer stockType = detailLogList.get(0).getStockType();
|
|
|
//2:还分销商库存
|
|
|
@@ -253,6 +259,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
item.setBookNum(item.getBookNum() == null ? BigDecimal.ZERO : item.getBookNum().subtract(totalNumMap.get(key)));
|
|
|
});
|
|
|
voyageStockDistributeNewMapper.updateBatch(list);
|
|
|
+ productRedisUtils.set(ProductRedisKeyConstants.STOCK_DISTRIBUTOR_REDIS_KEY_PREFIX + voyageId, list);
|
|
|
}
|
|
|
}
|
|
|
// 删除库存详情初定记录
|
|
|
@@ -288,7 +295,10 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
voyageStockLogDO.setDistributorId(distributorId);
|
|
|
voyageStockLogDO.setStoreId(storeId);
|
|
|
// 获取航次总库存
|
|
|
- VoyageStockDO stockDO = voyageStockMapper.selectById(voyageId);
|
|
|
+ VoyageStockDO stockDO = productRedisUtils.get(ProductRedisKeyConstants.STOCK_TOTAL_REDIS_KEY_PREFIX + voyageId, VoyageStockDO.class, 1);
|
|
|
+ if(stockDO == null) {
|
|
|
+ stockDO = voyageStockMapper.selectById(voyageId);
|
|
|
+ }
|
|
|
if (stockDO == null) {
|
|
|
throw exception(VOYAGE_NO_STOCK);
|
|
|
}
|
|
|
@@ -296,8 +306,11 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
BigDecimal shareNum = stockDO.getShareNum();
|
|
|
|
|
|
//航次库存详情
|
|
|
- List<VoyageStockDetailDO> stockDetailList = voyageStockDetailMapper.selectListByVoyageId(voyageId);
|
|
|
-
|
|
|
+ //航次库存详情
|
|
|
+ List<VoyageStockDetailDO> stockDetailList = productRedisUtils.getList(ProductRedisKeyConstants.STOCK_DETAIL_REDIS_KEY_PREFIX + voyageId, VoyageStockDetailDO.class, 1);
|
|
|
+ if(CollectionUtils.isAnyEmpty(stockDetailList)) {
|
|
|
+ stockDetailList = voyageStockDetailMapper.selectListByVoyageId(voyageId);
|
|
|
+ }
|
|
|
//判断分销商库存是否存在
|
|
|
VoyageStockDistributeNewDetailReqVO detailReqVO = new VoyageStockDistributeNewDetailReqVO();
|
|
|
detailReqVO.setVoyageId(voyageId);
|
|
|
@@ -305,7 +318,10 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
detailReqVO.setObjectId(distributorId);
|
|
|
//先获取非共享库存(分销商库存)
|
|
|
detailReqVO.setEnableShare(YesOrNoEnum.NO.getType());
|
|
|
- List<VoyageStockDistributeNewRespVO> distributeNewResps = voyageStockDistributeNewService.getDetail(detailReqVO);
|
|
|
+ List<VoyageStockDistributeNewRespVO> distributeNewResps = productRedisUtils.getList(ProductRedisKeyConstants.STOCK_DISTRIBUTOR_REDIS_KEY_PREFIX + voyageId, VoyageStockDistributeNewRespVO.class, 1);
|
|
|
+ if(CollectionUtils.isAnyEmpty(distributeNewResps)) {
|
|
|
+ distributeNewResps = voyageStockDistributeNewService.getDetail(detailReqVO);
|
|
|
+ }
|
|
|
//订单使用房间详情
|
|
|
List<OrderRoomUseDTO> orderRoomList = reqDTO.getOrderRoomList();
|
|
|
Map<String, BigDecimal> roomModelFloorNumMap = orderRoomList.stream()
|
|
|
@@ -569,6 +585,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
stockDO.setBookNum(stockDO.getBookNum().subtract(totalNum));
|
|
|
//更新航次总库存
|
|
|
voyageStockMapper.updateById(stockDO);
|
|
|
+ productRedisUtils.set(ProductRedisKeyConstants.STOCK_TOTAL_REDIS_KEY_PREFIX + voyageId, stockDO);
|
|
|
//删除航次库存操作记录
|
|
|
voyageStockLogMapper.deleteById(voyageStockLogDO);
|
|
|
} else {
|
|
|
@@ -599,6 +616,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
}
|
|
|
});
|
|
|
voyageStockDetailMapper.updateBatch(stockDetailList);
|
|
|
+ productRedisUtils.set(ProductRedisKeyConstants.STOCK_DETAIL_REDIS_KEY_PREFIX + voyageId, stockDetailList);
|
|
|
|
|
|
|
|
|
//2:还分销商库存
|
|
|
@@ -626,6 +644,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
}
|
|
|
});
|
|
|
voyageStockDistributeNewMapper.updateBatch(list);
|
|
|
+ productRedisUtils.set(ProductRedisKeyConstants.STOCK_DISTRIBUTOR_REDIS_KEY_PREFIX + voyageId, list);
|
|
|
}
|
|
|
}
|
|
|
// 删除库存详情初定记录
|
|
|
@@ -667,7 +686,10 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
voyageStockLogDO.setDistributorId(distributorId);
|
|
|
voyageStockLogDO.setStoreId(storeId);
|
|
|
// 获取航次总库存
|
|
|
- VoyageStockDO stockDO = voyageStockMapper.selectById(voyageId);
|
|
|
+ VoyageStockDO stockDO = productRedisUtils.get(ProductRedisKeyConstants.STOCK_TOTAL_REDIS_KEY_PREFIX + voyageId, VoyageStockDO.class, 1);
|
|
|
+ if(stockDO == null) {
|
|
|
+ stockDO = voyageStockMapper.selectById(voyageId);
|
|
|
+ }
|
|
|
if (stockDO == null) {
|
|
|
throw exception(VOYAGE_NO_STOCK);
|
|
|
}
|
|
|
@@ -675,8 +697,10 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
BigDecimal shareNum = stockDO.getShareNum();
|
|
|
|
|
|
//航次库存详情
|
|
|
- List<VoyageStockDetailDO> stockDetailList = voyageStockDetailMapper.selectListByVoyageId(voyageId);
|
|
|
-
|
|
|
+ List<VoyageStockDetailDO> stockDetailList = productRedisUtils.getList(ProductRedisKeyConstants.STOCK_DETAIL_REDIS_KEY_PREFIX + voyageId, VoyageStockDetailDO.class, 1);
|
|
|
+ if(CollectionUtils.isAnyEmpty(stockDetailList)) {
|
|
|
+ stockDetailList = voyageStockDetailMapper.selectListByVoyageId(voyageId);
|
|
|
+ }
|
|
|
//判断分销商库存是否存在
|
|
|
VoyageStockDistributeNewDetailReqVO detailReqVO = new VoyageStockDistributeNewDetailReqVO();
|
|
|
detailReqVO.setVoyageId(voyageId);
|
|
|
@@ -684,7 +708,10 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
detailReqVO.setObjectId(distributorId);
|
|
|
//先获取非共享库存(分销商库存)
|
|
|
detailReqVO.setEnableShare(YesOrNoEnum.NO.getType());
|
|
|
- List<VoyageStockDistributeNewRespVO> distributeNewRespList = voyageStockDistributeNewService.getDetail(detailReqVO);
|
|
|
+ List<VoyageStockDistributeNewRespVO> distributeNewRespList = productRedisUtils.getList(ProductRedisKeyConstants.STOCK_DISTRIBUTOR_REDIS_KEY_PREFIX + voyageId, VoyageStockDistributeNewRespVO.class, 1);
|
|
|
+ if(CollectionUtils.isAnyEmpty(distributeNewRespList)) {
|
|
|
+ distributeNewRespList = voyageStockDistributeNewService.getDetail(detailReqVO);
|
|
|
+ }
|
|
|
//订单使用房间详情
|
|
|
List<OrderRoomUseDTO> orderRoomList = reqDTO.getOrderRoomList();
|
|
|
Map<String, BigDecimal> roomModelFloorNumMap = orderRoomList.stream()
|