| package com.zy.asrs.controller; | 
|   | 
| import com.alibaba.fastjson.JSON; | 
| import com.baomidou.mybatisplus.mapper.EntityWrapper; | 
| import com.core.annotations.ManagerAuth; | 
| import com.core.common.Cools; | 
| import com.core.common.R; | 
| import com.core.exception.CoolException; | 
| import com.zy.asrs.domain.enums.CrnStatusType; | 
| import com.zy.asrs.domain.param.CrnDemoParam; | 
| import com.zy.asrs.domain.param.CrnOperatorParam; | 
| import com.zy.asrs.domain.vo.CommandLogVo; | 
| import com.zy.asrs.domain.vo.CrnMsgTableVo; | 
| import com.zy.asrs.domain.vo.CrnStateTableVo; | 
| import com.zy.asrs.entity.BasCrnError; | 
| import com.zy.asrs.entity.BasCrnp; | 
| import com.zy.asrs.entity.LocMast; | 
| import com.zy.asrs.entity.WrkMast; | 
| import com.zy.asrs.mapper.BasCrnErrorMapper; | 
| import com.zy.asrs.service.BasCrnpService; | 
| import com.zy.asrs.service.LocMastService; | 
| import com.zy.asrs.service.WrkMastService; | 
| import com.zy.asrs.service.impl.MainServiceImpl; | 
| import com.zy.asrs.utils.VersionUtils; | 
| import com.zy.core.CrnThread; | 
| import com.zy.core.cache.MessageQueue; | 
| import com.zy.core.cache.OutputQueue; | 
| import com.zy.core.cache.SlaveConnection; | 
| import com.zy.core.enums.CrnModeType; | 
| import com.zy.core.enums.CrnTaskModeType; | 
| import com.zy.core.enums.SlaveType; | 
| import com.zy.core.model.CrnSlave; | 
| import com.zy.core.model.Task; | 
| import com.zy.core.model.command.CrnCommand; | 
| import com.zy.core.model.protocol.CrnProtocol; | 
| import com.zy.core.properties.SlaveProperties; | 
| import com.zy.core.properties.SystemProperties; | 
| 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; | 
|   | 
| /** | 
|  * 堆垛机接口 | 
|  * Created by vincent on 2020-06-01 | 
|  */ | 
| @Slf4j | 
| @RestController | 
| @RequestMapping("/crn") | 
| public class CrnController { | 
|   | 
|     @Autowired | 
|     private SlaveProperties slaveProperties; | 
|     @Autowired | 
|     private WrkMastService wrkMastService; | 
|     @Autowired | 
|     private BasCrnErrorMapper basCrnErrorMapper; | 
|     @Autowired | 
|     private BasCrnpService basCrnpService; | 
|     @Autowired | 
|     private MainServiceImpl mainService; | 
|     @Autowired | 
|     private LocMastService locMastService; | 
|   | 
|   | 
|     @ManagerAuth(memo = "进行中的命令") | 
|     @PostMapping("/command/ongoing") | 
|     public R ongoingCommand(){ | 
|         List<CommandLogVo> list = new ArrayList<>(); | 
|         for (CrnSlave crn : slaveProperties.getCrn()) { | 
|             CommandLogVo vo = new CommandLogVo(); | 
|             vo.setCrnNo(crn.getId());   //  堆垛机号 | 
|             vo.setStatus(0);    //  状态 | 
|             list.add(vo); | 
|             // 获取堆垛机信息 | 
|             CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crn.getId()); | 
|             if (crnThread == null) { | 
|                 continue; | 
|             } | 
|             CrnProtocol crnProtocol = crnThread.getCrnProtocol(); | 
|             if (crnProtocol == null) { | 
|                 continue; | 
|             } | 
|             vo.setStatus(1);    //  状态 | 
|             Task task = MessageQueue.peek(SlaveType.Crn, crn.getId()); | 
|             if (task != null) { | 
|                 vo.setCommand(JSON.toJSONString((CrnCommand)task.getData())); | 
|             } | 
|         } | 
|         return R.ok().add(list); | 
|     } | 
|   | 
|     @PostMapping("/table/crn/state") | 
|     @ManagerAuth(memo = "堆垛机信息表") | 
|     public R crnStateTable(){ | 
|         List<CrnStateTableVo> list = new ArrayList<>(); | 
|         List<BasCrnp> crnps = basCrnpService.selectList(new EntityWrapper<BasCrnp>().orderBy("crn_no")); | 
|         for (BasCrnp basCrnp : crnps) { | 
|             // 表格行 | 
|             CrnStateTableVo vo = new CrnStateTableVo(); | 
|             vo.setCrnNo(basCrnp.getCrnNo());   //  堆垛机号 | 
|             list.add(vo); | 
|             // 获取堆垛机信息 | 
|             CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, basCrnp.getCrnNo()); | 
|             if (crnThread == null) { | 
|                 continue; | 
|             } | 
|             CrnProtocol crnProtocol = crnThread.getCrnProtocol(); | 
|             if (crnProtocol == null) { | 
|                 continue; | 
|             } | 
|             vo.setWorkNo(crnProtocol.getTaskNo());  //  任务号 | 
|             vo.setStatusType(crnProtocol.modeType.desc);   //  模式状态 | 
|             vo.setStatus(crnProtocol.getStatusType().desc);     //  状态 | 
|             vo.setLoading(( Cools.isEmpty(crnProtocol.getLoaded()) && crnProtocol.getLoaded()==1)?"有物":"无物");  //  有物 | 
|             vo.setBay(crnProtocol.getBay());    //  列 | 
|             vo.setLev(crnProtocol.getLevel());  //  层 | 
|   | 
|             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.setAlarm(crnError==null?"未知异常":crnError.getErrName()); | 
|             } | 
|         } | 
|         return R.ok().add(list); | 
|     } | 
|   | 
|     @PostMapping("/table/crn/msg") | 
|     @ManagerAuth(memo = "堆垛机数据表") | 
|     public R crnMsgTable(){ | 
|         List<CrnMsgTableVo> list = new ArrayList<>(); | 
|         List<BasCrnp> crnps = basCrnpService.selectList(new EntityWrapper<BasCrnp>().orderBy("crn_no")); | 
|         for (BasCrnp basCrnp : crnps) { | 
|             // 表格行 | 
|             CrnMsgTableVo vo = new CrnMsgTableVo(); | 
|             vo.setCrnNo(basCrnp.getCrnNo());   //  堆垛机号 | 
|             list.add(vo); | 
|             // 获取堆垛机信息 | 
|             CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, basCrnp.getCrnNo()); | 
|             if (crnThread == null) { | 
|                 continue; | 
|             } | 
|             CrnProtocol crnProtocol = crnThread.getCrnProtocol(); | 
|             if (crnProtocol == null) { | 
|                 continue; | 
|             } | 
|   | 
|             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());    //  目标库位 | 
|                 } | 
|             } else { | 
|                 vo.setStatus(crnProtocol.modeType.equals(CrnModeType.AUTO)? CrnStatusType.MACHINE_AUTO.getDesc(): CrnStatusType.MACHINE_UN_AUTO.getDesc());   //  模式状态 | 
|             } | 
|             vo.setXspeed(crnProtocol.getXSpeed());  //  走行速度(m/min) | 
|             vo.setYspeed(crnProtocol.getYSpeed());  //  升降速度(m/min) | 
|             vo.setZspeed(crnProtocol.getZSpeed());  //  叉牙速度(m/min) | 
|             vo.setXdistance(crnProtocol.getXDistance());  //  走行距离(Km) | 
|             vo.setYdistance(crnProtocol.getYDistance());  //  升降距离(Km) | 
|             vo.setXduration(crnProtocol.getXDuration());    //  走行时长(H) | 
|             vo.setYduration(crnProtocol.getYDuration());    //  升降时长(H) | 
|         } | 
|         return R.ok().add(list); | 
|     } | 
|   | 
|     @PostMapping("/output/site") | 
|     @ManagerAuth(memo = "堆垛机报文日志输出") | 
|     public R crnOutput(){ | 
|         StringBuilder str = new StringBuilder(); | 
|         String s; | 
|         int i = 0; | 
|         while((s = OutputQueue.CRN.poll()) != null && i <=10) { | 
|             str.append("\n").append(s); | 
|             i++; | 
|         } | 
|         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 { | 
|         if (Cools.isEmpty(param.getCrnId())){ | 
|             return R.error(); | 
|         } | 
|         if (Cools.isEmpty(param.getPassword())){ | 
|             return R.error("请输入口令"); | 
|         } | 
|         if (!param.getPassword().equals(SystemProperties.WCS_PASSWORD)){ | 
|             return R.error("口令错误"); | 
|         } | 
|         Thread.sleep(200L); | 
|         for (CrnSlave crnSlave : slaveProperties.getCrn()) { | 
|             if (crnSlave.getId().equals(param.getCrnId())) { | 
|                 crnSlave.setDemo(param.getOpt()); | 
|             } | 
|         } | 
| //        mainService.crnDemoOfLocMove(param.getCrnId()); | 
|         return R.ok(); | 
|     } | 
|   | 
|   | 
|   | 
|     /****************************************************************/ | 
|     /************************** 手动操作 ******************************/ | 
|     /****************************************************************/ | 
|   | 
|     @ManagerAuth(memo = "入库") | 
|     @PostMapping("/operator/put") | 
|     public R crnPut(CrnOperatorParam param){ | 
|         CrnCommand command = new CrnCommand(); | 
|         command.setCrnNo(param.getCrnNo()); // 堆垛机编号 | 
|         command.setTaskNo((short) 0); // 工作号 | 
|         command.setAckFinish((short) 0);  // 任务完成确认位 | 
|         command.setTaskMode(CrnTaskModeType.PAKIN); // 任务模式 | 
|         command.setSourcePosX(param.getSourceRow());     // 源库位排 | 
|         command.setSourcePosY(param.getSourceBay());     // 源库位列 | 
|         command.setSourcePosZ(param.getSourceLev());     // 源库位层 | 
|         command.setDestinationPosX(param.getRow());     // 目标库位排 | 
|         command.setDestinationPosY(param.getBay());     // 目标库位列 | 
|         command.setDestinationPosZ(param.getLev());     // 目标库位层 | 
|         return crnControl(command)?R.ok():R.error(); | 
|     } | 
|   | 
|     @ManagerAuth(memo = "出库") | 
|     @PostMapping("/operator/take") | 
|     public R crnTake(CrnOperatorParam param){ | 
|         CrnCommand command = new CrnCommand(); | 
|         command.setCrnNo(param.getCrnNo()); // 堆垛机编号 | 
|         command.setTaskNo((short) 0); // 工作号 | 
|         command.setAckFinish((short) 0);  // 任务完成确认位 | 
|         command.setTaskMode(CrnTaskModeType.PAKOUT); // 任务模式 | 
|         command.setSourcePosX(param.getSourceRow());     // 源库位排 | 
|         command.setSourcePosY(param.getSourceBay());     // 源库位列 | 
|         command.setSourcePosZ(param.getSourceLev());     // 源库位层 | 
|         command.setDestinationPosX(param.getRow());     // 目标库位排 | 
|         command.setDestinationPosY(param.getBay());     // 目标库位列 | 
|         command.setDestinationPosZ(param.getLev());     // 目标库位层 | 
|         return crnControl(command)?R.ok():R.error(); | 
|     } | 
|   | 
|     @ManagerAuth(memo = "库位转移") | 
|     @PostMapping("/operator/stockMove") | 
|     public R crnStockMove(CrnOperatorParam param){ | 
|         CrnCommand command = new CrnCommand(); | 
|         command.setCrnNo(param.getCrnNo()); // 堆垛机编号 | 
|         command.setTaskNo((short) 0); // 工作号 | 
|         command.setAckFinish((short) 0);  // 任务完成确认位 | 
|         command.setTaskMode(CrnTaskModeType.LOC_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());     // 目标库位层 | 
|         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(); | 
|     } | 
|   | 
|     @ManagerAuth(memo = "站到站") | 
|     @PostMapping("/operator/siteMove") | 
|     public R crnSiteMove(CrnOperatorParam param){ | 
|         CrnCommand command = new CrnCommand(); | 
|         command.setCrnNo(param.getCrnNo()); // 堆垛机编号 | 
|         command.setTaskNo((short) 0); // 工作号 | 
|         command.setAckFinish((short) 0);  // 任务完成确认位 | 
|         command.setTaskMode(CrnTaskModeType.LOC_MOVE); // 任务模式 | 
|         command.setSourcePosX(param.getSourceStaNo());     // 源库位排 | 
|         command.setSourcePosY((short) 0);     // 源库位列 | 
|         command.setSourcePosZ((short) 1);     // 源库位层 | 
|         command.setDestinationPosX(param.getStaNo());     // 目标库位排 | 
|         command.setDestinationPosY((short) 0);     // 目标库位列 | 
|         command.setDestinationPosZ((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){ | 
| //        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); | 
| //        return crnControl(command)?R.ok():R.error(); | 
| //    } | 
|   | 
|     @ManagerAuth(memo = "任务完成") | 
|     @PostMapping("/operator/taskComplete") | 
|     public R crnTaskComplete(CrnOperatorParam param){ | 
|         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);     // 目标库位层 | 
|         return crnControl(command)?R.ok():R.error(); | 
|     } | 
|   | 
| //    @ManagerAuth(memo = "暂停") | 
| //    @PostMapping("/operator/pause") | 
| //    public R crnPause(CrnOperatorParam param){ | 
| //        return R.ok("暂停成功"); | 
| //    } | 
| // | 
| //    @ManagerAuth(memo = "启动") | 
| //    @PostMapping("/operator/boot") | 
| //    public R crnBoot(CrnOperatorParam param){ | 
| //        return R.ok("启动成功"); | 
| //    } | 
|   | 
|     @ManagerAuth(memo = "清除命令") | 
|     @PostMapping("/operator/clearCommand") | 
|     public R crnClearCommand(CrnOperatorParam param){ | 
|         if (param.getCrnNo() == null) { | 
|             throw new CoolException("请选择堆垛机"); | 
|         } | 
|         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 = "手动复位") | 
|     @PostMapping("/operator/handleReset") | 
|     public R handleReset(CrnOperatorParam param) throws Exception { | 
|         if (param.getCrnNo() == null) { | 
|             throw new CoolException("请选择堆垛机"); | 
|         } | 
|         // 获取堆垛机缓存 | 
|         for (CrnSlave crn : slaveProperties.getCrn()) { | 
|             // 获取堆垛机信息 | 
|             if (param.getCrnNo().equals(crn.getId())) { | 
|                 CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crn.getId()); | 
|                 if (crnThread == null) { | 
|                     throw new CoolException("堆垛机不在线"); | 
|                 } | 
|                 CrnProtocol crnProtocol = crnThread.getCrnProtocol(); | 
|                 if (crnProtocol == null) { | 
|                     throw new CoolException("堆垛机不在线"); | 
|                 } | 
|                 CrnCommand crnCommand = new CrnCommand(); | 
|                 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))) { | 
|                     return R.ok(); | 
|                 } else { | 
|                     throw new CoolException("命令下发失败"); | 
|                 } | 
|   | 
|   | 
|             } | 
|         } | 
|   | 
|         return R.error(); | 
|     } | 
|   | 
|     private boolean crnControl(CrnCommand command){ | 
|         if (command.getCrnNo() == null) { | 
|             throw new CoolException("请选择堆垛机"); | 
|         } | 
|         for (CrnSlave crn : slaveProperties.getCrn()) { | 
|             // 获取堆垛机信息 | 
|             if (command.getCrnNo().equals(crn.getId())) { | 
|                 CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crn.getId()); | 
|                 if (crnThread == null) { | 
|                     throw new CoolException("堆垛机不在线"); | 
|                 } | 
|                 CrnProtocol crnProtocol = crnThread.getCrnProtocol(); | 
|                 if (crnProtocol == null) { | 
|                     throw new CoolException("堆垛机不在线"); | 
|                 } | 
|                 // 空闲判断 | 
| //                if (crnProtocol.getStatusType().equals(com.zy.core.enums.CrnStatusType.IDLE) && crnProtocol.getTaskNo() == 0) { | 
|                     if (MessageQueue.offer(SlaveType.Crn, crn.getId(), new Task(2, command))) { | 
|                         return true; | 
|                     } else { | 
|                         throw new CoolException("命令下发失败"); | 
|                     } | 
| //                } else { | 
| //                    throw new CoolException("堆垛机不在空闲状态"); | 
| //                } | 
|             } | 
|         } | 
|         return false; | 
|     } | 
|   | 
|     private void staNoProcess(CrnOperatorParam param, CrnCommand command){ | 
|         if (param.getSourceStaNo()!=null) { | 
|             if (param.getSourceStaNo() == 5) { | 
|                 command.setSourcePosX((short) 2);     // 源库位排 | 
|                 command.setSourcePosY((short) 0);     // 源库位列 | 
|                 command.setSourcePosZ((short) 1);     // 源库位层 | 
|             } else if (param.getSourceStaNo() == 6) { | 
|                 command.setSourcePosX((short) 1);     // 源库位排 | 
|                 command.setSourcePosY((short) 0);     // 源库位列 | 
|                 command.setSourcePosZ((short) 1);     // 源库位层 | 
|             } | 
|         } | 
|         if (param.getStaNo()!=null) { | 
|             if (param.getStaNo() == 5) { | 
|                 command.setDestinationPosX((short) 2);     // 目标库位排 | 
|                 command.setDestinationPosY((short) 0);     // 目标库位列 | 
|                 command.setDestinationPosZ((short) 1);     // 目标库位层 | 
|             } else if (param.getStaNo() == 6) { | 
|                 command.setDestinationPosX((short) 1);     // 目标库位排 | 
|                 command.setDestinationPosY((short) 0);     // 目标库位列 | 
|                 command.setDestinationPosZ((short) 1);     // 目标库位层 | 
|             } | 
|         } | 
|     } | 
|   | 
|   | 
| } |