| | |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.entity.*; |
| | | import com.zy.asrs.mapper.BasCrnErrorMapper; |
| | | import com.zy.asrs.mapper.WaitPakinMapper; |
| | | import com.zy.asrs.mapper.WrkMastMapper; |
| | | import com.zy.asrs.service.*; |
| | | import com.zy.asrs.utils.Utils; |
| | |
| | | import com.zy.common.model.MatDto; |
| | | import com.zy.common.model.SearchLocParam; |
| | | import com.zy.common.model.StartupDto; |
| | | import com.zy.common.service.CommonService; |
| | | import com.zy.common.utils.CollectionUtils; |
| | | import com.zy.common.utils.HttpHandler; |
| | | import com.zy.core.CrnThread; |
| | |
| | | @Transactional |
| | | public class MainServiceImpl { |
| | | |
| | | public static final long COMMAND_TIMEOUT = 5 * 1000; |
| | | |
| | | @Autowired |
| | | private CommonService commonService; |
| | | @Value("${wms.url}") |
| | | private String wmsUrl; |
| | | @Autowired |
| | | private SlaveProperties slaveProperties; |
| | | @Autowired |
| | | private WrkMastMapper wrkMastMapper; |
| | | @Autowired |
| | | private WrkDetlService wrkDetlService; |
| | | @Autowired |
| | | private WaitPakinMapper waitPakinMapper; |
| | | @Autowired |
| | | private LocMastService locMastService; |
| | | @Autowired |
| | |
| | | @Autowired |
| | | private BasDevpService basDevpService; |
| | | @Autowired |
| | | private LocDetlService locDetlService; |
| | | @Autowired |
| | | private BasErrLogService basErrLogService; |
| | | @Autowired |
| | | private BasCrnErrorMapper basCrnErrorMapper; |
| | | @Autowired |
| | | private BasSteService basSteService; |
| | | @Value("${wms.url}") |
| | | private String wmsUrl; |
| | | |
| | | /** |
| | | * 组托 |
| | |
| | | for (DevpSlave devp : slaveProperties.getDevp()) { |
| | | // 遍历拣料入库口 |
| | | for (DevpSlave.Sta pickSta : devp.getPickSta()) { |
| | | // 获取条码扫描仪信息 |
| | | BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, pickSta.getBarcode()); |
| | | if (barcodeThread == null) { |
| | | continue; |
| | | } |
| | | String barcode = barcodeThread.getBarcode(); |
| | | if(!Cools.isEmpty(barcode)) { |
| | | log.info("{}号条码扫描器检测条码信息:{}", pickSta.getBarcode(), barcode); |
| | | if("NG".endsWith(barcode) || "NoRead".equals(barcode)) { |
| | | continue; |
| | | } |
| | | } else { |
| | | continue; |
| | | } |
| | | |
| | | // 获取拣料入库站信息 |
| | | DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId()); |
| | |
| | | staProtocol = staProtocol.clone(); |
| | | } |
| | | if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.isInEnable() && staProtocol.isPakMk()){ |
| | | |
| | | // 获取条码扫描仪信息 |
| | | BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, pickSta.getBarcode()); |
| | | if (barcodeThread == null) { |
| | | continue; |
| | | } |
| | | String barcode = barcodeThread.getBarcode(); |
| | | if(!Cools.isEmpty(barcode)) { |
| | | log.info("{}号条码扫描器检测条码信息:{}", pickSta.getBarcode(), barcode); |
| | | if("NG".endsWith(barcode) || "NoRead".equals(barcode)) { |
| | | continue; |
| | | } |
| | | } else { |
| | | continue; |
| | | } |
| | | |
| | | WrkMast wrkMast = wrkMastMapper.selectPickStep(barcode); |
| | | if (wrkMast == null) { |
| | | // 无拣料数据 |
| | |
| | | // 有小车 |
| | | if (steNo != null) { |
| | | // 小车行走到堆垛机待搬移点 |
| | | if (wrkMast.getWrkSts() == 2L && wrkMast.getStaNo() == null) { |
| | | this.letCarBeReady(wrkMast, steNo); |
| | | if (wrkMast.getWrkSts() == 2L && wrkMast.getSteNo() == null) { |
| | | this.letCarBeReady(wrkMast, steNo, wrkMast.getLocNo()); |
| | | } |
| | | // 小车搬走 |
| | | if (wrkMast.getWrkSts() == 3L) { |
| | |
| | | // 有小车 |
| | | if (steNo != null) { |
| | | // 小车行走到堆垛机待搬移点 |
| | | if (wrkMast.getWrkSts() == 2L && wrkMast.getStaNo() == null) { |
| | | this.letCarBeReady(wrkMast, steNo); |
| | | if (wrkMast.getWrkSts() == 2L && wrkMast.getSteNo() == null) { |
| | | this.letCarBeReady(wrkMast, steNo, wrkMast.getLocNo()); |
| | | } |
| | | // 堆垛机将货放至小车上 3.小车待搬(小车不用搬运,已经在当前组库位) / 6.小车待入 ===>> 7.吊车入库中 |
| | | if (wrkMast.getWrkSts() == 3L || wrkMast.getWrkSts() == 6L) { |
| | |
| | | SteThread steThread = (SteThread) SlaveConnection.get(SlaveType.Ste, steNo); |
| | | SteProtocol steProtocol = steThread.getSteProtocol(); |
| | | if (steProtocol == null) { continue; } |
| | | if (steProtocol.getStatusType().equals(SteStatusType.IDLE)) { |
| | | if (steProtocol.isIdle()) { |
| | | |
| | | // 已经存在吊车执行任务时,则过滤 |
| | | if (wrkMastMapper.selectWorking(slave.getId()) != null) { |
| | |
| | | } |
| | | // 没有小车 |
| | | } else { |
| | | if (wrkMast.getWrkSts() == 2L && wrkMast.getStaNo() == null) { |
| | | if (wrkMast.getWrkSts() == 2L && wrkMast.getSteNo() == null) { |
| | | // 寻找当前堆垛机对应的小车 |
| | | SteThread steThread = queryIdleCar(wrkMast); |
| | | if (steThread != null) { |
| | | // 让小车等待搬运待续 |
| | | this.letCarBeReady(wrkMast, steThread.getSlave().getId()); |
| | | this.letCarBeReady(wrkMast, steThread.getSlave().getId(), wrkMast.getLocNo()); |
| | | } |
| | | } |
| | | // 堆垛机搬运小车 |
| | |
| | | // 不是最外层库位,需要使用穿梭车搬运后,再堆垛机出库 |
| | | } else { |
| | | // 当前组库位是否有穿梭车 |
| | | Integer steNo = this.hasCarOfIdle(wrkMast.getLocNo()); |
| | | Integer steNo = this.hasCarOfIdle(wrkMast.getSourceLocNo()); |
| | | // 有小车 |
| | | if (steNo != null) { |
| | | if (wrkMast.getWrkSts() == 11L && wrkMast.getSteNo() == null) { |
| | |
| | | SteThread steThread = (SteThread) SlaveConnection.get(SlaveType.Ste, steNo); |
| | | SteProtocol steProtocol = steThread.getSteProtocol(); |
| | | if (steProtocol == null) { continue; } |
| | | if (steProtocol.getStatusType().equals(SteStatusType.IDLE)) { |
| | | if (steProtocol.isIdle()) { |
| | | |
| | | // 命令下发区 -------------------------------------------------------------------------- |
| | | SteCommand steCommand = new SteCommand(); |
| | | steCommand.setSteNo(steNo); // 穿梭车编号 |
| | | steCommand.setTaskNo(wrkMast.getWrkNo()); // 工作号 |
| | | steCommand.setTaskMode(SteTaskModeType.TO_B); // 任务模式: 去近点 等待堆垛机叉取 |
| | | // todo:luxiaotao |
| | | steCommand.setTaskMode(SteTaskModeType.findOutByLoc(wrkMast.getSourceLocNo())); // 任务模式: 去近点 等待堆垛机叉取 |
| | | |
| | | if (!MessageQueue.offer(SlaveType.Ste, steNo, new Task(2, steCommand))) { |
| | | log.error("穿梭车命令下发失败,穿梭车号={},任务数据={}", steNo, JSON.toJSON(steCommand)); |
| | | } else { |
| | |
| | | |
| | | // 没有小车 |
| | | } else { |
| | | if (wrkMast.getWrkSts() == 11L && wrkMast.getStaNo() == null) { |
| | | if (wrkMast.getWrkSts() == 11L && wrkMast.getSteNo() == null) { |
| | | // 寻找最近的小车 |
| | | SteThread steThread = queryIdleCar(wrkMast); |
| | | if (steThread != null) { |
| | | // 让小车等待搬运待续 |
| | | this.letCarBeReady(wrkMast, steThread.getSlave().getId()); |
| | | this.letCarBeReady(wrkMast, steThread.getSlave().getId(), wrkMast.getSourceLocNo()); |
| | | } |
| | | } |
| | | // 堆垛机搬运小车 |
| | |
| | | SteThread steThread = (SteThread) SlaveConnection.get(SlaveType.Ste, ste.getId()); |
| | | SteProtocol steProtocol = steThread.getSteProtocol(); |
| | | if (steProtocol == null) { continue; } |
| | | if (steProtocol.getStatusType().equals(SteStatusType.IDLE)) { |
| | | if (steProtocol.isIdle()) { |
| | | if (Utils.getGroupRow(locNo).equals(Utils.getGroupRow(steProtocol.getRow().intValue())) && steProtocol.getBay() == Utils.getBay(locNo) && steProtocol.getLev() == Utils.getLev(locNo)) { |
| | | return steProtocol.getSteNo().intValue(); |
| | | } |
| | |
| | | SteThread steThread = (SteThread) SlaveConnection.get(SlaveType.Ste, basSte.getSteNo()); |
| | | SteProtocol steProtocol = steThread.getSteProtocol(); |
| | | if (steProtocol != null) { |
| | | if (steProtocol.getStatusType().equals(SteStatusType.IDLE)) { |
| | | if (steProtocol.isIdle()) { |
| | | return steThread; |
| | | } |
| | | } |
| | |
| | | * 让小车从 远点 ====>> 移动到近点 |
| | | * 等待堆垛机搬运 |
| | | */ |
| | | public void letCarBeReady(WrkMast wrkMast, Integer steNo) { |
| | | public void letCarBeReady(WrkMast wrkMast, Integer steNo, String locNo) { |
| | | // 获取穿梭车信息 |
| | | SteThread steThread = (SteThread) SlaveConnection.get(SlaveType.Ste, steNo); |
| | | SteProtocol steProtocol = steThread.getSteProtocol(); |
| | | if (steProtocol == null) { return; } |
| | | if (steProtocol.getStatusType().equals(SteStatusType.IDLE)) { |
| | | if (steProtocol.isIdle()) { |
| | | |
| | | // 命令下发区 -------------------------------------------------------------------------- |
| | | SteCommand steCommand = new SteCommand(); |
| | | steCommand.setSteNo(steNo); // 穿梭车编号 |
| | | steCommand.setTaskNo(wrkMast.getWrkNo()); // 工作号 |
| | | steCommand.setTaskMode(SteTaskModeType.TO_B); // 任务模式: 去近点 等待堆垛机叉取 |
| | | steCommand.setTaskMode(SteTaskModeType.findOriginByLoc(locNo)); // 任务模式: 去近点 等待堆垛机叉取 |
| | | |
| | | steCommand.setRow(Utils.getGroupRow(steProtocol.getRow().intValue()).shortValue()); |
| | | steCommand.setBay(steProtocol.getBay()); |
| | | steCommand.setLev(steProtocol.getLev()); |
| | | |
| | | if (!MessageQueue.offer(SlaveType.Ste, steNo, new Task(2, steCommand))) { |
| | | log.error("穿梭车命令下发失败,穿梭车号={},任务数据={}", steNo, JSON.toJSON(steCommand)); |
| | | } else { |
| | |
| | | SteThread steThread = (SteThread) SlaveConnection.get(SlaveType.Ste, steNo); |
| | | SteProtocol steProtocol = steThread.getSteProtocol(); |
| | | if (steProtocol == null) { return; } |
| | | if (steProtocol.getStatusType().equals(SteStatusType.IDLE)) { |
| | | if (steProtocol.isIdle()) { |
| | | // 堆垛机空闲 |
| | | if (crnProtocol.getStatusType().equals(CrnStatusType.IDLE) || crnProtocol.getTaskNo() == 0) { |
| | | LocMast locMast; |
| | |
| | | if (!MessageQueue.offer(SlaveType.Crn, wrkMast.getCrnNo(), new Task(2, crnCommand))) { |
| | | log.error("堆垛机命令下发失败,堆垛机号={},任务数据={}", wrkMast.getCrnNo(), JSON.toJSON(crnCommand)); |
| | | } else { |
| | | // 修改穿梭车运行中排列层 |
| | | steThread.modifyPos(Utils.getGroupRow(locMast.getLocNo()), locMast.getBay1(), locMast.getLev1()); |
| | | // 修改工作档状态 3.小车待搬 => 4.迁入小车 |
| | | Date now = new Date(); |
| | | wrkMast.setWrkSts(4L); |
| | |
| | | if (!MessageQueue.offer(SlaveType.Crn, wrkMast.getCrnNo(), new Task(2, crnCommand))) { |
| | | log.error("堆垛机命令下发失败,堆垛机号={},任务数据={}", wrkMast.getCrnNo(), JSON.toJSON(crnCommand)); |
| | | } else { |
| | | // 修改穿梭车运行中排列层 |
| | | steThread.modifyPos(Utils.getGroupRow(locMast.getLocNo()), locMast.getBay1(), locMast.getLev1()); |
| | | // 修改工作档状态 12.小车待搬 => 13.迁入小车 |
| | | Date now = new Date(); |
| | | wrkMast.setWrkSts(13L); |
| | |
| | | SteProtocol steProtocol = steThread.getSteProtocol(); |
| | | if (steProtocol == null) { return; } |
| | | // 穿梭车空闲 |
| | | if (steProtocol.getStatusType().equals(SteStatusType.IDLE)) { |
| | | if (steProtocol.isIdle()) { |
| | | // 堆垛机空闲 |
| | | if (crnProtocol.getStatusType().equals(CrnStatusType.IDLE) || crnProtocol.getTaskNo() == 0) { |
| | | |
| | |
| | | if (!MessageQueue.offer(SlaveType.Crn, wrkMast.getCrnNo(), new Task(2, crnCommand))) { |
| | | log.error("堆垛机命令下发失败,堆垛机号={},任务数据={}", wrkMast.getCrnNo(), JSON.toJSON(crnCommand)); |
| | | } else { |
| | | |
| | | // 修改穿梭车运行中排列层 |
| | | steThread.modifyPos(Utils.getGroupRow(idleLocNo), Utils.getBay(idleLocNo), Utils.getLev(idleLocNo)); |
| | | // 修改工作档状态 3.小车待搬 => 5.迁出小车 |
| | | Date now = new Date(); |
| | | wrkMast.setWrkSts(5L); |
| | |
| | | SteThread steThread = (SteThread) SlaveConnection.get(SlaveType.Ste, steNo); |
| | | SteProtocol steProtocol = steThread.getSteProtocol(); |
| | | if (steProtocol == null) { continue; } |
| | | if (steProtocol.getStatusType().equals(SteStatusType.IDLE)) { |
| | | if (steProtocol.isIdle()) { |
| | | // 命令下发区 -------------------------------------------------------------------------- |
| | | SteCommand steCommand = new SteCommand(); |
| | | steCommand.setSteNo(steNo); // 穿梭车编号 |
| | | steCommand.setTaskNo(wrkMast.getWrkNo()); // 工作号 |
| | | steCommand.setTaskMode(SteTaskModeType.TO_B); // 任务模式: 去近点 等待堆垛机叉取 |
| | | // todo:luxiaotao |
| | | steCommand.setTaskMode(SteTaskModeType.findInByLoc(wrkMast.getLocNo())); // 任务模式: 搬入库 |
| | | if (!MessageQueue.offer(SlaveType.Ste, steNo, new Task(2, steCommand))) { |
| | | log.error("穿梭车命令下发失败,穿梭车号={},任务数据={}", steNo, JSON.toJSON(steCommand)); |
| | | } else { |
| | |
| | | if (wrkMastMapper.updateById(wrkMast) > 0) { |
| | | // 堆垛机复位 |
| | | crnThread.setResetFlag(true); |
| | | // 穿梭车重新定位排列层 |
| | | SteThread steThread = (SteThread) SlaveConnection.get(SlaveType.Ste, wrkMast.getSteNo()); |
| | | if (!steThread.confirmPos()) { |
| | | log.error("{}号穿梭车重新定位失败!作业工作档任务号:{}", wrkMast.getSteNo(), wrkMast.getWrkNo()); |
| | | } |
| | | } else { |
| | | log.error("修改工作档状态 4.迁入小车 => 6.小车待入 失败!!,工作号={}", wrkMast.getWrkNo()); |
| | | } |
| | |
| | | if (wrkMastMapper.updateById(wrkMast) > 0) { |
| | | // 堆垛机复位 |
| | | crnThread.setResetFlag(true); |
| | | // 穿梭车重新定位排列层 |
| | | SteThread steThread = (SteThread) SlaveConnection.get(SlaveType.Ste, wrkMast.getSteNo()); |
| | | if (!steThread.confirmPos()) { |
| | | log.error("{}号穿梭车重新定位失败!作业工作档任务号:{}", wrkMast.getSteNo(), wrkMast.getWrkNo()); |
| | | } |
| | | } else { |
| | | log.error("修改工作档状态 5.迁出小车 => 6.小车待入 失败!!,工作号={}", wrkMast.getWrkNo()); |
| | | } |
| | |
| | | SteThread steThread = (SteThread) SlaveConnection.get(SlaveType.Ste, steNo); |
| | | SteProtocol steProtocol = steThread.getSteProtocol(); |
| | | if (steProtocol == null) { continue; } |
| | | if (steProtocol.getStatusType().equals(SteStatusType.IDLE)) { |
| | | if (steProtocol.isIdle()) { |
| | | // 穿梭车重新定位排列层 |
| | | if (!steThread.confirmPos()) { |
| | | log.error("{}号穿梭车重新定位失败!作业工作档任务号:{}", wrkMast.getSteNo(), wrkMast.getWrkNo()); |
| | | } |
| | | // 命令下发区 -------------------------------------------------------------------------- |
| | | SteCommand steCommand = new SteCommand(); |
| | | steCommand.setSteNo(steNo); // 穿梭车编号 |
| | | steCommand.setTaskNo(wrkMast.getWrkNo()); // 工作号 |
| | | steCommand.setTaskMode(SteTaskModeType.TO_B); // 任务模式: 去近点 等待堆垛机叉取 |
| | | // todo:luxiaotao |
| | | steCommand.setTaskMode(SteTaskModeType.findOutByLoc(wrkMast.getSourceLocNo())); // 任务模式: 搬出库 |
| | | if (!MessageQueue.offer(SlaveType.Ste, steNo, new Task(2, steCommand))) { |
| | | log.error("穿梭车命令下发失败,穿梭车号={},任务数据={}", steNo, JSON.toJSON(steCommand)); |
| | | } else { |
| | |
| | | SteThread steThread = (SteThread) SlaveConnection.get(SlaveType.Ste, ste.getId()); |
| | | SteProtocol steProtocol = steThread.getSteProtocol(); |
| | | if (steProtocol == null) { continue; } |
| | | if (steProtocol.getStatusType().equals(SteStatusType.WAITING) && steProtocol.getTaskNo() != 0) { |
| | | if (steProtocol.getWaiting() && steProtocol.getTaskNo() != 0) { |
| | | // 查询是否有待入库的任务 |
| | | WrkMast wrkMast = wrkMastMapper.selectCarWaiting(steProtocol.getTaskNo()); |
| | | if (wrkMast == null) { continue; } |
| | |
| | | ledCommand.setStaNo(wrkMast.getStaNo()); |
| | | if (wrkMast.getIoType() != 110) { |
| | | List<WrkDetl> wrkDetls = wrkDetlService.findByWorkNo(wrkMast.getWrkNo()); |
| | | wrkDetls.forEach(wrkDetl -> ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatNo(), wrkDetl.getMatName(), wrkDetl.getQty()))); |
| | | wrkDetls.forEach(wrkDetl -> ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getAnfme()))); |
| | | } |
| | | commands.add(ledCommand); |
| | | } |