#
Junjie
9 小时以前 27836d1b0bc74a5aa22a8b6c7cf40f2d0068db8a
src/main/java/com/zy/core/thread/impl/ZySiemensDualCrnThread.java
@@ -85,6 +85,11 @@
                    if (step == 2) {
                        List<SendDualCrnCommandParam> commandList = (List<SendDualCrnCommandParam>) task.getData();
                        for (SendDualCrnCommandParam sendDualCrnCommandParam : commandList) {
                            DualCrnCommand dualCrnCommand = sendDualCrnCommandParam.getCommands().get(0);
                            redisUtil.set(RedisKeyType.DUAL_CRN_COMMAND_IDX.key + dualCrnCommand.getTaskNo(), sendDualCrnCommandParam.getCommandIdx(), 60 * 60 * 24);
                        }
                        redisUtil.set(RedisKeyType.DUAL_CRN_COMMAND_.key + crnProtocol.getCrnNo(), JSON.toJSONString(commandList, SerializerFeature.DisableCircularReferenceDetect), 60 * 60 * 24);
                    } else if (step == 3) {
                        sendCommand((DualCrnCommand) task.getData());
@@ -109,28 +114,21 @@
                        continue;
                    }
//                    if (crnProtocol.getLoaded() == 1 && crnProtocol.getLoadedTwo() == 1) {
//                        Object wait = redisUtil.get(RedisKeyType.DUAL_CRN_PICK_WAIT_NEXT_TASK.key + crnProtocol.getCrnNo());
//                        if (wait != null) {
//                            redisUtil.del(RedisKeyType.DUAL_CRN_PICK_WAIT_NEXT_TASK.key + crnProtocol.getCrnNo());
//                        }
//                    }
                    if (!((crnProtocol.getStatusType().equals(DualCrnStatusType.IDLE) || crnProtocol.getStatusType().equals(DualCrnStatusType.FETCH_COMPLETE))
                            && (crnProtocol.getStatusTypeTwo().equals(DualCrnStatusType.IDLE) || crnProtocol.getStatusTypeTwo().equals(DualCrnStatusType.FETCH_COMPLETE)))
                    ) {
                        continue;
                    }
                    Object commandListObj = redisUtil.get(RedisKeyType.DUAL_CRN_COMMAND_.key + crnProtocol.getCrnNo());
                    if (commandListObj == null) {
                        continue;
                    }
                    List<SendDualCrnCommandParam> commandList = JSON.parseArray(commandListObj.toString(), SendDualCrnCommandParam.class);
                    List<SendDualCrnCommandParam> newCommandList = new ArrayList<>();
                    for (SendDualCrnCommandParam commandParam : commandList) {
                        SendDualCrnCommandParam processed = processStation(commandParam);
                        if(processed != null) {
                            newCommandList.add(processed);
                        }
                        processStation(commandParam);
                    }
                    redisUtil.set(RedisKeyType.DUAL_CRN_COMMAND_.key + crnProtocol.getCrnNo(), JSON.toJSONString(newCommandList, SerializerFeature.DisableCircularReferenceDetect), 60 * 60 * 24);
                    Thread.sleep(100);
                } catch (Exception e) {
                    log.error("DualCrnCommand Fail", e);
@@ -140,44 +138,61 @@
        commandThread.start();
    }
    private SendDualCrnCommandParam processStation(SendDualCrnCommandParam commandParam) {
    private void processStation(SendDualCrnCommandParam commandParam) {
        Integer station = commandParam.getStation();
        Integer idx = commandParam.getCommandIdx();
        List<DualCrnCommand> commandList = commandParam.getCommands();
        DualCrnCommand firstCommand = commandList.get(0);
        Object idxObj = redisUtil.get(RedisKeyType.DUAL_CRN_COMMAND_IDX.key + firstCommand.getTaskNo());
        if(idxObj == null) {
            return;
        }
        Integer idx = (Integer) idxObj;
        if (idx >= commandList.size()) {
            return commandParam;
            return;
        }
        DualCrnCommand dualCommand = commandList.get(idx);
        boolean send = false;
        if (station == 1) {
            if (crnProtocol.getStatus().equals(DualCrnStatusType.FETCH_COMPLETE.id)
                    || crnProtocol.getStatus().equals(DualCrnStatusType.IDLE.id)
            ) {
                send = true;
            if (crnProtocol.getTaskSend() == 0) {
                if (dualCommand.getTaskMode().intValue() == DualCrnTaskModeType.PICK.id) {
                    if (crnProtocol.getStatus().equals(DualCrnStatusType.IDLE.id)) {
                        send = true;
                    }
                } else if (dualCommand.getTaskMode().intValue() == DualCrnTaskModeType.PUT.id) {
                    if (crnProtocol.getStatus().equals(DualCrnStatusType.FETCH_COMPLETE.id)) {
                        send = true;
                    }
                }
            }
        }else {
            if (crnProtocol.getStatusTwo().equals(DualCrnStatusType.FETCH_COMPLETE.id)
                    || crnProtocol.getStatusTwo().equals(DualCrnStatusType.IDLE.id)
            ) {
                send = true;
            if (crnProtocol.getTaskSendTwo() == 0) {
                if (dualCommand.getTaskMode().intValue() == DualCrnTaskModeType.PICK.id) {
                    if (crnProtocol.getStatusTwo().equals(DualCrnStatusType.IDLE.id)) {
                        send = true;
                    }
                } else if (dualCommand.getTaskMode().intValue() == DualCrnTaskModeType.PUT.id) {
                    if (crnProtocol.getStatusTwo().equals(DualCrnStatusType.FETCH_COMPLETE.id)) {
                        send = true;
                    }
                }
            }
        }
        if (idx == 0) {
            if(send) {
                idx++;
                commandParam.setCommandIdx(idx);
                redisUtil.set(RedisKeyType.DUAL_CRN_COMMAND_IDX.key + firstCommand.getTaskNo(), idx, 60 * 60 * 24);
                sendCommand(dualCommand);
                redisUtil.set(RedisKeyType.DUAL_CRN_PICK_WAIT_NEXT_TASK.key + crnProtocol.getCrnNo(), "lock", 5);
            }
            return commandParam;
            return;
        }else {
            if (dualCommand.getTaskMode() == DualCrnTaskModeType.PUT.id.shortValue()) {
                //等待下一个任务
                Object wait = redisUtil.get(RedisKeyType.DUAL_CRN_PICK_WAIT_NEXT_TASK.key + crnProtocol.getCrnNo());
                if (wait != null) {
                    return commandParam;
                    return;
                }
                Integer taskNo = dualCommand.getTaskNo();
@@ -187,35 +202,35 @@
                    StationObjModel stationObjModel = JSON.parseObject(outTaskStationInfoObj.toString(), StationObjModel.class);
                    StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, stationObjModel.getDeviceNo());
                    if (stationThread == null) {
                        return commandParam;
                        return;
                    }
                    Map<Integer, StationProtocol> statusMap = stationThread.getStatusMap();
                    StationProtocol stationProtocol = statusMap.get(stationObjModel.getStationId());
                    if (stationProtocol == null) {
                        return commandParam;
                        return;
                    }
                    if (!stationProtocol.isAutoing()) {
                        return commandParam;
                        return;
                    }
                    if (stationProtocol.isLoading()) {
                        return commandParam;
                        return;
                    }
                    if (stationProtocol.getTaskNo() > 0) {
                        return commandParam;
                        return;
                    }
                }
            }
            if(send) {
                idx++;
                commandParam.setCommandIdx(idx);
                redisUtil.set(RedisKeyType.DUAL_CRN_COMMAND_IDX.key + firstCommand.getTaskNo(), idx, 60 * 60 * 24);
                sendCommand(dualCommand);
            }
            return commandParam;
            return;
        }
    }
@@ -305,6 +320,7 @@
        crnProtocol.setForkPos(crnStatus.getForkPos());
        crnProtocol.setLoaded(crnStatus.getLoaded());
        crnProtocol.setTaskReceive(crnStatus.getTaskReceive());
        crnProtocol.setTaskSend(crnStatus.getTaskSend());
        //工位2
        crnProtocol.setTaskNoTwo(crnStatus.getTaskNoTwo());
@@ -312,6 +328,7 @@
        crnProtocol.setForkPosTwo(crnStatus.getForkPosTwo());
        crnProtocol.setLoadedTwo(crnStatus.getLoadedTwo());
        crnProtocol.setTaskReceiveTwo(crnStatus.getTaskReceiveTwo());
        crnProtocol.setTaskSendTwo(crnStatus.getTaskSendTwo());
        crnProtocol.setBay(crnStatus.getBay());
        crnProtocol.setLevel(crnStatus.getLevel());
@@ -474,10 +491,10 @@
    }
    @Override
    public DualCrnCommand getResetCommand(Integer crnNo, Integer station) {
    public DualCrnCommand getResetCommand(Integer taskNo, Integer crnNo, Integer station) {
        DualCrnCommand crnCommand = new DualCrnCommand();
        crnCommand.setCrnNo(crnNo); // 堆垛机编号
        crnCommand.setTaskNo(0); // 工作号
        crnCommand.setTaskNo(taskNo); // 工作号
        crnCommand.setTaskMode(DualCrnTaskModeType.CONFIRM.id); // 任务模式:  确认
        crnCommand.setSourcePosX(0);     // 源库位排
        crnCommand.setSourcePosY(0);     // 源库位列