|
|
@@ -1,5 +1,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.yc.ship.framework.common.util.collection.CollectionUtils;
|
|
|
import com.yc.ship.framework.common.util.object.BeanUtils;
|
|
|
@@ -98,7 +100,9 @@ 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());
|
|
|
preCancelReduceStockDistributor(reqDTO.getOldOrderId(), reqDTO.getType());
|
|
|
}
|
|
|
//再去扣初定的库存
|
|
|
@@ -207,7 +211,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
}
|
|
|
//退还航次总库存
|
|
|
//找到确定时扣库存的记录
|
|
|
- VoyageStockLogDO voyageStockLogDO = voyageStockLogMapper.selectByOrder(orderId, TradeOrderStatusEnum.UNUSED.getStatus());
|
|
|
+ VoyageStockLogDO voyageStockLogDO = voyageStockLogMapper.selectByOrder(orderId);
|
|
|
if (voyageStockLogDO != null) {
|
|
|
//删除已使用房间记录
|
|
|
voyageStockRoomUsedMapper.deleteByOrderId(orderId);
|
|
|
@@ -232,13 +236,14 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
Long voyageId = voyageStockLogDO.getVoyageId();
|
|
|
Long distributorId = voyageStockLogDO.getDistributorId();
|
|
|
//找到初定时扣库存详情的记录
|
|
|
- List<VoyageStockDetailLogDO> detailLogList = voyageStockDetailLogMapper.selectListByOrder(orderId, TradeOrderStatusEnum.UNUSED.getStatus());
|
|
|
+ List<VoyageStockDetailLogDO> detailLogList = voyageStockDetailLogMapper.selectListByOrder(orderId);
|
|
|
if (detailLogList != null && !detailLogList.isEmpty()) {
|
|
|
+ Integer stockType = detailLogList.get(0).getStockType();
|
|
|
//退还航次库存详情
|
|
|
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 -> {
|
|
|
@@ -247,11 +252,14 @@ 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) {//使用的是共享库存,才退回共享库存
|
|
|
+ item.setShareNum(item.getShareNum().add(totalNumMap.get(key)));
|
|
|
+ }
|
|
|
});
|
|
|
voyageStockDetailMapper.updateBatch(stockDetailList);
|
|
|
productRedisUtils.set(ProductRedisKeyConstants.STOCK_DETAIL_REDIS_KEY_PREFIX + voyageId, stockDetailList);
|
|
|
|
|
|
- Integer stockType = detailLogList.get(0).getStockType();
|
|
|
+
|
|
|
//2:还分销商库存
|
|
|
if (stockType == 2) {
|
|
|
//判断分销商库存是否存在
|
|
|
@@ -268,11 +276,11 @@ 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, list);
|
|
|
+ productRedisUtils.set(ProductRedisKeyConstants.STOCK_DISTRIBUTOR_REDIS_KEY_PREFIX + voyageId+"_"+distributorId, list);
|
|
|
}
|
|
|
}
|
|
|
// 删除库存详情初定记录
|
|
|
- voyageStockDetailLogMapper.deleteByOrder(orderId, TradeOrderStatusEnum.UNUSED.getStatus());
|
|
|
+ voyageStockDetailLogMapper.deleteByOrder(orderId);
|
|
|
|
|
|
}
|
|
|
}
|
|
|
@@ -327,7 +335,7 @@ 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, VoyageStockDistributeNewRespVO.class, 1);
|
|
|
+ List<VoyageStockDistributeNewRespVO> distributeNewResps = productRedisUtils.getList(ProductRedisKeyConstants.STOCK_DISTRIBUTOR_REDIS_KEY_PREFIX + voyageId+"_"+distributorId, VoyageStockDistributeNewRespVO.class, 1);
|
|
|
if(CollectionUtils.isAnyEmpty(distributeNewResps)) {
|
|
|
distributeNewResps = voyageStockDistributeNewService.getDetail(detailReqVO);
|
|
|
}
|
|
|
@@ -344,18 +352,19 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
voyageStockLogDO.setStockType(1);
|
|
|
//判断共享库存是否充足
|
|
|
if (shareNum.compareTo(totalUseNum) < 0) {
|
|
|
- throw exception(VOYAGE_SHARE_STOCK_NOT_ENOUGH);
|
|
|
+ throw exception0(VOYAGE_SHARE_STOCK_NOT_ENOUGH.getCode(), String.format(VOYAGE_SHARE_STOCK_NOT_ENOUGH.getMsg(), shareNum, totalUseNum));
|
|
|
}
|
|
|
//判断航次房型楼层库存是否充足
|
|
|
// 判断库存是否充足
|
|
|
stockDetailList.forEach(item -> {
|
|
|
- BigDecimal canSellNum = item.getCanSellNum();
|
|
|
+ BigDecimal detailShareNum = item.getShareNum();
|
|
|
BigDecimal useNum = roomModelFloorNumMap.get(item.getRoomModelId() + "_" + item.getFloor());
|
|
|
if (useNum == null) {
|
|
|
useNum = BigDecimal.ZERO;
|
|
|
}
|
|
|
- if (canSellNum.compareTo(useNum) < 0) {
|
|
|
- throw exception0(VOYAGE_SHARE_ROOM_NOT_ENOUGH.getCode(), String.format(VOYAGE_SHARE_ROOM_NOT_ENOUGH.getMsg(), item.getRoomModelName(), item.getFloor()));
|
|
|
+ if (detailShareNum.compareTo(useNum) < 0) {
|
|
|
+ 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));
|
|
|
}
|
|
|
});
|
|
|
// 库存充足,扣库存详情
|
|
|
@@ -441,7 +450,8 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
useNum = BigDecimal.ZERO;
|
|
|
}
|
|
|
if (canSellNum.compareTo(useNum) < 0) {
|
|
|
- throw exception0(VOYAGE_DISTRIBUTOR_ROOM_NOT_ENOUGH.getCode(), String.format(VOYAGE_DISTRIBUTOR_ROOM_NOT_ENOUGH.getMsg(), item.getRoomModelName(), item.getFloor()));
|
|
|
+ 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));
|
|
|
}
|
|
|
});
|
|
|
// 扣分销商库存
|
|
|
@@ -574,8 +584,10 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
}
|
|
|
//退还航次总库存
|
|
|
//找到初定时扣库存的记录
|
|
|
- VoyageStockLogDO voyageStockLogDO = voyageStockLogMapper.selectByOrder(orderId, TradeOrderStatusEnum.YD.getStatus());
|
|
|
+ VoyageStockLogDO voyageStockLogDO = voyageStockLogMapper.selectByOrder(orderId);
|
|
|
+ log.info("进入初定还库存操作-orderId:"+orderId);
|
|
|
if (voyageStockLogDO != null) {
|
|
|
+ log.info("进入初定还总库存操作-voyageStockLogDO:"+ JSONObject.toJSONString(voyageStockLogDO));
|
|
|
//删除已使用房间记录
|
|
|
voyageStockRoomUsedMapper.deleteByOrderId(orderId);
|
|
|
Long voyageId = voyageStockLogDO.getVoyageId();
|
|
|
@@ -605,9 +617,10 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
Long voyageId = voyageStockLogDO.getVoyageId();
|
|
|
Long distributorId = voyageStockLogDO.getDistributorId();
|
|
|
//找到初定时扣库存详情的记录
|
|
|
- List<VoyageStockDetailLogDO> detailLogList = voyageStockDetailLogMapper.selectListByOrder(orderId, TradeOrderStatusEnum.YD.getStatus());
|
|
|
+ List<VoyageStockDetailLogDO> detailLogList = voyageStockDetailLogMapper.selectListByOrder(orderId);
|
|
|
Integer stockType = detailLogList.get(0).getStockType();
|
|
|
if (detailLogList != null && !detailLogList.isEmpty()) {
|
|
|
+ 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);
|
|
|
@@ -638,6 +651,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
detailReqVO.setObjectId(distributorId);
|
|
|
List<VoyageStockDistributeNewRespVO> distributeNewRespList = voyageStockDistributeNewService.getDetail(detailReqVO);
|
|
|
List<VoyageStockDistributeNewDO> list = BeanUtils.toBean(distributeNewRespList, VoyageStockDistributeNewDO.class);
|
|
|
+ log.info("进入初定还分销商库存详情操作,分销商库存还之前详情-distributeNewRespList:"+ JSONArray.toJSONString(distributeNewRespList));
|
|
|
if (list != null && !list.isEmpty()) {
|
|
|
list.forEach(item -> {
|
|
|
String key = item.getRoomModelId() + "_" + item.getFloor();
|
|
|
@@ -653,12 +667,13 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
item.setBookNum(BigDecimal.ZERO);
|
|
|
}
|
|
|
});
|
|
|
+ log.info("进入初定还分销商库存详情操作,分销商库存还之后详情-distributeNewRespList:"+ JSONArray.toJSONString(distributeNewRespList));
|
|
|
voyageStockDistributeNewMapper.updateBatch(list);
|
|
|
- productRedisUtils.set(ProductRedisKeyConstants.STOCK_DISTRIBUTOR_REDIS_KEY_PREFIX + voyageId, list);
|
|
|
+ productRedisUtils.set(ProductRedisKeyConstants.STOCK_DISTRIBUTOR_REDIS_KEY_PREFIX + voyageId + "_" +distributorId, list);
|
|
|
}
|
|
|
}
|
|
|
// 删除库存详情初定记录
|
|
|
- voyageStockDetailLogMapper.deleteByOrder(orderId, TradeOrderStatusEnum.YD.getStatus());
|
|
|
+ voyageStockDetailLogMapper.deleteByOrder(orderId);
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -670,6 +685,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
*
|
|
|
*/
|
|
|
private void preReduceStockDistributor(ReduceStockReqDTO reqDTO) {
|
|
|
+ log.info("进入初定扣库存操作-orderId:"+reqDTO.getOrderId());
|
|
|
//航次库存操作日志
|
|
|
VoyageStockLogDO voyageStockLogDO = new VoyageStockLogDO();
|
|
|
//航次库存详情操作日志
|
|
|
@@ -718,7 +734,7 @@ 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, VoyageStockDistributeNewRespVO.class, 1);
|
|
|
+ List<VoyageStockDistributeNewRespVO> distributeNewRespList = productRedisUtils.getList(ProductRedisKeyConstants.STOCK_DISTRIBUTOR_REDIS_KEY_PREFIX + voyageId+"_"+distributorId, VoyageStockDistributeNewRespVO.class, 1);
|
|
|
if(CollectionUtils.isAnyEmpty(distributeNewRespList)) {
|
|
|
distributeNewRespList = voyageStockDistributeNewService.getDetail(detailReqVO);
|
|
|
}
|
|
|
@@ -736,7 +752,7 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
voyageStockLogDO.setStockType(1);
|
|
|
//判断共享库存是否充足
|
|
|
if (shareNum.compareTo(totalUseNum) < 0) {
|
|
|
- throw exception(VOYAGE_SHARE_STOCK_NOT_ENOUGH);
|
|
|
+ throw exception0(VOYAGE_SHARE_STOCK_NOT_ENOUGH.getCode(), String.format(VOYAGE_SHARE_STOCK_NOT_ENOUGH.getMsg(), shareNum, totalUseNum));
|
|
|
}
|
|
|
//判断航次房型楼层库存是否充足
|
|
|
// 判断库存是否充足
|
|
|
@@ -749,8 +765,8 @@ 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()));
|
|
|
- throw exception0(VOYAGE_SHARE_ROOM_NOT_ENOUGH.getCode(), 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(), detailShareNum, useNum));
|
|
|
+ throw exception0(VOYAGE_SHARE_ROOM_NOT_ENOUGH.getCode(), String.format(VOYAGE_SHARE_ROOM_NOT_ENOUGH.getMsg(), item.getRoomModelName(), item.getFloor(), detailShareNum, useNum));
|
|
|
}
|
|
|
});
|
|
|
// 库存充足,扣库存详情
|
|
|
@@ -835,7 +851,8 @@ public class VoyageApiImpl implements VoyageApi {
|
|
|
useNum = BigDecimal.ZERO;
|
|
|
}
|
|
|
if (canSellNum.compareTo(useNum) < 0) {
|
|
|
- throw exception0(VOYAGE_DISTRIBUTOR_ROOM_NOT_ENOUGH.getCode(), String.format(VOYAGE_DISTRIBUTOR_ROOM_NOT_ENOUGH.getMsg(), item.getRoomModelName(), item.getFloor()));
|
|
|
+ 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));
|
|
|
}
|
|
|
});
|
|
|
// 扣分销商库存
|