|
|
@@ -27,6 +27,7 @@ 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.dal.redis.RedisKeyConstants;
|
|
|
import com.yc.ship.module.trade.enums.TradeOrderStatusEnum;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import me.zhyd.oauth.utils.UuidUtils;
|
|
|
@@ -98,7 +99,6 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
//用来控制redis缓存
|
|
|
try {
|
|
|
lock.lock(60, TimeUnit.SECONDS);
|
|
|
- String uuid = UuidUtils.getUUID();
|
|
|
//判断是分销商还是门店下单 1:分销商,2:门店
|
|
|
Integer type = reqDTO.getType();
|
|
|
//分销商下单,当前阶段不考虑门店下单
|
|
|
@@ -106,14 +106,14 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
//分销商下单只扣分销商库存,默认是OTA,默认OTC只能门店下单
|
|
|
//初定扣分销商库存
|
|
|
//先返还初定扣的库存,使用修改前一步订单的 ID
|
|
|
- preCancelReduceStockDistributor(reqDTO.getOrderId(), reqDTO.getType(),reqDTO.getOrderRoomList(), uuid);
|
|
|
+ preCancelReduceStockDistributor(reqDTO.getOrderId(), reqDTO.getType(),reqDTO.getOrderRoomList());
|
|
|
log.info("先还该订单的库存-orderId: {}", reqDTO.getOrderId());
|
|
|
if (reqDTO.getOldOrderId() != null && !reqDTO.getOldOrderId().equals(reqDTO.getOrderId())) {
|
|
|
log.info("如果是修改就还修改前的订单的库存-oldOrderId: {}", reqDTO.getOldOrderId());
|
|
|
- preCancelReduceStockDistributor(reqDTO.getOldOrderId(), reqDTO.getType(),reqDTO.getOrderRoomList(), uuid);
|
|
|
+ preCancelReduceStockDistributor(reqDTO.getOldOrderId(), reqDTO.getType(),reqDTO.getOrderRoomList());
|
|
|
}
|
|
|
//再去扣初定的库存
|
|
|
- preReduceStockDistributor(reqDTO, uuid);
|
|
|
+ preReduceStockDistributor(reqDTO);
|
|
|
}
|
|
|
} finally {
|
|
|
if (lock.isHeldByCurrentThread() && lock.isLocked()) {
|
|
|
@@ -133,16 +133,15 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
RLock lock = redissonClient.getLock(lockKey);
|
|
|
try {
|
|
|
lock.lock(60, TimeUnit.SECONDS);
|
|
|
- String uuid = UuidUtils.getUUID();
|
|
|
//判断是分销商还是门店下单 1:分销商,2:门店
|
|
|
Integer type = reqDTO.getType();
|
|
|
//分销商下单,当前阶段不考虑门店下单
|
|
|
if (Objects.equals(type, DistributorOrStoreEnum.DISTRIBUTOR.getValue())) {
|
|
|
//分销商下单只扣分销商库存,默认是OTA,默认OTC只能门店下单
|
|
|
//初定扣分销商库存
|
|
|
- preCancelReduceStockDistributor(reqDTO.getOrderId(), reqDTO.getType(),reqDTO.getOrderRoomList(), uuid);
|
|
|
+ preCancelReduceStockDistributor(reqDTO.getOrderId(), reqDTO.getType(),reqDTO.getOrderRoomList());
|
|
|
if (reqDTO.getOldOrderId() != null && !reqDTO.getOldOrderId().equals(reqDTO.getOrderId())) {
|
|
|
- preCancelReduceStockDistributor(reqDTO.getOldOrderId(), reqDTO.getType(),reqDTO.getOrderRoomList(), uuid);
|
|
|
+ preCancelReduceStockDistributor(reqDTO.getOldOrderId(), reqDTO.getType(),reqDTO.getOrderRoomList());
|
|
|
}
|
|
|
}
|
|
|
} finally {
|
|
|
@@ -163,7 +162,6 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
RLock lock = redissonClient.getLock(lockKey);
|
|
|
try {
|
|
|
lock.lock(60, TimeUnit.SECONDS);
|
|
|
- String uuid = UuidUtils.getUUID();
|
|
|
//判断是分销商还是门店下单 1:分销商,2:门店
|
|
|
Integer type = reqDTO.getType();
|
|
|
//分销商下单,当前阶段不考虑门店下单
|
|
|
@@ -171,16 +169,16 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
//分销商下单只扣分销商库存,默认是OTA,默认OTC只能门店下单
|
|
|
//初定扣分销商库存
|
|
|
//先返还初定扣的库存
|
|
|
- preCancelReduceStockDistributor(reqDTO.getOrderId(), reqDTO.getType(),reqDTO.getOrderRoomList(), uuid);
|
|
|
+ preCancelReduceStockDistributor(reqDTO.getOrderId(), reqDTO.getType(),reqDTO.getOrderRoomList());
|
|
|
if(reqDTO.getOldOrderId() != null && !reqDTO.getOldOrderId().equals(reqDTO.getOrderId())) {
|
|
|
if(reqDTO.getOldOrderStatus() != null && reqDTO.getOldOrderStatus().equals(TradeOrderStatusEnum.YD.getStatus())) {
|
|
|
- preCancelReduceStockDistributor(reqDTO.getOldOrderId(), reqDTO.getType(),reqDTO.getOrderRoomList(), uuid);
|
|
|
+ preCancelReduceStockDistributor(reqDTO.getOldOrderId(), reqDTO.getType(),reqDTO.getOrderRoomList());
|
|
|
}else {
|
|
|
- cancelReduceStockDistributor(reqDTO.getOldOrderId(), reqDTO.getType(),reqDTO.getOrderRoomList(), uuid);
|
|
|
+ cancelReduceStockDistributor(reqDTO.getOldOrderId(), reqDTO.getType(),reqDTO.getOrderRoomList());
|
|
|
}
|
|
|
}
|
|
|
//再去扣确定的库存
|
|
|
- reduceStockDistributor(reqDTO, uuid);
|
|
|
+ reduceStockDistributor(reqDTO);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
@@ -205,16 +203,15 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
RLock lock = redissonClient.getLock(lockKey);
|
|
|
try {
|
|
|
lock.lock(60, TimeUnit.SECONDS);
|
|
|
- String uuid = UuidUtils.getUUID();
|
|
|
//判断是分销商还是门店下单 1:分销商,2:门店
|
|
|
Integer type = reqDTO.getType();
|
|
|
//分销商下单,当前阶段不考虑门店下单
|
|
|
if (Objects.equals(type, DistributorOrStoreEnum.DISTRIBUTOR.getValue())) {
|
|
|
//分销商下单只扣分销商库存,默认是OTA,默认OTC只能门店下单
|
|
|
//初定扣分销商库存
|
|
|
- cancelReduceStockDistributor(reqDTO.getOrderId(), reqDTO.getType(),reqDTO.getOrderRoomList(), uuid);
|
|
|
+ cancelReduceStockDistributor(reqDTO.getOrderId(), reqDTO.getType(),reqDTO.getOrderRoomList());
|
|
|
if (reqDTO.getOldOrderId() != null && !reqDTO.getOldOrderId().equals(reqDTO.getOrderId())) {
|
|
|
- cancelReduceStockDistributor(reqDTO.getOldOrderId(), reqDTO.getType(),reqDTO.getOrderRoomList(), uuid);
|
|
|
+ cancelReduceStockDistributor(reqDTO.getOldOrderId(), reqDTO.getType(),reqDTO.getOrderRoomList());
|
|
|
}
|
|
|
}
|
|
|
} finally {
|
|
|
@@ -235,16 +232,15 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
RLock lock = redissonClient.getLock(lockKey);
|
|
|
try {
|
|
|
lock.lock(60, TimeUnit.SECONDS);
|
|
|
- String uuid = UuidUtils.getUUID();
|
|
|
//判断是分销商还是门店下单 1:分销商,2:门店
|
|
|
Integer type = reqDTO.getType();
|
|
|
//分销商下单,当前阶段不考虑门店下单
|
|
|
if (Objects.equals(type, DistributorOrStoreEnum.DISTRIBUTOR.getValue())) {
|
|
|
//分销商下单只扣分销商库存,默认是OTA,默认OTC只能门店下单
|
|
|
//初定扣分销商库存
|
|
|
- cancelReduceStockDistributor(reqDTO.getOrderId(), reqDTO.getType(),reqDTO.getOrderRoomList(), uuid);
|
|
|
+ cancelReduceStockDistributor(reqDTO.getOrderId(), reqDTO.getType(),reqDTO.getOrderRoomList());
|
|
|
if (reqDTO.getOldOrderId() != null && !reqDTO.getOldOrderId().equals(reqDTO.getOrderId())) {
|
|
|
- cancelReduceStockDistributor(reqDTO.getOldOrderId(), reqDTO.getType(),reqDTO.getOrderRoomList(), uuid);
|
|
|
+ cancelReduceStockDistributor(reqDTO.getOldOrderId(), reqDTO.getType(),reqDTO.getOrderRoomList());
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
@@ -261,7 +257,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
* 确定状态时取消订单还库存
|
|
|
* roomUseDTOList 需要退的房间
|
|
|
*/
|
|
|
- private void cancelReduceStockDistributor(Long orderId, Integer type,List<OrderRoomUseDTO> roomUseDTOList, String uuid) {
|
|
|
+ private void cancelReduceStockDistributor(Long orderId, Integer type,List<OrderRoomUseDTO> roomUseDTOList) {
|
|
|
if (orderId == null) {
|
|
|
return;
|
|
|
}
|
|
|
@@ -274,8 +270,12 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
voyageStockRoomUsedMapper.deleteByOrderId(orderId);
|
|
|
Long voyageId = voyageStockLogDO.getVoyageId();
|
|
|
log.info("开始确定订单还库存:航次ID:{}", voyageId);
|
|
|
- // 获取航次总库存
|
|
|
- VoyageStockDO stockDO = voyageStockMapper.selectById(voyageId);
|
|
|
+ // 获取航次总库存, 先查缓存,缓存没有再查数据库
|
|
|
+ VoyageStockDO stockDO = productRedisUtils.get(ProductRedisKeyConstants.STOCK_TOTAL_REDIS_KEY_PREFIX + voyageId, VoyageStockDO.class);
|
|
|
+ if (stockDO == null) {
|
|
|
+ log.info("开始确定订单还库存:缓存没有总库存,开始查询数据库");
|
|
|
+ stockDO = voyageStockMapper.selectById(voyageId);
|
|
|
+ }
|
|
|
log.info("开始确定订单还库存:退还前总库存:{}", JSONObject.toJSONString(stockDO));
|
|
|
//还航次总库存
|
|
|
BigDecimal totalNum = voyageStockLogDO.getVirtualNum().add(voyageStockLogDO.getRealNum());
|
|
|
@@ -296,7 +296,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
log.info("开始确定订单还库存:退还后总库存:{}", JSONObject.toJSONString(stockDO));
|
|
|
//更新航次总库存
|
|
|
voyageStockMapper.updateById(stockDO);
|
|
|
- productRedisUtils.set(ProductRedisKeyConstants.STOCK_TOTAL_REDIS_KEY_PREFIX + voyageId + "_" + uuid, stockDO);
|
|
|
+ productRedisUtils.set(ProductRedisKeyConstants.STOCK_TOTAL_REDIS_KEY_PREFIX + voyageId, stockDO);
|
|
|
//删除航次库存操作记录
|
|
|
voyageStockLogMapper.deleteById(voyageStockLogDO);
|
|
|
} else {
|
|
|
@@ -309,8 +309,11 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
List<VoyageStockDetailLogDO> detailLogList = voyageStockDetailLogMapper.selectListByOrder(orderId);
|
|
|
if (detailLogList != null && !detailLogList.isEmpty()) {
|
|
|
Integer stockType = detailLogList.get(0).getStockType();
|
|
|
- //退还航次库存详情
|
|
|
- List<VoyageStockDetailDO> stockDetailList = voyageStockDetailMapper.selectListByVoyageId(voyageId);
|
|
|
+ //退还航次库存详情, 先查缓存,缓存没有再查数据库
|
|
|
+ List<VoyageStockDetailDO> stockDetailList = productRedisUtils.getList(ProductRedisKeyConstants.STOCK_DETAIL_REDIS_KEY_PREFIX + voyageId, VoyageStockDetailDO.class);
|
|
|
+ if (CollectionUtils.isAnyEmpty(stockDetailList)) {
|
|
|
+ stockDetailList = voyageStockDetailMapper.selectListByVoyageId(voyageId);
|
|
|
+ }
|
|
|
log.info("开始确定订单还库存:退还前库存详情:{}", JSONObject.toJSONString(stockDetailList));
|
|
|
Map<String, BigDecimal> realNumMap = CollectionUtils.convertMap(detailLogList, item -> item.getRoomModelId() + "_" + item.getFloor(), VoyageStockDetailLogDO::getRealNum);
|
|
|
Map<String, BigDecimal> virtualNumMap = CollectionUtils.convertMap(detailLogList, item -> item.getRoomModelId() + "_" + item.getFloor(), VoyageStockDetailLogDO::getVirtualNum);
|
|
|
@@ -347,7 +350,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
});
|
|
|
log.info("开始确定订单还库存:退还后库存详情:{}", JSONObject.toJSONString(stockDetailList));
|
|
|
voyageStockDetailMapper.updateBatch(stockDetailList);
|
|
|
- productRedisUtils.set(ProductRedisKeyConstants.STOCK_DETAIL_REDIS_KEY_PREFIX + voyageId + "_" + uuid, stockDetailList);
|
|
|
+ productRedisUtils.set(ProductRedisKeyConstants.STOCK_DETAIL_REDIS_KEY_PREFIX + voyageId, stockDetailList);
|
|
|
|
|
|
|
|
|
//2:还分销商库存
|
|
|
@@ -357,7 +360,11 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
detailReqVO.setVoyageId(voyageId);
|
|
|
detailReqVO.setType(type);
|
|
|
detailReqVO.setDistributorId(distributorId);
|
|
|
- List<VoyageStockDistributeNewRespVO> distributeNewResp = voyageStockDistributeNewService.getDetail(detailReqVO);
|
|
|
+ // 先查缓存,缓存没有再查数据库
|
|
|
+ List<VoyageStockDistributeNewRespVO> distributeNewResp = productRedisUtils.getList(ProductRedisKeyConstants.STOCK_DISTRIBUTOR_REDIS_KEY_PREFIX + voyageId + "_" + distributorId, VoyageStockDistributeNewRespVO.class);
|
|
|
+ if (CollectionUtils.isAnyEmpty(distributeNewResp)) {
|
|
|
+ distributeNewResp = voyageStockDistributeNewService.getDetail(detailReqVO);
|
|
|
+ }
|
|
|
List<VoyageStockDistributeNewDO> list = BeanUtils.toBean(distributeNewResp, VoyageStockDistributeNewDO.class);
|
|
|
log.info("开始确定订单还库存:退还前分销商库存:{}", JSONObject.toJSONString(list));
|
|
|
if (list != null && !list.isEmpty()) {
|
|
|
@@ -372,7 +379,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
});
|
|
|
log.info("开始确定订单还库存:退还后分销商库存:{}", JSONObject.toJSONString(list));
|
|
|
voyageStockDistributeNewMapper.updateBatch(list);
|
|
|
- productRedisUtils.set(ProductRedisKeyConstants.STOCK_DISTRIBUTOR_REDIS_KEY_PREFIX + voyageId + "_" + distributorId + "_" + uuid, list);
|
|
|
+ productRedisUtils.set(ProductRedisKeyConstants.STOCK_DISTRIBUTOR_REDIS_KEY_PREFIX + voyageId + "_" + distributorId, list);
|
|
|
}
|
|
|
}
|
|
|
// 删除库存详情初定记录
|
|
|
@@ -384,7 +391,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
/**
|
|
|
* 确定时扣库存,有限扣实际库存,不足再扣虚拟库存
|
|
|
*/
|
|
|
- private void reduceStockDistributor(ReduceStockReqDTO reqDTO, String uuid) {
|
|
|
+ private void reduceStockDistributor(ReduceStockReqDTO reqDTO) {
|
|
|
//航次库存操作日志
|
|
|
VoyageStockLogDO voyageStockLogDO = new VoyageStockLogDO();
|
|
|
//航次库存详情操作日志
|
|
|
@@ -413,7 +420,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
voyageStockLogDO.setDistributorId(distributorId);
|
|
|
voyageStockLogDO.setStoreId(storeId);
|
|
|
// 获取航次总库存
|
|
|
- VoyageStockDO stockDO = productRedisUtils.get(ProductRedisKeyConstants.STOCK_TOTAL_REDIS_KEY_PREFIX + voyageId + "_" + uuid, VoyageStockDO.class, 1);
|
|
|
+ VoyageStockDO stockDO = productRedisUtils.get(ProductRedisKeyConstants.STOCK_TOTAL_REDIS_KEY_PREFIX + voyageId, VoyageStockDO.class);
|
|
|
if (stockDO == null) {
|
|
|
stockDO = voyageStockMapper.selectById(voyageId);
|
|
|
}
|
|
|
@@ -427,7 +434,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
|
|
|
//航次库存详情
|
|
|
//航次库存详情
|
|
|
- List<VoyageStockDetailDO> stockDetailList = productRedisUtils.getList(ProductRedisKeyConstants.STOCK_DETAIL_REDIS_KEY_PREFIX + voyageId + "_" + uuid, VoyageStockDetailDO.class, 1);
|
|
|
+ List<VoyageStockDetailDO> stockDetailList = productRedisUtils.getList(ProductRedisKeyConstants.STOCK_DETAIL_REDIS_KEY_PREFIX + voyageId, VoyageStockDetailDO.class);
|
|
|
if (CollectionUtils.isAnyEmpty(stockDetailList)) {
|
|
|
stockDetailList = voyageStockDetailMapper.selectListByVoyageId(voyageId);
|
|
|
}
|
|
|
@@ -439,7 +446,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
detailReqVO.setDistributorId(distributorId);
|
|
|
//先获取非共享库存(分销商库存)
|
|
|
detailReqVO.setEnableShare(YesOrNoEnum.NO.getType());
|
|
|
- List<VoyageStockDistributeNewRespVO> distributeNewResps = productRedisUtils.getList(ProductRedisKeyConstants.STOCK_DISTRIBUTOR_REDIS_KEY_PREFIX + voyageId + "_" + distributorId + "_" + uuid, VoyageStockDistributeNewRespVO.class, 1);
|
|
|
+ List<VoyageStockDistributeNewRespVO> distributeNewResps = productRedisUtils.getList(ProductRedisKeyConstants.STOCK_DISTRIBUTOR_REDIS_KEY_PREFIX + voyageId + "_" + distributorId, VoyageStockDistributeNewRespVO.class);
|
|
|
if (CollectionUtils.isAnyEmpty(distributeNewResps)) {
|
|
|
distributeNewResps = voyageStockDistributeNewService.getDetail(detailReqVO);
|
|
|
}
|
|
|
@@ -539,6 +546,8 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
});
|
|
|
log.info("开始确定订单扣库存-分销商未分配库存,扣共享库存-扣减后航次库存详情:{}", JSONObject.toJSONString(stockDetailList));
|
|
|
voyageStockDetailMapper.updateBatch(stockDetailList);
|
|
|
+ // 设置redis缓存
|
|
|
+ productRedisUtils.set(ProductRedisKeyConstants.STOCK_DETAIL_REDIS_KEY_PREFIX + voyageId, stockDetailList);
|
|
|
|
|
|
// 扣总库存
|
|
|
// 减可售房间数
|
|
|
@@ -573,6 +582,8 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
voyageStockLogDO.setShareNum(totalUseNum);
|
|
|
log.info("开始确定订单扣库存-分销商未分配库存,扣共享库存-扣减后航次总库存:{}", JSONObject.toJSONString(stockDO));
|
|
|
voyageStockMapper.updateById(stockDO);
|
|
|
+ // 设置redis缓存
|
|
|
+ productRedisUtils.set(ProductRedisKeyConstants.STOCK_TOTAL_REDIS_KEY_PREFIX + voyageId, stockDO);
|
|
|
} else {
|
|
|
log.info("开始确定订单扣库存-分销商已分配库存,扣分销商库存");
|
|
|
//2分销商库存
|
|
|
@@ -613,6 +624,8 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
log.info("开始确定订单扣库存-分销商已分配库存,扣分销商库存-扣减后分销商库存:{}", JSONObject.toJSONString(list));
|
|
|
|
|
|
voyageStockDistributeNewMapper.updateBatch(list);
|
|
|
+ // 添加库存详情
|
|
|
+ productRedisUtils.set(ProductRedisKeyConstants.STOCK_DISTRIBUTOR_REDIS_KEY_PREFIX + voyageId + "_" + distributorId, list);
|
|
|
|
|
|
// 库存充足,扣库存详情
|
|
|
//超卖库存
|
|
|
@@ -671,6 +684,8 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
});
|
|
|
log.info("开始确定订单扣库存-分销商已分配库存,扣分销商库存-扣减后航次库存详情:{}", JSONObject.toJSONString(stockDetailList));
|
|
|
voyageStockDetailMapper.updateBatch(stockDetailList);
|
|
|
+ // 设置 redis 缓存
|
|
|
+ productRedisUtils.set(ProductRedisKeyConstants.STOCK_DETAIL_REDIS_KEY_PREFIX + voyageId, stockDetailList);
|
|
|
|
|
|
// 扣总库存
|
|
|
// 减可售房间数
|
|
|
@@ -706,6 +721,8 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
voyageStockLogDO.setShareNum(BigDecimal.ZERO);
|
|
|
log.info("开始确定订单扣库存-分销商已分配库存,扣分销商库存-扣减后航次总库存:{}", JSONObject.toJSONString(stockDO));
|
|
|
voyageStockMapper.updateById(stockDO);
|
|
|
+ // 设置 redis 缓存
|
|
|
+ productRedisUtils.set(ProductRedisKeyConstants.STOCK_TOTAL_REDIS_KEY_PREFIX + voyageId, stockDO);
|
|
|
}
|
|
|
// 添加房间使用记录
|
|
|
List<VoyageStockRoomUsedDO> roomUsedList = new ArrayList<>();
|
|
|
@@ -744,7 +761,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
/**
|
|
|
* 初定取消还分销商库存
|
|
|
*/
|
|
|
- private void preCancelReduceStockDistributor(Long orderId, Integer type,List<OrderRoomUseDTO> orderRoomUseDTOList, String uuid) {
|
|
|
+ private void preCancelReduceStockDistributor(Long orderId, Integer type,List<OrderRoomUseDTO> orderRoomUseDTOList) {
|
|
|
if (orderId == null) {
|
|
|
return;
|
|
|
}
|
|
|
@@ -757,8 +774,11 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
//删除已使用房间记录
|
|
|
voyageStockRoomUsedMapper.deleteByOrderId(orderId);
|
|
|
Long voyageId = voyageStockLogDO.getVoyageId();
|
|
|
- // 获取航次总库存
|
|
|
- VoyageStockDO stockDO = voyageStockMapper.selectById(voyageId);
|
|
|
+ // 获取航次总库存,先从redis获取,如果redis没有,则从数据库获取
|
|
|
+ VoyageStockDO stockDO = productRedisUtils.get(ProductRedisKeyConstants.STOCK_TOTAL_REDIS_KEY_PREFIX + voyageId, VoyageStockDO.class);
|
|
|
+ if (stockDO == null) {
|
|
|
+ stockDO = voyageStockMapper.selectById(voyageId);
|
|
|
+ }
|
|
|
log.info("初定还库存操作-当前航次:{}",stockDO.getVoyageName());
|
|
|
log.info("初定还库存操作-当前航次退回库存前库存:{}",JSONObject.toJSONString(stockDO));
|
|
|
//还航次总库存
|
|
|
@@ -780,7 +800,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
log.info("初定还库存操作-当前航次退回库存后库存:{}",JSONObject.toJSONString(stockDO));
|
|
|
//更新航次总库存
|
|
|
voyageStockMapper.updateById(stockDO);
|
|
|
- productRedisUtils.set(ProductRedisKeyConstants.STOCK_TOTAL_REDIS_KEY_PREFIX + voyageId + "_" + uuid, stockDO);
|
|
|
+ productRedisUtils.set(ProductRedisKeyConstants.STOCK_TOTAL_REDIS_KEY_PREFIX + voyageId, stockDO);
|
|
|
//删除航次库存操作记录
|
|
|
voyageStockLogMapper.deleteById(voyageStockLogDO);
|
|
|
} else {
|
|
|
@@ -797,8 +817,11 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
}
|
|
|
Integer stockType = detailLogList.get(0).getStockType();
|
|
|
log.info("进入初定还库存详情操作,使用库存的记录-detailLogList:{}", JSONArray.toJSONString(detailLogList));
|
|
|
- //退还航次库存详情
|
|
|
- List<VoyageStockDetailDO> stockDetailList = voyageStockDetailMapper.selectListByVoyageId(voyageId);
|
|
|
+ //退还航次库存详情, 先从redis获取,如果redis没有,则从数据库获取
|
|
|
+ List<VoyageStockDetailDO> stockDetailList = productRedisUtils.getList(ProductRedisKeyConstants.STOCK_DETAIL_REDIS_KEY_PREFIX + voyageId, VoyageStockDetailDO.class);
|
|
|
+ if (CollectionUtils.isAnyEmpty(stockDetailList)) {
|
|
|
+ stockDetailList = voyageStockDetailMapper.selectListByVoyageId(voyageId);
|
|
|
+ }
|
|
|
Map<String, BigDecimal> realNumMap = CollectionUtils.convertMap(detailLogList, item -> item.getRoomModelId() + "_" + item.getFloor(), VoyageStockDetailLogDO::getRealNum);
|
|
|
Map<String, BigDecimal> virtualNumMap = CollectionUtils.convertMap(detailLogList, item -> item.getRoomModelId() + "_" + item.getFloor(), VoyageStockDetailLogDO::getVirtualNum);
|
|
|
// Map<String, BigDecimal> shareNumMap = CollectionUtils.convertMap(detailLogList, item -> item.getRoomModelId() + "_" + item.getFloor(), VoyageStockDetailLogDO::getShareNum);
|
|
|
@@ -820,7 +843,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
});
|
|
|
log.info("进入初定还库存详情操作,退还后库存详情-stockDetailList:{}", JSONArray.toJSONString(stockDetailList));
|
|
|
voyageStockDetailMapper.updateBatch(stockDetailList);
|
|
|
- productRedisUtils.set(ProductRedisKeyConstants.STOCK_DETAIL_REDIS_KEY_PREFIX + voyageId + "_" + uuid, stockDetailList);
|
|
|
+ productRedisUtils.set(ProductRedisKeyConstants.STOCK_DETAIL_REDIS_KEY_PREFIX + voyageId, stockDetailList);
|
|
|
|
|
|
|
|
|
//2:还分销商库存
|
|
|
@@ -830,7 +853,10 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
detailReqVO.setVoyageId(voyageId);
|
|
|
detailReqVO.setType(type);
|
|
|
detailReqVO.setDistributorId(distributorId);
|
|
|
- List<VoyageStockDistributeNewRespVO> distributeNewRespList = voyageStockDistributeNewService.getDetail(detailReqVO);
|
|
|
+ List<VoyageStockDistributeNewRespVO> distributeNewRespList = productRedisUtils.getList(ProductRedisKeyConstants.STOCK_DISTRIBUTOR_REDIS_KEY_PREFIX + voyageId + "_" + distributorId, VoyageStockDistributeNewRespVO.class);
|
|
|
+ if (CollectionUtils.isAnyEmpty(distributeNewRespList)) {
|
|
|
+ distributeNewRespList = voyageStockDistributeNewService.getDetail(detailReqVO);
|
|
|
+ }
|
|
|
List<VoyageStockDistributeNewDO> list = BeanUtils.toBean(distributeNewRespList, VoyageStockDistributeNewDO.class);
|
|
|
log.info("进入初定还分销商库存详情操作,分销商库存还之前详情-distributeNewRespList:{}", JSONArray.toJSONString(distributeNewRespList));
|
|
|
if (list != null && !list.isEmpty()) {
|
|
|
@@ -851,7 +877,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
});
|
|
|
log.info("进入初定还分销商库存详情操作,分销商库存还之后详情-distributeNewRespList:{}", JSONArray.toJSONString(distributeNewRespList));
|
|
|
voyageStockDistributeNewMapper.updateBatch(list);
|
|
|
- productRedisUtils.set(ProductRedisKeyConstants.STOCK_DISTRIBUTOR_REDIS_KEY_PREFIX + voyageId + "_" + distributorId + "_" + uuid, list);
|
|
|
+ productRedisUtils.set(ProductRedisKeyConstants.STOCK_DISTRIBUTOR_REDIS_KEY_PREFIX + voyageId + "_" + distributorId, list);
|
|
|
}
|
|
|
}
|
|
|
// 删除库存详情初定记录
|
|
|
@@ -863,7 +889,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
/**
|
|
|
* 初定扣分销商库存
|
|
|
*/
|
|
|
- private void preReduceStockDistributor(ReduceStockReqDTO reqDTO, String uuid) {
|
|
|
+ private void preReduceStockDistributor(ReduceStockReqDTO reqDTO) {
|
|
|
log.info("进入初定扣库存操作-orderId:{}", reqDTO.getOrderId());
|
|
|
//航次库存操作日志
|
|
|
VoyageStockLogDO voyageStockLogDO = new VoyageStockLogDO();
|
|
|
@@ -893,7 +919,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
voyageStockLogDO.setDistributorId(distributorId);
|
|
|
voyageStockLogDO.setStoreId(storeId);
|
|
|
// 获取航次总库存
|
|
|
- VoyageStockDO stockDO = productRedisUtils.get(ProductRedisKeyConstants.STOCK_TOTAL_REDIS_KEY_PREFIX + voyageId + "_" + uuid, VoyageStockDO.class, 1);
|
|
|
+ VoyageStockDO stockDO = productRedisUtils.get(ProductRedisKeyConstants.STOCK_TOTAL_REDIS_KEY_PREFIX + voyageId, VoyageStockDO.class);
|
|
|
if (stockDO == null) {
|
|
|
stockDO = voyageStockMapper.selectById(voyageId);
|
|
|
}
|
|
|
@@ -905,7 +931,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
BigDecimal shareNum = stockDO.getShareNum();
|
|
|
|
|
|
//航次库存详情
|
|
|
- List<VoyageStockDetailDO> stockDetailList = productRedisUtils.getList(ProductRedisKeyConstants.STOCK_DETAIL_REDIS_KEY_PREFIX + voyageId + "_" + uuid, VoyageStockDetailDO.class, 1);
|
|
|
+ List<VoyageStockDetailDO> stockDetailList = productRedisUtils.getList(ProductRedisKeyConstants.STOCK_DETAIL_REDIS_KEY_PREFIX + voyageId, VoyageStockDetailDO.class);
|
|
|
if (CollectionUtils.isAnyEmpty(stockDetailList)) {
|
|
|
stockDetailList = voyageStockDetailMapper.selectListByVoyageId(voyageId);
|
|
|
}
|
|
|
@@ -917,7 +943,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
detailReqVO.setDistributorId(distributorId);
|
|
|
//先获取非共享库存(分销商库存)
|
|
|
detailReqVO.setEnableShare(YesOrNoEnum.NO.getType());
|
|
|
- List<VoyageStockDistributeNewRespVO> distributeNewRespList = productRedisUtils.getList(ProductRedisKeyConstants.STOCK_DISTRIBUTOR_REDIS_KEY_PREFIX + voyageId + "_" + distributorId + "_" + uuid, VoyageStockDistributeNewRespVO.class, 1);
|
|
|
+ List<VoyageStockDistributeNewRespVO> distributeNewRespList = productRedisUtils.getList(ProductRedisKeyConstants.STOCK_DISTRIBUTOR_REDIS_KEY_PREFIX + voyageId + "_" + distributorId, VoyageStockDistributeNewRespVO.class);
|
|
|
if (CollectionUtils.isAnyEmpty(distributeNewRespList)) {
|
|
|
distributeNewRespList = voyageStockDistributeNewService.getDetail(detailReqVO);
|
|
|
}
|
|
|
@@ -1015,6 +1041,8 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
});
|
|
|
log.info("进入初定扣库存操作-分销商未分配库存,扣减共享库存-扣减后航次库存详情:{}",JSONObject.toJSONString(stockDetailList));
|
|
|
voyageStockDetailMapper.updateBatch(stockDetailList);
|
|
|
+ // 设置redis 缓存
|
|
|
+ productRedisUtils.set(ProductRedisKeyConstants.STOCK_DETAIL_REDIS_KEY_PREFIX + voyageId, stockDetailList);
|
|
|
|
|
|
// 扣总库存
|
|
|
// 减可售房间数
|
|
|
@@ -1046,6 +1074,8 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
voyageStockLogDO.setShareNum(totalUseNum);
|
|
|
log.info("进入初定扣库存操作-分销商未分配库存,扣减共享库存-扣减后航次总库存:{}",JSONObject.toJSONString(stockDO));
|
|
|
voyageStockMapper.updateById(stockDO);
|
|
|
+ // 设置redis 缓存
|
|
|
+ productRedisUtils.set(ProductRedisKeyConstants.STOCK_TOTAL_REDIS_KEY_PREFIX + voyageId, stockDO);
|
|
|
} else {
|
|
|
log.info("进入初定扣库存操作-分销商已分配库存,扣减分销商库存");
|
|
|
//2分销商库存
|
|
|
@@ -1084,6 +1114,8 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
});
|
|
|
log.info("进入初定扣库存操作-分销商已分配库存,扣减分销商库存-扣减后分销商航次库存详情:{}",JSONObject.toJSONString(list));
|
|
|
voyageStockDistributeNewMapper.updateBatch(list);
|
|
|
+ // 设置redis 缓存
|
|
|
+ productRedisUtils.set(ProductRedisKeyConstants.STOCK_DISTRIBUTOR_REDIS_KEY_PREFIX + voyageId + "_" + distributorId, list);
|
|
|
|
|
|
// 库存充足,扣库存详情
|
|
|
//使用的实际库存
|
|
|
@@ -1139,6 +1171,8 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
});
|
|
|
log.info("进入初定扣库存操作-分销商已分配库存,扣减分销商库存-扣减后航次库存详情:{}",JSONObject.toJSONString(stockDetailList));
|
|
|
voyageStockDetailMapper.updateBatch(stockDetailList);
|
|
|
+ // 设置redis 缓存
|
|
|
+ productRedisUtils.set(ProductRedisKeyConstants.STOCK_DETAIL_REDIS_KEY_PREFIX + voyageId, stockDetailList);
|
|
|
|
|
|
// 扣总库存
|
|
|
// 减可售房间数
|
|
|
@@ -1171,6 +1205,8 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
voyageStockLogDO.setShareNum(BigDecimal.ZERO);
|
|
|
log.info("进入初定扣库存操作-分销商已分配库存,扣减分销商库存-扣减后航次总库存:{}",JSONObject.toJSONString(stockDO));
|
|
|
voyageStockMapper.updateById(stockDO);
|
|
|
+ // 设置redis 缓存
|
|
|
+ productRedisUtils.set(ProductRedisKeyConstants.STOCK_TOTAL_REDIS_KEY_PREFIX + voyageId, stockDO);
|
|
|
}
|
|
|
// 添加房间使用记录
|
|
|
List<VoyageStockRoomUsedDO> roomUsedList = new ArrayList<>();
|