From 97c788f31a57b4e8c3fc8091dc29aab598adeebb Mon Sep 17 00:00:00 2001
From: dubin <bindu_bean@163.com>
Date: 星期日, 04 一月 2026 08:07:00 +0800
Subject: [PATCH] #1

---
 src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java |  398 +++++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 274 insertions(+), 124 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 e9dd9ac..13af51d 100644
--- a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -36,6 +36,7 @@
 import com.zy.core.thread.LedThread;
 import com.zy.core.thread.SiemensDevpThread;
 import com.zy.system.service.ConfigService;
+import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -43,6 +44,7 @@
 import org.springframework.transaction.interceptor.TransactionAspectSupport;
 
 import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * 绔嬩綋浠撳簱WCS绯荤粺涓绘祦绋嬩笟鍔�
@@ -122,6 +124,11 @@
                     continue;
                 }
 
+                String barcode = barcodeThread.getBarcode();
+                if (Cools.isEmpty(barcode)){
+                    continue;
+                }
+
                 if (staProtocol.isAutoing()
                         && staProtocol.isInEnable()
                         && !staProtocol.isEmptyMk()
@@ -129,10 +136,10 @@
                         && staProtocol.isPakMk()) {
                     News.warnNoLog("" + mark + " - 0" + " - 寮�濮嬫墽琛�");
 
-                    String barcode = barcodeThread.getBarcode();
+
                     if (!Cools.isEmpty(barcode)) {
                         News.info("" + mark + " - 1" + " - {}鍙锋潯鐮佹壂鎻忓櫒妫�娴嬫潯鐮佷俊鎭細{}", inSta.getBarcode(), barcode);
-                        if ("NG".endsWith(barcode) || "NoRead".equals(barcode) || "empty".equals(barcode)) {
+                        if ("NG".endsWith(barcode) || "No Read".equals(barcode) || "empty".equals(barcode)) {
                             News.info("" + mark + " - 2" + " - 鎵爜澶辫触1 ===>> {}鍙锋潯鐮佹壂鎻忓櫒妫�娴嬫潯鐮佷俊鎭細{},绔欑偣:{}", inSta.getBarcode(), barcode, inSta.getStaNo());
                             // led 寮傚父鏄剧ず
                             if (ledThread != null) {
@@ -156,12 +163,12 @@
                     //杩囨护鍒ゆ柇锛岄槻姝㈡嫞鏂欏啀鍏ュ簱璐х墿锛岀粡杩囧叆搴撶珯鍐嶅叆搴撴椂锛岃閫�鍥炲埌閫�搴撶珯
                     WrkMast wrkMast1 = wrkMastMapper.selectPakInStepBarcode(barcode);
                     if (wrkMast1 != null) {
-                        if (wrkMast1.getIoType() == 103 || wrkMast1.getIoType() == 107 || wrkMast1.getIoType() == 104) {
+                        if (wrkMast1.getIoType() == 103 || wrkMast1.getIoType() == 107 || wrkMast1.getIoType() == 104|| wrkMast1.getIoType() == 53 || wrkMast1.getIoType() == 57 || wrkMast1.getIoType() == 54) {
                             continue;
                         }
                     }
                     if (wrkMast != null) {
-                        News.error("" + mark + " - 4" + " - 宸ヤ綔妗d腑宸插瓨鍦ㄨ绔欑姸鎬佷负锛� 2.璁惧涓婅蛋 锛夌殑鏁版嵁,宸ヤ綔鍙�={}", wrkMast.getWrkNo());
+                        News.error("" + mark + " - 4" + " - 宸ヤ綔妗d腑宸插瓨鍦ㄨ绔欑姸鎬佷负锛� 3.寮�濮嬫墽琛屽叆搴撲换鍔� 锛夌殑鏁版嵁,宸ヤ綔鍙�={}", wrkMast.getWrkNo());
 
                         // led 寮傚父鏄剧ず
                         if (ledThread != null) {
@@ -220,6 +227,9 @@
 
                             barcodeThread.setBarcode("");
                             boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, command));
+                            if (result) {
+                                News.info("WCS--->PLC涓嬪彂浠诲姟鎴愬姛:{}",command.toString());
+                            }
                             if (!result) {
                                 throw new CoolException("鏇存柊plc绔欑偣淇℃伅澶辫触");
                             }
@@ -227,6 +237,7 @@
                             currentWrkMast.setWrkSts(3L);// 3.璁惧鎵ц涓�
                             currentWrkMast.setCrnStrTime(new Date());
                             wrkMastService.updateById(currentWrkMast);
+                            Thread.sleep(3000); // 寤舵椂3S
                         } else {
                             News.error("" + mark + " - 5" + " - 璇锋眰鎺ュ彛澶辫触锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + "/rpc/pakin/loc/v1", JSON.toJSONString(param), response);
 
@@ -234,6 +245,19 @@
                             if (ledThread != null) {
                                 String errorMsg = jsonObject.getString("msg");
                                 MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(5, errorMsg));
+                            }
+
+                            //鎵樼洏閫�鍥�
+//                            LiftCommand command = new LiftCommand();
+//                            command.setWorkNo(9998);
+//                            command.setSourceStaNo(inSta.getStaNo());
+//                            command.setTargetStaNo(inSta.getBackSta());
+                            Integer back = 999;
+
+                            barcodeThread.setBarcode("");
+                            boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(4, back));
+                            if (!result) {
+                                throw new CoolException("鏇存柊plc绔欑偣淇℃伅澶辫触");
                             }
                         }
 
@@ -293,17 +317,18 @@
                             continue;
                         }
 
-                    WrkMast wrkMast = wrkMastMapper.selectPickStep(barcode);
+                        WrkMast wrkMast = wrkMastMapper.selectPickStep(barcode);
 //                        WrkMast wrkMast = wrkMastMapper.selectPakInStep3(staProtocol.getWorkNo().intValue());
-//                        if (wrkMast == null) {
-//                            // 鏃犳嫞鏂欐暟鎹�
-//                            continue;
-//                        }
+                        if (wrkMast == null) {
+                            // 鏃犳嫞鏂欐暟鎹�
+                            continue;
+                        }
 
                         if ((wrkMast.getIoType() != 103 && wrkMast.getIoType() != 104 && wrkMast.getIoType() != 107)
                                 || Cools.isEmpty(wrkMast.getStaNo()) || Cools.isEmpty(wrkMast.getSourceStaNo())) {
                             continue;
                         }
+
 
                         // 鑾峰彇鐩爣绔�
                         Wrapper<StaDesc> wrapper = new EntityWrapper<StaDesc>()
@@ -348,7 +373,7 @@
                             param.setLocType1(locTypeDto.getLocType1());
                             String response = new HttpHandler.Builder()
                                     .setUri(wmsUrl)
-                                    .setPath("/rpc/pakin/pick/loc/v1")
+                                    .setPath("/rpc/pakin/loc/returnWarehouse")
                                     .setJson(JSON.toJSONString(param))
                                     .build()
                                     .doPost();
@@ -361,12 +386,12 @@
                                     continue;
                                 }
 
-                                if(newWrkMast.getWrkSts() != 53 && newWrkMast.getWrkSts() != 57) {
+                                if(newWrkMast.getIoType() != 53 && newWrkMast.getIoType() != 57) {
                                     News.error("" + mark + " - 3" + " - 鎷i�夌洏鐐瑰洖搴撳伐浣滄。绫诲瀷寮傚父锛侊紒锛� [plc缂栧彿锛歿}]", devp.getId());
                                     continue;
                                 }
 
-                                if (wrkMast.getWrkSts() != 2) {
+                                if (newWrkMast.getWrkSts() != 2) {
                                     News.error("" + mark + " - 3" + " - 鎷i�夌洏鐐瑰洖搴撳伐浣滄。鐘舵�佸紓甯革紒锛侊紒 [plc缂栧彿锛歿}]", devp.getId());
                                     continue;
                                 }
@@ -445,9 +470,9 @@
             return;
         }
 
-        if (!staProtocol.isOutEnable()) {
-            return;
-        }
+//        if (!staProtocol.isOutEnable()) {
+//            return;
+//        }
 
         //妫�鏌ユ槸鍚︽湁姝e湪鎵ц鐨勪换鍔�
         List<WrkMast> workingWrkMast = wrkMastService.selectList(new EntityWrapper<WrkMast>().in("wrk_sts", 3, 12));
@@ -494,9 +519,9 @@
                 continue;
             }
 
-            if (liftProtocol.getWorkNo() <= 0) {
-                continue;
-            }
+//            if (liftProtocol.getWorkNo() <= 0) {
+//                continue;
+//            }
 
             if (liftProtocol.getMode() != 1) {
                 continue;
@@ -506,23 +531,37 @@
                 continue;
             }
 
-            WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("wrk_no", liftProtocol.getWorkNo()));
-            if (wrkMast == null) {
-                continue;
-            }
+//            WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("wrk_no", liftProtocol.getWorkNo()));
+//            if (wrkMast == null) {
+//                continue;
+//            }
 
-            if (wrkMast.getWrkSts() == 3) {
-                wrkMast.setWrkSts(4L);
-                wrkMast.setCrnEndTime(new Date());
-                wrkMast.setIoTime(new Date());
-                wrkMastService.updateById(wrkMast);
-            }else if (wrkMast.getWrkSts() == 12) {
-                wrkMast.setWrkSts(14L);
-                wrkMast.setCrnEndTime(new Date());
-                wrkMast.setIoTime(new Date());
-                wrkMastService.updateById(wrkMast);
-            }else {
-                News.error("鏈煡鐨勫伐浣滅姸鎬�");
+            List<WrkMast> wrkMastList = wrkMastService.selectList(new EntityWrapper<WrkMast>().in("wrk_sts", 3,12));
+            for (WrkMast wrkMast : wrkMastList) {
+                if (wrkMast.getWrkSts() == 3) {
+                    String locNo = wrkMast.getLocNo();
+                    Integer staNo = Utils.getStaNoByLocNo(locNo);
+                    StaProtocol staProtocol = devpThread.getStation().get(staNo);
+                    if (staProtocol.getWorkNo() <= 0 || !staProtocol.isLoading() || !staProtocol.isAutoing() || !Integer.valueOf(staProtocol.getWorkNo()).equals(wrkMast.getWrkNo())){
+                        continue;
+                    }
+                    wrkMast.setWrkSts(4L);
+                    wrkMast.setCrnEndTime(new Date());
+                    //wrkMast.setIoTime(new Date());
+                    wrkMastService.updateById(wrkMast);
+                }else if (wrkMast.getWrkSts() == 12) {
+                    Integer targetStaNo = wrkMast.getStaNo();
+                    StaProtocol staProtocol = devpThread.getStation().get(targetStaNo);
+                    if (staProtocol.getWorkNo() <= 0 || !staProtocol.isLoading() || !staProtocol.isAutoing() || !Integer.valueOf(staProtocol.getWorkNo()).equals(wrkMast.getWrkNo())){
+                        continue;
+                    }
+                    wrkMast.setWrkSts(14L);
+                    wrkMast.setCrnEndTime(new Date());
+                    //wrkMast.setIoTime(new Date());
+                    wrkMastService.updateById(wrkMast);
+                }else {
+                    News.error("鏈煡鐨勫伐浣滅姸鎬�");
+                }
             }
         }
     }
