From a2eb2511f620956dbb5d36742f1d0ffda034f090 Mon Sep 17 00:00:00 2001
From: Junjie <DELL@qq.com>
Date: 星期四, 15 一月 2026 16:07:28 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/utils/WmsOperateUtils.java | 258 ++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 214 insertions(+), 44 deletions(-)
diff --git a/src/main/java/com/zy/core/utils/WmsOperateUtils.java b/src/main/java/com/zy/core/utils/WmsOperateUtils.java
index 78e193b..42e682a 100644
--- a/src/main/java/com/zy/core/utils/WmsOperateUtils.java
+++ b/src/main/java/com/zy/core/utils/WmsOperateUtils.java
@@ -1,20 +1,28 @@
package com.zy.core.utils;
import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.Cools;
import com.core.exception.CoolException;
import com.zy.asrs.entity.BasCrnp;
+import com.zy.asrs.entity.BasDualCrnp;
+import com.zy.asrs.entity.BasStation;
import com.zy.asrs.entity.HttpRequestLog;
import com.zy.asrs.entity.WrkMast;
import com.zy.asrs.service.BasCrnpService;
+import com.zy.asrs.service.BasDualCrnpService;
+import com.zy.asrs.service.BasStationService;
import com.zy.asrs.service.HttpRequestLogService;
import com.zy.asrs.service.WrkMastService;
import com.zy.asrs.utils.Utils;
+import com.zy.common.entity.FindCrnNoResult;
import com.zy.common.service.CommonService;
import com.zy.common.utils.HttpHandler;
+import com.zy.common.utils.RedisUtil;
import com.zy.core.News;
+import com.zy.core.enums.RedisKeyType;
+import com.zy.core.enums.SlaveType;
import com.zy.system.entity.Config;
import com.zy.system.service.ConfigService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -39,62 +47,167 @@
private CommonService commonService;
@Autowired
private BasCrnpService basCrnpService;
+ @Autowired
+ private BasDualCrnpService basDualCrnpService;
+ @Autowired
+ private BasStationService basStationService;
+ @Autowired
+ private RedisUtil redisUtil;
- //鐢宠鍏ュ簱浠诲姟
+ // 鐢宠鍏ュ簱浠诲姟
public synchronized String applyInTask(String barcode, Integer sourceStaNo, Integer locType1) {
- String wmsUrl = null;
- Config wmsSystemUriConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "wmsSystemUri"));
- if (wmsSystemUriConfig != null) {
- wmsUrl = wmsSystemUriConfig.getValue();
+ Object systemConfigMapObj = redisUtil.get(RedisKeyType.SYSTEM_CONFIG_MAP.key);
+ if (systemConfigMapObj == null) {
+ News.error("绯荤粺Config缂撳瓨澶辨晥");
+ return null;
}
+ HashMap<String, String> systemConfigMap = (HashMap<String, String>) systemConfigMapObj;
+ String wmsUrl = systemConfigMap.get("wmsSystemUri");
if (wmsUrl == null) {
News.error("鏈厤缃甒MS绯荤粺URI锛岄厤缃枃浠禖ode缂栫爜锛歸msSystemUri");
return null;
}
- String wmsSystemInUrl = null;
- Config wmsSystemInUrlConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "wmsSystemInUrl"));
- if (wmsSystemInUrlConfig != null) {
- wmsSystemInUrl = wmsSystemInUrlConfig.getValue();
- }
-
- if(wmsSystemInUrlConfig == null){
+ String wmsSystemInUrl = systemConfigMap.get("wmsSystemInUrl");
+ if (wmsSystemInUrl == null) {
News.error("鏈厤缃甒MS鍏ュ簱鎺ュ彛鍦板潃锛岄厤缃枃浠禖ode缂栫爜锛歸msSystemInUrl");
return null;
}
HashMap<String, Object> requestParam = new HashMap<>();
String response = null;
+ int result = 0;
try {
+ BasStation basStation = basStationService
+ .selectOne(new EntityWrapper<BasStation>().eq("station_id", sourceStaNo));
+ if (basStation == null) {
+ News.error("绔欑偣{}涓嶅瓨鍦�", sourceStaNo);
+ return null;
+ }
+
+ String stationNo = String.valueOf(sourceStaNo);
+ if (!Cools.isEmpty(basStation.getStationAlias())) {
+ stationNo = basStation.getStationAlias();
+ }
+
requestParam.put("barcode", barcode);
- requestParam.put("sourceStaNo", sourceStaNo);
+ requestParam.put("sourceStaNo", stationNo);
requestParam.put("locType1", locType1);
- requestParam.put("row", Utils.getInTaskEnableRow());
+ requestParam.put("row", Utils.getInTaskEnableRow(sourceStaNo));
response = new HttpHandler.Builder()
.setUri(wmsUrl)
.setPath(wmsSystemInUrl)
.setJson(JSON.toJSONString(requestParam))
- .setTimeout(360, TimeUnit.SECONDS)
+ .setTimeout(30, TimeUnit.SECONDS)
.build()
.doPost();
- News.info("璇锋眰WMS鍏ュ簱鎺ュ彛鎴愬姛锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + wmsSystemInUrl, JSON.toJSONString(requestParam), response);
+ if (response != null) {
+ JSONObject jsonObject = JSON.parseObject(response);
+ if (jsonObject.getInteger("code") == 200) {
+ result = 1;
+ News.info("璇锋眰WMS鍏ュ簱鎺ュ彛鎴愬姛锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + wmsSystemInUrl,
+ JSON.toJSONString(requestParam), response);
+ } else {
+ News.info("璇锋眰WMS鍏ュ簱鎺ュ彛澶辫触锛屾帴鍙h繑鍥濩ode寮傚父锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + wmsSystemInUrl,
+ JSON.toJSONString(requestParam), response);
+ }
+ } else {
+ News.info("璇锋眰WMS鍏ュ簱鎺ュ彛澶辫触锛屾帴鍙f湭鍝嶅簲锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + wmsSystemInUrl,
+ JSON.toJSONString(requestParam), response);
+ }
} catch (Exception e) {
- News.error("璇锋眰WMS鍏ュ簱鎺ュ彛寮傚父锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + wmsSystemInUrl, JSON.toJSONString(requestParam), response, e);
+ News.error("璇锋眰WMS鍏ュ簱鎺ュ彛寮傚父锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + wmsSystemInUrl,
+ JSON.toJSONString(requestParam), response, e);
} finally {
HttpRequestLog httpRequestLog = new HttpRequestLog();
httpRequestLog.setName(wmsUrl + wmsSystemInUrl);
httpRequestLog.setRequest(JSON.toJSONString(requestParam));
httpRequestLog.setResponse(response);
httpRequestLog.setCreateTime(new Date());
+ httpRequestLog.setResult(result);
httpRequestLogService.insert(httpRequestLog);
}
return response;
}
- //鐢宠浠诲姟閲嶆柊鍒嗛厤搴撲綅
- public synchronized String applyReassignTaskLocNo(Integer taskNo) {
+ /**
+ * 寮傛鐢宠鍏ュ簱浠诲姟 - 闈為樆濉炵増鏈�
+ * 灏嗚姹傛彁浜ゅ埌绾跨▼姹犲紓姝ユ墽琛岋紝缁撴灉瀛樺偍鍒癛edis涓�
+ *
+ * @param barcode 鎵樼洏鐮�
+ * @param sourceStaNo 绔欑偣缂栧彿
+ * @param locType1 鎵樼洏楂樺害
+ */
+ public void applyInTaskAsync(String barcode, Integer sourceStaNo, Integer locType1) {
+ String requestKey = RedisKeyType.ASYNC_WMS_IN_TASK_REQUEST.key + barcode + "_" + sourceStaNo;
+ String responseKey = RedisKeyType.ASYNC_WMS_IN_TASK_RESPONSE.key + barcode + "_" + sourceStaNo;
+
+ // 妫�鏌ユ槸鍚﹀凡鏈夎姹傚湪杩涜涓�
+ Object existingRequest = redisUtil.get(requestKey);
+ if (existingRequest != null) {
+ return; // 宸叉湁璇锋眰鍦ㄨ繘琛屼腑锛岃烦杩�
+ }
+
+ // 鏍囪璇锋眰杩涜涓紝璁剧疆60绉掕秴鏃�
+ redisUtil.set(requestKey, "processing", 60);
+
+ // 鎻愪氦寮傛浠诲姟
+ new Thread(() -> {
+ try {
+ String response = applyInTask(barcode, sourceStaNo, locType1);
+ if (response != null) {
+ // 瀛樺偍鍝嶅簲缁撴灉锛岃缃�60绉掕秴鏃�
+ redisUtil.set(responseKey, response, 60);
+ News.info("寮傛WMS鍏ュ簱璇锋眰瀹屾垚锛宐arcode={}锛宻tationId={}锛宺esponse={}", barcode, sourceStaNo, response);
+ } else {
+ // 璇锋眰澶辫触锛屽瓨鍌ㄥけ璐ユ爣璁�
+ redisUtil.set(responseKey, "FAILED", 10);
+ News.error("寮傛WMS鍏ュ簱璇锋眰澶辫触锛宐arcode={}锛宻tationId={}", barcode, sourceStaNo);
+ }
+ } catch (Exception e) {
+ News.error("寮傛WMS鍏ュ簱璇锋眰寮傚父锛宐arcode={}锛宻tationId={}锛宔rror={}", barcode, sourceStaNo, e.getMessage());
+ redisUtil.set(responseKey, "ERROR:" + e.getMessage(), 10);
+ } finally {
+ // 娓呴櫎璇锋眰杩涜涓爣璁�
+ redisUtil.del(requestKey);
+ }
+ }).start();
+ }
+
+ /**
+ * 鏌ヨ寮傛鍏ュ簱浠诲姟璇锋眰缁撴灉
+ *
+ * @param barcode 鎵樼洏鐮�
+ * @param stationId 绔欑偣缂栧彿
+ * @return 鍝嶅簲缁撴灉锛宯ull琛ㄧず杩樻湭瀹屾垚鎴栨湭鎵惧埌
+ */
+ public String queryAsyncInTaskResponse(String barcode, Integer stationId) {
+ String responseKey = RedisKeyType.ASYNC_WMS_IN_TASK_RESPONSE.key + barcode + "_" + stationId;
+ Object response = redisUtil.get(responseKey);
+ if (response != null) {
+ // 鑾峰彇鍚庡垹闄わ紝閬垮厤閲嶅澶勭悊
+ redisUtil.del(responseKey);
+ return response.toString();
+ }
+ return null;
+ }
+
+ /**
+ * 妫�鏌ユ槸鍚︽湁寮傛璇锋眰姝e湪杩涜涓�
+ *
+ * @param barcode 鎵樼洏鐮�
+ * @param stationId 绔欑偣缂栧彿
+ * @return true琛ㄧず姝e湪璇锋眰涓�
+ */
+ public boolean isAsyncRequestInProgress(String barcode, Integer stationId) {
+ String requestKey = RedisKeyType.ASYNC_WMS_IN_TASK_REQUEST.key + barcode + "_" + stationId;
+ return redisUtil.get(requestKey) != null;
+ }
+
+ // 鐢宠浠诲姟閲嶆柊鍒嗛厤搴撲綅
+ public synchronized String applyReassignTaskLocNo(Integer taskNo, Integer stationId) {
String wmsUrl = null;
Config wmsSystemUriConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "wmsSystemUri"));
if (wmsSystemUriConfig != null) {
@@ -107,12 +220,13 @@
}
String wmsSystemReassignInTaskUrl = null;
- Config wmsSystemReassignInTaskUrlConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "wmsSystemReassignInTaskUrl"));
+ Config wmsSystemReassignInTaskUrlConfig = configService
+ .selectOne(new EntityWrapper<Config>().eq("code", "wmsSystemReassignInTaskUrl"));
if (wmsSystemReassignInTaskUrlConfig != null) {
wmsSystemReassignInTaskUrl = wmsSystemReassignInTaskUrlConfig.getValue();
}
- if(wmsSystemReassignInTaskUrl == null){
+ if (wmsSystemReassignInTaskUrl == null) {
News.error("鏈厤缃甒MS浠诲姟閲嶆柊鍒嗛厤鍏ュ簱搴撲綅鎺ュ彛鍦板潃锛岄厤缃枃浠禖ode缂栫爜锛歸msSystemReassignInTaskUrl");
return null;
}
@@ -125,32 +239,57 @@
HashMap<String, Object> requestParam = new HashMap<>();
String response = null;
+ int result = 0;
try {
+ List<Integer> excludeCrnList = new ArrayList<>();
+ List<Integer> excludeDualCrnList = new ArrayList<>();
+ if (!Cools.isEmpty(wrkMast.getCrnNo())) {
+ excludeCrnList.add(wrkMast.getCrnNo());
+ }
+ if (!Cools.isEmpty(wrkMast.getDualCrnNo())) {
+ excludeDualCrnList.add(wrkMast.getDualCrnNo());
+ }
+
requestParam.put("taskNo", wrkMast.getWmsWrkNo());
- requestParam.put("row", Utils.getInTaskEnableRow(new ArrayList<>(wrkMast.getCrnNo())));
+ requestParam.put("row", Utils.getInTaskEnableRow(stationId, excludeCrnList, excludeDualCrnList, false));
response = new HttpHandler.Builder()
.setUri(wmsUrl)
.setPath(wmsSystemReassignInTaskUrl)
.setJson(JSON.toJSONString(requestParam))
- .setTimeout(360, TimeUnit.SECONDS)
+ .setTimeout(30, TimeUnit.SECONDS)
.build()
.doPost();
- News.info("璇锋眰鐢宠浠诲姟閲嶆柊鍒嗛厤鍏ュ簱鎺ュ彛鎴愬姛锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + wmsSystemReassignInTaskUrl, JSON.toJSONString(requestParam), response);
+ if (response != null) {
+ JSONObject jsonObject = JSON.parseObject(response);
+ if (jsonObject.getInteger("code") == 200) {
+ result = 1;
+ News.info("璇锋眰鐢宠浠诲姟閲嶆柊鍒嗛厤鍏ュ簱鎺ュ彛鎴愬姛锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + wmsSystemReassignInTaskUrl,
+ JSON.toJSONString(requestParam), response);
+ } else {
+ News.info("璇锋眰鐢宠浠诲姟閲嶆柊鍒嗛厤鍏ュ簱鎺ュ彛澶辫触锛屾帴鍙h繑鍥濩ode寮傚父锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}",
+ wmsUrl + wmsSystemReassignInTaskUrl, JSON.toJSONString(requestParam), response);
+ }
+ } else {
+ News.info("璇锋眰鐢宠浠诲姟閲嶆柊鍒嗛厤鍏ュ簱鎺ュ彛澶辫触锛屾帴鍙f湭鍝嶅簲锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + wmsSystemReassignInTaskUrl,
+ JSON.toJSONString(requestParam), response);
+ }
} catch (Exception e) {
- News.error("璇锋眰鐢宠浠诲姟閲嶆柊鍒嗛厤鍏ュ簱鎺ュ彛寮傚父锛侊紒锛乽rl锛歿}锛況equest锛歿}锛� response锛歿}", wmsUrl + wmsSystemReassignInTaskUrl, JSON.toJSONString(requestParam), response, e);
+ News.error("璇锋眰鐢宠浠诲姟閲嶆柊鍒嗛厤鍏ュ簱鎺ュ彛寮傚父锛侊紒锛乽rl锛歿}锛況equest锛歿}锛� response锛歿}", wmsUrl + wmsSystemReassignInTaskUrl,
+ JSON.toJSONString(requestParam), response, e);
} finally {
HttpRequestLog httpRequestLog = new HttpRequestLog();
httpRequestLog.setName(wmsUrl + wmsSystemReassignInTaskUrl);
httpRequestLog.setRequest(JSON.toJSONString(requestParam));
httpRequestLog.setResponse(response);
httpRequestLog.setCreateTime(new Date());
+ httpRequestLog.setResult(result);
httpRequestLogService.insert(httpRequestLog);
}
return response;
}
- //鐢宠鍦ㄥ簱搴撲綅鏇存崲搴撲綅
+ // 鐢宠鍦ㄥ簱搴撲綅鏇存崲搴撲綅
public synchronized String applyChangeLocNo(String locNo) {
String wmsUrl = null;
Config wmsSystemUriConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "wmsSystemUri"));
@@ -164,33 +303,50 @@
}
String wmsSystemChangeLocNoUrl = null;
- Config wmsSystemChangeLocNoUrlConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "wmsSystemChangeLocNoUrl"));
+ Config wmsSystemChangeLocNoUrlConfig = configService
+ .selectOne(new EntityWrapper<Config>().eq("code", "wmsSystemChangeLocNoUrl"));
if (wmsSystemChangeLocNoUrlConfig != null) {
wmsSystemChangeLocNoUrl = wmsSystemChangeLocNoUrlConfig.getValue();
}
- if(wmsSystemChangeLocNoUrl == null){
+ if (wmsSystemChangeLocNoUrl == null) {
News.error("鏈厤缃敵璇峰湪搴撳簱浣嶆洿鎹㈠簱浣嶆帴鍙e湴鍧�锛岄厤缃枃浠禖ode缂栫爜锛歸msSystemChangeLocNoUrl");
return null;
}
- Integer crnNo = commonService.findCrnNoByLocNo(locNo);
- if (crnNo == null) {
+ FindCrnNoResult findCrnNoResult = commonService.findCrnNoByLocNo(locNo);
+ if (findCrnNoResult == null) {
return null;
}
- BasCrnp basCrnp = basCrnpService.selectOne(new EntityWrapper<BasCrnp>().eq("crn_no", crnNo));
- if (basCrnp == null) {
- return null;
- }
-
+ Integer crnNo = findCrnNoResult.getCrnNo();
List<Integer> crnRows = new ArrayList<>();
- List<List<Integer>> rowList = basCrnp.getControlRows$();
- for (List<Integer> list : rowList) {
- crnRows.addAll(list);
+
+ if (findCrnNoResult.getCrnType().equals(SlaveType.Crn)) {
+ BasCrnp basCrnp = basCrnpService.selectOne(new EntityWrapper<BasCrnp>().eq("crn_no", crnNo));
+ if (basCrnp == null) {
+ return null;
+ }
+ List<List<Integer>> rowList = basCrnp.getControlRows$();
+ for (List<Integer> list : rowList) {
+ crnRows.addAll(list);
+ }
+ } else if (findCrnNoResult.getCrnType().equals(SlaveType.DualCrn)) {
+ BasDualCrnp basDualCrnp = basDualCrnpService
+ .selectOne(new EntityWrapper<BasDualCrnp>().eq("crn_no", crnNo));
+ if (basDualCrnp == null) {
+ return null;
+ }
+ List<List<Integer>> rowList = basDualCrnp.getControlRows$();
+ for (List<Integer> list : rowList) {
+ crnRows.addAll(list);
+ }
+ } else {
+ throw new CoolException("鏈煡璁惧绫诲瀷");
}
HashMap<String, Object> requestParam = new HashMap<>();
String response = null;
+ int result = 0;
try {
requestParam.put("locNo", locNo);
requestParam.put("row", crnRows);
@@ -199,23 +355,37 @@
.setUri(wmsUrl)
.setPath(wmsSystemChangeLocNoUrl)
.setJson(JSON.toJSONString(requestParam))
- .setTimeout(360, TimeUnit.SECONDS)
+ .setTimeout(30, TimeUnit.SECONDS)
.build()
.doPost();
- News.info("璇锋眰WMS鐢宠鏇存崲搴撲綅鎺ュ彛鎴愬姛锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + wmsSystemChangeLocNoUrl, JSON.toJSONString(requestParam), response);
- return response;
+ if (response != null) {
+ JSONObject jsonObject = JSON.parseObject(response);
+ if (jsonObject.getInteger("code") == 200) {
+ result = 1;
+ News.info("璇锋眰WMS鐢宠鏇存崲搴撲綅鎺ュ彛鎴愬姛锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + wmsSystemChangeLocNoUrl,
+ JSON.toJSONString(requestParam), response);
+ } else {
+ News.info("璇锋眰WMS鐢宠鏇存崲搴撲綅鎺ュ彛澶辫触锛屾帴鍙h繑鍥濩ode寮傚父锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}",
+ wmsUrl + wmsSystemChangeLocNoUrl, JSON.toJSONString(requestParam), response);
+ }
+ } else {
+ News.info("璇锋眰WMS鐢宠鏇存崲搴撲綅鎺ュ彛澶辫触锛屾帴鍙f湭鍝嶅簲锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + wmsSystemChangeLocNoUrl,
+ JSON.toJSONString(requestParam), response);
+ }
} catch (Exception e) {
- News.error("璇锋眰WMS鐢宠鏇存崲搴撲綅鎺ュ彛寮傚父锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + wmsSystemChangeLocNoUrl, JSON.toJSONString(requestParam), response, e);
+ News.error("璇锋眰WMS鐢宠鏇存崲搴撲綅鎺ュ彛寮傚父锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + wmsSystemChangeLocNoUrl,
+ JSON.toJSONString(requestParam), response, e);
} finally {
HttpRequestLog httpRequestLog = new HttpRequestLog();
httpRequestLog.setName(wmsUrl + wmsSystemChangeLocNoUrl);
httpRequestLog.setRequest(JSON.toJSONString(requestParam));
httpRequestLog.setResponse(response);
httpRequestLog.setCreateTime(new Date());
+ httpRequestLog.setResult(result);
httpRequestLogService.insert(httpRequestLog);
}
- return null;
+ return response;
}
}
--
Gitblit v1.9.1