From 62b1f39e60f64ec4e05b21d11af3e36f5891a91a Mon Sep 17 00:00:00 2001
From: zc <zc@123>
Date: 星期二, 29 四月 2025 20:10:27 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java |  208 +++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 165 insertions(+), 43 deletions(-)

diff --git a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
index 892adf2..3ac2728 100644
--- a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -1,8 +1,10 @@
 package com.zy.asrs.service.impl;
 
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.core.common.Cools;
 import com.zy.asrs.domain.enums.NotifyMsgType;
 import com.zy.asrs.entity.*;
 import com.zy.asrs.service.*;
@@ -20,14 +22,8 @@
 import com.zy.core.cache.SlaveConnection;
 import com.zy.core.dispatcher.ShuttleDispatchUtils;
 import com.zy.core.enums.*;
-import com.zy.core.model.DevpSlave;
-import com.zy.core.model.LiftSlave;
-import com.zy.core.model.ShuttleSlave;
-import com.zy.core.model.Task;
-import com.zy.core.model.command.LiftAssignCommand;
-import com.zy.core.model.command.LiftCommand;
-import com.zy.core.model.command.ShuttleAssignCommand;
-import com.zy.core.model.command.ShuttleCommand;
+import com.zy.core.model.*;
+import com.zy.core.model.command.*;
 import com.zy.core.model.protocol.ForkLiftStaProtocol;
 import com.zy.core.model.protocol.LiftProtocol;
 import com.zy.core.model.protocol.ShuttleProtocol;
@@ -38,12 +34,15 @@
 import com.zy.core.thread.LiftThread;
 import com.zy.core.thread.ShuttleThread;
 import com.zy.core.thread.impl.FyDevpThread;
+import com.zy.core.thread.impl.NormalLedThread;
 import com.zy.system.service.ConfigService;
