|  |  | 
 |  |  | import com.zy.asrs.service.LocMastService; | 
 |  |  | import com.zy.asrs.service.WrkMastService; | 
 |  |  | import com.zy.asrs.service.impl.MainServiceImpl; | 
 |  |  | import com.zy.asrs.service.impl.TaskWrkServiceImpl; | 
 |  |  | import com.zy.asrs.utils.CommandUtils; | 
 |  |  | import com.zy.asrs.utils.VersionUtils; | 
 |  |  | import com.zy.core.CrnThread; | 
 |  |  | 
 |  |  | @RestController | 
 |  |  | public class CrnController { | 
 |  |  |  | 
 |  |  |     @Value("${wms.url}") | 
 |  |  |     private String wmsUrl; | 
 |  |  |     @Value("${wms.movePath}") | 
 |  |  |     private String movePath; | 
 |  |  | //    @Value("${wms.url}") | 
 |  |  | //    private String wmsUrl; | 
 |  |  | //    @Value("${wms.movePath}") | 
 |  |  | //    private String movePath; | 
 |  |  |  | 
 |  |  |  | 
 |  |  |  | 
 |  |  | 
 |  |  |     private MainServiceImpl mainService; | 
 |  |  |     @Autowired | 
 |  |  |     private LocMastService locMastService; | 
 |  |  |     @Autowired | 
 |  |  |     private TaskWrkServiceImpl taskWrkService; | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     @ManagerAuth(memo = "进行中的命令") | 
 |  |  | 
 |  |  |             vo.setForkOffset(crnProtocol.getForkPosType().desc);    // 货叉位置 | 
 |  |  |             vo.setLiftPos(crnProtocol.getLiftPosType().desc); | 
 |  |  |             vo.setWalkPos(crnProtocol.getWalkPos()==1?"不在定位":"在定位"); | 
 |  |  |             vo.setWarnCode(String.valueOf(crnProtocol.getAlarm1())); | 
 |  |  |             vo.setWarnCode(String.valueOf(crnProtocol.getAlarm())); | 
 |  |  |             if (crnProtocol.getAlarm() > 0) { | 
 |  |  |                 BasCrnError crnError = basCrnErrorMapper.selectById(crnProtocol.getAlarm()); | 
 |  |  |                 vo.setAlarm(crnError==null?"未知异常":crnError.getErrName()); | 
 |  |  | 
 |  |  |         vo.setForkOffset(crnProtocol.getForkPosType().desc);    // 货叉位置 | 
 |  |  |         vo.setLiftPos(crnProtocol.getLiftPosType().desc); | 
 |  |  |         vo.setWalkPos(crnProtocol.getWalkPos()==1?"不在定位":"在定位"); | 
 |  |  |         vo.setWarnCode(String.valueOf(crnProtocol.getAlarm1())); | 
 |  |  |         if (crnProtocol.getAlarm1() > 0) { | 
 |  |  |             BasCrnError crnError = basCrnErrorMapper.selectById(crnProtocol.getAlarm1()); | 
 |  |  |         vo.setWarnCode(String.valueOf(crnProtocol.getAlarm())); | 
 |  |  |         if (crnProtocol.getAlarm() > 0) { | 
 |  |  |             BasCrnError crnError = basCrnErrorMapper.selectById(crnProtocol.getAlarm()); | 
 |  |  |             vo.setAlarm(crnError==null?"未知异常":crnError.getErrName()); | 
 |  |  |         } | 
 |  |  |         return R.ok().add(vo); | 
 |  |  | 
 |  |  |  | 
 |  |  |             vo.setWorkNo(crnProtocol.getTaskNo());  //  任务号 | 
 |  |  |             if (crnProtocol.getTaskNo()>0) { | 
 |  |  |                 WrkMast wrkMast = wrkMastService.selectById(crnProtocol.getTaskNo()); | 
 |  |  |                 if (wrkMast != null) { | 
 |  |  |                     vo.setStatus(CrnStatusType.process(wrkMast.getIoType()).getDesc());   //  模式状态 | 
 |  |  |                     vo.setSourceStaNo(wrkMast.getSourceStaNo$());    //  源站 | 
 |  |  |                     vo.setStaNo(wrkMast.getStaNo$());   //  目标站 | 
 |  |  |                     vo.setSourceLocNo(wrkMast.getSourceLocNo());    //  源库位 | 
 |  |  |                     vo.setLocNo(wrkMast.getLocNo());    //  目标库位 | 
 |  |  |                 TaskWrk taskWrk = taskWrkService.selectByWrkNo(crnProtocol.getTaskNo().intValue()); | 
 |  |  |                 if (taskWrk != null) { | 
 |  |  | //                    vo.setWrkSts(taskWrk.getWrkSts$());   // 工作状态 | 
 |  |  | //                    vo.setIoType(taskWrk.getIoType$());   //  入出库类型 | 
 |  |  |                     vo.setSourceStaNo(taskWrk.getStartPoint()); | 
 |  |  |                     vo.setStaNo(taskWrk.getTargetPoint()); | 
 |  |  |                 } | 
 |  |  |             } else { | 
 |  |  |                 vo.setStatus(crnProtocol.modeType.equals(CrnModeType.AUTO)? CrnStatusType.MACHINE_AUTO.getDesc(): CrnStatusType.MACHINE_UN_AUTO.getDesc());   //  模式状态 | 
 |  |  | 
 |  |  |  | 
 |  |  |         vo.setWorkNo(crnProtocol.getTaskNo());  //  任务号 | 
 |  |  |         if (crnProtocol.getTaskNo()>0) { | 
 |  |  |             WrkMast wrkMast = wrkMastService.selectById(crnProtocol.getTaskNo()); | 
 |  |  |             if (wrkMast != null) { | 
 |  |  |                 vo.setStatus(CrnStatusType.process(wrkMast.getIoType()).getDesc());   //  模式状态 | 
 |  |  |                 vo.setSourceStaNo(wrkMast.getSourceStaNo$());    //  源站 | 
 |  |  |                 vo.setStaNo(wrkMast.getStaNo$());   //  目标站 | 
 |  |  |                 vo.setSourceLocNo(wrkMast.getSourceLocNo());    //  源库位 | 
 |  |  |                 vo.setLocNo(wrkMast.getLocNo());    //  目标库位 | 
 |  |  |             TaskWrk taskWrk = taskWrkService.selectByWrkNo(crnProtocol.getTaskNo().intValue()); | 
 |  |  |             if (taskWrk != null) { | 
 |  |  | //                vo.setWrkSts(taskWrk.getWrkSts$());   // 工作状态 | 
 |  |  | //                vo.setIoType(taskWrk.getIoType$());   //  入出库类型 | 
 |  |  |                 vo.setSourceStaNo(taskWrk.getStartPoint()); | 
 |  |  |                 vo.setStaNo(taskWrk.getTargetPoint()); | 
 |  |  | //            if (wrkMast != null) { | 
 |  |  | //                vo.setStatus(CrnStatusType.process(wrkMast.getIoType()).getDesc());   //  模式状态 | 
 |  |  | //                vo.setSourceStaNo(wrkMast.getSourceStaNo$());    //  源站 | 
 |  |  | //                vo.setStaNo(wrkMast.getStaNo$());   //  目标站 | 
 |  |  | //                vo.setSourceLocNo(wrkMast.getSourceLocNo());    //  源库位 | 
 |  |  | //                vo.setLocNo(wrkMast.getLocNo());    //  目标库位 | 
 |  |  |             } | 
 |  |  |         } else { | 
 |  |  |             vo.setStatus(crnProtocol.modeType.equals(CrnModeType.AUTO)? CrnStatusType.MACHINE_AUTO.getDesc(): CrnStatusType.MACHINE_UN_AUTO.getDesc());   //  模式状态 | 
 |  |  | 
 |  |  |  | 
 |  |  |             vo.setWorkNo(crnProtocol.getTaskNo());  //  任务号 | 
 |  |  |             if (crnProtocol.getTaskNo()>0) { | 
 |  |  |                 WrkMast wrkMast = wrkMastService.selectById(crnProtocol.getTaskNo()); | 
 |  |  |                 if (wrkMast != null) { | 
 |  |  |                     vo.setDeviceStatus(CrnStatusType.process(wrkMast.getIoType()).getDesc());   //  模式状态 | 
 |  |  |                     vo.setSourceStaNo(wrkMast.getSourceStaNo$());    //  源站 | 
 |  |  |                     vo.setStaNo(wrkMast.getStaNo$());   //  目标站 | 
 |  |  |                     vo.setSourceLocNo(wrkMast.getSourceLocNo());    //  源库位 | 
 |  |  |                     vo.setLocNo(wrkMast.getLocNo());    //  目标库位 | 
 |  |  |                 TaskWrk taskWrk = taskWrkService.selectByWrkNo(crnProtocol.getTaskNo().intValue()); | 
 |  |  | //                WrkMast wrkMast = wrkMastService.selectById(crnProtocol.getTaskNo()); | 
 |  |  |                 if (taskWrk != null) { | 
 |  |  |                     vo.setDeviceStatus(CrnStatusType.process(taskWrk.getIoType()).getDesc());   //  模式状态 | 
 |  |  |                     vo.setSourceStaNo(taskWrk.getStartPoint());    //  源站 | 
 |  |  |                     vo.setStaNo(taskWrk.getTargetPoint());   //  目标站 | 
 |  |  | //                    vo.setSourceLocNo(taskWrk.getTargetPoint());    //  源库位 | 
 |  |  | //                    vo.setLocNo(taskWrk.getLocNo());    //  目标库位 | 
 |  |  |                 } | 
 |  |  |             } else { | 
 |  |  |                 vo.setDeviceStatus(crnProtocol.modeType.equals(CrnModeType.AUTO)? CrnStatusType.MACHINE_AUTO.getDesc(): CrnStatusType.MACHINE_UN_AUTO.getDesc());   //  模式状态 | 
 |  |  |                 if (Cools.isEmpty(crnProtocol.modeType)){ | 
 |  |  |                     vo.setDeviceStatus(CrnStatusType.MACHINE_UN_AUTO.getDesc());   //  模式状态 | 
 |  |  |                 } else { | 
 |  |  |                     vo.setDeviceStatus(crnProtocol.modeType.equals(CrnModeType.AUTO)? CrnStatusType.MACHINE_AUTO.getDesc(): CrnStatusType.MACHINE_UN_AUTO.getDesc());   //  模式状态 | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |             vo.setLaneNo(crnProtocol.getLaneNo());  // | 
 |  |  |             vo.setErrorCrn(crnProtocol.getErrCrn());  // | 
 |  |  |             vo.setXspeed(crnProtocol.getXSpeed());  //  走行速度(m/min) | 
 |  |  |             vo.setYspeed(crnProtocol.getYSpeed());  //  升降速度(m/min) | 
 |  |  |             vo.setZspeed(crnProtocol.getZSpeed());  //  叉牙速度(m/min) | 
 |  |  | 
 |  |  |             vo.setYdistance(crnProtocol.getYDistance());  //  升降距离(Km) | 
 |  |  |             vo.setXduration(crnProtocol.getXDuration());    //  走行时长(H) | 
 |  |  |             vo.setYduration(crnProtocol.getYDuration());    //  升降时长(H) | 
 |  |  |  | 
 |  |  |             vo.setStatusType(crnProtocol.modeType.desc);   //  模式状态 | 
 |  |  |             if (Cools.isEmpty(crnProtocol.modeType)){ | 
 |  |  |                 vo.setStatusType(CrnStatusType.MACHINE_UN_AUTO.getDesc());   //  模式状态 | 
 |  |  |             } else { | 
 |  |  |                 vo.setStatusType(crnProtocol.modeType.desc);   //  模式状态 | 
 |  |  |             } | 
 |  |  |             vo.setWrkStatus(crnProtocol.getStatusType().id);     //  任务状态 | 
 |  |  |             vo.setLoading((crnProtocol.getLoaded() != null && crnProtocol.getLoaded() == 1) ? "有物" : "无物");  //  有物 | 
 |  |  |             vo.setBay(crnProtocol.getBay());    //  列 | 
 |  |  | 
 |  |  |             vo.setForkOffset(crnProtocol.getForkPosType().desc);    // 货叉位置 | 
 |  |  |             vo.setLiftPos(crnProtocol.getLiftPosType().desc); | 
 |  |  |             vo.setWalkPos(crnProtocol.getWalkPos()==1?"不在定位":"在定位"); | 
 |  |  |             vo.setWarnCode(String.valueOf(crnProtocol.getAlarm1())); | 
 |  |  |             if (crnProtocol.getAlarm1() > 0) { | 
 |  |  |                 BasCrnError crnError = basCrnErrorMapper.selectById(crnProtocol.getAlarm1()); | 
 |  |  |             vo.setWarnCode(String.valueOf(crnProtocol.getAlarm())); | 
 |  |  |             if (crnProtocol.getAlarm() > 0) { | 
 |  |  |                 BasCrnError crnError = basCrnErrorMapper.selectById(crnProtocol.getAlarm()); | 
 |  |  |                 vo.setAlarm(crnError==null?"未知异常":crnError.getErrName()); | 
 |  |  |             } | 
 |  |  |             vo.setInEnable(basCrnp.getInEnable()); | 
 |  |  |             vo.setOutEnable(basCrnp.getOutEnable()); | 
 |  |  |             vo.setTaskComplete(crnThread.getResetFlag()? "任务完成下发等待":"-"); | 
 |  |  |         } | 
 |  |  |         return R.ok().add(list); | 
 |  |  |     } | 
 |  |  | 
 |  |  |         command.setDestinationPosX(param.getBay());     // 目标库位列 | 
 |  |  |         command.setDestinationPosY(param.getLev());     // 目标库位层 | 
 |  |  |         command.setCommand((short)1); | 
 |  |  |         LocMast sourceLoc = locMastService.selectOne(new EntityWrapper<LocMast>().eq("row1", command.getSourcePosX()) | 
 |  |  |                 .eq("bay1", command.getSourcePosY()).eq("lev1", command.getSourcePosZ())); | 
 |  |  |         LocMast loc = locMastService.selectOne(new EntityWrapper<LocMast>().eq("row1", command.getDestinationPosX()) | 
 |  |  |                 .eq("bay1", command.getDestinationPosY()).eq("lev1", command.getDestinationPosZ())); | 
 |  |  |         VersionUtils.locMoveCheckLocType(sourceLoc, loc); | 
 |  |  | //        LocMast sourceLoc = locMastService.selectOne(new EntityWrapper<LocMast>().eq("row1", command.getSourcePosX()) | 
 |  |  | //                .eq("bay1", command.getSourcePosY()).eq("lev1", command.getSourcePosZ())); | 
 |  |  | //        LocMast loc = locMastService.selectOne(new EntityWrapper<LocMast>().eq("row1", command.getDestinationPosX()) | 
 |  |  | //                .eq("bay1", command.getDestinationPosY()).eq("lev1", command.getDestinationPosZ())); | 
 |  |  | //        VersionUtils.locMoveCheckLocType(sourceLoc, loc); | 
 |  |  |         return crnControl(command)?R.ok():R.error(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | 
 |  |  | //        if (SystemProperties.WCS_RUNNING_STATUS.get()) { | 
 |  |  | //            return R.error("wcs系统状态为开启"); | 
 |  |  | //        } | 
 |  |  |         CrnCommand command = new CrnCommand(); | 
 |  |  |         command.setCrnNo(param.getCrnNo()); // 堆垛机编号 | 
 |  |  |         command.setTaskNo((short) 0); // 工作号 | 
 |  |  |         command.setAckFinish((short) 1);  // 任务完成确认位 | 
 |  |  |         command.setTaskMode(CrnTaskModeType.NONE); // 任务模式 | 
 |  |  |         command.setSourcePosX((short) 0);     // 源库位排 | 
 |  |  |         command.setSourcePosY((short) 0);     // 源库位列 | 
 |  |  |         command.setSourcePosZ((short) 0);     // 源库位层 | 
 |  |  |         command.setDestinationPosX((short) 0);     // 目标库位排 | 
 |  |  |         command.setDestinationPosY((short) 0);     // 目标库位列 | 
 |  |  |         command.setDestinationPosZ((short) 0);     // 目标库位层 | 
 |  |  |         command.setCommand((short)0); | 
 |  |  |         return crnControl(command)?R.ok():R.error(); | 
 |  |  |         if (Cools.isEmpty(param.getCrnNo()) || param.getCrnNo() == 0) { | 
 |  |  |             return R.error("请选择堆垛机"); | 
 |  |  |         } | 
 |  |  |         CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, param.getCrnNo()); | 
 |  |  |         crnThread.setResetFlag(true); | 
 |  |  |         return R.ok(); | 
 |  |  | //        CrnCommand command = new CrnCommand(); | 
 |  |  | //        command.setCrnNo(); // 堆垛机编号 | 
 |  |  | //        command.setTaskNo((short) 0); // 工作号 | 
 |  |  | //        command.setAckFinish((short) 1);  // 任务完成确认位 | 
 |  |  | //        command.setTaskMode(CrnTaskModeType.NONE); // 任务模式 | 
 |  |  | //        command.setSourcePosX((short) 0);     // 源库位排 | 
 |  |  | //        command.setSourcePosY((short) 0);     // 源库位列 | 
 |  |  | //        command.setSourcePosZ((short) 0);     // 源库位层 | 
 |  |  | //        command.setDestinationPosX((short) 0);     // 目标库位排 | 
 |  |  | //        command.setDestinationPosY((short) 0);     // 目标库位列 | 
 |  |  | //        command.setDestinationPosZ((short) 0);     // 目标库位层 | 
 |  |  | //        command.setCommand((short)0); | 
 |  |  | //        return crnControl(command)?R.ok():R.error(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @ManagerAuth(memo = "任务完成指令清除") | 
 |  |  |     @PostMapping("/crn/operator/taskCompleteClearCommand") | 
 |  |  |     public R crnTaskCompleteClearCommand(CrnOperatorParam param){ | 
 |  |  |         // 系统运行状态判断 | 
 |  |  | //        if (SystemProperties.WCS_RUNNING_STATUS.get()) { | 
 |  |  | //            return R.error("wcs系统状态为开启"); | 
 |  |  | //        } | 
 |  |  |         // 系统运行状态判断 | 
 |  |  |         if (Cools.isEmpty(param.getCrnNo()) || param.getCrnNo() == 0) { | 
 |  |  |             return R.error("请选择堆垛机"); | 
 |  |  |         } | 
 |  |  |         CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, param.getCrnNo()); | 
 |  |  |         crnThread.setResetFlag(false); | 
 |  |  |         return R.ok(); | 
 |  |  | //        CrnCommand command = new CrnCommand(); | 
 |  |  | //        command.setCrnNo(); // 堆垛机编号 | 
 |  |  | //        command.setTaskNo((short) 0); // 工作号 | 
 |  |  | //        command.setAckFinish((short) 1);  // 任务完成确认位 | 
 |  |  | //        command.setTaskMode(CrnTaskModeType.NONE); // 任务模式 | 
 |  |  | //        command.setSourcePosX((short) 0);     // 源库位排 | 
 |  |  | //        command.setSourcePosY((short) 0);     // 源库位列 | 
 |  |  | //        command.setSourcePosZ((short) 0);     // 源库位层 | 
 |  |  | //        command.setDestinationPosX((short) 0);     // 目标库位排 | 
 |  |  | //        command.setDestinationPosY((short) 0);     // 目标库位列 | 
 |  |  | //        command.setDestinationPosZ((short) 0);     // 目标库位层 | 
 |  |  | //        command.setCommand((short)0); | 
 |  |  | //        return crnControl(command)?R.ok():R.error(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | //    @ManagerAuth(memo = "暂停") | 
 |  |  | 
 |  |  |                 } | 
 |  |  |                 CrnCommand crnCommand = new CrnCommand(); | 
 |  |  |                 crnCommand.setCrnNo(crn.getId()); // 堆垛机编号 | 
 |  |  |                 crnCommand.setLaneNo(crnProtocol.getLaneNo()); // 堆垛机巷道号 | 
 |  |  |                 crnCommand.setTaskMode(CrnTaskModeType.CLEAR); | 
 |  |  |                 crnCommand.setAckFinish((short) 0);  // 任务完成确认位 | 
 |  |  |                 crnCommand.setCommand((short) 0);  // 任务完成确认位 | 
 |  |  |                 // 延时发送 | 
 |  |  |                 Thread.sleep(1000L); | 
 |  |  |                 if (CommandUtils.offer(SlaveType.Crn, crn.getId(), new Task(5, crnCommand), false)) { | 
 |  |  |                 if (MessageQueue.offer(SlaveType.Crn, crn.getId(), new Task(5, crnCommand))) { | 
 |  |  |                     return R.ok(); | 
 |  |  |                 } else { | 
 |  |  |                     throw new CoolException("命令下发失败"); | 
 |  |  | 
 |  |  |                 if (crnProtocol == null) { | 
 |  |  |                     throw new CoolException("堆垛机不在线"); | 
 |  |  |                 } | 
 |  |  |                 command.setLaneNo(crnProtocol.getLaneNo()); // 堆垛机巷道号 | 
 |  |  |  | 
 |  |  |                 // 空闲判断 | 
 |  |  | //                if (crnProtocol.getStatusType().equals(com.zy.core.enums.CrnStatusType.IDLE) && crnProtocol.getTaskNo() == 0) { | 
 |  |  |                 if (CommandUtils.offer(SlaveType.Crn, crn.getId(), new Task(4, command), false)) { | 
 |  |  |                 if (MessageQueue.offer(SlaveType.Crn, crn.getId(), new Task(4, command))) { | 
 |  |  |                     return true; | 
 |  |  |                 } else { | 
 |  |  |                     throw new CoolException("命令下发失败"); | 
 |  |  | 
 |  |  |                 if (crnProtocol == null) { | 
 |  |  |                     throw new CoolException("堆垛机不在线"); | 
 |  |  |                 } | 
 |  |  |                 command.setLaneNo(crnProtocol.getLaneNo()); // 堆垛机巷道号 | 
 |  |  |  | 
 |  |  |                 // 空闲判断 | 
 |  |  | //                if (crnProtocol.getStatusType().equals(com.zy.core.enums.CrnStatusType.IDLE) && crnProtocol.getTaskNo() == 0) { | 
 |  |  |                 if (CommandUtils.offer(SlaveType.Crn, crn.getId(), new Task(2, command), false)) { | 
 |  |  |                 if (MessageQueue.offer(SlaveType.Crn, crn.getId(), new Task(2, command))) { | 
 |  |  |                     return true; | 
 |  |  |                 } else { | 
 |  |  |                     throw new CoolException("命令下发失败"); |