소스 검색

提交备料修改

24282 1 년 전
부모
커밋
2f067bed0d

+ 1 - 0
sd-business/src/main/java/com/sd/business/entity/in/po/InOutStorageBom.java

@@ -53,4 +53,5 @@ public class InOutStorageBom extends BasePo implements InOutFun {
      * 结存库存数量
      */
     private BigDecimal balanceInventoryQuantity;
+
 }

+ 1 - 0
sd-business/src/main/java/com/sd/business/entity/inventory/bo/InOutFun.java

@@ -18,4 +18,5 @@ public interface InOutFun {
      * 保存结存库存数量
      */
     void setBalanceInventoryQuantity(BigDecimal balanceInventoryQuantity);
+
 }

+ 7 - 6
sd-business/src/main/java/com/sd/business/service/inventory/impl/InventoryServiceImpl.java

@@ -161,23 +161,23 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
             Map<Long, List<InOutStorageDetails>> inOutStorageDetailsMap = getInOutStorageDetailsMap(warehouseId, bomSpecIdList);
 
             for (InOutFun inOutFun : list) {
-                Long bomSpecId = inOutFun.getBomSpecId();
-                BigDecimal quantity = inOutFun.getQuantity();
 
+                BigDecimal quantity = inOutFun.getQuantity();
+                Long bomSpecId = inOutFun.getBomSpecId();
                 Inventory inventory = inventoryMap.get(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库存不足,库存为:" +
+                        throw new ServiceException("出库失败,品号为:" + bomSpec.getCode() + " 的bom库存不足,库存为:" +
                                 (inventory == null ? BigDecimal.ZERO : inventory.getQuantity()) + ",需要出库:" + quantity);
                     }
                     inventory.setQuantity(inventory.getQuantity().subtract(quantity));
@@ -191,6 +191,7 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
 
                 // 保存当前入库记录的结存库存
                 inOutFun.setBalanceInventoryQuantity(inventory.getQuantity().add(inventory.getLockQuantity()));
+
             }
 
             // 修改计算结存单价的出入库明细表
@@ -464,7 +465,7 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
                 });
                 PurchaseBom purchaseBom = purchaseBomMap.get(inOutFun.getBomSpecId());
                 // 实际库存数  当前库存数量加锁定库存
-                BigDecimal actualInventoryQuantity  = inventory.getQuantity().add(inventory.getLockQuantity());
+                BigDecimal actualInventoryQuantity = inventory.getQuantity().add(inventory.getLockQuantity());
                 // 结存数量
                 BigDecimal sumQuantity = actualInventoryQuantity.add(inOutFun.getQuantity());
                 // 结存金额

+ 13 - 6
sd-business/src/main/java/com/sd/business/service/order/impl/OrderServiceImpl.java

@@ -6,6 +6,7 @@ import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson2.JSON;
 import com.baomidou.dynamic.datasource.annotation.DSTransactional;
+import com.baomidou.mybatisplus.core.toolkit.StringPool;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fjhx.file.utils.ObsFileUtil;
@@ -38,7 +39,6 @@ import com.sd.business.entity.order.vo.*;
 import com.sd.business.entity.price.po.PriceBillingStandard;
 import com.sd.business.entity.price.po.PriceBillingStandardDetail;
 import com.sd.business.entity.sku.po.SkuSpec;
-import com.sd.business.entity.statement.dto.StatementOfAccountDto;
 import com.sd.business.entity.statement.po.StatementOfAccount;
 import com.sd.business.entity.warehouse.constant.WarehouseConstant;
 import com.sd.business.mapper.order.OrderMapper;
@@ -282,7 +282,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderInfo> implem
             // 拥有采购角色的账号创建的自主订单为采购订单
             Long userId = SecurityUtils.getUserId();
             Set<String> roleKeys = roleService.selectRolePermissionByUserId(userId);
-            if (!Collections.disjoint(roleKeys, Arrays.asList("sypurchasing","purchasingOfficer","bzpurchasing"))) {
+            if (!Collections.disjoint(roleKeys, Arrays.asList("sypurchasing", "purchasingOfficer", "bzpurchasing"))) {
                 orderDto.setClassify(OrderClassifyEnum.PURCHASE_ORDER.getKey());
             }
         }
