From ebdfec3e9db0977bccca0527be7d2226fbbd0229 Mon Sep 17 00:00:00 2001
From: Junjie <540245094@qq.com>
Date: 星期三, 12 六月 2024 11:02:16 +0800
Subject: [PATCH] #

---
 zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/service/impl/MainServiceImpl.java |   87 +++++++++++++++++++++++++++++++++++--------
 1 files changed, 70 insertions(+), 17 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..6773aea 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
@@ -9,6 +9,7 @@
 import com.zy.asrs.common.utils.HttpHandler;
 import com.zy.asrs.framework.common.Cools;
 import com.zy.asrs.framework.common.SnowflakeIdWorker;
+import com.zy.asrs.framework.exception.CoolException;
 import com.zy.asrs.wcs.core.domain.dto.MatDto;
 import com.zy.asrs.wcs.core.domain.dto.RedisMapDto;
 import com.zy.asrs.wcs.core.domain.dto.StaDto;
@@ -17,6 +18,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 +80,8 @@
     private RedisUtil redisUtil;
     @Autowired
     private BasConveyorService basConveyorService;
+    @Autowired
+    private BasConveyorStaService basConveyorStaService;
     @Autowired
     private BasLedService basLedService;
 
@@ -177,7 +181,7 @@
 
                         //鑾峰彇鍏ュ簱浠诲姟绫诲瀷
                         TaskCtg taskCtg = taskCtgService.getOne(new LambdaQueryWrapper<TaskCtg>()
-                                .eq(TaskCtg::getFlag, "IN")
+                                .eq(TaskCtg::getFlag, String.valueOf(TaskCtgType.IN))
                                 .eq(TaskCtg::getStatus, 1));
 
                         // 鍒ゆ柇閲嶅宸ヤ綔妗�
@@ -266,6 +270,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 +381,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 +412,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();
@@ -423,14 +442,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 +464,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 +477,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 +514,25 @@
         }
     }
 
+    // 瑙f瀽灏忚溅绉诲姩宸ヤ綔妗�
+    public synchronized void analyzeMoveTask() {
+        for (Task task : taskService.selectWaitAnalyzeMoveTask()) {
+            // 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 +547,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 +691,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