Junjie
2 天以前 63b01db83d9aad8a15276b4236a9a22e4aeef065
src/main/java/com/zy/core/plugin/FakeProcess.java
@@ -1,6 +1,5 @@
package com.zy.core.plugin;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zy.asrs.entity.*;
import com.zy.asrs.service.*;
@@ -8,6 +7,7 @@
import com.zy.core.News;
import com.zy.core.cache.MessageQueue;
import com.zy.core.cache.SlaveConnection;
import com.zy.core.dispatch.StationCommandDispatchResult;
import com.zy.core.dispatch.StationCommandDispatcher;
import com.zy.core.enums.*;
import com.zy.core.model.StationObjModel;
@@ -21,7 +21,6 @@
import com.zy.core.plugin.station.FakeStationMonitor;
import com.zy.core.plugin.station.FakeTaskGenerator;
import com.zy.core.plugin.store.StoreInTaskContext;
import com.zy.core.plugin.store.StoreInTaskGenerationService;
import com.zy.core.plugin.store.StoreInTaskPolicy;
import com.zy.core.task.MainProcessLane;
import com.zy.core.task.MainProcessTaskSubmitter;
@@ -59,50 +58,83 @@
    private static volatile String fakeGenerateInTask = "Y";
    private static volatile String fakeGenerateOutTask = "Y";
    private static final Map<String, Long> OUT_STATION_STAY_MARKER = new HashMap<String, Long>();
    private static final Map<Integer, Long> OUT_STATION_STAY_MARKER = new HashMap<Integer, Long>();
    private final Object outStationStayLock = new Object();
    private boolean shouldDispatchOutStationWriteInfo(String taskNo) {
    private boolean shouldDispatchOutStationWriteInfo(Integer wrkNo) {
        long now = System.currentTimeMillis();
        long timeoutMs = getOutStationStayTimeoutMs();
        synchronized (outStationStayLock) {
            Long lastTime = OUT_STATION_STAY_MARKER.get(taskNo);
            Long lastTime = OUT_STATION_STAY_MARKER.get(wrkNo);
            if (lastTime == null || now - lastTime >= timeoutMs) {
                OUT_STATION_STAY_MARKER.put(taskNo, now);
                OUT_STATION_STAY_MARKER.put(wrkNo, now);
                return true;
            }
            return false;
        }
    }
    private void clearOutStationStayMarker(String taskNo) {
    private void clearOutStationStayMarker(Integer wrkNo) {
        synchronized (outStationStayLock) {
            OUT_STATION_STAY_MARKER.remove(taskNo);
            OUT_STATION_STAY_MARKER.remove(wrkNo);
        }
    }
    private void dispatchOutStationWriteInfoIfReady(WrkMast wrkMast, BasCrnp basCrnp) {
        String taskNo = wrkMast == null ? null : wrkMast.getWmsWrkNo();
        if (taskNo == null || !shouldDispatchOutStationWriteInfo(taskNo)) {
        Integer wrkNo = wrkMast == null ? null : wrkMast.getWrkNo();
        if (wrkNo == null) {
            News.error("仿真出库站点写入跳过,WCS任务号为空。sourceStaNo={},crnNo={}",
                    wrkMast == null ? null : wrkMast.getSourceStaNo(),
                    basCrnp == null ? null : basCrnp.getCrnNo());
            return;
        }
        if (!shouldDispatchOutStationWriteInfo(wrkNo)) {
            News.error("仿真出库站点写入跳过,命中节流限制。wrkNo={},sourceStaNo={},crnNo={}",
                    wrkNo,
                    wrkMast == null ? null : wrkMast.getSourceStaNo(),
                    basCrnp == null ? null : basCrnp.getCrnNo());
            return;
        }
        String taskNo = String.valueOf(wrkNo);
        List<StationObjModel> outStationList = basCrnp.getOutStationList$();
        if (outStationList.isEmpty()) {
            News.info("堆垛机:{} 出库站点未设置", basCrnp.getCrnNo());
            News.error("仿真出库站点写入失败,堆垛机未配置出库站点。crnNo={},wrkNo={},taskNo={}",
                    basCrnp.getCrnNo(), wrkMast == null ? null : wrkMast.getWrkNo(), taskNo);
            return;
        }
        boolean matched = false;
        for (StationObjModel stationObjModel : outStationList) {
            if (!stationObjModel.getStationId().equals(wrkMast.getSourceStaNo())) {
                continue;
            }
            matched = true;
            StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, stationObjModel.getDeviceNo());
            if (stationThread == null) {
                News.error("仿真出库站点写入失败,站点线程不存在。taskNo={},wrkNo={},stationId={},deviceNo={}",
                        taskNo, wrkMast.getWrkNo(), stationObjModel.getStationId(), stationObjModel.getDeviceNo());
                continue;
            }
            StationCommand command = stationThread.getCommand(StationCommandType.WRITE_INFO, 9998,
                    wrkMast.getSourceStaNo(), 0, 0);
            stationCommandDispatcher.dispatch(stationObjModel.getDeviceNo(), command, "fake-process", "crn-out-complete-write-info");
            StationCommandDispatchResult dispatchResult = stationCommandDispatcher.dispatch(
                    stationObjModel.getDeviceNo(), command, "fake-process", "crn-out-complete-write-info");
            News.info("仿真出库站点写入命令分发结果。taskNo={},wrkNo={},crnNo={},stationId={},deviceNo={},accepted={},reason={},queueDepth={}",
                    taskNo,
                    wrkMast.getWrkNo(),
                    basCrnp.getCrnNo(),
                    stationObjModel.getStationId(),
                    stationObjModel.getDeviceNo(),
                    dispatchResult != null && dispatchResult.isAccepted(),
                    dispatchResult == null ? null : dispatchResult.getReason(),
                    dispatchResult == null ? null : dispatchResult.getQueueDepth());
        }
        if (!matched) {
            News.error("仿真出库站点写入失败,未匹配到sourceStaNo对应出库站点。taskNo={},wrkNo={},sourceStaNo={},crnNo={}",
                    taskNo,
                    wrkMast == null ? null : wrkMast.getWrkNo(),
                    wrkMast == null ? null : wrkMast.getSourceStaNo(),
                    basCrnp == null ? null : basCrnp.getCrnNo());
        }
    }
@@ -295,7 +327,7 @@
        wrkMast.setIoTime(now);
        wrkMast.setModiTime(now);
        if (wrkMastService.updateById(wrkMast)) {
            clearOutStationStayMarker(wrkMast.getWmsWrkNo());
            clearOutStationStayMarker(wrkMast.getWrkNo());
            wrkAnalysisService.markCraneComplete(wrkMast, now, updateWrkSts);
            CrnCommand resetCommand = crnThread.getResetCommand(crnProtocol.getTaskNo(), crnProtocol.getCrnNo());
            MessageQueue.offer(SlaveType.Crn, crnProtocol.getCrnNo(), new Task(2, resetCommand));