@@ -352,7 +352,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderInfo> implem
             // 拥有采购角色的账号创建的自主订单为采购订单
             Long userId = dto.getCreateUser();
             Set<String> roleKeys = roleService.selectRolePermissionByUserId(userId);
-            if (!Collections.disjoint(roleKeys, Arrays.asList("sypurchasing","purchasingOfficer","bzpurchasing"))) {
+            if (!Collections.disjoint(roleKeys, Arrays.asList("sypurchasing", "purchasingOfficer", "bzpurchasing"))) {
                 dto.setClassify(OrderClassifyEnum.PURCHASE_ORDER.getKey());
             }
         }
@@ -441,7 +441,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderInfo> implem
             // 拥有采购角色的账号创建的自主订单为采购订单
             Long userId = dto.getCreateUser();
             Set<String> roleKeys = roleService.selectRolePermissionByUserId(userId);
-            if (!Collections.disjoint(roleKeys, Arrays.asList("sypurchasing","purchasingOfficer","bzpurchasing"))) {
+            if (!Collections.disjoint(roleKeys, Arrays.asList("sypurchasing", "purchasingOfficer", "bzpurchasing"))) {
                 dto.setClassify(OrderClassifyEnum.PURCHASE_ORDER.getKey());
             }
         }
@@ -729,7 +729,9 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderInfo> implem
         semiFinishedProductInOutStorageDto.setWarehouseId(WarehouseConstant.SEMI_FINISHED_PRODUCT);
         semiFinishedProductInOutStorageDto.setDepartmentId(orderInfo.getOutDepartmentId());
         semiFinishedProductInOutStorageDto.setApplicant(SecurityUtils.getLoginUser().getUser().getNickName());
-        semiFinishedProductInOutStorageDto.setRemark("删除订单:" + orderInfo.getCode() + " 主材退料入库");
+        semiFinishedProductInOutStorageDto.setRemark("删除订单:" + orderInfo.getCode()
+                + (StrUtil.isBlank(orderInfo.getWlnCode()) ? StringPool.EMPTY : "(" + orderInfo.getWlnCode() + ")")
+                + " 主材退料入库");
         semiFinishedProductInOutStorageDto.setInOutStorageBomList(semiFinishedProductInOutStorageBomList);
         inOutStorageService.add(semiFinishedProductInOutStorageDto);
 
@@ -750,7 +752,9 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderInfo> implem
         packagingMaterialInOutStorageDto.setWarehouseId(WarehouseConstant.PACKAGING_MATERIAL);
         packagingMaterialInOutStorageDto.setDepartmentId(orderInfo.getOutDepartmentId());
         packagingMaterialInOutStorageDto.setApplicant(SecurityUtils.getLoginUser().getUser().getNickName());
-        packagingMaterialInOutStorageDto.setRemark("删除订单:" + orderInfo.getCode() + " 包材退料入库");
+        packagingMaterialInOutStorageDto.setRemark("删除订单:" + orderInfo.getCode()
+                + (StrUtil.isBlank(orderInfo.getWlnCode()) ? StringPool.EMPTY : "(" + orderInfo.getWlnCode() + ")")
+                + " 包材退料入库");
         packagingMaterialInOutStorageDto.setInOutStorageBomList(packagingMaterialInOutStorageBomList);
         inOutStorageService.add(packagingMaterialInOutStorageDto);
 
@@ -920,6 +924,9 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderInfo> implem
             return;
         }
 
+        orderInfo.setLockStorage(StatusConstant.NO);
+        update(q -> q.eq(BaseIdPo::getId, orderInfo.getId()).set(OrderInfo::getLockStorage, StatusConstant.NO));
+
         List<OrderSku> orderSkuList = orderSkuService.list(q -> q.eq(OrderSku::getOrderId, orderInfo.getId()));
 
         List<Long> bomSpecIdList = orderSkuList.stream().map(OrderSku::getBomSpecId).collect(Collectors.toList());

+ 61 - 67
sd-business/src/main/java/com/sd/business/service/production/impl/StockPreparationServiceImpl.java