@@ -659,8 +698,6 @@
             DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, led.getDevpPlcId());
             // 鍛戒护闆嗗悎
             List<LedCommand> commands = new ArrayList<>();
-//            // 宸ヤ綔妗i泦鍚�
-//            List<WrkMast> wrkMasts = new ArrayList<>();
             List<Integer> workNoList = new ArrayList<>();
             for (Integer staNo : led.getStaArr()) {
                 // 鑾峰彇鍙夎溅绔欑偣
@@ -678,8 +715,7 @@
                 String barcode = null;
 
                 // 鑾峰彇宸ヤ綔妗f暟鎹�
-                WrkMast wrkMast = wrkMastMapper.selectById(staProtocol.getWorkNo());
-//                if (null == wrkMast || wrkMast.getWrkSts() < 14 || wrkMast.getIoType() < 100) { continue; }
+                WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("wrk_no",staProtocol.getWorkNo()).in("io_type",101,103,104,107));
                 if (null == wrkMast) {
                     List<WrkMastLog> wrkMastLogs = wrkMastLogService.selectList(new EntityWrapper<WrkMastLog>()
                             .eq("wrk_no", staProtocol.getWorkNo())
@@ -751,63 +787,47 @@
                 ledCommand.setLocNo(locNo);
                 ledCommand.setStaNo(targetStaNo);
                 ledCommand.setBarcode(barcode);
-//                ledCommand.setSourceStaNo(wrkMast.getSourceStaNo());
+
+                // 淇敼寮�濮嬶細澶勭悊澶氫釜wrkDetl锛屼笉鍚堝苟
                 if (ioType != 110 && ioType != 10) {
                     List<WrkDetl> wrkDetls = wrkDetlService.findByWorkNo(wrkNo);
 
                     if (!wrkDetls.isEmpty()) {
-                        WrkDetl wrkDetl = wrkDetls.get(0);
-                        double anfme = 0D;
-                        double weight = 0D;
-                        for (WrkDetl detl : wrkDetls) {
-                            anfme += detl.getAnfme();
-                            weight += detl.getWeight();
-                            wrkDetl.setAnfme(anfme);
-                            wrkDetl.setWeight(weight);
-                        }
-
+                        // 鑾峰彇搴撳瓨淇℃伅
                         List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>()
                                 .eq("loc_no", wrkMast.getSourceLocNo()));
                         double totalAnfme = 0D;
                         double totalWeight = 0D;
                         for (LocDetl locDetl : locDetls) {
                             totalAnfme += locDetl.getAnfme();
-                            totalWeight += locDetl.getWeight();
+//                        totalWeight += locDetl.getWeight();
                         }
-                        wrkDetl.setStockNum(totalAnfme);
-                        wrkDetl.setStockNum2(totalWeight);
 
-                        ledCommand.getMatDtos().add(new MatDto(
-                                wrkDetl.getMatnr()
-                                , wrkDetl.getMaktx()
-                                , wrkDetl.getAnfme()
-                                , wrkDetl.getWeight()
-                                , wrkDetl.getStockNum()
-                                , wrkDetl.getStockNum2()
-                                , wrkDetl.getSpecs()
-                                , wrkDetl.getSku()
-                                , wrkDetl.getZpallet()
-                                , wrkDetl.getModel()
-                                , wrkDetl.getSupp()
-                                , wrkDetl.getKpCstmrName()
-                                , wrkDetl.getOrderNo()
-                                , wrkDetl.getCstateid$()
-                        ));
-
-                    }else {
+                        // 涓烘瘡涓猈rkDetl鍒涘缓鐙珛鐨凪atDto
+                        for (WrkDetl wrkDetl : wrkDetls) {
+                            // 娉ㄦ剰锛氳繖閲屼娇鐢ㄦ瘡涓獁rkDetl鐨勫師濮嬫暟鎹紝涓嶅悎骞�
+                            ledCommand.getMatDtos().add(new MatDto(
+                                    wrkDetl.getMatnr()
+                                    , wrkDetl.getMaktx()
+                                    , wrkDetl.getAnfme()  // 浣跨敤鍗曚釜鐗╂枡鐨勬暟閲忥紝涓嶇疮鍔�
+                                    , wrkDetl.getWeight() // 浣跨敤鍗曚釜鐗╂枡鐨勯噸閲忥紝涓嶇疮鍔�
+                                    , totalAnfme          // 搴撳瓨鎬绘暟锛堣繖涓槸姝e父鐨勶級
+                                    , totalWeight         // 搴撳瓨鎬婚噸閲忥紙杩欎釜鏄甯哥殑锛�
+                                    , wrkDetl.getSpecs()
+                                    , wrkDetl.getSku()
+                                    , wrkDetl.getZpallet()
+                                    , wrkDetl.getModel()
+                                    , wrkDetl.getSupp()
+                                    , wrkDetl.getKpCstmrName()
+                                    , wrkDetl.getOrderNo()
+                                    , wrkDetl.getBatch()
+//                                , wrkDetl.getCstateid$()
+                            ));
+                        }
+                    } else {
                         List<WrkDetlLog> wrkDetlLogs = wrkDetlLogService.selectTodayByWrkNo(wrkNo);
-                        if(!wrkDetlLogs.isEmpty()) {
-                            WrkDetlLog wrkDetlLog = wrkDetlLogs.get(0);
-
-                            double anfme = 0D;
-                            double weight = 0D;
-                            for (WrkDetlLog detl : wrkDetlLogs) {
-                                anfme += detl.getAnfme();
-                                weight += detl.getWeight();
-                                wrkDetlLog.setAnfme(anfme);
-                                wrkDetlLog.setWeight(weight);
-                            }
-
+                        if (!wrkDetlLogs.isEmpty()) {
+                            // 鑾峰彇搴撳瓨淇℃伅
                             List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>()
                                     .eq("loc_no", sourceLocNo));
                             double totalAnfme = 0D;
@@ -816,29 +836,33 @@
                                 totalAnfme += locDetl.getAnfme();
                                 totalWeight += locDetl.getWeight();
                             }
-                            wrkDetlLog.setStockNum(totalAnfme);
-                            wrkDetlLog.setStockNum2(totalWeight);
 
-                            ledCommand.getMatDtos().add(new MatDto(
-                                    wrkDetlLog.getMatnr()
-                                    , wrkDetlLog.getMaktx()
-                                    , wrkDetlLog.getAnfme()
-                                    , wrkDetlLog.getWeight()
-                                    , wrkDetlLog.getStockNum()
-                                    , wrkDetlLog.getStockNum2()
-                                    , wrkDetlLog.getSpecs()
-                                    , wrkDetlLog.getSku()
-                                    , wrkDetlLog.getZpallet()
-                                    , wrkDetlLog.getModel()
-                                    , wrkDetlLog.getSupp()
-                                    , wrkDetlLog.getKpCstmrName()
-                                    , wrkDetlLog.getOrderNo()
-                                    , wrkDetlLog.getCstateid$()
-                            ));
+                            // 涓烘瘡涓猈rkDetlLog鍒涘缓鐙珛鐨凪atDto
+                            for (WrkDetlLog wrkDetlLog : wrkDetlLogs) {
+                                // 娉ㄦ剰锛氳繖閲屼娇鐢ㄦ瘡涓獁rkDetlLog鐨勫師濮嬫暟鎹紝涓嶅悎骞�
+                                ledCommand.getMatDtos().add(new MatDto(
+                                        wrkDetlLog.getMatnr()
+                                        , wrkDetlLog.getMaktx()
+                                        , wrkDetlLog.getAnfme()  // 浣跨敤鍗曚釜鐗╂枡鐨勬暟閲忥紝涓嶇疮鍔�
+                                        , wrkDetlLog.getWeight() // 浣跨敤鍗曚釜鐗╂枡鐨勯噸閲忥紝涓嶇疮鍔�
+                                        , totalAnfme              // 搴撳瓨鎬绘暟
+                                        , totalWeight             // 搴撳瓨鎬婚噸閲�
+                                        , wrkDetlLog.getSpecs()
+                                        , wrkDetlLog.getSku()
+                                        , wrkDetlLog.getZpallet()
+                                        , wrkDetlLog.getModel()
+                                        , wrkDetlLog.getSupp()
+                                        , wrkDetlLog.getKpCstmrName()
+                                        , wrkDetlLog.getOrderNo()
+                                        , wrkDetlLog.getBatch()
+//                                    , wrkDetlLog.getCstateid$()
+                                ));
+                            }
                         }
                     }
-
                 }
