From 68c374208d9738d9bddb186f4cd675eb0c93694c Mon Sep 17 00:00:00 2001
From: YYC <1833023622@qq.com>
Date: 星期五, 14 七月 2023 23:10:14 +0800
Subject: [PATCH] 问题修改

---
 igds-inout/src/main/java/com/ld/igds/inout/manager/InoutManager.java |  306 ++++++++++++++++++++++++++++++++++----------------
 1 files changed, 205 insertions(+), 101 deletions(-)

diff --git a/igds-inout/src/main/java/com/ld/igds/inout/manager/InoutManager.java b/igds-inout/src/main/java/com/ld/igds/inout/manager/InoutManager.java
index 5ed72b9..c62bd2b 100644
--- a/igds-inout/src/main/java/com/ld/igds/inout/manager/InoutManager.java
+++ b/igds-inout/src/main/java/com/ld/igds/inout/manager/InoutManager.java
@@ -3,11 +3,11 @@
 import com.ld.igds.check.CheckStandardManager;
 import com.ld.igds.check.dto.CheckItemData;
 import com.ld.igds.check.dto.CheckUpdateResult;
-import com.ld.igds.common.CoreCommonService;
 import com.ld.igds.constant.RespCodeEnum;
 import com.ld.igds.data.Page;
 import com.ld.igds.data.PageResponse;
 import com.ld.igds.file.CoreFileService;
+import com.ld.igds.file.dto.FileData;
 import com.ld.igds.inout.InoutConstant;
 import com.ld.igds.inout.dto.InoutCheckData;
 import com.ld.igds.inout.dto.InoutCheckParam;
@@ -20,9 +20,7 @@
 import com.ld.igds.models.InoutSysConf;
 import com.ld.igds.util.ContextUtil;
 import com.ld.igds.util.DateUtil;
-
 import lombok.extern.slf4j.Slf4j;
-
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.time.DateFormatUtils;
 import org.apache.commons.lang3.time.DateUtils;
@@ -30,7 +28,6 @@
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
-
 import java.util.Arrays;
 import java.util.Date;
 import java.util.List;
@@ -49,13 +46,13 @@
     @Resource
     private CoreFileService fileService;
     @Resource
-    private CoreCommonService commonService;
-    @Resource
     private InoutCommonService inoutCommonService;
     @Resource
     private CheckStandardManager checkStandardManager;
     @Resource
-    private InoutDeviceManager inoutDeviceManager;
+    private InoutEventControlManager inoutEventControl;
+    @Resource
+    private CoreFileService coreFileService;
 
     /**
      * 鐩存帴浠庢暟鎹簱鏌ヨ锛屼笉鑰冭檻淇℃伅鐘舵��
@@ -199,9 +196,12 @@
      * @param data
      * @return
      */
