From 4e5b7d1003f61841de9d550bf75e8376cdc32f51 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期一, 13 四月 2026 17:02:52 +0800
Subject: [PATCH] #入库站异常信息

---
 src/main/java/com/zy/core/plugin/store/StoreInTaskGenerationService.java |  505 +++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 391 insertions(+), 114 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 0436732..522b34f 100644
--- a/src/main/java/com/zy/core/plugin/store/StoreInTaskGenerationService.java
+++ b/src/main/java/com/zy/core/plugin/store/StoreInTaskGenerationService.java
@@ -6,18 +6,26 @@
 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.BasDevpService;
+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.dispatch.StationCommandDispatchResult;
+import com.zy.core.dispatch.StationCommandDispatcher;
 import com.zy.core.enums.RedisKeyType;
 import com.zy.core.enums.SlaveType;
+import com.zy.core.enums.StationCommandType;
+import com.zy.core.enums.WrkIoType;
 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;
 import com.zy.core.thread.StationThread;
 import com.zy.core.utils.StationOperateProcessUtils;
 import com.zy.core.utils.WmsOperateUtils;
@@ -25,14 +33,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 BasDevpService basDevpService;
     @Autowired
     private WrkMastService wrkMastService;
     @Autowired
@@ -43,148 +50,418 @@
     private WmsOperateUtils wmsOperateUtils;
     @Autowired
     private CommonService commonService;
+    @Autowired
+    private MainProcessTaskSubmitter mainProcessTaskSubmitter;
+    @Autowired
+    private StationCommandDispatcher stationCommandDispatcher;
+    @Autowired
+    private WrkLastnoService wrkLastnoService;
 