+import io.swagger.models.auth.In;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
+import java.io.IOException;
 import java.util.*;
 
 /**
@@ -183,32 +182,33 @@
                     LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed());
                     String errMsg = "";
                     if (!back && staProtocol.isBackErr()) {
-                        errMsg = "瓒呭寮傚父";
+                        errMsg = "鍚庤秴闄�";
                         back = true;
                     }
                     if (!back && staProtocol.isHighErr()) {
                         errMsg = "瓒呴珮寮傚父";
                         back = true;
                     }
-                    if (!back && staProtocol.isRightErr()) {
-                        errMsg = "瓒呴暱寮傚父";
+                    if (!back && staProtocol.isWeightErr()) {
+                        errMsg = "瓒呴噸寮傚父";
                         back = true;
                     }
-                    if (!back && staProtocol.isWeightErr()) {
-                        errMsg = "瓒呴噸";
+                    if (!back && staProtocol.isRightErr()) {
+                        errMsg = "鍙宠秴闄�";
+                        back = true;
+                    }
+                    if (!back && staProtocol.isLeftErr()) {
+                        errMsg = "宸﹁秴闄�";
+                        back = true;
+                    }
+                    if (!back && staProtocol.isBarcodeErr()) {
+                        errMsg = "鎵爜寮傚父";
                         back = true;
                     }
                     // 閫�鍥�
                     if (back) {
-                        if (!staProtocol.isLoading()) {
-                            continue;
-                        }
-                        if (!staProtocol.isPakMk()) {
-                            continue;
-                        }
                         // led 寮傚父鏄剧ず
                         if (ledThread != null) {
-                            MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errMsg));
                             ledThread.error(errMsg);
                         }
                     }
@@ -216,6 +216,9 @@
                     // 鍒ゆ柇鏄惁婊¤冻鍏ュ簱鏉′欢
                     if (staProtocol.isAutoing() && staProtocol.isLoading() && isInEnable(devpThread, inSta.getStaNo()) && !staProtocol.isEmptyMk() && (workNo == 0 || (workNo >= 9990 && workNo <= 9999)) && staProtocol.isPakMk()) {
                         String barcode = staProtocol.getBarcode();
+                        if (Cools.isEmpty(barcode) || "?".endsWith(barcode) || "NG".endsWith(barcode) || "NoRead".equals(barcode) || "00000000".equals(barcode)) {
+                            continue;
+                        }
                         // 鍒ゆ柇閲嶅宸ヤ綔妗�
                         WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("source_sta_no", inSta.getStaNo()).eq("barcode", barcode));
                         if (wrkMast != null && wrkMast.getWrkSts() == WrkStsType.NEW_INBOUND.sts) {
@@ -303,6 +306,42 @@
                     } else {
                         staProtocol = staProtocol.clone();
                     }
+                    LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed());
+                    String errMsg = "";
+                    boolean back = false;
+                    if (!back && staProtocol.isBackErr()) {
+                        errMsg = "鍚庤秴闄�";
+                        back = true;
+                    }
+                    if (!back && staProtocol.isHighErr()) {
+                        errMsg = "瓒呴珮寮傚父";
+                        back = true;
+                    }
+                    if (!back && staProtocol.isWeightErr()) {
+                        errMsg = "瓒呴噸寮傚父";
+                        back = true;
+                    }
+                    if (!back && staProtocol.isRightErr()) {
+                        errMsg = "鍙宠秴闄�";
+                        back = true;
+                    }
+                    if (!back && staProtocol.isLeftErr()) {
+                        errMsg = "宸﹁秴闄�";
+                        back = true;
+                    }
+                    if (!back && staProtocol.isBarcodeErr()) {
+                        errMsg = "鎵爜寮傚父";
+                        back = true;
+                    }
+                    // 閫�鍥�
+                    if (back) {
+
+                        // led 寮傚父鏄剧ず
+                        if (ledThread != null) {
+                            ledThread.error(errMsg);
+                        }
+                    }
+
                     Short workNo = staProtocol.getWorkNo();
                     if (staProtocol.isAutoing() && staProtocol.isLoading() && isInEnable(devpThread, inSta.getStaNo()) && !staProtocol.isEmptyMk() && (workNo == 0 || (workNo >= 9990 && workNo <= 9999)) && staProtocol.isPakMk()) {
                         String barcode = staProtocol.getBarcode();
@@ -382,6 +421,29 @@
                 if (wrkMast.getStaNo() == 1026) {
                     locNo = "1200305";
                 }
+                //鑾峰彇鎻愬崌鏈轰俊鎭�
+                LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, 1);
+                if (liftThread == null) {
+                    continue;
+                }
+
+                LiftProtocol liftProtocol = liftThread.getStatus();
+                if (liftProtocol == null) {
+                    continue;
+                }
+
+                if (!liftThread.isIdle()) {
+                    continue;
+                }
+
+
+                //鍒ゆ柇鎻愬崌鏈哄唴鏄惁鏈夋墭鐩�
+                if (liftProtocol.getHasTray()) {
+                    News.info("{}浠诲姟锛寋}鍙锋彁鍗囨満锛屾彁鍗囨満鍐呮棤鎵樼洏锛岀姝㈡淳鍙�", wrkMast.getWrkNo(), liftProtocol.getLiftNo());
+                    continue;
+                }
+
+
                 boolean dispatchShuttle = shuttleDispatchUtils.searchDispatchShuttleNoLift(wrkMast.getWrkNo(), locNo, wrkMast.getLocNo(), "TRANSPORT_DEVP");
                 if (!dispatchShuttle) {
                     News.info("{}浠诲姟锛岃皟搴﹀皬杞﹀け璐�", wrkMast.getWrkNo());
@@ -395,6 +457,8 @@
                 wrkMast.setModiTime(new Date());
                 if (!wrkMastService.updateById(wrkMast)) {
                     News.info("{}浠诲姟锛屾洿鏂板伐浣滄。澶辫触", wrkMast.getWrkNo());
+                } else {
+                    setLedData(Integer.parseInt(wrkMast.getWmsWrkNo()), wrkMast.getStaNo());
                 }
             }
         }
@@ -429,15 +493,19 @@
             if (wrkMast.getStaNo() == 1024) {
                 locNo = "1200305";
             }
+
             boolean dispatchShuttle = shuttleDispatchUtils.searchDispatchShuttleNoLift(wrkMast.getWrkNo(), wrkMast.getSourceLocNo(), locNo, "TRANSPORT_DEVP");
             if (!dispatchShuttle) {
                 News.info("{}浠诲姟锛岃皟搴﹀皬杞﹀け璐�", wrkMast.getWrkNo());
                 continue;
             }
-
+            WrkMast wrkMast2 = wrkMastService.selectByMainWrkNo(wrkMast.getWrkNo());
             wrkMast.setWrkSts(WrkStsType.OUTBOUND_SHUTTLE_RUN.sts);
             wrkMast.setSystemMsg("");//娓呯┖娑堟伅
             wrkMast.setModiTime(now);
+            if (wrkMast2 != null) {
+                wrkMast.setShuttleNo(wrkMast2.getShuttleNo());
+            }
             if (!wrkMastService.updateById(wrkMast)) {
                 News.info("{}浠诲姟锛屾洿鏂板伐浣滄。澶辫触", wrkMast.getWrkNo());
             } else {
@@ -510,12 +578,39 @@
                         wrkMast.setModiTime(new Date());
                         wrkMast.setShuttleNo(null);
                         wrkMastService.updateById(wrkMast);
+                        setLedData(Integer.parseInt(wrkMast.getWmsWrkNo()), wrkMast.getStaNo());
                     }
                 }
             }
         }
     }
 
+
+    private void setLedData(Integer wrkNo, Integer staNo) {
+        try {
+            Map<String, Object> param = new HashMap<>();
+            param.put("taskNo", wrkNo);
+            String response = null;
+            response = new HttpHandler.Builder()
+                    .setUri(wmsUrl)
+                    .setPath("/rpc/led/getTask2")
+                    .setJson(JSON.toJSONString(param))
+                    .build()
+                    .doPost();
+            JSONObject jsonObject = JSON.parseObject(response);
+            Integer code = jsonObject.getInteger("code");
+            if (code.equals(200)) {
+                String data = jsonObject.getString("data");
+                List<LedCommand> wrkDetls = JSONArray.parseArray(data, LedCommand.class);
+                redisUtil.set("LED_" + staNo, wrkDetls, 30);
+                log.info("鐢佃鏈烘暟鎹缃細{},{}", staNo, data);
+            } else {
+                log.info("鐢佃鏈烘暟鎹缃紓甯革細{},{}", wrkNo, response);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
 
     /**
      * 鍒濆鍖栧疄鏃跺湴鍥�
@@ -851,17 +946,17 @@
             for (WrkMast wrkMast : wrkMasts) {
                 boolean step0 = this.liftInExecuteStep0(wrkMast);//璁惧涓婅蛋
                 if (!step0) {
-                    return;
+                    continue;
                 }
 
                 boolean step1 = this.liftInExecuteStep1(wrkMast);//鎻愬崌鏈烘惉杩�
                 if (!step1) {
-                    return;
+                    continue;
                 }
 
                 boolean step2 = this.liftInExecuteStep2(wrkMast);//瑙﹀彂鎼繍浠诲姟
                 if (!step2) {
-                    return;
+                    continue;
                 }
             }
         } catch (Exception e) {
@@ -892,19 +987,27 @@
             LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, led);
             String errMsg = "";
             if (!back && staProtocol.isBackErr()) {
-                errMsg = "瓒呭寮傚父";
+                errMsg = "鍚庤秴闄�";
                 back = true;
             }
             if (!back && staProtocol.isHighErr()) {
                 errMsg = "瓒呴珮寮傚父";
                 back = true;
             }
-            if (!back && staProtocol.isRightErr()) {
-                errMsg = "瓒呴暱寮傚父";
+            if (!back && staProtocol.isWeightErr()) {
+                errMsg = "瓒呴噸寮傚父";
                 back = true;
             }
-            if (!back && staProtocol.isWeightErr()) {
-                errMsg = "瓒呴噸";
+            if (!back && staProtocol.isRightErr()) {
+                errMsg = "鍙宠秴闄�";
+                back = true;
+            }
+            if (!back && staProtocol.isLeftErr()) {
+                errMsg = "宸﹁秴闄�";
+                back = true;
+            }
+            if (!back && staProtocol.isBarcodeErr()) {
+                errMsg = "鎵爜寮傚父";
                 back = true;
             }
             // 閫�鍥�
@@ -915,16 +1018,21 @@
                     ledThread.error(errMsg);
                 }
             }
-            if (!staProtocol.isAutoing()) {
-                News.info("{}浠诲姟锛寋}绔欑偣锛屼笉鍦ㄨ嚜鍔ㄧ姸鎬�", wrkMast.getWrkNo(), staProtocol.getSiteId());
-                return false;
-            }
+            String barcode = staProtocol.getBarcode();
+
 
             if (!staProtocol.isLoading()) {
                 News.info("{}浠诲姟锛寋}绔欑偣锛屾棤鎵樼洏", wrkMast.getWrkNo(), staProtocol.getSiteId());
                 return false;
             }
             if (wrkMast.getSourceStaNo() != 1031) {
+                if (!staProtocol.isAutoing()) {
+                    News.info("{}浠诲姟锛寋}绔欑偣锛屼笉鍦ㄨ嚜鍔ㄧ姸鎬�", wrkMast.getWrkNo(), staProtocol.getSiteId());
+                    return false;
+                }
+                if (Cools.isEmpty(barcode) || "?".endsWith(barcode) || "NG".endsWith(barcode) || "NoRead".equals(barcode) || "00000000".equals(barcode)) {
+                    return false;
+                }
                 if (!staProtocol.getBarcode().equals(wrkMast.getBarcode())) {
                     News.info("{}浠诲姟锛寋}绔欑偣锛屾墭鐩樼爜涓嶅尮閰嶏紝绔欑偣鎵樼洏鐮侊細{}锛屼换鍔℃墭鐩樼爜锛歿}", wrkMast.getWrkNo(), staProtocol.getSiteId(), staProtocol.getBarcode(), wrkMast.getBarcode());
                     return false;
@@ -956,6 +1064,7 @@
             wrkMast.setSystemMsg("");//娓呯┖娑堟伅
             wrkMast.setModiTime(now);
             if (wrkMastService.updateById(wrkMast)) {
+                setLedData(Integer.parseInt(wrkMast.getWmsWrkNo()), wrkMast.getStaNo());
                 return false;
             }
             return false;
@@ -1035,7 +1144,7 @@
                     return false;
                 }
             } else if (sourceStaNo == 1012) {
-                if (staProtocol.getWorkNo().intValue() != wrkMast.getWrkNo()) {
+                if (staProtocol.getFinishWorkNo().intValue() != wrkMast.getWrkNo()) {
                     News.info("{}浠诲姟锛寋}绔欑偣锛屼换鍔″彿涓嶄竴鑷�", wrkMast.getWrkNo(), staProtocol.getSiteId());
                     return false;
                 }
@@ -1052,7 +1161,7 @@
             } else if (wrkMast.getSourceStaNo() == 1032) {
                 locNo = "0200308";
             }
-            boolean dispatchShuttle = shuttleDispatchUtils.searchDispatchShuttleS(wrkMast.getWrkNo(), locNo, wrkMast.getLocNo(), "TRANSPORT_LIFT");
+            boolean dispatchShuttle = shuttleDispatchUtils.searchDispatchShuttleNoLift(wrkMast.getWrkNo(), locNo, wrkMast.getLocNo(), "TRANSPORT_LIFT");
             if (!dispatchShuttle) {
                 News.info("{}浠诲姟锛岃皟搴﹀皬杞﹀け璐�", wrkMast.getWrkNo());
                 return false;
@@ -1155,12 +1264,12 @@
             for (WrkMast wrkMast : wrkMasts) {
                 boolean step1 = this.liftOutExecuteStep1(wrkMast);//瑙﹀彂鎼繍浠诲姟
                 if (!step1) {
-                    return;
+                    continue;
                 }
 
                 boolean step2 = this.liftOutExecuteStep2(wrkMast);//鎻愬崌鏈烘惉杩�
                 if (!step2) {
-                    return;
+                    continue;
                 }
             }
         } catch (Exception e) {
@@ -1281,12 +1390,12 @@
             //鑾峰彇鎻愬崌鏈哄懡浠�
             List<LiftCommand> liftCommands = liftThread.getPalletOutCommand(wrkMast.getWrkNo(), sourceLev, wrkMast.getStaNo());
             LiftCommand liftCommand = liftCommands.get(0);
-            if (wrkMast.getStaNo() == 1031) {
-                liftCommand.setTaskNo(wrkMast.getWrkNo());
-            } else {
-                int deviceWrk = commonService.getWorkNo(8);//鐢熸垚鎻愬崌鏈鸿澶囧伐浣滃彿
-                liftCommand.setTaskNo(deviceWrk);//鏇存崲闅忔満浠诲姟鍙�
-            }
+//            if (wrkMast.getMainWrkNo() != null) {
+            liftCommand.setTaskNo(wrkMast.getWrkNo());
+//            } else {
+//                int deviceWrk = commonService.getWorkNo(8);//鐢熸垚鎻愬崌鏈鸿澶囧伐浣滃彿
+//                liftCommand.setTaskNo(deviceWrk);//鏇存崲闅忔満浠诲姟鍙�
+//            }
 
             ArrayList<LiftCommand> commands = new ArrayList<>();
             commands.add(liftCommand);
@@ -1304,6 +1413,7 @@
             wrkMast.setModiTime(now);
 
             if (wrkMastService.updateById(wrkMast)) {
+                setLedData(Integer.parseInt(wrkMast.getWmsWrkNo()), wrkMast.getStaNo());
                 //涓嬪彂浠诲姟
                 liftAction.assignWork(wrkMast.getLiftNo(), assignCommand);
                 return false;
@@ -1740,6 +1850,14 @@
         try {
             this.recShuttleErr();
             this.recLiftErr();
+            LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, 1);
+            ledThread.errorReset();
+            ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, 2);
+            ledThread.errorReset();
+            ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, 3);
+            ledThread.errorReset();
+            ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, 4);
+            ledThread.errorReset();
         } catch (Exception e) {
             News.error("recErr fail", e);
         }
@@ -2263,6 +2381,10 @@
      * 鍏ュ嚭搴撴ā寮忓垏鎹㈠嚱鏁�
      */
     public synchronized void ioConvert() {
+        for (LedSlave led : slaveProperties.getLed()) {
+            NormalLedThread ledThread = (NormalLedThread) SlaveConnection.get(SlaveType.Led, led.getId());
+            ledThread.reset();
+        }
         try {
             // 鏍规嵁杈撻�佺嚎plc閬嶅巻
             FyDevpThread devpThread = (FyDevpThread) SlaveConnection.get(SlaveType.Devp, 1);

--
Gitblit v1.9.1