From 06ee622946d64da07bde8840db216a22c70dffba Mon Sep 17 00:00:00 2001
From: TQS <56479841@qq.com>
Date: 星期三, 21 八月 2024 17:23:44 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java |  259 ++++++++++++++++++++++++++++-----------------------
 1 files changed, 141 insertions(+), 118 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 1504420..506e3c6 100644
--- a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -1065,7 +1065,7 @@
                         //  鍒ゆ柇鍫嗗灈鏈虹姸鎬佺瓑寰呯‘璁�
                         if (crnProtocol.modeType == CrnModeType.AUTO
                                 && crnProtocol.statusType == CrnStatusType.IDLE
-                                && crnProtocol.forkPosType == CrnForkPosType.HOME) {
+                                && crnProtocol.forkPosType == CrnForkPosType.HOME && crnStn.getBay()!=(short)4) {
                             News.info("鍫嗗灈鏈烘帴椹充换鍔℃墽琛岋紝宸ヤ綔鍙凤細"+staProtocol.getWorkNo()+"锛涙墽琛屽爢鍨涙満鍙凤細"+slave.getId()+"锛涙帴椹冲彇璐т綅锛�"+crnStn.getStaNo()+"锛涙帴椹虫斁璐т綅锛�"+staProtocol.getSiteId());
                             // 鍫嗗灈鏈烘帴椹充换鍔″懡浠や笅鍙戝尯 --------------------------------------------------------------------------
                             CrnCommand crnCommand = new CrnCommand();
@@ -1097,7 +1097,7 @@
                         //  鍒ゆ柇鍫嗗灈鏈虹姸鎬佺瓑寰呯‘璁�
                         if (crnProtocol.modeType == CrnModeType.AUTO
                                 && crnProtocol.statusType == CrnStatusType.IDLE
-                                && crnProtocol.forkPosType == CrnForkPosType.HOME) {
+                                && crnProtocol.forkPosType == CrnForkPosType.HOME && crnStn.getBay()==(short)4) {
                             News.info("鍫嗗灈鏈烘帴椹充换鍔℃墽琛岋紝宸ヤ綔鍙凤細"+staProtocol.getWorkNo()+"锛涙墽琛屽爢鍨涙満鍙凤細"+slave.getId()+"锛涙帴椹冲彇璐т綅锛�"+crnStn.getStaNo()+"锛涙帴椹虫斁璐т綅锛�"+staProtocol.getSiteId());
                             // 鍫嗗灈鏈烘帴椹充换鍔″懡浠や笅鍙戝尯 --------------------------------------------------------------------------
                             CrnCommand crnCommand = new CrnCommand();
@@ -2707,6 +2707,7 @@
             SteThread steThread = (SteThread) SlaveConnection.get(SlaveType.Ste, ste.getId());
             SteProtocol steProtocol = steThread.getSteProtocol();
             if (steProtocol == null) { continue; }
+            if (Cools.isEmpty(steProtocol.loca))  continue;
             if (steProtocol.loca==0) continue;
             if (Utils.getGroupRow(locNo).equals(Utils.getGroupRow(steProtocol.getRow().intValue())) && steProtocol.getBay() == Utils.getBay(locNo) && steProtocol.getLev() == Utils.getLev(locNo)) {
                 return steProtocol.getSteNo().intValue();
@@ -2724,6 +2725,7 @@
             SteThread steThread = (SteThread) SlaveConnection.get(SlaveType.Ste, ste.getId());
             SteProtocol steProtocol = steThread.getSteProtocol();
             if (steProtocol == null) { continue; }
+            if (Cools.isEmpty(steProtocol.loca)) continue;
             if (steProtocol.loca==0) continue;
             if (steProtocol.isIdle()) {
                 if (Utils.getGroupRow(locNo).equals(Utils.getGroupRow(steProtocol.getRow().intValue())) && steProtocol.getBay() == Utils.getBay(locNo) && steProtocol.getLev() == Utils.getLev(locNo)) {
@@ -3578,6 +3580,7 @@
             SteThread steThread = (SteThread) SlaveConnection.get(SlaveType.Ste, ste.getId());
             SteProtocol steProtocol = steThread.getSteProtocol();
             if (steProtocol == null) { continue; }
+            if (Cools.isEmpty(steProtocol.loca)) continue;
             if (steProtocol.loca==0) continue;
             if (steProtocol.getWaiting() && steProtocol.getTaskNo() == 0){
                 News.info("ste[id={}] 鏀跺埌绛夊緟WCS纭淇″彿锛屼絾鏄换鍔″彿(鍦板潃V824)涓�0", steProtocol.getSteNo());
@@ -4095,109 +4098,116 @@
      */
     public synchronized void ledExecute() {
         for (LedSlave led : slaveProperties.getLed()) {
-            // 鑾峰彇杈撻�佺嚎plc绾跨▼
-            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, led.getDevpPlcId());
-            // 鍛戒护闆嗗悎
-            List<LedCommand> commands = new ArrayList<>();
-            // 宸ヤ綔妗i泦鍚�
-            List<WrkMast> wrkMasts = new ArrayList<>();
-            for (Integer staNo : led.getStaArr()) {
-                // 鑾峰彇鍙夎溅绔欑偣
-                StaProtocol staProtocol = devpThread.getStation().get(staNo);
-                if (null == staProtocol || null == staProtocol.getWorkNo() || 0 == staProtocol.getWorkNo() || !staProtocol.isLoading()) {
-                    continue;
-                } else {
-                    staProtocol = staProtocol.clone();
-                }
-                // 鑾峰彇宸ヤ綔妗f暟鎹�
-                WrkMast wrkMast = wrkMastMapper.selectById(staProtocol.getWorkNo());
-                if (null == wrkMast || wrkMast.getWrkSts() < 14 || wrkMast.getIoType() < 100) { continue; }
-                wrkMasts.add(wrkMast);
-                // 缁勮鍛戒护
-                LedCommand ledCommand = new LedCommand();
-                ledCommand.setWorkNo(wrkMast.getWrkNo());
-                ledCommand.setIoType(wrkMast.getIoType());
-                // 鍑哄簱妯″紡
-                switch (wrkMast.getIoType()) {
-                    case 101:
-                        ledCommand.setTitle("鍏ㄦ澘鍑哄簱");
-                        break;
-                    case 103:
-                        ledCommand.setTitle("鎷f枡鍑哄簱");
-                        break;
-                    case 104:
-                        ledCommand.setTitle("骞舵澘鍑哄簱");
-                        break;
-                    case 107:
-                        ledCommand.setTitle("鐩樼偣鍑哄簱");
-                        break;
-                    case 110:
-                        ledCommand.setTitle("绌烘澘鍑哄簱");
-                        ledCommand.setEmptyMk(true);
-                        break;
-                    default:
-                        News.error("浠诲姟鍏ュ嚭搴撶被鍨嬮敊璇紒锛侊紒[宸ヤ綔鍙凤細{}] [鍏ュ嚭搴撶被鍨嬶細{}]", wrkMast.getWrkNo(), wrkMast.getIoType());
-                        break;
-                }
-                ledCommand.setSourceLocNo(wrkMast.getSourceLocNo());
-                ledCommand.setStaNo(wrkMast.getStaNo());
-                ledCommand.setBarcode(wrkMast.getBarcode());
-                if (wrkMast.getIoType() != 110) {
-                    List<WrkDetl> wrkDetls = wrkDetlService.findByWorkNo(wrkMast.getWrkNo());
+            try{
+                // 鑾峰彇杈撻�佺嚎plc绾跨▼
+                DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, led.getDevpPlcId());
+                // 鍛戒护闆嗗悎
+                List<LedCommand> commands = new ArrayList<>();
+                // 宸ヤ綔妗i泦鍚�
+                List<WrkMast> wrkMasts = new ArrayList<>();
+                for (Integer staNo : led.getStaArr()) {
+                    // 鑾峰彇鍙夎溅绔欑偣
+                    StaProtocol staProtocol = devpThread.getStation().get(staNo);
+                    if (null == staProtocol || null == staProtocol.getWorkNo() || 0 == staProtocol.getWorkNo() || !staProtocol.isLoading()) {
+                        continue;
+                    } else {
+                        staProtocol = staProtocol.clone();
+                    }
+                    // 鑾峰彇宸ヤ綔妗f暟鎹�
+                    WrkMast wrkMast = wrkMastMapper.selectById(staProtocol.getWorkNo());
+                    if (null == wrkMast || wrkMast.getWrkSts() < 14 || wrkMast.getIoType() < 100) { continue; }
+                    wrkMasts.add(wrkMast);
+                    // 缁勮鍛戒护
+                    LedCommand ledCommand = new LedCommand();
+                    ledCommand.setWorkNo(wrkMast.getWrkNo());
+                    ledCommand.setIoType(wrkMast.getIoType());
+                    // 鍑哄簱妯″紡
+                    switch (wrkMast.getIoType()) {
+                        case 101:
+                            ledCommand.setTitle("鍏ㄦ澘鍑哄簱");
+                            break;
+                        case 103:
+                            ledCommand.setTitle("鎷f枡鍑哄簱");
+                            break;
+                        case 104:
+                            ledCommand.setTitle("骞舵澘鍑哄簱");
+                            break;
+                        case 107:
+                            ledCommand.setTitle("鐩樼偣鍑哄簱");
+                            break;
+                        case 110:
+                            ledCommand.setTitle("绌烘澘鍑哄簱");
+                            ledCommand.setEmptyMk(true);
+                            break;
+                        default:
+                            News.error("浠诲姟鍏ュ嚭搴撶被鍨嬮敊璇紒锛侊紒[宸ヤ綔鍙凤細{}] [鍏ュ嚭搴撶被鍨嬶細{}]", wrkMast.getWrkNo(), wrkMast.getIoType());
+                            break;
+                    }
+                    ledCommand.setSourceLocNo(wrkMast.getSourceLocNo());
+                    ledCommand.setStaNo(wrkMast.getStaNo());
+                    ledCommand.setBarcode(wrkMast.getBarcode());
+                    if (wrkMast.getIoType() != 110) {
+                        List<WrkDetl> wrkDetls = wrkDetlService.findByWorkNo(wrkMast.getWrkNo());
 
-                    wrkDetls.forEach(wrkDetl -> {
-                        Double total = 0.0;
-                        EntityWrapper<LocDetl> wrapper = new EntityWrapper<>();
-                        LocDetl locDetl = locDetlService.selectOne(wrapper.eq("zpallet", wrkDetl.getZpallet()).eq("matnr", wrkDetl.getMatnr()));
-                        if (Cools.isEmpty(locDetl)) {
-                            total = wrkDetl.getAnfme();
-                        } else {
-                            total = locDetl.getAnfme();
-                        }
-                        if (wrkMast.getIoType() == 101) {
-                            ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getBatch(), wrkDetl.getSpecs(), wrkDetl.getManu(), wrkDetl.getMemo(), wrkDetl.getAnfme(),total));
-                        }
-                        if (wrkMast.getIoType() == 103 && (null == wrkDetl.getInspect() || 0 == wrkDetl.getInspect())) {
-                            ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getBatch(), wrkDetl.getSpecs(), wrkDetl.getManu(), wrkDetl.getMemo(), wrkDetl.getAnfme(),total));
-                        }
-                        if (wrkMast.getIoType() == 107) {
-                            ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getBatch(), wrkDetl.getSpecs(), wrkDetl.getManu(), wrkDetl.getMemo(), wrkDetl.getAnfme(),total));
-                        }
-                    });
+                        wrkDetls.forEach(wrkDetl -> {
+                            Double total = 0.0;
+                            EntityWrapper<LocDetl> wrapper = new EntityWrapper<>();
+                            LocDetl locDetl = locDetlService.selectOne(wrapper.eq("zpallet", wrkDetl.getZpallet()).eq("matnr", wrkDetl.getMatnr()));
+                            if (Cools.isEmpty(locDetl)) {
+                                total = wrkDetl.getAnfme();
+                            } else {
+                                total = locDetl.getAnfme();
+                            }
+                            if (wrkMast.getIoType() == 101) {
+                                ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getBatch(), wrkDetl.getSpecs(), wrkDetl.getManu(), wrkDetl.getMemo(), wrkDetl.getAnfme(),total));
+                            }
+                            if (wrkMast.getIoType() == 103 && (null == wrkDetl.getInspect() || 0 == wrkDetl.getInspect())) {
+                                ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getBatch(), wrkDetl.getSpecs(), wrkDetl.getManu(), wrkDetl.getMemo(), wrkDetl.getAnfme(),total));
+                            }
+                            if (wrkMast.getIoType() == 107) {
+                                ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getBatch(), wrkDetl.getSpecs(), wrkDetl.getManu(), wrkDetl.getMemo(), wrkDetl.getAnfme(),total));
+                            }
+                        });
+                    }
+                    commands.add(ledCommand);
                 }
