From 6017ff0fac73ee771282f8c4711f20ec9ca67bd7 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期二, 07 十一月 2023 08:54:13 +0800
Subject: [PATCH] #Redis Key Type

---
 src/main/java/com/zy/asrs/utils/Utils.java |  321 +++++++++++++++++++++++++++++++++--------------------
 1 files changed, 200 insertions(+), 121 deletions(-)

diff --git a/src/main/java/com/zy/asrs/utils/Utils.java b/src/main/java/com/zy/asrs/utils/Utils.java
index 72821fa..afd653a 100644
--- a/src/main/java/com/zy/asrs/utils/Utils.java
+++ b/src/main/java/com/zy/asrs/utils/Utils.java
@@ -1,13 +1,17 @@
 package com.zy.asrs.utils;
 
 import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.mapper.EntityWrapper;
 import com.core.common.Arith;
 import com.core.common.Cools;
 import com.core.common.SpringUtils;
 import com.zy.asrs.entity.BasShuttle;
 import com.zy.asrs.entity.LocMast;
+import com.zy.asrs.entity.WrkMast;
+import com.zy.asrs.mapper.WrkMastMapper;
 import com.zy.asrs.service.BasShuttleService;
 import com.zy.asrs.service.LocMastService;
+import com.zy.asrs.service.WrkMastService;
 import com.zy.asrs.service.impl.MainServiceImpl;
 import com.zy.common.model.NavigateNode;
 import com.zy.common.model.enums.NavigationMapType;
@@ -16,6 +20,7 @@
 import com.zy.common.utils.NavigatePositionConvert;
 import com.zy.common.utils.NavigateUtils;
 import com.zy.common.utils.ShuttleDispatchUtils;
+import com.zy.core.DevpThread;
 import com.zy.core.Slave;
 import com.zy.core.cache.MessageQueue;
 import com.zy.core.cache.SlaveConnection;
@@ -28,15 +33,13 @@
 import com.zy.core.model.command.ShuttleCommand;
 import com.zy.core.model.protocol.NyShuttleProtocol;
 import com.zy.core.model.protocol.ShuttleProtocol;
+import com.zy.core.model.protocol.StaProtocol;
 import com.zy.core.properties.SlaveProperties;
 import com.zy.core.thread.NyShuttleThread;
 import com.zy.core.thread.ShuttleThread;
 
 import java.text.DecimalFormat;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
+import java.util.*;
 
 /**
  * Created by vincent on 2020/8/27
@@ -44,10 +47,28 @@
 public class Utils {
 
     public static final List<Integer> FIRST_GROUP_ROW_LIST = new ArrayList<Integer>() {{
-        add(1);add(2);add(3);add(4);
+        add(1);
     }};
     public static final List<Integer> SECOND_GROUP_ROW_LIST = new ArrayList<Integer>() {{
-        add(5);add(6);add(7);add(8);add(9);add(10);add(11);
+        add(3);add(4);
+    }};
+    public static final List<Integer> THIRD_GROUP_ROW_LIST = new ArrayList<Integer>() {{
+        add(6);add(7);
+    }};
+    public static final List<Integer> FOURTH_GROUP_ROW_LIST = new ArrayList<Integer>() {{
+        add(8);
+    }};
+    public static final List<Integer> FIFTH_GROUP_ROW_LIST = new ArrayList<Integer>() {{
+        add(10);add(11);
+    }};
+    public static final List<Integer> SIXTH_GROUP_ROW_LIST = new ArrayList<Integer>() {{
+        add(13);add(14);add(15);add(16);
+    }};
+    public static final List<Integer> SEVENTH_GROUP_ROW_LIST = new ArrayList<Integer>() {{
+        add(13);add(14);
+    }};
+    public static final List<Integer> EIGHTH_GROUP_ROW_LIST = new ArrayList<Integer>() {{
+        add(16);
     }};
 
     private static final DecimalFormat fmt = new DecimalFormat("##0.00");
@@ -272,124 +293,80 @@
         return zerofill(String.valueOf(row), 2) + zerofill(String.valueOf(bay), 3) + zerofill(String.valueOf(lev), 2);
     }
 
-
-    /**
-     * 褰撴绱㈠埌鍙屾繁搴撲綅鐨勬祬搴撲綅鏃讹紝濡傛灉娣卞簱浣嶆棤璐э紝鍒欐斁鍏ュ搴旂殑娣卞簱浣�
-     */
-    public static void toDeepIfEmptyByShallow(String shallowLoc) {
-        int row = getRow(shallowLoc);
-        int remainder = (int) Arith.remainder(row, 4);
-        int targetRow = 0;
-        if (remainder == 2) {
-            targetRow = row - 1;
-        } else if (remainder == 3) {
-            targetRow = row + 1;
-        } else {
-            throw new RuntimeException(shallowLoc + "涓嶆槸娴呭簱浣嶏紝绯荤粺绻佸繖");
-        }
-        String targetLoc = zerofill(String.valueOf(targetRow), 2) + shallowLoc.substring(2);
-
-    }
-
     public static String getLocNo(Number row, Number bay, Number lev) {
         return zerofill(String.valueOf(row), 2) + zerofill(String.valueOf(bay), 3) + zerofill(String.valueOf(lev), 2);
     }
 
