| | |
| | | */ |
| | | @Slf4j |
| | | @Service("mainService") |
| | | @Transactional |
| | | public class MainServiceImpl { |
| | | |
| | | public static final long COMMAND_TIMEOUT = 5 * 1000; |
| | |
| | | * 堆垛机站出库到出库站 |
| | | */ |
| | | public synchronized void crnStnToOutStn(Integer mark) { |
| | | List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>() |
| | | .eq("wrk_sts", 12) |
| | | ); |
| | | |
| | | 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(); |
| | | for (WrkMast wrkMast : wrkMasts) { |
| | | // 判断工作档条件 |
| | | if (wrkMast.getIoType() < 100 || wrkMast.getStaNo() == null || wrkMast.getSourceStaNo() == null) { |
| | | continue; |
| | | } |
| | | |
| | | Integer devpId = null; |
| | | Integer sourceStaNo = wrkMast.getSourceStaNo(); |
| | | for (CrnSlave crnSlave : slaveProperties.getCrn()) { |
| | | for (CrnSlave.CrnStn crnStn : crnSlave.getCrnOutStn()) { |
| | | if (crnStn.getStaNo().equals(sourceStaNo)) { |
| | | devpId = crnStn.getDevpPlcId(); |
| | | break; |
| | | } |
| | | } |
| | | if (staProtocol.isAutoing() && staProtocol.isLoading() && (staProtocol.getWorkNo() == 0 || staProtocol.getStaNo() == null)) { |
| | | // 查询工作档 |
| | | WrkMast wrkMast = wrkMastMapper.selectPakOutStep2(staProtocol.getSiteId()); |
| | | if (wrkMast == null) { |
| | | } |
| | | |
| | | if (devpId == null) { |
| | | News.error("" + mark + " - 0" + " - 堆垛机站出库到出库站,未找到对应PLC"); |
| | | continue; |
| | | } |
| | | |
| | | DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devpId); |
| | | StaProtocol staProtocol = devpThread.getStation().get(sourceStaNo); |
| | | if (staProtocol == null) { |
| | | continue; |
| | | } else { |
| | | staProtocol = staProtocol.clone(); |
| | | } |
| | | |
| | | if (staProtocol.isAutoing() && staProtocol.isLoading() && (staProtocol.getWorkNo() == 0 || staProtocol.getStaNo() == null)) { |
| | | CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, wrkMast.getCrnNo()); |
| | | CrnProtocol crnProtocol = crnThread.getCrnProtocol(); |
| | | |
| | | if (crnProtocol.modeType == CrnModeType.AUTO && crnProtocol.getTaskNo().equals(wrkMast.getWrkNo().shortValue()) |
| | | && (crnProtocol.statusType == CrnStatusType.PUTTING || crnProtocol.statusType == CrnStatusType.WAITING)) { |
| | | //放货中 或 等待确认 |
| | | News.warnNoLog("" + mark + " - 0" + " - 开始执行"); |
| | | |
| | | // 命令下发区 -------------------------------------------------------------------------- |
| | | LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>() |
| | | .eq("loc_no", wrkMast.getSourceLocNo())); |
| | | |
| | | // 下发站点信息 |
| | | staProtocol.setWorkNo(wrkMast.getWrkNo().shortValue()); |
| | | staProtocol.setStaNo(wrkMast.getStaNo().shortValue()); |
| | | staProtocol.setPalletSize(locMast.getLocType2()); |
| | | if (!MessageQueue.offer(SlaveType.Devp, devpId, new Task(2, staProtocol))) { |
| | | continue; |
| | | } |
| | | // 判断工作档条件 |
| | | if (wrkMast.getIoType() < 100 || wrkMast.getStaNo() == null || wrkMast.getSourceStaNo() == null) { |
| | | continue; |
| | | } |
| | | // 判断吊车是否实际已完成,且电脑状态在move中,以备电脑进行更新工作档 |
| | | CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, wrkMast.getCrnNo()); |
| | | CrnProtocol crnProtocol = crnThread.getCrnProtocol(); |
| | | if (crnProtocol.statusType == CrnStatusType.FETCHING || crnProtocol.statusType == CrnStatusType.PUTTING) { |
| | | // 移动中 |
| | | continue; |
| | | } |
| | | // 判断堆垛机状态等待确认 |
| | | if (crnProtocol.modeType == CrnModeType.AUTO && crnProtocol.getTaskNo().equals(wrkMast.getWrkNo().shortValue()) |
| | | && crnProtocol.statusType == CrnStatusType.WAITING |
| | | && crnProtocol.forkPosType == CrnForkPosType.HOME) { |
| | | News.warnNoLog("" + mark + " - 0" + " - 开始执行"); |
| | | |
| | | // 命令下发区 -------------------------------------------------------------------------- |
| | | |
| | | LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>() |
| | | .eq("loc_no", wrkMast.getSourceLocNo())); |
| | | |
| | | // 下发站点信息 |
| | | staProtocol.setWorkNo(wrkMast.getWrkNo().shortValue()); |
| | | staProtocol.setStaNo(wrkMast.getStaNo().shortValue()); |
| | | staProtocol.setPalletSize(locMast.getLocType2()); |
| | | if (!MessageQueue.offer(SlaveType.Devp, crnStn.getDevpPlcId(), new Task(2, staProtocol))) { |
| | | continue; |
| | | } |
| | | |
| | | // 更新工作档状态为14失败 |
| | | wrkMast.setWrkSts(14L); |
| | | wrkMast.setCrnEndTime(new Date()); |
| | | if (wrkMastMapper.updateById(wrkMast) != 0) { |
| | | // 复位堆垛机 |
| | | crnThread.setResetFlag(true); |
| | | } else { |
| | | News.error("" + mark + " - 1" + " - 更新工作档的工作状态为14失败!!! [工作号:{}]", wrkMast.getWrkNo()); |
| | | } |
| | | |
| | | // 更新工作档状态为14失败 |
| | | wrkMast.setWrkSts(14L); |
| | | wrkMast.setCrnEndTime(new Date()); |
| | | if (wrkMastMapper.updateById(wrkMast) != 0) { |
| | | News.info("" + mark + " - 1" + " - 更新工作档的工作状态为14成功!!! [工作号:{}]", wrkMast.getWrkNo()); |
| | | } else { |
| | | News.errorNoLog("" + mark + " - 6" + " - 堆垛机信息不符合入库条件!!!" |
| | | + " 堆垛机状态:" + crnProtocol.modeType + "==自动AUTO:" + CrnModeType.AUTO |
| | | + "、堆垛机任务号:" + crnProtocol.getTaskNo() + "==工作档任务号:" + wrkMast.getWrkNo().shortValue() |
| | | + "、状态枚举:" + crnProtocol.statusType + "==WAITING:90 //任务完成等待WCS确认):" + CrnStatusType.WAITING |
| | | + "、货叉位置:" + crnProtocol.forkPosType + "==HOME:0 // 货叉原位:" + CrnForkPosType.HOME); |
| | | News.error("" + mark + " - 1" + " - 更新工作档的工作状态为14失败!!! [工作号:{}]", wrkMast.getWrkNo()); |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | | |
| | | News.infoNoLog("" + mark + " - 0" + " - 堆垛机站出库到出库站 ===》执行完成"); |
| | | } |
| | | |
| | |
| | | // if(crnThread.isBackHpFlag()){ |
| | | // continue; |
| | | // } |
| | | |
| | | //堆垛机回原点任务中 |
| | | Object object = redisUtil.get(RedisConstantType.CRN_MOVE_LOCK); |
| | | if (object != null) { |
| | | continue; |
| | | } |
| | | |
| | | // 只有当堆垛机空闲 并且 无任务时才继续执行 |
| | | if (crnProtocol.getStatusType() == CrnStatusType.IDLE && crnProtocol.getTaskNo() == 0 && crnProtocol.getModeType() == CrnModeType.AUTO |
| | |
| | | News.error("堆垛机移动命令下发失败,堆垛机号={},任务数据={}", crnProtocol.getCrnNo(), JSON.toJSON(crnCommand)); |
| | | } |
| | | crnThread.setBackHpFlag(true); |
| | | redisUtil.set(RedisConstantType.CRN_MOVE_LOCK + crn.getId(), "lock", 60); |
| | | redisUtil.set(RedisConstantType.CRN_MOVE_LOCK + crn.getId(), "lock", 10); |
| | | try { |
| | | Thread.sleep(500); |
| | | } catch (Exception e) { |
| | |
| | | News.error("堆垛机移动命令下发失败,堆垛机号={},任务数据={}", crnProtocol.getCrnNo(), JSON.toJSON(crnCommand)); |
| | | } |
| | | crnThread.setBackHpFlag(true); |
| | | redisUtil.set(RedisConstantType.CRN_MOVE_LOCK + crn.getId(), "lock", 60); |
| | | redisUtil.set(RedisConstantType.CRN_MOVE_LOCK + crn.getId(), "lock", 10); |
| | | try { |
| | | Thread.sleep(500); |
| | | } catch (Exception e) { |
| | |
| | | // continue; |
| | | } |
| | | // 判断堆垛机出库站状态 |
| | | if (staProtocol.isAutoing() && !staProtocol.isLoading() && staDetl.getCanouting() != null && staDetl.getCanouting().equals("Y") |
| | | && staProtocol.getWorkNo() == 0) { |
| | | if (staProtocol.isAutoing() && !staProtocol.isLoading() && staDetl.getCanouting() != null && staDetl.getCanouting().equals("Y")) { |
| | | |
| | | //根据参数判断是否校验可出信号 |
| | | String crnOutVerifyOut = "Y"; |
| | |
| | | |
| | | if (crnOutVerifyOut.equals("Y")) { |
| | | if (!staProtocol.isOutEnable()) { |
| | | continue; |
| | | } |
| | | |
| | | if (staProtocol.getWorkNo() > 0) { |
| | | continue; |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | if (crnProtocol.getCrnNo() == 1) { |
| | | //判断堆垛机和当前任务是否处于一个巷道 |
| | | if (Utils.getLaneByLocNo(wrkMast.getSourceLocNo()) != crnProtocol.getCrnLane()) { |
| | | //判断堆垛机所在巷道是否存在其他任务,如存在则优先执行 |
| | | List<WrkMast> currentWrkMasts = wrkMastService.selectLaneWrkMast(crnProtocol.getCrnLane(), false); |
| | | if (!currentWrkMasts.isEmpty()) { |
| | | continue;//当前堆垛机所在巷道存在任务 |
| | | String turnCrnExecuteCurrentChannel = "Y"; |
| | | Config turnCrnExecuteCurrentChannelConfig = configService.selectOne(new EntityWrapper<Config>() |
| | | .eq("code", "turnCrnExecuteCurrentChannel") |
| | | ); |
| | | if (turnCrnExecuteCurrentChannelConfig != null) { |
| | | turnCrnExecuteCurrentChannel = turnCrnExecuteCurrentChannelConfig.getValue(); |
| | | } |
| | | |
| | | if(turnCrnExecuteCurrentChannel.equals("Y")) { |
| | | //判断堆垛机和当前任务是否处于一个巷道 |
| | | if (Utils.getLaneByLocNo(wrkMast.getSourceLocNo()) != crnProtocol.getCrnLane()) { |
| | | //判断堆垛机所在巷道是否存在其他任务,如存在则优先执行 |
| | | List<WrkMast> currentWrkMasts = wrkMastService.selectLaneWrkMast(crnProtocol.getCrnLane(), false); |
| | | if (!currentWrkMasts.isEmpty()) { |
| | | continue;//当前堆垛机所在巷道存在任务 |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | if (wrkMastMapper.updateById(wrkMast) == 0) { |
| | | News.error("" + mark + " - 3" + " - 5" + " - 【库位移转】 修改工作档状态 11.生成出库ID => 12.吊车出库中 失败!!,工作号={}", wrkMast.getWrkNo()); |
| | | } |
| | | crnProtocol.setLastIo("I"); |
| | | } |
| | | News.infoNoLog("" + mark + " - 3" + " - 0" + " - 堆垛机入出库作业下发:库位移转完成"); |
| | | |
| | |
| | | if (crnProtocol.getTaskNo() == 9999) { |
| | | // 堆垛机复位 |
| | | crnThread.setResetFlag(true); |
| | | } else { |
| | | // 获取入库待确认工作档 |
| | | WrkMast wrkMast = wrkMastMapper.selectPakInStep3(crnProtocol.getTaskNo().intValue()); |
| | | if (wrkMast == null) { |
| | | News.error("" + mark + " - 1" + " - 堆垛机处于等待确认且任务完成状态,但未找到工作档。堆垛机号={},工作号={}", crn.getId(), crnProtocol.getTaskNo()); |
| | | continue; |
| | | } |
| | | continue; |
| | | } |
| | | |
| | | // 获取待确认工作档 |
| | | WrkMast wrkMast = wrkMastMapper.selectPakInStep3(crnProtocol.getTaskNo().intValue()); |
| | | if (wrkMast == null) { |
| | | News.error("" + mark + " - 1" + " - 堆垛机处于等待确认且任务完成状态,但未找到工作档。堆垛机号={},工作号={}", crn.getId(), crnProtocol.getTaskNo()); |
| | | continue; |
| | | } |
| | | |
| | | Date now = new Date(); |
| | | if(wrkMast.getIoType() < 100){ |
| | | // 入库 + 库位转移 ==> 4.入库完成 |
| | | if (wrkMast.getWrkSts() == 3 || (wrkMast.getWrkSts() == 12 && (wrkMast.getIoType() == 11 || wrkMast.getIoType() == 111))) { |
| | | wrkMast.setWrkSts(4L); |
| | | } else { |
| | | continue; |
| | | } |
| | | Date now = new Date(); |
| | | |
| | | wrkMast.setCrnEndTime(now); |
| | | wrkMast.setModiTime(now); |
| | | // 修改成功后复位堆垛机 |
| | | if (wrkMastMapper.updateById(wrkMast) > 0) { |
| | | // 堆垛机复位 |
| | | News.warnNoLog("" + mark + " - 2" + " - 修改成功后复位堆垛机 : 堆垛机号={}", crnThread.getCrnProtocol().getCrnNo()); |
| | | crnThread.setResetFlag(true); |
| | | } |
| | | }else { |
| | | List<Long> list = new ArrayList<>(); |
| | | list.add(14L); |
| | | list.add(15L); |
| | | if (!list.contains(wrkMast.getWrkSts())) { |
| | | News.error("" + mark + " - 1" + " - 堆垛机处于等待确认但工作档状态未完成。堆垛机号={},工作号={}", crn.getId(), crnProtocol.getTaskNo()); |
| | | continue; |
| | | } |
| | | |
| | | wrkMast.setCrnEndTime(now); |
| | | if (wrkMastMapper.updateById(wrkMast) != 0) { |
| | | // 复位堆垛机 |
| | | crnThread.setResetFlag(true); |
| | | } |
| | | } |
| | |
| | | if (jsonObject.getInteger("code").equals(200)) { |
| | | StartupDto dto = jsonObject.getObject("data", StartupDto.class); |
| | | |
| | | LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>() |
| | | .eq("loc_no", dto.getLocNo())); |
| | | |
| | | // 更新站点信息 且 下发plc命令 |
| | | staProtocol.setWorkNo(dto.getWorkNo().shortValue()); |
| | | staProtocol.setStaNo(dto.getStaNo().shortValue()); |
| | | staProtocol.setPalletSize(locMast.getLocType2()); |
| | | devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | | boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | | if (!result) { |
| | |
| | | wrkMast1.setIoType(3); // 入出库状态:3.站到站 |
| | | wrkMast1.setIoPri(13D); // 优先级 |
| | | wrkMast1.setSourceStaNo(emptyInSta.getStaNo()); |
| | | wrkMast1.setStaNo(1007); |
| | | wrkMast1.setStaNo(1004); |
| | | wrkMast1.setBarcode(barcode); |
| | | // 操作人员数据 |
| | | wrkMast1.setAppeTime(new Date()); |
| | |
| | | // 更新站点信息 且 下发plc命令 |
| | | staProtocol.setWorkNo((short) workNo); |
| | | staProtocol.setStaNo((short) 2003); |
| | | staProtocol.setPalletSize((short) 1); |
| | | devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | | boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | | if (!result) { |