|  |  |  | 
|---|
|  |  |  | for (CrnSlave crnSlave : slaveProperties.getCrn()) { | 
|---|
|  |  |  | // 遍历堆垛机出库站 | 
|---|
|  |  |  | for (CrnSlave.CrnStn crnStn : crnSlave.getCrnOutStn()) { | 
|---|
|  |  |  | // 获取堆垛机出库站信息 | 
|---|
|  |  |  | DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, crnStn.getDevpPlcId()); | 
|---|
|  |  |  | StaProtocol staProtocol = devpThread.getStation().get(crnStn.getStaNo()); | 
|---|
|  |  |  | if (staProtocol == null) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | staProtocol = staProtocol.clone(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (staProtocol.isAutoing() && staProtocol.isLoading() && (staProtocol.getWorkNo() == 0 || staProtocol.getStaNo() == 0)) { | 
|---|
|  |  |  | // 查询工作档 | 
|---|
|  |  |  | TaskWrk taskWrk = taskWrkMapper.selectCrnStaWorking(crnSlave.getId(), staProtocol.getSiteId().toString()); | 
|---|
|  |  |  | if (taskWrk == null) { | 
|---|
|  |  |  | List<StaDesc> staDescs = staDescMapper.selectList(new EntityWrapper<StaDesc>().eq("crn_no", crnSlave.getId()).eq("crn_stn", crnStn.getStaNo())); | 
|---|
|  |  |  | for (StaDesc staDesc : staDescs){ | 
|---|
|  |  |  | // 获取堆垛机出库站信息 | 
|---|
|  |  |  | DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, crnStn.getDevpPlcId()); | 
|---|
|  |  |  | StaProtocol staProtocol = devpThread.getStation().get(crnStn.getStaNo()); | 
|---|
|  |  |  | if (staProtocol == null) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | staProtocol = staProtocol.clone(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 判断工作档条件 | 
|---|
|  |  |  | if (taskWrk.getWrkSts() == 12 && taskWrk.getIoType() == 2) { | 
|---|
|  |  |  | // 判断吊车是否实际已完成,且电脑状态在move中,以备电脑进行更新工作档 | 
|---|
|  |  |  | CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, taskWrk.getCrnNo()); | 
|---|
|  |  |  | CrnProtocol crnProtocol = crnThread.getCrnProtocol(); | 
|---|
|  |  |  | if (crnProtocol.statusType == CrnStatusType.FETCHING || crnProtocol.statusType == CrnStatusType.PUTTING) { | 
|---|
|  |  |  | // 移动中 | 
|---|
|  |  |  | if (staProtocol.isAutoing() && staProtocol.isLoading() && (staProtocol.getWorkNo() == 0 || staProtocol.getStaNo() == 0)) { | 
|---|
|  |  |  | // 查询工作档 | 
|---|
|  |  |  | TaskWrk taskWrk = taskWrkMapper.selectCrnStaWorking(crnSlave.getId(), staDesc.getStnNo().toString()); | 
|---|
|  |  |  | if (taskWrk == null) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //  判断堆垛机状态等待确认 | 
|---|
|  |  |  | if (crnProtocol.modeType == CrnModeType.AUTO && crnProtocol.getTaskNo().equals(taskWrk.getWrkNo().shortValue()) | 
|---|
|  |  |  | && crnProtocol.getTaskFinish() == 0 | 
|---|
|  |  |  | && crnProtocol.forkPosType == CrnForkPosType.HOME) { | 
|---|
|  |  |  | // 命令下发区 -------------------------------------------------------------------------- | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 下发站点信息 | 
|---|
|  |  |  | staProtocol.setWorkNo(taskWrk.getWrkNo().shortValue()); | 
|---|
|  |  |  | String targetPoint = taskWrk.getTargetPoint(); | 
|---|
|  |  |  | int i = Integer.parseInt(targetPoint); | 
|---|
|  |  |  | staProtocol.setStaNo((short)i); | 
|---|
|  |  |  | if (!CommandUtils.offer(SlaveType.Devp, crnStn.getDevpPlcId(), new Task(2, staProtocol))) { | 
|---|
|  |  |  | // 判断工作档条件 | 
|---|
|  |  |  | if (taskWrk.getWrkSts() == 12 && taskWrk.getIoType() == 2) { | 
|---|
|  |  |  | // 判断吊车是否实际已完成,且电脑状态在move中,以备电脑进行更新工作档 | 
|---|
|  |  |  | CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, taskWrk.getCrnNo()); | 
|---|
|  |  |  | CrnProtocol crnProtocol = crnThread.getCrnProtocol(); | 
|---|
|  |  |  | if (crnProtocol.statusType == CrnStatusType.FETCHING || crnProtocol.statusType == CrnStatusType.PUTTING) { | 
|---|
|  |  |  | // 移动中 | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //  判断堆垛机状态等待确认 | 
|---|
|  |  |  | if (crnProtocol.modeType == CrnModeType.AUTO && crnProtocol.getTaskNo().equals(taskWrk.getWrkNo().shortValue()) | 
|---|
|  |  |  | && crnProtocol.getTaskFinish() == 0 | 
|---|
|  |  |  | && crnProtocol.forkPosType == CrnForkPosType.HOME) { | 
|---|
|  |  |  | // 命令下发区 -------------------------------------------------------------------------- | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 更新工作档状态为14失败 | 
|---|
|  |  |  | taskWrk.setWrkSts(14); | 
|---|
|  |  |  | if (taskWrkMapper.updateById(taskWrk) != 0) { | 
|---|
|  |  |  | // 复位堆垛机 | 
|---|
|  |  |  | crnThread.setResetFlag(true); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | log.error("更新工作档的工作状态为14失败!!! [工作号:{}]", taskWrk.getWrkNo()); | 
|---|
|  |  |  | // 下发站点信息 | 
|---|
|  |  |  | staProtocol.setWorkNo(taskWrk.getWrkNo().shortValue()); | 
|---|
|  |  |  | String targetPoint = taskWrk.getTargetPoint(); | 
|---|
|  |  |  | int i = Integer.parseInt(targetPoint); | 
|---|
|  |  |  | staProtocol.setStaNo((short)i); | 
|---|
|  |  |  | if (!CommandUtils.offer(SlaveType.Devp, crnStn.getDevpPlcId(), new Task(2, staProtocol))) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 更新工作档状态为14失败 | 
|---|
|  |  |  | taskWrk.setWrkSts(14); | 
|---|
|  |  |  | if (taskWrkMapper.updateById(taskWrk) != 0) { | 
|---|
|  |  |  | // 复位堆垛机 | 
|---|
|  |  |  | crnThread.setResetFlag(true); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | log.error("更新工作档的工作状态为14失败!!! [工作号:{}]", taskWrk.getWrkNo()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public void crnStnToLoc(CrnSlave slave, CrnProtocol crnProtocol){ | 
|---|
|  |  |  | for (CrnSlave.CrnStn crnStn : slave.getCrnInStn()) { | 
|---|
|  |  |  | boolean flag = false; | 
|---|
|  |  |  | // 获取堆垛机入库站信息 | 
|---|
|  |  |  | DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, crnStn.getDevpPlcId()); | 
|---|
|  |  |  | StaProtocol staProtocol = devpThread.getStation().get(crnStn.getStaNo()); | 
|---|
|  |  |  | if (staProtocol == null) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | staProtocol = staProtocol.clone(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 查询站点详细信息 | 
|---|
|  |  |  | BasDevp staDetl = basDevpService.selectById(crnStn.getStaNo()); | 
|---|
|  |  |  | if (staDetl == null) { | 
|---|
|  |  |  | log.error("入库 ===>> 堆垛机站点在数据库不存在, 站点编号={}", crnStn.getStaNo()); | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.getWorkNo() > 0 && staProtocol.isInEnable() | 
|---|
|  |  |  | && staDetl.getCanining()!=null && staDetl.getCanining().equals("Y")) { | 
|---|
|  |  |  | flag = true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!flag) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 获取工作状态为2(设备上走)的入库工作档 | 
|---|
|  |  |  | TaskWrk taskWrk = taskWrkMapper.selectPakIn(slave.getId(), staProtocol.getWorkNo().intValue(), crnStn.getStaNo().toString()); | 
|---|
|  |  |  | if(null == taskWrk) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<StaDesc> staDescs = staDescMapper.selectList(new EntityWrapper<StaDesc>().eq("crn_no", slave.getId()).eq("crn_stn", crnStn.getStaNo())); | 
|---|
|  |  |  | for (StaDesc staDesc : staDescs) { | 
|---|
|  |  |  | boolean flag = false; | 
|---|
|  |  |  | // 获取堆垛机入库站信息 | 
|---|
|  |  |  | DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, crnStn.getDevpPlcId()); | 
|---|
|  |  |  | StaProtocol staProtocol = devpThread.getStation().get(crnStn.getStaNo()); | 
|---|
|  |  |  | if (staProtocol == null) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | staProtocol = staProtocol.clone(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 查询站点详细信息 | 
|---|
|  |  |  | BasDevp staDetl = basDevpService.selectById(crnStn.getStaNo()); | 
|---|
|  |  |  | if (staDetl == null) { | 
|---|
|  |  |  | log.error("入库 ===>> 堆垛机站点在数据库不存在, 站点编号={}", crnStn.getStaNo()); | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.getWorkNo() > 0 && staProtocol.isInEnable() | 
|---|
|  |  |  | && staDetl.getCanining()!=null && staDetl.getCanining().equals("Y")) { | 
|---|
|  |  |  | flag = true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!flag) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 获取工作状态为2(设备上走)的入库工作档 | 
|---|
|  |  |  | TaskWrk taskWrk = taskWrkMapper.selectPakIn(slave.getId(), staProtocol.getWorkNo().intValue(), staDesc.getStnNo().toString()); | 
|---|
|  |  |  | if(null == taskWrk) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 堆垛机控制过滤 | 
|---|
|  |  |  | if (!crnProtocol.getStatusType().equals(CrnStatusType.IDLE) || crnProtocol.getTaskNo() != 0) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 堆垛机控制过滤 | 
|---|
|  |  |  | if (!crnProtocol.getStatusType().equals(CrnStatusType.IDLE) || crnProtocol.getTaskNo() != 0) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 已经存在吊车执行任务时,则过滤 | 
|---|
|  |  |  | if (taskWrkMapper.selectCrnWorking(slave.getId()) != null) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 已经存在吊车执行任务时,则过滤 | 
|---|
|  |  |  | if (taskWrkMapper.selectCrnWorking(slave.getId()) != null) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 命令下发区 -------------------------------------------------------------------------- | 
|---|
|  |  |  | CrnCommand crnCommand = new CrnCommand(); | 
|---|
|  |  |  | crnCommand.setCrnNo(slave.getId()); // 堆垛机编号 | 
|---|
|  |  |  | crnCommand.setTaskNo(taskWrk.getWrkNo().shortValue()); // 工作号 | 
|---|
|  |  |  | crnCommand.setAckFinish((short) 0);  // 任务完成确认位 | 
|---|
|  |  |  | crnCommand.setTaskMode(CrnTaskModeType.LOC_MOVE); // 任务模式:  库位移转 | 
|---|
|  |  |  | crnCommand.setSourcePosX(crnStn.getBay().shortValue());     // 源库位列 | 
|---|
|  |  |  | crnCommand.setSourcePosY(crnStn.getLev().shortValue());     // 源库位层 | 
|---|
|  |  |  | crnCommand.setSourcePosZ(crnStn.getRow().shortValue());     // 源库位排 | 
|---|
|  |  |  | crnCommand.setDestinationPosX(Utils.getBayShort(taskWrk.getTargetPoint()));     // 目标库位列 | 
|---|
|  |  |  | crnCommand.setDestinationPosY(Utils.getLevShort(taskWrk.getTargetPoint()));     // 目标库位层 | 
|---|
|  |  |  | crnCommand.setDestinationPosZ(Utils.getRowShort(taskWrk.getTargetPoint()));     // 目标库位排 | 
|---|
|  |  |  | crnCommand.setCommand((short)1); | 
|---|
|  |  |  | if (!CommandUtils.offer(SlaveType.Crn, taskWrk.getCrnNo(), new Task(2, crnCommand))) { | 
|---|
|  |  |  | log.error("堆垛机命令下发失败,堆垛机号={},任务数据={}", taskWrk.getCrnNo(), JSON.toJSON(crnCommand)); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | // 修改工作档状态 2.设备上走 => 3.吊车入库中 | 
|---|
|  |  |  | Date now = new Date(); | 
|---|
|  |  |  | taskWrk.setWrkSts(3); | 
|---|
|  |  |  | taskWrk.setModiTime(now); | 
|---|
|  |  |  | if (taskWrkMapper.updateById(taskWrk) == 0) { | 
|---|
|  |  |  | log.error("修改工作档状态 2.设备上走 => 3.吊车入库中 失败!!,工作号={}", taskWrk.getWrkNo()); | 
|---|
|  |  |  | // 命令下发区 -------------------------------------------------------------------------- | 
|---|
|  |  |  | CrnCommand crnCommand = new CrnCommand(); | 
|---|
|  |  |  | crnCommand.setCrnNo(slave.getId()); // 堆垛机编号 | 
|---|
|  |  |  | crnCommand.setTaskNo(taskWrk.getWrkNo().shortValue()); // 工作号 | 
|---|
|  |  |  | crnCommand.setAckFinish((short) 0);  // 任务完成确认位 | 
|---|
|  |  |  | crnCommand.setTaskMode(CrnTaskModeType.LOC_MOVE); // 任务模式:  库位移转 | 
|---|
|  |  |  | crnCommand.setSourcePosX(crnStn.getBay().shortValue());     // 源库位列 | 
|---|
|  |  |  | crnCommand.setSourcePosY(crnStn.getLev().shortValue());     // 源库位层 | 
|---|
|  |  |  | crnCommand.setSourcePosZ(crnStn.getRow().shortValue());     // 源库位排 | 
|---|
|  |  |  | crnCommand.setDestinationPosX(Utils.getBayShort(taskWrk.getTargetPoint()));     // 目标库位列 | 
|---|
|  |  |  | crnCommand.setDestinationPosY(Utils.getLevShort(taskWrk.getTargetPoint()));     // 目标库位层 | 
|---|
|  |  |  | crnCommand.setDestinationPosZ(Utils.getRowShort(taskWrk.getTargetPoint()));     // 目标库位排 | 
|---|
|  |  |  | crnCommand.setCommand((short)1); | 
|---|
|  |  |  | if (!CommandUtils.offer(SlaveType.Crn, taskWrk.getCrnNo(), new Task(2, crnCommand))) { | 
|---|
|  |  |  | log.error("堆垛机命令下发失败,堆垛机号={},任务数据={}", taskWrk.getCrnNo(), JSON.toJSON(crnCommand)); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | // 修改工作档状态 2.设备上走 => 3.吊车入库中 | 
|---|
|  |  |  | Date now = new Date(); | 
|---|
|  |  |  | taskWrk.setWrkSts(3); | 
|---|
|  |  |  | taskWrk.setModiTime(now); | 
|---|
|  |  |  | if (taskWrkMapper.updateById(taskWrk) == 0) { | 
|---|
|  |  |  | log.error("修改工作档状态 2.设备上走 => 3.吊车入库中 失败!!,工作号={}", taskWrk.getWrkNo()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|