-                commands.add(ledCommand);
-            }
-            Set<Integer> workNos = wrkMasts.stream().map(WrkMast::getWrkNo).collect(Collectors.toSet());
-            // 鑾峰彇LED绾跨▼
-            LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, led.getId());
-            // 鐩稿悓宸ヤ綔鍙烽泦鍚堝垯杩囨护
-            if (CollectionUtils.equals(ledThread.getWorkNos(), workNos)) {
-                continue;
-            }
-            // 鍛戒护涓嬪彂 -------------------------------------------------------------------------------
-            if (!commands.isEmpty()) {
-                if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(1, commands))) {
-                    News.error("{}鍙稬ED鍛戒护涓嬪彂澶辫触锛侊紒锛乕ip锛歿}] [port锛歿}]", led.getId(), led.getIp(), led.getPort());
+                Set<Integer> workNos = wrkMasts.stream().map(WrkMast::getWrkNo).collect(Collectors.toSet());
+                // 鑾峰彇LED绾跨▼
+                LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, led.getId());
+                // 鐩稿悓宸ヤ綔鍙烽泦鍚堝垯杩囨护
+                if (CollectionUtils.equals(ledThread.getWorkNos(), workNos)) {
                     continue;
                 }
-            }
-
-            try {
-                // 淇敼涓绘。led鏍囪
-                for (WrkMast wrkMast : wrkMasts) {
-                    wrkMast.setOveMk("Y");
-                    wrkMast.setModiTime(new Date());
-                    if (wrkMastMapper.updateById(wrkMast) == 0) {
-                        throw new CoolException("鏇存柊宸ヤ綔妗eけ璐�");
+                // 鍛戒护涓嬪彂 -------------------------------------------------------------------------------
+                if (!commands.isEmpty()) {
+                    if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(1, commands))) {
+                        News.error("{}鍙稬ED鍛戒护涓嬪彂澶辫触锛侊紒锛乕ip锛歿}] [port锛歿}]", led.getId(), led.getIp(), led.getPort());
+                        continue;
+                    } else {
+                        News.info("{}鍙稬ED鍛戒护涓嬪彂鎴愬姛锛侊紒锛乕ip锛歿}] [port锛歿}]", led.getId(), led.getIp(), led.getPort());
+                        News.info("{}鍙稬ED鍛戒护涓嬪彂鎴愬姛锛侊紒锛乕commands锛歿}]", led.getId(), commands);
                     }
                 }
 
-                // 鏇存柊绾跨▼褰撳墠宸ヤ綔鍙烽泦鍚�
-                ledThread.setWorkNos(workNos);
+                try {
+                    // 淇敼涓绘。led鏍囪
+                    for (WrkMast wrkMast : wrkMasts) {
+                        wrkMast.setOveMk("Y");
+                        wrkMast.setModiTime(new Date());
+                        if (wrkMastMapper.updateById(wrkMast) == 0) {
+                            throw new CoolException("鏇存柊宸ヤ綔妗eけ璐�");
+                        }
+                    }
 
-            } catch (Exception e) {
-                e.printStackTrace();
-                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+                    // 鏇存柊绾跨▼褰撳墠宸ヤ綔鍙烽泦鍚�
+                    ledThread.setWorkNos(workNos);
+
+                } catch (Exception e) {
+                    e.printStackTrace();
+                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+                }
+            } catch (Exception e){
+                News.error(e.getMessage());
             }
 
         }
