|
|
@@ -184,6 +184,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ log.error("开始确定订单扣库存异常:{}", e.getMessage());
|
|
|
throw e;
|
|
|
} finally {
|
|
|
if (lock.isHeldByCurrentThread() && lock.isLocked()) {
|
|
|
@@ -247,6 +248,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
+ log.error("取消订单还库存异常:{}", e.getMessage());
|
|
|
e.printStackTrace();
|
|
|
}finally {
|
|
|
if (lock.isHeldByCurrentThread() && lock.isLocked()) {
|
|
|
@@ -263,7 +265,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
if (orderId == null) {
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
+ log.info("开始确定订单还库存:订单ID:{}", orderId);
|
|
|
//退还航次总库存
|
|
|
//找到确定时扣库存的记录
|
|
|
VoyageStockLogDO voyageStockLogDO = voyageStockLogMapper.selectByOrder(orderId);
|
|
|
@@ -271,8 +273,10 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
//删除已使用房间记录
|
|
|
voyageStockRoomUsedMapper.deleteByOrderId(orderId);
|
|
|
Long voyageId = voyageStockLogDO.getVoyageId();
|
|
|
+ log.info("开始确定订单还库存:航次ID:{}", voyageId);
|
|
|
// 获取航次总库存
|
|
|
VoyageStockDO stockDO = voyageStockMapper.selectById(voyageId);
|
|
|
+ log.info("开始确定订单还库存:退还前总库存:{}", JSONObject.toJSONString(stockDO));
|
|
|
//还航次总库存
|
|
|
BigDecimal totalNum = voyageStockLogDO.getVirtualNum().add(voyageStockLogDO.getRealNum());
|
|
|
if (voyageStockLogDO.getStockType() != null && voyageStockLogDO.getStockType() == 1) {
|
|
|
@@ -289,6 +293,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
stockDO.setCanSellNum(stockDO.getCanSellNum().add(totalNum));
|
|
|
// 减去已预订数量
|
|
|
stockDO.setBookNum(stockDO.getBookNum().subtract(totalNum));
|
|
|
+ log.info("开始确定订单还库存:退还后总库存:{}", JSONObject.toJSONString(stockDO));
|
|
|
//更新航次总库存
|
|
|
voyageStockMapper.updateById(stockDO);
|
|
|
productRedisUtils.set(ProductRedisKeyConstants.STOCK_TOTAL_REDIS_KEY_PREFIX + voyageId + "_" + uuid, stockDO);
|
|
|
@@ -306,6 +311,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
Integer stockType = detailLogList.get(0).getStockType();
|
|
|
//退还航次库存详情
|
|
|
List<VoyageStockDetailDO> 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);
|
|
|
// Map<String, BigDecimal> shareNumMap = CollectionUtils.convertMap(detailLogList, item -> item.getRoomModelId() + "_" + item.getFloor(), VoyageStockDetailLogDO::getShareNum);
|
|
|
@@ -313,6 +319,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
|
|
|
stockDetailList.forEach(item -> {
|
|
|
String key = item.getRoomModelId() + "_" + item.getFloor();
|
|
|
+
|
|
|
BigDecimal totalNum = totalNumMap.get(key);
|
|
|
if (totalNum == null) {
|
|
|
totalNum = BigDecimal.ZERO;
|
|
|
@@ -325,6 +332,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
if (virtualNum == null) {
|
|
|
virtualNum = BigDecimal.ZERO;
|
|
|
}
|
|
|
+ log.info("开始确定订单还库存:退还房型:{},退还楼层:{},退还数量:{}",item.getRoomModelId(),item.getFloor(),totalNum);
|
|
|
item.setBookNum(item.getBookNum().subtract(totalNum));
|
|
|
item.setCanSellNum(item.getCanSellNum().add(totalNum));
|
|
|
item.setRealTotalNum(item.getRealTotalNum().add(realNum));
|
|
|
@@ -337,6 +345,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
item.setShareNum(item.getShareNum().add(totalNum));
|
|
|
}
|
|
|
});
|
|
|
+ log.info("开始确定订单还库存:退还后库存详情:{}", JSONObject.toJSONString(stockDetailList));
|
|
|
voyageStockDetailMapper.updateBatch(stockDetailList);
|
|
|
productRedisUtils.set(ProductRedisKeyConstants.STOCK_DETAIL_REDIS_KEY_PREFIX + voyageId + "_" + uuid, stockDetailList);
|
|
|
|
|
|
@@ -350,12 +359,14 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
detailReqVO.setDistributorId(distributorId);
|
|
|
List<VoyageStockDistributeNewRespVO> distributeNewResp = voyageStockDistributeNewService.getDetail(detailReqVO);
|
|
|
List<VoyageStockDistributeNewDO> list = BeanUtils.toBean(distributeNewResp, VoyageStockDistributeNewDO.class);
|
|
|
+ log.info("开始确定订单还库存:退还前分销商库存:{}", JSONObject.toJSONString(list));
|
|
|
if (list != null && !list.isEmpty()) {
|
|
|
list.forEach(item -> {
|
|
|
String key = item.getRoomModelId() + "_" + item.getFloor();
|
|
|
item.setNum(item.getNum().add(totalNumMap.get(key)));
|
|
|
item.setBookNum(item.getBookNum() == null ? BigDecimal.ZERO : item.getBookNum().subtract(totalNumMap.get(key)));
|
|
|
});
|
|
|
+ log.info("开始确定订单还库存:退还后分销商库存:{}", JSONObject.toJSONString(list));
|
|
|
voyageStockDistributeNewMapper.updateBatch(list);
|
|
|
productRedisUtils.set(ProductRedisKeyConstants.STOCK_DISTRIBUTOR_REDIS_KEY_PREFIX + voyageId + "_" + distributorId + "_" + uuid, list);
|
|
|
}
|
|
|
@@ -378,12 +389,14 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
Integer type = reqDTO.getType();
|
|
|
//航次ID
|
|
|
Long voyageId = reqDTO.getVoyageId();
|
|
|
+ log.info("开始确定订单扣库存:航次ID:{}", voyageId);
|
|
|
//分销商ID
|
|
|
Long distributorId = reqDTO.getDistributorId();
|
|
|
//门店ID
|
|
|
Long storeId = reqDTO.getStoreId();
|
|
|
//总共使用房间数量
|
|
|
BigDecimal totalUseNum = reqDTO.getUseRoomNum();
|
|
|
+ log.info("开始确定订单扣库存:总共使用房间数量:{}", totalUseNum);
|
|
|
Long orderId = reqDTO.getOrderId();
|
|
|
Integer orderStatus = reqDTO.getOrderStatus();
|
|
|
|
|
|
@@ -400,6 +413,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
if (stockDO == null) {
|
|
|
stockDO = voyageStockMapper.selectById(voyageId);
|
|
|
}
|
|
|
+ log.info("开始确定订单扣库存:扣减前航次总库存:{}", JSONObject.toJSONString(stockDO));
|
|
|
if (stockDO == null) {
|
|
|
throw exception(VOYAGE_NO_STOCK);
|
|
|
}
|
|
|
@@ -413,6 +427,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
if (CollectionUtils.isAnyEmpty(stockDetailList)) {
|
|
|
stockDetailList = voyageStockDetailMapper.selectListByVoyageId(voyageId);
|
|
|
}
|
|
|
+ log.info("开始确定订单扣库存:扣减前航次库存详情:{}", JSONObject.toJSONString(stockDetailList));
|
|
|
//判断分销商库存是否存在
|
|
|
VoyageStockDistributeNewDetailReqVO detailReqVO = new VoyageStockDistributeNewDetailReqVO();
|
|
|
detailReqVO.setVoyageId(voyageId);
|
|
|
@@ -424,6 +439,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
if (CollectionUtils.isAnyEmpty(distributeNewResps)) {
|
|
|
distributeNewResps = voyageStockDistributeNewService.getDetail(detailReqVO);
|
|
|
}
|
|
|
+ log.info("开始确定订单扣库存:扣减前分销商库存:{}", JSONObject.toJSONString(distributeNewResps));
|
|
|
//订单使用房间详情
|
|
|
List<OrderRoomUseDTO> orderRoomList = reqDTO.getOrderRoomList();
|
|
|
Map<String, BigDecimal> roomModelFloorNumMap = orderRoomList.stream()
|
|
|
@@ -434,9 +450,12 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
));
|
|
|
//分销商未分配库存,扣共享库存
|
|
|
if (CollectionUtils.isAnyEmpty(distributeNewResps)) {
|
|
|
+ log.info("开始确定订单扣库存-分销商未分配库存,扣共享库存");
|
|
|
+
|
|
|
//1共享库存
|
|
|
voyageStockLogDO.setStockType(1);
|
|
|
//判断共享库存是否充足
|
|
|
+ log.info("开始确定订单扣库存-分销商未分配库存,扣共享库存-共享库存:{},总共使用房间数量:{}", shareNum, totalUseNum);
|
|
|
if (shareNum.compareTo(totalUseNum) < 0) {
|
|
|
log.error("{}", String.format(VOYAGE_SHARE_STOCK_NOT_ENOUGH.getMsg(), shareNum, totalUseNum));
|
|
|
throw exception0(VOYAGE_SHARE_STOCK_NOT_ENOUGH.getCode(), String.format(VOYAGE_SHARE_STOCK_NOT_ENOUGH.getMsg(), shareNum, totalUseNum));
|
|
|
@@ -450,6 +469,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
if (useNum == null) {
|
|
|
useNum = BigDecimal.ZERO;
|
|
|
}
|
|
|
+ log.info("开始确定订单扣库存-分销商未分配库存,扣共享库存-房型:{},楼层:{},共享库存:{},总共使用房间数量:{}", item.getRoomModelName(), item.getFloor(),detailShareNum, useNum);
|
|
|
if (detailShareNum.compareTo(useNum) < 0) {
|
|
|
log.error("{}", String.format(VOYAGE_SHARE_ROOM_NOT_ENOUGH.getMsg(), item.getRoomModelName(), item.getFloor(), detailShareNum, useNum));
|
|
|
throw exception0(VOYAGE_SHARE_ROOM_NOT_ENOUGH.getCode(), String.format(VOYAGE_SHARE_ROOM_NOT_ENOUGH.getMsg(), item.getRoomModelName(), item.getFloor(), detailShareNum, useNum));
|
|
|
@@ -513,6 +533,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
|
|
|
|
|
|
});
|
|
|
+ log.info("开始确定订单扣库存-分销商未分配库存,扣共享库存-扣减后航次库存详情:{}", JSONObject.toJSONString(stockDetailList));
|
|
|
voyageStockDetailMapper.updateBatch(stockDetailList);
|
|
|
|
|
|
// 扣总库存
|
|
|
@@ -546,8 +567,10 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
// 扣共享库存
|
|
|
stockDO.setShareNum(stockDO.getShareNum().subtract(totalUseNum));
|
|
|
voyageStockLogDO.setShareNum(totalUseNum);
|
|
|
+ log.info("开始确定订单扣库存-分销商未分配库存,扣共享库存-扣减后航次总库存:{}", JSONObject.toJSONString(stockDO));
|
|
|
voyageStockMapper.updateById(stockDO);
|
|
|
} else {
|
|
|
+ log.info("开始确定订单扣库存-分销商已分配库存,扣分销商库存");
|
|
|
//2分销商库存
|
|
|
voyageStockLogDO.setStockType(2);
|
|
|
|
|
|
@@ -560,6 +583,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
if (useNum == null) {
|
|
|
useNum = BigDecimal.ZERO;
|
|
|
}
|
|
|
+ log.info("开始确定订单扣库存-分销商已分配库存,扣分销商库存-房型:{},楼层:{},分销商库存:{},总共使用房间数量:{}", item.getRoomModelName(), item.getFloor(),canSellNum, useNum);
|
|
|
if (canSellNum.compareTo(useNum) < 0) {
|
|
|
log.error("{}", String.format(VOYAGE_DISTRIBUTOR_ROOM_NOT_ENOUGH.getMsg(), item.getRoomModelName(), item.getFloor(), canSellNum, useNum));
|
|
|
throw exception0(VOYAGE_DISTRIBUTOR_ROOM_NOT_ENOUGH.getCode(), String.format(VOYAGE_DISTRIBUTOR_ROOM_NOT_ENOUGH.getMsg(), item.getRoomModelName(), item.getFloor(), canSellNum, useNum));
|
|
|
@@ -582,6 +606,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
item.setBookNum(useNum);
|
|
|
}
|
|
|
});
|
|
|
+ log.info("开始确定订单扣库存-分销商已分配库存,扣分销商库存-扣减后分销商库存:{}", JSONObject.toJSONString(list));
|
|
|
|
|
|
voyageStockDistributeNewMapper.updateBatch(list);
|
|
|
|
|
|
@@ -640,6 +665,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
detailLogList.add(voyageStockDetailLogDO);
|
|
|
|
|
|
});
|
|
|
+ log.info("开始确定订单扣库存-分销商已分配库存,扣分销商库存-扣减后航次库存详情:{}", JSONObject.toJSONString(stockDetailList));
|
|
|
voyageStockDetailMapper.updateBatch(stockDetailList);
|
|
|
|
|
|
// 扣总库存
|
|
|
@@ -674,6 +700,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
stockDO.setBookNum(stockDO.getBookNum().add(totalUseNum));
|
|
|
// 扣共享库存,此处为分销商库存,不扣共享库存
|
|
|
voyageStockLogDO.setShareNum(BigDecimal.ZERO);
|
|
|
+ log.info("开始确定订单扣库存-分销商已分配库存,扣分销商库存-扣减后航次总库存:{}", JSONObject.toJSONString(stockDO));
|
|
|
voyageStockMapper.updateById(stockDO);
|
|
|
}
|
|
|
// 添加房间使用记录
|
|
|
@@ -842,6 +869,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
Integer type = reqDTO.getType();
|
|
|
//航次ID
|
|
|
Long voyageId = reqDTO.getVoyageId();
|
|
|
+ log.info("进入初定扣库存操作:航次ID:{}", voyageId);
|
|
|
//分销商ID
|
|
|
Long distributorId = reqDTO.getDistributorId();
|
|
|
//门店ID
|