-    //鍑哄叆搴撶珯鐐瑰彿杞崲瀵瑰簲妤煎眰
-    public static Integer outInStaNoToLev(Integer distSta) {
-        Integer distLev = 1;//鐩爣妤煎眰
-        switch (distSta) {
-            case 102:
-                distLev = 2;//杈撻�佺嚎妤煎眰
-            case 105:
-                distLev = 1;//涓�妤�
-            case 106:
-                distLev = 3;//浜屾ゼ
-            case 107:
-                distLev = 4;//涓夋ゼ
-            case 108:
-                distLev = 5;//鍥涙ゼ
-        }
-        return distLev;
-    }
-
-    //妤煎眰杞崲瀵瑰簲鍑哄叆搴撶珯鐐瑰彿
-    public static Integer levToOutInStaNo(Integer lev) {
-        Integer staNo = null;//绔欑偣鍙�
-        switch (lev) {
-            case 1:
-                staNo = 105;
-                break;
-            case 2://杈撻�佺嚎灞�
-                staNo = 105;
-                break;
-            case 3:
-                staNo = 106;
-                break;
-            case 4:
-                staNo = 107;
-                break;
-            case 5:
-                staNo = 108;
-                break;
-        }
-        return staNo;
-    }
-
-    //鎻愬崌鏈轰綅缃弽棣堣浆鎹㈠嚭鍏ュ簱绔欑偣搴撲綅鍙�
-    public static String liftArrivalToOutInStaLocNo(Short liftArrival) {
-        String locNo = null;
-        switch (liftArrival) {
-            case 1:
-                locNo = "1800201";
-                break;
-            case 4:
-                locNo = "1800202";
-                break;
-            case 8:
-                locNo = "1800203";
-                break;
-            case 16:
-                locNo = "1800204";
-                break;
-        }
-        return locNo;
-    }
-
     public static void main(String[] args) {
-        System.out.println(JSON.toJSONString(getGroupOutsideLoc("0200101")));
+        System.out.println(JSON.toJSONString(getGroupLoc("1606101")));
     }
 
