From 1654b0a8c149f86d38f3202cb88c655ad0a25384 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期三, 01 四月 2026 10:33:25 +0800
Subject: [PATCH] #出库任务路径计算增加cache
---
src/main/java/com/zy/common/service/CommonService.java | 77 ++++++++++++++++++++++++++++++++++++++
1 files changed, 77 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 f03a253..578a1a4 100644
--- a/src/main/java/com/zy/common/service/CommonService.java
+++ b/src/main/java/com/zy/common/service/CommonService.java
@@ -31,6 +31,8 @@
@Service
public class CommonService {
+ private static final long OUT_STATION_ROUTE_CACHE_SECONDS = 300L;
+
@Autowired
private WrkMastService wrkMastService;
@Autowired
@@ -686,12 +688,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) {
@@ -701,4 +709,73 @@
return finalSourceStationId;
}
+ /**
+ * 鍑哄簱璺緞鎼滅储浠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