From 375f337b2a91e59beb0b41dc89353de1e92aa6a1 Mon Sep 17 00:00:00 2001
From: chen.llin <1442464845@qq.comm>
Date: 星期四, 22 一月 2026 18:54:50 +0800
Subject: [PATCH] agv工作档增加 is_deleted

---
 src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java |  116 +++++++++++++++++++++++++++-------------------------------
 1 files changed, 54 insertions(+), 62 deletions(-)

diff --git a/src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java b/src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java
index 6a89950..4e573e0 100644
--- a/src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java
@@ -37,6 +37,8 @@
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicInteger;
 import java.util.stream.Collectors;
 
 /**
@@ -126,16 +128,27 @@
     @Resource
     private AgvProperties agvProperties;
 
+    /**
+     * 绔欑偣杞璁℃暟鍣紝鐢ㄤ簬骞冲潎鍒嗛厤绔欑偣
+     * Key: 绔欑偣缁勬爣璇嗭紙濡� "east" 鎴� "west"锛夛紝Value: 褰撳墠杞绱㈠紩
+     */
+    private final Map<String, AtomicInteger> siteRoundRobinCounters = new ConcurrentHashMap<>();
+
     @Override
     public R inLocCallAgv(CallAgvParam param,Long userId) {
         int type = param.getType();
         String sourceSite = param.getSourceSite();
         String barcode = param.getBarcode();
-        int ioType;
-        LocCache locCache = locCacheService.selectOne(new EntityWrapper<LocCache>().eq("loc_no", sourceSite));
-        if (null == locCache) {
-            throw new CoolException("绔欑偣涓嶅瓨鍦細" + sourceSite);
+        
+        // 妫�鏌ユ墭鐩樼爜鍜屾殏瀛樹綅缂栫爜鏄惁鐩稿悓
+        if (barcode != null && sourceSite != null && barcode.trim().equals(sourceSite.trim())) {
+            throw new CoolException("鎵樼洏鐮佸拰鏆傚瓨浣嶇紪鐮佷笉鑳界浉鍚�");
         }
+        
+        int ioType;
+        // 鏌ヨ婧愮珯鐐癸紙搴撲綅锛変俊鎭紝浣嗕笉妫�鏌ユ槸鍚﹀瓨鍦紝鍏佽涓嬪崟鎴愬姛
+        // 绔欑偣涓嶅瓨鍦ㄧ殑妫�鏌ュ皢鍦ㄥ畾鏃朵换鍔★紙AgvHandler.callAgv锛変腑杩涜
+        LocCache locCache = locCacheService.selectOne(new EntityWrapper<LocCache>().eq("loc_no", sourceSite));
         switch (type) {
             case 1:
                 // 鍒ゆ柇鏈夋病鏈夌粍鎵�
@@ -143,10 +156,13 @@
                 if (count == 0) {
                     throw new CoolException("鏉$爜鏈粍鎵橈細" + barcode);
                 }
-                ioType = 101;
+                ioType = 1; // AGV瀹瑰櫒鍏ュ簱锛堝疄鎵樺叆搴擄級
 
-                locCache.setLocSts(LocStsType.LOC_STS_TYPE_R.type);
-                locCacheService.updateById(locCache);
+                // 濡傛灉搴撲綅瀛樺湪锛屾洿鏂扮姸鎬佷负鍏ュ簱棰勭害锛涗笉瀛樺湪鍒欒烦杩囷紝鐢卞畾鏃朵换鍔″鐞�
+                if (locCache != null) {
+                    locCache.setLocSts(LocStsType.LOC_STS_TYPE_S.type); // S.鍏ュ簱棰勭害
+                    locCacheService.updateById(locCache);
+                }
                 break;
             case 2:
                 // 鍒ゆ柇鏄嫞閫夊洖搴撴墭鐩�
@@ -157,10 +173,13 @@
                 if (wrkMast.getIoType() != 103 && wrkMast.getIoType() != 107) {
                     throw new CoolException("鏉$爜涓嶉渶瑕佸洖搴擄細" + barcode);
                 }
-                ioType = wrkMast.getIoType() - 50;
+                ioType = wrkMast.getIoType() - 50; // 103->53(鎷f枡鍏ュ簱), 107->57(鐩樼偣鍏ュ簱)
 
-                locCache.setLocSts(LocStsType.LOC_STS_TYPE_R.type);
-                locCacheService.updateById(locCache);
+                // 濡傛灉搴撲綅瀛樺湪锛屾洿鏂扮姸鎬佷负鍏ュ簱棰勭害锛涗笉瀛樺湪鍒欒烦杩囷紝鐢卞畾鏃朵换鍔″鐞�
+                if (locCache != null) {
+                    locCache.setLocSts(LocStsType.LOC_STS_TYPE_S.type); // S.鍏ュ簱棰勭害锛堝鍣ㄥ洖搴撴槸鍏ュ簱鎿嶄綔锛�
+                    locCacheService.updateById(locCache);
+                }
                 break;
             case 3:
                 // 鍒ゆ柇鏄惁涓虹┖鎵樺叆搴擄細妫�鏌ユ潯鐮佸湪wms涓笉瀛樺湪锛岀‘璁や负绌烘墭鐩�
@@ -195,71 +214,41 @@
                 throw new CoolException("鍏ュ簱绫诲瀷閿欒,type锛�" + type);
         }
         // 鏉$爜瀛樺湪agv浠诲姟
-        int count = taskService.selectCount(new EntityWrapper<Task>().eq("barcode", barcode));
+        int count = taskService.selectCount(new EntityWrapper<Task>().eq("barcode", barcode).eq("is_deleted", 0));
         if (count > 0) {
             throw new CoolException(barcode+ "锛氭潯鐮佸瓨鍦╝gv鎼繍浠诲姟!");
         }
 
-        // 鏍规嵁whs_type閫夋嫨绔欑偣鍜屾満鍣ㄤ汉缁�
-        Long whsType = locCache.getWhsType();
-        List<String> targetStations;
+        // 鏍规嵁whs_type纭畾鏈哄櫒浜虹粍锛堢珯鐐瑰垎閰嶅畬鍏ㄧ敱瀹氭椂浠诲姟澶勭悊锛�
+        // 濡傛灉搴撲綅涓嶅瓨鍦紝浣跨敤榛樿閫昏緫锛堟牴鎹畉ype鍒ゆ柇锛�
+        Long whsType = locCache != null ? locCache.getWhsType() : null;
         String robotGroup;
         
         if (whsType != null && whsType.equals(agvProperties.getWhsTypeMapping().getInboundArea())) {
-            // whs_type = 1: 鍏ュ簱鍖猴紝浣跨敤涓滀晶绔欑偣鍜孏roup-001
-            targetStations = agvProperties.getEastStations();
+            // whs_type = 1: 鍏ュ簱鍖猴紝浣跨敤Group-001
             robotGroup = agvProperties.getRobotGroupEast();
-            log.info("搴撲綅whs_type={}锛屼娇鐢ㄥ叆搴撳尯閰嶇疆锛堜笢渚х珯鐐瑰拰Group-001锛�", whsType);
+            log.info("搴撲綅whs_type={}锛屼娇鐢ㄥ叆搴撳尯閰嶇疆锛坽}锛�", whsType, robotGroup);
         } else if (whsType != null && whsType.equals(agvProperties.getWhsTypeMapping().getCacheArea())) {
-            // whs_type = 2: 缂撳瓨鍖猴紝浣跨敤瑗夸晶绔欑偣鍜孏roup-002
-            targetStations = agvProperties.getWestStations();
+            // whs_type = 2: 缂撳瓨鍖猴紝浣跨敤Group-002
             robotGroup = agvProperties.getRobotGroupWest();
-            log.info("搴撲綅whs_type={}锛屼娇鐢ㄧ紦瀛樺尯閰嶇疆锛堣タ渚х珯鐐瑰拰Group-002锛�", whsType);
+            log.info("搴撲綅whs_type={}锛屼娇鐢ㄧ紦瀛樺尯閰嶇疆锛坽}锛�", whsType, robotGroup);
         } else {
             // whs_type涓虹┖鎴栧叾浠栧�硷紝鏍规嵁type鍒ゆ柇锛堝吋瀹规棫閫昏緫锛�
+            // 濡傛灉搴撲綅涓嶅瓨鍦紝涔熶娇鐢ㄦ閫昏緫
             if (type == 1) {
-                targetStations = agvProperties.getEastStations();
                 robotGroup = agvProperties.getRobotGroupEast();
             } else {
-                targetStations = agvProperties.getWestStations();
                 robotGroup = agvProperties.getRobotGroupWest();
             }
-            log.warn("搴撲綅whs_type={}鏈厤缃垨涓嶅湪鏄犲皠鑼冨洿鍐咃紝浣跨敤type={}鐨勯粯璁ら�昏緫", whsType, type);
+            if (locCache == null) {
+                log.warn("婧愮珯鐐癸紙搴撲綅锛墈}涓嶅瓨鍦紝浣跨敤type={}鐨勯粯璁ら�昏緫锛屾満鍣ㄤ汉缁勶細{}锛岀珯鐐瑰垎閰嶅皢鍦ㄥ畾鏃朵换鍔′腑杩涜", sourceSite, type, robotGroup);
+            } else {
+                log.warn("搴撲綅whs_type={}鏈厤缃垨涓嶅湪鏄犲皠鑼冨洿鍐咃紝浣跨敤type={}鐨勯粯璁ら�昏緫锛屾満鍣ㄤ汉缁勶細{}", whsType, type, robotGroup);
+            }
         }
         
-        // 灏嗙珯鐐瑰瓧绗︿覆鍒楄〃杞崲涓烘暣鏁板垪琛�
-        List<Integer> siteIntList = targetStations.stream()
-                .map(Integer::parseInt)
-                .collect(Collectors.toList());
-        
-        // 鍒ゆ柇鑳藉叆绔欑偣
-        List<Integer> sites = basDevpMapper.selectList(
-                new EntityWrapper<BasDevp>()
-                        .eq("canining", "Y")
-                        .in("dev_no", siteIntList)
-        ).stream().map(BasDevp::getDevNo).collect(Collectors.toList());
-
-        if (sites.isEmpty()) {
-            throw new CoolException("娌℃湁鑳藉叆绔欑偣,whs_type锛�" + whsType + ",type锛�" + type);
-        }
-
-        // 鑾峰彇娌℃湁鍑哄簱浠诲姟鐨勭珯鐐�
-        List<Integer> canInSites = basDevpMapper.getCanInSites(sites);
-        if (canInSites.isEmpty()) {
-            throw new CoolException("璇风瓑寰呭嚭搴撳畬鎴�,type:" + type);
-        }
-
-        // 瀵绘壘鍏ュ簱浠诲姟鏈�灏戠殑绔欑偣
-        List<BasDevp> devList = basDevpMapper.selectList(new EntityWrapper<BasDevp>().in("dev_no", canInSites));
-        // 鍏ュ簱浠诲姟鏁版帓搴�
-        devList.sort(Comparator.comparing(BasDevp::getInQty));
-
-        // 鍙栧叆搴撲换鍔℃渶灏戠珯鐐�
-        BasDevp basDevp = devList.get(0);
-        int endSite = basDevp.getDevNo();
-
-        // 鍏ュ簱鏆傚瓨+1
-        basDevpMapper.incrementInQty(endSite);
+        // 绔欑偣鍒嗛厤瀹屽叏鐢卞畾鏃朵换鍔″鐞嗭紝姝ゅ涓嶅垎閰嶇珯鐐癸紝鍙垱寤轰换鍔�
+        log.info("鍒涘缓AGV浠诲姟锛岀珯鐐瑰垎閰嶅皢鍦ㄥ畾鏃朵换鍔′腑澶勭悊锛屾満鍣ㄤ汉缁勶細{}", robotGroup);
 
 
         // 鑾峰彇宸ヤ綔鍙�
@@ -273,14 +262,14 @@
                 .setIoType(ioType) // 鍏ュ嚭搴撶姸鎬侊細 1.鍏ュ簱
                 .setTaskType("agv")
                 .setIoPri(10D)
-                .setStaNo(String.valueOf(endSite))
+                .setStaNo(null) // 绔欑偣鍒嗛厤瀹屽叏鐢卞畾鏃朵换鍔″鐞�
                 .setSourceStaNo(sourceSite) // 璁剧疆婧愮珯鐐�
                 .setInvWh(robotGroup) // 鏍规嵁whs_type璁剧疆鏈哄櫒浜虹粍
-                .setFullPlt(ioType != 10 ? "N" : "Y")// 婊℃澘锛歒
+                .setFullPlt(ioType == 10 ? "N" : "Y")// 绌烘墭鍏ュ簱(ioType=10)璁剧疆涓篘锛屽叾浠栧叆搴撹缃负Y锛堟弧鏉匡級
                 .setPicking("N") // 鎷f枡
                 .setExitMk("N")// 閫�鍑�
-                .setSourceLocNo(locCache.getLocNo()) // 璁剧疆婧愬簱浣嶇紪鍙凤紝鐢ㄤ簬AGV fromBin
-                .setEmptyMk(ioType == 10 ? "Y" : "N")// 绌烘澘
+                .setSourceLocNo(locCache != null ? locCache.getLocNo() : sourceSite) // 璁剧疆婧愬簱浣嶇紪鍙凤紝鐢ㄤ簬AGV fromBin锛屽鏋滃簱浣嶄笉瀛樺湪鍒欎娇鐢╯ourceSite
+                .setEmptyMk(ioType == 10 ? "Y" : "N")// 绌烘墭鍏ュ簱(ioType=10)璁剧疆涓篩锛屽叾浠栬缃负N
                 .setBarcode(barcode)// 鎵樼洏鐮�
                 .setLinkMis("N")
                 .setAppeTime(now)
@@ -289,8 +278,11 @@
             throw new CoolException("淇濆瓨宸ヤ綔妗eけ璐�");
         }
 
-        // 鏇存柊鏆傚瓨浣嶇姸鎬佷负 R.鍑哄簱棰勭害
-        basStationMapper.updateLocStsBatch( Collections.singletonList(String.valueOf(sourceSite)), "R");
+        // 濡傛灉搴撲綅瀛樺湪锛屾牴鎹甶oType鏇存柊鏆傚瓨浣嶇姸鎬侊細鍏ュ簱浠诲姟璁剧疆涓篠锛堝叆搴撻绾︼級锛屽嚭搴撲换鍔¤缃负R锛堝嚭搴撻绾︼級
+        if (locCache != null) {
+            String locSts = (ioType < 100) ? "S" : "R"; // 鍏ュ簱浠诲姟锛坕oType < 100锛夎缃负S锛屽嚭搴撲换鍔¤缃负R
+            basStationMapper.updateLocStsBatch( Collections.singletonList(String.valueOf(sourceSite)), locSts);
+        }
         return R.ok("agv浠诲姟鐢熸垚鎴愬姛!");
 
     }

--
Gitblit v1.9.1