| | |
| | | import com.core.common.Cools; |
| | | 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.VersionUtils; |
| | | import com.zy.common.model.MatDto; |
| | | import com.zy.common.model.StartupDto; |
| | | import com.zy.common.service.CommonService; |
| | | import com.zy.common.utils.CollectionUtils; |
| | | import com.zy.core.CrnThread; |
| | | import com.zy.core.cache.MessageQueue; |
| | | import com.zy.core.cache.SlaveConnection; |
| | | import com.zy.core.enums.*; |
| | |
| | | import com.zy.core.model.protocol.StaProtocol; |
| | | import com.zy.core.properties.SlaveProperties; |
| | | import com.zy.core.thread.BarcodeThread; |
| | | import com.zy.core.CrnThread; |
| | | import com.zy.core.thread.DevpThread; |
| | | import com.zy.core.thread.LedThread; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | @Autowired |
| | | private BasDevpService basDevpService; |
| | | @Autowired |
| | | private LocDetlService locDetlService; |
| | | @Autowired |
| | | private BasErrLogService basErrLogService; |
| | | @Autowired |
| | | private BasCrnErrorMapper basCrnErrorMapper; |
| | | @Autowired |
| | | private JdbcTemplate jdbcTemplate; |
| | | |
| | | /** |
| | |
| | | staProtocol = staProtocol.clone(); |
| | | } |
| | | // 判断是否满足入库条件 |
| | | if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.isInEnable() |
| | | if (staProtocol.isAutoing() && staProtocol.isLoading() |
| | | // && staProtocol.isInEnable() |
| | | && !staProtocol.isEmptyMk() && staProtocol.getWorkNo() == 0 |
| | | && staProtocol.isPakMk() && !Cools.isEmpty(barcode)) { |
| | | // 判断重复工作档 |
| | |
| | | /** |
| | | * 堆垛机异常信息记录 |
| | | */ |
| | | @Async |
| | | public void recCrnErr(){ |
| | | Date now = new Date(); |
| | | for (CrnSlave crn : slaveProperties.getCrn()) { |
| | | // 获取堆垛机信息 |
| | | CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crn.getId()); |
| | | CrnProtocol crnProtocol = crnThread.getCrnProtocol(); |
| | | if (crnProtocol == null) { |
| | | continue; |
| | | } |
| | | if (crnProtocol.getModeType() != CrnModeType.STOP) { |
| | | // 有任务 |
| | | if (crnProtocol.getTaskNo() != 0) { |
| | | BasErrLog latest = basErrLogService.findLatestByTaskNo(crn.getId(), crnProtocol.getTaskNo().intValue()); |
| | | // 有异常 |
| | | if (latest == null) { |
| | | if (crnProtocol.getAlarm1() != null && crnProtocol.getAlarm1() > 0) { |
| | | WrkMast wrkMast = wrkMastMapper.selectById(crnProtocol.getTaskNo()); |
| | | BasCrnError crnError = basCrnErrorMapper.selectById(crnProtocol.getAlarm1()); |
| | | BasErrLog basErrLog = new BasErrLog( |
| | | null, // 编号 |
| | | wrkMast.getWrkNo(), // 工作号 |
| | | now, // 发生时间 |
| | | null, // 结束时间 |
| | | wrkMast.getWrkSts(), // 工作状态 |
| | | wrkMast.getIoType(), // 入出库类型 |
| | | crn.getId(), // 堆垛机 |
| | | null, // plc |
| | | wrkMast.getLocNo(), // 目标库位 |
| | | wrkMast.getStaNo(), // 目标站 |
| | | wrkMast.getSourceStaNo(), // 源站 |
| | | wrkMast.getSourceLocNo(), // 源库位 |
| | | wrkMast.getBarcode(), // 条码 |
| | | crnProtocol.getAlarm1().intValue(), // 异常码 |
| | | crnError.getErrName(), // 异常 |
| | | 1, // 异常情况 |
| | | now, // 添加时间 |
| | | null, // 添加人员 |
| | | now, // 修改时间 |
| | | null, // 修改人员 |
| | | "任务中异常" // 备注 |
| | | ); |
| | | if (!basErrLogService.insert(basErrLog)) { |
| | | log.error("堆垛机plc异常记录失败 ===>> [id:{}] [error:{}]", crn.getId(), crnError.getErrName()); |
| | | } |
| | | } |
| | | } else { |
| | | // 异常修复 |
| | | if (crnProtocol.getAlarm1() == null || crnProtocol.getAlarm1() == 0) { |
| | | latest.setEndTime(now); |
| | | latest.setUpdateTime(now); |
| | | latest.setStatus(2); |
| | | if (!basErrLogService.updateById(latest)) { |
| | | log.error("堆垛机plc异常记录修复失败 ===>> [id:{}] [errLogId:{}]", crn.getId(), latest.getId()); |
| | | } |
| | | } |
| | | } |
| | | // 无任务 |
| | | } else { |
| | | BasErrLog latest = basErrLogService.findLatest(crn.getId()); |
| | | // 有异常 |
| | | if (crnProtocol.getAlarm1() != null && crnProtocol.getAlarm1() > 0) { |
| | | // 记录新异常 |
| | | if (latest == null || (latest.getErrCode() != crnProtocol.getAlarm1().intValue())) { |
| | | BasCrnError crnError = basCrnErrorMapper.selectById(crnProtocol.getAlarm1()); |
| | | BasErrLog basErrLog = new BasErrLog( |
| | | null, // 编号 |
| | | null, // 工作号 |
| | | now, // 发生时间 |
| | | null, // 结束时间 |
| | | null, // 工作状态 |
| | | null, // 入出库类型 |
| | | crn.getId(), // 堆垛机 |
| | | null, // plc |
| | | null, // 目标库位 |
| | | null, // 目标站 |
| | | null, // 源站 |
| | | null, // 源库位 |
| | | null, // 条码 |
| | | crnProtocol.getAlarm1().intValue(), // 异常码 |
| | | crnError.getErrName(), // 异常 |
| | | 1, // 异常情况 |
| | | now, // 添加时间 |
| | | null, // 添加人员 |
| | | now, // 修改时间 |
| | | null, // 修改人员 |
| | | "无任务异常" // 备注 |
| | | ); |
| | | if (!basErrLogService.insert(basErrLog)) { |
| | | log.error("堆垛机plc异常记录失败 ===>> [id:{}] [error:{}]", crn.getId(), crnError.getErrName()); |
| | | } |
| | | } |
| | | // 无异常 |
| | | } else { |
| | | // 异常修复 |
| | | if (latest != null && latest.getStatus() == 1) { |
| | | latest.setEndTime(now); |
| | | latest.setUpdateTime(now); |
| | | latest.setStatus(2); |
| | | if (!basErrLogService.updateById(latest)) { |
| | | log.error("堆垛机plc异常记录修复失败 ===>> [id:{}] [errLogId:{}]", crn.getId(), latest.getId()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | ledCommand.setStaNo(wrkMast.getStaNo()); |
| | | if (wrkMast.getIoType() != 110) { |
| | | List<WrkDetl> wrkDetls = wrkDetlService.findByWorkNo(wrkMast.getWrkNo()); |
| | | wrkDetls.forEach(wrkDetl -> ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMatnr(), wrkDetl.getAnfme()))); |
| | | wrkDetls.forEach(wrkDetl -> ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getAnfme()))); |
| | | } |
| | | commands.add(ledCommand); |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 堆垛机演示 ===>> 库位移转 |
| | | */ |
| | | @Async |
| | | public void crnDemoOfLocMove(Integer crn){ |
| | | for (int i = 0; i < 5; i++) { |
| | | |
| | | LocMast sourceLoc = locMastService.queryDemoSourceLoc(crn); |
| | | LocMast loc = locMastService.queryDemoLoc(crn); |
| | | if (null == sourceLoc || null == loc) { |
| | | break; |
| | | } |
| | | String sourceLocNo = sourceLoc.getLocNo(); |
| | | String locNo = loc.getLocNo(); |
| | | |
| | | // 获取工作号 |
| | | int workNo = commonService.getWorkNo(0); |
| | | // 保存工作档 |
| | | WrkMast wrkMast = new WrkMast(); |
| | | wrkMast.setWrkNo(workNo); |
| | | wrkMast.setIoTime(new Date()); |
| | | wrkMast.setWrkSts(11L); // 工作状态:11.生成出库ID |
| | | wrkMast.setIoType(11); // 入出库状态: 11.库格移载 |
| | | wrkMast.setIoPri(13D); |
| | | wrkMast.setCrnNo(crn); |
| | | wrkMast.setSourceLocNo(sourceLocNo); // 源库位 |
| | | wrkMast.setLocNo(locNo); // 目标库位 |
| | | wrkMast.setFullPlt("N"); // 满板:Y |
| | | wrkMast.setPicking("N"); // 拣料 |
| | | wrkMast.setExitMk("N"); // 退出 |
| | | wrkMast.setEmptyMk(sourceLoc.getLocSts().equals("D")?"Y":"N"); // 空板 |
| | | wrkMast.setBarcode(sourceLoc.getBarcode()); // 托盘码 |
| | | wrkMast.setLinkMis("N"); |
| | | wrkMast.setAppeTime(new Date()); |
| | | wrkMast.setModiTime(new Date()); |
| | | int res = wrkMastMapper.insert(wrkMast); |
| | | if (res == 0) { |
| | | throw new CoolException("保存工作档失败"); |
| | | } |
| | | // 工作档明细保存 |
| | | List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", sourceLocNo)); |
| | | for (LocDetl locDetl : locDetls) { |
| | | WrkDetl wrkDetl = new WrkDetl(); |
| | | wrkDetl.setWrkNo(workNo); |
| | | wrkDetl.setIoTime(new Date()); |
| | | wrkDetl.setAnfme(locDetl.getAnfme()); |
| | | VersionUtils.setWrkDetl(wrkDetl, locDetl); // 版本控制 |
| | | wrkDetl.setAppeTime(new Date()); |
| | | wrkDetl.setModiTime(new Date()); |
| | | if (!wrkDetlService.insert(wrkDetl)) { |
| | | throw new CoolException("保存工作档明细失败"); |
| | | } |
| | | } |
| | | // 修改源库位状态 |
| | | if (sourceLoc.getLocSts().equals("D") || sourceLoc.getLocSts().equals("F")) { |
| | | sourceLoc.setLocSts("R"); // R.出库预约 |
| | | sourceLoc.setModiTime(new Date()); |
| | | if (!locMastService.updateById(sourceLoc)){ |
| | | throw new CoolException("更新源库位状态失败"); |
| | | } |
| | | } else { |
| | | throw new CoolException("源库位出库失败"); |
| | | } |
| | | // 修改目标库位状态 |
| | | if (loc.getLocSts().equals("O")) { |
| | | loc.setLocSts("S"); // S.入库预约 |
| | | loc.setModiTime(new Date()); |
| | | if (!locMastService.updateById(loc)) { |
| | | throw new CoolException("更新目标库位状态失败"); |
| | | } |
| | | } else { |
| | | throw new CoolException("移转失败"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |