From 785ce007ce4b7b2119a99aacc95cefe9da09e32e Mon Sep 17 00:00:00 2001
From: jiazx0107@163.com <jiazx0107@163.com>
Date: 星期二, 04 七月 2023 16:49:09 +0800
Subject: [PATCH] 优化出入库逻辑,调整节点事件

---
 igds-inout/src/main/java/com/ld/igds/inout/manager/InoutManager.java |  169 +++++++++++++++++++++++++++++++------------------------
 1 files changed, 95 insertions(+), 74 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 db7a478..bed9209 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,7 +3,6 @@
 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;
@@ -20,9 +19,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 +27,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 +45,11 @@
     @Resource
     private CoreFileService fileService;
     @Resource
-    private CoreCommonService commonService;
-    @Resource
     private InoutCommonService inoutCommonService;
     @Resource
     private CheckStandardManager checkStandardManager;
     @Resource
-    private InoutDeviceManager inoutDeviceManager;
+    private InoutEventControlManager inoutEventControl;
 
     /**
      * 鐩存帴浠庢暟鎹簱鏌ヨ锛屼笉鑰冭檻淇℃伅鐘舵��
@@ -199,9 +193,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());
@@ -293,46 +290,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(new Date());
-        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);
-    }
-
     /**
      * 鍗″洖鏀堕�昏緫澶勭悊
      *
@@ -371,6 +328,51 @@
 
         return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), "鎵ц鎴愬姛",
                 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);
+        }
+
+
+        // 娴佺▼瀹屾垚鏀朵簨浠�
+        inoutEventControl.onInoutComplete(data);
+
+        return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), null, data);
     }
 
     /**
@@ -424,7 +426,7 @@
                 data.setEmptyWeightTime(DateUtil.getNewByMinute(new Date(), -10));
             }
 
-            data = this.updateCheckItems(data);
+            data = this.updateCheckItems(data, false);
         } else {
             if (null == data.getEmptyWeightTime()) {
                 data.setEmptyWeightTime(DateUtil.getNewByMinute(new Date(), -50));
@@ -434,8 +436,15 @@
             }
         }
 
-        // 娣诲姞琛ュ崟鏁版嵁
-        return inoutService.insertData(data);
+
+        //鍏堜繚瀛樹富琛紝鍚庢墽琛屽瓙琛�
+        inoutService.insertData(data);
+
+        if (InoutConstant.TYPE_IN.equals(data.getType())) {
+            this.updateCheckItems(data, true);
+        }
+
+        return null;
     }
 
     /**
@@ -459,7 +468,7 @@
 
         // 淇濆瓨妫�娴嬮」鐩�
         if (InoutConstant.TYPE_IN.equals(data.getType())) {
-            data = updateCheckItems(data);
+            data = updateCheckItems(data, true);
         }
 
         return inoutService.updateData(data);
@@ -546,8 +555,13 @@
         return msg;
     }
 
-    public void initLpr(InoutConf conf) {
-        inoutDeviceManager.initLpr(conf);
+    /**
+     * 鍑哄叆搴撶櫥璁板垵濮嬪寲
+     *
+     * @param conf 杞︾墝璇嗗埆閰嶇疆淇℃伅
+     */
+    public void initInoutRegister(InoutConf conf) {
+        inoutEventControl.initInoutRegister(conf);
     }
 
     /**
@@ -557,8 +571,7 @@
      * @return
      * @throws Exception
      */
-    public PageResponse<InoutData> submitRegisterInout(InoutData data)
-            throws Exception {
+    public PageResponse<InoutData> submitRegisterInout(InoutData data) throws Exception {
 
         // 棣栧厛鍒ゆ柇娴佺▼涓槸鍚︽湁宸茬粡瀛樺湪鐨勮溅杈嗕俊鎭湭鎵ц瀹屾垚锛岀洿鎺ヤ粠鏁版嵁搴撲腑鏌ヨ
         InoutParam param = new InoutParam();
@@ -592,20 +605,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());
@@ -621,7 +634,7 @@
         data = updateBasicInfo(data, curProgress, nextProgress);
 
         // 鍏ュ簱绉伴噸鍙兘璋冩暣璐ㄦ鍗�
-        data = updateCheckItems(data);
+        data = updateCheckItems(data, true);
 
         // 鎵ц鏁版嵁鏇存柊
         String msg = inoutService.updateData(data);
@@ -632,14 +645,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)
@@ -670,11 +681,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)
@@ -705,6 +716,9 @@
 
         // 鎵ц闄勪欢淇℃伅
         fileService.saveInoutFiles(data.getFiles(), data.getCompanyId(), data.getId(), curProgress);
+
+        // 鍊间粨瀹屾垚瑙﹀彂浜嬩欢
+        inoutEventControl.onInoutHandle(data, curProgress, nextProgress);
 
         return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), "鎵ц鎴愬姛", data);
     }
@@ -774,6 +788,9 @@
         if (null != msg) {
             return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), msg);
         }
+
+        // 鎵︽牱瀹屾垚瑙﹀彂浜嬩欢
+        inoutEventControl.onInSimple(data);
 
         return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), "鎵ц鎴愬姛");
     }
@@ -857,6 +874,10 @@
             return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), msg);
         }
 
+
+        // 璐ㄦ瀹屾垚瑙﹀彂浜嬩欢
+        inoutEventControl.onInCheck(data,curProgress,nextProgress);
+
         return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), "鎵ц鎴愬姛");
     }
 
@@ -898,7 +919,7 @@
 
         try {
             List<CheckItemData> result = checkStandardManager.listCheckItem(
-                    param.getCheckId(), param.getCompanyId(),
+                    param.getCompanyId(), param.getCheckId(),
                     param.getFoodVariety());
 
             return new PageResponse<>(RespCodeEnum.CODE_0000, result);

--
Gitblit v1.9.3