-    private InoutData updateCheckItems(InoutData data) throws Exception {
+    private InoutData updateCheckItems(InoutData data, boolean toSave) throws Exception {
 
         if (null == data.getCheckItems()) return data;
+
+        //璁剧疆娌℃湁璐ㄦID锛屽彇娑堟墽琛屾寔涔呭寲
+        if (!toSave) data.setCheckId(null);
 
         // 鏇存柊妫�楠岄」鏁版嵁
         CheckUpdateResult checkUpdateResult = checkStandardManager.updateCheckItems(data.getCheckId(), data.getCompanyId(), data.getCheckItems());
@@ -216,6 +216,22 @@
         return data;
     }
 
+    private InoutData updateFiles(InoutData data) throws Exception {
+        List<FileData> files = data.getFiles();
+        if (null == files) {
+            return data;
+        }
+
+        for (FileData fileData : files) {
+            fileData.setFileId(ContextUtil.getUUID());
+            fileData.setCompanyId(data.getCompanyId());
+            fileData.setBizId(data.getId());
+            fileData.setCreateTime(new Date());
+            coreFileService.addRecord(fileData);
+        }
+
+        return data;
+    }
 
     /**
      * 浠庣紦瀛樹腑鑾峰彇涓嬩竴娴佺▼
@@ -293,46 +309,6 @@
         return data;
     }
 
-    public PageResponse<InoutData> submitComplete(InoutData data)
-            throws Exception {
-
-        if (StringUtils.isEmpty(data.getId())
-                || StringUtils.isEmpty(data.getType())
-                || StringUtils.isEmpty(data.getProgress())) {
-
-            return new PageResponse<>(RespCodeEnum.CODE_1007.getCode(),
-                    "娌℃湁鑾峰彇鍒拌溅杈嗕俊鎭��", data);
-        }
-
-        data.setUpdateTime(new Date());
-        if (null == data.getCompleteTime()) {
-            data.setCompleteTime(DateUtil.getNewByMinute(new Date(), 2));
-        }
-        if (null == data.getCompleteUser()) {
-            data.setCompleteUser(ContextUtil.getLoginUserCName());
-        }
-
-        // 璁剧疆娴佺▼鑺傜偣鐩存帴瀹屾垚
-        InoutParam param = new InoutParam();
-        param.setCompanyId(data.getCompanyId());
-        param.setId(data.getId());
-        param.setType(data.getType());
-        param.setDeptId(data.getDeptId());
-        param.setIntelCard(data.getIntelCard());
-        param.setUserId(data.getCompleteUser());
-        param.setDepotId(data.getDepotId());
-        param.setCompleteTime(data.getCompleteTime());
-        param.setProgress(InoutConstant.PROGRESS_RECORD);
-
-        String msg = inoutService.toComplete(param);
-
-        if (null != msg) {
-            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), msg);
-        }
-
-        return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), null, data);
-    }
-
     /**
      * 鍗″洖鏀堕�昏緫澶勭悊
      *
@@ -373,6 +349,52 @@
                 data);
     }
 
+
+    public PageResponse<InoutData> submitComplete(InoutData data)
+            throws Exception {
+
+        if (StringUtils.isEmpty(data.getId())
+                || StringUtils.isEmpty(data.getType())
+                || StringUtils.isEmpty(data.getProgress())) {
+
+            return new PageResponse<>(RespCodeEnum.CODE_1007.getCode(),
+                    "娌℃湁鑾峰彇鍒拌溅杈嗕俊鎭��", data);
+        }
+
+        data.setUpdateTime(new Date());
+        if (null == data.getCompleteTime()) {
+            data.setCompleteTime(DateUtil.getNewByMinute(new Date(), 2));
+        }
+        if (null == data.getCompleteUser()) {
+            data.setCompleteUser(ContextUtil.getLoginUserCName());
+        }
+
+        // 璁剧疆娴佺▼鑺傜偣鐩存帴瀹屾垚
+        InoutParam param = new InoutParam();
+        param.setCompanyId(data.getCompanyId());
+        param.setId(data.getId());
+        param.setType(data.getType());
+        param.setDeptId(data.getDeptId());
+        param.setIntelCard(data.getIntelCard());
+        param.setUserId(data.getCompleteUser());
+        param.setDepotId(data.getDepotId());
+        param.setCompleteTime(new Date());
+        param.setProgress(InoutConstant.PROGRESS_RECORD);
+
+        String msg = inoutService.toComplete(param);
+
+        if (null != msg) {
+            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), msg);
+        }
+        data.setCompleteTime(param.getCompleteTime());
+        data.setProgress(InoutConstant.PROGRESS_RECORD);
+        inoutService.updateInoutCache(data);
+        // 娴佺▼瀹屾垚鏀朵簨浠�
+        inoutEventControl.onInoutComplete(data);
+
+        return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), null, data);
+    }
+
     /**
      * 琛ュ崟鎿嶄綔 琛ュ崟鍥犱负瀹屾垚鏃堕棿涓嶇‘瀹氾紝鎵�浠ラ渶瑕佺郴缁熸牴鎹綋鍓嶆暟鎹繘琛岃嚜鍔ㄦ娴嬶紝璋冩暣鍘熸潵娴佹按淇℃伅鍜屽簱瀛�
      *
@@ -383,7 +405,7 @@
     public String addInoutData(InoutData data) throws Exception {
 
         if (data.getSettleWeight() <= 0.0) {
-            return "琛ュ崟鏁版嵁瑕佹眰缁撶畻閲嶉噺蹇呴』澶т簬0";
+            return "绯荤粺锛氳ˉ鍗曟暟鎹姹傜粨绠楅噸閲忓繀椤诲ぇ浜�0";
         }
 
         // 琛ュ崟鏁版嵁鐩存帴鍒扮粨鏋滅姸鎬�
@@ -415,40 +437,35 @@
             data.setCheckUser(loginUser);
         }
 
-        // 淇濆瓨妫�娴嬮」鐩�
-        if (InoutConstant.TYPE_IN.equals(data.getType())) {
 
+        if (InoutConstant.TYPE_IN.equals(data.getType())) {
             if (null == data.getFullWeightTime()) {
                 data.setFullWeightTime(DateUtil.getNewByMinute(new Date(), -50));
             }
             if (null == data.getEmptyWeightTime()) {
-                data.setEmptyWeightTime(DateUtil
-                        .getNewByMinute(new Date(), -10));
+                data.setEmptyWeightTime(DateUtil.getNewByMinute(new Date(), -10));
             }
 
-            // 鍏堟墽琛屽寲楠屼俊鎭繚瀛�
-            CheckUpdateResult checkResult = checkStandardManager
-                    .updateCheckItems(data.getCheckId(), data.getCompanyId(),
-                            data.getCheckItems());
-            if (null != checkResult) {
-                // if (null == data.getWet())data.setWet(checkResult.getWet());
-                // if (null ==
-                // data.getImpurity())data.setImpurity(checkResult.getImpurity());
-            }
+            data = this.updateCheckItems(data, false);
         } else {
             if (null == data.getEmptyWeightTime()) {
-                data.setEmptyWeightTime(DateUtil
-                        .getNewByMinute(new Date(), -50));
+                data.setEmptyWeightTime(DateUtil.getNewByMinute(new Date(), -50));
             }
             if (null == data.getFullWeightTime()) {
                 data.setFullWeightTime(DateUtil.getNewByMinute(new Date(), -10));
             }
         }
 
-        // 娣诲姞琛ュ崟鏁版嵁
-        String msg = inoutService.insertData(data);
 
-        return msg;
+        //鍏堜繚瀛樹富琛紝鍚庢墽琛屽瓙琛�
+        inoutService.insertData(data);
+
+        if (InoutConstant.TYPE_IN.equals(data.getType())) {
+            this.updateCheckItems(data, true);
+        }
+        this.updateFiles(data);
+
+        return null;
     }
 
     /**
@@ -472,9 +489,9 @@
 
         // 淇濆瓨妫�娴嬮」鐩�
         if (InoutConstant.TYPE_IN.equals(data.getType())) {
-            data = updateCheckItems(data);
+            data = updateCheckItems(data, true);
         }
-        
+
         return inoutService.updateData(data);
     }
 
@@ -559,8 +576,13 @@
         return msg;
     }
 
-    public void initLpr(InoutConf conf) {
-        inoutDeviceManager.initLpr(conf);
+    /**
+     * 鍑哄叆搴撶櫥璁板垵濮嬪寲
+     *
+     * @param conf 杞︾墝璇嗗埆閰嶇疆淇℃伅
+     */
+    public void initInoutRegister(InoutConf conf) {
+        inoutEventControl.initInoutRegister(conf);
     }
 
     /**
@@ -570,8 +592,7 @@
      * @return
      * @throws Exception
      */
-    public PageResponse<InoutData> submitRegisterInout(InoutData data)
-            throws Exception {
+    public PageResponse<InoutData> submitRegisterInout(InoutData data) throws Exception {
 
         // 棣栧厛鍒ゆ柇娴佺▼涓槸鍚︽湁宸茬粡瀛樺湪鐨勮溅杈嗕俊鎭湭鎵ц瀹屾垚锛岀洿鎺ヤ粠鏁版嵁搴撲腑鏌ヨ
         InoutParam param = new InoutParam();
@@ -605,20 +626,20 @@
         String msg = inoutService.insertData(data);
 
         if (null != msg) {
-            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), msg,
-                    data);
+            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), msg, data);
         }
 
         // 鎵ц闄勪欢淇℃伅
