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 | 233 ++++++++++++++++++++++++++++-----------------------------
1 files changed, 114 insertions(+), 119 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 cd7487f..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,60 +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);
}
-
- /**
- * @param
- * @return
- * @author Ryan
- * @description 鑾峰彇鐩爣绔欑偣
- * @time 2025/3/31 09:49
- */
- public static String getTargetSite() {
- //TODO 绔欑偣绛栫暐鍚庣画鎺掓湡
- DeviceSiteService deviceSite = SpringUtils.getBean(DeviceSiteService.class);
- DeviceSite loc = deviceSite.getOne(new LambdaQueryWrapper<DeviceSite>().eq(DeviceSite::getStatus, 1), false);
- return !Objects.isNull(loc) ? loc.getSite() : null;
+ 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;
}
/**
@@ -172,12 +163,10 @@
* @param waveRule
* @return
*/
- public static List<OrderOutItemDto> getOutOrderList(List<WaveToLocParams> params, WaveRule waveRule) {
+ public static List<OrderOutItemDto> getOutOrderList(List<WaveToLocParams> params, WaveRule waveRule,String stationId,String locCode) {
LocService locService = SpringUtils.getBean(LocService.class);
LocItemService locItemService = SpringUtils.getBean(LocItemService.class);
- DeviceSiteService deviceSiteService = SpringUtils.getBean(DeviceSiteService.class);
BasStationAreaService basStationAreaService = SpringUtils.getBean(BasStationAreaService.class);
-// List<BasStationArea> basStationAreas = basStationAreaService.list(new LambdaQueryWrapper<>());//
List<Loc> locList = new ArrayList<>();
List<OrderOutItemDto> list = new ArrayList<>();
//涓嶈绔欑偣閲嶅浣跨敤闂
@@ -203,6 +192,11 @@
}
for (LocItem locItem : locItems) {
Loc loc = locService.getById(locItem.getLocId());
+ if (!Cools.isEmpty(locCode) || !Cools.isEmpty(stationId)) {
+ if (!loc.getCode().equals(locCode)){
+ continue;
+ }
+ }
List<LocItem> itemList = locItemService.list(new LambdaQueryWrapper<LocItem>().eq(LocItem::getLocId, loc.getId()));
if (issued.doubleValue() > 0 && locList.contains(loc)) {
@@ -231,7 +225,7 @@
// orderOutItemDto.setLocItem(locItem);
orderOutItemDto.setLoc(loc);
orderOutItemDto.getLocItemList().add(locItem);
- BasContainer containerType = getContainerType(loc.getBarcode());
+ BasContainer containerType = new WarehouseLocationRetrievalUtil().getContainerByBarcode(loc.getBarcode());
if (Cools.isEmpty(containerType)){
continue;
}
@@ -243,81 +237,101 @@
.apply("JSON_CONTAINS(container_type, {0}) = 1", containerType.getContainerType().toString())//瀹瑰櫒绫诲瀷
.eq(BasStationArea::getDeleted, 0));
// .apply("JSON_CONTAINS(station_alias, '\"{0}\"') = 1", null)//鍖哄煙鍖呭惈绔欑偣闆�
- if (basStationAreas.isEmpty()){
- throw new CoolException("鏈壘鍒扮鍚堟潯浠剁珯鐐癸紒锛侊紒璇锋鏌ュ簱鍖洪厤缃紒锛侊紒");
- }
- List<String> targSiteAreaList = new ArrayList<>();
- for (BasStationArea basStationArea : basStationAreas) {
- if (basStationArea.getStationAliasStaNo().isEmpty()){
- continue;
- }
- targSiteAreaList.add(basStationArea.getId().toString());
- }
- if (targSiteAreaList.isEmpty()){
- throw new CoolException("鏈壘鍒扮鍚堟潯浠剁珯鐐癸紒锛侊紒璇锋鏌ュ簱鍖洪厤缃紒锛侊紒");
- }
- int count = 0;
- for (BasStationArea basStationArea : basStationAreas) {
- count++;
- if (!basStationArea.getStationAliasStaNo().isEmpty()) {
- List<OrderOutItemDto.staListDto> maps = new ArrayList<>();
- for (String site : basStationArea.getStationAliasStaNo()) {
- OrderOutItemDto.staListDto staListDto = new OrderOutItemDto.staListDto();
- staListDto.setStaNo(site);
- staListDto.setStaName(site);
- maps.add(staListDto);
+ if (!basStationAreas.isEmpty() && Cools.isEmpty(stationId)){
+ List<String> targSiteAreaList = new ArrayList<>();
+ for (BasStationArea basStationArea : basStationAreas) {
+ if (basStationArea.getStationAliasStaNo().isEmpty()){
+ continue;
}
- orderOutItemDto.setStaNos(maps);
- //鑾峰彇婊¤冻鏉′欢绔欑偣
- Set<String> stationSet = new HashSet<>(basStationArea.getStationAliasStaNo());
+ targSiteAreaList.add(basStationArea.getId().toString());
+ }
+ if (targSiteAreaList.isEmpty()){
+ throw new CoolException("鏈壘鍒扮鍚堟潯浠剁珯鐐癸紒锛侊紒璇锋鏌ュ簱鍖洪厤缃紒锛侊紒");
+ }
+ int count = 0;
+ for (BasStationArea basStationArea : basStationAreas) {
+ count++;
+ if (!basStationArea.getStationAliasStaNo().isEmpty()) {
+ List<OrderOutItemDto.staListDto> maps = new ArrayList<>();
+ for (String site : basStationArea.getStationAliasStaNo()) {
+ OrderOutItemDto.staListDto staListDto = new OrderOutItemDto.staListDto();
+ staListDto.setStaNo(site);
+ staListDto.setStaName(site);
+ maps.add(staListDto);
+ }
+ orderOutItemDto.setStaNos(maps);
+ //鑾峰彇婊¤冻鏉′欢绔欑偣
+ Set<String> stationSet = new HashSet<>(basStationArea.getStationAliasStaNo());
// Set<String> stationSet = basStationArea.getStationAlias().stream().collect(Collectors.toSet());
// Set<String> stationSet = deviceSites.stream().map(DeviceSite::getSite).collect(Collectors.toSet());
- //宸蹭娇鐢ㄧ珯鐐�
- Set<String> stas = stations.stream().map(BasStation::getStationName).collect(Collectors.toSet());
- if (stas.size() == maps.size()) {
- stations = new ArrayList<>();
- stas = stations.stream().map(BasStation::getStationName).collect(Collectors.toSet());
- }
- BasStationService basStationService = SpringUtils.getBean(BasStationService.class);
- BasStation basStation = basStationService.getOne(new LambdaQueryWrapper<BasStation>()
- .eq(BasStation::getUseStatus, LocStsType.LOC_STS_TYPE_O.type)
- .in(BasStation::getStationName, stationSet)
- .notIn(!stas.isEmpty(), BasStation::getStationName, stas)
- .last("LIMIT 1"));
- if (!Objects.isNull(basStation)) {
- stations.add(basStation);
- }
-
- if (count == basStationAreas.size()) {
+ //宸蹭娇鐢ㄧ珯鐐�
+ Set<String> stas = stations.stream().map(BasStation::getStationName).collect(Collectors.toSet());
+ if (stas.size() == maps.size()) {
+ stations = new ArrayList<>();
+ stas = stations.stream().map(BasStation::getStationName).collect(Collectors.toSet());
+ }
+ BasStationService basStationService = SpringUtils.getBean(BasStationService.class);
+ BasStation basStation = basStationService.getOne(new LambdaQueryWrapper<BasStation>()
+ .eq(BasStation::getUseStatus, LocStsType.LOC_STS_TYPE_O.type)
+ .in(BasStation::getStationName, stationSet)
+ .notIn(!stas.isEmpty(), BasStation::getStationName, stas)
+ .last("LIMIT 1"));
if (!Objects.isNull(basStation)) {
+ stations.add(basStation);
+ }
+
+ if (count == basStationAreas.size()) {
+ if (!Objects.isNull(basStation)) {
+ orderOutItemDto.setTargSiteAreaNow(basStationArea.getStationAreaId());
+ orderOutItemDto.setSiteNo(basStation.getStationName());
+// throw new CoolException("绔欓粸涓嶅瓨鍦紒锛�");
+ } else if (!stas.isEmpty()) {
+ orderOutItemDto.setTargSiteAreaNow(basStationArea.getStationAreaId());
+ orderOutItemDto.setSiteNo(basStationArea.getStationAliasStaNo().get(0));
+ } else {
+ throw new CoolException("鏈壘鍒扮鍚堟潯浠剁珯鐐癸紒锛侊紒璇锋鏌ュ簱鍖烘垨鑰呰矾寰勯厤缃紒锛侊紒");
+ }
+ } else {
+ if (Objects.isNull(basStation)) {
+ continue;
+// throw new CoolException("绔欓粸涓嶅瓨鍦紒锛�");
+ }
orderOutItemDto.setTargSiteAreaNow(basStationArea.getStationAreaId());
orderOutItemDto.setSiteNo(basStation.getStationName());
-// throw new CoolException("绔欓粸涓嶅瓨鍦紒锛�");
- } else if (!stas.isEmpty()) {
- orderOutItemDto.setTargSiteAreaNow(basStationArea.getStationAreaId());
- orderOutItemDto.setSiteNo(basStationArea.getStationAliasStaNo().get(0));
- } else {
- throw new CoolException("鏈壘鍒扮鍚堟潯浠剁珯鐐癸紒锛侊紒璇锋鏌ュ簱鍖烘垨鑰呰矾寰勯厤缃紒锛侊紒");
}
- } else {
- if (Objects.isNull(basStation)) {
- continue;
-// throw new CoolException("绔欓粸涓嶅瓨鍦紒锛�");
- }
- orderOutItemDto.setTargSiteAreaNow(basStationArea.getStationAreaId());
- orderOutItemDto.setSiteNo(basStation.getStationName());
+
}
+ orderOutItemDto.setSource(item.getItemId().toString())
+ .setTargSiteAreaList(targSiteAreaList)
+ .setSourceId(item.getWaveId().toString());
+ list.add(orderOutItemDto);
+ locList.add(loc);
+
+ issued = issued.subtract(new BigDecimal(locItem.getAnfme().toString()));
+ break;
}
+ } else if (!Cools.isEmpty(stationId)){
+ BasStationService basStationService = SpringUtils.getBean(BasStationService.class);
+ BasStation basStation = basStationService.getOne(new LambdaQueryWrapper<BasStation>().eq(BasStation::getStationName, stationId));
+ if (Objects.isNull(basStation)) {
+ throw new CoolException("缁戝畾绔欓粸涓嶅瓨鍦紒锛�");
+ }
+ boolean available = new WarehouseLocationRetrievalUtil().queryPathIsItAvailableOutArea(loc.getAreaId().toString(), stationId, loc.getBarcode(),"out");
+ if (!available) {
+ throw new CoolException("鏈壘鍒扮鍚堟潯浠惰矾寰勶紒锛侊紒璇锋鏌ヨ矾寰勯厤缃紒锛侊紒");
+ }
+ orderOutItemDto.setSiteNo(basStation.getStationName());
orderOutItemDto.setSource(item.getItemId().toString())
- .setTargSiteAreaList(targSiteAreaList)
+ .setTargSiteAreaList(new ArrayList<>())
.setSourceId(item.getWaveId().toString());
list.add(orderOutItemDto);
- locList.add(loc);
+ locList.add(loc);
issued = issued.subtract(new BigDecimal(locItem.getAnfme().toString()));
- break;
+ } else {
+ throw new CoolException("鏈壘鍒扮鍚堟潯浠跺嚭搴撶珯鐐瑰尯鍩燂紒锛侊紒璇锋鏌ュ簱鍖洪厤缃紒锛侊紒");
}
}
}
@@ -325,25 +339,6 @@
}
return list;
- }
-
-
-
-
- //鏍规嵁鏉$爜鑾峰彇瑙勫垯
- private static BasContainer getContainerType(String barcode) {
- BasContainerService basContainerService = SpringUtils.getBean(BasContainerService.class);
- if (Cools.isEmpty(barcode)) {
- throw new CoolException("瀹瑰櫒鐮佷笉鑳戒负绌�");
- }
- List<BasContainer> containers = basContainerService.list(new LambdaQueryWrapper<>());
- for (BasContainer container : containers) {
- String codeType = container.getCodeType(); // 鑾峰彇姝e垯琛ㄨ揪寮�
- if (barcode.matches(codeType)) { // 鍒ゆ柇鏉$爜鏄惁绗﹀悎杩欎釜姝e垯
- return container;
- }
- }
- return null;
}
}
--
Gitblit v1.9.1