+                // 淇敼缁撴潫
+
                 commands.add(ledCommand);
             }
             Set<Integer> workNos = new HashSet<>(workNoList);
@@ -848,29 +872,11 @@
             if (CollectionUtils.equals(ledThread.getWorkNos(), workNos)) {
                 continue;
             }
-//             鍛戒护涓嬪彂 -------------------------------------------------------------------------------
-//            if (!commands.isEmpty()) {
-//                if (led.getId() < 7) {
-//                    if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(3, commands))) {
-//                        News.error(""+mark+" - 2"+" - {}鍙稬ED鍛戒护涓嬪彂澶辫触锛侊紒锛乕ip锛歿}] [port锛歿}]", led.getId(), led.getIp(), led.getPort());
-//                        continue;
-//                    } else {
-//                        ledThread.setLedMk(false);
-//                    }
-//                } else {
-//                    if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(1, commands))) {
-//                        News.error(""+mark+" - 3"+" - {}鍙稬ED鍛戒护涓嬪彂澶辫触锛侊紒锛乕ip锛歿}] [port锛歿}]", led.getId(), led.getIp(), led.getPort());
-//                        continue;
-//                    } else {
-//                        ledThread.setLedMk(false);
-//                    }
-//                }
-//
-//            }
+
             // 鍛戒护涓嬪彂 -------------------------------------------------------------------------------
             if (!commands.isEmpty()) {
                 if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(3, commands))) {
-                    News.error("{}鍙稬ED鍛戒护涓嬪彂澶辫触锛侊紒锛乕ip锛歿}] [port锛歿}]", led.getId(), led.getIp(), led.getPort());
+                    News.error("{}鍙稬ED鍛戒护涓嬪彂澶辫触--->鍑哄簱锛侊紒锛乕ip锛歿}] [port锛歿}]", led.getId(), led.getIp(), led.getPort());
                     continue;
                 } else {
                     ledThread.setLedMk(false);
@@ -918,10 +924,14 @@
             for (Integer staNo : led.getStaArr()) {
                 // 鑾峰彇鍙夎溅绔欑偣
                 StaProtocol staProtocol = devpThread.getStation().get(staNo);
+                StaProtocol staProtocol1 = devpThread.getStation().get(122);
                 if (staProtocol == null) {
                     continue;
                 }
-                if (staProtocol.getWorkNo() != 0 && staProtocol.isLoading()) {
+                if (staProtocol1 == null) {
+                    continue;
+                }
+                if ((staProtocol.getWorkNo() != 0 && staProtocol.isLoading()) || (staProtocol1.getWorkNo() != 0 || staProtocol1.isLoading())) {
                     reset = false;
                     break;
                 }
@@ -932,7 +942,7 @@
             if (reset && !ledThread.isLedMk()) {
                 ledThread.setLedMk(true);
                 if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(4, new ArrayList<>()))) {
-                    News.error("" + mark + " - 1" + " - {}鍙稬ED鍛戒护涓嬪彂澶辫触锛侊紒锛乕ip锛歿}] [port锛歿}]", led.getId(), led.getIp(), led.getPort());
+                    News.error("" + mark + " - 1" + " - {}鍙稬ED鍛戒护涓嬪彂澶辫触--->澶嶄綅锛侊紒锛乕ip锛歿}] [port锛歿}]", led.getId(), led.getIp(), led.getPort());
                 } else {
 
                 }
@@ -940,4 +950,144 @@
         }
         News.infoNoLog("" + mark + " - 0" + " - 鎵ц瀹屾垚锛氬叾浠�  ===>> LED鏄剧ず鍣ㄥ浣嶏紝鏄剧ず榛樿淇℃伅");
     }
