From 5095e9cf3e1c9ec9564793ebac5674d5c6c6ba00 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期三, 01 四月 2026 14:47:19 +0800
Subject: [PATCH] #入库任务路径计算增加cache
---
src/main/java/com/zy/common/service/CommonService.java | 214 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 214 insertions(+), 0 deletions(-)
diff --git a/src/main/java/com/zy/common/service/CommonService.java b/src/main/java/com/zy/common/service/CommonService.java
index bb00969..9169502 100644
--- a/src/main/java/com/zy/common/service/CommonService.java
+++ b/src/main/java/com/zy/common/service/CommonService.java
@@ -1,6 +1,7 @@
package com.zy.common.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.core.common.Cools;
import com.core.exception.CoolException;
import com.zy.asrs.domain.Result.CancelTaskBatchResult;
@@ -29,6 +30,8 @@
@Slf4j
@Service
public class CommonService {
+
+ private static final long OUT_STATION_ROUTE_CACHE_SECONDS = 60 * 60 * 24 * 7;
@Autowired
private WrkMastService wrkMastService;
@@ -112,6 +115,8 @@
wrkMast.setWrkSts(WrkStsType.COMPLETE_OUTBOUND.sts);
} else if (wrkMast.getIoType() == WrkIoType.LOC_MOVE.id) {
wrkMast.setWrkSts(WrkStsType.COMPLETE_LOC_MOVE.sts);
+ } else if (wrkMast.getIoType() == WrkIoType.CRN_MOVE.id) {
+ wrkMast.setWrkSts(WrkStsType.COMPLETE_CRN_MOVE.sts);
}
wrkMast.setModiTime(new Date());
@@ -142,6 +147,8 @@
} else if (wrkMast.getIoType().equals(WrkIoType.OUT.id) && !wrkMast.getWrkSts().equals(WrkStsType.NEW_OUTBOUND.sts)) {
cancelSuccess = true;
} else if (wrkMast.getIoType().equals(WrkIoType.LOC_MOVE.id) && !wrkMast.getWrkSts().equals(WrkStsType.NEW_LOC_MOVE.sts)) {
+ cancelSuccess = true;
+ } else if (wrkMast.getIoType().equals(WrkIoType.CRN_MOVE.id) && !wrkMast.getWrkSts().equals(WrkStsType.NEW_CRN_MOVE.sts)) {
cancelSuccess = true;
}
@@ -180,6 +187,80 @@
wrkMast.setModiTime(new Date());
wrkMastService.updateById(wrkMast);
return true;
+ }
+
+ public CancelTaskBatchResult cancelOutTaskBatchInfo(CancelTaskBatchParam param) {
+ if (param == null) {
+ throw new CoolException("鍙傛暟涓嶈兘涓虹┖");
+ }
+ List<CancelTaskParam> taskList = param.getTaskList();
+ if (taskList == null || taskList.isEmpty()) {
+ throw new CoolException("浠诲姟鍙傛暟鍒楄〃涓虹┖");
+ }
+
+ List<String> successList = new ArrayList<>();
+ List<String> failList = new ArrayList<>();
+ for (CancelTaskParam taskParam : taskList) {
+ if (taskParam == null) {
+ throw new CoolException("浠诲姟鍙傛暟涓嶈兘涓虹┖");
+ }
+ boolean cancelStatus = false;
+ try {
+ cancelStatus = cancelSingleOutTaskBatchInfo(taskParam);
+ } catch (Exception e) {
+ }
+
+ if (cancelStatus) {
+ successList.add(resolveTaskIdentifier(taskParam));
+ } else {
+ failList.add(resolveTaskIdentifier(taskParam));
+ }
+ }
+
+ CancelTaskBatchResult result = new CancelTaskBatchResult();
+ result.setSuccessList(successList);
+ result.setFailList(failList);
+ return result;
+ }
+
+ private boolean cancelSingleOutTaskBatchInfo(CancelTaskParam param) {
+ WrkMast wrkMast = null;
+ Integer wrkNo = param.getWrkNo();
+ String taskNo = param.getTaskNo();
+ if (wrkNo == null) {
+ if (Cools.isEmpty(taskNo)) {
+ throw new CoolException("WMS浠诲姟鍙蜂笉鑳戒负绌�");
+ }
+ wrkMast = wrkMastService.getOne(new QueryWrapper<WrkMast>().eq("wms_wrk_no", taskNo));
+ } else {
+ wrkMast = wrkMastService.selectByWorkNo(wrkNo);
+ }
+ if (wrkMast == null) {
+ throw new CoolException("浠诲姟涓嶅瓨鍦�");
+ }
+ if (!wrkMast.getIoType().equals(WrkIoType.OUT.id)) {
+ throw new CoolException("浠呮敮鎸佸嚭搴撲换鍔�");
+ }
+
+ boolean updated = wrkMast.getWrkNo() != null && wrkMastService.update(null, new UpdateWrapper<WrkMast>()
+ .eq("wrk_no", wrkMast.getWrkNo())
+ .set("batch", null)
+ .set("batch_seq", null)
+ .set("modi_time", new Date()));
+ if (!updated) {
+ throw new CoolException("鍙栨秷鍑哄簱浠诲姟鎵规鍜屾壒娆″簭鍙峰け璐�");
+ }
+ return true;
+ }
+
+ private String resolveTaskIdentifier(CancelTaskParam param) {
+ if (!Cools.isEmpty(param.getTaskNo())) {
+ return param.getTaskNo();
+ }
+ if (param.getWrkNo() != null) {
+ return String.valueOf(param.getWrkNo());
+ }
+ return "";
}
public CancelTaskBatchResult cancelTaskBatch(CancelTaskBatchParam param) {
@@ -575,12 +656,18 @@
stationList = basDualCrnp.getInStationList$();
}
+ Integer cachedTargetStationId = resolveCachedInStationId(findCrnNoResult, sourceStationId, stationList);
+ if (cachedTargetStationId != null) {
+ return cachedTargetStationId;
+ }
+
Integer targetStationId = null;
for (StationObjModel stationObjModel : stationList) {
try {
List<NavigateNode> navigateNodes = navigateUtils.calcReachablePathByStationId(sourceStationId, stationObjModel.getStationId());
if(!navigateNodes.isEmpty()) {
targetStationId = stationObjModel.getStationId();
+ cacheInStationId(findCrnNoResult, sourceStationId, targetStationId);
break;
}
} catch (Exception e) {
@@ -607,12 +694,18 @@
stationList = basDualCrnp.getOutStationList$();
}
+ Integer cachedSourceStationId = resolveCachedOutStationId(findCrnNoResult, targetStationId, stationList);
+ if (cachedSourceStationId != null) {
+ return cachedSourceStationId;
+ }
+
Integer finalSourceStationId = null;
for (StationObjModel stationObjModel : stationList) {
try {
List<NavigateNode> navigateNodes = navigateUtils.calcReachablePathByStationId(stationObjModel.getStationId(), targetStationId);
if(!navigateNodes.isEmpty()) {
finalSourceStationId = stationObjModel.getStationId();
+ cacheOutStationId(findCrnNoResult, targetStationId, finalSourceStationId);
break;
}
} catch (Exception e) {
@@ -622,4 +715,125 @@
return finalSourceStationId;
}
+ /**
+ * 鍏ュ簱璺緞鎼滅储鍚屾牱浠d环杈冮珮锛屽彧缂撳瓨宸茬‘璁ゅ彲杈剧殑鐩爣绔欑偣缁撴灉锛屽苟閫氳繃 TTL 闄愬埗闄堟棫椋庨櫓銆�
+ */
+ private Integer resolveCachedInStationId(FindCrnNoResult findCrnNoResult,
+ Integer sourceStationId,
+ List<StationObjModel> stationList) {
+ if (findCrnNoResult == null || findCrnNoResult.getCrnType() == null
+ || findCrnNoResult.getCrnNo() == null || sourceStationId == null
+ || stationList == null || stationList.isEmpty()) {
+ return null;
+ }
+
+ Object cacheValue = redisUtil.get(buildInStationRouteCacheKey(findCrnNoResult, sourceStationId));
+ if (cacheValue == null) {
+ return null;
+ }
+
+ Integer cachedStationId = parseInteger(cacheValue);
+ if (cachedStationId == null) {
+ return null;
+ }
+
+ for (StationObjModel stationObjModel : stationList) {
+ if (stationObjModel != null && cachedStationId.equals(stationObjModel.getStationId())) {
+ return cachedStationId;
+ }
+ }
+ return null;
+ }
+
+ private void cacheInStationId(FindCrnNoResult findCrnNoResult,
+ Integer sourceStationId,
+ Integer targetStationId) {
+ if (findCrnNoResult == null || findCrnNoResult.getCrnType() == null
+ || findCrnNoResult.getCrnNo() == null || sourceStationId == null
+ || targetStationId == null) {
+ return;
+ }
+ redisUtil.set(buildInStationRouteCacheKey(findCrnNoResult, sourceStationId),
+ targetStationId,
+ OUT_STATION_ROUTE_CACHE_SECONDS);
+ }
+
+ private String buildInStationRouteCacheKey(FindCrnNoResult findCrnNoResult, Integer sourceStationId) {
+ return RedisKeyType.IN_STATION_ROUTE_CACHE.key
+ + findCrnNoResult.getCrnType().name()
+ + "_"
+ + findCrnNoResult.getCrnNo()
+ + "_"
+ + sourceStationId;
+ }
+
+ /**
+ * 鍑哄簱璺緞鎼滅储浠d环杈冮珮锛屽彧缂撳瓨宸茬‘璁ゅ彲杈剧殑绔欑偣缁撴灉锛屽苟閫氳繃 TTL 鎺у埗闄堟棫椋庨櫓銆�
+ */
+ private Integer resolveCachedOutStationId(FindCrnNoResult findCrnNoResult,
+ Integer targetStationId,
+ List<StationObjModel> stationList) {
+ if (findCrnNoResult == null || findCrnNoResult.getCrnType() == null
+ || findCrnNoResult.getCrnNo() == null || targetStationId == null
+ || stationList == null || stationList.isEmpty()) {
+ return null;
+ }
+
+ Object cacheValue = redisUtil.get(buildOutStationRouteCacheKey(findCrnNoResult, targetStationId));
+ if (cacheValue == null) {
+ return null;
+ }
+
+ Integer cachedStationId = parseInteger(cacheValue);
+ if (cachedStationId == null) {
+ return null;
+ }
+
+ for (StationObjModel stationObjModel : stationList) {
+ if (stationObjModel != null && cachedStationId.equals(stationObjModel.getStationId())) {
+ return cachedStationId;
+ }
+ }
+ return null;
+ }
+
+ private void cacheOutStationId(FindCrnNoResult findCrnNoResult,
+ Integer targetStationId,
+ Integer sourceStationId) {
+ if (findCrnNoResult == null || findCrnNoResult.getCrnType() == null
+ || findCrnNoResult.getCrnNo() == null || targetStationId == null
+ || sourceStationId == null) {
+ return;
+ }
+ redisUtil.set(buildOutStationRouteCacheKey(findCrnNoResult, targetStationId),
+ sourceStationId,
+ OUT_STATION_ROUTE_CACHE_SECONDS);
+ }
+
+ private String buildOutStationRouteCacheKey(FindCrnNoResult findCrnNoResult, Integer targetStationId) {
+ return RedisKeyType.OUT_STATION_ROUTE_CACHE.key
+ + findCrnNoResult.getCrnType().name()
+ + "_"
+ + findCrnNoResult.getCrnNo()
+ + "_"
+ + targetStationId;
+ }
+
+ private Integer parseInteger(Object value) {
+ if (value == null) {
+ return null;
+ }
+ if (value instanceof Integer) {
+ return (Integer) value;
+ }
+ if (value instanceof Number) {
+ return ((Number) value).intValue();
+ }
+ try {
+ return Integer.parseInt(String.valueOf(value));
+ } catch (Exception ignore) {
+ return null;
+ }
+ }
+
}
--
Gitblit v1.9.1