@@ -4208,26 +4218,32 @@
      */
     public synchronized void ledReset() {
         for (LedSlave led : slaveProperties.getLed()) {
-            // 鑾峰彇杈撻�佺嚎plc绾跨▼
-            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, led.getDevpPlcId());
-            // 鍛戒护闆嗗悎
-            boolean reset = true;
-            for (Integer staNo : led.getStaArr()) {
-                // 鑾峰彇鍙夎溅绔欑偣
-                StaProtocol staProtocol = devpThread.getStation().get(staNo);
-                if (staProtocol == null) { continue; }
-                if (staProtocol.getWorkNo() != 0) {
-                    reset = false;
-                    break;
+            try{
+                // 鑾峰彇杈撻�佺嚎plc绾跨▼
+                DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, led.getDevpPlcId());
+                // 鍛戒护闆嗗悎
+                boolean reset = true;
+                for (Integer staNo : led.getStaArr()) {
+                    // 鑾峰彇鍙夎溅绔欑偣
+                    StaProtocol staProtocol = devpThread.getStation().get(staNo);
+                    if (staProtocol == null) { continue; }
+                    if (staProtocol.getWorkNo() != 0) {
+                        reset = false;
+                        break;
+                    }
                 }
-            }
-            // 鑾峰彇led绾跨▼
-            LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, led.getDevpPlcId());
-            // led鏄剧ず榛樿鍐呭
-            if (reset) {
-                if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(2, new ArrayList<>()))) {
-                    News.error("{}鍙稬ED鍛戒护涓嬪彂澶辫触锛侊紒锛乕ip锛歿}] [port锛歿}]", led.getId(), led.getIp(), led.getPort());
+                // 鑾峰彇led绾跨▼
+                LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, led.getDevpPlcId());
+                // led鏄剧ず榛樿鍐呭
+                if (reset) {
+                    if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(2, new ArrayList<>()))) {
+                        News.error("{}鍙稬ED澶嶄綅鍛戒护涓嬪彂澶辫触锛侊紒锛乕ip锛歿}] [port锛歿}]", led.getId(), led.getIp(), led.getPort());
+                    } else {
+//                        News.info("{}鍙稬ED澶嶄綅鍛戒护涓嬪彂鎴愬姛锛侊紒锛乕ip锛歿}] [port锛歿}]", led.getId(), led.getIp(), led.getPort());
+                    }
                 }
