From a5e0d72c0a71f795e56690879a560ce715fa6313 Mon Sep 17 00:00:00 2001
From: zwl <1051256694@qq.com>
Date: 星期五, 20 三月 2026 08:54:01 +0800
Subject: [PATCH] 入库口强制入库确认后还会退回一次,才可入库修复
---
src/main/java/com/zy/core/utils/WmsOperateUtils.java | 167 ++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 151 insertions(+), 16 deletions(-)
diff --git a/src/main/java/com/zy/core/utils/WmsOperateUtils.java b/src/main/java/com/zy/core/utils/WmsOperateUtils.java
index 42e682a..e28f5ce 100644
--- a/src/main/java/com/zy/core/utils/WmsOperateUtils.java
+++ b/src/main/java/com/zy/core/utils/WmsOperateUtils.java
@@ -5,33 +5,35 @@
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.entity.*;
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.service.impl.LocMastServiceImpl;
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.cache.MessageQueue;
import com.zy.core.enums.RedisKeyType;
import com.zy.core.enums.SlaveType;
+import com.zy.core.model.Task;
+import com.zy.core.model.command.CrnCommand;
import com.zy.system.entity.Config;
import com.zy.system.service.ConfigService;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
+import java.util.UUID;
import java.util.concurrent.TimeUnit;
@Component
@@ -53,14 +55,17 @@
private BasStationService basStationService;
@Autowired
private RedisUtil redisUtil;
+ @Autowired
+ private LocMastServiceImpl locMastService;
// 鐢宠鍏ュ簱浠诲姟
- public synchronized String applyInTask(String barcode, Integer sourceStaNo, Integer locType1) {
+ public synchronized String applyInTask(String barcode, Integer sourceStaNo, Integer locType1,Double weight) {
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");
@@ -95,6 +100,8 @@
requestParam.put("sourceStaNo", stationNo);
requestParam.put("locType1", locType1);
requestParam.put("row", Utils.getInTaskEnableRow(sourceStaNo));
+ requestParam.put("ioType",1);
+ requestParam.put("weight", weight);
response = new HttpHandler.Builder()
.setUri(wmsUrl)
@@ -134,14 +141,14 @@
/**
* 寮傛鐢宠鍏ュ簱浠诲姟 - 闈為樆濉炵増鏈�
- * 灏嗚姹傛彁浜ゅ埌绾跨▼姹犲紓姝ユ墽琛岋紝缁撴灉瀛樺偍鍒癛edis涓�
*
* @param barcode 鎵樼洏鐮�
* @param sourceStaNo 绔欑偣缂栧彿
* @param locType1 鎵樼洏楂樺害
*/
- public void applyInTaskAsync(String barcode, Integer sourceStaNo, Integer locType1) {
+ public void applyInTaskAsync(String barcode, Integer sourceStaNo, Integer locType1,Double weight) {
String requestKey = RedisKeyType.ASYNC_WMS_IN_TASK_REQUEST.key + barcode + "_" + sourceStaNo;
+ String requestVersionKey = RedisKeyType.ASYNC_WMS_IN_TASK_REQUEST_VERSION.key + barcode + "_" + sourceStaNo;
String responseKey = RedisKeyType.ASYNC_WMS_IN_TASK_RESPONSE.key + barcode + "_" + sourceStaNo;
// 妫�鏌ユ槸鍚﹀凡鏈夎姹傚湪杩涜涓�
@@ -150,28 +157,42 @@
return; // 宸叉湁璇锋眰鍦ㄨ繘琛屼腑锛岃烦杩�
}
- // 鏍囪璇锋眰杩涜涓紝璁剧疆60绉掕秴鏃�
- redisUtil.set(requestKey, "processing", 60);
+ String requestId = UUID.randomUUID().toString();
+ // 鏍囪璇锋眰杩涜涓紝璁板綍褰撳墠鏈�鏂拌姹傜増鏈紝鏃ц姹傛櫄鍒版椂涓嶅厑璁歌鐩栨柊缁撴灉
+ redisUtil.set(requestKey, requestId, 120);
+ redisUtil.set(requestVersionKey, requestId, 600);
+ redisUtil.del(responseKey);
// 鎻愪氦寮傛浠诲姟
new Thread(() -> {
try {
- String response = applyInTask(barcode, sourceStaNo, locType1);
+ String response = applyInTask(barcode, sourceStaNo, locType1,weight);
+ Object latestRequestVersion = redisUtil.get(requestVersionKey);
+ if (latestRequestVersion == null || !requestId.equals(latestRequestVersion.toString())) {
+ News.info("蹇界暐杩囨湡寮傛WMS鍏ュ簱鍝嶅簲锛宐arcode={}锛宻tationId={}锛宺equestId={}", barcode, sourceStaNo, requestId);
+ return;
+ }
if (response != null) {
// 瀛樺偍鍝嶅簲缁撴灉锛岃缃�60绉掕秴鏃�
redisUtil.set(responseKey, response, 60);
- News.info("寮傛WMS鍏ュ簱璇锋眰瀹屾垚锛宐arcode={}锛宻tationId={}锛宺esponse={}", barcode, sourceStaNo, response);
+ News.info("寮傛WMS鍏ュ簱璇锋眰瀹屾垚锛宐arcode={}锛宻tationId={}锛宺esponse={},weight={}", barcode, sourceStaNo, response,weight);
} else {
// 璇锋眰澶辫触锛屽瓨鍌ㄥけ璐ユ爣璁�
redisUtil.set(responseKey, "FAILED", 10);
- News.error("寮傛WMS鍏ュ簱璇锋眰澶辫触锛宐arcode={}锛宻tationId={}", barcode, sourceStaNo);
+ News.error("寮傛WMS鍏ュ簱璇锋眰澶辫触锛宐arcode={}锛宻tationId={},weight={}", barcode, sourceStaNo,weight);
}
} catch (Exception e) {
- News.error("寮傛WMS鍏ュ簱璇锋眰寮傚父锛宐arcode={}锛宻tationId={}锛宔rror={}", barcode, sourceStaNo, e.getMessage());
- redisUtil.set(responseKey, "ERROR:" + e.getMessage(), 10);
+ News.error("寮傛WMS鍏ュ簱璇锋眰寮傚父锛宐arcode={}锛宻tationId={}锛宔rror={},weight={}", barcode, sourceStaNo, e.getMessage(),weight);
+ Object latestRequestVersion = redisUtil.get(requestVersionKey);
+ if (latestRequestVersion != null && requestId.equals(latestRequestVersion.toString())) {
+ redisUtil.set(responseKey, "ERROR:" + e.getMessage(), 10);
+ }
} finally {
// 娓呴櫎璇锋眰杩涜涓爣璁�
- redisUtil.del(requestKey);
+ Object currentRequest = redisUtil.get(requestKey);
+ if (currentRequest != null && requestId.equals(currentRequest.toString())) {
+ redisUtil.del(requestKey);
+ }
}
}).start();
}
@@ -204,6 +225,15 @@
public boolean isAsyncRequestInProgress(String barcode, Integer stationId) {
String requestKey = RedisKeyType.ASYNC_WMS_IN_TASK_REQUEST.key + barcode + "_" + stationId;
return redisUtil.get(requestKey) != null;
+ }
+
+ public void clearAsyncInTaskCache(String barcode, Integer stationId) {
+ String cacheSuffix = barcode + "_" + stationId;
+ redisUtil.del(
+ RedisKeyType.ASYNC_WMS_IN_TASK_REQUEST.key + cacheSuffix,
+ RedisKeyType.ASYNC_WMS_IN_TASK_REQUEST_VERSION.key + cacheSuffix,
+ RedisKeyType.ASYNC_WMS_IN_TASK_RESPONSE.key + cacheSuffix
+ );
}
// 鐢宠浠诲姟閲嶆柊鍒嗛厤搴撲綅
@@ -388,4 +418,109 @@
return response;
}
+ @Async
+ public void reportCrnDb110StatusAsync(Integer crnNo, List<Integer> indices) {
+ try {
+ if (crnNo == null || indices == null || indices.isEmpty()) {
+ return;
+ }
+ reportCrnDb110Status(crnNo, indices);
+ } catch (Exception e) {
+ News.error("寮傛涓婃姤鍫嗗灈鏈篋B110鐘舵�佸紓甯革紝crnNo={}锛宨ndices={}", crnNo, JSON.toJSONString(indices), e);
+ } finally {
+ if (crnNo != null) {
+ redisUtil.del(RedisKeyType.REPORT_CRN_DB110_STATUS_LIMIT.key + crnNo);
+ }
+ }
+ }
+
+ // 涓婃姤鍫嗗灈鏈篋B110鐘舵�佹暟鎹�
+ public void reportCrnDb110Status(Integer crnNo, List<Integer> indices) {
+ Object systemConfigMapObj = redisUtil.get(RedisKeyType.SYSTEM_CONFIG_MAP.key);
+ if (systemConfigMapObj == null) {
+ News.error("绯荤粺Config缂撳瓨澶辨晥");
+ return;
+ }
+ HashMap<String, String> systemConfigMap = (HashMap<String, String>) systemConfigMapObj;
+
+ String wmsUrl = systemConfigMap.get("wmsSystemUri");
+ if (wmsUrl == null) {
+ News.error("鏈厤缃甒MS绯荤粺URI锛岄厤缃枃浠禖ode缂栫爜锛歸msSystemUri");
+ return;
+ }
+
+ String wmsSystemCrnStatusUrl = systemConfigMap.get("wmsSystemCrnStatusUrl");
+ if (wmsSystemCrnStatusUrl == null) {
+ News.error("鏈厤缃甒MS鍫嗗灈鏈虹姸鎬佷笂鎶ユ帴鍙e湴鍧�锛岄厤缃枃浠禖ode缂栫爜锛歸msSystemCrnStatusUrl");
+ return;
+ }
+
+ String response = null;
+ int result = 0;
+ BasCrnp crnNo1 = basCrnpService.selectOne(new EntityWrapper<BasCrnp>().eq("crn_no", crnNo));
+ if (crnNo1 == null) {
+ return;
+ }
+ // 鏍规嵁indices涓嬫爣浠巆rnNo1鐨刟rr鏁扮粍涓彇鍑哄搴斿��
+ String[] split = crnNo1.getArr().split(",");
+ for (Integer idx : indices) {
+ LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", split[idx]));
+ if (locMast == null||Cools.isEmpty(locMast.getBarcode())||locMast.getLocSts().equals("O")) {
+ News.info("娌℃湁鏌ヨ鍒拌搴撲綅鎴栬�呮病鏈夋壘鍒拌搴撲綅瀵瑰簲鎵樼洏鐮� 锛歿}", split[idx]);
+ CrnCommand command = new CrnCommand();
+ command.setLocNo(locMast.getLocNo());
+ command.setIndex(idx);
+ command.setValue((short)0);
+ MessageQueue.offer(SlaveType.Crn, crnNo, new Task(5, command));
+ continue;
+ }
+ try {
+ response = new HttpHandler.Builder()
+ .setUri(wmsUrl)
+ .setPath(wmsSystemCrnStatusUrl)
+ .setJson(locMast.getBarcode())
+ .setTimeout(30, TimeUnit.SECONDS)
+ .build()
+ .doPost();
+ if (response != null) {
+ JSONObject jsonObject = JSON.parseObject(response);
+ if (jsonObject.getInteger("code") == 200) {
+ result = 1;
+ CrnCommand command = new CrnCommand();
+ command.setLocNo(locMast.getLocNo());
+ command.setIndex(idx);
+ command.setValue((short)2);
+ MessageQueue.offer(SlaveType.Crn, crnNo, new Task(5, command));
+
+ News.info("璇锋眰WMS鍫嗗灈鏈虹姸鎬佷笂鎶ユ帴鍙f垚鍔燂紒锛侊紒url锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + wmsSystemCrnStatusUrl,
+ JSON.toJSONString(locMast.getBarcode()), response);
+ } else {
+ result = 0;
+ CrnCommand command = new CrnCommand();
+ command.setLocNo(locMast.getLocNo());
+ command.setIndex(idx);
+ command.setValue((short)0);
+ MessageQueue.offer(SlaveType.Crn, crnNo, new Task(5, command));
+ News.info("璇锋眰WMS鍫嗗灈鏈虹姸鎬佷笂鎶ユ帴鍙eけ璐ワ紝鎺ュ彛杩斿洖Code寮傚父锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}",
+ wmsUrl + wmsSystemCrnStatusUrl, JSON.toJSONString(locMast.getBarcode()), response);
+ }
+ } else {
+ News.info("璇锋眰WMS鍫嗗灈鏈虹姸鎬佷笂鎶ユ帴鍙eけ璐ワ紝鎺ュ彛鏈搷搴旓紒锛侊紒url锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + wmsSystemCrnStatusUrl,
+ JSON.toJSONString(locMast.getBarcode()), response);
+ }
+ } catch (Exception e) {
+ News.error("璇锋眰WMS鍫嗗灈鏈虹姸鎬佷笂鎶ユ帴鍙e紓甯革紒锛侊紒url锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + wmsSystemCrnStatusUrl,
+ JSON.toJSONString(locMast.getBarcode()), response, e);
+ } finally {
+ HttpRequestLog httpRequestLog = new HttpRequestLog();
+ httpRequestLog.setName(wmsUrl + wmsSystemCrnStatusUrl);
+ httpRequestLog.setRequest(JSON.toJSONString(locMast.getBarcode()));
+ httpRequestLog.setResponse(response);
+ httpRequestLog.setCreateTime(new Date());
+ httpRequestLog.setResult(result);
+ httpRequestLogService.insert(httpRequestLog);
+ }
+ }
+
+ }
}
--
Gitblit v1.9.1