From 691bee4229856f8bf81c2720092ecee1c9f21509 Mon Sep 17 00:00:00 2001
From: zhou zhou <3272660260@qq.com>
Date: 星期四, 09 四月 2026 19:18:12 +0800
Subject: [PATCH] #getter$摘出entity

---
 rsf-server/src/main/java/com/vincent/rsf/server/manager/utils/LocManageUtil.java |   54 ++++++++++++++++++++++++++++++------------------------
 1 files changed, 30 insertions(+), 24 deletions(-)

diff --git a/rsf-server/src/main/java/com/vincent/rsf/server/manager/utils/LocManageUtil.java b/rsf-server/src/main/java/com/vincent/rsf/server/manager/utils/LocManageUtil.java
index d999743..f5d8e89 100644
--- a/rsf-server/src/main/java/com/vincent/rsf/server/manager/utils/LocManageUtil.java
+++ b/rsf-server/src/main/java/com/vincent/rsf/server/manager/utils/LocManageUtil.java
@@ -5,6 +5,7 @@
 import com.vincent.rsf.framework.common.SpringUtils;
 import com.vincent.rsf.framework.exception.CoolException;
 import com.vincent.rsf.server.api.utils.LocUtils;
+import com.vincent.rsf.server.common.redis.RedisKeys;
 import com.vincent.rsf.server.manager.controller.dto.ExistDto;
 import com.vincent.rsf.server.manager.controller.dto.OrderOutItemDto;
 import com.vincent.rsf.server.manager.controller.params.WaveToLocParams;
@@ -12,14 +13,20 @@
 import com.vincent.rsf.server.manager.enums.TaskType;
 import com.vincent.rsf.server.manager.enums.WaveRuleType;
 import com.vincent.rsf.server.manager.service.*;
+import com.vincent.rsf.server.manager.service.impl.WmsRedisLuaService;
 import com.vincent.rsf.server.manager.enums.LocStsType;
 import org.apache.commons.lang3.StringUtils;
 
 import java.math.BigDecimal;
+import java.time.Duration;
 import java.util.*;
 import java.util.stream.Collectors;
 
 public class LocManageUtil {
+
+    private static final int TARGET_LOC_QUERY_LIMIT = 10;
+    private static final String TARGET_LOC_LOCK_KEY_PREFIX = "wms:loc:claim:";
+    private static final Duration TARGET_LOC_LOCK_TTL = Duration.ofMinutes(1);
 
     /**
      * @param
@@ -39,7 +46,7 @@
         Long locType = containerType;
         //TODO 搴撲綅绛栫暐鍚庣画鎺掓湡
         LocService locService = SpringUtils.getBean(LocService.class);
-        Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>()
+        List<Loc> locList = locService.list(new LambdaQueryWrapper<Loc>()
                 .eq(!Objects.isNull(locType), Loc::getType, locType)
                 .eq(Loc::getAreaId, areaId)
                 .eq(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type)
@@ -47,45 +54,44 @@
                 .orderByAsc(Loc::getLev)
                 .orderByAsc(Loc::getCol)
                 .orderByAsc(Loc::getRow)
-                .last("LIMIT 1")
+                .last("LIMIT " + TARGET_LOC_QUERY_LIMIT)
         );
 
-        return !Objects.isNull(loc) ? loc.getCode() : null;
+        return claimTargetLoc(locList);
     }
 
     public static String getTargetLoc(Long areaId, Long containerType) {
         Long locType = containerType;
-//        if (!Objects.isNull(containerType)) {
-//            LocTypeService locService = SpringUtils.getBean(LocTypeService.class);
-//            if (containerType.equals(ContainerType.CONTAINER_TYPE_NORMAL.val)) {
-//                LocType low = locService.getOne(new LambdaQueryWrapper<LocType>()
-//                        .eq(LocType::getCode, "L"));
-//                if (Objects.isNull(low)) {
-//                    throw new CoolException("搴綅椤炲瀷涓嶅瓨鍦紒锛�");
-//                }
-//                locType = low.getId();
-//            } else {
-//                LocType low = locService.getOne(new LambdaQueryWrapper<LocType>()
-//                        .eq(LocType::getCode, "H"));
-//                if (Objects.isNull(low)) {
-//                    throw new CoolException("搴綅椤炲瀷涓嶅瓨鍦紒锛�");
-//                }
-//                locType = low.getId();
-//            }
-//        }
         //TODO 搴撲綅绛栫暐鍚庣画鎺掓湡
         LocService locService = SpringUtils.getBean(LocService.class);
-        Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>()
+        List<Loc> locList = locService.list(new LambdaQueryWrapper<Loc>()
                 .eq(!Objects.isNull(locType), Loc::getType, locType)
                 .eq(Loc::getAreaId, areaId)
                 .eq(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type)
                 .orderByAsc(Loc::getLev)
                 .orderByAsc(Loc::getCol)
                 .orderByAsc(Loc::getRow)
-                .last("LIMIT 1")
+                .last("LIMIT " + TARGET_LOC_QUERY_LIMIT)
         );
 
-        return !Objects.isNull(loc) ? loc.getCode() : null;
+        return claimTargetLoc(locList);
+    }
+
+    private static String claimTargetLoc(List<Loc> locList) {
+        if (Cools.isEmpty(locList)) {
+            return null;
+        }
+        WmsRedisLuaService wmsRedisLuaService = SpringUtils.getBean(WmsRedisLuaService.class);
+        for (Loc loc : locList) {
+            if (Objects.isNull(loc) || Cools.isEmpty(loc.getCode())) {
+                continue;
+            }
+            boolean claimed = wmsRedisLuaService.claimLocation(RedisKeys.locationOccupy(loc.getCode()), loc.getCode(), TARGET_LOC_LOCK_TTL);
+            if (claimed) {
+                return loc.getCode();
+            }
+        }
+        return null;
     }
 
     /**

--
Gitblit v1.9.1