|
|
@@ -547,12 +547,18 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
VoyageStockDO stockDO = voyageStockMapper.selectById(voyageId);
|
|
|
//还航次总库存
|
|
|
BigDecimal totalNum = voyageStockLogDO.getVirtualNum().add(voyageStockLogDO.getRealNum());
|
|
|
- stockDO.setShareNum(stockDO.getShareNum().add(voyageStockLogDO.getShareNum())); //退回共享库存
|
|
|
- stockDO.setVirtualNum(stockDO.getVirtualNum().add(voyageStockLogDO.getVirtualNum())); //退回虚拟库存
|
|
|
- stockDO.setRealTotalNum(stockDO.getRealTotalNum().add(voyageStockLogDO.getRealNum())); //退回真实库存
|
|
|
- stockDO.setCanSellNum(stockDO.getCanSellNum().add(totalNum)); //退回可售库存
|
|
|
- stockDO.setBookNum(stockDO.getBookNum().subtract(totalNum)); // 减去已预订数量
|
|
|
- voyageStockMapper.updateById(stockDO);//更新航次总库存
|
|
|
+ //退回共享库存
|
|
|
+ stockDO.setShareNum(stockDO.getShareNum().add(voyageStockLogDO.getShareNum()));
|
|
|
+ //退回虚拟库存
|
|
|
+ stockDO.setVirtualNum(stockDO.getVirtualNum().add(voyageStockLogDO.getVirtualNum()));
|
|
|
+ //退回真实库存
|
|
|
+ stockDO.setRealTotalNum(stockDO.getRealTotalNum().add(voyageStockLogDO.getRealNum()));
|
|
|
+ //退回可售库存
|
|
|
+ stockDO.setCanSellNum(stockDO.getCanSellNum().add(totalNum));
|
|
|
+ // 减去已预订数量
|
|
|
+ stockDO.setBookNum(stockDO.getBookNum().subtract(totalNum));
|
|
|
+ //更新航次总库存
|
|
|
+ voyageStockMapper.updateById(stockDO);
|
|
|
//删除航次库存操作记录
|
|
|
voyageStockLogMapper.deleteById(voyageStockLogDO);
|
|
|
} else {
|
|
|
@@ -567,7 +573,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
//退还航次库存详情
|
|
|
List<VoyageStockDetailDO> 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> 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);
|
|
|
Map<String, BigDecimal> totalNumMap = CollectionUtils.convertMap(detailLogList, item -> item.getRoomModelId() + "_" + item.getFloor(), item -> item.getRealNum().add(item.getVirtualNum()));
|
|
|
|
|
|
@@ -576,20 +582,20 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
item.setBookNum(item.getBookNum().subtract(totalNumMap.get(key)));
|
|
|
item.setCanSellNum(item.getCanSellNum().add(totalNumMap.get(key)));
|
|
|
item.setRealTotalNum(item.getRealTotalNum().add(realNumMap.get(key)));
|
|
|
- item.setVirtualNum(item.getVirtualNum().add(VirtualNumMap.get(key)));
|
|
|
+ item.setVirtualNum(item.getVirtualNum().add(virtualNumMap.get(key)));
|
|
|
});
|
|
|
voyageStockDetailMapper.updateBatch(stockDetailList);
|
|
|
|
|
|
Integer stockType = detailLogList.get(0).getStockType();
|
|
|
-
|
|
|
- if (stockType == 2) { //2:还分销商库存
|
|
|
+ //2:还分销商库存
|
|
|
+ if (stockType == 2) {
|
|
|
//判断分销商库存是否存在
|
|
|
VoyageStockDistributeNewDetailReqVO detailReqVO = new VoyageStockDistributeNewDetailReqVO();
|
|
|
detailReqVO.setVoyageId(voyageId);
|
|
|
detailReqVO.setType(type);
|
|
|
detailReqVO.setObjectId(distributorId);
|
|
|
- List<VoyageStockDistributeNewRespVO> distributeNewRespVOS = voyageStockDistributeNewService.getDetail(detailReqVO);
|
|
|
- List<VoyageStockDistributeNewDO> list = BeanUtils.toBean(distributeNewRespVOS, VoyageStockDistributeNewDO.class);
|
|
|
+ List<VoyageStockDistributeNewRespVO> distributeNewRespList = voyageStockDistributeNewService.getDetail(detailReqVO);
|
|
|
+ List<VoyageStockDistributeNewDO> list = BeanUtils.toBean(distributeNewRespList, VoyageStockDistributeNewDO.class);
|
|
|
if (list != null && !list.isEmpty()) {
|
|
|
list.forEach(item -> {
|
|
|
String key = item.getRoomModelId() + "_" + item.getFloor();
|
|
|
@@ -610,7 +616,6 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
/**
|
|
|
* 初定扣分销商库存
|
|
|
*
|
|
|
- * @param reqDTO
|
|
|
*/
|
|
|
private void preReduceStockDistributor(ReduceStockReqDTO reqDTO) {
|
|
|
//航次库存操作日志
|
|
|
@@ -619,15 +624,20 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
List<VoyageStockDetailLogDO> detailLogList = new ArrayList<>();
|
|
|
|
|
|
Integer type = reqDTO.getType();
|
|
|
- Long voyageId = reqDTO.getVoyageId(); //航次ID
|
|
|
- Long distributorId = reqDTO.getDistributorId(); //分销商ID
|
|
|
- Long storeId = reqDTO.getStoreId(); //门店ID
|
|
|
- BigDecimal totalUseNum = reqDTO.getUseRoomNum(); //总共使用房间数量
|
|
|
+ //航次ID
|
|
|
+ Long voyageId = reqDTO.getVoyageId();
|
|
|
+ //分销商ID
|
|
|
+ Long distributorId = reqDTO.getDistributorId();
|
|
|
+ //门店ID
|
|
|
+ Long storeId = reqDTO.getStoreId();
|
|
|
+ //总共使用房间数量
|
|
|
+ BigDecimal totalUseNum = reqDTO.getUseRoomNum();
|
|
|
Long orderId = reqDTO.getOrderId();
|
|
|
Integer orderStatus = reqDTO.getOrderStatus();
|
|
|
|
|
|
voyageStockLogDO.setVoyageId(voyageId);
|
|
|
- voyageStockLogDO.setType(2);//标识减少
|
|
|
+ //标识减少
|
|
|
+ voyageStockLogDO.setType(2);
|
|
|
voyageStockLogDO.setOrderId(orderId);
|
|
|
voyageStockLogDO.setOrderStatus(orderStatus);
|
|
|
voyageStockLogDO.setOperateType(VoyageStockLogTypeEnum.ORDER_PRE_SUB.getValue());
|
|
|
@@ -649,16 +659,21 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
detailReqVO.setVoyageId(voyageId);
|
|
|
detailReqVO.setType(type);
|
|
|
detailReqVO.setObjectId(distributorId);
|
|
|
- detailReqVO.setEnableShare(YesOrNoEnum.NO.getType());//先获取非共享库存(分销商库存)
|
|
|
- List<VoyageStockDistributeNewRespVO> distributeNewRespVOS = voyageStockDistributeNewService.getDetail(detailReqVO);
|
|
|
- List<OrderRoomUseDTO> orderRoomList = reqDTO.getOrderRoomList();//订单使用房间详情
|
|
|
+ //先获取非共享库存(分销商库存)
|
|
|
+ detailReqVO.setEnableShare(YesOrNoEnum.NO.getType());
|
|
|
+ List<VoyageStockDistributeNewRespVO> distributeNewRespList = voyageStockDistributeNewService.getDetail(detailReqVO);
|
|
|
+ //订单使用房间详情
|
|
|
+ List<OrderRoomUseDTO> orderRoomList = reqDTO.getOrderRoomList();
|
|
|
Map<String, BigDecimal> roomModelFloorNumMap = orderRoomList.stream()
|
|
|
.collect(Collectors.groupingBy(
|
|
|
OrderRoomUseDTO::getKey,
|
|
|
- Collectors.mapping(OrderRoomUseDTO::getNum, Collectors.reducing(BigDecimal.ZERO, BigDecimal::add)) // 直接使用BigDecimal的reduce操作进行求和
|
|
|
+ // 直接使用BigDecimal的reduce操作进行求和
|
|
|
+ Collectors.mapping(OrderRoomUseDTO::getNum, Collectors.reducing(BigDecimal.ZERO, BigDecimal::add))
|
|
|
));
|
|
|
- if (distributeNewRespVOS.isEmpty()) {//分销商未分配库存,扣共享库存
|
|
|
- voyageStockLogDO.setStockType(1); //1共享库存
|
|
|
+ //分销商未分配库存,扣共享库存
|
|
|
+ if (distributeNewRespList.isEmpty()) {
|
|
|
+ //1共享库存
|
|
|
+ voyageStockLogDO.setStockType(1);
|
|
|
//判断共享库存是否充足
|
|
|
if (shareNum.compareTo(totalUseNum) < 0) {
|
|
|
throw exception(VOYAGE_SHARE_STOCK_NOT_ENOUGH);
|
|
|
@@ -719,7 +734,6 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
|
|
|
detailLogList.add(voyageStockDetailLogDO);
|
|
|
|
|
|
-
|
|
|
});
|
|
|
voyageStockDetailMapper.updateBatch(stockDetailList);
|
|
|
|
|
|
@@ -745,13 +759,12 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
voyageStockLogDO.setShareNum(totalUseNum);
|
|
|
voyageStockMapper.updateById(stockDO);
|
|
|
} else {
|
|
|
-
|
|
|
- voyageStockLogDO.setStockType(2); //2分销商库存
|
|
|
-
|
|
|
+ //2分销商库存
|
|
|
+ voyageStockLogDO.setStockType(2);
|
|
|
//分销商已分配库存,扣自身库存
|
|
|
|
|
|
//判断航次房型楼层库存是否充足
|
|
|
- distributeNewRespVOS.forEach(item -> {
|
|
|
+ distributeNewRespList.forEach(item -> {
|
|
|
BigDecimal canSellNum = item.getNum();
|
|
|
BigDecimal useNum = roomModelFloorNumMap.get(item.getRoomModelId() + "_" + item.getFloor());
|
|
|
if (useNum == null) {
|
|
|
@@ -763,7 +776,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
});
|
|
|
// 扣分销商库存
|
|
|
// 库存充足,扣库存详情
|
|
|
- List<VoyageStockDistributeNewDO> list = BeanUtils.toBean(distributeNewRespVOS, VoyageStockDistributeNewDO.class);
|
|
|
+ List<VoyageStockDistributeNewDO> list = BeanUtils.toBean(distributeNewRespList, VoyageStockDistributeNewDO.class);
|
|
|
list.forEach(item -> {
|
|
|
BigDecimal useNum = roomModelFloorNumMap.get(item.getRoomModelId() + "_" + item.getFloor());
|
|
|
if (useNum == null) {
|