| | |
| | | import com.zy.asrs.service.*; |
| | | import com.zy.asrs.utils.*; |
| | | import com.zy.common.model.LocTypeDto; |
| | | 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.common.utils.News; |
| | | import com.zy.core.CrnThread; |
| | | import com.zy.core.DevpThread; |
| | | import com.zy.core.cache.*; |
| | | import com.zy.core.enums.*; |
| | | import com.zy.core.model.*; |
| | | import com.zy.core.model.command.CrnCommand; |
| | | import com.zy.core.model.command.LedCommand; |
| | | import com.zy.core.model.protocol.*; |
| | | 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.system.entity.license.LicenseVerify; |
| | |
| | | import java.util.*; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 立体仓库WCS系统主流程业务 |
| | |
| | | private WrkMastMapper wrkMastMapper; |
| | | @Autowired |
| | | private WrkDetlService wrkDetlService; |
| | | @Autowired |
| | | private BasDevpOptService basDevpOptService; |
| | | @Autowired |
| | | private LocMastService locMastService; |
| | | @Autowired |
| | |
| | | if (barcodeThread == null) { |
| | | continue; |
| | | } |
| | | String barcode = barcodeThread.getBarcode(); |
| | | |
| | | if (!Cools.isEmpty(barcode)) { |
| | | // log.info("{}号条码扫描器检测条码信息:{}", inSta.getBarcode(), barcode); |
| | | if ("00000000".endsWith(barcode) || "NG".endsWith(barcode) || "NoRead".equals(barcode) || !CodeDetectionUtil.barcodeDetection(barcode)) { |
| | | continue; |
| | | } |
| | | } else { |
| | | continue; |
| | | } |
| | | |
| | | // 获取入库站信息 |
| | | // SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId()); |
| | |
| | | continue; |
| | | } else { |
| | | staProtocol = staProtocol.clone(); |
| | | } |
| | | |
| | | String barcode = barcodeThread.getBarcode(); |
| | | |
| | | if (!Cools.isEmpty(barcode)) { |
| | | // log.info("{}号条码扫描器检测条码信息:{}", inSta.getBarcode(), barcode); |
| | | if ("00000000".endsWith(barcode) || "NG".endsWith(barcode) || "NoRead".equals(barcode) || !CodeDetectionUtil.barcodeDetection(barcode)) { |
| | | continue; |
| | | } |
| | | } else { |
| | | continue; |
| | | } |
| | | |
| | | // 尺寸检测异常 |
| | |
| | | } |
| | | // 退回 |
| | | if (back) { |
| | | barcodeThread.setBarcode(""); |
| | | // 获取工作号 |
| | | int workNo = commonService.getWorkNo(3); |
| | | |
| | | staProtocol.setWorkNo(workNo); |
| | | staProtocol.setStaNo(inSta.getBackSta().shortValue()); |
| | | |
| | | devpThread.setPakMk(staProtocol.getSiteId(), false,201); |
| | | boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | | // led 异常显示 |
| | | LedErrorThreadUtil.ledErrorThread(errMsg,inSta.getLed(), LedErrorAreaType.FOUR_BARCODE.getDesc()); |
| | | continue; |
| | |
| | | // if(Cools.isEmpty(dto.getRgvNo()) || dto.getRgvNo() <= 0) { |
| | | // staProtocol.setStaNo(607);//607 |
| | | // } else {//如果存在RGV编号,说明需要RGV接驳,先下发任务到RGV源站 |
| | | staProtocol.setStaNo(dto.getRgvSstaNo().shortValue()); |
| | | // staProtocol.setStaNo(dto.getRgvSstaNo().shortValue()); |
| | | staProtocol.setStaNo(wrkMast.getStaNoSou$().shortValue()); |
| | | |
| | | // } |
| | | |
| | | devpThread.setPakMk(staProtocol.getSiteId(), false,283); |
| | |
| | | throw new CoolException("更新plc站点信息失败"); |
| | | } |
| | | } else { |
| | | // 获取工作号 |
| | | int workNo = commonService.getWorkNo(3); |
| | | |
| | | staProtocol.setWorkNo(workNo); |
| | | staProtocol.setStaNo(inSta.getBackSta().shortValue()); |
| | | |
| | | devpThread.setPakMk(staProtocol.getSiteId(), false,201); |
| | | boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | | // led 异常显示 |
| | | LedErrorThreadUtil.ledErrorThread("入库请求失败"+jsonObject.getInteger("code"),inSta.getLed(), LedErrorAreaType.ONE_OTHER.getDesc()); |
| | | log.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/pakin/loc/v1", JSON.toJSONString(param), response); |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 出库 ===>> 工作档信息写入led显示器 |
| | | */ |
| | | public synchronized void ledExecute() { |
| | | for (LedSlave led : slaveProperties.getLed()) { |
| | | // 获取输送线plc线程 |
| | | DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, led.getDevpPlcId()); |
| | | // 命令集合 |
| | | List<LedCommand> commands = new ArrayList<>(); |
| | | // 工作档集合 |
| | | List<WrkMast> wrkMasts = new ArrayList<>(); |
| | | for (Integer staNo : led.getStaArr()) { |
| | | // 获取叉车站点 |
| | | StaProtocol staProtocol = devpThread.getStation().get(staNo); |
| | | 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) { |
| | | if(staProtocol.getWorkNo() > 9999){ //异常退出 |
| | | String err = basDevpOptService.getErr(staProtocol.getWorkNo()); |
| | | MessageQueue.offer(SlaveType.Led, led.getId(), new Task(3, err)); |
| | | } |
| | | continue; |
| | | } |
| | | wrkMasts.add(wrkMast); |
| | | // 组装命令 |
| | | LedCommand ledCommand = new LedCommand(); |
| | | ledCommand.setWorkNo(wrkMast.getWrkNo()); |
| | | ledCommand.setIoType(wrkMast.getIoType()); |
| | | // 出库模式 |
| | | switch (wrkMast.getIoType()) { |
| | | case 1: |
| | | ledCommand.setTitle("全板入库"); |
| | | break; |
| | | case 10: |
| | | ledCommand.setTitle("空板入库"); |
| | | break; |
| | | case 12: |
| | | ledCommand.setTitle("物料衔接"); |
| | | break; |
| | | case 57: |
| | | ledCommand.setTitle("盘点再入库"); |
| | | break; |
| | | case 53: |
| | | ledCommand.setTitle("拣料再入库"); |
| | | break; |
| | | case 101: |
| | | ledCommand.setTitle("全板出库"); |
| | | break; |
| | | case 103: |
| | | ledCommand.setTitle("拣料出库"); |
| | | break; |
| | | case 104: |
| | | ledCommand.setTitle("并板出库"); |
| | | break; |
| | | case 107: |
| | | ledCommand.setTitle("盘点出库"); |
| | | break; |
| | | case 110: |
| | | ledCommand.setTitle("空板出库"); |
| | | ledCommand.setEmptyMk(true); |
| | | break; |
| | | default: |
| | | News.error("任务入出库类型错误!!![工作号:{}] [入出库类型:{}]", wrkMast.getWrkNo(), wrkMast.getIoType()); |
| | | break; |
| | | } |
| | | ledCommand.setSourceLocNo(wrkMast.getSourceLocNo()); |
| | | ledCommand.setStaNo(wrkMast.getStaNo()); |
| | | ledCommand.setBarcode(wrkMast.getBarcode()); |
| | | if(wrkMast.getIoType() == 12){ |
| | | List<WrkDetl> wrkDetls = wrkDetlService.findByBarcode(wrkMast.getBarcode()); |
| | | 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(); |
| | | } |
| | | ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getOrderNo(), wrkDetl.getSupp(), wrkDetl.getSku(),wrkDetl.getAnfme(),total)); |
| | | }); |
| | | } |
| | | 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.getOrderNo(), wrkDetl.getSupp(), wrkDetl.getSku(),wrkDetl.getAnfme(),total)); |
| | | } |
| | | if (wrkMast.getIoType() == 103 && (null == wrkDetl.getInspect() || 0 == wrkDetl.getInspect())) { |
| | | ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getOrderNo(), wrkDetl.getSupp(), wrkDetl.getSku(),wrkDetl.getAnfme(),total)); |
| | | } |
| | | if (wrkMast.getIoType() == 107) { |
| | | ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getOrderNo(), wrkDetl.getSupp(), wrkDetl.getSku(),wrkDetl.getAnfme(),total)); |
| | | } |
| | | }); |
| | | } |
| | | commands.add(ledCommand); |
| | | } |
| | | Set<Integer> workNos = wrkMasts.stream().map(WrkMast::getWrkNo).collect(Collectors.toSet()); |
| | | // 获取LED线程 |
| | | LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, led.getId()); |
| | | // 相同工作号集合则过滤 |
| | | if (CollectionUtils.equals(ledThread.getWorkNos(), workNos)) { |
| | | continue; |
| | | } |
| | | // 命令下发 ------------------------------------------------------------------------------- |
| | | 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()); |
| | | continue; |
| | | } |
| | | } |
| | | |
| | | try { |
| | | // 修改主档led标记 |
| | | for (WrkMast wrkMast : wrkMasts) { |
| | | wrkMast.setOveMk("Y"); |
| | | wrkMast.setModiTime(new Date()); |
| | | if (wrkMastMapper.updateById(wrkMast) == 0) { |
| | | throw new CoolException("更新工作档失败"); |
| | | } |
| | | } |
| | | |
| | | // 更新线程当前工作号集合 |
| | | ledThread.setWorkNos(workNos); |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 其他 ===>> LED显示器复位,显示默认信息 |
| | | */ |
| | | public synchronized void ledReset() { |
| | | for (LedSlave led : slaveProperties.getLed()) { |
| | | // 获取输送线plc线程 |
| | | DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, led.getDevpPlcId()); |
| | | // 命令集合 |
| | | boolean reset = true; |
| | | for (Integer staNo : led.getStaArr()) { |
| | | // System.out.println("staArr = " + staNo); |
| | | |
| | | // 获取叉车站点 |
| | | StaProtocol staProtocol = devpThread.getStation().get(staNo); |
| | | if (staProtocol == null) { continue; } |
| | | if (staProtocol.getWorkNo() != 0 || staProtocol.isErr()) { |
| | | reset = false; |
| | | break; |
| | | } |
| | | } |
| | | // 获取led线程 |
| | | LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, led.getId()); |
| | | // led显示默认内容 |
| | | if (reset) { |
| | | if (ledThread == null) { |
| | | continue; |
| | | } |
| | | if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(2, new ArrayList<>()))) { |
| | | News.error("{}号LED显示默认命令下发失败!!![ip:{}] [port:{}]", led.getId(), led.getIp(), led.getPort()); |
| | | } |
| | | // if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(4, new ArrayList<>()))) { |
| | | // News.error("{}号LED显示默认命令下发失败!!![ip:{}] [port:{}]", led.getId(), led.getIp(), led.getPort()); |
| | | // } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 堆垛机5分钟无任务则回到源点 |
| | | */ |
| | |
| | | if (!WrkMastLogList.isEmpty()) { |
| | | boolean signT = false; |
| | | for (WrkMast wrkMast : WrkMastLogList){ |
| | | Date completeTime = wrkMast.getIoTime(); |
| | | Date completeTime = wrkMast.getModiTime(); |
| | | if (completeTime==null){ |
| | | continue; |
| | | } |