From 2acfc2d2a0e956910c51bd996f443b3cb9bd3dc9 Mon Sep 17 00:00:00 2001
From: zwl <1051256694@qq.com>
Date: 星期日, 22 三月 2026 14:27:21 +0800
Subject: [PATCH] 优化找库位规则
---
src/main/java/com/zy/asrs/utils/Utils.java | 128 +++++++++++++++++++++---------------------
1 files changed, 65 insertions(+), 63 deletions(-)
diff --git a/src/main/java/com/zy/asrs/utils/Utils.java b/src/main/java/com/zy/asrs/utils/Utils.java
index e26c7d0..1081c54 100644
--- a/src/main/java/com/zy/asrs/utils/Utils.java
+++ b/src/main/java/com/zy/asrs/utils/Utils.java
@@ -149,10 +149,11 @@
* <p>澶勭悊瑙勫垯锛�
* 1. 鍏堟牴鎹叆搴撶珯鐐规煡璇㈡墍灞炲簱鍖恒��
* 2. 鍏堟彁鍙栬搴撳尯鍐呯殑鍫嗗灈鏈猴紝骞舵寜鍙敤绌哄簱浣嶈繃婊や笉鍙敤鍫嗗灈鏈恒��
- * 3. 鑻ュ綋鍓嶅簱鍖烘病鏈夋弧瓒虫潯浠剁殑绌哄簱浣嶏紝鍐嶈ˉ鍏呭叾浠栧簱鍖虹殑鍫嗗灈鏈恒��
- * 4. 褰� {@code locType1 = 1} 鏃讹紝鍏堣繑鍥炰綆搴撲綅鍫嗗灈鏈猴紝鍐嶆妸鍚屾壒鍫嗗灈鏈虹殑楂樺簱浣嶈拷鍔犲埌鍚庨潰銆�
- * 5. 瀵逛笉瀛樺湪銆佹晠闅溿�佷笉鍙叆浠ュ強鏃犵┖搴撲綅鐨勫爢鍨涙満鐩存帴鍓旈櫎銆�
- * 6. 褰撶墿鏂欎负 {@code emptyPallet} 鏃讹紝鎸夌┖鏉垮叆搴撲紭鍏堣鍒欓噸鏂版帓搴忋��
+ * 3. 褰� {@code locType1 = 1} 鏃讹紝鍏堣繑鍥炰綆搴撲綅鍫嗗灈鏈猴紝鍐嶆妸鍚屾壒鍫嗗灈鏈虹殑楂樺簱浣嶈拷鍔犲埌鍚庨潰銆�
+ * 4. 瀵逛笉瀛樺湪銆佹晠闅溿�佷笉鍙叆浠ュ強鏃犵┖搴撲綅鐨勫爢鍨涙満鐩存帴鍓旈櫎銆�
+ *
+ * <p>杩欓噷鏄彧璇绘帓搴忓伐鍏凤紝涓嶅啀鍐欏洖 {@code asr_row_lastno.crn_qty}銆�
+ * {@code crn_qty} 鍦ㄤ富鏁版嵁閲岃〃绀衡�滃爢鍨涙満鏁伴噺鈥濓紝涓嶈兘鍐嶈鎷挎潵褰撹疆璇㈡父鏍囷紝鍚﹀垯浼氭妸鏁翠粨閰嶇疆鍐欏潖銆�
*
* <p>杩斿洖缁撴灉涓殑姣忎竴椤规牸寮忎负锛�
* {@code {crnNo: 鍫嗗灈鏈哄彿, locType1: 搴撲綅楂樹綆绫诲瀷}}
@@ -183,35 +184,29 @@
// 鍏堝彇褰撳墠搴撳尯瀵瑰簲鐨勫爢鍨涙満銆�
List<Integer> preferredCrnNos = getAreaCrnNos(storageArea, rowLastno);
List<Integer> preferredAvailableCrnNos = getAvailableCrnNos(preferredCrnNos, locType1, emptyPallet, basCrnpService, locMastService);
- appendCrnLocTypeEntries(result, preferredAvailableCrnNos, locType1, locMastService);
+ appendCrnLocTypeEntries(result, preferredAvailableCrnNos, locType1, emptyPallet, locMastService);
- // 褰撳墠搴撳尯娌℃湁鍙敤瀹归噺鏃讹紝鍐嶈ˉ鍏呭叾浠栧簱鍖哄爢鍨涙満銆�
- if (!hasAvailableCapacity(preferredCrnNos, locType1, basCrnpService, locMastService)) {
- List<Integer> otherAreaCrnNos = getOtherAreaCrnNos(storageArea, rowLastno);
- List<Integer> otherAvailableCrnNos = getAvailableCrnNos(otherAreaCrnNos, locType1, emptyPallet, basCrnpService, locMastService);
- appendCrnLocTypeEntries(result, otherAvailableCrnNos, locType1, locMastService);
- }
return result;
}
- private static void appendCrnLocTypeEntries(List<Map<String, Integer>> result, List<Integer> crnNos, Integer locType1, LocMastService locMastService) {
+ private static void appendCrnLocTypeEntries(List<Map<String, Integer>> result, List<Integer> crnNos, Integer locType1, boolean emptyPallet, LocMastService locMastService) {
Short normalizedLocType1 = normalizeLocType1(locType1);
if (normalizedLocType1 == null) {
- appendCrnLocTypeEntries(result, crnNos, (short) 1, locMastService);
- appendCrnLocTypeEntries(result, crnNos, (short) 2, locMastService);
+ appendCrnLocTypeEntries(result, crnNos, (short) 1, emptyPallet, locMastService);
+ appendCrnLocTypeEntries(result, crnNos, (short) 2, emptyPallet, locMastService);
return;
}
- appendCrnLocTypeEntries(result, crnNos, normalizedLocType1, locMastService);
+ appendCrnLocTypeEntries(result, crnNos, normalizedLocType1, emptyPallet, locMastService);
if (normalizedLocType1 == 1) {
- appendCrnLocTypeEntries(result, crnNos, (short) 2, locMastService);
+ appendCrnLocTypeEntries(result, crnNos, (short) 2, emptyPallet, locMastService);
}
}
- private static void appendCrnLocTypeEntries(List<Map<String, Integer>> result, List<Integer> crnNos, Short targetLocType1, LocMastService locMastService) {
+ private static void appendCrnLocTypeEntries(List<Map<String, Integer>> result, List<Integer> crnNos, Short targetLocType1, boolean emptyPallet, LocMastService locMastService) {
if (targetLocType1 == null || Cools.isEmpty(crnNos)) {
return;
}
for (Integer crnNo : crnNos) {
- if (!hasAvailableLoc(crnNo, targetLocType1, locMastService) || containsCrnLocType(result, crnNo, targetLocType1)) {
+ if (!hasAvailableLoc(crnNo, targetLocType1, emptyPallet, locMastService) || containsCrnLocType(result, crnNo, targetLocType1)) {
continue;
}
Map<String, Integer> item = new LinkedHashMap<>();
@@ -247,7 +242,7 @@
if (crnNo == null || !basCrnpService.checkSiteError(crnNo, true)) {
continue;
}
- if (!hasAvailableLocForRequest(crnNo, locType1, locMastService)) {
+ if (!hasAvailableLocForRequest(crnNo, locType1, emptyPallet, locMastService)) {
continue;
}
availableCrnNos.add(crnNo);
@@ -272,25 +267,30 @@
return "Y".equalsIgnoreCase(basCrnp.getEmpIn()) ? 1 : 0;
}
- private static boolean hasAvailableLocForRequest(Integer crnNo, Integer locType1, LocMastService locMastService) {
+ private static boolean hasAvailableLocForRequest(Integer crnNo, Integer locType1, boolean emptyPallet, LocMastService locMastService) {
Short normalizedLocType1 = normalizeLocType1(locType1);
if (normalizedLocType1 == null) {
- return hasAvailableLoc(crnNo, (short) 1, locMastService) || hasAvailableLoc(crnNo, (short) 2, locMastService);
+ return hasAvailableLoc(crnNo, (short) 1, emptyPallet, locMastService)
+ || hasAvailableLoc(crnNo, (short) 2, emptyPallet, locMastService);
}
- if (hasAvailableLoc(crnNo, normalizedLocType1, locMastService)) {
+ if (hasAvailableLoc(crnNo, normalizedLocType1, emptyPallet, locMastService)) {
return true;
}
- return normalizedLocType1 == 1 && hasAvailableLoc(crnNo, (short) 2, locMastService);
+ return normalizedLocType1 == 1 && hasAvailableLoc(crnNo, (short) 2, emptyPallet, locMastService);
}
- private static boolean hasAvailableLoc(Integer crnNo, Short locType1, LocMastService locMastService) {
+ private static boolean hasAvailableLoc(Integer crnNo, Short locType1, boolean emptyPallet, LocMastService locMastService) {
if (crnNo == null || locType1 == null) {
return false;
}
- return locMastService.selectCount(new EntityWrapper<LocMast>()
- .eq("crn_no", crnNo)
- .eq("loc_sts", "O")
- .eq("loc_type1", locType1)) > 0;
+ EntityWrapper<LocMast> wrapper = new EntityWrapper<LocMast>();
+ wrapper.eq("crn_no", crnNo);
+ wrapper.eq("loc_sts", "O");
+ wrapper.eq("loc_type1", locType1);
+ if (!emptyPallet) {
+ wrapper.ne("loc_type2", 1);
+ }
+ return locMastService.selectCount(wrapper) > 0;
}
private static Short normalizeLocType1(Integer locType1) {
@@ -321,21 +321,10 @@
if (areaRowLastno == null) {
return new ArrayList<>(crnNos);
}
- Integer startCrnNo = resolveAreaStartCrnNo(areaRowLastno, rowLastno);
- Integer endCrnNo = resolveAreaEndCrnNo(areaRowLastno, rowLastno);
- if (startCrnNo != null && endCrnNo != null && startCrnNo <= endCrnNo) {
- for (int crnNo = startCrnNo; crnNo <= endCrnNo; crnNo++) {
- addAreaCrnNo(crnNos, crnNo, 1, endCrnNo);
- }
- for (int crnNo = areaRowLastno.getsCrnNo(); crnNo <= startCrnNo; crnNo++) {
- addAreaCrnNo(crnNos, crnNo, 1, endCrnNo);
- }
- Integer nextCrnQty = startCrnNo + 1;
- if (areaRowLastno.geteCrnNo() != null && nextCrnQty > areaRowLastno.geteCrnNo()) {
- nextCrnQty = areaRowLastno.getsCrnNo() == null ? 1 : areaRowLastno.getsCrnNo();
- }
- areaRowLastno.setCrnQty(nextCrnQty);
- SpringUtils.getBean(RowLastnoService.class).updateById(areaRowLastno);
+ Integer startCrnNo = resolveAreaStartCrnNo(areaRowLastno);
+ List<Integer> orderedCrnNos = getOrderedCrnNos(areaRowLastno, startCrnNo);
+ if (!orderedCrnNos.isEmpty()) {
+ crnNos.addAll(orderedCrnNos);
}
if (crnNos.isEmpty()) {
@@ -362,34 +351,47 @@
return defaultRowLastno;
}
- private static Integer resolveAreaStartCrnNo(RowLastno areaRowLastno, RowLastno defaultRowLastno) {
- if (areaRowLastno != null && areaRowLastno.getCrnQty() != null && areaRowLastno.getCrnQty() > 0) {
- return areaRowLastno.getCrnQty();
+ private static Integer resolveAreaStartCrnNo(RowLastno areaRowLastno) {
+ if (areaRowLastno == null) {
+ return null;
}
- if (areaRowLastno != null && areaRowLastno.getsCrnNo() != null && areaRowLastno.getsCrnNo() > 0) {
- return areaRowLastno.getsCrnNo();
+ Integer startCrnNo = areaRowLastno.getsCrnNo();
+ Integer endCrnNo = areaRowLastno.geteCrnNo();
+ Integer currentRow = areaRowLastno.getCurrentRow();
+ Integer rowSpan = getCrnRowSpan(areaRowLastno.getTypeId());
+ if (startCrnNo == null || startCrnNo <= 0) {
+ return 1;
}
- if (defaultRowLastno != null && defaultRowLastno.getsCrnNo() != null && defaultRowLastno.getsCrnNo() > 0) {
- return defaultRowLastno.getsCrnNo();
+ if (endCrnNo == null || endCrnNo < startCrnNo || currentRow == null || rowSpan == null || rowSpan <= 0) {
+ return startCrnNo;
}
- return 1;
+ int startRow = areaRowLastno.getsRow() == null ? 1 : areaRowLastno.getsRow();
+ int offset = Math.max(currentRow - startRow, 0) / rowSpan;
+ int resolvedCrnNo = startCrnNo + offset;
+ if (resolvedCrnNo < startCrnNo || resolvedCrnNo > endCrnNo) {
+ return startCrnNo;
+ }
+ return resolvedCrnNo;
}
- private static Integer resolveAreaEndCrnNo(RowLastno areaRowLastno, RowLastno defaultRowLastno) {
- if (areaRowLastno != null && areaRowLastno.geteCrnNo() != null && areaRowLastno.geteCrnNo() > 0) {
- return areaRowLastno.geteCrnNo();
+ private static List<Integer> getOrderedCrnNos(RowLastno rowLastno, Integer startCrnNo) {
+ List<Integer> orderedCrnNos = new ArrayList<>();
+ if (rowLastno == null) {
+ return orderedCrnNos;
}
- return null;
- }
-
- private static void addAreaCrnNo(LinkedHashSet<Integer> crnNos, Integer crnNo, Integer startCrnNo, Integer endCrnNo) {
- if (crnNos == null || crnNo == null || startCrnNo == null || endCrnNo == null) {
- return;
+ int start = rowLastno.getsCrnNo() == null ? 1 : rowLastno.getsCrnNo();
+ int end = rowLastno.geteCrnNo() == null ? start + ((rowLastno.getCrnQty() == null ? 1 : rowLastno.getCrnQty()) - 1) : rowLastno.geteCrnNo();
+ int first = startCrnNo == null ? start : startCrnNo;
+ if (first < start || first > end) {
+ first = start;
}
- if (crnNo < startCrnNo || crnNo > endCrnNo) {
- return;
+ for (int crnNo = first; crnNo <= end; crnNo++) {
+ orderedCrnNos.add(crnNo);
}
- crnNos.add(crnNo);
+ for (int crnNo = start; crnNo < first; crnNo++) {
+ orderedCrnNos.add(crnNo);
+ }
+ return orderedCrnNos;
}
private static List<Integer> getAllCrnNos(RowLastno rowLastno) {
--
Gitblit v1.9.1