24282 1 year ago
parent
commit
3eeb34da50

+ 5 - 0
sd-business/src/main/java/com/sd/business/entity/in/po/InOutStorage.java

@@ -31,6 +31,11 @@ public class InOutStorage extends BasePo {
     private Integer detailType;
 
     /**
+     * 分类类型 1原料 2包材
+     */
+    private Integer classifyType;
+
+    /**
      * 出入库单号
      */
     private String code;

+ 11 - 2
sd-business/src/main/java/com/sd/business/entity/in/po/InOutStorageBom.java

@@ -2,7 +2,6 @@ package com.sd.business.entity.in.po;
 
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.ruoyi.common.core.domain.BasePo;
-import com.sd.business.entity.inventory.bo.InOutFun;
 import lombok.Getter;
 import lombok.Setter;
 
@@ -19,7 +18,7 @@ import java.math.BigDecimal;
 @Getter
 @Setter
 @TableName("in_out_storage_bom")
-public class InOutStorageBom extends BasePo implements InOutFun {
+public class InOutStorageBom extends BasePo {
 
     /**
      * 出入库id
@@ -27,6 +26,11 @@ public class InOutStorageBom extends BasePo implements InOutFun {
     private Long inOutStorageId;
 
     /**
+     * 分类类型 1原料 2包材
+     */
+    private Integer classifyType;
+
+    /**
      * bom规格id
      */
     private Long bomSpecId;
@@ -36,4 +40,9 @@ public class InOutStorageBom extends BasePo implements InOutFun {
      */
     private BigDecimal quantity;
 
+    /**
+     * 米数
+     */
+    private BigDecimal meter;
+
 }

+ 10 - 0
sd-business/src/main/java/com/sd/business/entity/inventory/po/Inventory.java

@@ -23,6 +23,11 @@ import java.math.BigDecimal;
 public class Inventory extends BasePo {
 
     /**
+     * 分类类型 1原料 2包材
+     */
+    private Integer classifyType;
+
+    /**
      * 仓库id
      */
     private Long warehouseId;
@@ -39,4 +44,9 @@ public class Inventory extends BasePo {
     @ExcelProperty(value = "可用库存", index = 3)
     private BigDecimal quantity;
 
+    /**
+     * 米数
+     */
+    private BigDecimal meter;
+
 }

+ 24 - 0
sd-business/src/main/java/com/sd/business/entity/work/po/WorkOrder.java

@@ -47,6 +47,30 @@ public class WorkOrder extends BasePo {
     private Long printingPaperBomSpecId;
 
     /**
+     * 主材库存id
+     */
+    @NotNull(message = "主材库存id不能为空")
+    private Long masterInventoryId;
+
+    /**
+     * 打印纸库存id
+     */
+    @NotNull(message = "打印纸库存id不能为空")
+    private Long printingPaperInventoryId;
+
+    /**
+     * 主材长度
+     */
+    @NotNull(message = "主材长度不能为空")
+    private BigDecimal masterLength;
+
+    /**
+     * 打印纸长度
+     */
+    @NotNull(message = "打印纸长度不能为空")
+    private BigDecimal printingPaperLength;
+
+    /**
      * 排单数量
      */
     @NotNull(message = "排单数量不能为空")

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

@@ -80,7 +80,10 @@ public class InOutStorageServiceImpl extends ServiceImpl<InOutStorageMapper, InO
         dto.setInOutStorageTime(ObjectUtil.defaultIfNull(dto.getInOutStorageTime(), new Date()));
 
         List<InOutStorageBom> inOutStorageBomList = dto.getInOutStorageBomList();
-        inOutStorageBomList.forEach(item -> item.setInOutStorageId(dto.getId()));
+        inOutStorageBomList.forEach(item -> {
+            item.setInOutStorageId(dto.getId());
+            item.setClassifyType(dto.getClassifyType());
+        });
 
         if (InOutTypeEnum.getInOutType(dto.getType()).equals(InOutTypeEnum.IN)) {
             if (InDetailTypeEnum.PURCHASE.getKey().equals(dto.getDetailType())) {

+ 90 - 27
sd-business/src/main/java/com/sd/business/service/inventory/impl/InventoryServiceImpl.java

@@ -3,12 +3,12 @@ package com.sd.business.service.inventory.impl;
 import cn.hutool.core.date.DateUtil;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.google.common.collect.HashBasedTable;
 import com.ruoyi.common.exception.ServiceException;
 import com.sd.business.entity.bom.po.Bom;
 import com.sd.business.entity.bom.po.BomSpec;
 import com.sd.business.entity.in.dto.InOutStorageDto;
 import com.sd.business.entity.in.po.InOutStorageBom;
-import com.sd.business.entity.inventory.bo.InOutFun;
 import com.sd.business.entity.inventory.dto.InventorySelectDto;
 import com.sd.business.entity.inventory.dto.QuantityByWarehouseDto;
 import com.sd.business.entity.inventory.dto.QuantityDto;
@@ -27,9 +27,10 @@ import org.springframework.stereotype.Service;
 import javax.servlet.http.HttpServletResponse;
 import java.math.BigDecimal;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.function.Function;
+import java.util.Objects;
 import java.util.stream.Collectors;
 
 
@@ -112,29 +113,68 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
     public void in(InOutStorageDto dto) {
         List<InOutStorageBom> list = dto.getInOutStorageBomList();
         Long warehouseId = dto.getWarehouseId();
+        Integer classifyType = dto.getClassifyType();
 
-        List<Long> bomSpecIdList = list.stream().map(InOutFun::getBomSpecId).collect(Collectors.toList());
+        List<Long> bomSpecIdList = list.stream().map(InOutStorageBom::getBomSpecId).collect(Collectors.toList());
 
         synchronized (this) {
             // 通过事业部id和出库id获取bom规格库存
             List<Inventory> inventoryList = getInventoryList(warehouseId, bomSpecIdList);
 
-            // 通过bom规格分组
-            Map<Long, Inventory> map = inventoryList.stream().collect(Collectors.toMap(Inventory::getBomSpecId, Function.identity()));
-
-            for (InOutFun inOutFun : list) {
-                // 库存
-                Inventory inventory = map.computeIfAbsent(inOutFun.getBomSpecId(), item -> {
-                    Inventory tempInventory = new Inventory();
-                    tempInventory.setWarehouseId(warehouseId);
-                    tempInventory.setBomSpecId(item);
-                    tempInventory.setQuantity(BigDecimal.ZERO);
-                    return tempInventory;
-                });
-                inventory.setQuantity(inventory.getQuantity().add(inOutFun.getQuantity()));
+            // 原料分组
+            HashBasedTable<Long, String, Inventory> meterMap = HashBasedTable.create();
+
+            // 包材分组
+            Map<Long, Inventory> map = new HashMap<>();
+
+            // 原料
+            if (Objects.equals(classifyType, 1)) {
+                inventoryList.forEach(item -> meterMap.put(item.getBomSpecId(), item.getMeter().toPlainString(), item));
+            }
+            // 包材
+            else {
+                inventoryList.forEach(item -> map.put(item.getBomSpecId(), item));
+            }
+
+            for (InOutStorageBom inOutStorageBom : list) {
+                Long bomSpecId = inOutStorageBom.getBomSpecId();
+                BigDecimal meter = inOutStorageBom.getMeter();
+
+                Inventory inventory;
+
+                // 原料
+                if (Objects.equals(classifyType, 1)) {
+                    inventory = meterMap.get(bomSpecId, meter.toPlainString());
+                }
+                // 包材
+                else {
+                    inventory = map.get(bomSpecId);
+                }
+
+                if (inventory == null) {
+                    inventory = new Inventory();
+                    inventory.setClassifyType(classifyType);
+                    inventory.setWarehouseId(warehouseId);
+                    inventory.setBomSpecId(bomSpecId);
+                    inventory.setQuantity(BigDecimal.ZERO);
+
+                    // 原料
+                    if (Objects.equals(classifyType, 1)) {
+                        inventory.setMeter(meter);
+                        meterMap.put(bomSpecId, meter.toPlainString(), inventory);
+                    }
+                    // 包材
+                    else {
+                        map.put(bomSpecId, inventory);
+                    }
+
+                    inventoryList.add(inventory);
+                }
+
+                inventory.setQuantity(inventory.getQuantity().add(inOutStorageBom.getQuantity()));
             }
 
-            saveOrUpdateBatch(map.values());
+            saveOrUpdateBatch(inventoryList);
         }
     }
 
@@ -142,20 +182,46 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
     public void out(InOutStorageDto dto) {
         List<InOutStorageBom> list = dto.getInOutStorageBomList();
         Long warehouseId = dto.getWarehouseId();
+        Integer classifyType = dto.getClassifyType();
 
-        List<Long> bomSpecIdList = list.stream().map(InOutFun::getBomSpecId).collect(Collectors.toList());
+        List<Long> bomSpecIdList = list.stream().map(InOutStorageBom::getBomSpecId).collect(Collectors.toList());
 
         synchronized (this) {
 
             // 通过事业部id和出库id获取bom规格库存
             List<Inventory> inventoryList = getInventoryList(warehouseId, bomSpecIdList);
-            Map<Long, Inventory> map = inventoryList.stream().collect(Collectors.toMap(Inventory::getBomSpecId, Function.identity()));
 
-            for (InOutFun inOutFun : list) {
+            // 原料分组
+            HashBasedTable<Long, String, Inventory> meterMap = HashBasedTable.create();
+
+            // 包材分组
+            Map<Long, Inventory> map = new HashMap<>();
+
+            // 原料
+            if (Objects.equals(classifyType, 1)) {
+                inventoryList.forEach(item -> meterMap.put(item.getBomSpecId(), item.getMeter().toPlainString(), item));
+            }
+            // 包材
+            else {
+                inventoryList.forEach(item -> map.put(item.getBomSpecId(), item));
+            }
+
+            for (InOutStorageBom inOutStorageBom : list) {
+
+                BigDecimal quantity = inOutStorageBom.getQuantity();
+                Long bomSpecId = inOutStorageBom.getBomSpecId();
+                BigDecimal meter = inOutStorageBom.getMeter();
 
-                BigDecimal quantity = inOutFun.getQuantity();
-                Long bomSpecId = inOutFun.getBomSpecId();
-                Inventory inventory = map.get(bomSpecId);
+                Inventory inventory;
+
+                // 原料
+                if (Objects.equals(classifyType, 1)) {
+                    inventory = meterMap.get(bomSpecId, meter.toPlainString());
+                }
+                // 包材
+                else {
+                    inventory = map.get(bomSpecId);
+                }
 
                 if (inventory == null || inventory.getQuantity().compareTo(quantity) < 0) {
                     BomSpec bomSpec = bomSpecService.getById(bomSpecId);
@@ -177,10 +243,7 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
      * 通过仓库id获取bom规格库存
      */
     private List<Inventory> getInventoryList(Long warehouseId, List<Long> bomSpecIdList) {
-        return list(q -> q
-                .eq(Inventory::getWarehouseId, warehouseId)
-                .in(Inventory::getBomSpecId, bomSpecIdList)
-        );
+        return list(q -> q.eq(Inventory::getWarehouseId, warehouseId).in(Inventory::getBomSpecId, bomSpecIdList));
     }
 
 }