|
@@ -8,6 +8,7 @@ import com.yc.ship.module.product.dal.dataobject.voyagestockdistribute.VoyageSto
|
|
|
import com.yc.ship.module.product.dal.mysql.voyagestock.VoyageStockMapper;
|
|
|
import com.yc.ship.module.product.dal.mysql.voyagestockdetail.VoyageStockDetailMapper;
|
|
|
import com.yc.ship.module.product.dal.mysql.voyagestockdistribute.VoyageStockDistributeMapper;
|
|
|
+import com.yc.ship.module.product.enums.DistributorOrStoreEnum;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
@@ -41,87 +42,93 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
// 3.扣分销商类型库存
|
|
|
// 4.扣航次库存,优先扣虚拟库存
|
|
|
|
|
|
- Integer distributorType = reqDTO.getDistributorType();
|
|
|
- Long voyageId = reqDTO.getVoyageId();
|
|
|
- Long distributorId = reqDTO.getDistributorId();
|
|
|
- Long storeId = reqDTO.getStoreId();
|
|
|
+ Integer type = reqDTO.getType();//判断是分销商还是门店下单 1:分销商,2:门店
|
|
|
+ Long voyageId = reqDTO.getVoyageId(); //航次ID
|
|
|
+ Long distributorId = reqDTO.getDistributorId(); //分销商ID
|
|
|
+ Long storeId = reqDTO.getStoreId(); //门店ID
|
|
|
+ List<ReduceStockReqDTO.OrderRoomDTO> orderRoomList = reqDTO.getOrderRoomList();//订单使用房间详情
|
|
|
+
|
|
|
+ if(type == DistributorOrStoreEnum.DISTRIBUTOR.getValue()) {//分销商下单
|
|
|
+ //分销商下单只扣分销商库存,默认是OTA,默认OTC只能门店下单
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
|
|
|
// 1.扣门店库存
|
|
|
// 2.扣分销商库存
|
|
|
// 3.扣分销商类型库存
|
|
|
- List<VoyageStockDistributeDO> distributeDOList = voyageStockDistributeMapper.selectListByVoyageId(voyageId);
|
|
|
- List<ReduceStockReqDTO.OrderDetailReqDTO> orderDetailList = reqDTO.getOrderDetailList();
|
|
|
- Map<String, ReduceStockReqDTO.OrderDetailReqDTO> map = CollectionUtils.convertMap(orderDetailList, item -> {
|
|
|
- String key = distributorType + "_" + distributorId + "_" + storeId + "_" + item.getRoomModelId() + "_" + item.getFloor();
|
|
|
- return key;
|
|
|
- });
|
|
|
- AtomicReference<BigDecimal> totalNum = new AtomicReference<>(BigDecimal.ZERO);
|
|
|
- List<VoyageStockDistributeDO> updateList = new ArrayList<>();
|
|
|
- distributeDOList.stream().forEach(item -> {
|
|
|
- String key = item.getDistributorType() + "_" + item.getDistributorId() + "_" + item.getStoreId() + "_" + item.getRoomModelId() + "_" + item.getFloor();
|
|
|
- ReduceStockReqDTO.OrderDetailReqDTO orderDetailReqDTO = map.get(key);
|
|
|
- if (orderDetailReqDTO != null) {
|
|
|
- item.setSurplusNum(item.getSurplusNum().subtract(orderDetailReqDTO.getNum()));
|
|
|
- item.setBookNum(item.getBookNum().add(orderDetailReqDTO.getNum()));
|
|
|
- updateList.add(item);
|
|
|
- }
|
|
|
- totalNum.updateAndGet(v -> v.add(item.getNum()));
|
|
|
- });
|
|
|
- BigDecimal total = totalNum.get();
|
|
|
- voyageStockDistributeMapper.updateBatch(updateList);
|
|
|
-
|
|
|
- // 4.扣航次库存,优先扣虚拟库存
|
|
|
- VoyageStockDO stockDO = voyageStockMapper.selectById(voyageId);
|
|
|
- //判断可售房间数是否大于等于订单的房间数
|
|
|
- if(stockDO.getCanSellNum().compareTo(total) == -1) {
|
|
|
- throw exception0(500,"可售房间数不足");
|
|
|
- }
|
|
|
- //减虚拟房间数
|
|
|
- if(stockDO.getVirtualNum().compareTo(total) >=0 ) {
|
|
|
- stockDO.setVirtualNum(stockDO.getVirtualNum().subtract(totalNum.get()));
|
|
|
- }else {
|
|
|
- stockDO.setVirtualNum(BigDecimal.ZERO);
|
|
|
- // 加超卖房间数
|
|
|
- stockDO.setOversoldNum(stockDO.getOversoldNum().add(total.subtract(stockDO.getVirtualNum())));
|
|
|
- }
|
|
|
- //减可售房间数
|
|
|
- stockDO.setCanSellNum(stockDO.getCanSellNum().subtract(total));
|
|
|
- //加预定房间数
|
|
|
- stockDO.setBookNum(stockDO.getBookNum().add(total));
|
|
|
- voyageStockMapper.updateById(stockDO);
|
|
|
-
|
|
|
- // 5.扣库存详情
|
|
|
- Map<String, ReduceStockReqDTO.OrderDetailReqDTO> detailMap = CollectionUtils.convertMap(orderDetailList, item -> {
|
|
|
- String key = item.getRoomModelId() + "_" + item.getFloor();
|
|
|
- return key;
|
|
|
- });
|
|
|
- List<VoyageStockDetailDO> stockDetailList = voyageStockDetailMapper.selectListByVoyageId(voyageId);
|
|
|
- List<VoyageStockDetailDO> updateDetailList = new ArrayList<>();
|
|
|
- stockDetailList.stream().forEach(item -> {
|
|
|
- String key = item.getRoomModelId() + "_" + item.getFloor();
|
|
|
- ReduceStockReqDTO.OrderDetailReqDTO orderDetailReqDTO = detailMap.get(key);
|
|
|
- BigDecimal num = orderDetailReqDTO.getNum();
|
|
|
- if (orderDetailReqDTO != null) {
|
|
|
- //判断可售房间数是否大于等于订单的房间数
|
|
|
- if(item.getCanSellNum().compareTo(num) < 0) {
|
|
|
- throw exception0(500,"房型楼层可售房间数不足");
|
|
|
- }
|
|
|
- //减虚拟房间数
|
|
|
- if(item.getVirtualNum().compareTo(num) >= 0) {
|
|
|
- item.setVirtualNum(item.getVirtualNum().subtract(num));
|
|
|
- }else {
|
|
|
- item.setVirtualNum(BigDecimal.ZERO);
|
|
|
- // 加超卖房间数
|
|
|
- item.setOversoldNum(item.getOversoldNum().add(num.subtract(item.getVirtualNum())));
|
|
|
- }
|
|
|
- //减可售房间数
|
|
|
- item.setCanSellNum(item.getCanSellNum().subtract(num));
|
|
|
- //加预定房间数
|
|
|
- item.setBookNum(item.getBookNum().add(num));
|
|
|
- updateDetailList.add(item);
|
|
|
- }
|
|
|
- });
|
|
|
- voyageStockDetailMapper.updateBatch(updateDetailList);
|
|
|
+// List<VoyageStockDistributeDO> distributeDOList = voyageStockDistributeMapper.selectListByVoyageId(voyageId);
|
|
|
+// List<ReduceStockReqDTO.OrderDetailReqDTO> orderDetailList = reqDTO.getOrderDetailList();
|
|
|
+// Map<String, ReduceStockReqDTO.OrderDetailReqDTO> map = CollectionUtils.convertMap(orderDetailList, item -> {
|
|
|
+// String key = distributorType + "_" + distributorId + "_" + storeId + "_" + item.getRoomModelId() + "_" + item.getFloor();
|
|
|
+// return key;
|
|
|
+// });
|
|
|
+// AtomicReference<BigDecimal> totalNum = new AtomicReference<>(BigDecimal.ZERO);
|
|
|
+// List<VoyageStockDistributeDO> updateList = new ArrayList<>();
|
|
|
+// distributeDOList.stream().forEach(item -> {
|
|
|
+// String key = item.getDistributorType() + "_" + item.getDistributorId() + "_" + item.getStoreId() + "_" + item.getRoomModelId() + "_" + item.getFloor();
|
|
|
+// ReduceStockReqDTO.OrderDetailReqDTO orderDetailReqDTO = map.get(key);
|
|
|
+// if (orderDetailReqDTO != null) {
|
|
|
+// item.setSurplusNum(item.getSurplusNum().subtract(orderDetailReqDTO.getNum()));
|
|
|
+// item.setBookNum(item.getBookNum().add(orderDetailReqDTO.getNum()));
|
|
|
+// updateList.add(item);
|
|
|
+// }
|
|
|
+// totalNum.updateAndGet(v -> v.add(item.getNum()));
|
|
|
+// });
|
|
|
+// BigDecimal total = totalNum.get();
|
|
|
+// voyageStockDistributeMapper.updateBatch(updateList);
|
|
|
+//
|
|
|
+// // 4.扣航次库存,优先扣虚拟库存
|
|
|
+// VoyageStockDO stockDO = voyageStockMapper.selectById(voyageId);
|
|
|
+// //判断可售房间数是否大于等于订单的房间数
|
|
|
+// if(stockDO.getCanSellNum().compareTo(total) == -1) {
|
|
|
+// throw exception0(500,"可售房间数不足");
|
|
|
+// }
|
|
|
+// //减虚拟房间数
|
|
|
+// if(stockDO.getVirtualNum().compareTo(total) >=0 ) {
|
|
|
+// stockDO.setVirtualNum(stockDO.getVirtualNum().subtract(totalNum.get()));
|
|
|
+// }else {
|
|
|
+// stockDO.setVirtualNum(BigDecimal.ZERO);
|
|
|
+// // 加超卖房间数
|
|
|
+// stockDO.setOversoldNum(stockDO.getOversoldNum().add(total.subtract(stockDO.getVirtualNum())));
|
|
|
+// }
|
|
|
+// //减可售房间数
|
|
|
+// stockDO.setCanSellNum(stockDO.getCanSellNum().subtract(total));
|
|
|
+// //加预定房间数
|
|
|
+// stockDO.setBookNum(stockDO.getBookNum().add(total));
|
|
|
+// voyageStockMapper.updateById(stockDO);
|
|
|
+//
|
|
|
+// // 5.扣库存详情
|
|
|
+// Map<String, ReduceStockReqDTO.OrderDetailReqDTO> detailMap = CollectionUtils.convertMap(orderDetailList, item -> {
|
|
|
+// String key = item.getRoomModelId() + "_" + item.getFloor();
|
|
|
+// return key;
|
|
|
+// });
|
|
|
+// List<VoyageStockDetailDO> stockDetailList = voyageStockDetailMapper.selectListByVoyageId(voyageId);
|
|
|
+// List<VoyageStockDetailDO> updateDetailList = new ArrayList<>();
|
|
|
+// stockDetailList.stream().forEach(item -> {
|
|
|
+// String key = item.getRoomModelId() + "_" + item.getFloor();
|
|
|
+// ReduceStockReqDTO.OrderDetailReqDTO orderDetailReqDTO = detailMap.get(key);
|
|
|
+// BigDecimal num = orderDetailReqDTO.getNum();
|
|
|
+// if (orderDetailReqDTO != null) {
|
|
|
+// //判断可售房间数是否大于等于订单的房间数
|
|
|
+// if(item.getCanSellNum().compareTo(num) < 0) {
|
|
|
+// throw exception0(500,"房型楼层可售房间数不足");
|
|
|
+// }
|
|
|
+// //减虚拟房间数
|
|
|
+// if(item.getVirtualNum().compareTo(num) >= 0) {
|
|
|
+// item.setVirtualNum(item.getVirtualNum().subtract(num));
|
|
|
+// }else {
|
|
|
+// item.setVirtualNum(BigDecimal.ZERO);
|
|
|
+// // 加超卖房间数
|
|
|
+// item.setOversoldNum(item.getOversoldNum().add(num.subtract(item.getVirtualNum())));
|
|
|
+// }
|
|
|
+// //减可售房间数
|
|
|
+// item.setCanSellNum(item.getCanSellNum().subtract(num));
|
|
|
+// //加预定房间数
|
|
|
+// item.setBookNum(item.getBookNum().add(num));
|
|
|
+// updateDetailList.add(item);
|
|
|
+// }
|
|
|
+// });
|
|
|
+// voyageStockDetailMapper.updateBatch(updateDetailList);
|
|
|
}
|
|
|
}
|