From ef02f737f198ebe11178a956cb0e5caba2bc9508 Mon Sep 17 00:00:00 2001
From: cy <1664593601@qq.com>
Date: 星期三, 01 十一月 2023 15:59:47 +0800
Subject: [PATCH] feat: 盘点单生成入库、出库单

---
 consum-base/src/main/java/com/consum/base/service/LWhFormInventoryCoreService.java |  108 ++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 69 insertions(+), 39 deletions(-)

diff --git a/consum-base/src/main/java/com/consum/base/service/LWhFormInventoryCoreService.java b/consum-base/src/main/java/com/consum/base/service/LWhFormInventoryCoreService.java
index 6a5d972..149c587 100644
--- a/consum-base/src/main/java/com/consum/base/service/LWhFormInventoryCoreService.java
+++ b/consum-base/src/main/java/com/consum/base/service/LWhFormInventoryCoreService.java
@@ -3,7 +3,6 @@
 import com.consum.base.core.CodeGeneratorEnum;
 import com.consum.base.core.CodeGeneratorService;
 import com.consum.base.core.WhBusinessEnum;
-import com.consum.base.core.param.BaseWarehouseParam1;
 import com.consum.base.util.IdUtil;
 import com.consum.model.po.*;
 import com.iplatform.model.po.S_user_core;
@@ -82,24 +81,35 @@
      * errMsg 閿欒娑堟伅
      */
     @Transactional(rollbackFor = Exception.class)