+            } catch (Exception e){
+                News.error("LED寮傚父"+led.getId());
             }
         }
     }
@@ -4873,8 +4889,8 @@
                 SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
 
                 for (DevpSlave.Sta inSta : devp.getInSta()) {
-                    Integer sourceStaNo = inSta.getStaNo()==103 ? 104 : inSta.getStaNo()==113 ? 104 : 204;
-                    WrkMast pakout = wrkMastMapper.selectWorkingPakout(sourceStaNo);
+                    Integer staNoEnd = inSta.getStaNo()==113 ? 114 : 214;
+                    WrkMast pakout = wrkMastMapper.selectWorkingPakoutTwoF(staNoEnd);
                     boolean sign = true;
                     int[] staNos = new int[3];
 
@@ -4883,7 +4899,8 @@
                             staNos = new int[]{112,113,114};
                             for (int staNo : staNos){
                                 StaProtocol staProtocol = devpThread.getStation().get(staNo);
-                                if (!staProtocol.isAutoing() || staProtocol.isLoading()){
+                                if (Cools.isEmpty(staProtocol)) continue;
+                                if (!staProtocol.isAutoing() || staProtocol.isLoading() || staProtocol.getWorkNo()>0){
                                     sign = false;
                                 }
                             }
@@ -4912,6 +4929,7 @@
                             staNos = new int[]{212,213,214};
                             for (int staNo : staNos){
                                 StaProtocol staProtocol = devpThread.getStation().get(staNo);
+                                if (Cools.isEmpty(staProtocol)) continue;
                                 if (!staProtocol.isAutoing() || staProtocol.isLoading()){
                                     sign = false;
                                 }
@@ -4982,6 +5000,11 @@
                                 if (!MessageQueue.offer(SlaveType.Ste, ste.getId(), new Task(2, steCommand))) {
                                     News.error("绌挎杞﹀懡浠や笅鍙戝け璐ワ紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", ste.getId(), JSON.toJSON(steCommand));
                                 }
+                                try{
+                                    Thread.sleep(500);
+                                } catch (Exception e){
+
+                                }
                             }
                         }
                     }

--
Gitblit v1.9.1