From 0368c0b26c52b032e3ef86b3fda548d34fbfa4f7 Mon Sep 17 00:00:00 2001
From: ZY <zc857179121@qq.com>
Date: 星期日, 27 四月 2025 14:28:21 +0800
Subject: [PATCH] 1

---
 src/main/java/com/zy/common/service/AgvCommonService.java |  128 +++++++++++++++++++++++++++++++++++++++---
 1 files changed, 119 insertions(+), 9 deletions(-)

diff --git a/src/main/java/com/zy/common/service/AgvCommonService.java b/src/main/java/com/zy/common/service/AgvCommonService.java
index a24d141..1b906b2 100644
--- a/src/main/java/com/zy/common/service/AgvCommonService.java
+++ b/src/main/java/com/zy/common/service/AgvCommonService.java
@@ -134,7 +134,7 @@
 //            } else {
 //                //涓嶅姩杩欎釜閫昏緫
             if (type == 6) {
-                locMast = locUtils.getLocNoRuleByFloor(type, floor);
+                locMast = locUtils.getLocNoRuleByFloor6(type, floor);
             } else {
                 locMast = getLocNoRule(type, floor, isEmpty, isCurrLev);
             }
@@ -159,6 +159,8 @@
             EntityWrapper<AgvLocMast> wrapper = new EntityWrapper<>();
             wrapper.eq("loc_sts", "O").eq("loc_type1", type);
             List<AgvLocMast> agvLocMasts = new ArrayList<>();
+            List<AgvLocMast> all1 = new ArrayList<>();
+            List<AgvLocMast> all2 = new ArrayList<>();
             //涓嶆槸绌烘澘浼樺厛鎵�2灞�
             if (Cools.isEmpty(factory)) {
                 wrapper.eq("floor", floor).orderBy("lev1", true);
@@ -173,19 +175,58 @@
                 }
             }
             int num = 20;
+            int num2 = 20;
             Config config = configService.selectOne(new EntityWrapper<Config>().eq("code", "LOC_3_NUM"));
+            Config config2 = configService.selectOne(new EntityWrapper<Config>().eq("code", "LOC_3_NUM2"));
             if (config != null && !Cools.isEmpty(config.getValue())) {
                 num = Integer.parseInt(config.getValue());
             }
+            if (config2 != null && !Cools.isEmpty(config2.getValue())) {
+                num2 = Integer.parseInt(config2.getValue());
+            }
             agvLocMasts = agvLocMastService.selectList(wrapper);
             for (AgvLocMast agvLocMast : agvLocMasts) {
-
+                if (agvLocMast.getLev1() == 2) {
+                    all2.add(agvLocMast);
+                } else if (agvLocMast.getLev1() == 1) {
+                    all1.add(agvLocMast);
+                }
             }
