From f6decf71aa936d019a7732970744c6c33f5e6175 Mon Sep 17 00:00:00 2001
From: lsh <lsh123456>
Date: 星期三, 12 十月 2022 16:07:54 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java |  202 ++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 144 insertions(+), 58 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 b6c44c7..ac67afc 100644
--- a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -103,7 +103,7 @@
         for (DevpSlave devp : slaveProperties.getDevp()) {
             // 閬嶅巻鍏ュ簱鍙�
             for (DevpSlave.Sta inSta : devp.getInSta()) {
-//                inSta.setStaNo(102);
+                inSta.setStaNo(102);
                 // 鑾峰彇鏉$爜鎵弿浠俊鎭�
                 BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, inSta.getBarcode());
                 if (barcodeThread == null) {
@@ -167,7 +167,7 @@
                     try {
 
                         LocTypeDto locTypeDto = new LocTypeDto(staProtocol);
-//                        locTypeDto.setLocType1((short)1);
+                        locTypeDto.setLocType1((short)1);
                         SearchLocParam param = new SearchLocParam();
                         param.setBarcode(barcode);
                         param.setIoType(1);
@@ -1980,81 +1980,167 @@
     }
 
     /**
-     * 鏍规嵁PLC鎸夐挳娴嬭瘯淇″彿锛屽彂閫佸惎鍔ㄧ敵璇峰埌娴嬭瘯绯荤粺
+     * 鏍规嵁PLC鎸夐挳娴嬭瘯銆佸畬鎴愩�佹殏鍋滀俊鍙凤紝鏇存柊testMast琛ㄤ腑status鍊硷紝浜ょ敱WMS绯荤粺澶勭悊
      */
     @Transactional
-    public void startTest() {
+    public void packTest() {
         try {
             // 鏍规嵁杈撻�佺嚎plc閬嶅巻
             for (DevpSlave devp : slaveProperties.getDevp()) {
                 SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
                 if(null != devpThread){
-                    int channel = 0;
-                    for (int i = 0; i < 4; i++){
-                        switch (i){
-                            case 0:
-                                channel = devpThread.startSignal1;
+                    for (int i = 0; i < 48; i++){
+                        int olsStatus = 0;//testMast琛ㄥ師鏉tatus鏁版嵁鐘舵��
+                        int newStatus = 0;//testMast琛ㄥ緟淇敼鐨剆tatus鏁版嵁鐘舵��
+                        short newSingle = 0;  //PLC鍦板潃寰呬慨鏀圭殑鏂板��
+                        switch (devpThread.startSignal[i]){//鏍规嵁淇″彿鏌ユ壘testMast琛ㄤ腑瀵瑰簲鐘舵�佹潯浠�,olsStatus锛宯ewStatus鏍规嵁瀹為檯娴佺▼璋冩暣
+                            case 1://鍚姩澶嶆牳淇″彿
+                                olsStatus = 2;
+                                newStatus = 3;
+                                newSingle = 2;//娴嬭瘯澶嶆牳锛屽瘎瀛樺櫒鍦板潃锛�1===>>2
                                 break;
-                            case 1:
-                                channel = devpThread.startSignal2;
+                            case 3://瀹屾垚娴嬭瘯淇″彿
+                                olsStatus = 3;
+                                newStatus = 4;
+                                newSingle = 0;//娴嬭瘯瀹屾垚锛屽瘎瀛樺櫒鍦板潃娓呴浂锛�3===>>0
                                 break;
-                            case 2:
-                                channel = devpThread.startSignal3;
+                            case 5://鏆傚仠淇″彿
+                                olsStatus = 99;//plc缁欏嚭鏆傚仠淇″彿
+                                newStatus = 0;//WCS鏀跺埌鏆傚仠淇″彿鍚庯紝鏇存柊testMast
+                                newSingle = 6;//鏆傚仠娴嬭瘯锛屽瘎瀛樺櫒鍦板潃锛�5===>>6
                                 break;
-                            case 3:
-                                channel = devpThread.startSignal4;
+                            case 7://绱ф�ュ嚭搴撶‘璁ゅ厖鐢电嚎宸茬粡鎷斿嚭
+                                olsStatus = 99;//plc缁欏嚭鏆傚仠淇″彿
+                                newStatus = 0;//WCS鏀跺埌鏆傚仠淇″彿鍚庯紝鏇存柊testMast
+                                newSingle = 6;//鏆傚仠娴嬭瘯锛屽瘎瀛樺櫒鍦板潃锛�7===>>6
+                                break;
+                            case 8://瑙i櫎鏆傚仠
+                                olsStatus = 99;
+                                newStatus = 0;
+                                newSingle = 0;//娴嬭瘯澶嶆牳锛屽瘎瀛樺櫒鍦板潃锛�8===>>0
+                                break;
+                            case 11://鍏ュ簱鍓嶅垽鏂厖鐢电嚎鏄惁鏀惧ソ
+                                olsStatus = 99;
+                                newStatus = 0;
+                                newSingle = 11;//
+                                break;
+                            case 12://鍏呯數绾挎斁濂�
+                                olsStatus = 99;
+                                newStatus = 0;
+                                newSingle = 0;//娴嬭瘯澶嶆牳锛屽瘎瀛樺櫒鍦板潃锛�12===>>0
                                 break;
                         }
-                        if (channel == 1){
-                            TestMast testMast = testMastService.selectOne(new EntityWrapper<TestMast>()
-                                    .eq("channel",(i+1)).eq("status",0));
-                            if(null != testMast){
-                                Date now = new Date();
-                                //http璇锋眰娴嬭瘯
-                                TestDto testDto = new TestDto();
-                                testDto.setLocNo(testMast.getLocNo());
-                                testDto.setBarcode(testMast.getBarcode());
-                                testDto.setUserId(testMast.getUserId());
-                                testDto.setRequestTime(DateUtils.convert(now));
-                                String response = new HttpHandler.Builder()
-                                        .setUri(testUrl)
-                                        .setPath("/testUrlPath")
-                                        .setJson(JSON.toJSONString(testDto))
-                                        .build()
-                                        .doPost();
-                                JSONObject jsonObject = JSON.parseObject(response);
-                                if (jsonObject.getInteger("code").equals(200)) {
-                                    //鏇存柊娴嬭瘯琛ㄧ姸鎬�
-                                    testMast.setStatus(1);
-                                    testMast.setModiTime(now);
-                                    if(!testMastService.update(testMast,new EntityWrapper<TestMast>()
-                                            .eq("channel",1).eq("status",0))){
-                                        throw new CoolException("鏇存柊浜у搧娴嬭瘯鐘舵�佸け璐�");
-                                    }
-//                                    //鏇存柊搴撲綅鐘舵�侊紝閿佸畾pack鐘舵�侊紝绂佹鍏ュ嚭搴撲綔涓�
-//                                    LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no",testMast.getLocNo()));
-//                                    if(null != locMast){
-//                                        locMast.setPackStatus(2);//娴嬭瘯涓�
-//                                        locMast.setModiTime(now);
-//                                        if(!locMastService.update(locMast,new EntityWrapper<LocMast>().eq("loc_no",testMast.getLocNo()))){
-//                                            throw new CoolException("浜у搧寮�濮嬫祴璇曪紝鏇存柊鐩爣搴撲綅閿佸畾鐘舵�佸け璐�");
-//                                        }
-//                                    }
-                                    //澶嶄綅PLC淇″彿
-                                    boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, i*2));
-                                } else {
-                                    log.error("璇锋眰鎺ュ彛澶辫触锛侊紒锛乽rl锛歿},request锛歿},response锛歿}", testUrl+"/rpc/pakin/loc/v1", JSON.toJSONString(testDto), response);
-                                }
 
+                        TestMast testMast = testMastService.selectOne(new EntityWrapper<TestMast>()
+                                .eq("channel",(i+1)).eq("status",olsStatus));//鏌ユ壘鍘熸潵鐨勭姸鎬�
+                        if(null != testMast &&
+                                (devpThread.startSignal[i] == 1 || devpThread.startSignal[i] == 3)){
+                            testMast.setStatus(newStatus);
+                            testMast.setModiTime(new Date());
+                            if(!testMastService.update(testMast,new EntityWrapper<TestMast>()
+                                    .eq("channel",(i+1)).eq("status",olsStatus))){
+                                throw new CoolException("鏇存柊浜у搧娴嬭瘯鐘舵�佸け璐�");
                             }
-                        }
-
+                            //澶嶄綅PLC淇″彿锛屽�熺敤杈撻�佺珯鐐瑰疄浣撶被
+                            StaProtocol staProtocol = new StaProtocol();
+                            staProtocol.setSiteId(i*2);//瀵勫瓨鍣ㄥ湴鍧�
+                            staProtocol.setStaNo(newSingle);//淇敼PLC瀵勫瓨鍣ㄥ湴鍧�鍊�,1==>2鎴�3==>0,5==>6
+                            boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(3, staProtocol));
+                            if(!result){
+                                log.error("鏇存柊娴嬭瘯淇″彿澶辫触===>>[channel:{},locNo:{},barcode:{}]", i+1, testMast.getLocNo(), testMast.getBarcode());
+//                                throw new CoolException("鏇存柊娴嬭瘯淇″彿澶辫触===>>" + i);
+                            } else {
+                                devpThread.startSignal[i] = newSingle;
+                            }
+                        }else if (devpThread.startSignal[i] == 5){
+                            SearchLocParam param = new SearchLocParam();
+                            param.setBarcode(i+1+"");
+                            String response = new HttpHandler.Builder()
+                                    .setUri(wmsUrl)
+                                    .setPath("/mobile/test/suspend/auth")
+                                    .setJson(JSON.toJSONString(param))
+                                    .build()
+                                    .doPost();
+                            JSONObject jsonObject = JSON.parseObject(response);
+                            if (jsonObject.getInteger("code").equals(200)) {
+                                //澶嶄綅PLC淇″彿锛屽�熺敤杈撻�佺珯鐐瑰疄浣撶被
+                                StaProtocol staProtocol = new StaProtocol();
+                                staProtocol.setSiteId(i*2);//瀵勫瓨鍣ㄥ湴鍧�
+                                staProtocol.setStaNo(newSingle);//淇敼PLC瀵勫瓨鍣ㄥ湴鍧�鍊�,5==>6
+                                boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(3, staProtocol));
+                                if(!result){
+                                    log.error("鏆傚仠娴嬭瘯澶辫触===>>["+i+1+"]鍙烽�氶亾");
+//                                throw new CoolException("鏇存柊娴嬭瘯淇″彿澶辫触===>>" + i);
+                                } else {
+                                    devpThread.startSignal[i] = newSingle;
+                                }
+                            } else {
+                                log.error("璇锋眰鎺ュ彛澶辫触锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl+"/mobile/test/suspend/auth", JSON.toJSONString(param), response);
+                            }
+                        }else if (devpThread.startSignal[i] == 7){
+                            LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>()
+                                    .eq("channel",(i+1)));
+                            if (locMast.getLocSts().equals("F")){
+                                locMast.setPackStatus(7); //7.绱ф�ュ嚭搴�
+                                locMastService.update(locMast,new EntityWrapper<LocMast>()
+                                        .eq("channel",(i+1)));
+                            }
+                            //澶嶄綅PLC淇″彿锛屽�熺敤杈撻�佺珯鐐瑰疄浣撶被
+                            StaProtocol staProtocol = new StaProtocol();
+                            staProtocol.setSiteId(i*2);//瀵勫瓨鍣ㄥ湴鍧�
+                            staProtocol.setStaNo(newSingle);//淇敼PLC瀵勫瓨鍣ㄥ湴鍧�鍊�,7==>6
+                            boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(3, staProtocol));
+                            if(!result){
+                                log.error("鏇存柊搴撲綅绱ф�ュ嚭搴撲俊鍙峰け璐�===>>[channel:{},locNo:{},barcode:{}]", i+1, locMast.getLocNo(), locMast.getBarcode());
+//                                throw new CoolException("鏇存柊娴嬭瘯淇″彿澶辫触===>>" + i);
+                            } else {
+                                devpThread.startSignal[i] = newSingle;
+                            }
+                        }else if (devpThread.startSignal[i] == 8){
+                            //澶嶄綅PLC淇″彿锛屽�熺敤杈撻�佺珯鐐瑰疄浣撶被
+                            StaProtocol staProtocol = new StaProtocol();
+                            staProtocol.setSiteId(i*2);//瀵勫瓨鍣ㄥ湴鍧�
+                            staProtocol.setStaNo(newSingle);//淇敼PLC瀵勫瓨鍣ㄥ湴鍧�鍊�,8==>0
+                            boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(3, staProtocol));
+                            if(!result){
+//                                log.error("鏇存柊搴撲綅绱ф�ュ嚭搴撲俊鍙峰け璐�===>>[channel:{},locNo:{},barcode:{}]", i+1, locMast.getLocNo(), locMast.getBarcode());
+//                                throw new CoolException("鏇存柊娴嬭瘯淇″彿澶辫触===>>" + i);
+                            } else {
+                                devpThread.startSignal[i] = newSingle;
+                            }
+                        }else if (devpThread.startSignal[i] == 11){
+                            LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>()
+                                    .eq("channel",(i+1)));
+                            if (locMast.getLocSts().equals("O")){
+                                locMast.setLocSts("X");
+                                locMastService.update(locMast,new EntityWrapper<LocMast>()
+                                        .eq("channel",(i+1)));
+                            }
+                        }else if (devpThread.startSignal[i] == 12){
+                            LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>()
+                                    .eq("channel",(i+1)));
+                            if (locMast.getLocSts().equals("X")){
+                                locMast.setLocSts("O");
+                                locMastService.update(locMast,new EntityWrapper<LocMast>()
+                                        .eq("channel",(i+1)));
+                            }
+                            //澶嶄綅PLC淇″彿锛屽�熺敤杈撻�佺珯鐐瑰疄浣撶被
+                            StaProtocol staProtocol = new StaProtocol();
+                            staProtocol.setSiteId(i*2);//瀵勫瓨鍣ㄥ湴鍧�
+                            staProtocol.setStaNo(newSingle);//淇敼PLC瀵勫瓨鍣ㄥ湴鍧�鍊�,12==>0
+                            boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(3, staProtocol));
+                            if(!result){
+//                                log.error("鏇存柊搴撲綅绱ф�ュ嚭搴撲俊鍙峰け璐�===>>[channel:{},locNo:{},barcode:{}]", i+1, locMast.getLocNo(), locMast.getBarcode());
+//                                throw new CoolException("鏇存柊娴嬭瘯淇″彿澶辫触===>>" + i);
+                            } else {
+                                devpThread.startSignal[i] = newSingle;
+                            }
+                        }else { }
                     }
 
                 }
 
             }
-
         } catch (Exception e) {
             log.error("鍚姩娴嬭瘯  ===>> 鍚姩娴嬭瘯澶辫触", e);
             e.printStackTrace();

--
Gitblit v1.9.1