From 95d473bc8c09ef41e1455f93dec49c5ee6ac548f Mon Sep 17 00:00:00 2001
From: Junjie <540245094@qq.com>
Date: 星期二, 18 六月 2024 08:23:38 +0800
Subject: [PATCH] #

---
 zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/service/impl/MainServiceImpl.java |  149 +++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 117 insertions(+), 32 deletions(-)

diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/service/impl/MainServiceImpl.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/service/impl/MainServiceImpl.java
index db25c37..8f68095 100644
--- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/service/impl/MainServiceImpl.java
+++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/service/impl/MainServiceImpl.java
@@ -17,6 +17,7 @@
 import com.zy.asrs.wcs.core.model.MapNode;
 import com.zy.asrs.wcs.core.model.enums.DeviceCtgType;
 import com.zy.asrs.wcs.core.model.enums.MotionStsType;
+import com.zy.asrs.wcs.core.model.enums.TaskCtgType;
 import com.zy.asrs.wcs.core.model.enums.TaskStsType;
 import com.zy.asrs.wcs.core.service.*;
 import com.zy.asrs.wcs.core.utils.RedisUtil;
@@ -78,6 +79,10 @@
     private RedisUtil redisUtil;
     @Autowired
     private BasConveyorService basConveyorService;
+    @Autowired
+    private BasConveyorStaService basConveyorStaService;
+    @Autowired
+    private BasConveyorPathService basConveyorPathService;
     @Autowired
     private BasLedService basLedService;
 
@@ -177,7 +182,7 @@
 
                         //鑾峰彇鍏ュ簱浠诲姟绫诲瀷
                         TaskCtg taskCtg = taskCtgService.getOne(new LambdaQueryWrapper<TaskCtg>()
-                                .eq(TaskCtg::getFlag, "IN")
+                                .eq(TaskCtg::getFlag, String.valueOf(TaskCtgType.IN))
                                 .eq(TaskCtg::getStatus, 1));
 
                         // 鍒ゆ柇閲嶅宸ヤ綔妗�
