|
@@ -28,6 +28,7 @@ import com.sd.business.entity.in.dto.InOutStorageDto;
|
|
|
import com.sd.business.entity.in.emums.InDetailTypeEnum;
|
|
|
import com.sd.business.entity.in.emums.InOutTypeEnum;
|
|
|
import com.sd.business.entity.in.po.InOutStorageBom;
|
|
|
+import com.sd.business.entity.inventory.po.Inventory;
|
|
|
import com.sd.business.entity.order.dto.*;
|
|
|
import com.sd.business.entity.order.enums.OrderExceptionTypeEnum;
|
|
|
import com.sd.business.entity.order.enums.OrderStatusEnum;
|
|
@@ -44,6 +45,7 @@ import com.sd.business.service.bom.BomService;
|
|
|
import com.sd.business.service.bom.BomSpecService;
|
|
|
import com.sd.business.service.department.DepartmentService;
|
|
|
import com.sd.business.service.in.InOutStorageService;
|
|
|
+import com.sd.business.service.inventory.InventoryService;
|
|
|
import com.sd.business.service.order.*;
|
|
|
import com.sd.business.service.price.PriceBillingStandardDetailService;
|
|
|
import com.sd.business.service.price.PriceBillingStandardService;
|
|
@@ -106,6 +108,9 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderInfo> implem
|
|
|
private StatementOfAccountService statementOfAccountService;
|
|
|
|
|
|
@Autowired
|
|
|
+ private InventoryService inventoryService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
private ISysUserService sysUserService;
|
|
|
|
|
|
@Override
|
|
@@ -246,6 +251,12 @@ 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);
|
|
|
+ }
|
|
|
+
|
|
|
orderDto.setSource(1);
|
|
|
orderDto.setCode("PI" + new Date().getTime());
|
|
|
orderDto.setSettlementStatus(1);
|
|
@@ -254,7 +265,6 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderInfo> implem
|
|
|
orderDto.setExceptionType(OrderExceptionTypeEnum.NORMAL.getKey().toString());
|
|
|
this.save(orderDto);
|
|
|
|
|
|
- List<OrderSkuDto> orderSkuList = orderDto.getOrderSkuList();
|
|
|
List<OrderSku> tempOrderSkuList = orderSkuList.stream()
|
|
|
.peek(item -> item.setOrderId(orderDto.getId()))
|
|
|
.peek(item -> item.setStockPreparationStatus(StatusConstant.NO))
|
|
@@ -302,9 +312,14 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderInfo> implem
|
|
|
@DSTransactional
|
|
|
@Override
|
|
|
public void edit(OrderInfoDto orderDto) {
|
|
|
+ List<OrderSkuDto> orderSkuList = orderDto.getOrderSkuList();
|
|
|
+ // 自建订单判断库存
|
|
|
+ if (ObjectUtil.equals(orderDto.getType(), 1)) {
|
|
|
+ this.checkSkuInventory(orderSkuList);
|
|
|
+ }
|
|
|
+
|
|
|
this.updateById(orderDto);
|
|
|
|
|
|
- List<OrderSkuDto> orderSkuList = orderDto.getOrderSkuList();
|
|
|
List<OrderSku> tempOrderSkuList = orderSkuList.stream()
|
|
|
.peek(item -> item.setOrderId(orderDto.getId()))
|
|
|
.peek(item -> item.setStockPreparationStatus(StatusConstant.NO))
|
|
@@ -710,4 +725,46 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderInfo> implem
|
|
|
ObsFileUtil.removeFile(id);
|
|
|
}
|
|
|
|
|
|
+ private void checkSkuInventory(List<OrderSkuDto> orderSkuList) {
|
|
|
+ List<Long> bomSpecIdList = orderSkuList.stream().map(OrderSku::getBomSpecId).collect(Collectors.toList());
|
|
|
+ // 区分半成品仓和包材仓库
|
|
|
+ Map<Long, BomSpecBo> bomSpecBoMap = skuSpecService.getBomSpecBoByIdList(bomSpecIdList);
|
|
|
+ // 自建订单判断库存
|
|
|
+ for (OrderSkuDto orderSkuDto : orderSkuList) {
|
|
|
+ // 判断sku库存
|
|
|
+ Long bomSpecId = orderSkuDto.getBomSpecId();
|
|
|
+ BomSpecBo bomSpecBo = bomSpecBoMap.get(bomSpecId);
|
|
|
+ if (bomSpecBo == null) {
|
|
|
+ throw new ServiceException("未知bom规格id:" + bomSpecId);
|
|
|
+ }
|
|
|
+ Long warehouseId;
|
|
|
+ // 主材
|
|
|
+ if (ObjectUtil.equals(bomSpecBo.getClassifyParentId(), 1L)) {
|
|
|
+ warehouseId = WarehouseConstant.SEMI_FINISHED_PRODUCT;
|
|
|
+ } else {
|
|
|
+ warehouseId = WarehouseConstant.PACKAGING_MATERIAL;
|
|
|
+ }
|
|
|
+ Inventory inventory = inventoryService.getOne(q -> q.eq(Inventory::getWarehouseId, warehouseId)
|
|
|
+ .eq(Inventory::getBomSpecId, bomSpecId));
|
|
|
+ if (inventory == null || inventory.getQuantity().compareTo(orderSkuDto.getQuantity()) < 0) {
|
|
|
+ throw new ServiceException("操作失败,品名为:" + bomSpecBo.getBomSpecName() + " 的bom库存不足,库存为:" +
|
|
|
+ (inventory == null ? BigDecimal.ZERO : inventory.getQuantity()));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 判断包材库存
|
|
|
+ for (OrderSkuBom orderSkuBom : orderSkuDto.getOrderSkuBomList()) {
|
|
|
+ BomSpec bomSpec = bomSpecService.getById(orderSkuBom.getBomSpecId());
|
|
|
+ if (bomSpec == null) {
|
|
|
+ throw new ServiceException("未知bom规格id:" + orderSkuBom.getBomSpecId());
|
|
|
+ }
|
|
|
+ Inventory bomInventory = inventoryService.getOne(q -> q.eq(Inventory::getWarehouseId, WarehouseConstant.PACKAGING_MATERIAL)
|
|
|
+ .eq(Inventory::getBomSpecId, orderSkuBom.getBomSpecId()));
|
|
|
+ if (bomInventory == null || bomInventory.getQuantity().compareTo(orderSkuBom.getQuantity()) < 0) {
|
|
|
+ throw new ServiceException("操作失败,品名为:" + bomSpec.getName() + " 的bom库存不足,库存为:" +
|
|
|
+ (bomInventory == null ? BigDecimal.ZERO : bomInventory.getQuantity()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|