From 2fe0faeef380c33b5dc56682ee816478971122d2 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期三, 01 四月 2026 16:43:15 +0800
Subject: [PATCH] #入库任务优化
---
src/main/java/com/zy/core/utils/WmsOperateUtils.java | 51 +++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 49 insertions(+), 2 deletions(-)
diff --git a/src/main/java/com/zy/core/utils/WmsOperateUtils.java b/src/main/java/com/zy/core/utils/WmsOperateUtils.java
index 2edc720..358a9e0 100644
--- a/src/main/java/com/zy/core/utils/WmsOperateUtils.java
+++ b/src/main/java/com/zy/core/utils/WmsOperateUtils.java
@@ -68,7 +68,12 @@
}
public String applyInTask(InTaskApplyRequest request) {
+ long startMs = System.currentTimeMillis();
+ Map<String, Long> stepCostMap = new LinkedHashMap<>();
+
+ long redisGetStartNs = System.nanoTime();
Object systemConfigMapObj = redisUtil.get(RedisKeyType.SYSTEM_CONFIG_MAP.key);
+ addStepCost(stepCostMap, "redisUtil.get", elapsedMsFromNano(redisGetStartNs));
if (systemConfigMapObj == null) {
News.error("绯荤粺Config缂撳瓨澶辨晥");
return null;
@@ -90,10 +95,11 @@
Map<String, Object> requestParam = new LinkedHashMap<>();
String response = null;
int result = 0;
- long startMs = System.currentTimeMillis();
try {
+ long stationQueryStartNs = System.nanoTime();
BasStation basStation = basStationService
.getOne(new QueryWrapper<BasStation>().eq("station_id", request.getSourceStaNo()));
+ addStepCost(stepCostMap, "basStationService.getOne", elapsedMsFromNano(stationQueryStartNs));
if (basStation == null) {
News.error("绔欑偣{}涓嶅瓨鍦�", request.getSourceStaNo());
return null;
@@ -107,11 +113,14 @@
requestParam.put("barcode", request.getBarcode());
requestParam.put("sourceStaNo", stationNo);
requestParam.put("locType1", request.getLocType1() == null ? 1 : request.getLocType1());
+ long getRowStartNs = System.nanoTime();
requestParam.put("row", Utils.getInTaskEnableRowWithCache(request.getSourceStaNo()));
+ addStepCost(stepCostMap, "Utils.getInTaskEnableRowWithCache", elapsedMsFromNano(getRowStartNs));
if (request.getExtraParams() != null && !request.getExtraParams().isEmpty()) {
requestParam.putAll(request.getExtraParams());
}
+ long httpPostStartNs = System.nanoTime();
response = new HttpHandler.Builder()
.setUri(wmsUrl)
.setPath(wmsSystemInUrl)
@@ -119,8 +128,11 @@
.setTimeout(APPLY_IN_TASK_TIMEOUT_SECONDS, TimeUnit.SECONDS)
.build()
.doPost();
+ addStepCost(stepCostMap, "HttpHandler.doPost", elapsedMsFromNano(httpPostStartNs));
if (!Cools.isEmpty(response)) {
+ long parseResponseStartNs = System.nanoTime();
JSONObject jsonObject = JSON.parseObject(response);
+ addStepCost(stepCostMap, "JSON.parseObject", elapsedMsFromNano(parseResponseStartNs));
if (jsonObject.getInteger("code") == 200) {
result = 1;
News.info("璇锋眰WMS鍏ュ簱鎺ュ彛鎴愬姛锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}锛沜ost={}ms",
@@ -143,7 +155,15 @@
httpRequestLog.setResponse(response);
httpRequestLog.setCreateTime(new Date());
httpRequestLog.setResult(result);
- httpRequestLogService.save(httpRequestLog);
+ long saveRequestLogStartNs = System.nanoTime();
+ try {
+ httpRequestLogService.save(httpRequestLog);
+ } finally {
+ addStepCost(stepCostMap, "httpRequestLogService.save", elapsedMsFromNano(saveRequestLogStartNs));
+ News.info("WMS鍏ュ簱鐢宠鑰楁椂缁熻锛歶rl锛歿}锛沚arcode锛歿}锛泂ourceStaNo锛歿}锛泂tepCosts锛歿}锛泂lowestStep锛歿}锛泃otalCost={}ms",
+ wmsUrl + wmsSystemInUrl, request.getBarcode(), request.getSourceStaNo(),
+ formatStepCosts(stepCostMap), getSlowestStep(stepCostMap), elapsedMs(startMs));
+ }
}
return response;
}
@@ -344,4 +364,31 @@
return System.currentTimeMillis() - startMs;
}
+ private long elapsedMsFromNano(long startNs) {
+ return TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNs);
+ }
+
+ private void addStepCost(Map<String, Long> stepCostMap, String stepName, long costMs) {
+ stepCostMap.put(stepName, costMs);
+ }
+
+ private String formatStepCosts(Map<String, Long> stepCostMap) {
+ return JSON.toJSONString(stepCostMap);
+ }
+
+ private String getSlowestStep(Map<String, Long> stepCostMap) {
+ String slowestStepName = "-";
+ long maxCostMs = -1L;
+ for (Map.Entry<String, Long> entry : stepCostMap.entrySet()) {
+ if (entry.getValue() != null && entry.getValue() > maxCostMs) {
+ slowestStepName = entry.getKey();
+ maxCostMs = entry.getValue();
+ }
+ }
+ if (maxCostMs < 0) {
+ return "-";
+ }
+ return slowestStepName + "=" + maxCostMs + "ms";
+ }
+
}
--
Gitblit v1.9.1