From 94860d0ab6d9fedf9413b2083eb9af17d8bd7d54 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期三, 28 九月 2022 13:44:11 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java |  319 ++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 220 insertions(+), 99 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 efa2107..258fe03 100644
--- a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -43,10 +43,7 @@
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.interceptor.TransactionAspectSupport;
 
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -117,11 +114,33 @@
                     }
                     String barcode = barcodeThread.getBarcode();
                     if(!Cools.isEmpty(barcode)) {
-                        log.info("{}鍙锋潯鐮佹壂鎻忓櫒妫�娴嬫潯鐮佷俊鎭細{}", inSta.getBarcode(), barcode);
-                        if("NG".endsWith(barcode) || "NoRead".equals(barcode)) {
+//                        log.info("{}鍙锋潯鐮佹壂鎻忓櫒妫�娴嬫潯鐮佷俊鎭細{}", inSta.getBarcode(), barcode);
+                        if("NG".endsWith(barcode) || "NoRead".equals(barcode) || "empty".equals(barcode)) {
+                            staProtocol.setWorkNo((short) 9995);
+                            staProtocol.setStaNo(inSta.getBackSta().shortValue());
+                            devpThread.setPakMk(staProtocol.getSiteId(), false);
+                            MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
+
+                            // led 寮傚父鏄剧ず
+                            LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed());
+                            if (ledThread != null) {
+                                String errorMsg = "鎵爜澶辫触锛岃閲嶈瘯";
+                                MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errorMsg));
+                            }
                             continue;
                         }
                     } else {
+                        staProtocol.setWorkNo((short) 9995);
+                        staProtocol.setStaNo(inSta.getBackSta().shortValue());
+                        devpThread.setPakMk(staProtocol.getSiteId(), false);
+                        MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
+
+                        // led 寮傚父鏄剧ず
+                        LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed());
+                        if (ledThread != null) {
+                            String errorMsg = "鎵爜澶辫触锛岃閲嶈瘯";
+                            MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errorMsg));
+                        }
                         continue;
                     }
 
@@ -238,21 +257,21 @@
                 if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.isInEnable() && staProtocol.isPakMk()){
 
                     // 鑾峰彇鏉$爜鎵弿浠俊鎭�
-                    BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, pickSta.getBarcode());
-                    if (barcodeThread == null) {
-                        continue;
-                    }
-                    String barcode = barcodeThread.getBarcode();
-                    if(!Cools.isEmpty(barcode)) {
-                        log.info("{}鍙锋潯鐮佹壂鎻忓櫒妫�娴嬫潯鐮佷俊鎭細{}", pickSta.getBarcode(), barcode);
-                        if("NG".endsWith(barcode) || "NoRead".equals(barcode)) {
-                            continue;
-                        }
-                    } else {
-                        continue;
-                    }
+//                    BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, pickSta.getBarcode());
+//                    if (barcodeThread == null) {
+//                        continue;
+//                    }
+//                    String barcode = barcodeThread.getBarcode();
+//                    if(!Cools.isEmpty(barcode)) {
+//                        log.info("{}鍙锋潯鐮佹壂鎻忓櫒妫�娴嬫潯鐮佷俊鎭細{}", pickSta.getBarcode(), barcode);
+//                        if("NG".endsWith(barcode) || "NoRead".equals(barcode)) {
+//                            continue;
+//                        }
+//                    } else {
+//                        continue;
+//                    }
 