-        fileService.saveInoutFiles(data.getFiles(), data.getCompanyId(),
-                data.getId(), curProgress);
+        fileService.saveInoutFiles(data.getFiles(), data.getCompanyId(), data.getId(), curProgress);
+
+        //鐧昏瀹屾垚浜嬩欢
+        inoutEventControl.onInoutRegister(data);
 
         return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), "鎵ц鎴愬姛",
                 data);
     }
 
-    public PageResponse<InoutData> submitWeightIn(InoutData data)
-            throws Exception {
+    public PageResponse<InoutData> submitWeightIn(InoutData data) throws Exception {
         // 鑾峰彇绯荤粺鍙傛暟閰嶇疆
         InoutSysConf inoutSysConf = inoutCommonService.getCacheInoutSysConf(
                 data.getCompanyId(), data.getDeptId());
@@ -634,7 +655,7 @@
         data = updateBasicInfo(data, curProgress, nextProgress);
 
         // 鍏ュ簱绉伴噸鍙兘璋冩暣璐ㄦ鍗�
-        data = updateCheckItems(data);
+        data = updateCheckItems(data, true);
 
         // 鎵ц鏁版嵁鏇存柊
         String msg = inoutService.updateData(data);
@@ -645,14 +666,12 @@
         }
 
         // 鎵ц闄勪欢淇℃伅
-        fileService.saveInoutFiles(data.getFiles(), data.getCompanyId(),
-                data.getId(), curProgress);
+        fileService.saveInoutFiles(data.getFiles(), data.getCompanyId(), data.getId(), curProgress);
 
-        // 绉伴噸瀹屾垚锛岃皟鐢ㄥ嚭鍏ュ簱鎺у埗閫昏緫澶勭悊
-        inoutDeviceManager.controlWeight(data, curProgress, nextProgress);
+        // 绉伴噸瀹屾垚浜嬩欢
+        inoutEventControl.onInoutWeight(data, curProgress, nextProgress);
 
-        return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), "鎵ц鎴愬姛",
-                data);
+        return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), "鎵ц鎴愬姛", data);
     }
 
     public PageResponse<InoutData> submitWeightOut(InoutData data)
