| | |
| | | import com.zy.core.properties.SlaveProperties; |
| | | import com.zy.core.thread.BarcodeThread; |
| | | import com.zy.core.thread.LedThread; |
| | | import com.zy.core.thread.RgvThread; |
| | | import com.zy.core.thread.SiemensDevpThread; |
| | | import com.zy.core.model.RgvSlave; |
| | | import com.zy.core.model.protocol.RgvProtocol; |
| | | import com.zy.entity.*; |
| | | import com.zy.mapper.*; |
| | | import com.zy.mapper.BasRgvErrMapper; |
| | | import com.zy.service.*; |
| | | import com.zy.utils.*; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | |
| | | @Resource |
| | | private BasDevpErrLogService basDevpErrLogService; |
| | | |
| | | @Autowired |
| | | private BasRgvErrMapper basRgvErrMapper; |
| | | |
| | | @Value("${wms.url}") |
| | | private String wmsUrl; |
| | |
| | | continue; |
| | | } |
| | | |
| | | // 尺寸检测异常(复刻generateStoreWrkFile的逻辑,但不包括扫码失败) |
| | | boolean back = false; |
| | | String errMsg = ""; |
| | | if (staProtocol.isFrontErr()) { |
| | | errMsg = "前超限"; |
| | | back = true; |
| | | } |
| | | if (!back && staProtocol.isBackErr()) { |
| | | errMsg = "后超限"; |
| | | back = true; |
| | | } |
| | | if (!back && staProtocol.isHighErr()) { |
| | | errMsg = "高超限"; |
| | | back = true; |
| | | } |
| | | if (!back && staProtocol.isLeftErr()) { |
| | | errMsg = "左超限"; |
| | | back = true; |
| | | } |
| | | if (!back && staProtocol.isRightErr()) { |
| | | errMsg = "右超限"; |
| | | back = true; |
| | | } |
| | | if (!back && staProtocol.isWeightErr()) { |
| | | errMsg = "超重"; |
| | | back = true; |
| | | } |
| | | // 退回(空托入库的条件是isEmptyMk为true) |
| | | if (back && staProtocol.isInEnable() && staProtocol.isLoading() && staProtocol.isPakMk() && staProtocol.isEmptyMk()) { |
| | | Integer ledId = emptyInSta.getLed(); |
| | | if (ledId != null) { |
| | | MessageQueue.offer(SlaveType.Led, ledId, new Task(3, errMsg)); |
| | | } |
| | | News.info("{}空板入库回退:{},任务号:{}", emptyInSta.getStaNo(), errMsg, staProtocol.getWorkNo()); |
| | | staProtocol.setWorkNo(9999); |
| | | staProtocol.setStaNo(emptyInSta.getBackSta().shortValue()); |
| | | devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | | MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | | log.error("输送线下发1(空板):"+staProtocol.getWorkNo()+","+emptyInSta.getBackSta()); |
| | | continue; |
| | | } |
| | | |
| | | News.warnNoLog(""+mark+" - 0"+" - 开始执行:空栈板初始化入库,叉车入库站放货,条码:{}", barcode); |
| | | |
| | | try { |
| | |
| | | ledCommand.setStaNo(dto.getStaNo()); |
| | | commands.add(ledCommand); |
| | | MessageQueue.offer(SlaveType.Led, emptyInSta.getLed(), new Task(1, commands)); |
| | | // ledThread.errorReset(); |
| | | } |
| | | // 成功时重置LED错误 |
| | | if (ledThread != null) { |
| | | ledThread.errorReset(); |
| | | } |
| | | } else { |
| | | String errorMsg = jsonObject.getString("msg"); |
| | | // 如果任务回退,并且站点不是自动状态,则不触发回退 |
| | | if (!staProtocol.isAutoing()) { |
| | | log.error("空板入库回退"+staProtocol.getWorkNo()+","+errorMsg+",站点不是自动状态,不触发回退"); |
| | | log.error("空板入库回退,"+staProtocol.getWorkNo()+","+errorMsg+",站点不是自动状态,不触发回退"); |
| | | continue; |
| | | } |
| | | log.error("空板入库回退"+staProtocol.getWorkNo()+","+errorMsg); |
| | | staProtocol.setWorkNo(9999); |
| | | staProtocol.setStaNo(emptyInSta.getBackSta().shortValue()); |
| | | devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | | boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | | if (!result) { |
| | | News.errorNoLog(""+mark+" - 2"+" - 更新plc站点信息失败"); |
| | | throw new CoolException("更新plc站点信息失败"); |
| | | } |
| | | |
| | | if (ledThread != null) { |
| | | |
| | | MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | | log.error("空板入库回退,"+staProtocol.getWorkNo()+","+errorMsg); |
| | | if (!Cools.isEmpty(errorMsg)) { |
| | | MessageQueue.offer(SlaveType.Led, emptyInSta.getLed(), new Task(3, errorMsg)); |
| | | } |
| | | } |
| | | // News.error(""+mark+" - 3"+" - 请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/pakin/loc/v1", JSON.toJSONString(param), response); |
| | | } |
| | |
| | | ); |
| | | if (!basDevpErrLogService.insert(basErrLog)) { |
| | | News.error("输送线异常信息插入表asr_bas_devp_err_log异常:{}", basErrLog); |
| | | } |
| | | |
| | | // 输送线报警时托盘退回 |
| | | if (staProtocol.isInEnable() && staProtocol.isLoading() && staProtocol.isPakMk() && !staProtocol.isEmptyMk()) { |
| | | Integer backSta = findBackSta(devp, siteNo); |
| | | if (backSta != null) { |
| | | log.info("【输送线报警退回】站点:{},工作号:{},报警:{},退回站:{}", siteNo, workNo, plcErr, backSta); |
| | | // 推送到LED显示报警信息 |
| | | Integer ledId = findLedId(devp, siteNo); |
| | | if (ledId != null) { |
| | | MessageQueue.offer(SlaveType.Led, ledId, new Task(3, plcErr)); |
| | | } |
| | | // 设置退回站 |
| | | staProtocol.setWorkNo(9999); |
| | | staProtocol.setStaNo(backSta.shortValue()); |
| | | devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | | boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | | if (!result) { |
| | | News.error("输送线报警退回失败,站点:{},工作号:{}", siteNo, workNo); |
| | | } else { |
| | | log.info("【输送线报警退回】成功下发退回指令,站点:{},工作号:{},退回站:{}", siteNo, workNo, backSta); |
| | | } |
| | | } else { |
| | | log.warn("【输送线报警退回】未找到退回站配置,站点:{},工作号:{}", siteNo, workNo); |
| | | } |
| | | } |
| | | } |
| | | } else { |
| | |
| | | } |
| | | |
| | | /** |
| | | * 根据站点号查找退回站 |
| | | */ |
| | | private Integer findBackSta(DevpSlave devp, Integer siteNo) { |
| | | // 查找入库站 |
| | | for (DevpSlave.Sta inSta : devp.getInSta()) { |
| | | if (inSta.getStaNo().equals(siteNo)) { |
| | | return inSta.getBackSta(); |
| | | } |
| | | } |
| | | // 查找拣料站 |
| | | for (DevpSlave.Sta pickSta : devp.getPickSta()) { |
| | | if (pickSta.getStaNo().equals(siteNo)) { |
| | | return pickSta.getBackSta(); |
| | | } |
| | | } |
| | | // 查找空板入库站 |
| | | for (DevpSlave.Sta emptyInSta : devp.getEmptyInSta()) { |
| | | if (emptyInSta.getStaNo().equals(siteNo)) { |
| | | return emptyInSta.getBackSta(); |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 根据站点号查找LED ID |
| | | */ |
| | | private Integer findLedId(DevpSlave devp, Integer siteNo) { |
| | | // 查找入库站 |
| | | for (DevpSlave.Sta inSta : devp.getInSta()) { |
| | | if (inSta.getStaNo().equals(siteNo)) { |
| | | return inSta.getLed(); |
| | | } |
| | | } |
| | | // 查找拣料站 |
| | | for (DevpSlave.Sta pickSta : devp.getPickSta()) { |
| | | if (pickSta.getStaNo().equals(siteNo)) { |
| | | return pickSta.getLed(); |
| | | } |
| | | } |
| | | // 查找空板入库站 |
| | | for (DevpSlave.Sta emptyInSta : devp.getEmptyInSta()) { |
| | | if (emptyInSta.getStaNo().equals(siteNo)) { |
| | | return emptyInSta.getLed(); |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * RGV异常检测和托盘退回 |
| | | */ |
| | | public synchronized void recRgvErr() { |
| | | Date now = new Date(); |
| | | for (RgvSlave rgv : slaveProperties.getRgv()) { |
| | | RgvThread rgvThread = (RgvThread) SlaveConnection.get(SlaveType.Rgv, rgv.getId()); |
| | | if (rgvThread == null) { |
| | | continue; |
| | | } |
| | | RgvProtocol rgvProtocol = rgvThread.getRgvProtocol(); |
| | | if (rgvProtocol == null) { |
| | | continue; |
| | | } |
| | | |
| | | // 检测RGV报警 |
| | | Short alarm = rgvProtocol.getAlarm(); |
| | | Short taskNo1 = rgvProtocol.getTaskNo1(); |
| | | |
| | | // 如果有报警且有任务 |
| | | if (alarm != null && alarm > 0 && taskNo1 != null && taskNo1 > 0 && taskNo1 <= 9000) { |
| | | Integer workNo = taskNo1.intValue(); |
| | | WrkMast wrkMast = wrkMastMapper.selectById(workNo); |
| | | if (wrkMast == null) { |
| | | log.warn("【RGV报警处理】工作档不存在,RGV:{},工作号:{}", rgv.getId(), workNo); |
| | | continue; |
| | | } |
| | | |
| | | // 获取报警信息 |
| | | BasRgvErr rgvErr = basRgvErrMapper.selectById(alarm.longValue()); |
| | | String alarmMsg = rgvErr != null ? rgvErr.getErrName() : "未知异常(" + alarm + ")"; |
| | | |
| | | log.info("【RGV报警处理】RGV:{},工作号:{},报警:{}", rgv.getId(), workNo, alarmMsg); |
| | | |
| | | // 根据工作档的源站点查找对应的输送线站点和退回站 |
| | | Integer sourceStaNo = wrkMast.getStaNo(); // 源站点(目标站) |
| | | if (sourceStaNo == null) { |
| | | log.warn("【RGV报警处理】工作档源站点为空,RGV:{},工作号:{}", rgv.getId(), workNo); |
| | | continue; |
| | | } |
| | | |
| | | // 查找对应的输送线配置和退回站 |
| | | Integer backSta = null; |
| | | Integer finalDevpId = null; |
| | | Integer siteNo = null; |
| | | DevpThread devpThread = null; |
| | | DevpSlave targetDevp = null; |
| | | |
| | | // 遍历所有输送线,查找包含该站点的配置 |
| | | for (DevpSlave devp : slaveProperties.getDevp()) { |
| | | DevpThread dt = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId()); |
| | | if (dt == null) { |
| | | continue; |
| | | } |
| | | Map<Integer, StaProtocol> station = dt.getStation(); |
| | | if (station != null && station.containsKey(sourceStaNo)) { |
| | | // 找到对应的输送线站点 |
| | | backSta = findBackSta(devp, sourceStaNo); |
| | | if (backSta != null) { |
| | | finalDevpId = devp.getId(); |
| | | siteNo = sourceStaNo; |
| | | devpThread = dt; |
| | | targetDevp = devp; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (backSta != null && devpThread != null && siteNo != null && finalDevpId != null) { |
| | | StaProtocol staProtocol = devpThread.getStation().get(siteNo); |
| | | if (staProtocol != null && staProtocol.isInEnable() && staProtocol.isLoading() && staProtocol.isPakMk() && !staProtocol.isEmptyMk()) { |
| | | log.info("【RGV报警退回】RGV:{},工作号:{},报警:{},站点:{},退回站:{}", rgv.getId(), workNo, alarmMsg, siteNo, backSta); |
| | | |
| | | // 推送到LED显示报警信息 |
| | | Integer ledId = findLedId(targetDevp, siteNo); |
| | | if (ledId != null) { |
| | | MessageQueue.offer(SlaveType.Led, ledId, new Task(3, "RGV报警:" + alarmMsg)); |
| | | } |
| | | |
| | | // 设置退回站 |
| | | staProtocol.setWorkNo(9999); |
| | | staProtocol.setStaNo(backSta.shortValue()); |
| | | devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | | boolean result = MessageQueue.offer(SlaveType.Devp, finalDevpId, new Task(2, staProtocol)); |
| | | if (!result) { |
| | | News.error("RGV报警退回失败,RGV:{},站点:{},工作号:{}", rgv.getId(), siteNo, workNo); |
| | | } else { |
| | | log.info("【RGV报警退回】成功下发退回指令,RGV:{},站点:{},工作号:{},退回站:{}", rgv.getId(), siteNo, workNo, backSta); |
| | | } |
| | | } else { |
| | | log.debug("【RGV报警退回】站点状态不符合退回条件,RGV:{},站点:{},工作号:{},inEnable:{},loading:{},pakMk:{},emptyMk:{}", |
| | | rgv.getId(), siteNo, workNo, |
| | | staProtocol != null ? staProtocol.isInEnable() : false, |
| | | staProtocol != null ? staProtocol.isLoading() : false, |
| | | staProtocol != null ? staProtocol.isPakMk() : false, |
| | | staProtocol != null ? staProtocol.isEmptyMk() : false); |
| | | } |
| | | } else { |
| | | log.warn("【RGV报警退回】未找到对应的输送线站点或退回站配置,RGV:{},工作号:{},源站点:{}", rgv.getId(), workNo, sourceStaNo); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 出库 ===>> 工作档信息写入led显示器 |
| | | */ |
| | | public synchronized void ledExecute() { |