24282 1 년 전
부모
커밋
626699a8a2

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

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

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

@@ -1,5 +1,6 @@
 package com.sd.business.service.in.impl;
 
+import cn.hutool.core.util.ObjectUtil;
 import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -75,31 +76,26 @@ public class InOutStorageServiceImpl extends ServiceImpl<InOutStorageMapper, InO
     @Transactional(rollbackFor = Exception.class)
     @Override
     public void add(InOutStorageDto dto) {
-
         dto.setId(IdWorker.getId());
+        dto.setInOutStorageTime(ObjectUtil.defaultIfNull(dto.getInOutStorageTime(), new Date()));
+
         List<InOutStorageBom> inOutStorageBomList = dto.getInOutStorageBomList();
         inOutStorageBomList.forEach(item -> item.setInOutStorageId(dto.getId()));
 
         if (InOutTypeEnum.getInOutType(dto.getType()).equals(InOutTypeEnum.IN)) {
-            // 赋值入库单号
-            dto.setCode(CodeEnum.IN_CODE.getCode());
             if (InDetailTypeEnum.PURCHASE.getKey().equals(dto.getDetailType())) {
-                // 采购入库
-                inventoryService.purchaseInStorage(dto.getPurchaseId(), dto.getDepartmentId(), dto.getWarehouseId(), inOutStorageBomList);
                 // 更新采购到货数量
                 purchaseService.updatePurchaseBomArrivalQuantity(dto.getPurchaseId(), inOutStorageBomList);
-            } else {
-                // 更新库存
-                inventoryService.in(dto.getDepartmentId(), dto.getWarehouseId(), inOutStorageBomList);
             }
+            // 赋值入库单号
+            dto.setCode(CodeEnum.IN_CODE.getCode());
+            // 更新库存
+            inventoryService.in(dto);
         } else {
             // 赋值出库单号
             dto.setCode(CodeEnum.OUT_CODE.getCode());
             // 更新库存
-            inventoryService.out(dto.getDepartmentId(), dto.getWarehouseId(), inOutStorageBomList, dto.getLockStorage());
-        }
-        if (dto.getInOutStorageTime() == null) {
-            dto.setInOutStorageTime(new Date());
+            inventoryService.out(dto);
         }
 
         // 保存出入库信息

+ 3 - 18
sd-business/src/main/java/com/sd/business/service/inventory/InventoryService.java

@@ -2,8 +2,7 @@ package com.sd.business.service.inventory;
 
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ruoyi.common.core.service.BaseService;
-import com.sd.business.entity.in.po.InOutStorageBom;
-import com.sd.business.entity.inventory.bo.InOutFun;
+import com.sd.business.entity.in.dto.InOutStorageDto;
 import com.sd.business.entity.inventory.dto.InventorySelectDto;
 import com.sd.business.entity.inventory.dto.QuantityByDepartmentDto;
 import com.sd.business.entity.inventory.dto.QuantityByWarehouseDto;
@@ -54,27 +53,13 @@ public interface InventoryService extends BaseService<Inventory> {
     List<QuantityByDepartmentVo> getQuantityByDepartment(QuantityByDepartmentDto dto);
 
     /**
-     * 采购入库
-     */
-    void purchaseInStorage(Long purchaseId, Long departmentId, Long warehouseId, List<InOutStorageBom> inOutStorageBomList);
-
-    /**
      * 入库逻辑
-     *
-     * @param departmentId 事业部id
-     * @param warehouseId  仓库id
-     * @param list         入库明细
      */
-    void in(Long departmentId, Long warehouseId, List<? extends InOutFun> list);
+    void in(InOutStorageDto dto);
 
     /**
      * 出库逻辑
-     *
-     * @param departmentId 事业部id
-     * @param warehouseId  仓库id
-     * @param list         出库明细
-     * @param lockStorage  是否从锁定库存出库
      */
-    void out(Long departmentId, Long warehouseId, List<? extends InOutFun> list, Integer lockStorage);
+    void out(InOutStorageDto dto);
 
 }

+ 14 - 46
sd-business/src/main/java/com/sd/business/service/inventory/impl/InventoryServiceImpl.java

@@ -7,6 +7,7 @@ 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.department.po.Department;
+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;
@@ -133,55 +134,21 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
     }
 
     @Override
