|
@@ -25,7 +25,6 @@ import com.yc.ship.module.product.enums.YesOrNoEnum;
|
|
|
import com.yc.ship.module.product.framework.lock.ProductRedisKeyConstants;
|
|
import com.yc.ship.module.product.framework.lock.ProductRedisKeyConstants;
|
|
|
import com.yc.ship.module.product.service.voyagestockdistribute.VoyageStockDistributeNewService;
|
|
import com.yc.ship.module.product.service.voyagestockdistribute.VoyageStockDistributeNewService;
|
|
|
import com.yc.ship.module.product.utils.ProductRedisUtils;
|
|
import com.yc.ship.module.product.utils.ProductRedisUtils;
|
|
|
-import com.yc.ship.module.resource.api.room.RoomApi;
|
|
|
|
|
import com.yc.ship.module.trade.enums.TradeOrderStatusEnum;
|
|
import com.yc.ship.module.trade.enums.TradeOrderStatusEnum;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.redisson.api.RLock;
|
|
import org.redisson.api.RLock;
|
|
@@ -45,6 +44,9 @@ import static com.yc.ship.framework.common.exception.util.ServiceExceptionUtil.e
|
|
|
import static com.yc.ship.framework.common.exception.util.ServiceExceptionUtil.exception0;
|
|
import static com.yc.ship.framework.common.exception.util.ServiceExceptionUtil.exception0;
|
|
|
import static com.yc.ship.module.product.enums.ErrorCodeConstants.*;
|
|
import static com.yc.ship.module.product.enums.ErrorCodeConstants.*;
|
|
|
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * @author sky
|
|
|
|
|
+ */
|
|
|
@Service
|
|
@Service
|
|
|
@Slf4j
|
|
@Slf4j
|
|
|
public class VoyageApiImpl implements VoyageApi {
|
|
public class VoyageApiImpl implements VoyageApi {
|
|
@@ -61,9 +63,6 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
@Resource
|
|
@Resource
|
|
|
private VoyageStockDistributeNewService voyageStockDistributeNewService;
|
|
private VoyageStockDistributeNewService voyageStockDistributeNewService;
|
|
|
|
|
|
|
|
- @Resource
|
|
|
|
|
- private RoomApi roomApi;
|
|
|
|
|
-
|
|
|
|
|
@Resource
|
|
@Resource
|
|
|
private RedissonClient redissonClient;
|
|
private RedissonClient redissonClient;
|
|
|
|
|
|
|
@@ -82,7 +81,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
@Override
|
|
@Override
|
|
|
public void preReduceStock(ReduceStockReqDTO reqDTO) {
|
|
public void preReduceStock(ReduceStockReqDTO reqDTO) {
|
|
|
//TODO: 当前阶段不考虑门店库存
|
|
//TODO: 当前阶段不考虑门店库存
|
|
|
- log.info("开始初定订单扣库存:订单ID:"+reqDTO.getOrderId()+"old订单ID:"+reqDTO.getOldOrderId());
|
|
|
|
|
|
|
+ log.info("开始初定订单扣库存:订单ID:{}old订单ID:{}", reqDTO.getOrderId(), reqDTO.getOldOrderId());
|
|
|
|
|
|
|
|
Long voyageId = reqDTO.getVoyageId();
|
|
Long voyageId = reqDTO.getVoyageId();
|
|
|
//现在给整个航次的库存加锁
|
|
//现在给整个航次的库存加锁
|
|
@@ -98,7 +97,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
//初定扣分销商库存
|
|
//初定扣分销商库存
|
|
|
//先返还初定扣的库存,使用修改前一步订单的 ID
|
|
//先返还初定扣的库存,使用修改前一步订单的 ID
|
|
|
preCancelReduceStockDistributor(reqDTO.getOrderId(), reqDTO.getType());
|
|
preCancelReduceStockDistributor(reqDTO.getOrderId(), reqDTO.getType());
|
|
|
- if(reqDTO.getOldOrderId() != null && reqDTO.getOldOrderId() != reqDTO.getOrderId()) {
|
|
|
|
|
|
|
+ if(reqDTO.getOldOrderId() != null && !reqDTO.getOldOrderId().equals(reqDTO.getOrderId())) {
|
|
|
preCancelReduceStockDistributor(reqDTO.getOldOrderId(), reqDTO.getType());
|
|
preCancelReduceStockDistributor(reqDTO.getOldOrderId(), reqDTO.getType());
|
|
|
}
|
|
}
|
|
|
//再去扣初定的库存
|
|
//再去扣初定的库存
|
|
@@ -107,13 +106,10 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
} catch (ServiceException e) {
|
|
} catch (ServiceException e) {
|
|
|
throw exception0(e.getCode(), e.getMessage());
|
|
throw exception0(e.getCode(), e.getMessage());
|
|
|
} finally {
|
|
} finally {
|
|
|
- try {
|
|
|
|
|
- if (lock.isHeldByCurrentThread() && lock.isLocked()) {
|
|
|
|
|
- lock.unlock();
|
|
|
|
|
- }
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- log.error("释放锁异常", e);
|
|
|
|
|
|
|
+ if (lock.isLocked() && lock.isHeldByCurrentThread()) {
|
|
|
|
|
+ lock.unlock();
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -127,12 +123,14 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
RLock lock = redissonClient.getLock(lockKey);
|
|
RLock lock = redissonClient.getLock(lockKey);
|
|
|
try {
|
|
try {
|
|
|
lock.lock(60, TimeUnit.SECONDS);
|
|
lock.lock(60, TimeUnit.SECONDS);
|
|
|
- Integer type = reqDTO.getType();//判断是分销商还是门店下单 1:分销商,2:门店
|
|
|
|
|
- if (Objects.equals(type, DistributorOrStoreEnum.DISTRIBUTOR.getValue())) {//分销商下单,当前阶段不考虑门店下单
|
|
|
|
|
|
|
+ //判断是分销商还是门店下单 1:分销商,2:门店
|
|
|
|
|
+ Integer type = reqDTO.getType();
|
|
|
|
|
+ //分销商下单,当前阶段不考虑门店下单
|
|
|
|
|
+ if (Objects.equals(type, DistributorOrStoreEnum.DISTRIBUTOR.getValue())) {
|
|
|
//分销商下单只扣分销商库存,默认是OTA,默认OTC只能门店下单
|
|
//分销商下单只扣分销商库存,默认是OTA,默认OTC只能门店下单
|
|
|
//初定扣分销商库存
|
|
//初定扣分销商库存
|
|
|
preCancelReduceStockDistributor(reqDTO.getOrderId(), reqDTO.getType());
|
|
preCancelReduceStockDistributor(reqDTO.getOrderId(), reqDTO.getType());
|
|
|
- if(reqDTO.getOldOrderId() != null && reqDTO.getOldOrderId() != reqDTO.getOrderId()) {
|
|
|
|
|
|
|
+ if(reqDTO.getOldOrderId() != null && !reqDTO.getOldOrderId().equals(reqDTO.getOrderId())) {
|
|
|
preCancelReduceStockDistributor(reqDTO.getOldOrderId(), reqDTO.getType());
|
|
preCancelReduceStockDistributor(reqDTO.getOldOrderId(), reqDTO.getType());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -153,13 +151,15 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
RLock lock = redissonClient.getLock(lockKey);
|
|
RLock lock = redissonClient.getLock(lockKey);
|
|
|
try {
|
|
try {
|
|
|
lock.lock(60, TimeUnit.SECONDS);
|
|
lock.lock(60, TimeUnit.SECONDS);
|
|
|
- Integer type = reqDTO.getType();//判断是分销商还是门店下单 1:分销商,2:门店
|
|
|
|
|
- if (Objects.equals(type, DistributorOrStoreEnum.DISTRIBUTOR.getValue())) {//分销商下单,当前阶段不考虑门店下单
|
|
|
|
|
|
|
+ //判断是分销商还是门店下单 1:分销商,2:门店
|
|
|
|
|
+ Integer type = reqDTO.getType();
|
|
|
|
|
+ //分销商下单,当前阶段不考虑门店下单
|
|
|
|
|
+ if (Objects.equals(type, DistributorOrStoreEnum.DISTRIBUTOR.getValue())) {
|
|
|
//分销商下单只扣分销商库存,默认是OTA,默认OTC只能门店下单
|
|
//分销商下单只扣分销商库存,默认是OTA,默认OTC只能门店下单
|
|
|
//初定扣分销商库存
|
|
//初定扣分销商库存
|
|
|
//先返还初定扣的库存
|
|
//先返还初定扣的库存
|
|
|
preCancelReduceStockDistributor(reqDTO.getOrderId(), reqDTO.getType());
|
|
preCancelReduceStockDistributor(reqDTO.getOrderId(), reqDTO.getType());
|
|
|
- if(reqDTO.getOldOrderId() != null && reqDTO.getOldOrderId() != reqDTO.getOrderId()) {
|
|
|
|
|
|
|
+ if(reqDTO.getOldOrderId() != null && !reqDTO.getOldOrderId().equals(reqDTO.getOrderId())) {
|
|
|
preCancelReduceStockDistributor(reqDTO.getOldOrderId(), reqDTO.getType());
|
|
preCancelReduceStockDistributor(reqDTO.getOldOrderId(), reqDTO.getType());
|
|
|
}
|
|
}
|
|
|
//再去扣确定的库存
|
|
//再去扣确定的库存
|
|
@@ -182,12 +182,14 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
RLock lock = redissonClient.getLock(lockKey);
|
|
RLock lock = redissonClient.getLock(lockKey);
|
|
|
try {
|
|
try {
|
|
|
lock.lock(60, TimeUnit.SECONDS);
|
|
lock.lock(60, TimeUnit.SECONDS);
|
|
|
- Integer type = reqDTO.getType();//判断是分销商还是门店下单 1:分销商,2:门店
|
|
|
|
|
- if (Objects.equals(type, DistributorOrStoreEnum.DISTRIBUTOR.getValue())) {//分销商下单,当前阶段不考虑门店下单
|
|
|
|
|
|
|
+ //判断是分销商还是门店下单 1:分销商,2:门店
|
|
|
|
|
+ Integer type = reqDTO.getType();
|
|
|
|
|
+ //分销商下单,当前阶段不考虑门店下单
|
|
|
|
|
+ if (Objects.equals(type, DistributorOrStoreEnum.DISTRIBUTOR.getValue())) {
|
|
|
//分销商下单只扣分销商库存,默认是OTA,默认OTC只能门店下单
|
|
//分销商下单只扣分销商库存,默认是OTA,默认OTC只能门店下单
|
|
|
//初定扣分销商库存
|
|
//初定扣分销商库存
|
|
|
cancelReduceStockDistributor(reqDTO.getOrderId(), reqDTO.getType());
|
|
cancelReduceStockDistributor(reqDTO.getOrderId(), reqDTO.getType());
|
|
|
- if(reqDTO.getOldOrderId() != null && reqDTO.getOldOrderId() != reqDTO.getOrderId()) {
|
|
|
|
|
|
|
+ if(reqDTO.getOldOrderId() != null && !reqDTO.getOldOrderId().equals(reqDTO.getOrderId())) {
|
|
|
cancelReduceStockDistributor(reqDTO.getOldOrderId(), reqDTO.getType());
|
|
cancelReduceStockDistributor(reqDTO.getOldOrderId(), reqDTO.getType());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -216,12 +218,18 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
VoyageStockDO stockDO = voyageStockMapper.selectById(voyageId);
|
|
VoyageStockDO stockDO = voyageStockMapper.selectById(voyageId);
|
|
|
//还航次总库存
|
|
//还航次总库存
|
|
|
BigDecimal totalNum = voyageStockLogDO.getVirtualNum().add(voyageStockLogDO.getRealNum());
|
|
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);
|
|
|
productRedisUtils.set(ProductRedisKeyConstants.STOCK_TOTAL_REDIS_KEY_PREFIX + voyageId, stockDO);
|
|
productRedisUtils.set(ProductRedisKeyConstants.STOCK_TOTAL_REDIS_KEY_PREFIX + voyageId, stockDO);
|
|
|
//删除航次库存操作记录
|
|
//删除航次库存操作记录
|
|
|
voyageStockLogMapper.deleteById(voyageStockLogDO);
|
|
voyageStockLogMapper.deleteById(voyageStockLogDO);
|
|
@@ -237,7 +245,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
//退还航次库存详情
|
|
//退还航次库存详情
|
|
|
List<VoyageStockDetailDO> stockDetailList = voyageStockDetailMapper.selectListByVoyageId(voyageId);
|
|
List<VoyageStockDetailDO> stockDetailList = voyageStockDetailMapper.selectListByVoyageId(voyageId);
|
|
|
Map<String, BigDecimal> realNumMap = CollectionUtils.convertMap(detailLogList, item -> item.getRoomModelId() + "_" + item.getFloor(), VoyageStockDetailLogDO::getRealNum);
|
|
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> 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()));
|
|
Map<String, BigDecimal> totalNumMap = CollectionUtils.convertMap(detailLogList, item -> item.getRoomModelId() + "_" + item.getFloor(), item -> item.getRealNum().add(item.getVirtualNum()));
|
|
|
|
|
|
|
@@ -246,7 +254,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
item.setBookNum(item.getBookNum().subtract(totalNumMap.get(key)));
|
|
item.setBookNum(item.getBookNum().subtract(totalNumMap.get(key)));
|
|
|
item.setCanSellNum(item.getCanSellNum().add(totalNumMap.get(key)));
|
|
item.setCanSellNum(item.getCanSellNum().add(totalNumMap.get(key)));
|
|
|
item.setRealTotalNum(item.getRealTotalNum().add(realNumMap.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);
|
|
voyageStockDetailMapper.updateBatch(stockDetailList);
|
|
|
productRedisUtils.set(ProductRedisKeyConstants.STOCK_DETAIL_REDIS_KEY_PREFIX + voyageId, stockDetailList);
|
|
productRedisUtils.set(ProductRedisKeyConstants.STOCK_DETAIL_REDIS_KEY_PREFIX + voyageId, stockDetailList);
|
|
@@ -259,8 +267,8 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
detailReqVO.setVoyageId(voyageId);
|
|
detailReqVO.setVoyageId(voyageId);
|
|
|
detailReqVO.setType(type);
|
|
detailReqVO.setType(type);
|
|
|
detailReqVO.setObjectId(distributorId);
|
|
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()) {
|
|
if (list != null && !list.isEmpty()) {
|
|
|
list.forEach(item -> {
|
|
list.forEach(item -> {
|
|
|
String key = item.getRoomModelId() + "_" + item.getFloor();
|
|
String key = item.getRoomModelId() + "_" + item.getFloor();
|
|
@@ -280,7 +288,6 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
/**
|
|
/**
|
|
|
* 确定时扣库存,有限扣实际库存,不足再扣虚拟库存
|
|
* 确定时扣库存,有限扣实际库存,不足再扣虚拟库存
|
|
|
*
|
|
*
|
|
|
- * @param reqDTO
|
|
|
|
|
*/
|
|
*/
|
|
|
private void reduceStockDistributor(ReduceStockReqDTO reqDTO) {
|
|
private void reduceStockDistributor(ReduceStockReqDTO reqDTO) {
|
|
|
//航次库存操作日志
|
|
//航次库存操作日志
|
|
@@ -289,15 +296,20 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
List<VoyageStockDetailLogDO> detailLogList = new ArrayList<>();
|
|
List<VoyageStockDetailLogDO> detailLogList = new ArrayList<>();
|
|
|
|
|
|
|
|
Integer type = reqDTO.getType();
|
|
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();
|
|
Long orderId = reqDTO.getOrderId();
|
|
|
Integer orderStatus = reqDTO.getOrderStatus();
|
|
Integer orderStatus = reqDTO.getOrderStatus();
|
|
|
|
|
|
|
|
voyageStockLogDO.setVoyageId(voyageId);
|
|
voyageStockLogDO.setVoyageId(voyageId);
|
|
|
- voyageStockLogDO.setType(2);//标识减少
|
|
|
|
|
|
|
+ //标识减少
|
|
|
|
|
+ voyageStockLogDO.setType(2);
|
|
|
voyageStockLogDO.setOrderId(orderId);
|
|
voyageStockLogDO.setOrderId(orderId);
|
|
|
voyageStockLogDO.setOrderStatus(orderStatus);
|
|
voyageStockLogDO.setOrderStatus(orderStatus);
|
|
|
voyageStockLogDO.setOperateType(VoyageStockLogTypeEnum.ORDER_SUB.getValue());
|
|
voyageStockLogDO.setOperateType(VoyageStockLogTypeEnum.ORDER_SUB.getValue());
|
|
@@ -336,7 +348,8 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
Map<String, BigDecimal> roomModelFloorNumMap = orderRoomList.stream()
|
|
Map<String, BigDecimal> roomModelFloorNumMap = orderRoomList.stream()
|
|
|
.collect(Collectors.groupingBy(
|
|
.collect(Collectors.groupingBy(
|
|
|
OrderRoomUseDTO::getKey,
|
|
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 (CollectionUtils.isAnyEmpty(distributeNewResps)) {
|
|
if (CollectionUtils.isAnyEmpty(distributeNewResps)) {
|
|
@@ -599,68 +612,69 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
//删除航次库存操作记录
|
|
//删除航次库存操作记录
|
|
|
voyageStockLogMapper.deleteById(voyageStockLogDO);
|
|
voyageStockLogMapper.deleteById(voyageStockLogDO);
|
|
|
} else {
|
|
} else {
|
|
|
- log.error("订单取消时,未找到对应的航次库存操作记录,订单ID:{}", orderId);
|
|
|
|
|
|
|
+ log.error("订单取消时,未找到对应的航次库存,订单ID:{}", orderId);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
Long voyageId = voyageStockLogDO.getVoyageId();
|
|
Long voyageId = voyageStockLogDO.getVoyageId();
|
|
|
Long distributorId = voyageStockLogDO.getDistributorId();
|
|
Long distributorId = voyageStockLogDO.getDistributorId();
|
|
|
//找到初定时扣库存详情的记录
|
|
//找到初定时扣库存详情的记录
|
|
|
List<VoyageStockDetailLogDO> detailLogList = voyageStockDetailLogMapper.selectListByOrder(orderId, TradeOrderStatusEnum.YD.getStatus());
|
|
List<VoyageStockDetailLogDO> detailLogList = voyageStockDetailLogMapper.selectListByOrder(orderId, TradeOrderStatusEnum.YD.getStatus());
|
|
|
|
|
+ if (detailLogList.isEmpty()) {
|
|
|
|
|
+ log.error("订单取消时,未找到对应的航次库存详情操作记录,订单ID:{}", orderId);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
Integer stockType = detailLogList.get(0).getStockType();
|
|
Integer stockType = detailLogList.get(0).getStockType();
|
|
|
- if (detailLogList != null && !detailLogList.isEmpty()) {
|
|
|
|
|
- //退还航次库存详情
|
|
|
|
|
- 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);
|
|
|
|
|
|
|
+ //退还航次库存详情
|
|
|
|
|
+ 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> 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.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)));
|
|
|
|
|
- if(stockType == 1) {//共享库存要还回库存详情
|
|
|
|
|
- item.setShareNum(item.getShareNum().add(totalNumMap.get(key)));
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- voyageStockDetailMapper.updateBatch(stockDetailList);
|
|
|
|
|
- productRedisUtils.set(ProductRedisKeyConstants.STOCK_DETAIL_REDIS_KEY_PREFIX + voyageId, stockDetailList);
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- //2:还分销商库存
|
|
|
|
|
- if (stockType == 2) {
|
|
|
|
|
- //判断分销商库存是否存在
|
|
|
|
|
- VoyageStockDistributeNewDetailReqVO detailReqVO = new VoyageStockDistributeNewDetailReqVO();
|
|
|
|
|
- detailReqVO.setVoyageId(voyageId);
|
|
|
|
|
- detailReqVO.setType(type);
|
|
|
|
|
- detailReqVO.setObjectId(distributorId);
|
|
|
|
|
- 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();
|
|
|
|
|
- if(item.getBookNum()==null){
|
|
|
|
|
- item.setBookNum(BigDecimal.ZERO);
|
|
|
|
|
- }
|
|
|
|
|
- if(item.getNum()==null){
|
|
|
|
|
- item.setNum(BigDecimal.ZERO);
|
|
|
|
|
- }
|
|
|
|
|
- item.setNum(item.getNum().add(totalNumMap.get(key)));
|
|
|
|
|
- item.setBookNum(item.getBookNum().subtract(totalNumMap.get(key)));
|
|
|
|
|
- if(item.getBookNum().compareTo(BigDecimal.ZERO)<0){
|
|
|
|
|
- item.setBookNum(BigDecimal.ZERO);
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- voyageStockDistributeNewMapper.updateBatch(list);
|
|
|
|
|
- productRedisUtils.set(ProductRedisKeyConstants.STOCK_DISTRIBUTOR_REDIS_KEY_PREFIX + voyageId, list);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ Map<String, BigDecimal> totalNumMap = CollectionUtils.convertMap(detailLogList, item -> item.getRoomModelId() + "_" + item.getFloor(), item -> item.getRealNum().add(item.getVirtualNum()));
|
|
|
|
|
+
|
|
|
|
|
+ stockDetailList.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)));
|
|
|
|
|
+ if(stockType == 1) {//共享库存要还回库存详情
|
|
|
|
|
+ item.setShareNum(item.getShareNum().add(totalNumMap.get(key)));
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ voyageStockDetailMapper.updateBatch(stockDetailList);
|
|
|
|
|
+ productRedisUtils.set(ProductRedisKeyConstants.STOCK_DETAIL_REDIS_KEY_PREFIX + voyageId, stockDetailList);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ //2:还分销商库存
|
|
|
|
|
+ if (stockType == 2) {
|
|
|
|
|
+ //判断分销商库存是否存在
|
|
|
|
|
+ VoyageStockDistributeNewDetailReqVO detailReqVO = new VoyageStockDistributeNewDetailReqVO();
|
|
|
|
|
+ detailReqVO.setVoyageId(voyageId);
|
|
|
|
|
+ detailReqVO.setType(type);
|
|
|
|
|
+ detailReqVO.setObjectId(distributorId);
|
|
|
|
|
+ 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();
|
|
|
|
|
+ if(item.getBookNum()==null){
|
|
|
|
|
+ item.setBookNum(BigDecimal.ZERO);
|
|
|
|
|
+ }
|
|
|
|
|
+ if(item.getNum()==null){
|
|
|
|
|
+ item.setNum(BigDecimal.ZERO);
|
|
|
|
|
+ }
|
|
|
|
|
+ item.setNum(item.getNum().add(totalNumMap.get(key)));
|
|
|
|
|
+ item.setBookNum(item.getBookNum().subtract(totalNumMap.get(key)));
|
|
|
|
|
+ if(item.getBookNum().compareTo(BigDecimal.ZERO)<0){
|
|
|
|
|
+ item.setBookNum(BigDecimal.ZERO);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ voyageStockDistributeNewMapper.updateBatch(list);
|
|
|
|
|
+ productRedisUtils.set(ProductRedisKeyConstants.STOCK_DISTRIBUTOR_REDIS_KEY_PREFIX + voyageId, list);
|
|
|
}
|
|
}
|
|
|
- // 删除库存详情初定记录
|
|
|
|
|
- voyageStockDetailLogMapper.deleteByOrder(orderId, TradeOrderStatusEnum.YD.getStatus());
|
|
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+ // 删除库存详情初定记录
|
|
|
|
|
+ voyageStockDetailLogMapper.deleteByOrder(orderId, TradeOrderStatusEnum.YD.getStatus());
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|
|
@@ -749,7 +763,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
useNum = BigDecimal.ZERO;
|
|
useNum = BigDecimal.ZERO;
|
|
|
}
|
|
}
|
|
|
if (detailShareNum.compareTo(useNum) < 0) {
|
|
if (detailShareNum.compareTo(useNum) < 0) {
|
|
|
- log.error(String.format(VOYAGE_SHARE_ROOM_NOT_ENOUGH.getMsg(), item.getRoomModelName(), item.getFloor()));
|
|
|
|
|
|
|
+ log.error("共享库存扣减异常:{}",String.format(VOYAGE_SHARE_ROOM_NOT_ENOUGH.getMsg(), item.getRoomModelName(), item.getFloor()));
|
|
|
throw exception0(VOYAGE_SHARE_ROOM_NOT_ENOUGH.getCode(), String.format(VOYAGE_SHARE_ROOM_NOT_ENOUGH.getMsg(), item.getRoomModelName(), item.getFloor()));
|
|
throw exception0(VOYAGE_SHARE_ROOM_NOT_ENOUGH.getCode(), String.format(VOYAGE_SHARE_ROOM_NOT_ENOUGH.getMsg(), item.getRoomModelName(), item.getFloor()));
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|