Selaa lähdekoodia

生产备料出库

24282 1 vuosi sitten
vanhempi
commit
e34f75108c

+ 24 - 0
sd-business/src/main/java/com/sd/business/entity/in/bo/InOutStorageBomBo.java

@@ -0,0 +1,24 @@
+package com.sd.business.entity.in.bo;
+
+import com.sd.business.entity.in.po.InOutStorageBom;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * <p>
+ * 出入库bom
+ * </p>
+ *
+ * @author
+ * @since 2023-07-03
+ */
+@Getter
+@Setter
+public class InOutStorageBomBo extends InOutStorageBom {
+
+    /**
+     * 锁定库存
+     */
+    private Integer lockStorage;
+
+}

+ 5 - 0
sd-business/src/main/java/com/sd/business/entity/in/dto/InOutStorageDto.java

@@ -23,4 +23,9 @@ public class InOutStorageDto extends InOutStorage {
     @NotEmpty(message = "物料信息不能为空")
     private List<InOutStorageBom> inOutStorageBomList;
 
+    /**
+     * 是否出锁定库存 1是 0否
+     */
+    private Integer lockStorage;
+
 }

+ 5 - 0
sd-business/src/main/java/com/sd/business/entity/production/vo/StockPreparationVo.java

@@ -94,4 +94,9 @@ public class StockPreparationVo {
      */
     private Integer printType;
 
+    /**
+     * 库存是否锁定
+     */
+    private Integer lockStorage;
+
 }

+ 1 - 1
sd-business/src/main/java/com/sd/business/service/in/impl/InOutStorageServiceImpl.java

@@ -95,7 +95,7 @@ public class InOutStorageServiceImpl extends ServiceImpl<InOutStorageMapper, InO
             // 赋值出库单号
             inOutStorageDto.setCode(CodeEnum.OUT_CODE.getCode());
             // 更新库存
-            inventoryService.out(inOutStorageDto.getDepartmentId(), inOutStorageDto.getWarehouseId(), inOutStorageBomList);
+            inventoryService.out(inOutStorageDto.getDepartmentId(), inOutStorageDto.getWarehouseId(), inOutStorageBomList, inOutStorageDto.getLockStorage());
         }
 
         // 保存出入库信息

+ 2 - 1
sd-business/src/main/java/com/sd/business/service/inventory/InventoryService.java