-    public void purchaseInStorage(Long purchaseId, Long departmentId, Long warehouseId, List<InOutStorageBom> inOutStorageBomList) {
-        List<Long> bomSpecIdList = inOutStorageBomList.stream().map(InOutStorageBom::getBomSpecId).collect(Collectors.toList());
-        synchronized (this) {
-
-            // 通过事业部id和出库id获取bom规格库存
-            List<Inventory> inventoryList = getInventoryList(departmentId, warehouseId, bomSpecIdList);
-
-            // 通过bom规格分组
-            Map<Long, Inventory> map = inventoryList.stream().collect(Collectors.toMap(Inventory::getBomSpecId, Function.identity()));
-
-            for (InOutStorageBom inOutStorageBom : inOutStorageBomList) {
-
-                // 库存
-                Inventory inventory = map.computeIfAbsent(inOutStorageBom.getBomSpecId(), item -> {
-                    Inventory tempInventory = new Inventory();
-                    tempInventory.setWarehouseId(warehouseId);
-                    tempInventory.setDepartmentId(departmentId);
-                    tempInventory.setBomSpecId(item);
-                    tempInventory.setQuantity(BigDecimal.ZERO);
-                    inventoryList.add(tempInventory);
-                    return tempInventory;
-                });
-
-                // 数量
-                BigDecimal sumQuantity = inventory.getQuantity().add(inOutStorageBom.getQuantity());
-                inventory.setQuantity(sumQuantity);
-            }
-
-            saveOrUpdateBatch(inventoryList);
-        }
-    }
-
-    @Override
-    public void in(Long departmentId, Long warehouseId, List<? extends InOutFun> list) {
-        if (list.isEmpty()) {
-            return;
-        }
+    public void in(InOutStorageDto dto) {
+        List<InOutStorageBom> list = dto.getInOutStorageBomList();
+        Long departmentId = dto.getDepartmentId();
+        Long warehouseId = dto.getWarehouseId();
 
         List<Long> bomSpecIdList = list.stream().map(InOutFun::getBomSpecId).collect(Collectors.toList());
 
         synchronized (this) {
-
             // 通过事业部id和出库id获取bom规格库存
             List<Inventory> inventoryList = getInventoryList(departmentId, warehouseId, bomSpecIdList);
 
             // 通过bom规格分组
             Map<Long, Inventory> map = inventoryList.stream().collect(Collectors.toMap(Inventory::getBomSpecId, Function.identity()));
-            for (InOutFun inOutFun : list) {
 
+            for (InOutFun inOutFun : list) {
                 // 库存
                 Inventory inventory = map.computeIfAbsent(inOutFun.getBomSpecId(), item -> {
                     Inventory tempInventory = new Inventory();
@@ -189,32 +156,34 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
                     tempInventory.setDepartmentId(departmentId);
                     tempInventory.setBomSpecId(item);
                     tempInventory.setQuantity(BigDecimal.ZERO);
-                    inventoryList.add(tempInventory);
                     return tempInventory;
                 });
                 inventory.setQuantity(inventory.getQuantity().add(inOutFun.getQuantity()));
             }
 
-            saveOrUpdateBatch(inventoryList);
+            saveOrUpdateBatch(map.values());
         }
     }
 
     @Override
-    public void out(Long departmentId, Long warehouseId, List<? extends InOutFun> list, Integer lockStorage) {
+    public void out(InOutStorageDto dto) {
+        List<InOutStorageBom> list = dto.getInOutStorageBomList();
+        Long departmentId = dto.getDepartmentId();
+        Long warehouseId = dto.getWarehouseId();
+
         List<Long> bomSpecIdList = list.stream().map(InOutFun::getBomSpecId).collect(Collectors.toList());
 
         synchronized (this) {
 
             // 通过事业部id和出库id获取bom规格库存
             List<Inventory> inventoryList = getInventoryList(departmentId, warehouseId, bomSpecIdList);
-            Map<Long, Inventory> inventoryMap = inventoryList.stream().collect(Collectors.toMap(Inventory::getBomSpecId, Function.identity()));
+            Map<Long, Inventory> map = inventoryList.stream().collect(Collectors.toMap(Inventory::getBomSpecId, Function.identity()));
 
             for (InOutFun inOutFun : list) {
 
                 BigDecimal quantity = inOutFun.getQuantity();
                 Long bomSpecId = inOutFun.getBomSpecId();
-                Inventory inventory = inventoryMap.get(bomSpecId);
-
+                Inventory inventory = map.get(bomSpecId);
 
                 if (inventory == null || inventory.getQuantity().compareTo(quantity) < 0) {
                     BomSpec bomSpec = bomSpecService.getById(bomSpecId);
@@ -225,7 +194,6 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
                             (inventory == null ? BigDecimal.ZERO : inventory.getQuantity()) + ",需要出库:" + quantity);
                 }
                 inventory.setQuantity(inventory.getQuantity().subtract(quantity));
-
             }
 
             // 修改库存数量

+ 0 - 1
sd-business/src/main/java/com/sd/business/service/order/impl/OrderInfoServiceImpl.java

@@ -1233,7 +1233,6 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
             inOutStorageDto.setDepartmentId(DepartmentConstant.SD_SPORTS);
             inOutStorageDto.setApplicant(SecurityUtils.getLoginUser().getUser().getNickName());
             inOutStorageDto.setInOutStorageBomList(outStorageBomList);
-            inOutStorageDto.setLockStorage(StatusConstant.NO);
             inOutStorageService.add(inOutStorageDto);
         }
         if (!inBomMap.isEmpty()) {

+ 5 - 8
sd-business/src/main/java/com/sd/business/service/purchase/impl/PurchaseServiceImpl.java

@@ -9,7 +9,6 @@ import com.fjhx.flow.enums.FlowStatusEnum;
 import com.ruoyi.common.constant.StatusConstant;
 import com.ruoyi.common.core.domain.BaseIdPo;
 import com.ruoyi.common.exception.ServiceException;
-import com.sd.business.entity.bom.bo.BomSpecBo;
 import com.sd.business.entity.bom.po.BomSpec;
 import com.sd.business.entity.in.po.InOutStorageBom;
 import com.sd.business.entity.purchase.dto.PurchaseBomImportDataDto;
@@ -24,7 +23,6 @@ import com.sd.business.mapper.purchase.PurchaseMapper;
 import com.sd.business.service.bom.BomSpecService;
 import com.sd.business.service.purchase.PurchaseBomService;
 import com.sd.business.service.purchase.PurchaseService;
-import com.sd.business.service.sku.SkuSpecService;
 import com.sd.business.service.supplier.SupplierService;
 import com.sd.business.util.CodeEnum;
 import com.sd.framework.util.Assert;
@@ -34,7 +32,10 @@ import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
 import java.math.RoundingMode;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
 import java.util.stream.Collectors;
 
 
@@ -56,12 +57,8 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase> i
     private BomSpecService bomSpecService;
 
     @Autowired
-    private SkuSpecService skuSpecService;
-
-    @Autowired
     private SupplierService supplierService;
 
-
     @Override
     public Page<PurchaseVo> getPage(PurchaseSelectDto dto) {
 
@@ -212,7 +209,6 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase> i
             purchase.setTotalAmountExcludingTax(BigDecimal.ZERO);
             purchase.setDeliveryDate(bomList.get(0).getDeliveryDate());
 
-
             List<PurchaseBom> bomData = bomList.stream().map(item -> {
                 BomSpec bomSpec = bomSpecMap.get(item.getBomSpecCode());
                 if (bomSpec == null) {
@@ -267,4 +263,5 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase> i
             Assert.gtZero(new BigDecimal(dto.getUnitPrice()), "采购单价必须大于0");
         }
     }
+
 }