From 23ce02b630df91f468290c638aa5811fd04e8c9d Mon Sep 17 00:00:00 2001
From: 1 <1@123>
Date: 星期二, 10 三月 2026 14:54:39 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/devlop-phyz' into devlop-phyz

---
 rsf-server/src/main/java/com/vincent/rsf/server/manager/schedules/TaskCacheLocSchedules.java |  181 ++++++++++++++++++++++++++++-----------------
 1 files changed, 112 insertions(+), 69 deletions(-)

diff --git a/rsf-server/src/main/java/com/vincent/rsf/server/manager/schedules/TaskCacheLocSchedules.java b/rsf-server/src/main/java/com/vincent/rsf/server/manager/schedules/TaskCacheLocSchedules.java
index 08ee052..b9eb2df 100644
--- a/rsf-server/src/main/java/com/vincent/rsf/server/manager/schedules/TaskCacheLocSchedules.java
+++ b/rsf-server/src/main/java/com/vincent/rsf/server/manager/schedules/TaskCacheLocSchedules.java
@@ -23,8 +23,10 @@
 import org.springframework.transaction.annotation.Transactional;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
 
 /**
  * @author Munch D. Luffy
@@ -80,7 +82,8 @@
             for (String c : split) {
                 WarehouseAreas byId = warehouseAreasService.getById(Integer.parseInt(c));
                 if (!Cools.isEmpty(byId)) {
-                    Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getAreaId, byId.getId()).eq(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_F.type),false);
+                    Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getAreaId, byId.getId()).eq(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_F.type)
+                            .last("LIMIT 1"));
                     if (!Objects.isNull(loc)) {
                         curLoc = loc.getCode();
                         break;
@@ -95,7 +98,8 @@
             for (String c : split) {
                 WarehouseAreas byId = warehouseAreasService.getById(Integer.parseInt(c));
                 if (!Cools.isEmpty(byId)) {
-                    Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getAreaId, byId.getId()).eq(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type),false);
+                    Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getAreaId, byId.getId()).eq(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type)
+                            .last("LIMIT 1"));
                     if (!Objects.isNull(loc)) {
                         deepLoc = loc.getCode();
                         break;
@@ -143,83 +147,122 @@
         if (Cools.isEmpty(autoRunContainerEndYz)) {
             return;
         }
+
+        String autoRunContainerEndYzCount = configService.getVal("AUTO_RUN_CHECK_OUT_YZ_COUNT", String.class);
+        if (Cools.isEmpty(autoRunContainerEndYzCount)) {
+            return;
+        }
+        int autoOutCount = Integer.parseInt(autoRunContainerEndYzCount);
+        if (autoOutCount <= 0) {
+            return;
+        }
+        List<Long> souLocArea = new ArrayList<>();
+        List<Long> endLocArea = new ArrayList<>();
         String curLoc = null;
         String deepLoc = null;
         try{
-            String[] split = autoRunAreaStartYz.split(";");
-            for (String c : split) {
+            for (String c :  autoRunAreaStartYz.split(";")) {
                 WarehouseAreas byId = warehouseAreasService.getById(Integer.parseInt(c));
                 if (!Cools.isEmpty(byId)) {
-                    Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getAreaId, byId.getId()).eq(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_D.type),false);
-                    if (!Objects.isNull(loc)) {
-                        curLoc = loc.getCode();
-                        break;
-                    }
+                    souLocArea.add(byId.getId());
                 }
+            }
+            if (souLocArea.isEmpty()) {
+                return;
             }
         } catch (Exception e){
             log.error("閰嶇疆鍙傛暟AUTO_RUN_AREA_START_YZ瑙f瀽澶辫触锛岃妫�鏌ワ紒锛侊紒");
-        }
-        //瀹瑰櫒闆嗗悎
-        //姣忎釜瀹瑰櫒瀵瑰簲鐨勫鍣ㄧ爜绫诲瀷
-        //
-
-        try{
-//            String[] containerList = autoRunContainerEndYz.split(";");
-//            ArrayList<Long> CONTAINER_IDS = new ArrayList<>();
-//            for (String c : containerList) {
-//                CONTAINER_IDS.add(Long.parseLong(c));
-//            }
-            BasContainer basContainer = basContainerService.getOne(new LambdaQueryWrapper<BasContainer>()
-                    .in(BasContainer::getContainerType, 1, false));
-//            if (Cools.isEmpty(basContainer)){
-//                throw new CoolException("鏈煡璇㈠埌鐩稿叧瀹瑰櫒瑙勫垯");
-//            }
-//
-//
-            List<Long> areaList = new ArrayList<>();//鎵�鏈夊簱鍖�
-//            List<Long> areaList1 = new ArrayList<>();//鎵�鏈夊鍣ㄧ被鍨�
-//            List<Long> areaList2 = new ArrayList<>();//鎵�鏈夊簱鍖�
-//            List<Long> areaList3 = new ArrayList<>();//鎵�鏈夊簱鍖�
-
-            boolean sign = true;
-//            //瀹瑰櫒绫诲瀷鏌ヨ  璧风偣
-            String[] split = autoRunAreaEndYz.split(";");
-            for (String c : split) {
-                WarehouseAreas byId = warehouseAreasService.getById(Integer.parseInt(c));
-                if (!Cools.isEmpty(byId)) {
-                    if (sign){
-                        areaList.add(byId.getId());
-                        Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getAreaId, byId.getId()).eq(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type),false);
-                        if (!Objects.isNull(loc)) {
-                            deepLoc = loc.getCode();
-                            sign = false;
-                        }
-                    }
-                }
-            }
-
-
-            String barcodeType = "barcode REGEXP '"+basContainer.getCodeType()+"'";
-            List<Loc> loc1 = locService.list(new LambdaQueryWrapper<Loc>()
-                    .apply(barcodeType)
-                    .eq(Loc::getDeleted, 0)
-                    .eq(Loc::getStatus, 1)
-                    .eq(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_D.type)
-                    .in(Loc::getAreaId, areaList)
-                    .orderByDesc(Loc::getId));
-
-
-        } catch (Exception e){
-            log.error("閰嶇疆鍙傛暟AUTO_RUN_AREA_START_YZ瑙f瀽澶辫触锛岃妫�鏌ワ紒锛侊紒");
-        }
-
-        if (curLoc == null ||  deepLoc == null) {
             return;
         }
-        LocToTaskParams params = new LocToTaskParams();
-        params.setOrgLoc(curLoc).setTarLoc(deepLoc);
-        //鐢熸垚绉诲簱浣嶄换鍔�
-        locItemService.genMoveTask(params, 9999L);
+        try{
+            for (String c : autoRunAreaEndYz.split(";")) {
+                WarehouseAreas byId = warehouseAreasService.getById(Integer.parseInt(c));
+                if (!Cools.isEmpty(byId)) {
+                    endLocArea.add(byId.getId());
+                }
+            }
+            if (endLocArea.isEmpty()) {
+                return;
+            }
+        } catch (Exception e){
+            log.error("閰嶇疆鍙傛暟AUTO_RUN_OUT_END_YZ瑙f瀽澶辫触锛岃妫�鏌ワ紒锛侊紒");
+            return;
+        }
+
+        ConcurrentHashMap<String,Integer> CONTAINER_IDS = new ConcurrentHashMap<>();//闇�瑕佽ˉ鍏呯殑瀹瑰櫒鏌ヨ鏉′欢
+//        ArrayList<String> CONTAINER_IDS = new ArrayList<>();//闇�瑕佽ˉ鍏呯殑瀹瑰櫒鏌ヨ鏉′欢
+        try{
+            String[] containerList = autoRunContainerEndYz.split(";");
+            for (String c : containerList) {//瀹瑰櫒闆嗗悎
+                long parseLong = Long.parseLong(c);
+                BasContainer basContainer = basContainerService.getOne(new LambdaQueryWrapper<BasContainer>()
+                        .eq(BasContainer::getContainerType, parseLong).last("LIMIT 1"));
+                if (Cools.isEmpty(basContainer)){
+                    throw new CoolException("鏈煡璇㈠埌鐩稿叧瀹瑰櫒瑙勫垯锛屽鍣ㄧ紪鐮丆ONTAINER_ID锛�"+c);
+                }
+                //鏌ヨ缁堢偣鏄惁闇�瑕佽ˉ鍏呮瀹瑰櫒
+                String barcodeType = "barcode REGEXP '"+basContainer.getCodeType()+"'";
+                int count = locService.count(new LambdaQueryWrapper<Loc>()
+                        .apply(barcodeType)
+                        .in(Loc::getUseStatus, new ArrayList<>(Arrays.asList(
+                                LocStsType.LOC_STS_TYPE_D.type,
+                                LocStsType.LOC_STS_TYPE_S.type
+                        )))
+                        .in(Loc::getAreaId, endLocArea)
+                        .eq(Loc::getDeleted, 0)
+                        .eq(Loc::getStatus, 1)
+                        .orderByDesc(Loc::getId));
+                if (!Cools.isEmpty(count) && count<autoOutCount){
+                    CONTAINER_IDS.put(barcodeType, autoOutCount-count);
+                }
+            }
+        } catch (Exception e){
+            log.error("閰嶇疆鍙傛暟AUTO_RUN_AREA_START_YZ瑙f瀽澶辫触锛岃妫�鏌ワ紒锛侊紒");
+            return;
+        }
+        List<LocToTaskParams> locMove = new  ArrayList<>();
+        List<String> locList = new  ArrayList<>();
+        for (ConcurrentHashMap.Entry<String,Integer> entry : CONTAINER_IDS.entrySet()) {
+            String barcodeType = entry.getKey();// 鑾峰彇String閿�
+            Integer entryValue = entry.getValue();// 鑾峰彇鏁伴噺
+            List<Loc> souLocList = locService.list(new LambdaQueryWrapper<Loc>()
+                    .apply(barcodeType)
+                    .eq(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_D.type)
+                    .in(Loc::getAreaId, souLocArea)
+                    .eq(Loc::getDeleted, 0)
+                    .eq(Loc::getStatus, 1)
+                    .orderByDesc(Loc::getId));
+            for (Loc souLoc : souLocList) {
+                if (entryValue<=0){
+                    break;
+                }
+                entryValue--;
+
+                Loc endLoc = locService.getOne(new LambdaQueryWrapper<Loc>()
+                        .eq(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type)
+                        .in(Loc::getAreaId, endLocArea)
+                        .notIn(!locList.isEmpty(), Loc::getCode, locList)
+                        .eq(Loc::getDeleted, 0)
+                        .eq(Loc::getStatus, 1)
+                        .orderByDesc(Loc::getId).last("LIMIT 1"));
+                if (Cools.isEmpty(souLoc)){
+                    continue;
+                }
+                locMove.add(new LocToTaskParams().setOrgLoc(souLoc.getCode()).setTarLoc(endLoc.getCode()));
+                locList.add(endLoc.getCode());
+            }
+        }
+
+        if (locMove.isEmpty()) {
+            return;
+        }
+        for (LocToTaskParams locToTaskParams : locMove) {
+            //鐢熸垚绉诲簱浣嶄换鍔�
+            try{
+                locItemService.genMoveTask(locToTaskParams, 9999L);
+            }catch (Exception e){
+                log.error("鐢熸垚绉诲簱浣嶄换鍔″け璐ワ紝璇锋鏌ワ紒锛侊紒"+locToTaskParams.toString());
+            }
+        }
     }
 }

--
Gitblit v1.9.1