zwl
2026-03-20 84e27510eac3b86af8a98d7498eb451b876c5413
src/main/java/com/zy/core/plugin/NormalProcess.java
@@ -4,7 +4,6 @@
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.Cools;
import com.core.common.SpringUtils;
import com.zy.asrs.domain.param.CreateInTaskParam;
import com.zy.asrs.entity.BasCrnp;
import com.zy.asrs.entity.BasDevp;
@@ -34,10 +33,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
@Slf4j
@Component
@@ -85,6 +81,8 @@
        //上报堆垛机DB110状态数据
        reportDb110();
        //跨区入库任务下发,修改站点任务号为入库任务号
        taskToNewAreaInTaskStationSend();
    }
    /**
@@ -164,6 +162,10 @@
                        Integer stationIdVal = stationProtocol.getStationId();
                        String stationBackKey = RedisKeyType.GENERATE_STATION_BACK_LIMIT.key + barcode + "_" + stationIdVal;
                        if (redisUtil.get(stationBackKey) != null) {
                            continue;
                        }
                        // 1. 首先查询是否有已完成的异步响应
                        String response = wmsOperateUtils.queryAsyncInTaskResponse(barcode, stationIdVal);
@@ -204,6 +206,7 @@
                                    News.taskInfo(wrkMast.getWrkNo(), "获取输送线命令失败");
                                    continue;
                                }
                                redisUtil.del(stationBackKey);
                                stationProtocol.setSystemWarning("");
                                MessageQueue.offer(SlaveType.Devp, basDevp.getDevpNo(), new Task(2, command));
                            } else {
@@ -212,12 +215,13 @@
                                StationCommand command = stationThread.getCommand(StationCommandType.WRITE_INFO,
                                        9991, 1015, 1013, 0);
                                MessageQueue.offer(SlaveType.Devp, basDevp.getDevpNo(), new Task(2, command));
                                // 接口返回非200,重新发起请求
                                News.error("WMS入库接口返回非200,重新发起请求,barcode={},stationId={},response={}", barcode,
                                redisUtil.set(stationBackKey, "lock", 15);
                                wmsOperateUtils.clearAsyncInTaskCache(barcode, stationIdVal);
                                // 接口返回非200,先退回,等待下次循环重新请求
                                News.error("WMS入库接口返回非200,先退回后等待重试,barcode={},stationId={},response={}", barcode,
                                        stationIdVal, response);
                                wmsOperateUtils.applyInTaskAsync(barcode, stationIdVal,
                                        stationProtocol.getPalletHeight(),stationProtocol.getWeight());
                                redisUtil.set(RedisKeyType.GENERATE_IN_TASK_LIMIT.key + stationId, "lock", 2);
                                continue;
                            }
                        } else {
                            // 3. 没有响应结果,检查是否有请求正在进行中
@@ -306,15 +310,76 @@
                }
            }
            try {
                WmsOperateUtils wmsOperateUtils = SpringUtils.getBean(WmsOperateUtils.class);
                if (wmsOperateUtils != null) {
                    wmsOperateUtils.reportCrnDb110Status(crnProtocol.getCrnNo(), currentIndices);
                }
            } catch (Exception e) {
                log.error("Report Crn Db110 Status Fail", e);
            if (currentIndices.isEmpty()) {
                continue;
            }
            String reportLockKey = RedisKeyType.REPORT_CRN_DB110_STATUS_LIMIT.key + crnProtocol.getCrnNo();
            if (redisUtil.get(reportLockKey) != null) {
                continue;
            }
            long reportLockSeconds = Math.max(60L, currentIndices.size() * 35L);
            redisUtil.set(reportLockKey, "lock", reportLockSeconds);
            wmsOperateUtils.reportCrnDb110StatusAsync(crnProtocol.getCrnNo(), new ArrayList<>(currentIndices));
        }
    }
    //跨区入库任务下发,修改站点任务号为入库任务号
    public synchronized void taskToNewAreaInTaskStationSend() {
        Set<String> list = redisUtil.searchKeys(RedisKeyType.RECEIVE_IN_TASK_CHANGE_STATION_TASK.key);
        for (String key : list) {
            Object dataStr = redisUtil.get(key);
            if (dataStr == null) {
                continue;
            }
            JSONObject data = JSON.parseObject(dataStr.toString());
            Integer oldTaskNo = data.getInteger("oldTaskNo");
            Integer newTaskNo = data.getInteger("newTaskNo");
            StationCommand command = data.getObject("command", StationCommand.class);
            Integer stationId = data.getInteger("stationId");
            Integer deviceNo = data.getInteger("deviceNo");
            Object lock = redisUtil.get(RedisKeyType.SEND_LIMIT_RECEIVE_IN_TASK_CHANGE_STATION_TASK.key + stationId);
            if(lock != null){
                continue;
            }
            StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, deviceNo);
            if(stationThread == null){
                continue;
            }
            Map<Integer, StationProtocol> statusMap = stationThread.getStatusMap();
            StationProtocol stationProtocol = statusMap.get(stationId);
            if(stationProtocol == null){
                continue;
            }
            if (!stationProtocol.isAutoing()) {
                continue;
            }
            if (!stationProtocol.isLoading()) {
                continue;
            }
            if (stationProtocol.getTaskNo() == 0) {
                continue;
            }
            if (!stationProtocol.getTaskNo().equals(oldTaskNo)) {
                //和缓存命令不相同删除
                redisUtil.del(key);
                continue;
            }
            //缓存命令相同,下发命令改变入库任务号信息
            MessageQueue.offer(SlaveType.Devp, deviceNo, new Task(2, command));
            redisUtil.set(RedisKeyType.SEND_LIMIT_RECEIVE_IN_TASK_CHANGE_STATION_TASK.key + stationId, "lock", 5);
        }
    }
}