|  |  | 
 |  |  | import com.zy.core.cache.MessageQueue; | 
 |  |  | import com.zy.core.cache.OutputQueue; | 
 |  |  | import com.zy.core.cache.SlaveConnection; | 
 |  |  | import com.zy.core.enums.CrnLiftPosType; | 
 |  |  | import com.zy.core.enums.CrnModeType; | 
 |  |  | import com.zy.core.enums.CrnTaskModeType; | 
 |  |  | import com.zy.core.enums.SlaveType; | 
 |  |  | 
 |  |  | import com.zy.core.model.protocol.CrnProtocol; | 
 |  |  | import com.zy.core.properties.SlaveProperties; | 
 |  |  | import com.zy.core.properties.SystemProperties; | 
 |  |  | import com.zy.system.entity.Config; | 
 |  |  | import com.zy.system.service.ConfigService; | 
 |  |  | import lombok.extern.slf4j.Slf4j; | 
 |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
 |  |  | import org.springframework.web.bind.annotation.GetMapping; | 
 |  |  | import org.springframework.web.bind.annotation.PostMapping; | 
 |  |  | import org.springframework.web.bind.annotation.RequestMapping; | 
 |  |  | import org.springframework.web.bind.annotation.RestController; | 
 |  |  |  | 
 |  |  | import java.util.ArrayList; | 
 |  |  | import java.util.HashMap; | 
 |  |  | import java.util.List; | 
 |  |  | import java.util.Map; | 
 |  |  |  | 
 |  |  | /** | 
 |  |  |  * 堆垛机接口 | 
 |  |  | 
 |  |  |     private MainServiceImpl mainService; | 
 |  |  |     @Autowired | 
 |  |  |     private LocMastService locMastService; | 
 |  |  |     @Autowired | 
 |  |  |     private ConfigService configService; | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     @ManagerAuth(memo = "进行中的命令") | 
 |  |  | 
 |  |  |                 continue; | 
 |  |  |             } | 
 |  |  |             vo.setWorkNo(crnProtocol.getTaskNo());  //  任务号 | 
 |  |  | //            if (crnProtocol.getTaskNo()>0) { | 
 |  |  | //                WrkMast wrkMast = wrkMastService.selectById(crnProtocol.getTaskNo()); | 
 |  |  | //                if (wrkMast != null) { | 
 |  |  | //                    vo.setStatusType(CrnStatusType.process(wrkMast.getIoType()).getDesc());   //  模式状态 | 
 |  |  | //                } | 
 |  |  | //            } else { | 
 |  |  | // | 
 |  |  | //            } | 
 |  |  |             vo.setStatusType(crnProtocol.modeType.desc);   //  模式状态 | 
 |  |  |             if (crnProtocol.getTaskFinish() == 1) { | 
 |  |  |                 vo.setStatus("等待确认"); | 
 |  |  |             } else { | 
 |  |  |                 vo.setStatus(crnProtocol.getStatusType().desc);     //  状态 | 
 |  |  |             } | 
 |  |  |             vo.setStatus(crnProtocol.getStatusType().desc);     //  状态 | 
 |  |  |             vo.setLoading(crnProtocol.getLoaded()==1?"有物":"无物");  //  有物 | 
 |  |  |             vo.setBay(crnProtocol.getBay());    //  列 | 
 |  |  |             vo.setLev(crnProtocol.getLevel());  //  层 | 
 |  |  |             vo.setLiftPos(crnProtocol.getLiftPosType().desc); | 
 |  |  |             if (crnProtocol.getPlatformHigh()) { | 
 |  |  |                 vo.setSitePos("站台高位"); | 
 |  |  |             } | 
 |  |  |             if (crnProtocol.getPlatformLow()) { | 
 |  |  |                 vo.setSitePos("站台高位"); | 
 |  |  |             } | 
 |  |  | //            vo.setXOrigin(crnProtocol.getBay()==1?"是":"否");     //  走行原点 | 
 |  |  | //            vo.setYOrigin(crnProtocol.getLevel()==1?"是":"否");     // 升降原点 | 
 |  |  |             vo.setForkOffset(crnProtocol.getForkPosType().desc);    // 货叉位置 | 
 |  |  |             vo.setXLocation(crnProtocol.getWalkPos() == 1?"是":"否");      // 走行定位 | 
 |  |  |             vo.setYLocation(crnProtocol.getLiftPosType().equals(CrnLiftPosType.NONE)?"否":"是");      // 升降定位 | 
 |  |  | //            vo.setStop(crnProtocol.getCrnError1().controlStop||crnProtocol.getCrnError1().mainStop||crnProtocol.getCrnError1().remoteStop?"是":"否");       //  急停 | 
 |  |  |             vo.setAlarm1(String.valueOf(crnProtocol.getAlarm1())); | 
 |  |  |             vo.setAlarm2(String.valueOf(crnProtocol.getAlarm2())); | 
 |  |  |             vo.setAlarm3(String.valueOf(crnProtocol.getAlarm3())); | 
 |  |  |             vo.setAlarm4(String.valueOf(crnProtocol.getAlarm4())); | 
 |  |  | //            vo.setWarnCode(String.valueOf(crnProtocol.getAlarm1()));  //  异常码 | 
 |  |  |  | 
 |  |  |             vo.setForkOffset(crnProtocol.getForkPosType().desc);    // 货叉位置 | 
 |  |  |             vo.setLiftPos(crnProtocol.getLiftPosType().desc); | 
 |  |  |             vo.setWalkPos(crnProtocol.getWalkPos()==1?"不在定位":"在定位"); | 
 |  |  |             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(list); | 
 |  |  |     } | 
 |  |  | 
 |  |  |     @PostMapping("/table/crn/msg") | 
 |  |  |     @ManagerAuth(memo = "堆垛机数据表") | 
 |  |  |     public R crnMsgTable(){ | 
 |  |  |         Config crnSearchDetectTaskCountConfig = configService.selectOne(new EntityWrapper<Config>() | 
 |  |  |                 .eq("code", "crnSearchDetectTaskCount") | 
 |  |  |         ); | 
 |  |  |         int crnSearchDetectTaskCount = Integer.parseInt(crnSearchDetectTaskCountConfig.getValue()); | 
 |  |  |  | 
 |  |  |         Config applyInTaskTotalCountConfig = configService.selectOne(new EntityWrapper<Config>() | 
 |  |  |                 .eq("code", "applyInTaskTotalCount") | 
 |  |  |         ); | 
 |  |  |         int applyInTaskTotalCount = Integer.parseInt(applyInTaskTotalCountConfig.getValue()); | 
 |  |  |  | 
 |  |  |         List<CrnMsgTableVo> list = new ArrayList<>(); | 
 |  |  |         List<BasCrnp> crnps = basCrnpService.selectList(new EntityWrapper<BasCrnp>().orderBy("crn_no")); | 
 |  |  |         for (BasCrnp basCrnp : crnps) { | 
 |  |  | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |             vo.setWorkNo(crnProtocol.getTaskNo());  //  任务号 | 
 |  |  |             BasCrnError crnError = basCrnErrorMapper.selectById(crnProtocol.getAlarm1()); | 
 |  |  |             if (null != crnError) { | 
 |  |  |                 vo.setError(crnError.getErrName()); | 
 |  |  |             } | 
 |  |  |             if (crnProtocol.getTaskNo()>0) { | 
 |  |  |                 WrkMast wrkMast = wrkMastService.selectById(crnProtocol.getTaskNo()); | 
 |  |  |                 if (wrkMast != null) { | 
 |  |  | 
 |  |  |             vo.setYdistance(crnProtocol.getYDistance());  //  升降距离(Km) | 
 |  |  |             vo.setXduration(crnProtocol.getXDuration());    //  走行时长(H) | 
 |  |  |             vo.setYduration(crnProtocol.getYDuration());    //  升降时长(H) | 
 |  |  |             vo.setCrnSearchDetectTaskCount(crnSearchDetectTaskCount); | 
 |  |  |             vo.setApplyInTaskTotalCount(applyInTaskTotalCount); | 
 |  |  |  | 
 |  |  |             List<WrkMast> inWrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>() | 
 |  |  |                     .eq("crn_no", basCrnp.getCrnNo()) | 
 |  |  |                     .in("io_type", 1, 10, 53, 57) | 
 |  |  |             ); | 
 |  |  |             vo.setCurrentInTask(inWrkMasts.size()); | 
 |  |  |  | 
 |  |  |             List<WrkMast> wrkMastsList = wrkMastService.selectList(new EntityWrapper<WrkMast>() | 
 |  |  |                     .eq("crn_no", basCrnp.getCrnNo()) | 
 |  |  |                     .in("io_type", 1, 10, 53, 57, 101, 103, 107, 110) | 
 |  |  |             ); | 
 |  |  |             vo.setCurrentTotalTask(wrkMastsList.size()); | 
 |  |  |         } | 
 |  |  |         return R.ok().add(list); | 
 |  |  |     } | 
 |  |  | 
 |  |  |         return R.ok().add(str.toString()); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     @GetMapping("/demo/status") | 
 |  |  |     public R demoStatus(){ | 
 |  |  |         List<Map<String, Object>> res = new ArrayList<>(); | 
 |  |  |         for (CrnSlave crnSlave : slaveProperties.getCrn()) { | 
 |  |  |             Map<String, Object> map = new HashMap<>(); | 
 |  |  |             map.put("crnNo", crnSlave.getId()); | 
 |  |  |             map.put("demo", crnSlave.getDemo()); | 
 |  |  |             res.add(map); | 
 |  |  |         } | 
 |  |  |         return R.ok().add(res); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     @PostMapping("/demo/switch") | 
 |  |  |     @ManagerAuth(memo = "堆垛机演示") | 
 |  |  |     public R crnDemo(CrnDemoParam param) throws InterruptedException { | 
 |  |  | 
 |  |  |             return R.error("口令错误"); | 
 |  |  |         } | 
 |  |  |         Thread.sleep(200L); | 
 |  |  |         mainService.crnDemoOfLocMove(param.getCrnId()); | 
 |  |  |         for (CrnSlave crnSlave : slaveProperties.getCrn()) { | 
 |  |  |             if (crnSlave.getId().equals(param.getCrnId())) { | 
 |  |  |                 crnSlave.setDemo(param.getOpt()); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  | //        mainService.crnDemoOfLocMove(param.getCrnId()); | 
 |  |  |         return R.ok(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     /****************************************************************/ | 
 |  |  | 
 |  |  |         command.setCrnNo(param.getCrnNo()); // 堆垛机编号 | 
 |  |  |         command.setTaskNo((short) 0); // 工作号 | 
 |  |  |         command.setAckFinish((short) 0);  // 任务完成确认位 | 
 |  |  |         command.setTaskMode(CrnTaskModeType.SITE_MOVE); // 任务模式 | 
 |  |  |         command.setTaskMode(CrnTaskModeType.LOC_MOVE); // 任务模式 | 
 |  |  |         command.setSourcePosX(param.getSourceStaNo());     // 源库位排 | 
 |  |  |         command.setSourcePosY((short) 0);     // 源库位列 | 
 |  |  |         command.setSourcePosZ((short) 1);     // 源库位层 | 
 |  |  | 
 |  |  |         return crnControl(command)?R.ok():R.error(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @ManagerAuth(memo = "回原点") | 
 |  |  |     @PostMapping("/operator/bacOrigin") | 
 |  |  |     public R crnBacOrigin(CrnOperatorParam param){ | 
 |  |  |         CrnCommand command = new CrnCommand(); | 
 |  |  |         command.setCrnNo(param.getCrnNo()); // 堆垛机编号 | 
 |  |  |         command.setTaskNo((short) 0); // 工作号 | 
 |  |  |         command.setAckFinish((short) 0);  // 任务完成确认位 | 
 |  |  |         command.setTaskMode(CrnTaskModeType.GO_ORIGIN); // 任务模式 | 
 |  |  |         command.setSourcePosX((short) 0);     // 源库位排 | 
 |  |  |         command.setSourcePosY((short) 0);     // 源库位列 | 
 |  |  |         command.setSourcePosZ((short) 0);     // 源库位层 | 
 |  |  |         command.setDestinationPosX((short) 0);     // 目标库位排 | 
 |  |  |         command.setDestinationPosY((short) 0);     // 目标库位列 | 
 |  |  |         command.setDestinationPosZ((short) 0);     // 目标库位层 | 
 |  |  |         return crnControl(command)?R.ok():R.error(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @ManagerAuth(memo = "反原点") | 
 |  |  |     @PostMapping("/operator/reverseOrigin") | 
 |  |  |     public R reverseOrigin(CrnOperatorParam param){ | 
 |  |  |         CrnCommand command = new CrnCommand(); | 
 |  |  |         command.setCrnNo(param.getCrnNo()); // 堆垛机编号 | 
 |  |  |         command.setTaskNo((short) 0); // 工作号 | 
 |  |  |         command.setAckFinish((short) 0);  // 任务完成确认位 | 
 |  |  |         command.setTaskMode(CrnTaskModeType.GO_ORIGIN); // 任务模式 | 
 |  |  |         command.setSourcePosX((short) 0);     // 源库位排 | 
 |  |  |         command.setSourcePosY((short) 0);     // 源库位列 | 
 |  |  |         command.setSourcePosZ((short) 0);     // 源库位层 | 
 |  |  |         command.setDestinationPosX((short) 0);     // 目标库位排 | 
 |  |  |         command.setDestinationPosY((short) 34);     // 目标库位列 | 
 |  |  |         command.setDestinationPosZ((short) 5);     // 目标库位层 | 
 |  |  |         return crnControl(command)?R.ok():R.error(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | //    @ManagerAuth(memo = "坐标移动") | 
 |  |  | //    @PostMapping("/operator/coorMove") | 
 |  |  | //    public R crnCoorMove(CrnOperatorParam param){ | 
 |  |  | //    @ManagerAuth(memo = "回原点") | 
 |  |  | //    @PostMapping("/operator/bacOrigin") | 
 |  |  | //    public R crnBacOrigin(CrnOperatorParam param){ | 
 |  |  | //        CrnCommand command = new CrnCommand(); | 
 |  |  | //        command.setCrnNo(param.getCrnNo()); // 堆垛机编号 | 
 |  |  | //        command.setTaskNo((short) 0); // 工作号 | 
 |  |  | //        command.setAckFinish((short) 0);  // 任务完成确认位 | 
 |  |  | //        command.setTaskMode(CrnTaskModeType.OFFSET_MOVE); // 任务模式 | 
 |  |  | //        command.setSourcePosX(param.getSourceRow());     // 源库位排 | 
 |  |  | //        command.setSourcePosY(param.getSourceBay());     // 源库位列 | 
 |  |  | //        command.setSourcePosZ(param.getSourceLev());     // 源库位层 | 
 |  |  | //        command.setDestinationPosX(param.getRow());     // 目标库位排 | 
 |  |  | //        command.setDestinationPosY(param.getBay());     // 目标库位列 | 
 |  |  | //        command.setDestinationPosZ(param.getLev());     // 目标库位层 | 
 |  |  | //        staNoProcess(param, command); | 
 |  |  | //        command.setTaskMode(CrnTaskModeType.GO_ORIGIN); // 任务模式 | 
 |  |  | //        command.setSourcePosX((short) 0);     // 源库位排 | 
 |  |  | //        command.setSourcePosY((short) 0);     // 源库位列 | 
 |  |  | //        command.setSourcePosZ((short) 0);     // 源库位层 | 
 |  |  | //        command.setDestinationPosX((short) 0);     // 目标库位排 | 
 |  |  | //        command.setDestinationPosY((short) 0);     // 目标库位列 | 
 |  |  | //        command.setDestinationPosZ((short) 0);     // 目标库位层 | 
 |  |  | //        return crnControl(command)?R.ok():R.error(); | 
 |  |  | //    } | 
 |  |  |  | 
 |  |  | //    @ManagerAuth(memo = "反原点") | 
 |  |  | //    @PostMapping("/operator/reverseOrigin") | 
 |  |  | //    public R reverseOrigin(CrnOperatorParam param){ | 
 |  |  | //        CrnCommand command = new CrnCommand(); | 
 |  |  | //        command.setCrnNo(param.getCrnNo()); // 堆垛机编号 | 
 |  |  | //        command.setTaskNo((short) 0); // 工作号 | 
 |  |  | //        command.setAckFinish((short) 0);  // 任务完成确认位 | 
 |  |  | //        command.setTaskMode(CrnTaskModeType.GO_ORIGIN); // 任务模式 | 
 |  |  | //        command.setSourcePosX((short) 0);     // 源库位排 | 
 |  |  | //        command.setSourcePosY((short) 0);     // 源库位列 | 
 |  |  | //        command.setSourcePosZ((short) 0);     // 源库位层 | 
 |  |  | //        command.setDestinationPosX((short) 0);     // 目标库位排 | 
 |  |  | //        command.setDestinationPosY((short) 34);     // 目标库位列 | 
 |  |  | //        command.setDestinationPosZ((short) 5);     // 目标库位层 | 
 |  |  | //        return crnControl(command)?R.ok():R.error(); | 
 |  |  | //    } | 
 |  |  |  | 
 |  |  |     @ManagerAuth(memo = "坐标移动") | 
 |  |  |     @PostMapping("/operator/crnMove") | 
 |  |  |     public R crnCoorMove(CrnOperatorParam param){ | 
 |  |  |         CrnCommand command = new CrnCommand(); | 
 |  |  |         command.setCrnNo(param.getCrnNo()); // 堆垛机编号 | 
 |  |  |         command.setTaskNo((short) 9999); // 工作号 | 
 |  |  |         command.setAckFinish((short) 0);  // 任务完成确认位 | 
 |  |  |         command.setTaskMode(CrnTaskModeType.CRN_MOVE); // 任务模式 | 
 |  |  |         command.setSourcePosX(param.getSourceRow());     // 源库位排 | 
 |  |  |         command.setSourcePosY(param.getSourceBay());     // 源库位列 | 
 |  |  |         command.setSourcePosZ(param.getSourceLev());     // 源库位层 | 
 |  |  |         command.setDestinationPosX(param.getRow());     // 目标库位排 | 
 |  |  |         command.setDestinationPosY(param.getBay());     // 目标库位列 | 
 |  |  |         command.setDestinationPosZ(param.getLev());     // 目标库位层 | 
 |  |  |         staNoProcess(param, command); | 
 |  |  |  | 
 |  |  |         return crnControl(command)?R.ok():R.error(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @ManagerAuth(memo = "任务完成") | 
 |  |  |     @PostMapping("/operator/taskComplete") | 
 |  |  | 
 |  |  |         if (param.getCrnNo() == null) { | 
 |  |  |             throw new CoolException("请选择堆垛机"); | 
 |  |  |         } | 
 |  |  |         MessageQueue.clear(SlaveType.Crn, param.getCrnNo()); | 
 |  |  |         return R.ok("清除命令成功"); | 
 |  |  |         CrnCommand command = new CrnCommand(); | 
 |  |  |         command.setCrnNo(param.getCrnNo()); // 堆垛机编号 | 
 |  |  |         command.setTaskNo((short) 0); // 工作号 | 
 |  |  |         command.setAckFinish((short) 0);  // 任务完成确认位 | 
 |  |  |         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);     // 目标库位层 | 
 |  |  |         return crnControl(command)?R.ok():R.error(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @ManagerAuth(memo = "手动复位") | 
 |  |  | 
 |  |  |                 crnCommand.setCrnNo(crn.getId()); // 堆垛机编号 | 
 |  |  |                 crnCommand.setTaskMode(CrnTaskModeType.CLEAR); | 
 |  |  |                 crnCommand.setAckFinish((short) 0);  // 任务完成确认位 | 
 |  |  |                 crnCommand.setCommand((short) 0);  // 任务完成确认位 | 
 |  |  |                 // 延时发送 | 
 |  |  |                 Thread.sleep(1000L); | 
 |  |  |                 if (MessageQueue.offer(SlaveType.Crn, crn.getId(), new Task(2, crnCommand))) { |