@@ -292,7 +292,7 @@ public class StockPreparationServiceImpl implements StockPreparationService {
         IWrapper<StockPreparationVo> wrapper = getWrapper(dto);
         List<StockPreparationVo> stockPreparationVoList = stockPreparationMapper.uncompletedList(wrapper);
 
-        if (stockPreparationVoList.size() == 0) {
+        if (stockPreparationVoList.isEmpty()) {
             return Collections.emptyList();
         }
 
@@ -361,7 +361,7 @@ public class StockPreparationServiceImpl implements StockPreparationService {
                 .filter(item -> WarehouseConstant.SEMI_FINISHED_PRODUCT.equals(item.getWarehouseId()))
                 .map(OutBomVo::getBomSpecId)
                 .collect(Collectors.toList());
-        if (semiFinishedProductBomSpecIdList.size() > 0) {
+        if (!semiFinishedProductBomSpecIdList.isEmpty()) {
             List<Inventory> tempList = inventoryService.list(q -> q.eq(Inventory::getWarehouseId, WarehouseConstant.SEMI_FINISHED_PRODUCT)
                     .eq(Inventory::getDepartmentId, outDepartmentId)
                     .in(Inventory::getBomSpecId, semiFinishedProductBomSpecIdList));
@@ -376,7 +376,7 @@ public class StockPreparationServiceImpl implements StockPreparationService {
                 .filter(item -> WarehouseConstant.PACKAGING_MATERIAL.equals(item.getWarehouseId()))
                 .map(OutBomVo::getBomSpecId)
                 .collect(Collectors.toList());
-        if (packagingMaterialBomSpecIdList.size() > 0) {
+        if (!packagingMaterialBomSpecIdList.isEmpty()) {
             List<Inventory> tempList = inventoryService.list(q -> q
                     .eq(Inventory::getWarehouseId, WarehouseConstant.PACKAGING_MATERIAL)
                     .eq(Inventory::getDepartmentId, outDepartmentId)
@@ -497,92 +497,86 @@ public class StockPreparationServiceImpl implements StockPreparationService {
         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, InOutStorageBomBo> map = Stream.concat(
-                        // 主材
-                        orderSkuList.stream().map(item -> {
-                            Integer lockStorage = orderIdLockStorageMap.get(item.getOrderId());
+        List<InOutStorageBomBo> inOutStorageBomBoList = Stream.concat(
 
-                            InOutStorageBomBo inOutStorageBom = new InOutStorageBomBo();
-                            inOutStorageBom.setBomSpecId(item.getBomSpecId());
-                            inOutStorageBom.setQuantity(item.getQuantity());
-                            inOutStorageBom.setLockStorage(lockStorage);
-                            return inOutStorageBom;
-                        }),
+                // 主材
+                orderSkuList.stream().map(item -> {
+                    InOutStorageBomBo inOutStorageBom = new InOutStorageBomBo();
+                    inOutStorageBom.setBomSpecId(item.getBomSpecId());
+                    inOutStorageBom.setQuantity(item.getQuantity());
+                    inOutStorageBom.setLockStorage(orderIdLockStorageMap.get(item.getOrderId()));
+                    return inOutStorageBom;
+                }),
 
-                        // 包材
-                        orderSkuBomList.stream().map(item -> {
-                            OrderSku orderSku = orderSkuMap.get(item.getOrderSkuId());
-                            InOutStorageBomBo inOutStorageBom = new InOutStorageBomBo();
-                            inOutStorageBom.setBomSpecId(item.getBomSpecId());
-                            inOutStorageBom.setQuantity(item.getQuantity().multiply(orderSku.getQuantity()));
-                            return inOutStorageBom;
-                        })
-                )
-                .collect(Collectors.toMap(
-                        InOutStorageBom::getBomSpecId,
-                        Function.identity(),
-                        (v1, v2) -> {
-                            v1.setQuantity(v1.getQuantity().add(v2.getQuantity()));
-                            return v1;
-                        })
-                );
+                // 包材
+                orderSkuBomList.stream().map(item -> {
+                    InOutStorageBomBo inOutStorageBom = new InOutStorageBomBo();
+                    inOutStorageBom.setBomSpecId(item.getBomSpecId());
+                    inOutStorageBom.setQuantity(item.getQuantity().multiply(orderSkuMap.get(item.getOrderSkuId()).getQuantity()));
+                    return inOutStorageBom;
+                })
 
-        Map<Long, BomSpecBo> bomSpecBo = skuSpecService.getBomSpecBoByIdList(map.keySet());
+        ).collect(Collectors.toList());
 
-        // 合并sku主材和包材
-        List<InOutStorageBomBo> list = new ArrayList<>(map.values());
+        List<Long> bomSpecIdList = inOutStorageBomBoList.stream().map(InOutStorageBom::getBomSpecId).collect(Collectors.toList());
+        Map<Long, BomSpecBo> bomSpecBo = skuSpecService.getBomSpecBoByIdList(bomSpecIdList);
 
         // 主材从半成品仓出库(从冻结库存出库)
-        List<InOutStorageBom> lockSemiFinishedProductInOutStorageBomList = list.stream()
+        List<InOutStorageBom> lockSemiFinishedProductInOutStorageBomList = inOutStorageBomBoList.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);
+        if (!lockSemiFinishedProductInOutStorageBomList.isEmpty()) {
+            productionOut(WarehouseConstant.SEMI_FINISHED_PRODUCT, dto, lockSemiFinishedProductInOutStorageBomList, StatusConstant.YES);
         }
 
         // 主材从半成品仓出库(从非冻结库存出库)
-        List<InOutStorageBom> semiFinishedProductInOutStorageBomList = list.stream()
+        List<InOutStorageBom> semiFinishedProductInOutStorageBomList = inOutStorageBomBoList.stream()
                 .filter(item -> ObjectUtil.equal(bomSpecBo.get(item.getBomSpecId()).getClassifyParentId(), 1L))
                 .filter(item -> ObjectUtil.notEqual(item.getLockStorage(), StatusConstant.YES))
                 .collect(Collectors.toList());
-        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);
+        if (!semiFinishedProductInOutStorageBomList.isEmpty()) {
+            productionOut(WarehouseConstant.SEMI_FINISHED_PRODUCT, dto, semiFinishedProductInOutStorageBomList, StatusConstant.NO);
         }
 
         // 包材从包材仓出库
-        List<InOutStorageBom> packagingMaterialInOutStorageBomList = list.stream()
+        List<InOutStorageBom> packagingMaterialInOutStorageBomList = inOutStorageBomBoList.stream()
                 .filter(item -> ObjectUtil.notEqual(bomSpecBo.get(item.getBomSpecId()).getClassifyParentId(), 1L))
                 .collect(Collectors.toList());
-        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);
+        if (!packagingMaterialInOutStorageBomList.isEmpty()) {
+            productionOut(WarehouseConstant.PACKAGING_MATERIAL, dto, packagingMaterialInOutStorageBomList, StatusConstant.NO);
         }
 
     }
 
+    /**
+     * 生产出库
+     *
+     * @param warehouseId         出库id
+     * @param dto                 入参
+     * @param inOutStorageBomList 出库bom规格明细
+     */
+    private void productionOut(Long warehouseId, StockPreparationDto dto, List<InOutStorageBom> inOutStorageBomList, Integer lockStorage) {
+
+        // 合并相同bom规格出库数量
+        List<InOutStorageBom> list = new ArrayList<>(inOutStorageBomList.stream().collect(Collectors.toMap(
+                InOutStorageBom::getBomSpecId,
+                Function.identity(),
+                (v1, v2) -> {
+                    v1.setQuantity(v1.getQuantity().add(v2.getQuantity()));
+                    return v1;
+                })).values());
+
+        InOutStorageDto inOutStorageDto = new InOutStorageDto();
+        inOutStorageDto.setType(InOutTypeEnum.OUT.getKey());
+        inOutStorageDto.setDetailType(OutDetailTypeEnum.PRODUCTION.getKey());
+        inOutStorageDto.setWarehouseId(warehouseId);
+        inOutStorageDto.setDepartmentId(dto.getOutDepartmentId());
+        inOutStorageDto.setApplicant(dto.getApplicant());
+        inOutStorageDto.setRemark(dto.getRemark());
+        inOutStorageDto.setInOutStorageBomList(list);
+        inOutStorageDto.setLockStorage(lockStorage);
+        inOutStorageService.add(inOutStorageDto);
+    }
+
 }