@@ -683,11 +702,11 @@
         fileService.saveInoutFiles(data.getFiles(), data.getCompanyId(),
                 data.getId(), curProgress);
 
-        // 绉伴噸鍚庢牴鎹綋鍓嶆祦绋嬬姸鎬佸拰涓嬩竴涓姸鎬侊紝閫氱煡绉伴噸鎺у埗鍣�
-        inoutDeviceManager.controlWeight(data, curProgress, nextProgress);
 
-        return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), "鎵ц鎴愬姛",
-                data);
+        // 绉伴噸瀹屾垚浜嬩欢
+        inoutEventControl.onInoutWeight(data, curProgress, nextProgress);
+
+        return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), "鎵ц鎴愬姛", data);
     }
 
     public PageResponse<InoutData> submitHandle(InoutData data)
@@ -698,8 +717,7 @@
         }
 
         // 鑾峰彇绯荤粺鍙傛暟閰嶇疆
-        InoutSysConf inoutSysConf = inoutCommonService.getCacheInoutSysConf(
-                data.getCompanyId(), data.getDeptId());
+        InoutSysConf inoutSysConf = inoutCommonService.getCacheInoutSysConf(data.getCompanyId(), data.getDeptId());
         if (null == inoutSysConf) {
             return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(),
                     "鎻愮ず锛氬綋鍓嶇郴缁熶腑娴佺▼閰嶇疆寮傚父锛岃鑱旂郴绠$悊鍛�", data);
@@ -707,24 +725,23 @@
 
         // 鑾峰彇涓嬩竴涓祦绋嬬姸鎬�
         String curProgress = data.getProgress();
-        String nextProgress = getNextProgress(curProgress, data.getType(),
-                inoutSysConf);
+        String nextProgress = getNextProgress(curProgress, data.getType(), inoutSysConf);
         data = updateBasicInfo(data, curProgress, nextProgress);
 
         // 鎵ц鏁版嵁鏇存柊
         String msg = inoutService.updateDataByHandle(data);
 
         if (null != msg) {
-            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), msg,
-                    data);
+            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), msg, data);
         }
 
         // 鎵ц闄勪欢淇℃伅
-        fileService.saveInoutFiles(data.getFiles(), data.getCompanyId(),
-                data.getId(), curProgress);
+        fileService.saveInoutFiles(data.getFiles(), data.getCompanyId(), data.getId(), curProgress);
 
