|
|
@@ -36,6 +36,7 @@ import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
import static com.yc.ship.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
@@ -43,7 +44,7 @@ import static com.yc.ship.module.product.enums.ErrorCodeConstants.*;
|
|
|
|
|
|
@Service
|
|
|
@Slf4j
|
|
|
-public class VoyageApiImpl implements VoyageApi{
|
|
|
+public class VoyageApiImpl implements VoyageApi {
|
|
|
|
|
|
@Resource
|
|
|
private VoyageStockDistributeNewMapper voyageStockDistributeNewMapper;
|
|
|
@@ -84,7 +85,7 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
try {
|
|
|
lock.lock(60, TimeUnit.SECONDS);
|
|
|
Integer type = reqDTO.getType();//判断是分销商还是门店下单 1:分销商,2:门店
|
|
|
- if (type == DistributorOrStoreEnum.DISTRIBUTOR.getValue()) {//分销商下单,当前阶段不考虑门店下单
|
|
|
+ if (Objects.equals(type, DistributorOrStoreEnum.DISTRIBUTOR.getValue())) {//分销商下单,当前阶段不考虑门店下单
|
|
|
//分销商下单只扣分销商库存,默认是OTA,默认OTC只能门店下单
|
|
|
//初定扣分销商库存
|
|
|
//先返还初定扣的库存
|
|
|
@@ -92,8 +93,8 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
//再去扣初定的库存
|
|
|
preReduceStockDistributor(reqDTO);
|
|
|
}
|
|
|
- }finally {
|
|
|
- if(lock.isHeldByCurrentThread() && lock.isLocked()){
|
|
|
+ } finally {
|
|
|
+ if (lock.isHeldByCurrentThread() && lock.isLocked()) {
|
|
|
lock.unlock();
|
|
|
}
|
|
|
}
|
|
|
@@ -111,13 +112,13 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
try {
|
|
|
lock.lock(60, TimeUnit.SECONDS);
|
|
|
Integer type = reqDTO.getType();//判断是分销商还是门店下单 1:分销商,2:门店
|
|
|
- if (type == DistributorOrStoreEnum.DISTRIBUTOR.getValue()) {//分销商下单,当前阶段不考虑门店下单
|
|
|
+ if (Objects.equals(type, DistributorOrStoreEnum.DISTRIBUTOR.getValue())) {//分销商下单,当前阶段不考虑门店下单
|
|
|
//分销商下单只扣分销商库存,默认是OTA,默认OTC只能门店下单
|
|
|
//初定扣分销商库存
|
|
|
preCancelReduceStockDistributor(reqDTO.getOrderId(), reqDTO.getType());
|
|
|
}
|
|
|
- }finally {
|
|
|
- if(lock.isHeldByCurrentThread() && lock.isLocked()){
|
|
|
+ } finally {
|
|
|
+ if (lock.isHeldByCurrentThread() && lock.isLocked()) {
|
|
|
lock.unlock();
|
|
|
}
|
|
|
}
|
|
|
@@ -135,7 +136,7 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
try {
|
|
|
lock.lock(60, TimeUnit.SECONDS);
|
|
|
Integer type = reqDTO.getType();//判断是分销商还是门店下单 1:分销商,2:门店
|
|
|
- if (type == DistributorOrStoreEnum.DISTRIBUTOR.getValue()) {//分销商下单,当前阶段不考虑门店下单
|
|
|
+ if (Objects.equals(type, DistributorOrStoreEnum.DISTRIBUTOR.getValue())) {//分销商下单,当前阶段不考虑门店下单
|
|
|
//分销商下单只扣分销商库存,默认是OTA,默认OTC只能门店下单
|
|
|
//初定扣分销商库存
|
|
|
//先返还初定扣的库存
|
|
|
@@ -143,8 +144,8 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
//再去扣确定的库存
|
|
|
reduceStockDistributor(reqDTO);
|
|
|
}
|
|
|
- }finally {
|
|
|
- if(lock.isHeldByCurrentThread() && lock.isLocked()){
|
|
|
+ } finally {
|
|
|
+ if (lock.isHeldByCurrentThread() && lock.isLocked()) {
|
|
|
lock.unlock();
|
|
|
}
|
|
|
}
|
|
|
@@ -161,13 +162,13 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
try {
|
|
|
lock.lock(60, TimeUnit.SECONDS);
|
|
|
Integer type = reqDTO.getType();//判断是分销商还是门店下单 1:分销商,2:门店
|
|
|
- if (type == DistributorOrStoreEnum.DISTRIBUTOR.getValue()) {//分销商下单,当前阶段不考虑门店下单
|
|
|
+ if (Objects.equals(type, DistributorOrStoreEnum.DISTRIBUTOR.getValue())) {//分销商下单,当前阶段不考虑门店下单
|
|
|
//分销商下单只扣分销商库存,默认是OTA,默认OTC只能门店下单
|
|
|
//初定扣分销商库存
|
|
|
cancelReduceStockDistributor(reqDTO.getOrderId(), reqDTO.getType());
|
|
|
}
|
|
|
- }finally {
|
|
|
- if(lock.isHeldByCurrentThread() && lock.isLocked()){
|
|
|
+ } finally {
|
|
|
+ if (lock.isHeldByCurrentThread() && lock.isLocked()) {
|
|
|
lock.unlock();
|
|
|
}
|
|
|
}
|
|
|
@@ -175,14 +176,12 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
|
|
|
/**
|
|
|
* 确定状态时取消订单还库存
|
|
|
- * @param orderId
|
|
|
- * @param type
|
|
|
*/
|
|
|
private void cancelReduceStockDistributor(Long orderId, Integer type) {
|
|
|
//退还航次总库存
|
|
|
//找到确定时扣库存的记录
|
|
|
VoyageStockLogDO voyageStockLogDO = voyageStockLogMapper.selectByOrder(orderId, TradeOrderStatusEnum.UNUSED.getStatus());
|
|
|
- if(voyageStockLogDO != null){
|
|
|
+ if (voyageStockLogDO != null) {
|
|
|
//删除已使用房间记录
|
|
|
voyageStockRoomUsedMapper.deleteByOrderId(orderId);
|
|
|
Long voyageId = voyageStockLogDO.getVoyageId();
|
|
|
@@ -198,7 +197,7 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
voyageStockMapper.updateById(stockDO);//更新航次总库存
|
|
|
//删除航次库存操作记录
|
|
|
voyageStockLogMapper.deleteById(voyageStockLogDO);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
log.error("订单取消时,未找到对应的航次库存操作记录,订单ID:{}", orderId);
|
|
|
return;
|
|
|
}
|
|
|
@@ -206,7 +205,7 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
Long distributorId = voyageStockLogDO.getDistributorId();
|
|
|
//找到初定时扣库存详情的记录
|
|
|
List<VoyageStockDetailLogDO> detailLogList = voyageStockDetailLogMapper.selectListByOrder(orderId, TradeOrderStatusEnum.UNUSED.getStatus());
|
|
|
- if(detailLogList != null && detailLogList.size() > 0) {
|
|
|
+ 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);
|
|
|
@@ -214,7 +213,7 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
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 -> {
|
|
|
+ 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)));
|
|
|
@@ -225,16 +224,16 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
|
|
|
Integer stockType = detailLogList.get(0).getStockType();
|
|
|
|
|
|
- if(stockType == 2) { //2:还分销商库存
|
|
|
+ if (stockType == 2) { //2:还分销商库存
|
|
|
//判断分销商库存是否存在
|
|
|
VoyageStockDistributeNewDetailReqVO detailReqVO = new VoyageStockDistributeNewDetailReqVO();
|
|
|
detailReqVO.setVoyageId(voyageId);
|
|
|
detailReqVO.setType(type);
|
|
|
detailReqVO.setObjectId(distributorId);
|
|
|
- List<VoyageStockDistributeNewRespVO> distributeNewRespVOS = voyageStockDistributeNewService.getDetail(detailReqVO);
|
|
|
+ List<VoyageStockDistributeNewRespVO> distributeNewRespVOS = voyageStockDistributeNewService.getDetail(detailReqVO);
|
|
|
List<VoyageStockDistributeNewDO> list = BeanUtils.toBean(distributeNewRespVOS, VoyageStockDistributeNewDO.class);
|
|
|
- if(list != null && list.size() > 0) {
|
|
|
- list.stream().forEach(item -> {
|
|
|
+ if (list != null && !list.isEmpty()) {
|
|
|
+ list.forEach(item -> {
|
|
|
String key = item.getRoomModelId() + "_" + item.getFloor();
|
|
|
item.setNum(item.getNum().add(totalNumMap.get(key)));
|
|
|
item.setBookNum(item.getBookNum().subtract(totalNumMap.get(key)));
|
|
|
@@ -250,6 +249,7 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
|
|
|
/**
|
|
|
* 确定时扣库存,有限扣实际库存,不足再扣虚拟库存
|
|
|
+ *
|
|
|
* @param reqDTO
|
|
|
*/
|
|
|
private void reduceStockDistributor(ReduceStockReqDTO reqDTO) {
|
|
|
@@ -275,7 +275,7 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
voyageStockLogDO.setStoreId(storeId);
|
|
|
// 获取航次总库存
|
|
|
VoyageStockDO stockDO = voyageStockMapper.selectById(voyageId);
|
|
|
- if(stockDO == null) {
|
|
|
+ if (stockDO == null) {
|
|
|
throw exception(VOYAGE_NO_STOCK);
|
|
|
}
|
|
|
//共享库存
|
|
|
@@ -289,7 +289,7 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
detailReqVO.setVoyageId(voyageId);
|
|
|
detailReqVO.setType(type);
|
|
|
detailReqVO.setObjectId(distributorId);
|
|
|
- List<VoyageStockDistributeNewRespVO> distributeNewRespVOS = voyageStockDistributeNewService.getDetail(detailReqVO);
|
|
|
+ List<VoyageStockDistributeNewRespVO> distributeNewRespVOS = voyageStockDistributeNewService.getDetail(detailReqVO);
|
|
|
List<OrderRoomUseDTO> orderRoomList = reqDTO.getOrderRoomList();//订单使用房间详情
|
|
|
List<Long> roomIds = CollectionUtils.convertList(orderRoomList, OrderRoomUseDTO::getRoomId);
|
|
|
List<RoomRespDTO> roomList = roomApi.getRoomListByIds(roomIds);
|
|
|
@@ -297,29 +297,29 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
Map<String, BigDecimal> roomModelFloorNumMap = CollectionUtils.convertMap(roomList,
|
|
|
item -> item.getRoomModelId() + "_" + item.getFloors(),
|
|
|
item -> roomMap.get(item.getId()) == null ? BigDecimal.ZERO : roomMap.get(item.getId()));
|
|
|
- if(distributeNewRespVOS.isEmpty()) {//分销商未分配库存,扣共享库存
|
|
|
+ if (distributeNewRespVOS.isEmpty()) {//分销商未分配库存,扣共享库存
|
|
|
|
|
|
voyageStockLogDO.setStockType(1); //1共享库存
|
|
|
//判断共享库存是否充足
|
|
|
- if(shareNum.compareTo(totalUseNum) < 0) {
|
|
|
+ if (shareNum.compareTo(totalUseNum) < 0) {
|
|
|
throw exception(VOYAGE_SHARE_STOCK_NOT_ENOUGH);
|
|
|
}
|
|
|
//判断航次房型楼层库存是否充足
|
|
|
// 判断库存是否充足
|
|
|
- stockDetailList.stream().forEach(item -> {
|
|
|
+ stockDetailList.forEach(item -> {
|
|
|
BigDecimal canSellNum = item.getCanSellNum();
|
|
|
BigDecimal useNum = roomModelFloorNumMap.get(item.getRoomModelId() + "_" + item.getFloor());
|
|
|
- if(useNum == null) {
|
|
|
+ if (useNum == null) {
|
|
|
useNum = BigDecimal.ZERO;
|
|
|
}
|
|
|
- if(canSellNum.compareTo(useNum) < 0) {
|
|
|
+ if (canSellNum.compareTo(useNum) < 0) {
|
|
|
throw exception(VOYAGE_SHARE_ROOM_NOT_ENOUGH.getCode(), String.format(VOYAGE_SHARE_ROOM_NOT_ENOUGH.getMsg(), item.getRoomModelName(), item.getFloor()));
|
|
|
}
|
|
|
});
|
|
|
// 库存充足,扣库存详情
|
|
|
- stockDetailList.stream().forEach(item -> {
|
|
|
+ stockDetailList.forEach(item -> {
|
|
|
BigDecimal useNum = roomModelFloorNumMap.get(item.getRoomModelId() + "_" + item.getFloor());
|
|
|
- if(useNum == null) {
|
|
|
+ if (useNum == null) {
|
|
|
useNum = BigDecimal.ZERO;
|
|
|
}
|
|
|
//航次库存详情操作日志
|
|
|
@@ -339,11 +339,11 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
// 减可售房间数
|
|
|
item.setCanSellNum(item.getCanSellNum().subtract(useNum));
|
|
|
// 减实际房间数,此处确定,先扣实际库存,实际库存不足再扣细虚拟库存
|
|
|
- if(item.getRealTotalNum().compareTo(useNum) >= 0) {
|
|
|
+ if (item.getRealTotalNum().compareTo(useNum) >= 0) {
|
|
|
voyageStockDetailLogDO.setVirtualNum(BigDecimal.ZERO);
|
|
|
voyageStockDetailLogDO.setRealNum(useNum);
|
|
|
item.setRealTotalNum(item.getRealTotalNum().subtract(useNum));
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
voyageStockDetailLogDO.setVirtualNum(useNum.subtract(item.getRealTotalNum()));
|
|
|
voyageStockDetailLogDO.setRealNum(useNum);
|
|
|
item.setRealTotalNum(BigDecimal.ZERO);
|
|
|
@@ -363,11 +363,11 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
// 减可售房间数
|
|
|
stockDO.setCanSellNum(stockDO.getCanSellNum().subtract(totalUseNum));
|
|
|
// 减实际房间数,此处确定,先扣实际库存,实际库存不足再扣虚拟库存
|
|
|
- if(stockDO.getRealTotalNum().compareTo(totalUseNum) >= 0) {
|
|
|
+ if (stockDO.getRealTotalNum().compareTo(totalUseNum) >= 0) {
|
|
|
stockDO.setRealTotalNum(stockDO.getRealTotalNum().subtract(totalUseNum));
|
|
|
voyageStockLogDO.setVirtualNum(BigDecimal.ZERO);
|
|
|
voyageStockLogDO.setRealNum(totalUseNum);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
voyageStockLogDO.setRealNum(stockDO.getRealTotalNum());
|
|
|
voyageStockLogDO.setVirtualNum(totalUseNum.subtract(voyageStockLogDO.getRealNum()));
|
|
|
stockDO.setRealTotalNum(BigDecimal.ZERO);
|
|
|
@@ -380,29 +380,29 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
stockDO.setShareNum(stockDO.getShareNum().subtract(totalUseNum));
|
|
|
voyageStockLogDO.setShareNum(totalUseNum);
|
|
|
voyageStockMapper.updateById(stockDO);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
|
|
|
voyageStockLogDO.setStockType(2); //2分销商库存
|
|
|
|
|
|
//分销商已分配库存,扣自身库存
|
|
|
|
|
|
//判断航次房型楼层库存是否充足
|
|
|
- distributeNewRespVOS.stream().forEach(item -> {
|
|
|
+ distributeNewRespVOS.forEach(item -> {
|
|
|
BigDecimal canSellNum = item.getNum();
|
|
|
BigDecimal useNum = roomModelFloorNumMap.get(item.getRoomModelId() + "_" + item.getFloor());
|
|
|
- if(useNum == null) {
|
|
|
+ if (useNum == null) {
|
|
|
useNum = BigDecimal.ZERO;
|
|
|
}
|
|
|
- if(canSellNum.compareTo(useNum) < 0) {
|
|
|
+ if (canSellNum.compareTo(useNum) < 0) {
|
|
|
throw exception(VOYAGE_DISTRIBUTOR_ROOM_NOT_ENOUGH.getCode(), String.format(VOYAGE_DISTRIBUTOR_ROOM_NOT_ENOUGH.getMsg(), item.getRoomModelName(), item.getFloor()));
|
|
|
}
|
|
|
});
|
|
|
// 扣分销商库存
|
|
|
// 库存充足,扣库存详情
|
|
|
List<VoyageStockDistributeNewDO> list = BeanUtils.toBean(distributeNewRespVOS, VoyageStockDistributeNewDO.class);
|
|
|
- list.stream().forEach(item -> {
|
|
|
+ list.forEach(item -> {
|
|
|
BigDecimal useNum = roomModelFloorNumMap.get(item.getRoomModelId() + "_" + item.getFloor());
|
|
|
- if(useNum == null) {
|
|
|
+ if (useNum == null) {
|
|
|
useNum = BigDecimal.ZERO;
|
|
|
}
|
|
|
// 减可售房间数
|
|
|
@@ -414,9 +414,9 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
voyageStockDistributeNewMapper.updateBatch(list);
|
|
|
|
|
|
// 库存充足,扣库存详情
|
|
|
- stockDetailList.stream().forEach(item -> {
|
|
|
+ stockDetailList.forEach(item -> {
|
|
|
BigDecimal useNum = roomModelFloorNumMap.get(item.getRoomModelId() + "_" + item.getFloor());
|
|
|
- if(useNum == null) {
|
|
|
+ if (useNum == null) {
|
|
|
useNum = BigDecimal.ZERO;
|
|
|
}
|
|
|
|
|
|
@@ -436,11 +436,11 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
// 减可售房间数
|
|
|
item.setCanSellNum(item.getCanSellNum().subtract(useNum));
|
|
|
// 减实际房间数,此处确定,先扣实际库存,实际库存不足再扣实际库存
|
|
|
- if(item.getVirtualNum().compareTo(useNum) >= 0) {
|
|
|
+ if (item.getVirtualNum().compareTo(useNum) >= 0) {
|
|
|
voyageStockDetailLogDO.setRealNum(useNum);
|
|
|
voyageStockDetailLogDO.setVirtualNum(BigDecimal.ZERO);
|
|
|
item.setRealTotalNum(item.getRealTotalNum().subtract(useNum));
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
voyageStockDetailLogDO.setRealNum(item.getRealTotalNum());
|
|
|
voyageStockDetailLogDO.setVirtualNum(totalUseNum.subtract(item.getRealTotalNum()));
|
|
|
item.setRealTotalNum(BigDecimal.ZERO);
|
|
|
@@ -461,11 +461,11 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
// 减剩余房间数
|
|
|
// stockDO.setSurplusNum(stockDO.getSurplusNum().subtract(totalUseNum));
|
|
|
// 减实际房间数,此处确定,先扣实际库存,实际库存不足再扣虚拟库存
|
|
|
- if(stockDO.getRealTotalNum().compareTo(totalUseNum) >= 0) {
|
|
|
+ if (stockDO.getRealTotalNum().compareTo(totalUseNum) >= 0) {
|
|
|
stockDO.setRealTotalNum(stockDO.getRealTotalNum().subtract(totalUseNum));
|
|
|
voyageStockLogDO.setRealNum(totalUseNum);
|
|
|
voyageStockLogDO.setVirtualNum(BigDecimal.ZERO);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
voyageStockLogDO.setRealNum(stockDO.getRealTotalNum());
|
|
|
voyageStockLogDO.setVirtualNum(totalUseNum.subtract(voyageStockLogDO.getRealNum()));
|
|
|
stockDO.setRealTotalNum(BigDecimal.ZERO);
|
|
|
@@ -486,7 +486,7 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
roomUsedDO.setOrderId(orderId);
|
|
|
roomUsedDO.setVoyageId(voyageId);
|
|
|
RoomRespDTO roomRespDTO = roomIdMap.get(item.getRoomId());
|
|
|
- if(roomRespDTO == null) {
|
|
|
+ if (roomRespDTO == null) {
|
|
|
throw exception(VOYAGE_ROOM_NOT_EXIST.getCode(), String.format(VOYAGE_ROOM_NOT_EXIST.getMsg(), item.getRoomId()));
|
|
|
}
|
|
|
roomUsedDO.setRoomModelId(roomRespDTO.getRoomModelId());
|
|
|
@@ -498,14 +498,14 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
});
|
|
|
//先删除当前订单已被使用的房间
|
|
|
voyageStockRoomUsedMapper.deleteByOrderId(orderId);
|
|
|
- if(roomUsedList.size() > 0) {
|
|
|
+ if (!roomUsedList.isEmpty()) {
|
|
|
voyageStockRoomUsedMapper.insertBatch(roomUsedList);
|
|
|
}
|
|
|
|
|
|
// 添加库存日志
|
|
|
voyageStockLogMapper.insert(voyageStockLogDO);
|
|
|
// 添加库存详情日志
|
|
|
- if(detailLogList.size() > 0) {
|
|
|
+ if (!detailLogList.isEmpty()) {
|
|
|
voyageStockDetailLogMapper.insertBatch(detailLogList);
|
|
|
}
|
|
|
}
|
|
|
@@ -517,7 +517,7 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
//退还航次总库存
|
|
|
//找到初定时扣库存的记录
|
|
|
VoyageStockLogDO voyageStockLogDO = voyageStockLogMapper.selectByOrder(orderId, TradeOrderStatusEnum.YD.getStatus());
|
|
|
- if(voyageStockLogDO != null){
|
|
|
+ if (voyageStockLogDO != null) {
|
|
|
//删除已使用房间记录
|
|
|
voyageStockRoomUsedMapper.deleteByOrderId(orderId);
|
|
|
Long voyageId = voyageStockLogDO.getVoyageId();
|
|
|
@@ -533,7 +533,7 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
voyageStockMapper.updateById(stockDO);//更新航次总库存
|
|
|
//删除航次库存操作记录
|
|
|
voyageStockLogMapper.deleteById(voyageStockLogDO);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
log.error("订单取消时,未找到对应的航次库存操作记录,订单ID:{}", orderId);
|
|
|
return;
|
|
|
}
|
|
|
@@ -541,7 +541,7 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
Long distributorId = voyageStockLogDO.getDistributorId();
|
|
|
//找到初定时扣库存详情的记录
|
|
|
List<VoyageStockDetailLogDO> detailLogList = voyageStockDetailLogMapper.selectListByOrder(orderId, TradeOrderStatusEnum.YD.getStatus());
|
|
|
- if(detailLogList != null && detailLogList.size() > 0) {
|
|
|
+ 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);
|
|
|
@@ -549,7 +549,7 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
// 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 -> {
|
|
|
+ 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)));
|
|
|
@@ -560,16 +560,16 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
|
|
|
Integer stockType = detailLogList.get(0).getStockType();
|
|
|
|
|
|
- if(stockType == 2) { //2:还分销商库存
|
|
|
+ if (stockType == 2) { //2:还分销商库存
|
|
|
//判断分销商库存是否存在
|
|
|
VoyageStockDistributeNewDetailReqVO detailReqVO = new VoyageStockDistributeNewDetailReqVO();
|
|
|
detailReqVO.setVoyageId(voyageId);
|
|
|
detailReqVO.setType(type);
|
|
|
detailReqVO.setObjectId(distributorId);
|
|
|
- List<VoyageStockDistributeNewRespVO> distributeNewRespVOS = voyageStockDistributeNewService.getDetail(detailReqVO);
|
|
|
+ List<VoyageStockDistributeNewRespVO> distributeNewRespVOS = voyageStockDistributeNewService.getDetail(detailReqVO);
|
|
|
List<VoyageStockDistributeNewDO> list = BeanUtils.toBean(distributeNewRespVOS, VoyageStockDistributeNewDO.class);
|
|
|
- if(list != null && list.size() > 0) {
|
|
|
- list.stream().forEach(item -> {
|
|
|
+ if (list != null && !list.isEmpty()) {
|
|
|
+ list.forEach(item -> {
|
|
|
String key = item.getRoomModelId() + "_" + item.getFloor();
|
|
|
item.setNum(item.getNum().add(totalNumMap.get(key)));
|
|
|
item.setBookNum(item.getBookNum().subtract(totalNumMap.get(key)));
|
|
|
@@ -583,14 +583,11 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 初定扣分销商库存
|
|
|
+ *
|
|
|
* @param reqDTO
|
|
|
*/
|
|
|
private void preReduceStockDistributor(ReduceStockReqDTO reqDTO) {
|
|
|
@@ -616,7 +613,7 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
voyageStockLogDO.setStoreId(storeId);
|
|
|
// 获取航次总库存
|
|
|
VoyageStockDO stockDO = voyageStockMapper.selectById(voyageId);
|
|
|
- if(stockDO == null) {
|
|
|
+ if (stockDO == null) {
|
|
|
throw exception(VOYAGE_NO_STOCK);
|
|
|
}
|
|
|
//共享库存
|
|
|
@@ -630,7 +627,7 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
detailReqVO.setVoyageId(voyageId);
|
|
|
detailReqVO.setType(type);
|
|
|
detailReqVO.setObjectId(distributorId);
|
|
|
- List<VoyageStockDistributeNewRespVO> distributeNewRespVOS = voyageStockDistributeNewService.getDetail(detailReqVO);
|
|
|
+ List<VoyageStockDistributeNewRespVO> distributeNewRespVOS = voyageStockDistributeNewService.getDetail(detailReqVO);
|
|
|
List<OrderRoomUseDTO> orderRoomList = reqDTO.getOrderRoomList();//订单使用房间详情
|
|
|
List<Long> roomIds = CollectionUtils.convertList(orderRoomList, OrderRoomUseDTO::getRoomId);
|
|
|
List<RoomRespDTO> roomList = roomApi.getRoomListByIds(roomIds);
|
|
|
@@ -638,29 +635,29 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
Map<String, BigDecimal> roomModelFloorNumMap = CollectionUtils.convertMap(roomList,
|
|
|
item -> item.getRoomModelId() + "_" + item.getFloors(),
|
|
|
item -> roomMap.get(item.getId()) == null ? BigDecimal.ZERO : roomMap.get(item.getId()));
|
|
|
- if(distributeNewRespVOS.isEmpty()) {//分销商未分配库存,扣共享库存
|
|
|
+ if (distributeNewRespVOS.isEmpty()) {//分销商未分配库存,扣共享库存
|
|
|
|
|
|
voyageStockLogDO.setStockType(1); //1共享库存
|
|
|
//判断共享库存是否充足
|
|
|
- if(shareNum.compareTo(totalUseNum) < 0) {
|
|
|
+ if (shareNum.compareTo(totalUseNum) < 0) {
|
|
|
throw exception(VOYAGE_SHARE_STOCK_NOT_ENOUGH);
|
|
|
}
|
|
|
//判断航次房型楼层库存是否充足
|
|
|
// 判断库存是否充足
|
|
|
- stockDetailList.stream().forEach(item -> {
|
|
|
+ stockDetailList.forEach(item -> {
|
|
|
BigDecimal canSellNum = item.getCanSellNum();
|
|
|
BigDecimal useNum = roomModelFloorNumMap.get(item.getRoomModelId() + "_" + item.getFloor());
|
|
|
- if(useNum == null) {
|
|
|
+ if (useNum == null) {
|
|
|
useNum = BigDecimal.ZERO;
|
|
|
}
|
|
|
- if(canSellNum.compareTo(useNum) < 0) {
|
|
|
+ if (canSellNum.compareTo(useNum) < 0) {
|
|
|
throw exception(VOYAGE_SHARE_ROOM_NOT_ENOUGH.getCode(), String.format(VOYAGE_SHARE_ROOM_NOT_ENOUGH.getMsg(), item.getRoomModelName(), item.getFloor()));
|
|
|
}
|
|
|
});
|
|
|
// 库存充足,扣库存详情
|
|
|
- stockDetailList.stream().forEach(item -> {
|
|
|
+ stockDetailList.forEach(item -> {
|
|
|
BigDecimal useNum = roomModelFloorNumMap.get(item.getRoomModelId() + "_" + item.getFloor());
|
|
|
- if(useNum == null) {
|
|
|
+ if (useNum == null) {
|
|
|
useNum = BigDecimal.ZERO;
|
|
|
}
|
|
|
//航次库存详情操作日志
|
|
|
@@ -680,11 +677,11 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
// 减可售房间数
|
|
|
item.setCanSellNum(item.getCanSellNum().subtract(useNum));
|
|
|
// 减虚拟房间数,此处初定,先扣虚拟库存,虚拟库存不足再扣实际库存
|
|
|
- if(item.getVirtualNum().compareTo(useNum) >= 0) {
|
|
|
+ if (item.getVirtualNum().compareTo(useNum) >= 0) {
|
|
|
voyageStockDetailLogDO.setVirtualNum(useNum);
|
|
|
voyageStockDetailLogDO.setRealNum(BigDecimal.ZERO);
|
|
|
item.setVirtualNum(item.getVirtualNum().subtract(useNum));
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
voyageStockDetailLogDO.setVirtualNum(item.getVirtualNum());
|
|
|
voyageStockDetailLogDO.setRealNum(useNum.subtract(item.getVirtualNum()));
|
|
|
item.setVirtualNum(BigDecimal.ZERO);
|
|
|
@@ -704,11 +701,11 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
// 减可售房间数
|
|
|
stockDO.setCanSellNum(stockDO.getCanSellNum().subtract(totalUseNum));
|
|
|
// 减虚拟房间数,此处初定,先扣虚拟库存,虚拟库存不足再扣实际库存
|
|
|
- if(stockDO.getVirtualNum().compareTo(totalUseNum) >= 0) {
|
|
|
+ if (stockDO.getVirtualNum().compareTo(totalUseNum) >= 0) {
|
|
|
stockDO.setVirtualNum(stockDO.getVirtualNum().subtract(totalUseNum));
|
|
|
voyageStockLogDO.setVirtualNum(totalUseNum);
|
|
|
voyageStockLogDO.setRealNum(BigDecimal.ZERO);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
voyageStockLogDO.setVirtualNum(stockDO.getVirtualNum());
|
|
|
voyageStockLogDO.setRealNum(totalUseNum.subtract(voyageStockLogDO.getVirtualNum()));
|
|
|
stockDO.setVirtualNum(BigDecimal.ZERO);
|
|
|
@@ -721,43 +718,47 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
stockDO.setShareNum(stockDO.getShareNum().subtract(totalUseNum));
|
|
|
voyageStockLogDO.setShareNum(totalUseNum);
|
|
|
voyageStockMapper.updateById(stockDO);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
|
|
|
voyageStockLogDO.setStockType(2); //2分销商库存
|
|
|
|
|
|
//分销商已分配库存,扣自身库存
|
|
|
|
|
|
//判断航次房型楼层库存是否充足
|
|
|
- distributeNewRespVOS.stream().forEach(item -> {
|
|
|
+ distributeNewRespVOS.forEach(item -> {
|
|
|
BigDecimal canSellNum = item.getNum();
|
|
|
BigDecimal useNum = roomModelFloorNumMap.get(item.getRoomModelId() + "_" + item.getFloor());
|
|
|
- if(useNum == null) {
|
|
|
+ if (useNum == null) {
|
|
|
useNum = BigDecimal.ZERO;
|
|
|
}
|
|
|
- if(canSellNum.compareTo(useNum) < 0) {
|
|
|
+ if (canSellNum.compareTo(useNum) < 0) {
|
|
|
throw exception(VOYAGE_DISTRIBUTOR_ROOM_NOT_ENOUGH.getCode(), String.format(VOYAGE_DISTRIBUTOR_ROOM_NOT_ENOUGH.getMsg(), item.getRoomModelName(), item.getFloor()));
|
|
|
}
|
|
|
});
|
|
|
// 扣分销商库存
|
|
|
// 库存充足,扣库存详情
|
|
|
List<VoyageStockDistributeNewDO> list = BeanUtils.toBean(distributeNewRespVOS, VoyageStockDistributeNewDO.class);
|
|
|
- list.stream().forEach(item -> {
|
|
|
+ list.forEach(item -> {
|
|
|
BigDecimal useNum = roomModelFloorNumMap.get(item.getRoomModelId() + "_" + item.getFloor());
|
|
|
- if(useNum == null) {
|
|
|
+ if (useNum == null) {
|
|
|
useNum = BigDecimal.ZERO;
|
|
|
}
|
|
|
// 减可售房间数
|
|
|
item.setNum(item.getNum().subtract(useNum));
|
|
|
// 加预定房间数
|
|
|
- item.setBookNum(item.getBookNum().add(useNum));
|
|
|
+ if (item.getBookNum() != null) {
|
|
|
+ item.setBookNum(item.getBookNum().add(useNum));
|
|
|
+ } else {
|
|
|
+ item.setBookNum(useNum);
|
|
|
+ }
|
|
|
});
|
|
|
|
|
|
voyageStockDistributeNewMapper.updateBatch(list);
|
|
|
|
|
|
// 库存充足,扣库存详情
|
|
|
- stockDetailList.stream().forEach(item -> {
|
|
|
+ stockDetailList.forEach(item -> {
|
|
|
BigDecimal useNum = roomModelFloorNumMap.get(item.getRoomModelId() + "_" + item.getFloor());
|
|
|
- if(useNum == null) {
|
|
|
+ if (useNum == null) {
|
|
|
useNum = BigDecimal.ZERO;
|
|
|
}
|
|
|
|
|
|
@@ -777,11 +778,11 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
// 减可售房间数
|
|
|
item.setCanSellNum(item.getCanSellNum().subtract(useNum));
|
|
|
// 减虚拟房间数,此处初定,先扣虚拟库存,虚拟库存不足再扣实际库存
|
|
|
- if(item.getVirtualNum().compareTo(useNum) >= 0) {
|
|
|
+ if (item.getVirtualNum().compareTo(useNum) >= 0) {
|
|
|
voyageStockDetailLogDO.setVirtualNum(useNum);
|
|
|
voyageStockDetailLogDO.setRealNum(BigDecimal.ZERO);
|
|
|
item.setVirtualNum(item.getVirtualNum().subtract(useNum));
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
voyageStockDetailLogDO.setVirtualNum(item.getVirtualNum());
|
|
|
voyageStockDetailLogDO.setRealNum(totalUseNum.subtract(item.getVirtualNum()));
|
|
|
item.setVirtualNum(BigDecimal.ZERO);
|
|
|
@@ -802,11 +803,11 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
// 减剩余房间数
|
|
|
// stockDO.setSurplusNum(stockDO.getSurplusNum().subtract(totalUseNum));
|
|
|
// 减虚拟房间数,此处初定,先扣虚拟库存,虚拟库存不足再扣实际库存
|
|
|
- if(stockDO.getVirtualNum().compareTo(totalUseNum) >= 0) {
|
|
|
+ if (stockDO.getVirtualNum().compareTo(totalUseNum) >= 0) {
|
|
|
stockDO.setVirtualNum(stockDO.getVirtualNum().subtract(totalUseNum));
|
|
|
voyageStockLogDO.setVirtualNum(totalUseNum);
|
|
|
voyageStockLogDO.setRealNum(BigDecimal.ZERO);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
voyageStockLogDO.setVirtualNum(stockDO.getVirtualNum());
|
|
|
voyageStockLogDO.setRealNum(totalUseNum.subtract(voyageStockLogDO.getVirtualNum()));
|
|
|
stockDO.setVirtualNum(BigDecimal.ZERO);
|
|
|
@@ -827,7 +828,7 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
roomUsedDO.setOrderId(orderId);
|
|
|
roomUsedDO.setVoyageId(voyageId);
|
|
|
RoomRespDTO roomRespDTO = roomIdMap.get(item.getRoomId());
|
|
|
- if(roomRespDTO == null) {
|
|
|
+ if (roomRespDTO == null) {
|
|
|
throw exception(VOYAGE_ROOM_NOT_EXIST.getCode(), String.format(VOYAGE_ROOM_NOT_EXIST.getMsg(), item.getRoomId()));
|
|
|
}
|
|
|
roomUsedDO.setRoomModelId(roomRespDTO.getRoomModelId());
|
|
|
@@ -839,14 +840,14 @@ public class VoyageApiImpl implements VoyageApi{
|
|
|
});
|
|
|
//先删除当前订单已被使用的房间
|
|
|
voyageStockRoomUsedMapper.deleteByOrderId(orderId);
|
|
|
- if(roomUsedList.size() > 0) {
|
|
|
+ if (!roomUsedList.isEmpty()) {
|
|
|
voyageStockRoomUsedMapper.insertBatch(roomUsedList);
|
|
|
}
|
|
|
|
|
|
// 添加库存日志
|
|
|
voyageStockLogMapper.insert(voyageStockLogDO);
|
|
|
// 添加库存详情日志
|
|
|
- if(detailLogList.size() > 0) {
|
|
|
+ if (!detailLogList.isEmpty()) {
|
|
|
voyageStockDetailLogMapper.insertBatch(detailLogList);
|
|
|
}
|
|
|
}
|