From f7009ef55b73941d904f57e642bbe30b86421634 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期一, 13 四月 2026 18:26:56 +0800
Subject: [PATCH] #入库命令耗时日志
---
src/main/java/com/zy/common/service/CommonService.java | 84 +++++++++++++++++++++++++++++++++++++++--
1 files changed, 79 insertions(+), 5 deletions(-)
diff --git a/src/main/java/com/zy/common/service/CommonService.java b/src/main/java/com/zy/common/service/CommonService.java
index 8c4ef5a..d3abb1f 100644
--- a/src/main/java/com/zy/common/service/CommonService.java
+++ b/src/main/java/com/zy/common/service/CommonService.java
@@ -33,6 +33,11 @@
public class CommonService {
private static final long OUT_STATION_ROUTE_CACHE_SECONDS = 60 * 60 * 24 * 7;
+ /**
+ * 鍏ュ簱鐩爣绔欑殑鎷撴墤鍙樺寲棰戠巼寰堜綆锛屽厑璁镐娇鐢� 24h 缂撳瓨鍑忓皯閲嶅鍙揪璺緞鎼滅储銆�
+ */
+ private static final long IN_STATION_ROUTE_CACHE_SECONDS = 60 * 60 * 24;
+ private static final long IN_STATION_ROUTE_SLOW_LOG_THRESHOLD_MS = 200L;
@Autowired
private WrkMastService wrkMastService;
@@ -677,27 +682,42 @@
}
public Integer findInStationId(FindCrnNoResult findCrnNoResult, Integer sourceStationId) {
+ return resolveInStationId(findCrnNoResult, sourceStationId).getTargetStationId();
+ }
+
+ public InStationResolveResult resolveInStationId(FindCrnNoResult findCrnNoResult, Integer sourceStationId) {
+ long resolveStartNs = System.nanoTime();
+ if (findCrnNoResult == null || findCrnNoResult.getCrnType() == null
+ || findCrnNoResult.getCrnNo() == null || sourceStationId == null) {
+ return InStationResolveResult.empty(false, nanosToMillis(resolveStartNs));
+ }
List<StationObjModel> stationList = new ArrayList<>();
Integer crnNo = findCrnNoResult.getCrnNo();
if (findCrnNoResult.getCrnType().equals(SlaveType.Crn)) {
BasCrnp basCrnp = basCrnpService.getOne(new QueryWrapper<BasCrnp>().eq("crn_no", crnNo));
if(basCrnp == null) {
- return null;
+ return InStationResolveResult.empty(false, nanosToMillis(resolveStartNs));
}
stationList = basCrnp.getInStationList$();
} else if (findCrnNoResult.getCrnType().equals(SlaveType.DualCrn)) {
BasDualCrnp basDualCrnp = basDualCrnpService.getOne(new QueryWrapper<BasDualCrnp>().eq("crn_no", crnNo));
if(basDualCrnp == null) {
- return null;
+ return InStationResolveResult.empty(false, nanosToMillis(resolveStartNs));
}
stationList = basDualCrnp.getInStationList$();
}
Integer cachedTargetStationId = resolveCachedInStationId(findCrnNoResult, sourceStationId, stationList);
if (cachedTargetStationId != null) {
- return cachedTargetStationId;
+ long totalCostMs = nanosToMillis(resolveStartNs);
+ if (totalCostMs >= IN_STATION_ROUTE_SLOW_LOG_THRESHOLD_MS) {
+ log.info("鍏ュ簱鐩爣绔欑紦瀛樺懡涓�楁椂杈冮暱锛宻ourceStationId={}锛宑rnNo={}锛宼argetStationId={}锛宼otalCost={}ms",
+ sourceStationId, crnNo, cachedTargetStationId, totalCostMs);
+ }
+ return InStationResolveResult.cacheHit(cachedTargetStationId, totalCostMs);
}
+ long searchStartNs = System.nanoTime();
Integer targetStationId = null;
for (StationObjModel stationObjModel : stationList) {
try {
@@ -711,7 +731,11 @@
// e.printStackTrace();
}
}
- return targetStationId;
+ long searchCostMs = nanosToMillis(searchStartNs);
+ long totalCostMs = nanosToMillis(resolveStartNs);
+ log.info("鍏ュ簱鐩爣绔欑紦瀛樻湭鍛戒腑锛宻ourceStationId={}锛宑rnNo={}锛宼argetStationId={}锛宻earchCost={}ms锛宼otalCost={}ms",
+ sourceStationId, crnNo, targetStationId, searchCostMs, totalCostMs);
+ return InStationResolveResult.searchResult(targetStationId, totalCostMs, searchCostMs);
}
public Integer findOutStationId(FindCrnNoResult findCrnNoResult, Integer targetStationId) {
@@ -792,7 +816,7 @@
}
redisUtil.set(buildInStationRouteCacheKey(findCrnNoResult, sourceStationId),
targetStationId,
- OUT_STATION_ROUTE_CACHE_SECONDS);
+ IN_STATION_ROUTE_CACHE_SECONDS);
}
private String buildInStationRouteCacheKey(FindCrnNoResult findCrnNoResult, Integer sourceStationId) {
@@ -873,4 +897,54 @@
}
}
+ private long nanosToMillis(long startNs) {
+ long elapsedNs = System.nanoTime() - startNs;
+ return elapsedNs <= 0L ? 0L : elapsedNs / 1_000_000L;
+ }
+
+ public static class InStationResolveResult {
+ private final Integer targetStationId;
+ private final boolean cacheHit;
+ private final long totalCostMs;
+ private final long searchCostMs;
+
+ private InStationResolveResult(Integer targetStationId,
+ boolean cacheHit,
+ long totalCostMs,
+ long searchCostMs) {
+ this.targetStationId = targetStationId;
+ this.cacheHit = cacheHit;
+ this.totalCostMs = totalCostMs;
+ this.searchCostMs = searchCostMs;
+ }
+
+ public static InStationResolveResult cacheHit(Integer targetStationId, long totalCostMs) {
+ return new InStationResolveResult(targetStationId, true, totalCostMs, 0L);
+ }
+
+ public static InStationResolveResult searchResult(Integer targetStationId, long totalCostMs, long searchCostMs) {
+ return new InStationResolveResult(targetStationId, false, totalCostMs, searchCostMs);
+ }
+
+ public static InStationResolveResult empty(boolean cacheHit, long totalCostMs) {
+ return new InStationResolveResult(null, cacheHit, totalCostMs, 0L);
+ }
+
+ public Integer getTargetStationId() {
+ return targetStationId;
+ }
+
+ public boolean isCacheHit() {
+ return cacheHit;
+ }
+
+ public long getTotalCostMs() {
+ return totalCostMs;
+ }
+
+ public long getSearchCostMs() {
+ return searchCostMs;
+ }
+ }
+
}
--
Gitblit v1.9.1