-                    WrkMast wrkMast = wrkMastMapper.selectPickStep(barcode);
+                    WrkMast wrkMast = wrkMastMapper.selectPickStep(staProtocol.getWorkNo());
                     if (wrkMast == null) {
                         // 鏃犳嫞鏂欐暟鎹�
                         continue;
@@ -295,6 +314,9 @@
                         wrkMast.setModiTime(new Date());
                         if (wrkMastMapper.updateById(wrkMast) == 0) {
                             throw new CoolException("鏇存柊宸ヤ綔妗f暟鎹姸鎬佸け璐�");
+                        }
+                        if (wrkMastMapper.setSteEmpty(wrkMast.getWrkNo()) == 0) {
+//                            throw new CoolException("鏇存柊宸ヤ綔妗f暟鎹姸鎬佸け璐�");
                         }
                         // 淇敼搴撲綅鐘舵�� Q.鎷f枡/鐩樼偣/骞舵澘鍐嶅叆搴�
                         LocMast locMast = locMastService.selectById(wrkMast.getLocNo());
@@ -2222,21 +2244,118 @@
     }
 
 
+    public List<String> crn1DemoLocs = new ArrayList<String>(); public String crn1LastLoc = "";
+    public List<String> crn2DemoLocs = new ArrayList<String>(); public String crn2LastLoc = "";
+    public List<String> crn3DemoLocs = new ArrayList<String>(); public String crn3LastLoc = "";
     public synchronized void demo() {
+        if (Cools.isEmpty(crn1DemoLocs)) {
+            crn1DemoLocs = locMastService.getDemoNextLoc(1);
+        }
+        if (Cools.isEmpty(crn2DemoLocs)) {
+            crn2DemoLocs = locMastService.getDemoNextLoc(2);
+        }
+        if (Cools.isEmpty(crn3DemoLocs)) {
+            crn3DemoLocs = locMastService.getDemoNextLoc(3);
+        }
         for (CrnSlave crn : slaveProperties.getCrn()) {
-            // 鑾峰彇鍫嗗灈鏈轰俊鎭�
-            CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crn.getId());
-            CrnProtocol crnProtocol = crnThread.getCrnProtocol();
-            if (crnProtocol == null) {
+            if (!crn.getDemo()) {
                 continue;
-            }
-            BasCrnp basCrnp = basCrnpService.selectById(crn.getId());
-            if (basCrnp == null) {
-                log.error("{}鍙峰爢鍨涙満灏氭湭鍦ㄦ暟鎹簱杩涜缁存姢锛�", crn.getId());
-                continue;
+            }   // 蹇呴』涓烘紨绀虹姸鎬�
+
+//            CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crn.getId());
+//            CrnProtocol crnProtocol = crnThread.getCrnProtocol();
+//            if (crnProtocol == null) {
+//                continue;
+//            }
+
+            // 鍙湁褰撳爢鍨涙満绌洪棽 骞朵笖 鏃犱换鍔℃椂鎵嶇户缁墽琛�
+//            if (crnProtocol.getStatusType() == CrnStatusType.IDLE && crnProtocol.getTaskNo() == 0 && crnProtocol.getModeType() == CrnModeType.AUTO) {
+
+                String locNo = null;
+                Iterator<String> iterator = crn1DemoLocs.iterator();
+                if (crn.getId() == 1) {
+                    iterator = crn1DemoLocs.iterator();
+                } else if (crn.getId() == 2) {
+                    iterator = crn2DemoLocs.iterator();
+                } else if (crn.getId() == 3) {
+                    iterator = crn3DemoLocs.iterator();
+                }
+                while (iterator.hasNext()) {
+                    String next = iterator.next();
+                    String lastLoc = "";
+                    if (crn.getId() == 1) {
+                        lastLoc = crn1LastLoc;
+                    } else if (crn.getId() == 2) {
+                        lastLoc = crn2LastLoc;
+                    } else if (crn.getId() == 3) {
+                        lastLoc = crn3LastLoc;
+                    }
+                    if (!Cools.isEmpty(lastLoc)) {
+                        if (!lastLoc.substring(2, 7).equals(next.substring(2, 7)) || !Utils.getGroupRow(lastLoc).equals(Utils.getGroupRow(next))) {
+                            locNo = next;
+                            iterator.remove();
+                            break;
+                        } else {
+                            iterator.remove();
+                        }
+                    } else {
+                        locNo = next;
+                        iterator.remove();
+                        break;
+                    }
+
+                }
+                if (!Cools.isEmpty(locNo)) {
+                    if (crn.getId() == 1) {
+                        crn1LastLoc = locNo;
+                    } else if (crn.getId() == 2) {
+                        crn2LastLoc = locNo;
+                    } else if (crn.getId() == 3) {
+                        crn3LastLoc = locNo;
+                    }
+                }
+
+//                log.info("{}鍙峰爢鍨涙満瀵箋}搴撲綅杩涜婕旂ず", crn.getId(), locNo);
+
+            // 鑾峰彇绉诲簱宸ヤ綔妗d俊鎭�
+//                WrkMast wrkMast = wrkMastMapper.selectLocMove(crn.getId());
+//                if (null != wrkMast) { continue; }
+//
+//                LocMast sourceLoc = locMastService.queryDemoSourceLoc(crn.getId());
+//                LocMast loc = locMastService.queryDemoLoc(crn.getId());
+//                if (null == sourceLoc || null == loc) { continue; }
+//
+//                String sourceLocNo = sourceLoc.getLocNo();
+//                String locNo = loc.getLocNo();
+//
+//                // 鑾峰彇宸ヤ綔鍙�
+//                int workNo = commonService.getWorkNo(WorkNoType.PICK.type);
+//                // 淇濆瓨宸ヤ綔妗�
+//                wrkMast = new WrkMast();
+//                wrkMast.setWrkNo(workNo);
+//                wrkMast.setIoTime(new Date());
+//                wrkMast.setWrkSts(11L); // 宸ヤ綔鐘舵�侊細11.鐢熸垚鍑哄簱ID
+//                wrkMast.setIoType(11); // 鍏ュ嚭搴撶姸鎬侊細 11.搴撴牸绉昏浇
+//                wrkMast.setIoPri(13D);
+//                wrkMast.setCrnNo(crn.getId());
+//                wrkMast.setSourceLocNo(sourceLocNo); // 婧愬簱浣�
+//                wrkMast.setLocNo(locNo); // 鐩爣搴撲綅
+//                wrkMast.setFullPlt("N"); // 婊℃澘锛歒
+//                wrkMast.setPicking("N"); // 鎷f枡
+//                wrkMast.setExitMk("N"); // 閫�鍑�
+//                wrkMast.setEmptyMk(sourceLoc.getLocSts().equals("D")?"Y":"N"); // 绌烘澘
+//                wrkMast.setBarcode(sourceLoc.getBarcode()); // 鎵樼洏鐮�
+//                wrkMast.setLinkMis("N");
+//                wrkMast.setAppeTime(new Date());
+//                wrkMast.setModiTime(new Date());
+//                int res = wrkMastMapper.insert(wrkMast);
+//                if (res == 0) {
+//                    throw new CoolException("淇濆瓨宸ヤ綔妗eけ璐�");
+//                }
+
             }
 
-        }
+//        }
     }
 
     /**
@@ -2250,77 +2369,79 @@
             CrnProtocol crnProtocol = crnThread.getCrnProtocol();
             if (crnProtocol == null) { continue; }
 
+            log.info("{}鍙峰爢鍨涙満姝e湪婕旂ず", crn.getId());
+
             // 鍙湁褰撳爢鍨涙満绌洪棽 骞朵笖 鏃犱换鍔℃椂鎵嶇户缁墽琛�
             if (crnProtocol.getStatusType() == CrnStatusType.IDLE && crnProtocol.getTaskNo() == 0 && crnProtocol.getModeType() == CrnModeType.AUTO) {
-                // 鑾峰彇绉诲簱宸ヤ綔妗d俊鎭�
-                WrkMast wrkMast = wrkMastMapper.selectLocMove(crn.getId());
-                if (null != wrkMast) { continue; }
-
-                LocMast sourceLoc = locMastService.queryDemoSourceLoc(crn.getId());
-                LocMast loc = locMastService.queryDemoLoc(crn.getId());
-                if (null == sourceLoc || null == loc) { continue; }
-
-                String sourceLocNo = sourceLoc.getLocNo();
-                String locNo = loc.getLocNo();
-
-                // 鑾峰彇宸ヤ綔鍙�
-                int workNo = commonService.getWorkNo(WorkNoType.PICK.type);
-                // 淇濆瓨宸ヤ綔妗�
-                wrkMast = new WrkMast();
-                wrkMast.setWrkNo(workNo);
-                wrkMast.setIoTime(new Date());
-                wrkMast.setWrkSts(11L); // 宸ヤ綔鐘舵�侊細11.鐢熸垚鍑哄簱ID
-                wrkMast.setIoType(11); // 鍏ュ嚭搴撶姸鎬侊細 11.搴撴牸绉昏浇
-                wrkMast.setIoPri(13D);
-                wrkMast.setCrnNo(crn.getId());
-                wrkMast.setSourceLocNo(sourceLocNo); // 婧愬簱浣�
-                wrkMast.setLocNo(locNo); // 鐩爣搴撲綅
-                wrkMast.setFullPlt("N"); // 婊℃澘锛歒
-                wrkMast.setPicking("N"); // 鎷f枡
-                wrkMast.setExitMk("N"); // 閫�鍑�
-                wrkMast.setEmptyMk(sourceLoc.getLocSts().equals("D")?"Y":"N"); // 绌烘澘
-                wrkMast.setBarcode(sourceLoc.getBarcode()); // 鎵樼洏鐮�
-                wrkMast.setLinkMis("N");
-                wrkMast.setAppeTime(new Date());
-                wrkMast.setModiTime(new Date());
-                int res = wrkMastMapper.insert(wrkMast);
-                if (res == 0) {
-                    throw new CoolException("淇濆瓨宸ヤ綔妗eけ璐�");
-                }
-                // 宸ヤ綔妗f槑缁嗕繚瀛�
-                List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", sourceLocNo));
-                for (LocDetl locDetl : locDetls) {
-                    WrkDetl wrkDetl = new WrkDetl();
-                    wrkDetl.sync(locDetl);
-                    wrkDetl.setWrkNo(workNo);
-                    wrkDetl.setIoTime(new Date());
-                    wrkDetl.setAnfme(locDetl.getAnfme());
-                    wrkDetl.setAppeTime(new Date());
-                    wrkDetl.setModiTime(new Date());
-                    if (!wrkDetlService.insert(wrkDetl)) {
-                        throw new CoolException("淇濆瓨宸ヤ綔妗f槑缁嗗け璐�");
-                    }
-                }
-                // 淇敼婧愬簱浣嶇姸鎬�
-                if (sourceLoc.getLocSts().equals("D") || sourceLoc.getLocSts().equals("F")) {
-                    sourceLoc.setLocSts("R"); // R.鍑哄簱棰勭害
-                    sourceLoc.setModiTime(new Date());
-                    if (!locMastService.updateById(sourceLoc)){
-                        throw new CoolException("鏇存柊婧愬簱浣嶇姸鎬佸け璐�");
-                    }
-                } else {
-                    throw new CoolException("婧愬簱浣嶅嚭搴撳け璐�");
-                }
-                // 淇敼鐩爣搴撲綅鐘舵��
-                if (loc.getLocSts().equals("O")) {
-                    loc.setLocSts("S"); // S.鍏ュ簱棰勭害
-                    loc.setModiTime(new Date());
-                    if (!locMastService.updateById(loc)) {
-                        throw new CoolException("鏇存柊鐩爣搴撲綅鐘舵�佸け璐�");
-                    }
-                } else {
-                    throw new CoolException("绉昏浆澶辫触");
-                }
+//                // 鑾峰彇绉诲簱宸ヤ綔妗d俊鎭�
+//                WrkMast wrkMast = wrkMastMapper.selectLocMove(crn.getId());
+//                if (null != wrkMast) { continue; }
+//
+//                LocMast sourceLoc = locMastService.queryDemoSourceLoc(crn.getId());
+//                LocMast loc = locMastService.queryDemoLoc(crn.getId());
+//                if (null == sourceLoc || null == loc) { continue; }
+//
+//                String sourceLocNo = sourceLoc.getLocNo();
+//                String locNo = loc.getLocNo();
+//
+//                // 鑾峰彇宸ヤ綔鍙�
+//                int workNo = commonService.getWorkNo(WorkNoType.PICK.type);
+//                // 淇濆瓨宸ヤ綔妗�
+//                wrkMast = new WrkMast();
+//                wrkMast.setWrkNo(workNo);
+//                wrkMast.setIoTime(new Date());
+//                wrkMast.setWrkSts(11L); // 宸ヤ綔鐘舵�侊細11.鐢熸垚鍑哄簱ID
+//                wrkMast.setIoType(11); // 鍏ュ嚭搴撶姸鎬侊細 11.搴撴牸绉昏浇
+//                wrkMast.setIoPri(13D);
+//                wrkMast.setCrnNo(crn.getId());
+//                wrkMast.setSourceLocNo(sourceLocNo); // 婧愬簱浣�
+//                wrkMast.setLocNo(locNo); // 鐩爣搴撲綅
+//                wrkMast.setFullPlt("N"); // 婊℃澘锛歒
+//                wrkMast.setPicking("N"); // 鎷f枡
+//                wrkMast.setExitMk("N"); // 閫�鍑�
+//                wrkMast.setEmptyMk(sourceLoc.getLocSts().equals("D")?"Y":"N"); // 绌烘澘
+//                wrkMast.setBarcode(sourceLoc.getBarcode()); // 鎵樼洏鐮�
+//                wrkMast.setLinkMis("N");
+//                wrkMast.setAppeTime(new Date());
+//                wrkMast.setModiTime(new Date());
+//                int res = wrkMastMapper.insert(wrkMast);
+//                if (res == 0) {
+//                    throw new CoolException("淇濆瓨宸ヤ綔妗eけ璐�");
+//                }
+//                // 宸ヤ綔妗f槑缁嗕繚瀛�
+//                List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", sourceLocNo));
+//                for (LocDetl locDetl : locDetls) {
+//                    WrkDetl wrkDetl = new WrkDetl();
+//                    wrkDetl.sync(locDetl);
+//                    wrkDetl.setWrkNo(workNo);
+//                    wrkDetl.setIoTime(new Date());
+//                    wrkDetl.setAnfme(locDetl.getAnfme());
+//                    wrkDetl.setAppeTime(new Date());
+//                    wrkDetl.setModiTime(new Date());
+//                    if (!wrkDetlService.insert(wrkDetl)) {
+//                        throw new CoolException("淇濆瓨宸ヤ綔妗f槑缁嗗け璐�");
+//                    }
+//                }
+//                // 淇敼婧愬簱浣嶇姸鎬�
+//                if (sourceLoc.getLocSts().equals("D") || sourceLoc.getLocSts().equals("F")) {
+//                    sourceLoc.setLocSts("R"); // R.鍑哄簱棰勭害
+//                    sourceLoc.setModiTime(new Date());
+//                    if (!locMastService.updateById(sourceLoc)){
+//                        throw new CoolException("鏇存柊婧愬簱浣嶇姸鎬佸け璐�");
+//                    }
+//                } else {
+//                    throw new CoolException("婧愬簱浣嶅嚭搴撳け璐�");
+//                }
+//                // 淇敼鐩爣搴撲綅鐘舵��
+//                if (loc.getLocSts().equals("O")) {
+//                    loc.setLocSts("S"); // S.鍏ュ簱棰勭害
+//                    loc.setModiTime(new Date());
+//                    if (!locMastService.updateById(loc)) {
+//                        throw new CoolException("鏇存柊鐩爣搴撲綅鐘舵�佸け璐�");
+//                    }
+//                } else {
+//                    throw new CoolException("绉昏浆澶辫触");
+//                }
 
             }
 

--
Gitblit v1.9.1