|
|
@@ -10,10 +10,12 @@ import com.yc.ship.module.product.dal.dataobject.voyagestock.VoyageStockDO;
|
|
|
import com.yc.ship.module.product.dal.dataobject.voyagestock.VoyageStockLogDO;
|
|
|
import com.yc.ship.module.product.dal.dataobject.voyagestock.VoyageStockRoomUsedDO;
|
|
|
import com.yc.ship.module.product.dal.dataobject.voyagestockdetail.VoyageStockDetailDO;
|
|
|
+import com.yc.ship.module.product.dal.dataobject.voyagestockdetail.VoyageStockDetailLogDO;
|
|
|
import com.yc.ship.module.product.dal.dataobject.voyagestockdistribute.VoyageStockDistributeNewDO;
|
|
|
import com.yc.ship.module.product.dal.mysql.voyagestock.VoyageStockLogMapper;
|
|
|
import com.yc.ship.module.product.dal.mysql.voyagestock.VoyageStockMapper;
|
|
|
import com.yc.ship.module.product.dal.mysql.voyagestock.VoyageStockRoomUsedMapper;
|
|
|
+import com.yc.ship.module.product.dal.mysql.voyagestockdetail.VoyageStockDetailLogMapper;
|
|
|
import com.yc.ship.module.product.dal.mysql.voyagestockdetail.VoyageStockDetailMapper;
|
|
|
import com.yc.ship.module.product.dal.mysql.voyagestockdistribute.VoyageStockDistributeNewMapper;
|
|
|
import com.yc.ship.module.product.enums.DistributorOrStoreEnum;
|
|
|
@@ -22,6 +24,7 @@ import com.yc.ship.module.product.framework.lock.ProductRedisKeyConstants;
|
|
|
import com.yc.ship.module.product.service.voyagestockdistribute.VoyageStockDistributeNewService;
|
|
|
import com.yc.ship.module.resource.api.room.RoomApi;
|
|
|
import com.yc.ship.module.resource.api.room.dto.RoomRespDTO;
|
|
|
+import com.yc.ship.module.trade.enums.TradeOrderStatusEnum;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.redisson.api.RLock;
|
|
|
import org.redisson.api.RedissonClient;
|
|
|
@@ -66,6 +69,9 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
@Resource
|
|
|
private VoyageStockLogMapper voyageStockLogMapper;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private VoyageStockDetailLogMapper voyageStockDetailLogMapper;
|
|
|
+
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
public void preReduceStock(ReduceStockReqDTO reqDTO) {
|
|
|
@@ -105,7 +111,7 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
if (type == DistributorOrStoreEnum.DISTRIBUTOR.getValue()) {//分销商下单,当前阶段不考虑门店下单
|
|
|
//分销商下单只扣分销商库存,默认是OTA,默认OTC只能门店下单
|
|
|
//初定扣分销商库存
|
|
|
- preCancelReduceStockDistributor(reqDTO);
|
|
|
+ preCancelReduceStockDistributor(reqDTO.getOrderId(), reqDTO.getType());
|
|
|
}
|
|
|
}finally {
|
|
|
if(lock.isHeldByCurrentThread() && lock.isLocked()){
|
|
|
@@ -116,20 +122,81 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
|
|
|
/**
|
|
|
* 初定取消还分销商库存
|
|
|
- * @param reqDTO
|
|
|
*/
|
|
|
- private void preCancelReduceStockDistributor(ReduceStockReqDTO reqDTO) {
|
|
|
- Integer type = reqDTO.getType();
|
|
|
- Long voyageId = reqDTO.getVoyageId(); //航次ID
|
|
|
- Long distributorId = reqDTO.getDistributorId(); //分销商ID
|
|
|
- Long storeId = reqDTO.getStoreId(); //门店ID
|
|
|
- BigDecimal totalUseNum = reqDTO.getUseRoomNum(); //总共使用房间数量
|
|
|
- Long orderId = reqDTO.getOrderId();
|
|
|
- Integer orderStatus = reqDTO.getOrderStatus();
|
|
|
-
|
|
|
+ private void preCancelReduceStockDistributor(Long orderId, Integer type) {
|
|
|
//删除已使用房间记录
|
|
|
voyageStockRoomUsedMapper.deleteByOrderId(orderId);
|
|
|
|
|
|
+ //退还航次总库存
|
|
|
+ //找到初定时扣库存的记录
|
|
|
+ VoyageStockLogDO voyageStockLogDO = voyageStockLogMapper.selectByOrder(orderId, TradeOrderStatusEnum.YD.getStatus());
|
|
|
+ if(voyageStockLogDO != null){
|
|
|
+ Long voyageId = voyageStockLogDO.getVoyageId();
|
|
|
+ // 获取航次总库存
|
|
|
+ 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);//更新航次总库存
|
|
|
+ //删除航次库存操作记录
|
|
|
+ voyageStockLogMapper.deleteById(voyageStockLogDO);
|
|
|
+ }else {
|
|
|
+ log.error("订单取消时,未找到对应的航次库存操作记录,订单ID:{}", orderId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Long voyageId = voyageStockLogDO.getVoyageId();
|
|
|
+ Long distributorId = voyageStockLogDO.getDistributorId();
|
|
|
+ //找到初定时扣库存详情的记录
|
|
|
+ List<VoyageStockDetailLogDO> detailLogList = voyageStockDetailLogMapper.selectListByOrder(orderId, TradeOrderStatusEnum.YD.getStatus());
|
|
|
+ if(detailLogList != null && detailLogList.size() > 0) {
|
|
|
+ //退还航次库存详情
|
|
|
+ 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> 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()));
|
|
|
+
|
|
|
+ stockDetailList.stream().forEach(item -> {
|
|
|
+ String key = item.getRoomModelId() + "_" + item.getFloor();
|
|
|
+ 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)));
|
|
|
+ });
|
|
|
+ voyageStockDetailMapper.updateBatch(stockDetailList);
|
|
|
+
|
|
|
+ Integer stockType = detailLogList.get(0).getStockType();
|
|
|
+
|
|
|
+ if(stockType == 2) { //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);
|
|
|
+ if(list != null && list.size() > 0) {
|
|
|
+ list.stream().forEach(item -> {
|
|
|
+ String key = item.getRoomModelId() + "_" + item.getFloor();
|
|
|
+ item.setNum(item.getNum().add(totalNumMap.get(key)));
|
|
|
+ item.setBookNum(item.getBookNum().subtract(totalNumMap.get(key)));
|
|
|
+ });
|
|
|
+ voyageStockDistributeNewMapper.updateBatch(list);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 删除库存详情初定记录
|
|
|
+ voyageStockDetailLogMapper.deleteByOrder(orderId, TradeOrderStatusEnum.YD.getStatus());
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -140,6 +207,8 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
private void preReduceStockDistributor(ReduceStockReqDTO reqDTO) {
|
|
|
//航次库存操作日志
|
|
|
VoyageStockLogDO voyageStockLogDO = new VoyageStockLogDO();
|
|
|
+ //航次库存详情操作日志
|
|
|
+ List<VoyageStockDetailLogDO> detailLogList = new ArrayList<>();
|
|
|
|
|
|
Integer type = reqDTO.getType();
|
|
|
Long voyageId = reqDTO.getVoyageId(); //航次ID
|
|
|
@@ -154,7 +223,8 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
voyageStockLogDO.setOrderId(orderId);
|
|
|
voyageStockLogDO.setOrderStatus(orderStatus);
|
|
|
voyageStockLogDO.setOperateType(VoyageStockLogTypeEnum.ORDER_PRE_SUB.getValue());
|
|
|
-
|
|
|
+ voyageStockLogDO.setDistributorId(distributorId);
|
|
|
+ voyageStockLogDO.setStoreId(storeId);
|
|
|
// 获取航次总库存
|
|
|
VoyageStockDO stockDO = voyageStockMapper.selectById(voyageId);
|
|
|
if(stockDO == null) {
|
|
|
@@ -163,7 +233,7 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
//共享库存
|
|
|
BigDecimal shareNum = stockDO.getShareNum();
|
|
|
|
|
|
- ///航次库存详情
|
|
|
+ //航次库存详情
|
|
|
List<VoyageStockDetailDO> stockDetailList = voyageStockDetailMapper.selectListByVoyageId(voyageId);
|
|
|
|
|
|
//判断分销商库存是否存在
|
|
|
@@ -180,6 +250,8 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
item -> item.getRoomModelId() + "_" + item.getFloors(),
|
|
|
item -> roomMap.get(item.getId()) == null ? BigDecimal.ZERO : roomMap.get(item.getId()));
|
|
|
if(distributeNewRespVOS.isEmpty()) {//分销商未分配库存,扣共享库存
|
|
|
+
|
|
|
+ voyageStockLogDO.setStockType(1); //1共享库存
|
|
|
//判断共享库存是否充足
|
|
|
if(shareNum.compareTo(totalUseNum) < 0) {
|
|
|
throw exception(VOYAGE_SHARE_STOCK_NOT_ENOUGH);
|
|
|
@@ -202,12 +274,30 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
if(useNum == null) {
|
|
|
useNum = BigDecimal.ZERO;
|
|
|
}
|
|
|
+ //航次库存详情操作日志
|
|
|
+ VoyageStockDetailLogDO voyageStockDetailLogDO = new VoyageStockDetailLogDO();
|
|
|
+ voyageStockDetailLogDO.setVoyageId(voyageId);
|
|
|
+ voyageStockDetailLogDO.setType(2);//标识减少
|
|
|
+ voyageStockDetailLogDO.setOrderId(orderId);
|
|
|
+ voyageStockDetailLogDO.setOrderStatus(orderStatus);
|
|
|
+ voyageStockDetailLogDO.setOperateType(VoyageStockLogTypeEnum.ORDER_PRE_SUB.getValue());
|
|
|
+ voyageStockDetailLogDO.setRoomModelId(item.getRoomModelId());
|
|
|
+ voyageStockDetailLogDO.setFloor(item.getFloor());
|
|
|
+ voyageStockDetailLogDO.setDistributorId(distributorId);
|
|
|
+ voyageStockDetailLogDO.setStoreId(storeId);
|
|
|
+ voyageStockDetailLogDO.setStockType(1); //1共享库存
|
|
|
+
|
|
|
+
|
|
|
// 减可售房间数
|
|
|
item.setCanSellNum(item.getCanSellNum().subtract(useNum));
|
|
|
// 减虚拟房间数,此处初定,先扣虚拟库存,虚拟库存不足再扣实际库存
|
|
|
if(item.getVirtualNum().compareTo(useNum) >= 0) {
|
|
|
+ voyageStockDetailLogDO.setVirtualNum(useNum);
|
|
|
+ voyageStockDetailLogDO.setRealNum(BigDecimal.ZERO);
|
|
|
item.setVirtualNum(item.getVirtualNum().subtract(useNum));
|
|
|
}else {
|
|
|
+ voyageStockDetailLogDO.setVirtualNum(item.getVirtualNum());
|
|
|
+ voyageStockDetailLogDO.setRealNum(useNum.subtract(item.getVirtualNum()));
|
|
|
item.setVirtualNum(BigDecimal.ZERO);
|
|
|
// 扣实际房间数
|
|
|
item.setRealTotalNum(item.getRealTotalNum().subtract(useNum.subtract(item.getVirtualNum())));
|
|
|
@@ -215,6 +305,9 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
// 加预定房间数
|
|
|
item.setBookNum(item.getBookNum().add(useNum));
|
|
|
|
|
|
+ detailLogList.add(voyageStockDetailLogDO);
|
|
|
+
|
|
|
+
|
|
|
});
|
|
|
voyageStockDetailMapper.updateBatch(stockDetailList);
|
|
|
|
|
|
@@ -240,6 +333,9 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
voyageStockLogDO.setShareNum(totalUseNum);
|
|
|
voyageStockMapper.updateById(stockDO);
|
|
|
}else {
|
|
|
+
|
|
|
+ voyageStockLogDO.setStockType(2); //2分销商库存
|
|
|
+
|
|
|
//分销商已分配库存,扣自身库存
|
|
|
|
|
|
//判断航次房型楼层库存是否充足
|
|
|
@@ -255,15 +351,18 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
});
|
|
|
// 扣分销商库存
|
|
|
// 库存充足,扣库存详情
|
|
|
- distributeNewRespVOS.stream().forEach(item -> {
|
|
|
+ List<VoyageStockDistributeNewDO> list = BeanUtils.toBean(distributeNewRespVOS, VoyageStockDistributeNewDO.class);
|
|
|
+ list.stream().forEach(item -> {
|
|
|
BigDecimal useNum = roomModelFloorNumMap.get(item.getRoomModelId() + "_" + item.getFloor());
|
|
|
if(useNum == null) {
|
|
|
useNum = BigDecimal.ZERO;
|
|
|
}
|
|
|
// 减可售房间数
|
|
|
item.setNum(item.getNum().subtract(useNum));
|
|
|
+ // 加预定房间数
|
|
|
+ item.setBookNum(item.getBookNum().add(useNum));
|
|
|
});
|
|
|
- List<VoyageStockDistributeNewDO> list = BeanUtils.toBean(distributeNewRespVOS, VoyageStockDistributeNewDO.class);
|
|
|
+
|
|
|
voyageStockDistributeNewMapper.updateBatch(list);
|
|
|
|
|
|
// 库存充足,扣库存详情
|
|
|
@@ -272,12 +371,30 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
if(useNum == null) {
|
|
|
useNum = BigDecimal.ZERO;
|
|
|
}
|
|
|
+
|
|
|
+ //航次库存详情操作日志
|
|
|
+ VoyageStockDetailLogDO voyageStockDetailLogDO = new VoyageStockDetailLogDO();
|
|
|
+ voyageStockDetailLogDO.setVoyageId(voyageId);
|
|
|
+ voyageStockDetailLogDO.setType(2);//标识减少
|
|
|
+ voyageStockDetailLogDO.setOrderId(orderId);
|
|
|
+ voyageStockDetailLogDO.setOrderStatus(orderStatus);
|
|
|
+ voyageStockDetailLogDO.setOperateType(VoyageStockLogTypeEnum.ORDER_PRE_SUB.getValue());
|
|
|
+ voyageStockDetailLogDO.setRoomModelId(item.getRoomModelId());
|
|
|
+ voyageStockDetailLogDO.setFloor(item.getFloor());
|
|
|
+ voyageStockDetailLogDO.setDistributorId(distributorId);
|
|
|
+ voyageStockDetailLogDO.setStoreId(storeId);
|
|
|
+ voyageStockDetailLogDO.setStockType(2); //2分销商库存
|
|
|
+
|
|
|
// 减可售房间数
|
|
|
item.setCanSellNum(item.getCanSellNum().subtract(useNum));
|
|
|
// 减虚拟房间数,此处初定,先扣虚拟库存,虚拟库存不足再扣实际库存
|
|
|
if(item.getVirtualNum().compareTo(useNum) >= 0) {
|
|
|
+ voyageStockDetailLogDO.setVirtualNum(useNum);
|
|
|
+ voyageStockDetailLogDO.setRealNum(BigDecimal.ZERO);
|
|
|
item.setVirtualNum(item.getVirtualNum().subtract(useNum));
|
|
|
}else {
|
|
|
+ voyageStockDetailLogDO.setVirtualNum(item.getVirtualNum());
|
|
|
+ voyageStockDetailLogDO.setRealNum(totalUseNum.subtract(item.getVirtualNum()));
|
|
|
item.setVirtualNum(BigDecimal.ZERO);
|
|
|
// 扣实际房间数
|
|
|
item.setRealTotalNum(item.getRealTotalNum().subtract(useNum.subtract(item.getVirtualNum())));
|
|
|
@@ -285,6 +402,8 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
// 加预定房间数
|
|
|
item.setBookNum(item.getBookNum().add(useNum));
|
|
|
|
|
|
+ detailLogList.add(voyageStockDetailLogDO);
|
|
|
+
|
|
|
});
|
|
|
voyageStockDetailMapper.updateBatch(stockDetailList);
|
|
|
|
|
|
@@ -292,7 +411,7 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
// 减可售房间数
|
|
|
stockDO.setCanSellNum(stockDO.getCanSellNum().subtract(totalUseNum));
|
|
|
// 减剩余房间数
|
|
|
- stockDO.setSurplusNum(stockDO.getSurplusNum().subtract(totalUseNum));
|
|
|
+// stockDO.setSurplusNum(stockDO.getSurplusNum().subtract(totalUseNum));
|
|
|
// 减虚拟房间数,此处初定,先扣虚拟库存,虚拟库存不足再扣实际库存
|
|
|
if(stockDO.getVirtualNum().compareTo(totalUseNum) >= 0) {
|
|
|
stockDO.setVirtualNum(stockDO.getVirtualNum().subtract(totalUseNum));
|
|
|
@@ -307,9 +426,8 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
}
|
|
|
// 加预定房间数
|
|
|
stockDO.setBookNum(stockDO.getBookNum().add(totalUseNum));
|
|
|
- // 扣共享库存
|
|
|
- stockDO.setShareNum(stockDO.getShareNum().subtract(totalUseNum));
|
|
|
- voyageStockLogDO.setShareNum(totalUseNum);
|
|
|
+ // 扣共享库存,此处为分销商库存,不扣共享库存
|
|
|
+ voyageStockLogDO.setShareNum(BigDecimal.ZERO);
|
|
|
voyageStockMapper.updateById(stockDO);
|
|
|
}
|
|
|
// 添加房间使用记录
|
|
|
@@ -338,5 +456,9 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
|
|
|
// 添加库存日志
|
|
|
voyageStockLogMapper.insert(voyageStockLogDO);
|
|
|
+ // 添加库存详情日志
|
|
|
+ if(detailLogList.size() > 0) {
|
|
|
+ voyageStockDetailLogMapper.insertBatch(detailLogList);
|
|
|
+ }
|
|
|
}
|
|
|
}
|