#
Junjie
10 小时以前 cbb00d4729243e4949b3c921fc2f94cb03ca8aaa
src/main/java/com/zy/core/thread/impl/ZyStationV5Thread.java
@@ -28,11 +28,13 @@
import com.zy.core.model.Task;
import com.zy.core.model.command.StationCommand;
import com.zy.core.model.protocol.StationProtocol;
import com.zy.core.model.protocol.StationTaskBufferItem;
import com.zy.core.network.DeviceConnectPool;
import com.zy.core.network.ZyStationConnectDriver;
import com.zy.core.network.entity.ZyStationStatusEntity;
import com.zy.core.service.StationTaskLoopService;
import com.zy.core.thread.impl.v5.StationV5SegmentExecutor;
import com.zy.core.thread.support.RecentStationArrivalTracker;
import com.zy.core.trace.StationTaskTraceRegistry;
import com.zy.core.utils.DeviceLogRedisKeyBuilder;
import lombok.Data;
@@ -72,10 +74,12 @@
    private long deviceDataLogTime = System.currentTimeMillis();
    private ExecutorService executor = Executors.newFixedThreadPool(9999);
    private StationV5SegmentExecutor segmentExecutor;
    private final RecentStationArrivalTracker recentArrivalTracker;
    public ZyStationV5Thread(DeviceConfig deviceConfig, RedisUtil redisUtil) {
        this.deviceConfig = deviceConfig;
        this.redisUtil = redisUtil;
        this.recentArrivalTracker = new RecentStationArrivalTracker(redisUtil);
        this.segmentExecutor = new StationV5SegmentExecutor(deviceConfig, redisUtil, this::sendCommand);
    }
@@ -171,6 +175,8 @@
                    stationProtocol.setEnableIn(statusEntity.isEnableIn());
                    stationProtocol.setWeight(statusEntity.getWeight());
                    stationProtocol.setTaskWriteIdx(statusEntity.getTaskWriteIdx());
                    stationProtocol.setTaskBufferItems(statusEntity.getTaskBufferItems());
                    recentArrivalTracker.observe(statusEntity.getStationId(), statusEntity.getTaskNo(), statusEntity.isLoading());
                }
                if (!Cools.isEmpty(stationProtocol.getSystemWarning())) {
@@ -230,6 +236,11 @@
            map.put(stationProtocol.getStationId(), stationProtocol);
        }
        return map;
    }
    @Override
    public boolean hasRecentArrival(Integer stationId, Integer taskNo) {
        return recentArrivalTracker.hasRecentArrival(stationId, taskNo);
    }
    @Override
@@ -353,6 +364,47 @@
    }
    @Override
    public synchronized boolean clearPath(Integer taskNo) {
        if (taskNo == null || taskNo <= 0) {
            return false;
        }
        if (zyStationConnectDriver == null) {
            return false;
        }
        List<StationProtocol> status = getStatus();
        if (status == null || status.isEmpty()) {
            return false;
        }
        boolean found = false;
        boolean success = true;
        for (StationProtocol stationProtocol : status) {
            List<StationTaskBufferItem> taskBufferItems = stationProtocol == null ? null : stationProtocol.getTaskBufferItems();
            if (taskBufferItems == null || taskBufferItems.isEmpty()) {
                continue;
            }
            Integer stationId = stationProtocol.getStationId();
            for (StationTaskBufferItem item : taskBufferItems) {
                if (item == null || !Objects.equals(taskNo, item.getTaskNo())) {
                    continue;
                }
                found = true;
                if (!zyStationConnectDriver.clearTaskBufferSlot(stationId, item.getSlotIdx())) {
                    success = false;
                    log.warn("输送站缓存区残留路径清理失败。stationId={}, slotIdx={}, taskNo={}",
                            stationId, item.getSlotIdx(), item.getTaskNo());
                    continue;
                }else {
                    success = true;
                    log.warn("输送站缓存区残留路径清理成功。stationId={}, slotIdx={}, taskNo={}",
                            stationId, item.getSlotIdx(), item.getTaskNo());
                }
            }
        }
        return found && success;
    }
    @Override
    public CommandResponse sendCommand(StationCommand command) {
        CommandResponse commandResponse = null;
        try {
@@ -361,6 +413,9 @@
            e.printStackTrace();
        } finally {
            BasStationOptService optService = SpringUtils.getBean(BasStationOptService.class);
            if (optService == null) {
                return commandResponse;
            }
            List<ZyStationStatusEntity> statusListEntity = zyStationConnectDriver.getStatus();
            ZyStationStatusEntity matched = null;
            if (statusListEntity != null) {
@@ -383,12 +438,10 @@
                    null,
                    JSON.toJSONString(command),
                    JSON.toJSONString(matched),
                    1,
                    commandResponse != null && Boolean.TRUE.equals(commandResponse.getResult()) ? 1 : 0,
                    JSON.toJSONString(commandResponse)
            );
            if (optService != null) {
                optService.save(basStationOpt);
            }
            optService.save(basStationOpt);
        }
        return commandResponse;
    }