Junjie
2023-12-25 2dc3f0507d6e883d16b1c3c095ca06455a6fa1a7
src/main/java/com/zy/core/thread/LiftThread.java
@@ -351,7 +351,15 @@
            return false;
        }
        WrkMastMapper wrkMastMapper = SpringUtils.getBean(WrkMastMapper.class);
        if (wrkNo >= 20000 && wrkNo <= 30000) {
            //提升机设备工作号,需要查询对应任务号
            BasLiftOptService basLiftOptService = SpringUtils.getBean(BasLiftOptService.class);
            BasLiftOpt basLiftOpt = basLiftOptService.selectByDeviceWrk(liftProtocol.getTaskNo().toString(), liftProtocol.getLiftNo().intValue());
            if (basLiftOpt != null) {
                wrkNo = basLiftOpt.getWrkNo().shortValue();
            }
        }
        Object o = redisUtil.get(RedisKeyType.LIFT.key + wrkNo);
        if (o == null) {
            return false;
@@ -363,12 +371,42 @@
        //总步序
        int size = commands.size();
        //取出命令
        NyLiftCommand command = commands.get(commandStep);
        if (!redisCommand.getLiftNo().equals(liftProtocol.getLiftNo())) {
            return false;
        }
        if (commandStep != 0) {
            //判断上一条指令是否做完
            NyLiftCommand lastCommand = commands.get(commandStep - 1);//上一条指令
            if (!liftProtocol.getBusy() && liftProtocol.getTaskNo().equals(lastCommand.getTaskNo())) {
                //提升机空闲、且提升机工作号与上一条指令工作号相同
                lastCommand.setComplete(true);//标记任务完成
            }
            //任务数据保存到redis
            redisUtil.set(RedisKeyType.LIFT.key + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand));
            if (!lastCommand.getComplete()) {
                //上一条任务未完成,禁止下发命令
                return false;
            }
            //判断是否为最后一条命令且命令执行完成,抛出等待确认状态
            NyLiftCommand endCommand = commands.get(commands.size() - 1);
            if (endCommand.getComplete()) {
                //已执行完成
                //删除redis
                redisUtil.del(RedisKeyType.LIFT.key + redisCommand.getWrkNo());
                //对主线程抛出等待确认状态waiting
                liftProtocol.setProtocolStatus(LiftProtocolStatusType.WAITING);
                News.info("提升机任务执行下发完成执行结束,提升机号={},任务数据={}", redisCommand.getLiftNo(), JSON.toJSON(redisCommand));
            }
        }
        //取出命令
        NyLiftCommand command = commands.get(commandStep);
        //下发命令
        if (!write(command)) {
@@ -400,23 +438,30 @@
            liftOptService.insert(opt);
        }
        //判断数据是否执行完成
        if (commandStep < size - 1) {
            //更新redis数据
            //步序增加
            commandStep++;
            redisCommand.setCommandStep(commandStep);
            //任务数据保存到redis
            redisUtil.set(RedisKeyType.LIFT.key + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand));
        }else {
            //已执行完成
            //删除redis
            redisUtil.del(RedisKeyType.LIFT.key + redisCommand.getWrkNo());
        //更新redis数据
        //步序增加
        commandStep++;
        redisCommand.setCommandStep(commandStep);
        //任务数据保存到redis
        redisUtil.set(RedisKeyType.LIFT.key + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand));
            //对主线程抛出等待确认状态waiting
            liftProtocol.setProtocolStatus(LiftProtocolStatusType.WAITING);
            News.info("提升机任务执行下发完成等待执行结束,提升机号={},任务数据={}", command.getLiftNo(), JSON.toJSON(command));
        }
//        //判断数据是否执行完成
//        if (commandStep < size - 1) {
//            //更新redis数据
//            //步序增加
//            commandStep++;
//            redisCommand.setCommandStep(commandStep);
//            //任务数据保存到redis
//            redisUtil.set(RedisKeyType.LIFT.key + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand));
//        }else {
//            //已执行完成
//            //删除redis
//            redisUtil.del(RedisKeyType.LIFT.key + redisCommand.getWrkNo());
//
//            //对主线程抛出等待确认状态waiting
//            liftProtocol.setProtocolStatus(LiftProtocolStatusType.WAITING);
//            News.info("提升机任务执行下发完成等待执行结束,提升机号={},任务数据={}", command.getLiftNo(), JSON.toJSON(command));
//        }
        if (redisCommand.getAssignCommand().getTaskMode() == NyLiftTaskModelType.RESET.id.shortValue()) {
            //复位命令