-    // 澶栦晶鏂瑰悜鐨勮揣浣�  浼樺厛鍏ュ簱鏂瑰悜/浼樺厛鍑哄簱鏂瑰悜 ===>> 鍙嶄箣
-    public static List<String> getGroupOutsideLoc(String locNo){
+    /**
+     * 鑾峰彇搴撲綅缁�
+     * @param locNo 搴撲綅鍙�
+     */
+    public static List<String> getGroupLoc(String locNo){
         int row = getRow(locNo);
-        List<String> result = new ArrayList<>();
+        int bay = getBay(locNo);
+        if (FIRST_GROUP_ROW_LIST.contains(row)) {
+            List<String> result = new ArrayList<>();
+            for (Integer row0 : FIRST_GROUP_ROW_LIST) {
+                result.add(zerofill(String.valueOf(row0), 2) + locNo.substring(2));
+            }
+            return result;
+        }
         if (SECOND_GROUP_ROW_LIST.contains(row)) {
-            for (Integer integer : SECOND_GROUP_ROW_LIST) {
-                if (integer < row) {
-                    result.add(zerofill(String.valueOf(integer), 2) + locNo.substring(2));
-                } else {
-                    break;
-                }
+            List<String> result = new ArrayList<>();
+            for (Integer row0 : SECOND_GROUP_ROW_LIST) {
+                result.add(zerofill(String.valueOf(row0), 2) + locNo.substring(2));
             }
-        } else if (FIRST_GROUP_ROW_LIST.contains(row)) {
-            List<Integer> clone = Arrays.asList(new Integer[FIRST_GROUP_ROW_LIST.size()]);
-            Collections.copy(clone, FIRST_GROUP_ROW_LIST);
-            Collections.reverse(clone);
-            for (Integer integer : clone) {
-                if (integer > row) {
-                    result.add(zerofill(String.valueOf(integer), 2) + locNo.substring(2));
-                } else {
-                    break;
-                }
-            }
-        } else {
-//            throw new RuntimeException("搴撲綅瑙f瀽寮傚父");
+            return result;
         }
-        if (!Cools.isEmpty(result)) {
+        if (THIRD_GROUP_ROW_LIST.contains(row)) {
+            List<String> result = new ArrayList<>();
+            for (Integer row0 : THIRD_GROUP_ROW_LIST) {
+                result.add(zerofill(String.valueOf(row0), 2) + locNo.substring(2));
+            }
             Collections.reverse(result);
+            return result;
         }
-        return result;
+        if (FOURTH_GROUP_ROW_LIST.contains(row)) {
+            List<String> result = new ArrayList<>();
+            for (Integer row0 : FOURTH_GROUP_ROW_LIST) {
+                result.add(zerofill(String.valueOf(row0), 2) + locNo.substring(2));
+            }
+            return result;
+        }
+        if (FIFTH_GROUP_ROW_LIST.contains(row)) {
+            List<String> result = new ArrayList<>();
+            for (Integer row0 : FIFTH_GROUP_ROW_LIST) {
+                result.add(zerofill(String.valueOf(row0), 2) + locNo.substring(2));
+            }
+            return result;
+        }
+        if (SIXTH_GROUP_ROW_LIST.contains(row) && (bay >= 59 && bay <= 61)) {
+            List<String> result = new ArrayList<>();
+            for (Integer row0 : SIXTH_GROUP_ROW_LIST) {
+                result.add(zerofill(String.valueOf(row0), 2) + locNo.substring(2));
+            }
+            Collections.reverse(result);
+            return result;
+        }
+        if (SEVENTH_GROUP_ROW_LIST.contains(row) && bay < 59) {
+            List<String> result = new ArrayList<>();
+            for (Integer row0 : SEVENTH_GROUP_ROW_LIST) {
+                result.add(zerofill(String.valueOf(row0), 2) + locNo.substring(2));
+            }
+            return result;
+        }
+        if (EIGHTH_GROUP_ROW_LIST.contains(row) && bay < 59) {
+            List<String> result = new ArrayList<>();
+            for (Integer row0 : EIGHTH_GROUP_ROW_LIST) {
+                result.add(zerofill(String.valueOf(row0), 2) + locNo.substring(2));
+            }
+            return result;
+        }
+        throw new RuntimeException("搴撲綅瑙f瀽寮傚父");
     }
 
     //鑾峰彇闄ょ櫧鍚嶅崟澶栫殑鎸囧畾妤煎眰鍏ㄩ儴绌挎杞y鍧愭爣鐐�
@@ -428,6 +405,9 @@
                 continue;//妤煎眰涓嶅悓
             }
 
+            if (shuttleProtocol.getCurrentLocNo() == null) {
+                continue;
+            }
             int[] xyPosition = NavigatePositionConvert.positionToXY(shuttleProtocol.getCurrentLocNo());//閫氳繃搴撲綅鍙疯幏鍙杧y鍧愭爣
             list.add(xyPosition);
         }
@@ -437,7 +417,7 @@
     //鎼滅储涓�鏉℃病鏈夊皬杞︾殑绌哄贩閬擄紝骞惰皟搴﹀皬杞�
     public static boolean searchEmptyGroupToMoveShuttle(int z, Integer currentShuttleId, NyShuttleThread shuttleThread) {
         LocMastService locMastService = SpringUtils.getBean(LocMastService.class);
-        MainServiceImpl mainServiceImpl = SpringUtils.getBean(MainServiceImpl.class);
+        WrkMastService wrkMastService = SpringUtils.getBean(WrkMastService.class);
         CommonService commonService = SpringUtils.getBean(CommonService.class);
         ShuttleDispatchUtils shuttleDispatchUtils = SpringUtils.getBean(ShuttleDispatchUtils.class);
 
@@ -455,6 +435,8 @@
         int distY = -1;
         int distX = -1;
         int distZ = -1;
+        //鑾峰彇閬胯搴撲綅
+        String distLocNo = null;
         for (int y = 20; y <= 56; y++) {
             boolean searchFlag = true;
             for (int x = 10; x <= 11; x++) {
@@ -469,19 +451,28 @@
                 distY = y;
                 distX = 11;
                 distZ = z;
+
+                //鑾峰彇閬胯搴撲綅
+                String locNo = NavigatePositionConvert.xyzToLocNo(distX, distY, distZ);
+                LocMast distLocMast = locMastService.queryByLoc(locNo);
+                if (distLocMast == null) {
+                    continue;
+                }
+
+                //鍒ゆ柇璇ュ簱浣嶆槸鍚﹀瓨鍦ㄥ伐浣滄。
+                EntityWrapper<WrkMast> wrapper = new EntityWrapper<>();
+                wrapper.eq("loc_no", locNo);
+                WrkMast wrkMast = wrkMastService.selectOne(wrapper);
+                if (wrkMast != null) {
+                    continue;//瀛樺湪宸ヤ綔妗h烦杩囪搴撲綅
+                }
+
+                distLocNo = locNo;
                 break;
             }
         }
 
-        if (distY != -1) {
-
-            //鑾峰彇閬胯搴撲綅
-            String distLocNo = NavigatePositionConvert.xyzToLocNo(distX, distY, distZ);
-            LocMast distLocMast = locMastService.queryByLoc(distLocNo);
-            if (distLocMast == null) {
-                return false;
-            }
-
+        if (distLocNo != null) {
             //璋冨害灏忚溅鍒伴伩璁╀綅缃�
             return shuttleDispatchUtils.dispatchShuttle(commonService.getWorkNo(7), distLocNo, shuttleProtocol.getShuttleNo().intValue());
         }
@@ -514,4 +505,92 @@
         return false;//鎸囧畾妤煎眰娌℃湁绌挎杞�
     }
 
+    //妫�娴嬪簱浣嶇粍鏄惁瀛樺湪灏忚溅锛屽瓨鍦ㄨ繑鍥炲皬杞﹀彿銆�
+    public static Integer checkGroupLocHasShuttle(List<String> groupLoc) {
+        if (groupLoc == null) {
+            return null;
+        }
+
+        if (groupLoc.isEmpty()) {
+            return null;
+        }
+
+        SlaveProperties slaveProperties = SpringUtils.getBean(SlaveProperties.class);
+        if (slaveProperties == null) {
+            return null;
+        }
+
+        for (String loc : groupLoc) {
+            for (ShuttleSlave slave : slaveProperties.getShuttle()) {
+                NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, slave.getId());
+                if (shuttleThread == null) {
+                    continue;
+                }
+
+                NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
+                if (shuttleProtocol == null) {
+                    continue;
+                }
+
+                if (shuttleProtocol.getCurrentLocNo() == null) {
+                    continue;
+                }
+
+                if (shuttleProtocol.getCurrentLocNo().equals(loc)) {
+                    //瀛樺湪灏忚溅
+                    return slave.getId();
+                }
+            }
+        }
+
+        return null;
+    }
+
+    //閫氳繃鎻愬崌鏈哄彿鍜屾ゼ灞傝幏鍙栧嚭鍏ュ簱妯″紡
+    public static Integer getOutInModelByLift(Integer liftNo, Integer lev) {
+        ArrayList<Integer> lev1 = new ArrayList<Integer>() {{
+            add(100);add(103);
+            add(105);
+        }};
+        ArrayList<Integer> lev2 = new ArrayList<Integer>() {{
+            add(200);add(203);
+            add(205);
+        }};
+        ArrayList<Integer> lev3 = new ArrayList<Integer>() {{
+            add(341);add(346);
+        }};
+
+        Integer staNo = null;
+        if (lev <= 4) {
+            staNo = lev1.get(liftNo - 1);
+        } else if (lev >= 5 && lev <= 7) {
+            staNo = lev2.get(liftNo - 1);
+        } else if ((lev >=8 && lev <= 10) && liftNo != 1) {
+            staNo = lev3.get(liftNo - 2);
+        }
+
+        if (staNo != null) {
+            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, 1);
+            StaProtocol staProtocol = devpThread.getStation().get(staNo);
+            if (staProtocol == null) {
+                return null;
+            }
+
+            if (staNo == 100 || staNo == 200) {//1鍙锋彁鍗囨満100绔欏拰200绔欓粯璁ゅ叏鏄嚭搴撴ā寮�
+                return 2;//鍑哄簱妯″紡
+            }
+
+            if (staNo == 341) {
+                return 1;//341绔欓粯璁ゅ彧鑳藉叆搴撴ā寮�
+            }
+
+            if (staProtocol.getOutInModel() == null) {
+                return null;//娌℃湁鍑哄叆搴撲俊鍙�
+            }
+
+            return staProtocol.getOutInModel().intValue();
+        }
+        return null;
+    }
+
 }

--
Gitblit v1.9.1