From 6e695903059e82c1c376bf2926ffb8b209c0dc3e Mon Sep 17 00:00:00 2001
From: 1 <1@123>
Date: 星期三, 11 三月 2026 15:45:57 +0800
Subject: [PATCH] lsh#

---
 rsf-server/src/main/java/com/vincent/rsf/server/manager/schedules/TaskCacheLocSchedules.java |  217 +++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 205 insertions(+), 12 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 012888b..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
@@ -2,7 +2,15 @@
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.vincent.rsf.framework.common.Cools;
+import com.vincent.rsf.framework.exception.CoolException;
+import com.vincent.rsf.server.manager.controller.params.LocToTaskParams;
+import com.vincent.rsf.server.manager.entity.BasContainer;
+import com.vincent.rsf.server.manager.entity.Loc;
+import com.vincent.rsf.server.manager.entity.WarehouseAreas;
+import com.vincent.rsf.server.manager.enums.LocStsType;
 import com.vincent.rsf.server.manager.service.*;
+import com.vincent.rsf.server.manager.service.impl.BasContainerServiceImpl;
+import com.vincent.rsf.server.manager.service.impl.WarehouseAreasServiceImpl;
 import com.vincent.rsf.server.system.constant.GlobalConfigCode;
 import com.vincent.rsf.server.system.entity.Config;
 import com.vincent.rsf.server.system.service.ConfigService;
@@ -15,7 +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
@@ -32,6 +43,14 @@
     private TaskService taskService;
     @Autowired
     private ConfigService configService;
+    @Autowired
+    private WarehouseAreasServiceImpl warehouseAreasService;
+    @Autowired
+    private LocService locService;
+    @Autowired
+    private LocItemService locItemService;
+    @Autowired
+    private BasContainerServiceImpl basContainerService;
 
     /**
      * @author Munch D. Luffy
@@ -42,23 +61,62 @@
     @Scheduled(cron = "0/15 * * * * ?")
     @Transactional(rollbackFor = Exception.class)
     public void startCacheInLocStock() throws Exception {
-        Config config = configService.getOne(new LambdaQueryWrapper<Config>().eq(Config::getFlag, GlobalConfigCode.AUTO_RUN_CHECK_ORDERS_YZ));
+        Config config = configService.getOne(new LambdaQueryWrapper<Config>().eq(Config::getFlag, GlobalConfigCode.AUTO_RUN_CHECK_IN_YZ));
         if (!Boolean.parseBoolean(config.getVal())) {
             return;
         }
 
-        String autoRunArea = configService.getVal("AUTO_RUN_AREA", String.class);
-        if (Cools.isEmpty(autoRunArea)) {
+        String autoRunAreaStartYz = configService.getVal("AUTO_RUN_IN_START_YZ", String.class);
+        if (Cools.isEmpty(autoRunAreaStartYz)) {
             return;
         }
-        List<Integer> array = new ArrayList<>();
-        for (char c : autoRunArea.toCharArray()) {
-            switch (c) {
-                case '1':
-                default:
-                    break;
-            }
+
+        String autoRunAreaEndYz = configService.getVal("AUTO_RUN_IN_END_YZ", String.class);
+        if (Cools.isEmpty(autoRunAreaEndYz)) {
+            return;
         }
+        String curLoc = null;
+        String deepLoc = null;
+        try{
+            String[] split = autoRunAreaStartYz.split(";");
+            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)
+                            .last("LIMIT 1"));
+                    if (!Objects.isNull(loc)) {
+                        curLoc = loc.getCode();
+                        break;
+                    }
+                }
+            }
+        } catch (Exception e){
+            log.error("閰嶇疆鍙傛暟AUTO_RUN_AREA_START_YZ瑙f瀽澶辫触锛岃妫�鏌ワ紒锛侊紒");
+        }
+        try{
+            String[] split = autoRunAreaEndYz.split(";");
+            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)
+                            .last("LIMIT 1"));
+                    if (!Objects.isNull(loc)) {
+                        deepLoc = loc.getCode();
+                        break;
+                    }
+                }
+            }
+        } 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);
     }
 
     /**
@@ -69,7 +127,142 @@
      */
     @Scheduled(cron = "0/5 * * * * ?  ")
     @Transactional(rollbackFor = Exception.class)
-    public void complateOutStock() throws Exception {
-        System.out.println("缂撳瓨鍖哄煙鑷姩鐢熸垚绌鸿揣鏋跺嚭搴撲换鍔�");
+    public void startCacheOutLocStock() throws Exception {
+        Config config = configService.getOne(new LambdaQueryWrapper<Config>().eq(Config::getFlag, GlobalConfigCode.AUTO_RUN_CHECK_OUT_YZ));
+        if (!Boolean.parseBoolean(config.getVal())) {
+            return;
+        }
+
+        String autoRunAreaStartYz = configService.getVal("AUTO_RUN_OUT_START_YZ", String.class);
+        if (Cools.isEmpty(autoRunAreaStartYz)) {
+            return;
+        }
+
+        String autoRunAreaEndYz = configService.getVal("AUTO_RUN_OUT_END_YZ", String.class);
+        if (Cools.isEmpty(autoRunAreaEndYz)) {
+            return;
+        }
+
+        String autoRunContainerEndYz = configService.getVal("AUTO_RUN_OUT_CONTAINER_YZ", String.class);
+        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{
+            for (String c :  autoRunAreaStartYz.split(";")) {
+                WarehouseAreas byId = warehouseAreasService.getById(Integer.parseInt(c));
+                if (!Cools.isEmpty(byId)) {
+                    souLocArea.add(byId.getId());
+                }
+            }
+            if (souLocArea.isEmpty()) {
+                return;
+            }
+        } catch (Exception e){
+            log.error("閰嶇疆鍙傛暟AUTO_RUN_AREA_START_YZ瑙f瀽澶辫触锛岃妫�鏌ワ紒锛侊紒");
+            return;
+        }
+        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