-
-            for (AgvLocMast agvLocMast : agvLocMasts) {
-                AgvLocMast agvLocMast1 = agvLocMastService.selectOne(new EntityWrapper<AgvLocMast>().eq("loc_no", agvLocMast.getLocNo()));
-                if (agvLocMast1.getLocSts().equals("O")) {
-                    return agvLocMast1;
+            if (factory != null && factory.equalsIgnoreCase("B")) {
+                if (all2.size() > num2) {
+                    for (AgvLocMast agvLocMast : all2) {
+                        AgvLocMast agvLocMast1 = agvLocMastService.selectOne(new EntityWrapper<AgvLocMast>().eq("loc_no", agvLocMast.getLocNo()));
+                        if (agvLocMast1.getLocSts().equals("O")) {
+                            return agvLocMast1;
+                        }
+                    }
+                } else if (all1.size() > num) {
+                    for (AgvLocMast agvLocMast : all1) {
+                        AgvLocMast agvLocMast1 = agvLocMastService.selectOne(new EntityWrapper<AgvLocMast>().eq("loc_no", agvLocMast.getLocNo()));
+                        if (agvLocMast1.getLocSts().equals("O")) {
+                            return agvLocMast1;
+                        }
+                    }
+                } else {
+                    throw new CoolException("鎼滅储搴撲綅鏃讹紝鏈壘鍒板彲鍏ュ簱搴撲綅銆�");
+                }
+            } else {
+                if (all1.size() > num) {
+                    for (AgvLocMast agvLocMast : all1) {
+                        AgvLocMast agvLocMast1 = agvLocMastService.selectOne(new EntityWrapper<AgvLocMast>().eq("loc_no", agvLocMast.getLocNo()));
+                        if (agvLocMast1.getLocSts().equals("O")) {
+                            return agvLocMast1;
+                        }
+                    }
+                } else if (all2.size() > num2) {
+                    for (AgvLocMast agvLocMast : all2) {
+                        AgvLocMast agvLocMast1 = agvLocMastService.selectOne(new EntityWrapper<AgvLocMast>().eq("loc_no", agvLocMast.getLocNo()));
+                        if (agvLocMast1.getLocSts().equals("O")) {
+                            return agvLocMast1;
+                        }
+                    }
+                } else {
+                    throw new CoolException("鎼滅储搴撲綅鏃讹紝鏈壘鍒板彲鍏ュ簱搴撲綅銆�");
                 }
             }
             throw new CoolException("鎼滅储搴撲綅鏃讹紝鏈壘鍒板彲鍏ュ簱搴撲綅銆�");
@@ -246,8 +287,51 @@
         try {
             EntityWrapper<AgvLocMast> wrapper = new EntityWrapper<>();
             wrapper.eq("loc_sts", "O").eq("loc_type1", type);
+            wrapper.eq("floor", floor).eq("lev1", lev1).orderBy("bay1", false);
+            List<AgvLocMast> agvLocMasts = agvLocMastService.selectList(wrapper);
+            for (AgvLocMast agvLocMast : agvLocMasts) {
+                AgvLocMast agvLocMast1 = agvLocMastService.selectOne(new EntityWrapper<AgvLocMast>().eq("loc_no", agvLocMast.getLocNo()));
+                if (agvLocMast1.getLocSts().equals("O")) {
+                    return agvLocMast1;
+                }
+            }
+            throw new CoolException("鎼滅储搴撲綅鏃讹紝鏈壘鍒板彲鍏ュ簱搴撲綅銆�");
+        } catch (Exception e) {
+            throw new CoolException("鎼滅储搴撲綅鏃讹紝鏈壘鍒板彲鍏ュ簱搴撲綅銆�");
+        }
+    }
+
+    /**
+     * 搴撲綅瑙勫垯鏌ユ壘
+     */
+    public AgvLocMast getLocByLocRule2(int type, int floor, int lev1) {
+
+        try {
+            EntityWrapper<AgvLocMast> wrapper = new EntityWrapper<>();
+            wrapper.eq("loc_sts", "O").eq("loc_type1", type);
             wrapper.eq("floor", floor).eq("lev1", lev1);
             List<AgvLocMast> agvLocMasts = agvLocMastService.selectList(wrapper);
+            if (lev1 == 2) {
+                int num = 20;
+                Config config = configService.selectOne(new EntityWrapper<Config>().eq("code", "LOC_3_NUM"));
+                if (config != null && !Cools.isEmpty(config.getValue())) {
+                    num = Integer.parseInt(config.getValue());
+                }
+                int er = agvLocMasts.size();
+                if (er < num) {
+                    throw new CoolException("鎼滅储搴撲綅鏃讹紝鏈壘鍒板彲鍏ュ簱搴撲綅銆�2");
+                }
+            } else if (lev1 == 1) {
+                int num = 8;
+                Config config = configService.selectOne(new EntityWrapper<Config>().eq("code", "LOC_3_NUM2"));
+                if (config != null && !Cools.isEmpty(config.getValue())) {
+                    num = Integer.parseInt(config.getValue());
+                }
+                int er = agvLocMasts.size();
+                if (er < num) {
+                    throw new CoolException("鎼滅储搴撲綅鏃讹紝鏈壘鍒板彲鍏ュ簱搴撲綅銆�1");
+                }
+            }
             for (AgvLocMast agvLocMast : agvLocMasts) {
                 AgvLocMast agvLocMast1 = agvLocMastService.selectOne(new EntityWrapper<AgvLocMast>().eq("loc_no", agvLocMast.getLocNo()));
                 if (agvLocMast1.getLocSts().equals("O")) {
@@ -268,15 +352,16 @@
         try {
             EntityWrapper<AgvLocMast> wrapper = new EntityWrapper<>();
             wrapper.eq("loc_sts", "O").eq("loc_type1", type);
-            wrapper.eq("floor", floor).eq("lev1", lev1);
-
+            wrapper.eq("floor", floor).eq("lev1", lev1).orderBy("bay1", true);
             List<AgvLocMast> agvLocMasts = agvLocMastService.selectList(wrapper);
+
             for (AgvLocMast agvLocMast : agvLocMasts) {
                 AgvLocMast agvLocMast1 = agvLocMastService.selectOne(new EntityWrapper<AgvLocMast>().eq("loc_no", agvLocMast.getLocNo()));
                 if (agvLocMast1.getLocSts().equals("O")) {
                     return agvLocMast1;
                 }
             }
+
             return null;
         } catch (Exception e) {
             throw new CoolException("鎼滅储搴撲綅鏃讹紝鏈壘鍒板彲鍏ュ簱搴撲綅銆�");
@@ -396,6 +481,31 @@
         return null;
     }
 
+    public AgvLocMast getLocNoOnXiSuer20(int type, int floor) {
+        EntityWrapper<AgvLocMast> wrapper = new EntityWrapper<>();
+        wrapper.eq("loc_sts", "O").eq("loc_type1", type);
+        wrapper.eq("floor", floor).eq("lev1", 2);
+        List<AgvLocMast> agvLocMasts = agvLocMastService.selectList(wrapper);
+        if (Cools.isEmpty(agvLocMasts)) {
+            return null;
+        } else {
+            int num = 15;
+            Config config = configService.selectOne(new EntityWrapper<Config>().eq("code", "LOC_6_NUM"));
+            if (config != null && !Cools.isEmpty(config.getValue())) {
+                num = Integer.parseInt(config.getValue());
+            }
+            if (agvLocMasts.size() > num) {
+                for (AgvLocMast agvLocMast : agvLocMasts) {
+                    AgvLocMast agvLocMast1 = agvLocMastService.selectOne(new EntityWrapper<AgvLocMast>().eq("loc_no", agvLocMast.getLocNo()));
+                    if (agvLocMast1.getLocSts().equals("O")) {
+                        return agvLocMast1;
+                    }
+                }
+            }
+        }
+        return null;
+    }
+
 
     //闅忔満鍙栦竴涓揣浣�
     private AgvLocMast getLocNoRule(int type, int floor, boolean isEmpty, boolean isCurrLev) {

--
Gitblit v1.9.1