| | |
| | | import org.springframework.transaction.interceptor.TransactionAspectSupport; |
| | | import springfox.documentation.spring.web.json.Json; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | |
| | |
| | | errMsg = errMsg + "扫码失败"; |
| | | back = true; |
| | | } |
| | | // 退回 |
| | | if (back) { |
| | | // led 异常显示 |
| | | LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed()); |
| | | if (ledThread != null) { |
| | | MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errMsg)); |
| | | } |
| | | continue; |
| | | } |
| | | String barcode = barcodeThread.getBarcode(); |
| | | if (!Cools.isEmpty(barcode) && !barcode.equals("00000000")) { |
| | | log.info("{}号条码扫描器检测条码信息:{}", inSta.getBarcode(), barcode); |
| | | if ("NG".endsWith(barcode) || "NoRead".equals(barcode)) { |
| | | continue; |
| | | } |
| | | } else { |
| | | // led 异常显示 |
| | | // LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed()); |
| | | // if (ledThread != null) { |
| | | // String errorMsg = "扫码失败,请重试"; |
| | | // MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errorMsg)); |
| | | // } |
| | | continue; |
| | | } |
| | | |
| | | if (staProtocol.isAutoing() && staProtocol.isLoading() |
| | | && staProtocol.isInEnable() |
| | | && !staProtocol.isEmptyMk() && (staProtocol.getWorkNo() >= 9992 && staProtocol.getWorkNo() <= 9999) |
| | | && !staProtocol.isEmptyMk() && (staProtocol.getWorkNo() >= 9990 && staProtocol.getWorkNo() <= 9999) |
| | | && staProtocol.isPakMk()) {// && !Cools.isEmpty(barcode)) { |
| | | |
| | | // if(Cools.isEmpty(barcode) || "NG".endsWith(barcode) || "NoRead".equals(barcode)) { |
| | | // log.info("{}号条码扫描器检测条码信息:{}", inSta.getBarcode(), barcode); |
| | | // //条码为空或者不符合,退库到172站点 |
| | | // staProtocol.setWorkNo((short)9999); |
| | | // staProtocol.setStaNo((short)172); |
| | | // devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | | // boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | | // if (!result) { |
| | | // throw new CoolException("更新plc站点信息失败"); |
| | | // } |
| | | // continue; |
| | | // } |
| | | |
| | | // 退回 |
| | | if (back ||(!Cools.isEmpty(barcode) && barcode.equals("00000000"))) { |
| | | staProtocol.setWorkNo((short) 9999); |
| | | staProtocol.setStaNo(inSta.getBackSta().shortValue()); |
| | | devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | | boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | | |
| | | // led 异常显示 |
| | | LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed()); |
| | | if (ledThread != null) { |
| | | MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errMsg)); |
| | | } |
| | | continue; |
| | | } |
| | | |
| | | // 判断重复工作档 |
| | | WrkMast wrkMast = wrkMastMapper.selectPakInStep1(inSta.getStaNo(), barcode); |
| | | if (wrkMast != null) { |
| | | News.error("工作档中已存在该站状态为( 2.设备上走 )的数据,工作号={}", wrkMast.getWrkNo()); |
| | | continue; |
| | | } |
| | | // 获取入库通知档 |
| | | List<WaitPakin> waitPakins = waitPakinMapper.selectList(new EntityWrapper<WaitPakin>().eq("zpallet", barcode).eq("io_status", "N")); |
| | | if (waitPakins.isEmpty()) { |
| | | log.error("无此入库条码数据。条码号={}", barcode); |
| | | continue; |
| | | } |
| | | |
| | |
| | | param.setIoType(1); |
| | | param.setSourceStaNo(inSta.getStaNo()); |
| | | param.setLocType1(locTypeDto.getLocType1()); |
| | | // param.setPackNo(pack); |
| | | String response = new HttpHandler.Builder() |
| | | .setUri(wmsUrl) |
| | | .setPath("/rpc/pakin/loc/v1") |
| | |
| | | staProtocol = staProtocol.clone(); |
| | | } |
| | | |
| | | // // 入出库模式判断 |
| | | // if (devpThread.ioMode != IoModeType.PAKOUT_MODE) { continue; } |
| | | |
| | | // 查询站点详细信息 |
| | | BasDevp staDetl = basDevpService.selectById(crnStn.getStaNo()); |
| | | if (staDetl == null) { |
| | |
| | | // 判断堆垛机出库站状态 |
| | | if (staProtocol.isAutoing() && !staProtocol.isLoading() && staDetl.getCanouting() != null && staDetl.getCanouting().equals("Y") |
| | | && staProtocol.getWorkNo() == 0 && staProtocol.isOutEnable()) { |
| | | //测试库位出库必须要按启动按钮才能出库 |
| | | if ((wrkMast.getStaNo() == 206 || wrkMast.getStaNo() == 1000) && locMast.getCtnKind() == 0) { |
| | | News.error("出库 ===>> 等待启动出库按钮", wrkMast); |
| | | continue; |
| | | } |
| | | // 命令下发区 -------------------------------------------------------------------------- |
| | | |
| | | // 堆垛机控制过滤 |
| | |
| | | WrkMast wrkMast = null; |
| | | if (Cools.isEmpty(wrkMasts)) { |
| | | return; |
| | | }else { |
| | | wrkMast = wrkMasts.get(0); |
| | | } |
| | | //先查测试库位转OK或者NG库位按了按钮的 |
| | | for (WrkMast wm : wrkMasts) { |
| | | LocMast sourceSta1 = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", wm.getSourceLocNo())); |
| | | if (!Cools.isEmpty(sourceSta1.getCtnKind())) { |
| | | if (sourceSta1.getCtnKind() == 1) { |
| | | wrkMast = wm; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | //后查等待库位转测试库位 |
| | | if (Cools.isEmpty(wrkMast)) { |
| | | for (WrkMast wm : wrkMasts) { |
| | | LocMast sourceSta1 = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", wm.getSourceLocNo())); |
| | | if (sourceSta1.getLocType1() == 3) { |
| | | wrkMast = wm; |
| | | } |
| | | } |
| | | } |
| | | //都没有满足条件的,跳过移库 |
| | | if (Cools.isEmpty(wrkMast)) { |
| | | return; |
| | | } |
| | | // //后查等待库位转测试库位 |
| | | // if (Cools.isEmpty(wrkMast)) { |
| | | // for (WrkMast wm : wrkMasts) { |
| | | // LocMast sourceSta1 = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", wm.getSourceLocNo())); |
| | | // if (sourceSta1.getLocType1() == 3) { |
| | | // wrkMast = wm; |
| | | // } |
| | | // } |
| | | // } |
| | | // //都没有满足条件的,跳过移库 |
| | | // if (Cools.isEmpty(wrkMast)) { |
| | | // return; |
| | | // } |
| | | |
| | | // 获取源库位信息 |
| | | LocMast sourceSta = locMastService.selectById(wrkMast.getSourceLocNo()); |
| | |
| | | * 出库 ===>> 工作档信息写入led显示器 |
| | | */ |
| | | @Async |
| | | public synchronized void ledExecute() { |
| | | public synchronized void ledExecute(Integer mark) { |
| | | |
| | | for (LedSlave led : slaveProperties.getLed()) { |
| | | // 获取输送线plc线程 |
| | | DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, led.getDevpPlcId()); |
| | |
| | | for (Integer staNo : led.getStaArr()) { |
| | | // 获取叉车站点 |
| | | StaProtocol staProtocol = devpThread.getStation().get(staNo); |
| | | if (null == staProtocol || null == staProtocol.getWorkNo() || 0 == staProtocol.getWorkNo()) { |
| | | if (null == staProtocol || null == staProtocol.getWorkNo() || 0 == staProtocol.getWorkNo() || !staProtocol.isLoading()) { |
| | | continue; |
| | | } else { |
| | | staProtocol = staProtocol.clone(); |
| | | } |
| | | // 获取工作档数据 |
| | | WrkMast wrkMast = wrkMastMapper.selectById(staProtocol.getWorkNo()); |
| | | // if (null == wrkMast || wrkMast.getWrkSts() < 14 || wrkMast.getIoType() < 100) { continue; } |
| | | if (null == wrkMast) { |
| | | continue; |
| | | } |
| | | log.info(""+mark+" - 0"+" - 开始执行:出库 ===>> 工作档信息写入led显示器"); |
| | | wrkMasts.add(wrkMast); |
| | | // 组装命令 |
| | | LedCommand ledCommand = new LedCommand(); |
| | |
| | | ledCommand.setEmptyMk(true); |
| | | break; |
| | | default: |
| | | News.error("任务入出库类型错误!!![工作号:{}] [入出库类型:{}]", wrkMast.getWrkNo(), wrkMast.getIoType()); |
| | | News.error(""+mark+" - 1"+" - 任务入出库类型错误!!![工作号:{}] [入出库类型:{}]", wrkMast.getWrkNo(), wrkMast.getIoType()); |
| | | break; |
| | | } |
| | | ledCommand.setSourceLocNo(wrkMast.getSourceLocNo()); |
| | | ledCommand.setLocNo(wrkMast.getLocNo()); |
| | | ledCommand.setStaNo(wrkMast.getStaNo()); |
| | | ledCommand.setBarcode(wrkMast.getBarcode()); |
| | | // ledCommand.setSourceStaNo(wrkMast.getSourceStaNo()); |
| | | if (wrkMast.getIoType() != 110 && wrkMast.getIoType() != 10) { |
| | | List<WrkDetl> wrkDetls = wrkDetlService.findByWorkNo(wrkMast.getWrkNo()); |
| | | |
| | | wrkDetls.forEach(wrkDetl -> { |
| | | Double total = 0.0; |
| | | EntityWrapper<LocDetl> wrapper = new EntityWrapper<>(); |
| | | LocDetl locDetl = locDetlService.selectOne(wrapper.eq("zpallet", wrkDetl.getZpallet()).eq("matnr", wrkDetl.getMatnr())); |
| | | if (Cools.isEmpty(locDetl)) { |
| | | total = wrkDetl.getAnfme(); |
| | | } else { |
| | | total = locDetl.getAnfme(); |
| | | } |
| | | if (wrkMast.getIoType() == 101 || wrkMast.getIoType() == 1) { |
| | | ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getBatch(), wrkDetl.getSpecs(), wrkDetl.getManu(), wrkDetl.getMemo(), wrkDetl.getAnfme(), total)); |
| | | } |
| | | if (wrkMast.getIoType() == 103 && (null == wrkDetl.getInspect() || 0 == wrkDetl.getInspect())) { |
| | | ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getBatch(), wrkDetl.getSpecs(), wrkDetl.getManu(), wrkDetl.getMemo(), wrkDetl.getAnfme(), total)); |
| | | } |
| | | if (wrkMast.getIoType() == 107 || wrkMast.getIoType() == 104) { |
| | | ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getBatch(), wrkDetl.getSpecs(), wrkDetl.getManu(), wrkDetl.getMemo(), wrkDetl.getAnfme(), total)); |
| | | } |
| | | }); |
| | | wrkDetls.forEach(wrkDetl -> ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getAnfme(),wrkDetl.getSpecs()))); |
| | | } |
| | | commands.add(ledCommand); |
| | | } |
| | | if (Cools.isEmpty(wrkMasts)) { |
| | | continue; |
| | | } |
| | | Set<Integer> workNos = wrkMasts.stream().map(WrkMast::getWrkNo).collect(Collectors.toSet()); |
| | | // 获取LED线程 |
| | |
| | | if (CollectionUtils.equals(ledThread.getWorkNos(), workNos)) { |
| | | continue; |
| | | } |
| | | // 命令下发 ------------------------------------------------------------------------------- |
| | | // if (!commands.isEmpty()) { |
| | | // if (led.getId() < 7) { |
| | | // if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(3, commands))) { |
| | | // News.error(""+mark+" - 2"+" - {}号LED命令下发失败!!![ip:{}] [port:{}]", led.getId(), led.getIp(), led.getPort()); |
| | | // continue; |
| | | // } else { |
| | | // ledThread.setLedMk(false); |
| | | // } |
| | | // } else { |
| | | // if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(1, commands))) { |
| | | // News.error(""+mark+" - 3"+" - {}号LED命令下发失败!!![ip:{}] [port:{}]", led.getId(), led.getIp(), led.getPort()); |
| | | // continue; |
| | | // } else { |
| | | // ledThread.setLedMk(false); |
| | | // } |
| | | // } |
| | | // |
| | | // } |
| | | // 命令下发 ------------------------------------------------------------------------------- |
| | | if (!commands.isEmpty()) { |
| | | if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(1, commands))) { |
| | | News.error("{}号LED显示内容命令下发失败!!![ip:{}] [port:{}]", led.getId(), led.getIp(), led.getPort()); |
| | | if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(3, commands))) { |
| | | News.error("{}号LED命令下发失败!!![ip:{}] [port:{}]", led.getId(), led.getIp(), led.getPort()); |
| | | continue; |
| | | }else { |
| | | ledThread.setLedMk(false); |
| | | } |
| | | } |
| | | |
| | |
| | | wrkMast.setOveMk("Y"); |
| | | wrkMast.setModiTime(new Date()); |
| | | if (wrkMastMapper.updateById(wrkMast) == 0) { |
| | | log.error(""+mark+" - 4"+" - 更新工作档失败"); |
| | | throw new CoolException("更新工作档失败"); |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | } |
| | | log.info(""+mark+" - 0"+" - 出库 ===>> 工作档信息写入led显示器执行完成"); |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 入出库模式切换函数 |
| | | */ |
| | | public void ioConvert() { |
| | | try { |
| | | // 根据输送线plc遍历 |
| | | for (DevpSlave devp : slaveProperties.getDevp()) { |
| | | SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId()); |
| | | |
| | | WrkMast pakout = wrkMastMapper.selectWorkingPakout(); |
| | | if (pakout != null) { |
| | | if (devpThread.ioMode != IoModeType.PAKOUT_MODE) { |
| | | // 出库切换中 |
| | | devpThread.ioMode = IoModeType.PAKOUT_BOOTING; |
| | | |
| | | WrkMast pakin = wrkMastMapper.selectWorkingPakin(); |
| | | if (pakin == null) { |
| | | // 出库模式 |
| | | devpThread.ioMode = IoModeType.PAKOUT_MODE; |
| | | } |
| | | } |
| | | } else { |
| | | // 入库模式 |
| | | devpThread.ioMode = IoModeType.PAKIN_MODE; |
| | | } |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | public void outOfDevp() { |
| | | List<WrkMast> wrkMasts = wrkMastMapper.selectPick(); |
| | | for (WrkMast wrkMast : wrkMasts) { |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 根据PLC按钮测试、完成、暂停信号,更新testMast表中status值,交由WMS系统处理 |
| | | */ |
| | | @Transactional |
| | | public void packTest() { |
| | | try { |
| | | // 根据输送线plc遍历 |
| | | for (DevpSlave devp : slaveProperties.getDevp()) { |
| | | SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId()); |
| | | if (null != devpThread) { |
| | | for (int i = 0; i < 48; i++) { |
| | | int olsStatus = 0;//testMast表原来status数据状态 |
| | | int newStatus = 0;//testMast表待修改的status数据状态 |
| | | short newSingle = 0; //PLC地址待修改的新值 |
| | | switch (devpThread.startSignal[i][0]) {//根据信号查找testMast表中对应状态条件,olsStatus,newStatus根据实际流程调整 |
| | | case 0://初始状态,入库 |
| | | olsStatus = 1;//待测 |
| | | newStatus = 1;//待测 |
| | | newSingle = 1;//库存有资料,寄存器地址,0===>>1 |
| | | break; |
| | | case 2://启动复核信号 |
| | | olsStatus = 1;//待测 |
| | | newStatus = 2;//复核中 |
| | | newSingle = 3;//测试复核,寄存器地址,2===>>3 |
| | | break; |
| | | case 3://测试完成 |
| | | olsStatus = 4;//测试完成 |
| | | newStatus = 4;//测试完成 |
| | | newSingle = 4;//(NG:4\OK:41)测试完成,寄存器地址,3===>>4\41 |
| | | break; |
| | | case 5://NG测试信号 |
| | | case 6://完成测试信号 |
| | | case 22://完成测试信号 |
| | | olsStatus = 4;//测试完成 |
| | | newStatus = 5;//已移库 |
| | | newSingle = 0;//启动移库,寄存器地址清零,5/6===>>0 |
| | | break; |
| | | case 7://暂停信号 |
| | | olsStatus = 99;//plc给出暂停信号 |
| | | newStatus = 0;//WCS收到暂停信号后,更新testMast |
| | | newSingle = 8;//暂停测试,寄存器地址,7===>>8 |
| | | break; |
| | | case 9://紧急出库确认充电线已经拔出 |
| | | olsStatus = 99;//plc给出暂停信号 |
| | | newStatus = 0;//WCS收到暂停信号后,更新testMast |
| | | newSingle = 8;//暂停测试,寄存器地址,9===>>8 |
| | | break; |
| | | case 10://解除暂停信号 |
| | | olsStatus = 0;//plc给出暂停信号 |
| | | newStatus = 1;//WCS收到暂停信号后,更新testMast |
| | | newSingle = 0;//暂停测试,寄存器地址,10===>>0/11 |
| | | break; |
| | | case 12://紧急出库确认充电线已经拔出 |
| | | newSingle = 11;//暂停测试,寄存器地址,12===>>11 |
| | | break; |
| | | case 13://入库前判断充电线是否放好 |
| | | newSingle = 14;//禁用库位,寄存器地址,13===>>14 |
| | | break; |
| | | case 15://充电线放好 |
| | | newSingle = 0;//复位,寄存器地址,12===>>0 |
| | | break; |
| | | default: |
| | | log.info("读取通道" + (i + 1) + "测试库位按钮信号:为" + devpThread.startSignal[i][0]); |
| | | continue; |
| | | } |
| | | |
| | | TestMast testMast = testMastService.selectOne(new EntityWrapper<TestMast>() |
| | | .eq("channel", (i + 1)).eq("status", olsStatus));//查找原来的状态 |
| | | LocMast locMast = null; |
| | | boolean sign = false; |
| | | switch (devpThread.startSignal[i][0]) { |
| | | case 0: |
| | | if (!Cools.isEmpty(testMast)) { |
| | | locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("channel", (i + 1))); |
| | | if (!Cools.isEmpty(locMast) && locMast.getLocSts().equals("F")) { |
| | | sign = true; |
| | | } |
| | | } |
| | | break; |
| | | case 3: |
| | | if (!Cools.isEmpty(testMast)) { |
| | | locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("channel", (i + 1))); |
| | | if (!Cools.isEmpty(locMast) && locMast.getLocSts().equals("F")) { |
| | | sign = true; |
| | | if (locMast.getPackStatus() == 3) {//测试完成 |
| | | newSingle = 41; |
| | | } else if (locMast.getPackStatus() == 4) {//测试失败 |
| | | newSingle = 4; |
| | | } else { |
| | | log.info("读取通道" + (i + 1) + "测试库位按钮信号:为" + devpThread.startSignal[i][0] + "通道库位pack状态信息异常" + locMast.getPackStatus()); |
| | | sign = false; |
| | | } |
| | | } |
| | | } |
| | | break; |
| | | case 5: |
| | | case 6: |
| | | if (!Cools.isEmpty(testMast)) { |
| | | locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("channel", (i + 1))); |
| | | if (!Cools.isEmpty(locMast) && locMast.getLocSts().equals("F")) { |
| | | if (devpThread.startSignal[i][0] == 5 && locMast.getPackStatus() == 4) { |
| | | sign = true; |
| | | } else if (devpThread.startSignal[i][0] == 6 && locMast.getPackStatus() == 3) { |
| | | sign = true; |
| | | } else { |
| | | log.error("测试完成移库时按下完成按钮与测试结果不一致===>>[channel:{}", i + 1); |
| | | } |
| | | } else { |
| | | log.error("测试完成移库时未查询到测试档案===>>[channel:{}", i + 1); |
| | | } |
| | | } |
| | | break; |
| | | case 2: |
| | | if (!Cools.isEmpty(testMast)) { |
| | | testMast.setStatus(newStatus); |
| | | testMast.setModiTime(new Date()); |
| | | if (!testMastService.update(testMast, new EntityWrapper<TestMast>().eq("channel", (i + 1)).eq("barcode", testMast.getBarcode()))) { |
| | | throw new CoolException("更新产品测试状态失败"); |
| | | } else { |
| | | sign = true; |
| | | } |
| | | } else { |
| | | log.error("启动测试时未查询到测试档案===>>[channel:{}", i + 1); |
| | | } |
| | | break; |
| | | case 7: |
| | | SearchLocParam param = new SearchLocParam(); |
| | | param.setBarcode(i + 1 + ""); |
| | | String response = new HttpHandler.Builder() |
| | | .setUri(wmsUrl) |
| | | .setPath("/mobile/test/suspend/auth") |
| | | .setJson(JSON.toJSONString(param)) |
| | | .build() |
| | | .doPost(); |
| | | JSONObject jsonObject = JSON.parseObject(response); |
| | | if (jsonObject.getInteger("code").equals(200)) { |
| | | testMast = testMastService.selectOne(new EntityWrapper<TestMast>().eq("channel", (i + 1))); |
| | | testMast.setStatus(newStatus); |
| | | testMast.setModiTime(new Date()); |
| | | if (!testMastService.update(testMast, new EntityWrapper<TestMast>().eq("channel", (i + 1)).eq("barcode", testMast.getBarcode()))) { |
| | | log.error("更新产品测试状态失败"); |
| | | } |
| | | sign = true; |
| | | } else { |
| | | log.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/mobile/test/suspend/auth", JSON.toJSONString(param), response); |
| | | } |
| | | break; |
| | | case 9: |
| | | case 12: |
| | | locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("channel", (i + 1))); |
| | | if (!Cools.isEmpty(locMast) && locMast.getLocSts().equals("F") || locMast.getLocSts().equals("D")) { |
| | | locMast.setPackStatus(8); //8.紧急出库 |
| | | if (locMastService.update(locMast, new EntityWrapper<LocMast>().eq("channel", (i + 1)))) { |
| | | log.info("库位:{},紧急出库!", locMast.getLocNo()); |
| | | } |
| | | } else { |
| | | log.error("库位不是在库状态,无需紧急出库!"); |
| | | } |
| | | sign = true; |
| | | break; |
| | | case 10: |
| | | if (!Cools.isEmpty(testMast)) { |
| | | locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("channel", (i + 1))); |
| | | if (!Cools.isEmpty(locMast) && locMast.getLocSts().equals("F")) { |
| | | if (locMast.getFireStatus().equals(1)) { |
| | | newSingle = 11; |
| | | } else { |
| | | testMast.setStatus(newStatus); |
| | | testMast.setModiTime(new Date()); |
| | | if (!testMastService.update(testMast, new EntityWrapper<TestMast>().eq("channel", (i + 1)).eq("barcode", testMast.getBarcode()))) { |
| | | throw new CoolException("更新产品测试状态失败"); |
| | | } else { |
| | | sign = true; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | sign = true; |
| | | break; |
| | | case 13: |
| | | locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("channel", (i + 1))); |
| | | if (locMast.getLocSts().equals("O")) { |
| | | locMast.setLocSts("X"); |
| | | locMastService.update(locMast, new EntityWrapper<LocMast>().eq("channel", (i + 1))); |
| | | } |
| | | sign = true; |
| | | break; |
| | | case 15: |
| | | locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("channel", (i + 1))); |
| | | if (locMast.getLocSts().equals("X")) { |
| | | locMast.setLocSts("O"); |
| | | locMastService.update(locMast, new EntityWrapper<LocMast>().eq("channel", (i + 1))); |
| | | } |
| | | sign = true; |
| | | break; |
| | | default: |
| | | log.info("读取通道" + (i + 1) + "测试库位按钮信号:为" + devpThread.startSignal[i][0]); |
| | | continue; |
| | | } |
| | | if (sign) { |
| | | boolean result = messageQueueOffer(i, newSingle, SlaveType.Devp, devp.getId()); |
| | | if (!result) { |
| | | log.error("更新测试信号失败===>>[channel:{},locNo:{},barcode:{}]", i + 1, testMast.getLocNo(), testMast.getBarcode()); |
| | | } else { |
| | | devpThread.startSignal[i][0] = newSingle; |
| | | } |
| | | } |
| | | try { |
| | | locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("channel", (i + 1))); |
| | | if (devpThread.startSignal[i][1] != locMast.getFireStatus()) { |
| | | messageQueueOffer2(i + 1, (short) ((int) locMast.getFireStatus()), SlaveType.Devp, devp.getId()); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("火警 ===>> 给输送线发送警报失败,通道号:", i + 1); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("启动测试 ===>> 启动测试失败", e); |
| | | e.printStackTrace(); |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | } |
| | | } |
| | | |
| | | public boolean messageQueueOffer(int i, short newSingle, SlaveType devp, Integer id) { |
| | | //复位PLC信号,借用输送站点实体类 |
| | |
| | | } |
| | | |
| | | /** |
| | | * 将火警报警信号写入到堆垛机PLC中 |
| | | */ |
| | | @Transactional |
| | | public void fierCrn() { |
| | | try { |
| | | for (CrnSlave crn : slaveProperties.getCrn()) { |
| | | if (crn.getId() != 1) { |
| | | continue; |
| | | } |
| | | // 获取堆垛机信息 |
| | | CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crn.getId()); |
| | | CrnProtocol crnProtocol = crnThread.getCrnProtocol(); |
| | | LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("fire_status", 1)); |
| | | if (!Cools.isEmpty(locMast)) { |
| | | //报警信号写入1 |
| | | if (!MessageQueue.offer(SlaveType.Crn, 1, new Task(4, 1))) { |
| | | News.error("火警 ===>> 给堆垛机发送报警信号失败"); |
| | | } |
| | | News.error("火警!!!!!!! ===>> 给堆垛机发送报警信号成功"); |
| | | } else { |
| | | //报警信号没有后,复位地址 |
| | | if (!MessageQueue.offer(SlaveType.Crn, 1, new Task(4, 0))) { |
| | | News.error("火警 ===>> 给堆垛机清零复位报警信号失败"); |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | News.error("火警 ===>> 给堆垛机发送警报失败", e); |
| | | e.printStackTrace(); |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 103站点有物下发pack码 |
| | | */ |
| | | @Transactional |
| | | public void packDevp() { |
| | | try { |
| | | // 根据输送线plc遍历 |
| | | for (DevpSlave devp : slaveProperties.getDevp()) { |
| | | BasDevp basDevp = basDevpService.selectOne(new EntityWrapper<BasDevp>().eq("dev_no", 103)); |
| | | if (Cools.isEmpty(basDevp)) { |
| | | News.error("103站点查询失败-MainServiceImpl.java-2255行"); |
| | | } |
| | | if (basDevp.getAutoing().equals("Y") && basDevp.getWrkNo() > 0 && basDevp.getLoading().equals("Y")) { |
| | | WrkDetl wrkDetl = wrkDetlService.devpPackNo(basDevp.getWrkNo()); |
| | | if (Cools.isEmpty(wrkDetl)) { |
| | | News.error("103站点查询失败-MainServiceImpl.java-2255行"); |
| | | } |
| | | MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(4, wrkDetl.getMatnr())); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | News.error("103 ===>> 给输送线发送Pack码失败", e); |
| | | e.printStackTrace(); |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 根据PLC按钮测试、完成、暂停信号,更新testMast表中status值,交由WMS系统处理 |
| | | * 更新PLC库位状态、更新库位启动状态 |
| | | */ |
| | | @Transactional |
| | | public void packTest1() { |
| | | try { |
| | | // 根据输送线plc遍历 |
| | | for (DevpSlave devp : slaveProperties.getDevp()) { |
| | | log.info("2363行程序开始运行"); |
| | | SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId()); |
| | | if (null != devpThread) { |
| | | for (int i = 0; i < 48; i++) { |
| | | // log.info("2367行程序开始运行,第"+i+"次"); |
| | | boolean fig = false; |
| | | if(null != devpThread){ |
| | | //devpThread.startSignal[i][0] |
| | | //0:空闲,1:待测,2:测试中;3.测试完成;4.测试失败; |
| | | |
| | | //locMast.setPackStatus |
| | | // "产品状态{0:空闲,1:待测,2:测试中;3.测试完成;4.测试失败;}" |
| | | |
| | | //testMast.setStatus |
| | | //"状态 0: 无货 1: 等待测试 2:测试中 3.测试完成;4.测试失败; " |
| | | for (int i = 0; i < 24; i++){ |
| | | //查询在库和预约出库 |
| | | LocMast locMast = locMastService.selectztgx("F", "R", i); |
| | | if (!Cools.isEmpty(locMast)) { |
| | | // log.info("2372行程序开始运行,查询测试档"); |
| | | TestMast testMast = testMastService.selectOne(new EntityWrapper<TestMast>() |
| | | .eq("loc_no", locMast.getLocNo()) |
| | | .eq("user_id", locMast.getBarcode())); |
| | | if (Cools.isEmpty(testMast)) { |
| | | LocMast locMast=locMastService.selectOne(new EntityWrapper<LocMast>().eq("channel",i+1)); |
| | | if(!Cools.isEmpty(locMast)){ |
| | | if (locMast.getLocSts().equals("F")){ |
| | | TestMast testMast=testMastService.selectOne(new EntityWrapper<TestMast>() |
| | | .eq("loc_no",locMast.getLocNo()) |
| | | .eq("user_id",locMast.getBarcode())); |
| | | if(Cools.isEmpty(testMast)){ |
| | | // log.info("2377行程序开始运行,测试档为空,跳过"); |
| | | continue; |
| | | } |
| | | // log.info("2380行程序开始运行,测试档不为空,下一步"); |
| | | //devpThread.startSignal[i][0] |
| | | //0:空,1:启动中,2:工作中,3:自动暂停,4:正常完成(OK),5:异常停止(NG),6:在线,7:离线,8:空闲 |
| | | |
| | | //locMast.setPackStatus |
| | | // "产品状态{0:无,1:待测,2:测试中;3.测试完成;4.测试失败;5.静置中;6:静置完成;7:暂停测试;8:紧急出库;9:在线;10:离线;11:空闲;}" |
| | | |
| | | //testMast.setStatus |
| | | //"状态 0: 待申请 1: 申请中 2: 已复核 3:测试中 4:完成 5:移库 6:火警" |
| | | if (devpThread.startSignal[i][0] == 8) { |
| | | News.info("2390行程序开始运行,修改测试档状态为 1、申请中,开始修改前:" + JSON.toJSONString(testMast)); |
| | | testMast.setStatus(1); |
| | | locMast.setPackStatus(1); |
| | | testMast.setModiTime(new Date()); |
| | | log.info("2394行程序开始运行,修改测试档状态为 1、申请中,修改数据后、未更新" + JSON.toJSONString(testMast)); |
| | | } else if (devpThread.startSignal[i][0] == 2 && locMast.getPackStatus() != 2) { |
| | | News.info("2396行程序开始运行,修改测试档状态为 3、测试中,开始修改前:" + JSON.toJSONString(testMast)); |
| | | testMast.setStatus(3); |
| | | locMast.setPackStatus(2); |
| | | testMast.setModiTime(new Date()); |
| | | log.info("2400,修改测试档状态为 3、测试中,修改数据后、未更新" + JSON.toJSONString(testMast)); |
| | | //NG转OK需要还原源库位和目标库位状态,OK转NG 删除任务档 |
| | | WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>() |
| | | .eq("source_loc_no", locMast.getLocNo()) |
| | | .eq("wrk_sts", 11)); |
| | | News.info("2405,查询状态为生成出库id的测试完成(NG或OK)任务档," + JSON.toJSONString(wrkMast)); |
| | | if (!Cools.isEmpty(wrkMast)) { |
| | | if (wrkMast.getWrkSts() == 11) { |
| | | if (wrkMast.getIoType() == 11) { |
| | | log.info("2409,删除任务档为移库的," + JSON.toJSONString(wrkMast)); |
| | | LocMast locMast1 = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", wrkMast.getLocNo())); |
| | | locMast1.setLocSts("O"); |
| | | locMastService.update(locMast1, new EntityWrapper<LocMast>().eq("loc_no", wrkMast.getLocNo())); |
| | | } |
| | | wrkMastMapper.deleteById(wrkMast); |
| | | log.info("2415,删除工作档" + JSON.toJSONString(wrkMast) + JSON.toJSONString(locMast)); |
| | | locMast.setLocSts("F"); |
| | | log.info("2417,删除工作档" + JSON.toJSONString(wrkMast) + JSON.toJSONString(locMast)); |
| | | wrkDetlService.delete(new EntityWrapper<WrkDetl>().eq("wrk_no", wrkMast.getWrkNo())); |
| | | log.info("2419,删除工作明细" + wrkMast.getWrkNo()); |
| | | if (!locMastService.update(locMast, new EntityWrapper<LocMast>() |
| | | .eq("channel", i + 1))) { |
| | | log.error("2422修改测试库位状态失败" + locMast.getLocNo() + JSON.toJSONString(locMast)); |
| | | } else { |
| | | log.error("2424修改测试库位状态成功" + locMast.getLocNo() + JSON.toJSONString(locMast)); |
| | | fig = true; |
| | | } |
| | | } |
| | | } |
| | | } else if (devpThread.startSignal[i][0] == 3) { |
| | | locMast.setPackStatus(7); |
| | | testMast.setModiTime(new Date()); |
| | | } else if (devpThread.startSignal[i][0] == 4 && testMast.getStatus() != 4 && locMast.getFireStatus() != 1 && testMast.getStatus() != 6) { |
| | | locMast.setPackStatus(3); |
| | | testMast.setStatus(4); |
| | | testMast.setModiTime(new Date()); |
| | | testMastService.insertPackQualified(true, new Date(), testMast.getBarcode()); |
| | | } else if (devpThread.startSignal[i][0] == 5 && testMast.getStatus() != 4 && locMast.getFireStatus() != 1 && testMast.getStatus() != 6) { |
| | | locMast.setPackStatus(4); |
| | | testMast.setStatus(4); |
| | | testMast.setModiTime(new Date()); |
| | | testMastService.insertPackQualified(false, new Date(), testMast.getBarcode()); |
| | | } |
| | | // else if(devpThread.startSignal[i][0]==6||devpThread.startSignal[i][0]==7||devpThread.startSignal[i][0]==8){ |
| | | // locMast.setPackStatus(devpThread.startSignal[i][0]+3); |
| | | // } |
| | | //通道启动按钮状态,1:可以启动出库或者移库,0:不能启动出库或者移库 |
| | | locMast.setCtnKind(devpThread.startSignal[i][2]); |
| | | if (devpThread.startSignal[i][2] == 1) { |
| | | if (!locMastService.update(locMast, new EntityWrapper<LocMast>() |
| | | .eq("loc_sts", "R") |
| | | .eq("channel", i + 1))) { |
| | | News.error("修改启动按钮状态,测试库位状态失败" + locMast.getLocNo(), locMast); |
| | | } |
| | | } else if (!locMast.getLocSts().equals("R")) { |
| | | if (!fig) { |
| | | if (!locMastService.update(locMast, new EntityWrapper<LocMast>() |
| | | .eq("loc_sts", "F") |
| | | .eq("channel", i + 1))) { |
| | | News.error("修改测试库位状态失败" + locMast.getLocNo(), locMast); |
| | | } |
| | | } |
| | | if (!testMastService.update(testMast, new EntityWrapper<TestMast>() |
| | | .eq("loc_no", locMast.getLocNo()) |
| | | .eq("user_id", locMast.getBarcode()))) { |
| | | News.error("修改测试档状态失败" + locMast.getLocNo(), locMast); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | //当充放电库位为O空库位时 |
| | | //库位状态改为8空闲 |
| | | //给PLC写消防信号 |
| | | for (int i = 0; i < 48; i++) { |
| | | LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("channel", i + 1)); |
| | | TestMast testMast = testMastService.selectOne(new EntityWrapper<TestMast>() |
| | | .eq("loc_no", locMast.getLocNo()) |
| | | .eq("user_id", locMast.getBarcode())); |
| | | if ((locMast.getLocSts().equals("O") || locMast.getLocSts().equals("S")) && devpThread.startSignal[i][0] != 8) { |
| | | Thread.sleep(1000); |
| | | MessageQueue.offer(SlaveType.Devp, 1, new Task(6, locMast.getChannel() - 1)); |
| | | } |
| | | try { |
| | | if (locMast.getFireStatus() != devpThread.startSignal[i][1]) { |
| | | messageQueueOffer2(i, (short) ((int) locMast.getFireStatus()), SlaveType.Devp, devp.getId()); |
| | | if (Cools.isEmpty(testMast)) { |
| | | continue; |
| | | } |
| | | if (locMast.getFireStatus() == 1) { |
| | | testMast.setStatus(6);//火警 |
| | | if (!testMastService.update(testMast, new EntityWrapper<TestMast>() |
| | | .eq("loc_no", locMast.getLocNo()) |
| | | .eq("user_id", locMast.getBarcode()))) { |
| | | News.error("修改测试档状态失败" + locMast.getLocNo(), locMast); |
| | | HashMap<String,Short> hashMap=new HashMap<>(); |
| | | if(devpThread.startSignal[i][0]!=locMast.getPackStatus()){ |
| | | hashMap.put("locSts",locMast.getPackStatus().shortValue()); |
| | | hashMap.put("channel",(short)(i*2)); |
| | | MessageQueue.offer(SlaveType.Devp, 1, new Task(6,hashMap)); |
| | | } |
| | | //同步设备状态 |
| | | if(locMast.getPackStatus()!=testMast.getStatus()){ |
| | | testMast.setStatus(locMast.getPackStatus()); |
| | | testMastService.updateById(testMast); |
| | | } |
| | | if(devpThread.startSignal[i][1]!=locMast.getCtnKind()){ |
| | | locMast.setCtnKind(devpThread.startSignal[i][1]); |
| | | locMastService.updateById(locMast); |
| | | } |
| | | }else if(locMast.getLocSts().equals("O")){ |
| | | //当充放电库位为O空库位时 |
| | | //库位状态改为0空闲 |
| | | locMast=locMastService.selectztgx("O",i); |
| | | if(!Cools.isEmpty(locMast)){ |
| | | HashMap<String,Short> hashMap=new HashMap<>(); |
| | | if(devpThread.startSignal[i][0]!=locMast.getPackStatus()){ |
| | | hashMap.put("locSts",(short)0); |
| | | hashMap.put("channel",(short)(i*2)); |
| | | MessageQueue.offer(SlaveType.Devp, 1, new Task(6,hashMap)); |
| | | locMast.setPackStatus(0); |
| | | locMastService.updateById(locMast); |
| | | } |
| | | |
| | | if(devpThread.startSignal[i][1]!=locMast.getChannel()){ |
| | | locMast.setCtnKind(devpThread.startSignal[i][1]); |
| | | locMastService.updateById(locMast); |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | News.error("火警 ===>> 给输送线发送警报失败,通道号:", i + 1); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | } |
| | | } catch (Exception e) { |
| | | News.error("获得测试库位状态失败", e); |