|
@@ -9,7 +9,6 @@ import com.alibaba.fastjson2.JSON;
|
|
|
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.fjhx.file.entity.ObsFile;
|
|
|
import com.fjhx.file.utils.ObsFileUtil;
|
|
|
import com.ruoyi.common.annotation.LogicIgnore;
|
|
|
import com.ruoyi.common.constant.StatusConstant;
|
|
@@ -251,12 +250,16 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderInfo> implem
|
|
|
@DSTransactional
|
|
|
@Override
|
|
|
public void add(OrderInfoDto orderDto) {
|
|
|
+
|
|
|
List<OrderSkuDto> orderSkuList = orderDto.getOrderSkuList();
|
|
|
- // 自建订单判断库存
|
|
|
- if (ObjectUtil.equals(orderDto.getType(), 1)) {
|
|
|
- this.checkSkuInventory(orderSkuList);
|
|
|
+ if (ObjectUtil.equal(orderDto.getStatus(), OrderStatusEnum.STOCK_PREPARATION.getKey())) {
|
|
|
+ lockStorage(orderSkuList);
|
|
|
+ orderDto.setLockStorage(StatusConstant.YES);
|
|
|
+ } else {
|
|
|
+ orderDto.setLockStorage(StatusConstant.NO);
|
|
|
}
|
|
|
|
|
|
+ // 新增订单
|
|
|
orderDto.setSource(1);
|
|
|
orderDto.setCode("PI" + new Date().getTime());
|
|
|
orderDto.setSettlementStatus(1);
|
|
@@ -265,6 +268,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderInfo> implem
|
|
|
orderDto.setExceptionType(OrderExceptionTypeEnum.NORMAL.getKey().toString());
|
|
|
this.save(orderDto);
|
|
|
|
|
|
+ // 新增订单产品包材配件
|
|
|
List<OrderSku> tempOrderSkuList = orderSkuList.stream()
|
|
|
.peek(item -> item.setOrderId(orderDto.getId()))
|
|
|
.peek(item -> item.setStockPreparationStatus(StatusConstant.NO))
|
|
@@ -272,10 +276,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderInfo> implem
|
|
|
.collect(Collectors.toList());
|
|
|
orderSkuService.saveBatch(tempOrderSkuList);
|
|
|
|
|
|
- for (OrderSkuDto item : orderSkuList) {
|
|
|
- ObsFileUtil.saveFile(Collections.singletonList(item.getSelfAdhesiveStickerFile()), item.getId());
|
|
|
- }
|
|
|
-
|
|
|
+ // 新增订单产品包装信息
|
|
|
List<OrderSkuBom> orderSkuBomList = orderSkuList.stream()
|
|
|
.flatMap(orderSku -> orderSku.getOrderSkuBomList().stream()
|
|
|
.peek(orderSkuBom -> orderSkuBom.setOrderId(orderDto.getId()))
|
|
@@ -283,8 +284,8 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderInfo> implem
|
|
|
.collect(Collectors.toList());
|
|
|
orderSkuBomService.saveBatch(orderSkuBomList);
|
|
|
|
|
|
+ // 保存订单包装信息
|
|
|
if (ObjectUtil.isNotEmpty(orderDto.getOrderPackageBomList())) {
|
|
|
- // 保存订单包装信息
|
|
|
List<OrderPackageBomDto> tempOrderPackageBomList = orderDto.getOrderPackageBomList();
|
|
|
List<OrderPackageBom> orderPackageBomList = tempOrderPackageBomList.stream()
|
|
|
.peek(item -> item.setOrderId(orderDto.getId()))
|
|
@@ -293,82 +294,125 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderInfo> implem
|
|
|
orderPackageBomService.saveBatch(orderPackageBomList);
|
|
|
}
|
|
|
|
|
|
+ // 订单操作日志
|
|
|
OrderOperatingLog orderOperatingLog = new OrderOperatingLog();
|
|
|
orderOperatingLog.setType(10);
|
|
|
orderOperatingLog.setOrderId(orderDto.getId());
|
|
|
orderOperatingLog.setOrderCode(orderDto.getCode());
|
|
|
orderOperatingLogService.save(orderOperatingLog);
|
|
|
|
|
|
- ObsFileUtil.saveFile(orderDto.getFileList(), orderDto.getId());
|
|
|
-
|
|
|
- // 保存 外箱不干胶图稿, 文件业务类型为 1
|
|
|
- ObsFile outerBoxSelfAdhesiveStickerFile = orderDto.getOuterBoxSelfAdhesiveStickerFile();
|
|
|
- if (ObjectUtil.isNotEmpty(outerBoxSelfAdhesiveStickerFile)) {
|
|
|
- ObsFileUtil.saveFile(Collections.singletonList(outerBoxSelfAdhesiveStickerFile), orderDto.getId(), 1);
|
|
|
+ // 保存产品不干胶图稿
|
|
|
+ for (OrderSkuDto item : orderSkuList) {
|
|
|
+ ObsFileUtil.saveFile(item.getSelfAdhesiveStickerFile(), item.getId());
|
|
|
}
|
|
|
|
|
|
+ // 保存附件
|
|
|
+ ObsFileUtil.saveFile(orderDto.getFileList(), orderDto.getId());
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@DSTransactional
|
|
|
@Override
|
|
|
- public void edit(OrderInfoDto orderDto) {
|
|
|
- List<OrderSkuDto> orderSkuList = orderDto.getOrderSkuList();
|
|
|
- // 自建订单判断库存
|
|
|
- if (ObjectUtil.equals(orderDto.getType(), 1)) {
|
|
|
- this.checkSkuInventory(orderSkuList);
|
|
|
- }
|
|
|
+ public void edit(OrderInfoDto dto) {
|
|
|
|
|
|
- this.updateById(orderDto);
|
|
|
+ // 更新订单
|
|
|
+ this.updateById(dto);
|
|
|
|
|
|
+ // 更新订单产品
|
|
|
+ List<OrderSkuDto> orderSkuList = dto.getOrderSkuList();
|
|
|
List<OrderSku> tempOrderSkuList = orderSkuList.stream()
|
|
|
- .peek(item -> item.setOrderId(orderDto.getId()))
|
|
|
+ .peek(item -> item.setOrderId(dto.getId()))
|
|
|
.peek(item -> item.setStockPreparationStatus(StatusConstant.NO))
|
|
|
.map(item -> (OrderSku) item)
|
|
|
.collect(Collectors.toList());
|
|
|
- orderSkuService.editLinked(tempOrderSkuList, OrderSku::getOrderId, orderDto.getId());
|
|
|
-
|
|
|
- for (OrderSkuDto item : orderSkuList) {
|
|
|
- ObsFileUtil.saveFile(Collections.singletonList(item.getSelfAdhesiveStickerFile()), item.getId());
|
|
|
- }
|
|
|
+ orderSkuService.editLinked(tempOrderSkuList, OrderSku::getOrderId, dto.getId());
|
|
|
|
|
|
+ // 更新订单产品包材配件
|
|
|
List<OrderSkuBom> orderSkuBomList = orderSkuList.stream()
|
|
|
.flatMap(orderSku -> orderSku.getOrderSkuBomList().stream()
|
|
|
- .peek(orderSkuBom -> orderSkuBom.setOrderId(orderDto.getId()))
|
|
|
+ .peek(orderSkuBom -> orderSkuBom.setOrderId(dto.getId()))
|
|
|
.peek(orderSkuBom -> orderSkuBom.setOrderSkuId(orderSku.getId())))
|
|
|
.collect(Collectors.toList());
|
|
|
- orderSkuBomService.editLinked(orderSkuBomList, OrderSkuBom::getOrderId, orderDto.getId());
|
|
|
+ orderSkuBomService.editLinked(orderSkuBomList, OrderSkuBom::getOrderId, dto.getId());
|
|
|
|
|
|
- if (ObjectUtil.isNotEmpty(orderDto.getOrderPackageBomList())) {
|
|
|
- // 更新订单包装信息
|
|
|
- List<OrderPackageBomDto> tempOrderPackageBomList = orderDto.getOrderPackageBomList();
|
|
|
+ // 更新订单产品包装信息
|
|
|
+ if (ObjectUtil.isNotEmpty(dto.getOrderPackageBomList())) {
|
|
|
+ List<OrderPackageBomDto> tempOrderPackageBomList = dto.getOrderPackageBomList();
|
|
|
List<OrderPackageBom> orderPackageBomList = tempOrderPackageBomList.stream()
|
|
|
- .peek(item -> item.setOrderId(orderDto.getId()))
|
|
|
+ .peek(item -> item.setOrderId(dto.getId()))
|
|
|
.map(item -> (OrderPackageBom) item)
|
|
|
.collect(Collectors.toList());
|
|
|
- orderPackageBomService.editLinked(orderPackageBomList, OrderPackageBom::getOrderId, orderDto.getId());
|
|
|
+ orderPackageBomService.editLinked(orderPackageBomList, OrderPackageBom::getOrderId, dto.getId());
|
|
|
}
|
|
|
|
|
|
- if (orderDto.getUpdateType() != null) {
|
|
|
+ // 订单操作日志
|
|
|
+ if (dto.getUpdateType() != null) {
|
|
|
OrderOperatingLog orderOperatingLog = new OrderOperatingLog();
|
|
|
- orderOperatingLog.setType(orderDto.getUpdateType());
|
|
|
- orderOperatingLog.setOrderId(orderDto.getId());
|
|
|
- orderOperatingLog.setOrderCode(orderDto.getCode());
|
|
|
+ orderOperatingLog.setType(dto.getUpdateType());
|
|
|
+ orderOperatingLog.setOrderId(dto.getId());
|
|
|
+ orderOperatingLog.setOrderCode(dto.getCode());
|
|
|
orderOperatingLogService.save(orderOperatingLog);
|
|
|
}
|
|
|
|
|
|
- ObsFileUtil.editFile(orderDto.getFileList(), orderDto.getId());
|
|
|
+ // 更新订单产品不干胶图稿
|
|
|
+ for (OrderSkuDto item : orderSkuList) {
|
|
|
+ ObsFileUtil.saveFile(item.getSelfAdhesiveStickerFile(), item.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新订单附件
|
|
|
+ ObsFileUtil.editFile(dto.getFileList(), dto.getId());
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void confirmation(OrderInfoDto dto) {
|
|
|
+ OrderInfo order = getById(dto.getId());
|
|
|
+
|
|
|
+ if (ObjectUtil.notEqual(order.getStatus(), OrderStatusEnum.DRAFT.getKey())
|
|
|
+ || ObjectUtil.notEqual(order.getStatus(), OrderStatusEnum.UNDER_REVIEW.getKey())) {
|
|
|
+ throw new ServiceException("订单不在草稿或待确认状态");
|
|
|
+ }
|
|
|
|
|
|
- // 更新 外箱不干胶图稿
|
|
|
- ObsFile outerBoxSelfAdhesiveStickerFile = orderDto.getOuterBoxSelfAdhesiveStickerFile();
|
|
|
- if (ObjectUtil.isNotEmpty(outerBoxSelfAdhesiveStickerFile)) {
|
|
|
- ObsFileUtil.editFile(Collections.singletonList(outerBoxSelfAdhesiveStickerFile), orderDto.getId(), 1);
|
|
|
+ // 自主订单需要锁定库存
|
|
|
+ List<OrderSkuDto> orderSkuList = dto.getOrderSkuList();
|
|
|
+ if (Objects.equals(dto.getType(), 1)) {
|
|
|
+ lockStorage(orderSkuList);
|
|
|
+ dto.setLockStorage(StatusConstant.YES);
|
|
|
}
|
|
|
|
|
|
+ // 更新订单
|
|
|
+ dto.setStatus(OrderStatusEnum.STOCK_PREPARATION.getKey());
|
|
|
+ this.updateById(dto);
|
|
|
+
|
|
|
+ // 更新订单产品
|
|
|
+ List<OrderSku> tempOrderSkuList = orderSkuList.stream()
|
|
|
+ .peek(item -> item.setOrderId(dto.getId()))
|
|
|
+ .peek(item -> item.setStockPreparationStatus(StatusConstant.NO))
|
|
|
+ .map(item -> (OrderSku) item)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ orderSkuService.editLinked(tempOrderSkuList, OrderSku::getOrderId, dto.getId());
|
|
|
+
|
|
|
+ // 更新包材
|
|
|
+ List<OrderSkuBom> orderSkuBomList = orderSkuList.stream()
|
|
|
+ .flatMap(orderSku -> orderSku.getOrderSkuBomList().stream()
|
|
|
+ .peek(orderSkuBom -> orderSkuBom.setOrderId(dto.getId()))
|
|
|
+ .peek(orderSkuBom -> orderSkuBom.setOrderSkuId(orderSku.getId())))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ orderSkuBomService.editLinked(orderSkuBomList, OrderSkuBom::getOrderId, dto.getId());
|
|
|
+
|
|
|
+ // 更新产品不干胶图稿
|
|
|
+ for (OrderSkuDto item : orderSkuList) {
|
|
|
+ ObsFileUtil.saveFile(item.getSelfAdhesiveStickerFile(), item.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新附件
|
|
|
+ ObsFileUtil.editFile(dto.getFileList(), dto.getId());
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@DSTransactional
|
|
|
@Override
|
|
|
- public void delete(Long id, boolean saveLog) {
|
|
|
+ public synchronized void delete(Long id, boolean saveLog) {
|
|
|
OrderInfo orderInfo = getById(id);
|
|
|
|
|
|
if (orderInfo == null) {
|
|
@@ -380,6 +424,8 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderInfo> implem
|
|
|
throw new ServiceException("订单正在生产中,无法直接删除,需要走审批流程");
|
|
|
}
|
|
|
|
|
|
+ unLockStorage(orderInfo);
|
|
|
+
|
|
|
// 删除订单以及订单关联数据
|
|
|
delete(id);
|
|
|
|
|
@@ -551,6 +597,8 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderInfo> implem
|
|
|
throw new ServiceException("未找到订单");
|
|
|
}
|
|
|
|
|
|
+ unLockStorage(orderInfo);
|
|
|
+
|
|
|
if (orderInfo.getStatus() <= OrderStatusEnum.STOCK_PREPARATION.getKey()) {
|
|
|
return;
|
|
|
}
|
|
@@ -716,7 +764,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderInfo> implem
|
|
|
/**
|
|
|
* 删除订单以及订单关联数据
|
|
|
*/
|
|
|
- private void delete(Long id) {
|
|
|
+ public void delete(Long id) {
|
|
|
this.removeById(id);
|
|
|
orderSkuService.remove(q -> q.eq(OrderSku::getOrderId, id));
|
|
|
orderSkuBomService.remove(q -> q.eq(OrderSkuBom::getOrderId, id));
|
|
@@ -753,4 +801,43 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderInfo> implem
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 锁定库存
|
|
|
+ */
|
|
|
+ private void lockStorage(List<? extends OrderSku> orderSkuList) {
|
|
|
+ List<Long> bomSpecIdList = orderSkuList.stream().map(OrderSku::getBomSpecId).collect(Collectors.toList());
|
|
|
+ Map<Long, BomSpecBo> bomSpecBoMap = skuSpecService.getBomSpecBoByIdList(bomSpecIdList);
|
|
|
+
|
|
|
+ boolean result = inventoryService.lockStorage(orderSkuList.stream()
|
|
|
+ .filter(item -> bomSpecBoMap.get(item.getBomSpecId()).getClassifyParentId().equals(1L))
|
|
|
+ .collect(Collectors.toList())
|
|
|
+ );
|
|
|
+
|
|
|
+ if (!result) {
|
|
|
+ throw new ServiceException("主材库存不足,无法确认订单");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 解锁库存
|
|
|
+ */
|
|
|
+ private void unLockStorage(OrderInfo orderInfo) {
|
|
|
+
|
|
|
+ if (ObjectUtil.notEqual(orderInfo.getLockStorage(), StatusConstant.YES)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<OrderSku> orderSkuList = orderSkuService.list(q -> q.eq(OrderSku::getOrderId, orderInfo.getId()));
|
|
|
+
|
|
|
+ List<Long> bomSpecIdList = orderSkuList.stream().map(OrderSku::getBomSpecId).collect(Collectors.toList());
|
|
|
+ Map<Long, BomSpecBo> bomSpecBoMap = skuSpecService.getBomSpecBoByIdList(bomSpecIdList);
|
|
|
+
|
|
|
+ orderSkuList = orderSkuList.stream()
|
|
|
+ .filter(item -> bomSpecBoMap.get(item.getBomSpecId()).getClassifyParentId().equals(1L))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ inventoryService.unlockStorage(orderSkuList);
|
|
|
+ }
|
|
|
+
|
|
|
}
|