-        return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), "鎵ц鎴愬姛",
-                data);
+        // 鍊间粨瀹屾垚瑙﹀彂浜嬩欢
+        inoutEventControl.onInoutHandle(data, curProgress, nextProgress);
+
+        return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), "鎵ц鎴愬姛", data);
     }
 
     /**
@@ -793,6 +810,9 @@
             return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), msg);
         }
 
+        // 鎵︽牱瀹屾垚瑙﹀彂浜嬩欢
+        inoutEventControl.onInSimple(data);
+
         return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), "鎵ц鎴愬姛");
     }
 
@@ -842,6 +862,7 @@
             data.setCheckTime(new Date());
         }
         curData.setCheckStatus(data.getCheckStatus());
+        curData.setFoodYear(data.getFoodYear());
 
 
         // 鑾峰彇涓嬩竴涓祦绋嬬姸鎬�
@@ -856,6 +877,13 @@
 
         curData.setProgress(curData.getProgress());
         curData.setType(curData.getType());
+        curData.setFoodLevel(data.getFoodLevel());
+        curData.setFoodVariety(data.getFoodVariety());
+        curData.setPrice(data.getPrice());
+        curData.setRemarks(data.getRemarks());
+        curData.setCheckItems(data.getCheckItems());
+        curData.setCheckTime(data.getCheckTime());
+        curData.setDepotId(data.getDepotId());
 
         if (StringUtils.isEmpty(data.getCheckUser())) {
             curData.setCheckUser(ContextUtil.getLoginUserCName());
@@ -870,7 +898,52 @@
             return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), msg);
         }
 
+
+        // 璐ㄦ瀹屾垚瑙﹀彂浜嬩欢
+        inoutEventControl.onInCheck(data, curProgress, nextProgress);
+
         return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), "鎵ц鎴愬姛");
+    }
+
+    public PageResponse<InoutCheckData> submitCheckData(InoutCheckData data) throws Exception {
+
+
+        // 鑾峰彇涓氬姟鏁版嵁淇℃伅
+        InoutParam param = new InoutParam();
+        param.setCompanyId(data.getCompanyId());
+        param.setId(data.getId());
+        InoutData curData = inoutService.inoutProgressQuery(param);
+
+        if (null == curData) {
+            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(),
+                    "娌℃湁鑾峰彇鍒板叆搴撲笟鍔℃暟鎹俊鎭紝鏇存柊澶辫触", data);
+        }
+
+        if (InoutConstant.PROGRESS_RECORD.equals(curData.getProgress())) {
+            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(),
+                    "褰撳墠娴佺▼宸茬粡缁撴潫锛屼笉鏀寔淇敼");
+        }
+
+        // 鏇存柊鍖栭獙椤逛俊鎭�
+        CheckUpdateResult checkResult = checkStandardManager.updateCheckItems(data.getCheckId(), data.getCompanyId(), data.getCheckItems());
+        if (StringUtils.isNotEmpty(checkResult.getMsg())) {
+            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(),
+                    "鍚庡彴鎵ц寮傚父锛�" + checkResult.getMsg(), data);
+        }
+
+        curData.setType(curData.getType());
+        curData.setFoodLevel(data.getFoodLevel());
+        curData.setFoodVariety(data.getFoodVariety());
+        curData.setPrice(data.getPrice());
+        curData.setDepotId(data.getDepotId());
+        curData.setCheckItems(data.getCheckItems());
+
+        String msg = inoutService.updateCheckData(curData);
+        if (null != msg) {
+            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), msg);
+        }
+
+        return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), "淇濆瓨鎴愬姛");
     }
 
     /**
@@ -911,7 +984,7 @@
 
         try {
             List<CheckItemData> result = checkStandardManager.listCheckItem(
-                    param.getCheckId(), param.getCompanyId(),
+                    param.getCompanyId(), param.getCheckId(),
                     param.getFoodVariety());
 
             return new PageResponse<>(RespCodeEnum.CODE_0000, result);
@@ -944,4 +1017,35 @@
         }
     }
 
+    /**
+     * @param param
+     * @return
+     */
+    public PageResponse<InoutCheckData> inoutDataByCheckId(InoutCheckParam param) {
+        if (StringUtils.isEmpty(param.getCheckId())) {
+            return new PageResponse<>(RespCodeEnum.CODE_1007.getCode(),
+                    "鏌ヨ鍙傛暟涓嶅畬鏁达紝鏌ヨ澶辫触锛�");
+        }
+
+        InoutCheckData result;
+        try {
+            param.setProgress(InoutConstant.PROGRESS_CHECK);
+            result = inoutService.inoutDataByCheckId(param);
+            if (null == result) {
+                return new PageResponse<>(RespCodeEnum.CODE_2000.getCode(),
+                        "绯荤粺鏈煡璇㈠埌鎵ц涓殑杞﹁締淇℃伅", null);
+            }
+
+            return new PageResponse<>(RespCodeEnum.CODE_0000, result);
+
+        } catch (Exception e) {
+            return new PageResponse<>(RespCodeEnum.CODE_2000.getCode(),
+                    e.getMessage());
+        }
+    }
+
+    public void initInoutWeight(List<InoutConf> listInoutConf, String sort) {
+        inoutEventControl.initInoutWeight(listInoutConf, sort);
+    }
+
 }
\ No newline at end of file

--
Gitblit v1.9.3