@@ -57,8 +57,9 @@ public interface InventoryService extends BaseService<Inventory> {
      * @param departmentId 事业部id
      * @param warehouseId  仓库id
      * @param list         出库明细
+     * @param lockStorage  是否从锁定库存出库
      */
-    void out(Long departmentId, Long warehouseId, List<? extends InOutFun> list);
+    void out(Long departmentId, Long warehouseId, List<? extends InOutFun> list, Integer lockStorage);
 
     /**
      * 查询库存

+ 22 - 10
sd-business/src/main/java/com/sd/business/service/inventory/impl/InventoryServiceImpl.java

@@ -4,6 +4,7 @@ import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.common.constant.StatusConstant;
 import com.ruoyi.common.core.domain.BaseIdPo;
 import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.common.utils.wrapper.IWrapper;
@@ -117,7 +118,6 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
             // 通过出库id获取bom规格结存列表
             Map<Long, List<InOutStorageDetails>> inOutStorageDetailsMap = getInOutStorageDetailsMap(warehouseId, bomSpecIdList);
 
-
             for (InOutFun inOutFun : list) {
 
                 // 库存
@@ -127,6 +127,7 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
                     tempInventory.setDepartmentId(departmentId);
                     tempInventory.setBomSpecId(item);
                     tempInventory.setQuantity(BigDecimal.ZERO);
+                    tempInventory.setLockQuantity(BigDecimal.ZERO);
                     inventoryList.add(tempInventory);
                     return tempInventory;
                 });
@@ -143,7 +144,7 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
     }
 
     @Override
-    public void out(Long departmentId, Long warehouseId, List<? extends InOutFun> list) {
+    public void out(Long departmentId, Long warehouseId, List<? extends InOutFun> list, Integer lockStorage) {
         List<Long> bomSpecIdList = list.stream().map(InOutFun::getBomSpecId).collect(Collectors.toList());
 
         synchronized (this) {
@@ -160,13 +161,22 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
                 BigDecimal quantity = inOutFun.getQuantity();
 
                 Inventory inventory = inventoryMap.get(bomSpecId);
-                if (inventory == null || inventory.getQuantity().compareTo(quantity) < 0) {
-                    BomSpec bomSpec = bomSpecService.getById(bomSpecId);
-                    if (bomSpec == null) {
-                        throw new ServiceException("未知bom规格id:" + bomSpecId);
+
+                // 出库非冻结库存
+                if (Objects.equals(lockStorage, StatusConstant.YES)) {
+                    inventory.setLockQuantity(inventory.getLockQuantity().subtract(quantity));
+                }
+                // 出库冻结库存
+                else {
+                    if (inventory == null || inventory.getQuantity().compareTo(quantity) < 0) {
+                        BomSpec bomSpec = bomSpecService.getById(bomSpecId);
+                        if (bomSpec == null) {
+                            throw new ServiceException("未知bom规格id:" + bomSpecId);
+                        }
+                        throw new ServiceException("出库失败,品名为:" + bomSpec.getName() + " 的bom库存不足,库存为:" +
+                                (inventory == null ? BigDecimal.ZERO : inventory.getQuantity()) + ",需要出库:" + quantity);
                     }
-                    throw new ServiceException("出库失败,品名为:" + bomSpec.getName() + " 的bom库存不足,库存为:" +
-                            (inventory == null ? BigDecimal.ZERO : inventory.getQuantity()) + ",需要出库:" + quantity);
+                    inventory.setQuantity(inventory.getQuantity().subtract(quantity));
                 }
 
                 // 计算出库结存单价
@@ -174,7 +184,7 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
 
                 // 赋值结存单价
                 inventory.setBalanceUnitPrice(balanceUnitPrice);
-                inventory.setQuantity(inventory.getQuantity().subtract(quantity));
+
             }
 
             // 修改计算结存单价的出入库明细表
@@ -233,6 +243,7 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
                 inventory.setWarehouseId(warehouseId);
                 inventory.setDepartmentId(departmentId);
                 inventory.setQuantity(new BigDecimal(quantity));
+                inventory.setLockQuantity(BigDecimal.ZERO);
                 inventory.setBalanceUnitPrice(BigDecimal.ZERO);
                 save(inventory);
             }
@@ -289,6 +300,7 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
                     addInventory.setDepartmentId(dto.getDepartmentId());
                     addInventory.setBomSpecId(bomSpecId);
                     addInventory.setQuantity(quantity);
+                    addInventory.setLockQuantity(BigDecimal.ZERO);
                     addInventory.setBalanceUnitPrice(BigDecimal.ZERO);
                     addInventoryList.add(addInventory);
 
@@ -437,6 +449,7 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
                     tempInventory.setDepartmentId(departmentId);
                     tempInventory.setBomSpecId(item);
                     tempInventory.setQuantity(BigDecimal.ZERO);
+                    tempInventory.setLockQuantity(BigDecimal.ZERO);
                     tempInventory.setBalanceUnitPrice(BigDecimal.ZERO);
                     inventoryList.add(tempInventory);
                     return tempInventory;
@@ -450,7 +463,6 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
 
                 // 获取入库结存单价
                 BigDecimal balanceUnitPrice = sumPrice.divide(sumQuantity, 2, RoundingMode.HALF_UP);
-                ;
 
                 inventory.setQuantity(sumQuantity);
                 inventory.setBalanceUnitPrice(balanceUnitPrice);

+ 60 - 32
sd-business/src/main/java/com/sd/business/service/production/impl/StockPreparationServiceImpl.java

@@ -10,6 +10,7 @@ import com.ruoyi.common.utils.wrapper.IWrapper;
 import com.sd.business.entity.bom.bo.BomSpecBo;
 import com.sd.business.entity.bom.po.BomSpec;
 import com.sd.business.entity.department.po.Department;
+import com.sd.business.entity.in.bo.InOutStorageBomBo;
 import com.sd.business.entity.in.dto.InOutStorageDto;
 import com.sd.business.entity.in.emums.InOutTypeEnum;
 import com.sd.business.entity.in.emums.OutDetailTypeEnum;
@@ -197,7 +198,7 @@ public class StockPreparationServiceImpl implements StockPreparationService {
                 .set(OrderSku::getStockPreparationStatus, StatusConstant.YES));
 
         // 订单出库
-        orderDelivery(orderIdList, dto);
+        orderDelivery(list, dto);
 
         List<ProductionTask> productionTaskList = new ArrayList<>();
         List<ProductionWorkOrder> productionWorkOrderList = new ArrayList<>();
@@ -333,7 +334,7 @@ public class StockPreparationServiceImpl implements StockPreparationService {
         if (semiFinishedProductBomSpecIdList.size() > 0) {
             semiFinishedProductInventoryMap = inventoryService.mapKV(
                     Inventory::getBomSpecId,
-                    Inventory::getQuantity,
+                    item -> item.getQuantity().add(item.getLockQuantity()),
                     q -> q.eq(Inventory::getWarehouseId, WarehouseConstant.SEMI_FINISHED_PRODUCT)
                             .eq(Inventory::getDepartmentId, outDepartmentId)
                             .in(Inventory::getBomSpecId, semiFinishedProductBomSpecIdList)
@@ -349,7 +350,7 @@ public class StockPreparationServiceImpl implements StockPreparationService {
         if (packagingMaterialBomSpecIdList.size() > 0) {
             packagingMaterialInventoryMap = inventoryService.mapKV(
                     Inventory::getBomSpecId,
-                    Inventory::getQuantity,
+                    item -> item.getQuantity().add(item.getLockQuantity()),
                     q -> q.eq(Inventory::getWarehouseId, WarehouseConstant.PACKAGING_MATERIAL)
                             .eq(Inventory::getDepartmentId, outDepartmentId)
                             .in(Inventory::getBomSpecId, packagingMaterialBomSpecIdList)
@@ -459,25 +460,31 @@ public class StockPreparationServiceImpl implements StockPreparationService {
     /**
      * 订单出库
      */
-    private void orderDelivery(List<Long> orderIdList, StockPreparationDto dto) {
+    private void orderDelivery(List<StockPreparationVo> stockPreparationVoList, StockPreparationDto dto) {
 
-        List<OrderSku> orderSkuList = orderSkuService.list(q -> q.in(OrderSku::getOrderId, orderIdList));
-        List<OrderSkuBom> orderSkuBomList = orderSkuBomService.list(q -> q.in(OrderSkuBom::getOrderId, orderIdList));
+        Map<Long, Integer> orderIdLockStorageMap = stockPreparationVoList.stream().collect(
+                Collectors.toMap(StockPreparationVo::getOrderId, StockPreparationVo::getLockStorage, (v1, v2) -> v1));
+
+        List<OrderSku> orderSkuList = orderSkuService.list(q -> q.in(OrderSku::getOrderId, orderIdLockStorageMap.keySet()));
+        List<OrderSkuBom> orderSkuBomList = orderSkuBomService.list(q -> q.in(OrderSkuBom::getOrderId, orderIdLockStorageMap.keySet()));
         Map<Long, OrderSku> orderSkuMap = orderSkuList.stream().collect(Collectors.toMap(BaseIdPo::getId, Function.identity()));
 
-        Map<Long, InOutStorageBom> map = Stream.concat(
+        Map<Long, InOutStorageBomBo> map = Stream.concat(
                         // 主材
                         orderSkuList.stream().map(item -> {
-                            InOutStorageBom inOutStorageBom = new InOutStorageBom();
+                            Integer lockStorage = orderIdLockStorageMap.get(item.getOrderId());
+
+                            InOutStorageBomBo inOutStorageBom = new InOutStorageBomBo();
                             inOutStorageBom.setBomSpecId(item.getBomSpecId());
                             inOutStorageBom.setQuantity(item.getQuantity());
+                            inOutStorageBom.setLockStorage(lockStorage);
                             return inOutStorageBom;
                         }),
 
                         // 包材
                         orderSkuBomList.stream().map(item -> {
                             OrderSku orderSku = orderSkuMap.get(item.getOrderSkuId());
-                            InOutStorageBom inOutStorageBom = new InOutStorageBom();
+                            InOutStorageBomBo inOutStorageBom = new InOutStorageBomBo();
                             inOutStorageBom.setBomSpecId(item.getBomSpecId());
                             inOutStorageBom.setQuantity(item.getQuantity().multiply(orderSku.getQuantity()));
                             return inOutStorageBom;
@@ -492,40 +499,61 @@ public class StockPreparationServiceImpl implements StockPreparationService {
                         })
                 );
 
+        Map<Long, BomSpecBo> bomSpecBo = skuSpecService.getBomSpecBoByIdList(map.keySet());
+
         // 合并sku主材和包材
-        List<InOutStorageBom> list = new ArrayList<>(map.values());
+        List<InOutStorageBomBo> list = new ArrayList<>(map.values());
 
-        Map<Long, BomSpecBo> bomSpecBo = skuSpecService.getBomSpecBoByIdList(map.keySet());
+        // 主材从半成品仓出库(从冻结库存出库)
+        List<InOutStorageBom> lockSemiFinishedProductInOutStorageBomList = list.stream()
+                .filter(item -> ObjectUtil.equal(bomSpecBo.get(item.getBomSpecId()).getClassifyParentId(), 1L))
+                .filter(item -> ObjectUtil.equal(item.getLockStorage(), StatusConstant.YES))
+                .collect(Collectors.toList());
+        if (lockSemiFinishedProductInOutStorageBomList.size() > 0) {
+            InOutStorageDto lockSemiFinishedProduct = new InOutStorageDto();
+            lockSemiFinishedProduct.setType(InOutTypeEnum.OUT.getKey());
+            lockSemiFinishedProduct.setDetailType(OutDetailTypeEnum.PRODUCTION.getKey());
+            lockSemiFinishedProduct.setWarehouseId(WarehouseConstant.SEMI_FINISHED_PRODUCT);
+            lockSemiFinishedProduct.setDepartmentId(dto.getOutDepartmentId());
+            lockSemiFinishedProduct.setApplicant(dto.getApplicant());
+            lockSemiFinishedProduct.setRemark(dto.getRemark());
+            lockSemiFinishedProduct.setLockStorage(StatusConstant.YES);
+            lockSemiFinishedProduct.setInOutStorageBomList(lockSemiFinishedProductInOutStorageBomList);
+            inOutStorageService.add(lockSemiFinishedProduct);
+        }
 
-        // 主材从半成品仓出库
+        // 主材从半成品仓出库(从非冻结库存出库)
         List<InOutStorageBom> semiFinishedProductInOutStorageBomList = list.stream()
                 .filter(item -> ObjectUtil.equal(bomSpecBo.get(item.getBomSpecId()).getClassifyParentId(), 1L))
+                .filter(item -> ObjectUtil.notEqual(item.getLockStorage(), StatusConstant.YES))
                 .collect(Collectors.toList());
-
-        InOutStorageDto semiFinishedProduct = new InOutStorageDto();
-        semiFinishedProduct.setType(InOutTypeEnum.OUT.getKey());
-        semiFinishedProduct.setDetailType(OutDetailTypeEnum.PRODUCTION.getKey());
-        semiFinishedProduct.setWarehouseId(WarehouseConstant.SEMI_FINISHED_PRODUCT);
-        semiFinishedProduct.setDepartmentId(dto.getOutDepartmentId());
-        semiFinishedProduct.setApplicant(dto.getApplicant());
-        semiFinishedProduct.setRemark(dto.getRemark());
-        semiFinishedProduct.setInOutStorageBomList(semiFinishedProductInOutStorageBomList);
-        inOutStorageService.add(semiFinishedProduct);
+        if (semiFinishedProductInOutStorageBomList.size() > 0) {
+            InOutStorageDto semiFinishedProduct = new InOutStorageDto();
+            semiFinishedProduct.setType(InOutTypeEnum.OUT.getKey());
+            semiFinishedProduct.setDetailType(OutDetailTypeEnum.PRODUCTION.getKey());
+            semiFinishedProduct.setWarehouseId(WarehouseConstant.SEMI_FINISHED_PRODUCT);
+            semiFinishedProduct.setDepartmentId(dto.getOutDepartmentId());
+            semiFinishedProduct.setApplicant(dto.getApplicant());
+            semiFinishedProduct.setRemark(dto.getRemark());
+            semiFinishedProduct.setInOutStorageBomList(semiFinishedProductInOutStorageBomList);
+            inOutStorageService.add(semiFinishedProduct);
+        }
 
         // 包材从包材仓出库
         List<InOutStorageBom> packagingMaterialInOutStorageBomList = list.stream()
                 .filter(item -> ObjectUtil.notEqual(bomSpecBo.get(item.getBomSpecId()).getClassifyParentId(), 1L))
                 .collect(Collectors.toList());
-
-        InOutStorageDto packagingMaterial = new InOutStorageDto();
-        packagingMaterial.setType(InOutTypeEnum.OUT.getKey());
-        packagingMaterial.setDetailType(OutDetailTypeEnum.PRODUCTION.getKey());
-        packagingMaterial.setWarehouseId(WarehouseConstant.PACKAGING_MATERIAL);
-        packagingMaterial.setDepartmentId(dto.getOutDepartmentId());
-        packagingMaterial.setApplicant(dto.getApplicant());
-        packagingMaterial.setRemark(dto.getRemark());
-        packagingMaterial.setInOutStorageBomList(packagingMaterialInOutStorageBomList);
-        inOutStorageService.add(packagingMaterial);
+        if (packagingMaterialInOutStorageBomList.size() > 0) {
+            InOutStorageDto packagingMaterial = new InOutStorageDto();
+            packagingMaterial.setType(InOutTypeEnum.OUT.getKey());
+            packagingMaterial.setDetailType(OutDetailTypeEnum.PRODUCTION.getKey());
+            packagingMaterial.setWarehouseId(WarehouseConstant.PACKAGING_MATERIAL);
+            packagingMaterial.setDepartmentId(dto.getOutDepartmentId());
+            packagingMaterial.setApplicant(dto.getApplicant());
+            packagingMaterial.setRemark(dto.getRemark());
+            packagingMaterial.setInOutStorageBomList(packagingMaterialInOutStorageBomList);
+            inOutStorageService.add(packagingMaterial);
+        }
 
     }
 

+ 1 - 0
sd-starter/src/test/java/C1_SyncInventoryTest.java

@@ -91,6 +91,7 @@ public class C1_SyncInventoryTest {
             inventory.setDepartmentId(0L);
             inventory.setWarehouseId(warehouseId);
             inventory.setBalanceUnitPrice(excelData.getBalanceUnitPrice());
+            inventory.setLockQuantity(BigDecimal.ZERO);
             inventorieList.add(inventory);
 
 

+ 1 - 0
sd-starter/src/test/java/C2_SyncInventoryTest.java

@@ -77,6 +77,7 @@ public class C2_SyncInventoryTest {
                 inventory.setDepartmentId(0L);
                 inventory.setQuantity(new BigDecimal(quantity));
                 inventory.setBalanceUnitPrice(BigDecimal.ZERO);
+                inventory.setLockQuantity(BigDecimal.ZERO);
                 inventoryService.save(inventory);
                 System.err.println(code + " 0库存");
             }