|
|
@@ -2,7 +2,7 @@ package com.yc.ship.module.product.api;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.yc.ship.framework.common.exception.ServiceException;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.yc.ship.framework.common.util.collection.CollectionUtils;
|
|
|
import com.yc.ship.framework.common.util.object.BeanUtils;
|
|
|
import com.yc.ship.module.product.api.dto.OrderRoomUseDTO;
|
|
|
@@ -27,11 +27,12 @@ import com.yc.ship.module.product.enums.YesOrNoEnum;
|
|
|
import com.yc.ship.module.product.framework.lock.ProductRedisKeyConstants;
|
|
|
import com.yc.ship.module.product.service.voyagestockdistribute.VoyageStockDistributeNewService;
|
|
|
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 lombok.extern.slf4j.Slf4j;
|
|
|
import org.redisson.api.RLock;
|
|
|
import org.redisson.api.RedissonClient;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Propagation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
|
|
|
@@ -48,6 +49,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.module.product.enums.ErrorCodeConstants.*;
|
|
|
|
|
|
+/**
|
|
|
+ * @author qsl
|
|
|
+ */
|
|
|
@Service
|
|
|
@Slf4j
|
|
|
public class VoyageApiImpl implements VoyageApi {
|
|
|
@@ -64,9 +68,6 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
@Resource
|
|
|
private VoyageStockDistributeNewService voyageStockDistributeNewService;
|
|
|
|
|
|
- @Resource
|
|
|
- private RoomApi roomApi;
|
|
|
-
|
|
|
@Resource
|
|
|
private RedissonClient redissonClient;
|
|
|
|
|
|
@@ -83,10 +84,10 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
private VoyageStockDetailLogMapper voyageStockDetailLogMapper;
|
|
|
|
|
|
@Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Transactional(propagation = Propagation.NESTED,rollbackFor = Exception.class)
|
|
|
public void preReduceStock(ReduceStockReqDTO reqDTO) {
|
|
|
//TODO: 当前阶段不考虑门店库存
|
|
|
- log.info("开始初定订单扣库存:订单ID:"+reqDTO.getOrderId()+"old订单ID:"+reqDTO.getOldOrderId());
|
|
|
+ log.info("开始初定订单扣库存:订单ID:{}old订单ID:{}", reqDTO.getOrderId(), reqDTO.getOldOrderId());
|
|
|
|
|
|
Long voyageId = reqDTO.getVoyageId();
|
|
|
//现在给整个航次的库存加锁
|
|
|
@@ -102,29 +103,23 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
//初定扣分销商库存
|
|
|
//先返还初定扣的库存,使用修改前一步订单的 ID
|
|
|
preCancelReduceStockDistributor(reqDTO.getOrderId(), reqDTO.getType());
|
|
|
- log.info("先还该订单的库存-orderId: "+reqDTO.getOrderId());
|
|
|
- if(reqDTO.getOldOrderId() != null && reqDTO.getOldOrderId() != reqDTO.getOrderId()) {
|
|
|
- log.info("如果是修改就还修改前的订单的库存-oldOrderId: "+reqDTO.getOldOrderId());
|
|
|
+ log.info("先还该订单的库存-orderId: {}", reqDTO.getOrderId());
|
|
|
+ if (reqDTO.getOldOrderId() != null && !reqDTO.getOldOrderId().equals(reqDTO.getOrderId())) {
|
|
|
+ log.info("如果是修改就还修改前的订单的库存-oldOrderId: {}", reqDTO.getOldOrderId());
|
|
|
preCancelReduceStockDistributor(reqDTO.getOldOrderId(), reqDTO.getType());
|
|
|
}
|
|
|
//再去扣初定的库存
|
|
|
preReduceStockDistributor(reqDTO);
|
|
|
}
|
|
|
- } catch (ServiceException e) {
|
|
|
- throw exception0(e.getCode(), e.getMessage());
|
|
|
} finally {
|
|
|
- try {
|
|
|
- if (lock.isHeldByCurrentThread() && lock.isLocked()) {
|
|
|
- lock.unlock();
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("释放锁异常", e);
|
|
|
+ if (lock.isHeldByCurrentThread() && lock.isLocked()) {
|
|
|
+ lock.unlock();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Transactional(propagation = Propagation.NESTED,rollbackFor = Exception.class)
|
|
|
public void preCancelReduceStock(ReduceStockReqDTO reqDTO) {
|
|
|
//TODO: 当前阶段不考虑门店库存
|
|
|
|
|
|
@@ -134,12 +129,14 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
RLock lock = redissonClient.getLock(lockKey);
|
|
|
try {
|
|
|
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只能门店下单
|
|
|
//初定扣分销商库存
|
|
|
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());
|
|
|
}
|
|
|
}
|
|
|
@@ -151,7 +148,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @Transactional
|
|
|
+ @Transactional(propagation = Propagation.NESTED,rollbackFor = Exception.class)
|
|
|
public void reduceStock(ReduceStockReqDTO reqDTO) {
|
|
|
//TODO: 当前阶段不考虑门店库存
|
|
|
|
|
|
@@ -161,22 +158,27 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
RLock lock = redissonClient.getLock(lockKey);
|
|
|
try {
|
|
|
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只能门店下单
|
|
|
//初定扣分销商库存
|
|
|
//先返还初定扣的库存
|
|
|
preCancelReduceStockDistributor(reqDTO.getOrderId(), reqDTO.getType());
|
|
|
- if(reqDTO.getOldOrderId() != null && !reqDTO.getOldOrderId().equals(reqDTO.getOrderId())) {
|
|
|
+ if (reqDTO.getOldOrderStatus() != null && reqDTO.getOldOrderStatus().equals(TradeOrderStatusEnum.YD.getStatus()) &&reqDTO.getOldOrderId() != null && !reqDTO.getOldOrderId().equals(reqDTO.getOrderId())) {
|
|
|
preCancelReduceStockDistributor(reqDTO.getOldOrderId(), reqDTO.getType());
|
|
|
}
|
|
|
+ if(reqDTO.getOldOrderStatus() != null && (Objects.equals(reqDTO.getOldOrderStatus(), TradeOrderStatusEnum.UNPAID.getStatus())||Objects.equals(reqDTO.getOldOrderStatus(), TradeOrderStatusEnum.YD.getStatus()))){
|
|
|
+ cancelReduceStockDistributor(reqDTO.getOldOrderId(), reqDTO.getType());
|
|
|
+ }
|
|
|
//再去扣确定的库存
|
|
|
reduceStockDistributor(reqDTO);
|
|
|
}
|
|
|
- }catch (Exception e){
|
|
|
+ } catch (Exception e) {
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
throw e;
|
|
|
- }finally {
|
|
|
+ } finally {
|
|
|
if (lock.isHeldByCurrentThread() && lock.isLocked()) {
|
|
|
lock.unlock();
|
|
|
}
|
|
|
@@ -185,7 +187,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Transactional(propagation = Propagation.NESTED,rollbackFor = Exception.class)
|
|
|
public void cancelReduceStock(ReduceStockReqDTO reqDTO) {
|
|
|
//TODO: 当前阶段不考虑门店库存
|
|
|
Long voyageId = reqDTO.getVoyageId();
|
|
|
@@ -194,12 +196,14 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
RLock lock = redissonClient.getLock(lockKey);
|
|
|
try {
|
|
|
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只能门店下单
|
|
|
//初定扣分销商库存
|
|
|
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());
|
|
|
}
|
|
|
}
|
|
|
@@ -214,7 +218,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
* 确定状态时取消订单还库存
|
|
|
*/
|
|
|
private void cancelReduceStockDistributor(Long orderId, Integer type) {
|
|
|
- if(orderId == null) {
|
|
|
+ if (orderId == null) {
|
|
|
return;
|
|
|
}
|
|
|
//退还航次总库存
|
|
|
@@ -228,14 +232,20 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
VoyageStockDO stockDO = voyageStockMapper.selectById(voyageId);
|
|
|
//还航次总库存
|
|
|
BigDecimal totalNum = voyageStockLogDO.getVirtualNum().add(voyageStockLogDO.getRealNum());
|
|
|
- if(voyageStockLogDO.getStockType() != null && voyageStockLogDO.getStockType() == 1) {
|
|
|
- stockDO.setShareNum(stockDO.getShareNum().add(voyageStockLogDO.getShareNum())); //退回共享库存
|
|
|
+ if (voyageStockLogDO.getStockType() != null && voyageStockLogDO.getStockType() == 1) {
|
|
|
+ //退回共享库存
|
|
|
+ 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.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);
|
|
|
//删除航次库存操作记录
|
|
|
voyageStockLogMapper.deleteById(voyageStockLogDO);
|
|
|
@@ -252,7 +262,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()));
|
|
|
|
|
|
@@ -261,8 +271,8 @@ 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)));
|
|
|
- if(stockType == 1) {//使用的是共享库存,才退回共享库存
|
|
|
+ item.setVirtualNum(item.getVirtualNum().add(virtualNumMap.get(key)));
|
|
|
+ if (stockType == 1) {//使用的是共享库存,才退回共享库存
|
|
|
item.setShareNum(item.getShareNum().add(totalNumMap.get(key)));
|
|
|
}
|
|
|
});
|
|
|
@@ -277,8 +287,8 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
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> distributeNewResp = voyageStockDistributeNewService.getDetail(detailReqVO);
|
|
|
+ List<VoyageStockDistributeNewDO> list = BeanUtils.toBean(distributeNewResp, VoyageStockDistributeNewDO.class);
|
|
|
if (list != null && !list.isEmpty()) {
|
|
|
list.forEach(item -> {
|
|
|
String key = item.getRoomModelId() + "_" + item.getFloor();
|
|
|
@@ -286,7 +296,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
item.setBookNum(item.getBookNum() == null ? BigDecimal.ZERO : item.getBookNum().subtract(totalNumMap.get(key)));
|
|
|
});
|
|
|
voyageStockDistributeNewMapper.updateBatch(list);
|
|
|
- productRedisUtils.set(ProductRedisKeyConstants.STOCK_DISTRIBUTOR_REDIS_KEY_PREFIX + voyageId+"_"+distributorId, list);
|
|
|
+ productRedisUtils.set(ProductRedisKeyConstants.STOCK_DISTRIBUTOR_REDIS_KEY_PREFIX + voyageId + "_" + distributorId, list);
|
|
|
}
|
|
|
}
|
|
|
// 删除库存详情初定记录
|
|
|
@@ -297,7 +307,6 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
|
|
|
/**
|
|
|
* 确定时扣库存,有限扣实际库存,不足再扣虚拟库存
|
|
|
- *
|
|
|
*/
|
|
|
private void reduceStockDistributor(ReduceStockReqDTO reqDTO) {
|
|
|
//航次库存操作日志
|
|
|
@@ -306,15 +315,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_SUB.getValue());
|
|
|
@@ -322,19 +336,20 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
voyageStockLogDO.setStoreId(storeId);
|
|
|
// 获取航次总库存
|
|
|
VoyageStockDO stockDO = productRedisUtils.get(ProductRedisKeyConstants.STOCK_TOTAL_REDIS_KEY_PREFIX + voyageId, VoyageStockDO.class, 1);
|
|
|
- if(stockDO == null) {
|
|
|
+ if (stockDO == null) {
|
|
|
stockDO = voyageStockMapper.selectById(voyageId);
|
|
|
}
|
|
|
if (stockDO == null) {
|
|
|
throw exception(VOYAGE_NO_STOCK);
|
|
|
}
|
|
|
+ voyageStockLogDO.setTenantId(stockDO.getTenantId());
|
|
|
//共享库存
|
|
|
BigDecimal shareNum = stockDO.getShareNum();
|
|
|
|
|
|
//航次库存详情
|
|
|
//航次库存详情
|
|
|
List<VoyageStockDetailDO> stockDetailList = productRedisUtils.getList(ProductRedisKeyConstants.STOCK_DETAIL_REDIS_KEY_PREFIX + voyageId, VoyageStockDetailDO.class, 1);
|
|
|
- if(CollectionUtils.isAnyEmpty(stockDetailList)) {
|
|
|
+ if (CollectionUtils.isAnyEmpty(stockDetailList)) {
|
|
|
stockDetailList = voyageStockDetailMapper.selectListByVoyageId(voyageId);
|
|
|
}
|
|
|
//判断分销商库存是否存在
|
|
|
@@ -344,8 +359,8 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
detailReqVO.setObjectId(distributorId);
|
|
|
//先获取非共享库存(分销商库存)
|
|
|
detailReqVO.setEnableShare(YesOrNoEnum.NO.getType());
|
|
|
- List<VoyageStockDistributeNewRespVO> distributeNewResps = productRedisUtils.getList(ProductRedisKeyConstants.STOCK_DISTRIBUTOR_REDIS_KEY_PREFIX + voyageId+"_"+distributorId, VoyageStockDistributeNewRespVO.class, 1);
|
|
|
- if(CollectionUtils.isAnyEmpty(distributeNewResps)) {
|
|
|
+ List<VoyageStockDistributeNewRespVO> distributeNewResps = productRedisUtils.getList(ProductRedisKeyConstants.STOCK_DISTRIBUTOR_REDIS_KEY_PREFIX + voyageId + "_" + distributorId, VoyageStockDistributeNewRespVO.class, 1);
|
|
|
+ if (CollectionUtils.isAnyEmpty(distributeNewResps)) {
|
|
|
distributeNewResps = voyageStockDistributeNewService.getDetail(detailReqVO);
|
|
|
}
|
|
|
//订单使用房间详情
|
|
|
@@ -353,7 +368,8 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
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 (CollectionUtils.isAnyEmpty(distributeNewResps)) {
|
|
|
@@ -372,7 +388,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
useNum = BigDecimal.ZERO;
|
|
|
}
|
|
|
if (detailShareNum.compareTo(useNum) < 0) {
|
|
|
- log.error(String.format(VOYAGE_SHARE_ROOM_NOT_ENOUGH.getMsg(), item.getRoomModelName(), item.getFloor(), detailShareNum, useNum));
|
|
|
+ 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));
|
|
|
}
|
|
|
});
|
|
|
@@ -459,7 +475,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
useNum = BigDecimal.ZERO;
|
|
|
}
|
|
|
if (canSellNum.compareTo(useNum) < 0) {
|
|
|
- log.error(String.format(VOYAGE_DISTRIBUTOR_ROOM_NOT_ENOUGH.getMsg(), item.getRoomModelName(), item.getFloor(), canSellNum, useNum));
|
|
|
+ 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));
|
|
|
}
|
|
|
});
|
|
|
@@ -588,15 +604,15 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
* 初定取消还分销商库存
|
|
|
*/
|
|
|
private void preCancelReduceStockDistributor(Long orderId, Integer type) {
|
|
|
- if(orderId == null) {
|
|
|
+ if (orderId == null) {
|
|
|
return;
|
|
|
}
|
|
|
//退还航次总库存
|
|
|
//找到初定时扣库存的记录
|
|
|
VoyageStockLogDO voyageStockLogDO = voyageStockLogMapper.selectByOrder(orderId);
|
|
|
- log.info("进入初定还库存操作-orderId:"+orderId);
|
|
|
+ log.info("进入初定还库存操作-orderId:{}", orderId);
|
|
|
if (voyageStockLogDO != null) {
|
|
|
- log.info("进入初定还总库存操作-voyageStockLogDO:"+ JSONObject.toJSONString(voyageStockLogDO));
|
|
|
+ log.info("进入初定还总库存操作-voyageStockLogDO:{}", JSONObject.toJSONString(voyageStockLogDO));
|
|
|
//删除已使用房间记录
|
|
|
voyageStockRoomUsedMapper.deleteByOrderId(orderId);
|
|
|
Long voyageId = voyageStockLogDO.getVoyageId();
|
|
|
@@ -605,7 +621,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
//还航次总库存
|
|
|
BigDecimal totalNum = voyageStockLogDO.getVirtualNum().add(voyageStockLogDO.getRealNum());
|
|
|
//退回共享库存
|
|
|
- if(voyageStockLogDO.getStockType() != null && voyageStockLogDO.getStockType() == 1) {
|
|
|
+ if (voyageStockLogDO.getStockType() != null && voyageStockLogDO.getStockType() == 1) {
|
|
|
stockDO.setShareNum(stockDO.getShareNum().add(voyageStockLogDO.getShareNum()));
|
|
|
}
|
|
|
//退回虚拟库存
|
|
|
@@ -622,19 +638,19 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
//删除航次库存操作记录
|
|
|
voyageStockLogMapper.deleteById(voyageStockLogDO);
|
|
|
} else {
|
|
|
- log.error("订单取消时,未找到对应的航次库存操作记录,订单ID:{}", orderId);
|
|
|
+ log.error("订单取消时1,未找到对应的航次库存操作记录,订单ID:{}", orderId);
|
|
|
return;
|
|
|
}
|
|
|
Long voyageId = voyageStockLogDO.getVoyageId();
|
|
|
Long distributorId = voyageStockLogDO.getDistributorId();
|
|
|
//找到初定时扣库存详情的记录
|
|
|
List<VoyageStockDetailLogDO> detailLogList = voyageStockDetailLogMapper.selectListByOrder(orderId);
|
|
|
- if(detailLogList.isEmpty()){
|
|
|
+ if (detailLogList.isEmpty()) {
|
|
|
log.error("订单取消时,未找到对应的航次库存详情操作记录,订单ID:{}", orderId);
|
|
|
return;
|
|
|
}
|
|
|
Integer stockType = detailLogList.get(0).getStockType();
|
|
|
- log.info("进入初定还库存详情操作,使用库存的记录-detailLogList:" + JSONArray.toJSONString(detailLogList));
|
|
|
+ log.info("进入初定还库存详情操作,使用库存的记录-detailLogList:{}", JSONArray.toJSONString(detailLogList));
|
|
|
//退还航次库存详情
|
|
|
List<VoyageStockDetailDO> stockDetailList = voyageStockDetailMapper.selectListByVoyageId(voyageId);
|
|
|
Map<String, BigDecimal> realNumMap = CollectionUtils.convertMap(detailLogList, item -> item.getRoomModelId() + "_" + item.getFloor(), VoyageStockDetailLogDO::getRealNum);
|
|
|
@@ -648,7 +664,8 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
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) {//共享库存要还回库存详情
|
|
|
+ if (stockType == 1) {
|
|
|
+ //共享库存要还回库存详情
|
|
|
item.setShareNum(item.getShareNum().add(totalNumMap.get(key)));
|
|
|
}
|
|
|
});
|
|
|
@@ -669,21 +686,21 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
if (list != null && !list.isEmpty()) {
|
|
|
list.forEach(item -> {
|
|
|
String key = item.getRoomModelId() + "_" + item.getFloor();
|
|
|
- if(item.getBookNum()==null){
|
|
|
+ if (item.getBookNum() == null) {
|
|
|
item.setBookNum(BigDecimal.ZERO);
|
|
|
}
|
|
|
- if(item.getNum()==null){
|
|
|
+ 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){
|
|
|
+ if (item.getBookNum().compareTo(BigDecimal.ZERO) < 0) {
|
|
|
item.setBookNum(BigDecimal.ZERO);
|
|
|
}
|
|
|
});
|
|
|
log.info("进入初定还分销商库存详情操作,分销商库存还之后详情-distributeNewRespList:{}", JSONArray.toJSONString(distributeNewRespList));
|
|
|
voyageStockDistributeNewMapper.updateBatch(list);
|
|
|
- productRedisUtils.set(ProductRedisKeyConstants.STOCK_DISTRIBUTOR_REDIS_KEY_PREFIX + voyageId + "_" +distributorId, list);
|
|
|
+ productRedisUtils.set(ProductRedisKeyConstants.STOCK_DISTRIBUTOR_REDIS_KEY_PREFIX + voyageId + "_" + distributorId, list);
|
|
|
}
|
|
|
}
|
|
|
// 删除库存详情初定记录
|
|
|
@@ -694,10 +711,9 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
|
|
|
/**
|
|
|
* 初定扣分销商库存
|
|
|
- *
|
|
|
*/
|
|
|
private void preReduceStockDistributor(ReduceStockReqDTO reqDTO) {
|
|
|
- log.info("进入初定扣库存操作-orderId:"+reqDTO.getOrderId());
|
|
|
+ log.info("进入初定扣库存操作-orderId:{}", reqDTO.getOrderId());
|
|
|
//航次库存操作日志
|
|
|
VoyageStockLogDO voyageStockLogDO = new VoyageStockLogDO();
|
|
|
//航次库存详情操作日志
|
|
|
@@ -725,7 +741,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
voyageStockLogDO.setStoreId(storeId);
|
|
|
// 获取航次总库存
|
|
|
VoyageStockDO stockDO = productRedisUtils.get(ProductRedisKeyConstants.STOCK_TOTAL_REDIS_KEY_PREFIX + voyageId, VoyageStockDO.class, 1);
|
|
|
- if(stockDO == null) {
|
|
|
+ if (stockDO == null) {
|
|
|
stockDO = voyageStockMapper.selectById(voyageId);
|
|
|
}
|
|
|
if (stockDO == null) {
|
|
|
@@ -736,7 +752,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
|
|
|
//航次库存详情
|
|
|
List<VoyageStockDetailDO> stockDetailList = productRedisUtils.getList(ProductRedisKeyConstants.STOCK_DETAIL_REDIS_KEY_PREFIX + voyageId, VoyageStockDetailDO.class, 1);
|
|
|
- if(CollectionUtils.isAnyEmpty(stockDetailList)) {
|
|
|
+ if (CollectionUtils.isAnyEmpty(stockDetailList)) {
|
|
|
stockDetailList = voyageStockDetailMapper.selectListByVoyageId(voyageId);
|
|
|
}
|
|
|
//判断分销商库存是否存在
|
|
|
@@ -746,8 +762,8 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
detailReqVO.setObjectId(distributorId);
|
|
|
//先获取非共享库存(分销商库存)
|
|
|
detailReqVO.setEnableShare(YesOrNoEnum.NO.getType());
|
|
|
- List<VoyageStockDistributeNewRespVO> distributeNewRespList = productRedisUtils.getList(ProductRedisKeyConstants.STOCK_DISTRIBUTOR_REDIS_KEY_PREFIX + voyageId+"_"+distributorId, VoyageStockDistributeNewRespVO.class, 1);
|
|
|
- if(CollectionUtils.isAnyEmpty(distributeNewRespList)) {
|
|
|
+ List<VoyageStockDistributeNewRespVO> distributeNewRespList = productRedisUtils.getList(ProductRedisKeyConstants.STOCK_DISTRIBUTOR_REDIS_KEY_PREFIX + voyageId + "_" + distributorId, VoyageStockDistributeNewRespVO.class, 1);
|
|
|
+ if (CollectionUtils.isAnyEmpty(distributeNewRespList)) {
|
|
|
distributeNewRespList = voyageStockDistributeNewService.getDetail(detailReqVO);
|
|
|
}
|
|
|
//订单使用房间详情
|
|
|
@@ -777,7 +793,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
useNum = BigDecimal.ZERO;
|
|
|
}
|
|
|
if (detailShareNum.compareTo(useNum) < 0) {
|
|
|
- log.error(String.format(VOYAGE_SHARE_ROOM_NOT_ENOUGH.getMsg(), item.getRoomModelName(), item.getFloor(), detailShareNum, useNum));
|
|
|
+ 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));
|
|
|
}
|
|
|
});
|
|
|
@@ -790,7 +806,8 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
//航次库存详情操作日志
|
|
|
VoyageStockDetailLogDO voyageStockDetailLogDO = new VoyageStockDetailLogDO();
|
|
|
voyageStockDetailLogDO.setVoyageId(voyageId);
|
|
|
- voyageStockDetailLogDO.setType(2);//标识减少
|
|
|
+ //标识减少
|
|
|
+ voyageStockDetailLogDO.setType(2);
|
|
|
voyageStockDetailLogDO.setOrderId(orderId);
|
|
|
voyageStockDetailLogDO.setOrderStatus(orderStatus);
|
|
|
voyageStockDetailLogDO.setOperateType(VoyageStockLogTypeEnum.ORDER_PRE_SUB.getValue());
|
|
|
@@ -798,7 +815,8 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
voyageStockDetailLogDO.setFloor(item.getFloor());
|
|
|
voyageStockDetailLogDO.setDistributorId(distributorId);
|
|
|
voyageStockDetailLogDO.setStoreId(storeId);
|
|
|
- voyageStockDetailLogDO.setStockType(1); //1共享库存
|
|
|
+ //1共享库存
|
|
|
+ voyageStockDetailLogDO.setStockType(1);
|
|
|
|
|
|
|
|
|
// 减可售房间数
|
|
|
@@ -863,7 +881,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
useNum = BigDecimal.ZERO;
|
|
|
}
|
|
|
if (canSellNum.compareTo(useNum) < 0) {
|
|
|
- log.error(String.format(VOYAGE_DISTRIBUTOR_ROOM_NOT_ENOUGH.getMsg(), item.getRoomModelName(), item.getFloor(), canSellNum, useNum));
|
|
|
+ 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));
|
|
|
}
|
|
|
});
|
|
|
@@ -905,7 +923,8 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
voyageStockDetailLogDO.setFloor(item.getFloor());
|
|
|
voyageStockDetailLogDO.setDistributorId(distributorId);
|
|
|
voyageStockDetailLogDO.setStoreId(storeId);
|
|
|
- voyageStockDetailLogDO.setStockType(2); //2分销商库存
|
|
|
+ //2分销商库存
|
|
|
+ voyageStockDetailLogDO.setStockType(2);
|
|
|
|
|
|
// 减可售房间数
|
|
|
item.setCanSellNum(item.getCanSellNum().subtract(useNum));
|
|
|
@@ -979,7 +998,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
if (!roomUsedList.isEmpty()) {
|
|
|
voyageStockRoomUsedMapper.insertBatch(roomUsedList);
|
|
|
}
|
|
|
-
|
|
|
+ voyageStockLogDO.setTenantId(stockDO.getTenantId());
|
|
|
// 添加库存日志
|
|
|
voyageStockLogMapper.insert(voyageStockLogDO);
|
|
|
// 添加库存详情日志
|