From 40dcac7c694867a4b66a9c8567cd2fe6959a25df Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期三, 06 五月 2026 08:51:05 +0800
Subject: [PATCH] #请求入库任务提示优化
---
src/main/java/com/zy/core/plugin/store/StoreInTaskGenerationService.java | 208 ++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 203 insertions(+), 5 deletions(-)
diff --git a/src/main/java/com/zy/core/plugin/store/StoreInTaskGenerationService.java b/src/main/java/com/zy/core/plugin/store/StoreInTaskGenerationService.java
index 491b9f9..9c54f23 100644
--- a/src/main/java/com/zy/core/plugin/store/StoreInTaskGenerationService.java
+++ b/src/main/java/com/zy/core/plugin/store/StoreInTaskGenerationService.java
@@ -6,16 +6,20 @@
import com.core.common.Cools;
import com.zy.asrs.domain.param.CreateInTaskParam;
import com.zy.asrs.entity.BasDevp;
+import com.zy.asrs.entity.WrkLastno;
import com.zy.asrs.entity.WrkMast;
+import com.zy.asrs.service.WrkLastnoService;
import com.zy.asrs.service.WrkMastService;
import com.zy.common.model.StartupDto;
import com.zy.common.service.CommonService;
import com.zy.common.utils.RedisUtil;
import com.zy.core.News;
import com.zy.core.cache.SlaveConnection;
-import com.zy.core.enums.RedisKeyType;
-import com.zy.core.enums.SlaveType;
+import com.zy.core.dispatch.StationCommandDispatchResult;
+import com.zy.core.dispatch.StationCommandDispatcher;
+import com.zy.core.enums.*;
import com.zy.core.model.StationObjModel;
+import com.zy.core.model.command.StationCommand;
import com.zy.core.model.protocol.StationProtocol;
import com.zy.core.task.MainProcessLane;
import com.zy.core.task.MainProcessTaskSubmitter;
@@ -26,11 +30,13 @@
import org.springframework.stereotype.Service;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
@Service
public class StoreInTaskGenerationService {
private static final int APPLY_IN_TASK_TIMEOUT_SECONDS = 5;
+ private static final int APPLY_FAIL_STATION_BACK_LOCK_SECONDS = 30;
@Autowired
private WrkMastService wrkMastService;
@@ -44,6 +50,10 @@
private CommonService commonService;
@Autowired
private MainProcessTaskSubmitter mainProcessTaskSubmitter;
+ @Autowired
+ private StationCommandDispatcher stationCommandDispatcher;
+ @Autowired
+ private WrkLastnoService wrkLastnoService;
/**
* 淇濈暀褰撳墠鎸夌珯鐐� lane 骞跺彂鐨勮兘鍔涳紝鍚屾椂鐢ㄤ竴涓畝鍗曡鏁伴伩鍏嶅苟鍙戠敓鎴愭妸绔欑偣浠诲姟鏁伴《绌夸笂闄愩��
@@ -53,6 +63,11 @@
public void generate(StoreInTaskPolicy policy, BasDevp basDevp, StationObjModel stationObjModel) {
try {
if (!policy.isEnabled()) {
+ return;
+ }
+
+ StoreInTaskContext earlyContext = buildContext(basDevp, stationObjModel);
+ if (earlyContext == null || !handleErrorStationBack(policy, earlyContext)) {
return;
}
@@ -135,11 +150,26 @@
return;
}
+ if (!stationProtocol.getIoMode().equals(1)) {
+ policy.setSystemWarning(context, "褰撳墠绔欑偣涓嶅浜庡叆搴撴ā寮�");
+ return;
+ }
+
String barcode = context.getStationProtocol().getBarcode();
- long count = wrkMastService.count(new QueryWrapper<WrkMast>().eq("barcode", barcode));
- if (count > 0) {
+ List<WrkMast> wrkMastList = wrkMastService.list(new QueryWrapper<WrkMast>()
+ .eq("barcode", barcode)
+ );
+ if (wrkMastList.size() > 0) {
+ boolean showTips = true;
+ for (WrkMast wrkMast : wrkMastList) {
+ if (wrkMast.getWrkSts().equals(WrkStsType.NEW_INBOUND.sts)) {
+ showTips = false;
+ break;
+ }
+ }
+
Object tipsLimit = redisUtil.get(RedisKeyType.GENERATE_IN_TASK_SUCCESS_REPEAT_WARNING_TIPS_LIMIT.key + barcode);
- if (tipsLimit == null) {
+ if (tipsLimit == null && showTips) {
policy.setSystemWarning(context, "绯荤粺浠诲姟宸插瓨鍦�");
}
return;
@@ -164,6 +194,86 @@
} finally {
releaseGenerateCapacity();
}
+ }
+
+ private boolean handleErrorStationBack(StoreInTaskPolicy policy, StoreInTaskContext context) {
+ StationProtocol stationProtocol = context.getStationProtocol();
+ if (stationProtocol == null) {
+ return false;
+ }
+
+ if (!stationProtocol.isAutoing()) {
+ return false;
+ }
+
+ if (!stationProtocol.isLoading()) {
+ return false;
+ }
+
+ if (stationProtocol.getError() <= 0) {
+ return true;
+ }
+
+ if (!stationProtocol.isInBarcodeError()) {
+ return true;
+ }
+
+ WrkLastno stationBackTaskRange = wrkLastnoService.getById(WrkIoType.STATION_BACK.id);
+ Integer currentTaskNo = stationProtocol.getTaskNo();
+ if (currentTaskNo != null
+ && currentTaskNo > 0
+ && stationBackTaskRange != null
+ && stationBackTaskRange.getsNo() != null
+ && stationBackTaskRange.geteNo() != null
+ && currentTaskNo >= stationBackTaskRange.getsNo()
+ && currentTaskNo <= stationBackTaskRange.geteNo()) {
+ News.info("鏉$爜绔欏凡澶勪簬閫�鍥炲伐浣滃彿鑼冨洿锛岃烦杩囬噸澶嶇敓鎴愰��鍥炲懡浠ゃ�俿tationId={}锛宼askNo={}锛宺ange=[{}, {}]",
+ stationProtocol.getStationId(),
+ currentTaskNo,
+ stationBackTaskRange.getsNo(),
+ stationBackTaskRange.geteNo());
+ return false;
+ }
+
+ StationObjModel backStation = context.getStationObjModel().getBackStation();
+ if (backStation == null || backStation.getStationId() == null) {
+ News.warn("鏉$爜绔欓��鍥炲け璐ワ紝閫�鍥炵珯鏈厤缃�俤eviceNo={}锛宻tationId={}",
+ context.getBasDevp() == null ? null : context.getBasDevp().getDevpNo(),
+ stationProtocol.getStationId());
+ return false;
+ }
+
+ if (stationProtocol.getTaskNo() != null
+ && stationProtocol.getTaskNo() > 0
+ && backStation.getStationId().equals(stationProtocol.getTargetStaNo())) {
+ return false;
+ }
+
+ Object lock = redisUtil.get(RedisKeyType.GENERATE_STATION_BACK_LIMIT.key + stationProtocol.getStationId());
+ if (lock != null) {
+ return false;
+ }
+
+ StationCommand command = context.getStationThread().getCommand(StationCommandType.MOVE,
+ commonService.getWorkNo(WrkIoType.STATION_BACK.id),
+ context.getStationObjModel().getStationId(),
+ backStation.getStationId(), 0);
+ if (command == null) {
+ News.taskInfo(stationProtocol.getTaskNo(), "{}宸ヤ綔,鑾峰彇杈撻�佺嚎鍛戒护澶辫触", stationProtocol.getTaskNo());
+ return false;
+ }
+ stationCommandDispatcher.dispatch(context.getBasDevp().getDevpNo(), command, "store-in-task", "station-back");
+ String errorMsg = Cools.isEmpty(stationProtocol.getErrorMsg()) ? "鏈煡寮傚父" : stationProtocol.getErrorMsg();
+ String warning = "鏉$爜绔欏紓甯搁��鍥烇紝鎶ヨ淇℃伅锛�" + errorMsg;
+ if (!Cools.isEmpty(stationProtocol.getSystemWarning())) {
+ warning = stationProtocol.getSystemWarning() + ";" + warning;
+ }
+ policy.setSystemWarning(context, warning);
+ News.info("{}鎵爜绔欏紓甯革紝宸查��鍥炶嚦{},鏉$爜绔欑姸鎬侊細{}", stationProtocol.getTaskNo(),
+ backStation.getStationId(), JSON.toJSONString(stationProtocol));
+ redisUtil.set(RedisKeyType.GENERATE_STATION_BACK_LIMIT.key + stationProtocol.getStationId(),
+ "lock", 60 * 60);
+ return false;
}
private StoreInTaskContext buildContext(BasDevp basDevp, StationObjModel stationObjModel) {
@@ -233,6 +343,94 @@
request.getBarcode(), request.getSourceStaNo(), result.getResponse(), result.getMessage());
redisUtil.set(policy.getGenerateLockKey(context), "lock", policy.getRetryLockSeconds(context));
policy.onApplyFailed(context, result);
+ triggerStationBackOnApplyFailed(policy, context, request, result);
+ }
+
+ /**
+ * WMS 鐢宠鍏ュ簱澶辫触鍚庯紝璐х墿浠嶅仠鐣欏湪鎵爜绔欙紝姝ゆ椂琛ュ彂閫�鍥炲埌鍏ュ簱绔欑殑杈撻�佸懡浠わ紝閬垮厤璐х墿闀挎湡婊炵暀銆�
+ */
+ private void triggerStationBackOnApplyFailed(StoreInTaskPolicy policy, StoreInTaskContext context,
+ InTaskApplyRequest request,
+ InTaskApplyResult result) {
+ if (context == null || context.getStationThread() == null || context.getStationObjModel() == null) {
+ return;
+ }
+
+ StationProtocol stationProtocol = context.getStationProtocol();
+ if (stationProtocol == null || stationProtocol.getStationId() == null) {
+ return;
+ }
+
+ StationObjModel backStation = context.getStationObjModel().getBackStation();
+ if (backStation == null || backStation.getStationId() == null) {
+ News.warn("WMS鍏ュ簱澶辫触鍚庢棤娉曢��鍥炲叆搴撶珯锛岄��鍥炵珯鏈厤缃�俠arcode={}锛宻tationId={}",
+ request == null ? null : request.getBarcode(), stationProtocol.getStationId());
+ return;
+ }
+
+ Integer currentStationId = stationProtocol.getStationId();
+ Integer backStationId = backStation.getStationId();
+ if (backStationId.equals(currentStationId)) {
+ return;
+ }
+
+ if (stationProtocol.getTaskNo() != null
+ && stationProtocol.getTaskNo() > 0
+ && backStationId.equals(stationProtocol.getTargetStaNo())) {
+ return;
+ }
+
+ String lockKey = RedisKeyType.GENERATE_STATION_BACK_LIMIT.key
+ + currentStationId + "_" + stationProtocol.getTaskNo();
+ if (redisUtil.get(lockKey) != null) {
+ return;
+ }
+
+ Integer stationBackTaskNo = commonService.getWorkNo(WrkIoType.STATION_BACK.id);
+ StationCommand command = context.getStationThread().getCommand(
+ StationCommandType.MOVE,
+ stationBackTaskNo,
+ currentStationId,
+ backStationId,
+ 0
+ );
+ if (command == null) {
+ News.warn("WMS鍏ュ簱澶辫触鍚庣敓鎴愰��鍥炲叆搴撶珯鍛戒护澶辫触銆俠arcode={}锛宻tationId={}锛宐ackStationId={}锛寃arning={}",
+ request == null ? null : request.getBarcode(),
+ currentStationId,
+ backStationId,
+ result == null ? null : result.getMessage());
+ return;
+ }
+
+ StationCommandDispatchResult dispatchResult = stationCommandDispatcher.dispatch(
+ context.getBasDevp().getDevpNo(),
+ command,
+ "store-in-task-generation",
+ "apply-failed-station-back"
+ );
+ if (!dispatchResult.isAccepted()) {
+ News.warn("WMS鍏ュ簱澶辫触鍚庨��鍥炲叆搴撶珯鍛戒护鍏ラ槦澶辫触銆俠arcode={}锛宻tationId={}锛宐ackStationId={}锛宺eason={}锛寃arning={}",
+ request == null ? null : request.getBarcode(),
+ currentStationId,
+ backStationId,
+ dispatchResult.getReason(),
+ result == null ? null : result.getMessage());
+ return;
+ }
+
+ redisUtil.set(lockKey, "lock", APPLY_FAIL_STATION_BACK_LOCK_SECONDS);
+ String currentWarning = stationProtocol.getSystemWarning();
+ String backWarning = "WMS鍏ュ簱澶辫触锛屽凡閫�鍥炲叆搴撶珯";
+ if (!Cools.isEmpty(currentWarning)) {
+ backWarning = currentWarning + ";" + backWarning;
+ }
+ policy.setSystemWarning(context, backWarning);
+ News.warn("WMS鍏ュ簱澶辫触锛屽凡瑙﹀彂璐х墿閫�鍥炲叆搴撶珯銆俠arcode={}锛宻tationId={}锛宐ackStationId={}锛寃arning={}",
+ request == null ? null : request.getBarcode(),
+ currentStationId,
+ backStationId,
+ result == null ? null : result.getMessage());
}
private HashMap<String, String> getSystemConfigMap() {
--
Gitblit v1.9.1