-}
+
+    public void ledExecuteIn(Integer mark) {
+        for (LedSlave led : slaveProperties.getLed()) {
+            // 鍛戒护闆嗗悎
+            List<LedCommand> commands = new ArrayList<>();
+            List<Integer> workNoList = new ArrayList<>();
+
+            // 鍏ュ簱宸ヤ綔妗� - 杩欓噷鍙兘闇�瑕佹坊鍔犳洿澶氭煡璇㈡潯浠讹紝纭繚鍙幏鍙栬LED瀵瑰簲鐨勫伐浣滄。
+            WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>()
+                            .eq("wrk_sts", 3)
+                            .in("io_type", 1, 53, 54, 57)
+                    // 鍙兘闇�瑕佹坊鍔燣ED鍏宠仈鏉′欢锛屼緥濡傜珯鐐圭紪鍙风瓑
+            );
+
+            if (wrkMast == null) {
+                continue;  // 娌℃湁宸ヤ綔妗o紝缁х画澶勭悊涓嬩竴涓狶ED
+            }
+
+            Integer wrkNo = wrkMast.getWrkNo();
+            Integer ioType = wrkMast.getIoType();
+            String sourceLocNo = wrkMast.getSourceLocNo();
+            String locNo = wrkMast.getLocNo();
+            Integer targetStaNo = wrkMast.getStaNo();
+            String barcode = wrkMast.getBarcode();
+
+            workNoList.add(wrkNo);
+
+            // 缁勮鍛戒护
+            LedCommand ledCommand = new LedCommand();
+            ledCommand.setWorkNo(wrkNo);
+            ledCommand.setIoType(ioType);
+
+            // 鍏ュ簱妯″紡 - 淇浜哻ase 54鍜�57鐨勬弿杩�
+            switch (ioType) {
+                case 1:
+                    ledCommand.setTitle("鍏ㄦ澘鍏ュ簱");
+                    break;
+                case 53:
+                    ledCommand.setTitle("鎷f枡鍏ュ簱");
+                    break;
+                case 54:
+                    ledCommand.setTitle("骞舵澘鍏ュ簱");  // 淇锛氬簲璇ユ槸骞舵澘鍏ュ簱锛屼笉鏄洏鐐瑰叆搴�
+                    break;
+                case 57:
+                    ledCommand.setTitle("鐩樼偣鍏ュ簱");  // 淇锛氬簲璇ユ槸鐩樼偣鍏ュ簱锛屼笉鏄苟鏉垮叆搴�
+                    break;
+                default:
+                    // 鍙�夌殑閿欒澶勭悊
+                    continue;  // 璺宠繃涓嶆敮鎸佺殑ioType
+            }
+
+            ledCommand.setSourceLocNo(sourceLocNo);
+            ledCommand.setLocNo(locNo);
+            ledCommand.setStaNo(targetStaNo);
+            ledCommand.setBarcode(barcode);
+
+            List<WrkDetl> wrkDetls = wrkDetlService.findByWorkNo(wrkNo);
+
+            // 鍗充娇wrkDetls涓虹┖锛屼篃搴旇澶勭悊LED鍛戒护锛堝彲鑳芥煇浜涘叆搴撶被鍨嬩笉闇�瑕佺墿鏂欐槑缁嗭級
+            if (!wrkDetls.isEmpty()) {
+                // 鑾峰彇搴撳瓨淇℃伅
+                List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>()
+                        .eq("loc_no", sourceLocNo));  // 浣跨敤sourceLocNo鑰屼笉鏄痺rkMast.getSourceLocNo()
+                double totalAnfme = 0D;
+                double totalWeight = 0D;
+                for (LocDetl locDetl : locDetls) {
+                    totalAnfme += locDetl.getAnfme();
+                    totalWeight += locDetl.getWeight();  // 濡傛灉鏁版嵁搴撴湁weight瀛楁锛屽簲璇ュ姞涓�
+                }
+
+                // 涓烘瘡涓猈rkDetl鍒涘缓鐙珛鐨凪atDto
+                for (WrkDetl wrkDetl : wrkDetls) {
+                    ledCommand.getMatDtos().add(new MatDto(
+                            wrkDetl.getMatnr(),
+                            wrkDetl.getMaktx(),
+                            wrkDetl.getAnfme(),   // 浣跨敤鍗曚釜鐗╂枡鐨勬暟閲�
+                            wrkDetl.getWeight(),  // 浣跨敤鍗曚釜鐗╂枡鐨勯噸閲�
+                            totalAnfme,           // 搴撳瓨鎬绘暟
+                            totalWeight,          // 搴撳瓨鎬婚噸閲�
+                            wrkDetl.getSpecs(),
+                            wrkDetl.getSku(),
+                            wrkDetl.getZpallet(),
+                            wrkDetl.getModel(),
+                            wrkDetl.getSupp(),
+                            wrkDetl.getKpCstmrName(),
+                            wrkDetl.getOrderNo(),
+                            wrkDetl.getBatch()
+                    ));
+                }
+            }
+
+            // 鍗充娇娌℃湁鐗╂枡鏄庣粏锛屼篃搴旇娣诲姞LED鍛戒护锛堟煇浜涘叆搴撶被鍨嬪彲鑳戒笉闇�瑕佹樉绀虹墿鏂欙級
+            commands.add(ledCommand);
+
+            Set<Integer> workNos = new HashSet<>(workNoList);
+            // 鑾峰彇LED绾跨▼
+            LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, led.getId());
+
+            if (ledThread == null) {
+                News.error("鏈壘鍒癓ED绾跨▼锛歔id锛歿}]", led.getId());
+                continue;
+            }
+
+            // 鐩稿悓宸ヤ綔鍙烽泦鍚堝垯杩囨护
+            if (CollectionUtils.equals(ledThread.getWorkNos(), workNos)) {
+                continue;
+            }
+
+            // 鍛戒护涓嬪彂 -------------------------------------------------------------------------------
+            if (!commands.isEmpty()) {
+                if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(3, commands))) {
+                    News.error("{}鍙稬ED鍛戒护涓嬪彂澶辫触--->鍏ュ簱锛侊紒锛乕ip锛歿}] [port锛歿}]", led.getId(), led.getIp(), led.getPort());
+                    continue;
+                } else {
+                    ledThread.setLedMk(false);
+                }
+            }
+
+            try {
+                // 淇敼涓绘。led鏍囪
+                // 娉ㄦ剰锛氳繖閲屽彧闇�瑕佹洿鏂板綋鍓嶅伐浣滄。锛屼笉闇�瑕佸惊鐜�
+                WrkMast wrkMastToUpdate = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("wrk_no", wrkNo));
+                if (wrkMastToUpdate != null) {
+                    wrkMastToUpdate.setOveMk("Y");
+                    wrkMastToUpdate.setModiTime(new Date());
+                    if (wrkMastMapper.updateById(wrkMastToUpdate) == 0) {
+                        News.errorNoLog("" + mark + " - 4" + " - 鏇存柊宸ヤ綔妗eけ璐�");
+                        throw new CoolException("鏇存柊宸ヤ綔妗eけ璐�");
+                    }
+                }
+
+                // 鏇存柊绾跨▼褰撳墠宸ヤ綔鍙烽泦鍚�
+                ledThread.setWorkNos(workNos);
+
+            } catch (Exception e) {
+                e.printStackTrace();
+                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+            }
+        }
+    }
+}
\ No newline at end of file

--
Gitblit v1.9.1