| | |
| | | import com.zy.core.enums.*; |
| | | import com.zy.core.model.ShuttleSlave; |
| | | import com.zy.core.model.Task; |
| | | import com.zy.core.model.command.LiftAssignCommand; |
| | | import com.zy.core.model.command.LiftCommand; |
| | | import com.zy.core.model.command.ShuttleAssignCommand; |
| | | import com.zy.core.model.command.ShuttleCommand; |
| | | import com.zy.core.model.command.*; |
| | | import com.zy.core.model.protocol.LiftProtocol; |
| | | import com.zy.core.model.protocol.ShuttleProtocol; |
| | | import lombok.Data; |
| | |
| | | import java.text.MessageFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | |
| | | if(shuttleProtocol.getProtocolStatusType() == ShuttleProtocolStatusType.FIXING |
| | | && shuttleProtocol.getTaskNo() != 0 |
| | | && shuttleProtocol.getBusyStatusType() == ShuttleStatusType.IDLE |
| | | && shuttleProtocol.getAssignCommand() != null){ |
| | | && shuttleProtocol.getBusyStatusType() == ShuttleStatusType.IDLE){ |
| | | //处于故障修复状态 |
| | | //执行下一步指令 |
| | | executeWork(shuttleProtocol.getAssignCommand()); |
| | | executeWork(shuttleProtocol.getTaskNo()); |
| | | } |
| | | |
| | | //四向穿梭车空闲、有任务、标记为true、存在任务指令,需要执行任务的下一条指令 |
| | | if (shuttleProtocol.getBusyStatusType() == ShuttleStatusType.IDLE |
| | | && shuttleProtocol.getTaskNo() != 0 |
| | | && shuttleProtocol.getPakMk() |
| | | && shuttleProtocol.getAssignCommand() != null) { |
| | | && shuttleProtocol.getPakMk()) { |
| | | //执行下一步指令 |
| | | executeWork(shuttleProtocol.getAssignCommand()); |
| | | executeWork(shuttleProtocol.getTaskNo()); |
| | | } |
| | | |
| | | //检测是否有提升机锁定标记,有则检测提升机是否到位,是否能走下一步命令 |
| | | if (shuttleProtocol.getBusyStatusType() == ShuttleStatusType.IDLE |
| | | && shuttleProtocol.getTaskNo() != 0 |
| | | && shuttleProtocol.getAssignCommand() != null) { |
| | | Object o = redisUtil.get("wrk_no_" + shuttleProtocol.getAssignCommand().getTaskNo()); |
| | | && shuttleProtocol.getTaskNo() != 0) { |
| | | Object o = redisUtil.get("wrk_no_" + shuttleProtocol.getTaskNo()); |
| | | if (o != null) { |
| | | HashMap map = JSON.parseObject(o.toString(), HashMap.class); |
| | | if (map.containsKey("liftSecurityMk") && Boolean.parseBoolean(map.get("liftSecurityMk").toString())) { |
| | | ShuttleRedisCommand redisCommand = JSON.parseObject(o.toString(), ShuttleRedisCommand.class); |
| | | if (redisCommand.getLiftSecurityMk()) { |
| | | //执行下一步指令 |
| | | executeWork(shuttleProtocol.getAssignCommand()); |
| | | executeWork(shuttleProtocol.getTaskNo()); |
| | | } |
| | | } |
| | | } |
| | |
| | | return false; |
| | | } |
| | | |
| | | BasShuttleService shuttleService = SpringUtils.getBean(BasShuttleService.class); |
| | | if (shuttleService == null) { |
| | | News.error("系统错误"); |
| | | return false; |
| | | } |
| | | |
| | | BasShuttle basShuttle = shuttleService.selectById(slave.getId().shortValue()); |
| | | if (basShuttle == null) { |
| | | News.error("四向穿梭车不存在"); |
| | | return false; |
| | | } |
| | | |
| | | command.setShuttleNo(slave.getId().shortValue()); |
| | | // 开始任务 |
| | | short[] array = new short[17]; |
| | |
| | | array[7] = middleToDistDistances[1]; |
| | | } |
| | | |
| | | array[8] = basShuttle.getRunSpeed().shortValue();//四向穿梭车运行速度,从系统数据库读出 |
| | | if (command.getRunDirection() != null) { |
| | | //小车运行方向 |
| | | array[8] = command.getRunDirection(); |
| | |
| | | |
| | | //分配任务 |
| | | private void assignWork(ShuttleAssignCommand assignCommand) { |
| | | //将此map存入redis中 |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | if (!assignCommand.getAuto()) { |
| | | List<ShuttleCommand> commands = new ArrayList<>(); |
| | | ShuttleCommand command = new ShuttleCommand(); |
| | |
| | | assignCommand.setCommands(commands); |
| | | } |
| | | |
| | | //四向穿梭车号 |
| | | map.put("shuttle_no", assignCommand.getShuttleNo()); |
| | | //工作号 |
| | | map.put("wrk_no", assignCommand.getTaskNo()); |
| | | //命令执行步序 |
| | | map.put("commandStep", 0); |
| | | //命令 |
| | | map.put("assignCommand", assignCommand); |
| | | //发生错误时尝试执行的指令,优先级最高 |
| | | map.put("errorCommands", new ArrayList<ShuttleCommand>()); |
| | | ShuttleRedisCommand redisCommand = new ShuttleRedisCommand(); |
| | | redisCommand.setShuttleNo(assignCommand.getShuttleNo());//四向穿梭车号 |
| | | redisCommand.setWrkNo(assignCommand.getTaskNo());//工作号 |
| | | redisCommand.setCommandStep(0);//命令执行步序 |
| | | redisCommand.setAssignCommand(assignCommand);//命令 |
| | | redisCommand.setErrorCommands(new ArrayList<ShuttleCommand>());//发生错误时尝试执行的指令,优先级最高 |
| | | shuttleProtocol.setTaskNo(assignCommand.getTaskNo()); |
| | | shuttleProtocol.setAssignCommand(assignCommand); |
| | | shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.WORKING); |
| | | //任务数据保存到redis |
| | | redisUtil.set("wrk_no_" + assignCommand.getTaskNo(), JSON.toJSONString(map)); |
| | | redisUtil.set("wrk_no_" + assignCommand.getTaskNo(), JSON.toJSONString(redisCommand)); |
| | | //执行下发任务 |
| | | executeWork(assignCommand); |
| | | executeWork(assignCommand.getTaskNo()); |
| | | } |
| | | |
| | | //执行下发的指令 |
| | | private boolean executeWork(ShuttleAssignCommand assignCommand) { |
| | | private boolean executeWork(Short wrkNo) { |
| | | //读取redis数据 |
| | | if (assignCommand == null) { |
| | | if (wrkNo == null) { |
| | | return false; |
| | | } |
| | | |
| | | Object o = redisUtil.get("wrk_no_" + assignCommand.getTaskNo()); |
| | | Object o = redisUtil.get("wrk_no_" + wrkNo); |
| | | if (o == null) { |
| | | return false; |
| | | } |
| | | HashMap map = JSON.parseObject(o.toString(), HashMap.class); |
| | | ShuttleRedisCommand redisCommand = JSON.parseObject(o.toString(), ShuttleRedisCommand.class); |
| | | |
| | | if (!checkLiftStation(assignCommand)) {//检测是否有提升机站点,有则调度提升机 |
| | | if (!checkLiftStation(wrkNo)) {//检测是否有提升机站点,有则调度提升机 |
| | | return false; |
| | | } |
| | | |
| | | //将标记置为false(防止重发) |
| | | shuttleProtocol.setPakMk(false); |
| | | |
| | | List<ShuttleCommand> errorCommands = JSON.parseArray(map.get("errorCommands").toString(),ShuttleCommand.class); |
| | | List<ShuttleCommand> errorCommands = redisCommand.getErrorCommands(); |
| | | if (errorCommands.size() > 0) { |
| | | //优先执行该指令 |
| | | ShuttleCommand errorCommand = errorCommands.get(0);//取出指令 |
| | |
| | | if (shuttleProtocol.getCurrentCode().equals(errorCommand.getStartCodeNum())) { |
| | | //起点和终点属于同一库位,无需再执行移动操作 |
| | | errorCommands.remove(0);//移除该命令 |
| | | map.put("errorCommands", new ArrayList<ShuttleCommand>()); |
| | | redisCommand.setErrorCommands(new ArrayList<ShuttleCommand>()); |
| | | shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.WORKING); |
| | | //当前步序 |
| | | int commandStep = Integer.parseInt(map.get("commandStep").toString()); |
| | | int commandStep = redisCommand.getCommandStep(); |
| | | //步序回退 |
| | | commandStep--; |
| | | map.put("commandStep", commandStep); |
| | | redisCommand.setCommandStep(commandStep); |
| | | //任务数据保存到redis |
| | | redisUtil.set("wrk_no_" + assignCommand.getTaskNo(), JSON.toJSONString(map)); |
| | | redisUtil.set("wrk_no_" + wrkNo, JSON.toJSONString(redisCommand)); |
| | | shuttleProtocol.setPakMk(true); |
| | | return true; |
| | | }else { |
| | |
| | | |
| | | shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.WORKING); |
| | | //当前步序 |
| | | int commandStep = Integer.parseInt(map.get("commandStep").toString()); |
| | | int commandStep = redisCommand.getCommandStep(); |
| | | //步序回退 |
| | | commandStep--; |
| | | map.put("commandStep", commandStep); |
| | | redisCommand.setCommandStep(commandStep); |
| | | } |
| | | |
| | | if (!write(errorCommand)) { |
| | |
| | | } else { |
| | | News.info("四向穿梭车命令下发成功,穿梭车号={},任务数据={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(errorCommand)); |
| | | errorCommands.remove(0); |
| | | map.put("errorCommands", errorCommands); |
| | | redisCommand.setErrorCommands(errorCommands); |
| | | //任务数据保存到redis |
| | | redisUtil.set("wrk_no_" + assignCommand.getTaskNo(), JSON.toJSONString(map)); |
| | | redisUtil.set("wrk_no_" + wrkNo, JSON.toJSONString(redisCommand)); |
| | | return true; |
| | | } |
| | | } |
| | | |
| | | List<ShuttleCommand> commands = assignCommand.getCommands(); |
| | | List<ShuttleCommand> commands = redisCommand.getAssignCommand().getCommands(); |
| | | //当前步序 |
| | | int commandStep = Integer.parseInt(map.get("commandStep").toString()); |
| | | int commandStep = redisCommand.getCommandStep(); |
| | | //path路径数目 |
| | | int size = commands.size(); |
| | | ShuttleAssignCommand assignCommand = redisCommand.getAssignCommand(); |
| | | |
| | | //取出命令 |
| | | ShuttleCommand command = commands.get(commandStep); |
| | |
| | | //更新redis数据 |
| | | //步序增加 |
| | | commandStep++; |
| | | map.put("commandStep", commandStep); |
| | | redisCommand.setCommandStep(commandStep); |
| | | //任务数据保存到redis |
| | | redisUtil.set("wrk_no_" + map.get("wrk_no").toString(), JSON.toJSONString(map)); |
| | | redisUtil.set("wrk_no_" + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand)); |
| | | }else { |
| | | //已执行完成 |
| | | //保存数据到数据库做流水 |
| | |
| | | shuttleOptService.insert(opt); |
| | | } |
| | | |
| | | if (map.containsKey("liftSecurityMk") && Boolean.parseBoolean(map.get("liftSecurityMk").toString())) { |
| | | if (redisCommand.getLiftSecurityMk()) { |
| | | //曾锁定过提升机,需要进行解锁 |
| | | LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, 1); |
| | | LiftProtocol liftProtocol = liftThread.getLiftProtocol(); |
| | |
| | | } |
| | | |
| | | //删除redis |
| | | redisUtil.del("wrk_no_" + map.get("wrk_no").toString()); |
| | | redisUtil.del("wrk_no_" + redisCommand.getWrkNo()); |
| | | |
| | | if (!assignCommand.getAuto()) { |
| | | //手动模式不抛出等待状态,直接复位 |
| | | if (assignCommand.getTaskMode() == 9) { |
| | | //设置四向穿梭车为空闲状态 |
| | | shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.IDLE); |
| | | //任务号清零 |
| | | shuttleProtocol.setTaskNo((short) 0); |
| | | //标记复位 |
| | | shuttleProtocol.setPakMk(true); |
| | | //任务指令清零 |
| | | shuttleProtocol.setAssignCommand(null); |
| | | } |
| | | //设置四向穿梭车为空闲状态 |
| | | shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.IDLE); |
| | | //任务号清零 |
| | | shuttleProtocol.setTaskNo((short) 0); |
| | | //标记复位 |
| | | shuttleProtocol.setPakMk(true); |
| | | News.info("四向穿梭车手动任务执行完成,穿梭车号={},任务数据={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(command)); |
| | | }else { |
| | | if (!assignCommand.getCharge()) { |
| | |
| | | /** |
| | | * 检测是否有提升机站点,有则调度提升机 |
| | | */ |
| | | private boolean checkLiftStation(ShuttleAssignCommand assignCommand) { |
| | | private boolean checkLiftStation(Short wrkNo) { |
| | | //读取redis数据 |
| | | if (assignCommand == null) { |
| | | if (wrkNo == null) { |
| | | return false; |
| | | } |
| | | |
| | | Object o = redisUtil.get("wrk_no_" + assignCommand.getTaskNo()); |
| | | Object o = redisUtil.get("wrk_no_" + wrkNo); |
| | | if (o == null) { |
| | | return false; |
| | | } |
| | | HashMap map = JSON.parseObject(o.toString(), HashMap.class); |
| | | ShuttleRedisCommand redisCommand = JSON.parseObject(o.toString(), ShuttleRedisCommand.class); |
| | | //当前步序 |
| | | int commandStep = Integer.parseInt(map.get("commandStep").toString()); |
| | | int commandStep = redisCommand.getCommandStep(); |
| | | |
| | | //检测是否存在提升机口的指令 |
| | | List<ShuttleCommand> commands = assignCommand.getCommands(); |
| | | List<ShuttleCommand> commands = redisCommand.getAssignCommand().getCommands(); |
| | | BasDevpService basDevpService = SpringUtils.getBean(BasDevpService.class); |
| | | ArrayList<Short> qrCodeValues = new ArrayList<>(); |
| | | for (BasDevp basDevp : basDevpService.selectList(null)) { |
| | |
| | | liftProtocol.setShuttleNo(shuttleProtocol.getShuttleNo());//设置四向穿梭车号 |
| | | liftProtocol.setProtocolStatus(LiftProtocolStatusType.WORKING);//设置提升机状态为工作中 |
| | | liftProtocol.setSecurityMk(true);//标记置为true,防止其他任务占用当前提升机 |
| | | map.put("liftSecurityMk", true);//标记置为true,防止其他任务占用当前提升机 |
| | | redisCommand.setLiftSecurityMk(true);//标记置为true,防止其他任务占用当前提升机 |
| | | //任务数据保存到redis |
| | | redisUtil.set("wrk_no_" + assignCommand.getTaskNo(), JSON.toJSONString(map)); |
| | | redisUtil.set("wrk_no_" + wrkNo, JSON.toJSONString(redisCommand)); |
| | | |
| | | //命令list |
| | | ArrayList<LiftCommand> liftCommands = new ArrayList<>(); |
| | |
| | | return false; |
| | | } |
| | | |
| | | HashMap map = JSON.parseObject(o.toString(), HashMap.class); |
| | | ShuttleRedisCommand redisCommand = JSON.parseObject(o.toString(), ShuttleRedisCommand.class); |
| | | List<ShuttleCommand> commands = assignCommand.getCommands(); |
| | | //当前步序 |
| | | int commandStep = Integer.parseInt(map.get("commandStep").toString()); |
| | | int commandStep = redisCommand.getCommandStep(); |
| | | //path路径数目 |
| | | int size = commands.size(); |
| | | |
| | |
| | | moveCommand.setStartCodeNum(command.getStartCodeNum());//存入目标库位号 |
| | | list.add(moveCommand); |
| | | |
| | | map.put("errorCommands", list); |
| | | redisCommand.setErrorCommands(list); |
| | | //任务数据保存到redis |
| | | redisUtil.set("wrk_no_" + assignCommand.getTaskNo(), JSON.toJSONString(map)); |
| | | redisUtil.set("wrk_no_" + assignCommand.getTaskNo(), JSON.toJSONString(redisCommand)); |
| | | shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.FIXING); |
| | | return true; |
| | | } |