-    public Map<String, Object> createInOutFormByInventoryId(Long whformInventoryId, S_user_core currentUser, FinSysTenantUser sysInfo) {
-        HashMap<String, Object> rtnMap = new HashMap<>();
+    public String createInOutFormByInventoryId(Long whformInventoryId, S_user_core currentUser, FinSysTenantUser sysInfo) {
+        LWhFormInventory lWhFormInventory = lWhFormInventoryService.get(new LWhFormInventory(whformInventoryId));
+        if (lWhFormInventory == null) {
+//            rtnMap.put("status", false);
+//            rtnMap.put("errMsg", "娌℃湁鎵惧埌鐩樼偣鍗�");
+            return "娌℃湁鎵惧埌鐩樼偣鍗�";
+        }
+        if (lWhFormInventory.getStates() != 1) {
+//            rtnMap.put("status", false);
+//            rtnMap.put("errMsg", "璇锋鏌ョ洏鐐瑰崟鐘舵��");
+            return "璇锋鏌ョ洏鐐瑰崟鐘舵��";
+        }
         List<LWhFormInventoryGoods> lWhFormInventoryGoods = this.lWhFormInventoryGoods.getByInventoryId(whformInventoryId);
         if (CollectionUtils.isEmpty(lWhFormInventoryGoods)) {
-            rtnMap.put("status", false);
-            rtnMap.put("errMsg", "娌℃湁鎵惧埌鐗╁搧");
-            return rtnMap;
+//            rtnMap.put("status", false);
+//            rtnMap.put("errMsg", "娌℃湁鎵惧埌鐩樼偣鍗曠粨鏋滅墿鍝�");
+            return "娌℃湁鎵惧埌鐩樼偣鍗曠粨鏋滅墿鍝�";
         }
         Map<Integer, List<LWhFormInventoryGoods>> inventoryGoodsMap = lWhFormInventoryGoods.stream()
                 .filter(goods -> goods.getInventoryResult() == 2 || goods.getInventoryResult() == 3)
                 .collect(Collectors.groupingBy(LWhFormInventoryGoods::getInventoryResult));
         if (CollectionUtils.isEmpty(lWhFormInventoryGoods)) {
-            rtnMap.put("status", true);
-            return rtnMap;
+//            rtnMap.put("status", true);
+            return null;
         }
-        LWhFormInventory lWhFormInventory = lWhFormInventoryService.get(new LWhFormInventory(whformInventoryId));
+
         Long warehouseId = lWhFormInventory.getWarehouseId();
         Long stopTime = lWhFormInventory.getStopTime();
+        Map<String, Object> inOutMap = new HashMap<>();
 
         for (Map.Entry<Integer, List<LWhFormInventoryGoods>> entry : inventoryGoodsMap.entrySet()) {
             //鐩樼偣缁撴灉锛�1=姝e父锛�2=鐩樼泩锛�3=鐩樹簭锛�
@@ -108,50 +118,61 @@
             if (inventoryResult == 2) {
                 // 鍒涘缓鍏ュ簱鍗曞苟鍏ュ簱
                 // 杩斿洖鍏ュ簱鍗曞彿
-                Long inFormByInventoryId = createInFormByInventoryId(warehouseId, stopTime, inventoryGoods, currentUser);
-                if (inFormByInventoryId == null) {
+                Map<String, Object> rkMap = createInFormByInventoryId(warehouseId, stopTime, inventoryGoods, currentUser);
+                if (rkMap == null) {
                     TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
 //                    throw new RuntimeException("鍒涘缓鍏ュ簱鍗曞け璐�");
                     log.error("鍒涘缓鍏ュ簱鍗曞け璐�");
-                    rtnMap.put("status", false);
-                    rtnMap.put("errMsg", "鍒涘缓鍏ュ簱鍗曞け璐�");
-                    return rtnMap;
+//                    rtnMap.put("status", false);
+//                    rtnMap.put("errMsg", "鍒涘缓鍏ュ簱鍗曞け璐�");
+                    return "鍒涘缓鍏ュ簱鍗曞け璐�";
                 }
-                String errMsg = lWhFormProcureCoreService.doProcure(warehouseId, currentUser);
+                Long inFormByInventoryId = (Long) inOutMap.get("inId");
+                inOutMap.putAll(rkMap);
+                String errMsg = lWhFormProcureCoreService.doProcure(inFormByInventoryId, currentUser);
                 if (errMsg != null) {
                     TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
 //                    throw new RuntimeException(errMsg);
                     log.error("鍒涘缓鍏ュ簱鍗曞け璐�");
-                    rtnMap.put("status", false);
-                    rtnMap.put("errMsg", "鍒涘缓鍏ュ簱鍗曞け璐�");
-                    return rtnMap;
+//                    rtnMap.put("status", false);
+//                    rtnMap.put("errMsg", "鍒涘缓鍏ュ簱鍗曞け璐�");
+                    return "鍒涘缓鍏ュ簱鍗曞け璐�";
                 }
             } else {
                 // 鍒涘缓鍑哄簱鍗曞苟鍑哄簱
-                Long lWhFormOutputId = this.createOutFormByInventoryId(warehouseId, stopTime, inventoryGoods, currentUser, sysInfo);
-                if (lWhFormOutputId == null) {
+                Map<String, Object> ckMap = createOutFormByInventoryId(warehouseId, stopTime, inventoryGoods, currentUser, sysInfo);
+                if (ckMap == null) {
                     TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
 //                    throw new RuntimeException("鍒涘缓鍑哄簱鍗曞け璐�");
                     log.error("鍒涘缓鍏ュ簱鍗曞け璐�");
-                    rtnMap.put("status", false);
-                    rtnMap.put("errMsg", "鍒涘缓鍏ュ簱鍗曞け璐�");
-                    return rtnMap;
+//                    rtnMap.put("status", false);
+//                    rtnMap.put("errMsg", "鍒涘缓鍏ュ簱鍗曞け璐�");
+                    return "鍒涘缓鍏ュ簱鍗曞け璐�";
                 }
+                inOutMap.putAll(ckMap);
+                Long lWhFormOutputId = (Long) inOutMap.get("outId");
                 //2.鏍规嵁鍑哄簱鍗曞嚭搴�
                 Long lWarehouseFlowId = lWhFormOutputCoreService.outFormByTransId(lWhFormOutputId, currentUser, stopTime);
                 if (lWarehouseFlowId == null) {
                     TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
 //                    throw new RuntimeException("鍒涘缓鍑哄簱鍗曞け璐�");
                     log.error("鍒涘缓鍏ュ簱鍗曞け璐�");
-                    rtnMap.put("status", false);
-                    rtnMap.put("errMsg", "鍒涘缓鍏ュ簱鍗曞け璐�");
-                    return rtnMap;
+//                    rtnMap.put("status", false);
+//                    rtnMap.put("errMsg", "鍒涘缓鍏ュ簱鍗曞け璐�");
+                    return "鍒涘缓鍏ュ簱鍗曞け璐�";
                 }
-
             }
         }
+        //
+        lWhFormInventory = new LWhFormInventory(whformInventoryId);
+        lWhFormInventory.setStates(2);
+        lWhFormInventory.setInWarehouseFormId((Long) inOutMap.get("inId"));
+        lWhFormInventory.setInBusinessFormCode((String) inOutMap.get("inCode"));
+        lWhFormInventory.setOutWarehouseFormId((Long) inOutMap.get("outId"));
+        lWhFormInventory.setOutBusinessFormCode((String) inOutMap.get("outCode"));
+        lWhFormInventoryService.update(lWhFormInventory);
 
-        return rtnMap;
+        return null;
     }
 
     /**
@@ -161,8 +182,8 @@
      * @param procureTime 閲囪喘鏃堕棿
      * @param currentUser
      */
-    private Long createInFormByInventoryId(Long warehouseId, Long procureTime, List<LWhFormInventoryGoods> inventoryGoodsList,
-                                           S_user_core currentUser) {
+    private Map<String, Object> createInFormByInventoryId(Long warehouseId, Long procureTime, List<LWhFormInventoryGoods> inventoryGoodsList,
+                                                          S_user_core currentUser) {
         if (CollectionUtils.isEmpty(inventoryGoodsList)) {
             return null;
         }
@@ -170,7 +191,8 @@
         BaseWarehouse baseWarehouse = baseWarehouseService.getById(warehouseId);
         LWhFormProcure lWhFormProcure = new LWhFormProcure();
         lWhFormProcure.setId(whFormProcureId);
-        lWhFormProcure.setBusinessFormCode(codeGeneratorService.createCodeByPrefix(CodeGeneratorEnum.Procure_Warehouse.getValue(), 10));
+        String inCode = codeGeneratorService.createCodeByPrefix(CodeGeneratorEnum.Procure_Warehouse.getValue(), 10);
+        lWhFormProcure.setBusinessFormCode(inCode);
         lWhFormProcure.setWarehouseId(warehouseId);
         lWhFormProcure.setWarehouseName(baseWarehouse.getWarehouseName());
         lWhFormProcure.setBuyerId(currentUser.getId());
@@ -182,7 +204,9 @@
         lWhFormProcure.setAgencyId(baseWarehouse.getAgencyId());
         lWhFormProcure.setAgencyName(baseWarehouse.getAgencyName());
         int result = lWhFormProcureService.insert(lWhFormProcure);
-        if (result == 0) return null;
+        if (result == 0) {
+            return null;
+        }
 
         ArrayList<LWhFormProcureGoods> procureGoodList = new ArrayList<>();
         ArrayList<LWhProcureModel> whProcureModeLlist = new ArrayList<>();
@@ -225,7 +249,11 @@
         }
         lWhFormProcureGoodsService.insertBatch(procureGoodList);
         lWhProcureModelService.insertBatch(whProcureModeLlist);
-        return whFormProcureId;
+
+        HashMap<String, Object> rtnMap = new HashMap<>();
+        rtnMap.put("inId", whFormProcureId);
+        rtnMap.put("inCode", inCode);
+        return rtnMap;
     }
 
     /**
@@ -235,8 +263,8 @@
      * @param procureTime 鍑哄簱鏃堕棿
      * @param currentUser
      */
-    private Long createOutFormByInventoryId(Long warehouseId, Long procureTime, List<LWhFormInventoryGoods> inventoryGoodsList,
-                                            S_user_core currentUser, FinSysTenantUser sysInfo) {
+    private Map<String, Object> createOutFormByInventoryId(Long warehouseId, Long procureTime, List<LWhFormInventoryGoods> inventoryGoodsList,
+                                                           S_user_core currentUser, FinSysTenantUser sysInfo) {
         if (CollectionUtils.isEmpty(inventoryGoodsList)) {
             return null;
         }
@@ -253,7 +281,8 @@
             return null;
         }
         lWhFormOutput.setWarehouseName(warehouse.getWarehouseName());
-        lWhFormOutput.setOutputCode(BaseWarehouseParam1.In_OutPutTypeEnum.Inventory_Output.getValue() + "");
+        String outCode = codeGeneratorService.createCodeByPrefix(CodeGeneratorEnum.OutPut_Warehouse.getValue(), 10);
+        lWhFormOutput.setOutputCode(outCode);
         lWhFormOutput.setOutputName("鐩樼偣鍑哄簱");
         lWhFormOutput.setAgencyId(Long.valueOf(sysInfo.getTenantId()));
         lWhFormOutput.setAgencyName(sysInfo.getTenantName());
@@ -283,9 +312,10 @@
             lWhProcureModel.setWorehouseCount(goodsNum);
             lWhProcureModelService.insert(lWhProcureModel);
         }
-
-
-        return lWhFormOutputId;
+        HashMap<String, Object> rtnMap = new HashMap<>();
+        rtnMap.put("outId", lWhFormOutputId);
+        rtnMap.put("outCode", outCode);
+        return rtnMap;
 
     }
 }

--
Gitblit v1.9.1