-    public void generate(StoreInTaskPolicy policy) {
+    /**
+     * 淇濈暀褰撳墠鎸夌珯鐐� lane 骞跺彂鐨勮兘鍔涳紝鍚屾椂鐢ㄤ竴涓畝鍗曡鏁伴伩鍏嶅苟鍙戠敓鎴愭妸绔欑偣浠诲姟鏁伴《绌夸笂闄愩��
+     */
+    private int inFlightGenerateCount = 0;
+
+    public void generate(StoreInTaskPolicy policy, BasDevp basDevp, StationObjModel stationObjModel) {
         try {
             if (!policy.isEnabled()) {
                 return;
             }
 
-            Object systemConfigMapObj = redisUtil.get(RedisKeyType.SYSTEM_CONFIG_MAP.key);
-            if (systemConfigMapObj == null) {
-                return;
-            }
-            HashMap<String, String> systemConfigMap = (HashMap<String, String>) systemConfigMapObj;
-
-            int conveyorStationTaskLimit = 30;
-            String conveyorStationTaskLimitStr = systemConfigMap.get("conveyorStationTaskLimit");
-            if (conveyorStationTaskLimitStr != null) {
-                conveyorStationTaskLimit = Integer.parseInt(conveyorStationTaskLimitStr);
-            }
-            int currentStationTaskCount = stationOperateProcessUtils.getCurrentStationTaskCount();
-            if (currentStationTaskCount > conveyorStationTaskLimit) {
-                News.error("杈撻�佺珯鐐逛换鍔″凡杈惧埌涓婇檺锛屼笂闄愬�硷細{}锛岀珯鐐逛换鍔℃暟锛歿}", conveyorStationTaskLimit, currentStationTaskCount);
+            StoreInTaskContext earlyContext = buildContext(basDevp, stationObjModel);
+            if (earlyContext == null || !handleErrorStationBack(policy, earlyContext)) {
                 return;
             }
 
-            List<BasDevp> basDevps = basDevpService.list(new QueryWrapper<>());
-            for (BasDevp basDevp : basDevps) {
-                StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo());
-                if (stationThread == null) {
-                    continue;
-                }
-
-                Map<Integer, StationProtocol> stationMap = stationThread.getStatusMap();
-                List<StationObjModel> barcodeStations = policy.getBarcodeStations(basDevp);
-                for (StationObjModel stationObjModel : barcodeStations) {
-                    Integer stationId = stationObjModel.getStationId();
-                    if (!stationMap.containsKey(stationId)) {
-                        continue;
-                    }
-
-                    StationProtocol stationProtocol = stationMap.get(stationId);
-                    if (stationProtocol == null) {
-                        continue;
-                    }
-
-                    StoreInTaskContext context = new StoreInTaskContext(basDevp, stationThread, stationObjModel,
-                            stationProtocol);
-                    if (!policy.matchCandidate(context)) {
-                        continue;
-                    }
-                    if (!policy.beforeApply(context)) {
-                        continue;
-                    }
-
-                    List<WrkMast> wrkMasts = wrkMastService.list(new QueryWrapper<WrkMast>()
-                            .eq("barcode", stationProtocol.getBarcode()));
-                    if (!wrkMasts.isEmpty()) {
-                        continue;
-                    }
-
-                    String generateLockKey = policy.getGenerateLockKey(context);
-                    Object lock = redisUtil.get(generateLockKey);
-                    if (lock != null) {
-                        continue;
-                    }
-
-                    policy.onRequestPermitGranted(context);
-
-                    InTaskApplyRequest request = policy.buildApplyRequest(context);
-                    AsyncInTaskResult result = wmsOperateUtils.queryAsyncInTaskResponse(request);
-                    if (result != null) {
-                        handleApplyResult(policy, context, request, result);
-                        continue;
-                    }
-
-                    if (wmsOperateUtils.isAsyncRequestInProgress(request)) {
-                        continue;
-                    }
-
-                    News.info("鍙戣捣寮傛WMS鍏ュ簱璇锋眰锛宐arcode={}锛宻tationId={}", request.getBarcode(),
-                            request.getSourceStaNo());
-                    wmsOperateUtils.applyInTaskAsync(request);
-                    redisUtil.set(generateLockKey, "lock", policy.getSubmitLockSeconds(context));
-                    policy.onApplySubmitted(context);
-                }
+            HashMap<String, String> systemConfigMap = getSystemConfigMap();
+            if (systemConfigMap == null) {
+                return;
             }
+            if (!hasAvailableStationTaskCapacity(systemConfigMap)) {
+                return;
+            }
+
+            generateByStation(policy, basDevp, stationObjModel, systemConfigMap);
         } catch (Exception e) {
-            News.error("鐢熸垚鍏ュ簱浠诲姟寮傚父锛宲olicy={}", policy.getPolicyName(), e);
+            Integer stationId = stationObjModel == null ? null : stationObjModel.getStationId();
+            News.error("鐢熸垚鍏ュ簱浠诲姟寮傚父锛宲olicy={}锛宻tationId={}", policy.getPolicyName(), stationId, e);
         }
     }
 
-    private void handleApplyResult(StoreInTaskPolicy policy, StoreInTaskContext context, InTaskApplyRequest request,
-                                   AsyncInTaskResult result) {
-        if (result.isSuccess()) {
-            handleApplySuccess(policy, context, request, result);
-            return;
-        }
-
-        if (result.isRetryableFailure()) {
-            News.error("WMS鍏ュ簱璇锋眰澶辫触锛岄噸鏂板彂璧疯姹傦紝barcode={}锛宻tationId={}锛宺esponse={}",
-                    request.getBarcode(), request.getSourceStaNo(), policy.buildFailureMessage(result));
-            wmsOperateUtils.clearAsyncInTaskResponse(request);
-            wmsOperateUtils.applyInTaskAsync(request);
-            redisUtil.set(policy.getGenerateLockKey(context), "lock", policy.getRetryLockSeconds(context));
-            policy.onApplyFailed(context, result);
-            return;
-        }
-
-        policy.onApplyFailed(context, result);
+    public void submitGenerateStoreTask(StoreInTaskPolicy policy,
+                                        BasDevp basDevp,
+                                        StationObjModel stationObjModel,
+                                        long minIntervalMs,
+                                        Runnable task) {
+        submitGenerateStoreTask(policy, basDevp, stationObjModel, MainProcessLane.GENERATE_STORE, minIntervalMs, task);
     }
 
-    private void handleApplySuccess(StoreInTaskPolicy policy, StoreInTaskContext context, InTaskApplyRequest request,
-                                    AsyncInTaskResult result) {
+    public void submitGenerateStoreTask(StoreInTaskPolicy policy,
+                                        BasDevp basDevp,
+                                        StationObjModel stationObjModel,
+                                        MainProcessLane lane,
+                                        long minIntervalMs,
+                                        Runnable task) {
+        Integer stationId = stationObjModel == null ? null : stationObjModel.getStationId();
+        mainProcessTaskSubmitter.submitKeyedSerialTask(
+                lane,
+                stationId,
+                "generateStoreWrkFile",
+                minIntervalMs,
+                task
+        );
+    }
+
+    private void generateByStation(StoreInTaskPolicy policy, BasDevp basDevp, StationObjModel stationObjModel,
+                                   HashMap<String, String> systemConfigMap) {
+        StoreInTaskContext context = buildContext(basDevp, stationObjModel);
+        if (context == null) {
+            return;
+        }
+
+        StationProtocol stationProtocol = context.getStationProtocol();
+        if (stationProtocol == null) {
+            return;
+        }
+
+        if (!stationProtocol.isAutoing()) {
+            return;
+        }
+
+        if (!stationProtocol.isLoading()) {
+            return;
+        }
+
+        if (!stationProtocol.isInEnable()) {
+            return;
+        }
+
+        if (stationProtocol.getTaskNo() == 0) {
+            return;
+        }
+
+        if (Cools.isEmpty(stationProtocol.getBarcode())) {
+            return;
+        }
+
+        if (stationProtocol.getError() > 0) {
+            return;
+        }
+
+        if (stationProtocol.isInBarcodeError()) {
+            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) {
+            Object tipsLimit = redisUtil.get(RedisKeyType.GENERATE_IN_TASK_SUCCESS_REPEAT_WARNING_TIPS_LIMIT.key + barcode);
+            if (tipsLimit == null) {
+                policy.setSystemWarning(context, "绯荤粺浠诲姟宸插瓨鍦�");
+            }
+            return;
+        }
+
+        if (redisUtil.get(policy.getGenerateLockKey(context)) != null) {
+            return;
+        }
+
+        if (!tryReserveGenerateCapacity(systemConfigMap)) {
+            return;
+        }
+
+        InTaskApplyRequest request = policy.buildApplyRequest(context);
         try {
-            JSONObject jsonObject = JSON.parseObject(result.getResponse());
+            policy.onRequestPermitGranted(context);
+            policy.setSystemWarning(context, "璇锋眰WMS涓�");
+            News.info("鍙戣捣鍚屾WMS鍏ュ簱璇锋眰锛宐arcode={}锛宻tationId={}锛宼imeout={}s",
+                    request.getBarcode(), request.getSourceStaNo(), APPLY_IN_TASK_TIMEOUT_SECONDS);
+            String response = wmsOperateUtils.applyInTask(request);
+            handleSyncApplyResponse(policy, context, request, response);
+        } 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) {
+        if (basDevp == null || stationObjModel == null || stationObjModel.getStationId() == null) {
+            return null;
+        }
+
+        StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo());
+        if (stationThread == null) {
+            return null;
+        }
+
+        Integer stationId = stationObjModel.getStationId();
+        Map<Integer, StationProtocol> stationMap = stationThread.getStatusMap();
+        if (stationMap == null || !stationMap.containsKey(stationId)) {
+            return null;
+        }
+
+        StationProtocol stationProtocol = stationMap.get(stationId);
+        if (stationProtocol == null) {
+            return null;
+        }
+
+        return new StoreInTaskContext(basDevp, stationThread, stationObjModel, stationProtocol);
+    }
+
+    private void handleSyncApplyResponse(StoreInTaskPolicy policy, StoreInTaskContext context, InTaskApplyRequest request,
+                                         String response) {
+        if (Cools.isEmpty(response)) {
+            markApplyFailed(policy, context, request, null, "FAILED");
+            return;
+        }
+
+        try {
+            JSONObject jsonObject = JSON.parseObject(response);
             if (jsonObject == null || !Integer.valueOf(200).equals(jsonObject.getInteger("code"))) {
-                AsyncInTaskResult failResult = new AsyncInTaskResult();
-                failResult.setStatus(AsyncInTaskStatus.RETRYABLE_FAIL);
-                failResult.setResponse(result.getResponse());
-                failResult.setMessage("WMS杩斿洖闈�200");
-                handleApplyResult(policy, context, request, failResult);
+                markApplyFailed(policy, context, request, response, "WMS杩斿洖闈�200");
                 return;
             }
 
             StartupDto dto = jsonObject.getObject("data", StartupDto.class);
             if (dto == null) {
-                AsyncInTaskResult failResult = new AsyncInTaskResult();
-                failResult.setStatus(AsyncInTaskStatus.RETRYABLE_FAIL);
-                failResult.setResponse(result.getResponse());
-                failResult.setMessage("WMS杩斿洖data涓虹┖");
-                handleApplyResult(policy, context, request, failResult);
+                markApplyFailed(policy, context, request, response, "WMS杩斿洖data涓虹┖");
                 return;
             }
 
             CreateInTaskParam taskParam = policy.buildCreateInTaskParam(context, dto);
             WrkMast wrkMast = commonService.createInTask(taskParam);
             policy.afterTaskCreated(context, wrkMast);
-            context.getStationProtocol().setSystemWarning("");
-            wmsOperateUtils.clearAsyncInTaskResponse(request);
+            policy.clearSystemWarning(context);
+            redisUtil.set(RedisKeyType.GENERATE_IN_TASK_SUCCESS_REPEAT_WARNING_TIPS_LIMIT.key + wrkMast.getBarcode(), "lock", 30);
         } catch (Exception e) {
-            News.error("澶勭悊WMS鍏ュ簱鎴愬姛鍝嶅簲澶辫触锛宐arcode={}锛宻tationId={}", request.getBarcode(),
+            News.error("澶勭悊WMS鍏ュ簱鍝嶅簲寮傚父锛宐arcode={}锛宻tationId={}", request.getBarcode(),
                     request.getSourceStaNo(), e);
+            markApplyFailed(policy, context, request, response, e.getMessage());
         }
     }
 
+    private void markApplyFailed(StoreInTaskPolicy policy, StoreInTaskContext context, InTaskApplyRequest request,
+                                 String response, String message) {
+        InTaskApplyResult result = new InTaskApplyResult();
+        result.setStatus(InTaskApplyStatus.RETRYABLE_FAIL);
+        result.setResponse(response);
+        result.setMessage(message);
+
+        News.error("WMS鍏ュ簱璇锋眰澶辫触锛宐arcode={}锛宻tationId={}锛宺esponse={}锛學CS鍝嶅簲={}",
+                request.getBarcode(), request.getSourceStaNo(), result.getResponse(), result.getMessage());
+        redisUtil.set(policy.getGenerateLockKey(context), "lock", policy.getRetryLockSeconds(context));
+        policy.onApplyFailed(context, result);
+        triggerStationBackOnApplyFailed(context, request, result);
+    }
+
+    /**
+     * WMS 鐢宠鍏ュ簱澶辫触鍚庯紝璐х墿浠嶅仠鐣欏湪鎵爜绔欙紝姝ゆ椂琛ュ彂閫�鍥炲埌鍏ュ簱绔欑殑杈撻�佸懡浠わ紝閬垮厤璐х墿闀挎湡婊炵暀銆�
+     */
+    private void triggerStationBackOnApplyFailed(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);
+        News.warn("WMS鍏ュ簱澶辫触锛屽凡瑙﹀彂璐х墿閫�鍥炲叆搴撶珯銆俠arcode={}锛宻tationId={}锛宐ackStationId={}锛寃arning={}",
+                request == null ? null : request.getBarcode(),
+                currentStationId,
+                backStationId,
+                result == null ? null : result.getMessage());
+    }
+
+    private HashMap<String, String> getSystemConfigMap() {
+        Object systemConfigMapObj = redisUtil.get(RedisKeyType.SYSTEM_CONFIG_MAP.key);
+        if (systemConfigMapObj == null) {
+            return null;
+        }
+        return (HashMap<String, String>) systemConfigMapObj;
+    }
+
+    private boolean hasAvailableStationTaskCapacity(HashMap<String, String> systemConfigMap) {
+        int conveyorStationTaskLimit = getConveyorStationTaskLimit(systemConfigMap);
+        int currentStationTaskCount = stationOperateProcessUtils.getCurrentStationTaskCount();
+        if (currentStationTaskCount > conveyorStationTaskLimit) {
+            News.error("杈撻�佺珯鐐逛换鍔″凡杈惧埌涓婇檺锛屼笂闄愬�硷細{}锛岀珯鐐逛换鍔℃暟锛歿}", conveyorStationTaskLimit, currentStationTaskCount);
+            return false;
+        }
+        return true;
+    }
+
+    private synchronized boolean tryReserveGenerateCapacity(HashMap<String, String> systemConfigMap) {
+        int conveyorStationTaskLimit = getConveyorStationTaskLimit(systemConfigMap);
+        int currentStationTaskCount = stationOperateProcessUtils.getCurrentStationTaskCount();
+        if (currentStationTaskCount + inFlightGenerateCount >= conveyorStationTaskLimit) {
+            News.error("杈撻�佺珯鐐逛换鍔″凡杈惧埌涓婇檺锛屼笂闄愬�硷細{}锛岀珯鐐逛换鍔℃暟锛歿}锛岀敓鎴愪腑浠诲姟鏁帮細{}",
+                    conveyorStationTaskLimit, currentStationTaskCount, inFlightGenerateCount);
+            return false;
+        }
+        inFlightGenerateCount++;
+        return true;
+    }
+
+    private synchronized void releaseGenerateCapacity() {
+        if (inFlightGenerateCount > 0) {
+            inFlightGenerateCount--;
+        }
+    }
+
+    private int getConveyorStationTaskLimit(HashMap<String, String> systemConfigMap) {
+        int conveyorStationTaskLimit = 30;
+        String conveyorStationTaskLimitStr = systemConfigMap.get("conveyorStationTaskLimit");
+        if (conveyorStationTaskLimitStr != null) {
+            conveyorStationTaskLimit = Integer.parseInt(conveyorStationTaskLimitStr);
+        }
+        return conveyorStationTaskLimit;
+    }
+
 }

--
Gitblit v1.9.1