@@ -216,10 +221,19 @@
                             Integer code = jsonObject.getInteger("code");
                             if (code.equals(200)) {
                                 StartupDto dto = jsonObject.getObject("data", StartupDto.class);
-                                devpThread.writeWorkSta(staProtocol.getSiteId(), dto.getWorkNo().shortValue(), dto.getStaNo().shortValue());
-                                devpThread.setPakMk(staProtocol.getSiteId(), false);
 
-                            } else if (code == 500) {
+                                //鑾峰彇杈撻�佽矾寰�
+                                BasConveyorPath conveyorPath = basConveyorPathService.getOne(new LambdaQueryWrapper<BasConveyorPath>()
+                                        .eq(BasConveyorPath::getTypeNo, TaskCtgType.IN.val())
+                                        .eq(BasConveyorPath::getDeviceId, devp.getId())
+                                        .eq(BasConveyorPath::getStnNo, staProtocol.getSiteId()));
+                                if (conveyorPath == null) {
+                                    News.error("杈撻�佽矾寰勪笉瀛樺湪");
+                                }else {
+                                    devpThread.writeWorkSta(staProtocol.getSiteId(), dto.getWorkNo().shortValue(), conveyorPath.getDeviceStn().shortValue());
+                                    devpThread.setPakMk(staProtocol.getSiteId(), false);
+                                }
+                            }else {
                                 if (ledThread != null) {
                                     String errorMsg = jsonObject.getString("msg");
                                     if (!Cools.isEmpty(errorMsg)) {
@@ -228,18 +242,6 @@
                                     }
                                 }
                                 News.error("璇锋眰鎺ュ彛澶辫触锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + "/rpc/pakin/loc/v2", JSON.toJSONString(param), response);
-                            } else if (code == 700) {
-//                            staProtocol.setWorkNo((short) 32002);
-//                            staProtocol.setRollback102(1);//102绔欏洖閫�淇″彿
-//                            devpThread.setPakMk(staProtocol.getSiteId(), false);
-//                            MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(5, staProtocol));
-
-                                // led 寮傚父鏄剧ず
-                                if (ledThread != null) {
-                                    String errorMsg = barcode + "鎵樼洏璇嗗埆寮傚父锛岃鍏堣繘琛岀粍鎵橈紒";
-                                    ledThread.error(errorMsg);
-                                    ledThread.setLedMk(false);
-                                }
                             }
                         } catch (Exception e) {
                             e.printStackTrace();
@@ -266,6 +268,11 @@
             for (Dict dict : dicts) {
                 String[] split = dict.getFlag().split("-");
                 int lev = Integer.parseInt(split[1]);
+
+                Object data = redisUtil.get(DeviceRedisConstant.MAP + lev);
+                if (data != null) {
+                    continue;
+                }
 
                 TreeMap<Integer, List<JSONObject>> rows = new TreeMap<>();
                 //鎺掑簭Row
@@ -372,6 +379,19 @@
                     list.add(mapNode.clone());
                 }
 
+                //鏈�鍚庝竴娆℃娴嬪湴鍥捐妭鐐规槸鍚﹀畬鏁达紝鍦板浘鐭╅樀row鍧囪杈惧埌鏈�闀縭ow
+                for (ArrayList<MapNode> list : lists) {
+                    int len = (row + 2);//row+2鏄洜涓哄ご鑺傜偣鍜屽熬鑺傜偣瀛樺湪浜轰负娣诲姞鐨�-1鑺傜偣
+                    if (list.size() == len) {
+                        continue;
+                    }
+                    //鑺傜偣闀垮害涓嶆弧瓒筹紝杩涜琛ヨ冻
+                    for (int i = list.size(); i < len; i++) {
+                        list.add(mapNode.clone());
+                    }
+                }
+
+
                 ArrayList<MapNode> headNodes = new ArrayList<>();
                 ArrayList<MapNode> footerNodes = new ArrayList<>();
                 for (int i = 0; i < row+2; i++) {
@@ -390,11 +410,8 @@
                 map.setUpdateTime(now);
                 map.setLev(lev);
 
-                Object data = redisUtil.get(DeviceRedisConstant.MAP + lev);
-                if (data == null) {
-                    //灏嗗湴鍥炬暟鎹瓨鍏edis
-                    redisUtil.set(DeviceRedisConstant.MAP + lev, JSON.toJSONString(map));
-                }
+                //灏嗗湴鍥炬暟鎹瓨鍏edis
+                redisUtil.set(DeviceRedisConstant.MAP + lev, JSON.toJSONString(map));
             }
         } catch (Exception e) {
             e.printStackTrace();
@@ -404,6 +421,23 @@
     // 瑙f瀽鍏ュ簱宸ヤ綔妗�
     public synchronized void analyzeInBoundTask() {
         for (Task task : taskService.selectWaitAnalyzeInBoundTask()) {
+            if (Cools.isEmpty(task.getShuttleNo())) {
+                //鍒嗛厤灏忚溅
+                //鎼滅储绌洪棽杞�
+                ShuttleThread shuttleThread = shuttleDispatcher.searchIdleShuttle(task);
+                if (shuttleThread == null) {
+                    News.info("{}浠诲姟鏈壘鍒扮┖闂茬┛姊溅", task.getTaskNo());
+                    continue;
+                }
+
+                task.setShuttleNo(Integer.valueOf(shuttleThread.getDevice().getDeviceNo()));//淇濆瓨绌挎杞﹀彿
+                task.setUpdateTime(new Date());
+                if (!taskService.updateById(task)) {
+                    News.info("{}浠诲姟鏇存柊绌挎杞﹀彿澶辫触", task.getTaskNo());
+                }
+                continue;
+            }
+
             // generate motion list
             List<Motion> motionList = analyzeService.generateMotion(task);
             if (motionList.isEmpty()) {
@@ -423,14 +457,19 @@
     /**
      * 鍑哄簱 ====>> 鍚屼竴鏃堕棿涓�鍙扮┛姊溅鍙兘鏈変竴涓嚭搴撲换鍔�
      */
-    public synchronized void generateOutboundWrkMast() {
+    public synchronized void analyzeOutBoundTask() {
         List<Task> tasks = taskService.selectPakOut();
         if (tasks.isEmpty()) {
             return;
         }
 
         for (Task task : tasks) {
-            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Conveyor, 1);
+            BasConveyorSta originStaObj = basConveyorStaService.selectBySiteNo(task.getOriginSite());//鑾峰彇婧愮珯
+            if (originStaObj == null) {
+                continue;
+            }
+
+            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Conveyor, originStaObj.getConveyorId().intValue());
             StaProtocol staProtocol = devpThread.getStation().get(Integer.parseInt(task.getOriginSite()));//婧愮珯
             StaProtocol staProtocol1 = devpThread.getStation().get(Integer.parseInt(task.getDestSite()));//鐩爣绔�
             if (staProtocol == null || staProtocol1 == null) {
@@ -440,15 +479,8 @@
                 staProtocol1 = staProtocol1.clone();
             }
 
-//            // 鏌ヨ绔欑偣璇︾粏淇℃伅
-//            BasDevp staDetl = basDevpService.selectById(outSta.getStaNo());
-//            if (staDetl == null) {
-//                log.error("鍑哄簱 ===>> 绔欑偣鍦ㄦ暟鎹簱涓嶅瓨鍦�, 绔欑偣缂栧彿={}", outSta.getStaNo());
-//                continue;
-//            }
             // 鍒ゆ柇鍫嗗灈鏈哄嚭搴撶珯鐘舵��
             if (staProtocol.isAutoing() && !staProtocol.isLoading() && staProtocol.getWorkNo() == 0 && staProtocol.isOutEnable()) {
-
                 if (!(staProtocol1.isAutoing() && !staProtocol1.isLoading() && staProtocol1.getWorkNo() == 0 && staProtocol1.isOutEnable())) {
                     continue;
                 }
@@ -460,6 +492,23 @@
 //                    News.info("{}浠诲姟锛屾祬搴撲綅瀛樺湪璐х墿锛岀郴缁熺瓑寰呬腑", wrkMast.getWrkNo());
 //                    continue;//娴呭簱浣嶅瓨鍦ㄦ湭鎵ц浠诲姟
 //                }
+
+                if (Cools.isEmpty(task.getShuttleNo())) {
+                    //鍒嗛厤灏忚溅
+                    //鎼滅储绌洪棽杞�
+                    ShuttleThread shuttleThread = shuttleDispatcher.searchIdleShuttle(task);
+                    if (shuttleThread == null) {
+                        News.info("{}浠诲姟鏈壘鍒扮┖闂茬┛姊溅", task.getTaskNo());
+                        continue;
+                    }
+
+                    task.setShuttleNo(Integer.valueOf(shuttleThread.getDevice().getDeviceNo()));//淇濆瓨绌挎杞﹀彿
+                    task.setUpdateTime(new Date());
+                    if (!taskService.updateById(task)) {
+                        News.info("{}浠诲姟鏇存柊绌挎杞﹀彿澶辫触", task.getTaskNo());
+                    }
+                    continue;
+                }
 
                 // generate motion list
                 List<Motion> motionList = analyzeService.generateMotion(task);
@@ -480,6 +529,42 @@
         }
     }
 
+    // 瑙f瀽灏忚溅绉诲姩宸ヤ綔妗�
+    public synchronized void analyzeMoveTask() {
+        for (Task task : taskService.selectWaitAnalyzeMoveTask()) {
+            if (Cools.isEmpty(task.getShuttleNo())) {
+                //鍒嗛厤灏忚溅
+                //鎼滅储绌洪棽杞�
+                ShuttleThread shuttleThread = shuttleDispatcher.searchIdleShuttle(task);
+                if (shuttleThread == null) {
+                    News.info("{}浠诲姟鏈壘鍒扮┖闂茬┛姊溅", task.getTaskNo());
+                    continue;
+                }
+
+                task.setShuttleNo(Integer.valueOf(shuttleThread.getDevice().getDeviceNo()));//淇濆瓨绌挎杞﹀彿
+                task.setUpdateTime(new Date());
+                if (!taskService.updateById(task)) {
+                    News.info("{}浠诲姟鏇存柊绌挎杞﹀彿澶辫触", task.getTaskNo());
+                }
+                continue;
+            }
+
+            // generate motion list
+            List<Motion> motionList = analyzeService.generateMotion(task);
+            if (motionList.isEmpty()) {
+                continue;
+            }
+            motionService.batchInsert(motionList, task.getUuid(), Integer.valueOf(task.getTaskNo()));
+
+            // 鏇存柊宸ヤ綔涓绘。
+            task.setTaskSts(TaskStsType.ANALYZE_MOVE.sts); // 宸ヤ綔鐘舵��
+            task.setUpdateTime(new Date());
+            if (!taskService.updateById(task)) {
+                News.error("鏇存柊宸ヤ綔妗eけ璐ワ紒锛侊紒 [宸ヤ綔鍙凤細{}]", task.getTaskNo());
+            }
+        }
+    }
+
     /**
      * 鍥涘悜绌挎杞︾數閲忔娴� ===>> 鍙戣捣鍏呯數
      */
@@ -494,7 +579,7 @@
 
         //鑾峰彇鍏呯數浠诲姟绫诲瀷
         TaskCtg taskCtg = taskCtgService.getOne(new LambdaQueryWrapper<TaskCtg>()
-                .eq(TaskCtg::getFlag, "CHARGE")
+                .eq(TaskCtg::getFlag, String.valueOf(TaskCtgType.CHARGE))
                 .eq(TaskCtg::getStatus, 1));
         if (taskCtg == null) {
             return;
@@ -638,7 +723,7 @@
 
         //鑾峰彇杩佺Щ浠诲姟绫诲瀷
         TaskCtg taskCtg = taskCtgService.getOne(new LambdaQueryWrapper<TaskCtg>()
-                .eq(TaskCtg::getFlag, "MOVE")
+                .eq(TaskCtg::getFlag, String.valueOf(TaskCtgType.MOVE))
                 .eq(TaskCtg::getStatus, 1));
         if (taskCtg == null) {
             return;

--
Gitblit v1.9.1