| | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.mapper.Wrapper; |
| | | import com.core.common.Cools; |
| | | import com.core.common.SpringUtils; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.entity.*; |
| | | import com.zy.asrs.mapper.*; |
| | | import com.zy.asrs.service.*; |
| | |
| | | import org.springframework.transaction.interceptor.TransactionAspectSupport; |
| | | |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 立体仓库WCS系统主流程业务 |
| | |
| | | @Autowired |
| | | private WrkMastService wrkMastService; |
| | | @Autowired |
| | | private WrkDetlService wrkDetlService; |
| | | @Autowired |
| | | private LocMastService locMastService; |
| | | @Autowired |
| | | private LocDetlService locDetlService; |
| | | @Autowired |
| | | private StaDescService staDescService; |
| | | @Autowired |
| | |
| | | @Autowired |
| | | private ErpService erpService; |
| | | @Autowired |
| | | private OrderMapper orderMapper; |
| | | @Autowired |
| | | private OrderDetlMapper orderDetlMapper; |
| | | @Autowired |
| | | private BasLiftService basLiftService; |
| | | @Autowired |
| | | private ShuttleDispatchUtils shuttleDispatchUtils; |
| | |
| | | private ConfigService configService; |
| | | @Autowired |
| | | private NavigateMapUtils navigateMapUtils; |
| | | @Autowired |
| | | private WrkDetlLogService wrkDetlLogService; |
| | | @Autowired |
| | | private MatService matService; |
| | | @Autowired |
| | | private NavigateMapData navigateMapData; |
| | | |
| | |
| | | * 出库 ===>> 工作档信息写入led显示器 |
| | | */ |
| | | public void ledExecute() { |
| | | try { |
| | | 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<>(); |
| | | List<WrkMastLog> wrkMastLogs = 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()); |
| | | Integer wrkNo = staProtocol.getWorkNo().intValue(); |
| | | Integer ioType = null; |
| | | String sourceLocNo = null; |
| | | String locNo = null; |
| | | Integer wrkStaNo = null; |
| | | String barcode = null; |
| | | if (wrkMast == null) { |
| | | //查询历史档 |
| | | WrkMastLog wrkMastLog = wrkMastLogMapper.selectLatestByWorkNo(staProtocol.getWorkNo().intValue()); |
| | | if (wrkMastLog == null) { |
| | | continue; |
| | | } |
| | | ioType = wrkMastLog.getIoType(); |
| | | sourceLocNo = wrkMastLog.getSourceLocNo(); |
| | | locNo = wrkMastLog.getLocNo(); |
| | | wrkStaNo = wrkMastLog.getStaNo(); |
| | | barcode = wrkMastLog.getBarcode(); |
| | | wrkMastLogs.add(wrkMastLog); |
| | | }else { |
| | | if (wrkMast.getWrkSts() < 14 || wrkMast.getIoType() < 100) { |
| | | continue; |
| | | } |
| | | ioType = wrkMast.getIoType(); |
| | | sourceLocNo = wrkMast.getSourceLocNo(); |
| | | locNo = wrkMast.getLocNo(); |
| | | wrkStaNo = wrkMast.getStaNo(); |
| | | barcode = wrkMast.getBarcode(); |
| | | wrkMasts.add(wrkMast); |
| | | } |
| | | // 组装命令 |
| | | LedCommand ledCommand = new LedCommand(); |
| | | ledCommand.setWorkNo(wrkNo); |
| | | ledCommand.setIoType(ioType); |
| | | // 出库模式 |
| | | switch (ioType) { |
| | | 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("任务入出库类型错误!!![工作号:{}] [入出库类型:{}]", wrkNo, ioType); |
| | | break; |
| | | } |
| | | ledCommand.setSourceLocNo(sourceLocNo); |
| | | ledCommand.setLocNo(locNo); |
| | | ledCommand.setStaNo(wrkStaNo); |
| | | ledCommand.setBarcode(barcode); |
| | | if (ioType != 110 && ioType != 10) { |
| | | List<WrkDetl> wrkDetls = wrkDetlService.selectList(new EntityWrapper<WrkDetl>().eq("wrk_no", wrkNo)); |
| | | if (!wrkDetls.isEmpty()) { |
| | | wrkDetls.forEach(wrkDetl -> { |
| | | double remainNum = wrkDetl.getStock() - wrkDetl.getAnfme();//剩余数量 |
| | | if (remainNum < 0) { |
| | | remainNum = 0; |
| | | } |
| | | String matnr = wrkDetl.getMatnr(); |
| | | Mat mat = matService.selectByMatnr(wrkDetl.getMatnr()); |
| | | if (mat != null) { |
| | | if (!mat.getMatnr().equals(mat.getMatnr2())) { |
| | | matnr += " - " + mat.getMatnr2(); |
| | | } |
| | | } |
| | | ledCommand.getMatDtos().add(new MatDto(matnr, wrkDetl.getMaktx(), wrkDetl.getAnfme(), remainNum, wrkDetl.getSpecs(), wrkDetl.getSuppCode(), wrkDetl.getOrderNo())); |
| | | }); |
| | | }else { |
| | | List<WrkDetlLog> wrkDetlLogs = wrkDetlLogService.selectLatestByWorkNo(wrkNo, barcode); |
| | | for (WrkDetlLog wrkDetlLog : wrkDetlLogs) { |
| | | double remainNum = wrkDetlLog.getStock() - wrkDetlLog.getAnfme();//剩余数量 |
| | | if (remainNum < 0) { |
| | | remainNum = 0; |
| | | } |
| | | String matnr = wrkDetlLog.getMatnr(); |
| | | Mat mat = matService.selectByMatnr(wrkDetlLog.getMatnr()); |
| | | if (mat != null) { |
| | | if (!mat.getMatnr().equals(mat.getMatnr2())) { |
| | | matnr += " - " + mat.getMatnr2(); |
| | | } |
| | | } |
| | | ledCommand.getMatDtos().add(new MatDto(matnr, wrkDetlLog.getMaktx(), wrkDetlLog.getAnfme(), remainNum, wrkDetlLog.getSpecs(), wrkDetlLog.getSuppCode())); |
| | | } |
| | | } |
| | | |
| | | // List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", sourceLocNo)); |
| | | // if (ioType == 101) { |
| | | // List<WrkDetl> wrkDetls = wrkDetlService.selectList(new EntityWrapper<WrkDetl>().eq("wrk_no", wrkNo)); |
| | | // wrkDetls.forEach(wrkDetl -> { |
| | | // ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getAnfme(), 0D, wrkDetl.getSpecs(), wrkDetl.getSuppCode())); |
| | | // }); |
| | | //// locDetls.forEach(locDetl -> { |
| | | //// Wrapper<WrkDetl> wrapper = new EntityWrapper<WrkDetl>().eq("matnr", locDetl.getMatnr()).eq("wrk_no", wrkNo); |
| | | //// Utils.wapperSetCondition(wrapper, "batch", locDetl.getBatch()); |
| | | //// Utils.wapperSetCondition(wrapper, "three_code", locDetl.getThreeCode()); |
| | | //// Utils.wapperSetCondition(wrapper, "dead_time", locDetl.getDeadTime()); |
| | | //// Utils.wapperSetCondition(wrapper, "supp_code", locDetl.getSuppCode());//料箱码 |
| | | //// List<WrkDetl> detl = wrkDetlService.selectList(wrapper); |
| | | //// if (Cools.isEmpty(detl)) { |
| | | //// String suppCode = ""; |
| | | //// if (locDetl.getSuppCode() != null) { |
| | | //// suppCode = locDetl.getSuppCode(); |
| | | //// } |
| | | //// ledCommand.getMatDtos().add(new MatDto(locDetl.getMatnr(), locDetl.getMaktx(), 0D, locDetl.getAnfme(), locDetl.getSpecs(), suppCode)); |
| | | //// } else { |
| | | //// //出库数量累计 |
| | | //// Double conut = 0.0; |
| | | //// for (WrkDetl wrkDetl : detl) { |
| | | //// conut = conut + wrkDetl.getAnfme(); |
| | | //// } |
| | | //// |
| | | //// for (WrkDetl wrkDetl : detl) { |
| | | //// String suppCode = ""; |
| | | //// if (wrkDetl.getSuppCode() != null) { |
| | | //// suppCode = wrkDetl.getSuppCode(); |
| | | //// } |
| | | //// ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getAnfme(), (locDetl.getAnfme() - conut), wrkDetl.getSpecs(), suppCode, wrkDetl.getOrderNo())); |
| | | //// } |
| | | //// } |
| | | //// |
| | | //// }); |
| | | // } else { |
| | | // locDetls.forEach(locDetl -> { |
| | | // Wrapper<WrkDetl> wrapper = new EntityWrapper<WrkDetl>().eq("matnr", locDetl.getMatnr()).eq("wrk_no", wrkNo); |
| | | // Utils.wapperSetCondition(wrapper, "batch", locDetl.getBatch()); |
| | | // Utils.wapperSetCondition(wrapper, "three_code", locDetl.getThreeCode()); |
| | | // Utils.wapperSetCondition(wrapper, "dead_time", locDetl.getDeadTime()); |
| | | // Utils.wapperSetCondition(wrapper, "supp_code", locDetl.getSuppCode());//料箱码 |
| | | // List<WrkDetl> detl = wrkDetlService.selectList(wrapper); |
| | | // if (Cools.isEmpty(detl)) { |
| | | // String suppCode = ""; |
| | | // if (locDetl.getSuppCode() != null) { |
| | | // suppCode = locDetl.getSuppCode(); |
| | | // } |
| | | // ledCommand.getMatDtos().add(new MatDto(locDetl.getMatnr(), locDetl.getMaktx(), 0D, locDetl.getAnfme(), locDetl.getSpecs(), suppCode)); |
| | | // } else { |
| | | // //出库数量累计 |
| | | // Double conut = 0.0; |
| | | // for (WrkDetl wrkDetl : detl) { |
| | | // conut = conut + wrkDetl.getAnfme(); |
| | | // } |
| | | // |
| | | // for (WrkDetl wrkDetl : detl) { |
| | | // String suppCode = ""; |
| | | // if (wrkDetl.getSuppCode() != null) { |
| | | // suppCode = wrkDetl.getSuppCode(); |
| | | // } |
| | | // ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getAnfme(), (wrkDetl.getStock() - conut), wrkDetl.getSpecs(), suppCode, wrkDetl.getOrderNo())); |
| | | // } |
| | | // } |
| | | // |
| | | // }); |
| | | // try { |
| | | // 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<>(); |
| | | // List<WrkMastLog> wrkMastLogs = 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()); |
| | | // Integer wrkNo = staProtocol.getWorkNo().intValue(); |
| | | // Integer ioType = null; |
| | | // String sourceLocNo = null; |
| | | // String locNo = null; |
| | | // Integer wrkStaNo = null; |
| | | // String barcode = null; |
| | | // if (wrkMast == null) { |
| | | // //查询历史档 |
| | | // WrkMastLog wrkMastLog = wrkMastLogMapper.selectLatestByWorkNo(staProtocol.getWorkNo().intValue()); |
| | | // if (wrkMastLog == null) { |
| | | // continue; |
| | | // } |
| | | // |
| | | // |
| | | // if (ioType == 107) { |
| | | // locDetls = new ArrayList<>(); |
| | | // ledCommand.setMatDtos(new ArrayList<>()); |
| | | // ioType = wrkMastLog.getIoType(); |
| | | // sourceLocNo = wrkMastLog.getSourceLocNo(); |
| | | // locNo = wrkMastLog.getLocNo(); |
| | | // wrkStaNo = wrkMastLog.getStaNo(); |
| | | // barcode = wrkMastLog.getBarcode(); |
| | | // wrkMastLogs.add(wrkMastLog); |
| | | // }else { |
| | | // if (wrkMast.getWrkSts() < 14 || wrkMast.getIoType() < 100) { |
| | | // continue; |
| | | // } |
| | | // |
| | | // if (locDetls.isEmpty() && ioType != 101) { |
| | | // List<WrkDetl> wrkDetls = wrkDetlService.selectList(new EntityWrapper<WrkDetl>().eq("wrk_no", wrkNo)); |
| | | // ioType = wrkMast.getIoType(); |
| | | // sourceLocNo = wrkMast.getSourceLocNo(); |
| | | // locNo = wrkMast.getLocNo(); |
| | | // wrkStaNo = wrkMast.getStaNo(); |
| | | // barcode = wrkMast.getBarcode(); |
| | | // wrkMasts.add(wrkMast); |
| | | // } |
| | | // // 组装命令 |
| | | // LedCommand ledCommand = new LedCommand(); |
| | | // ledCommand.setWorkNo(wrkNo); |
| | | // ledCommand.setIoType(ioType); |
| | | // // 出库模式 |
| | | // switch (ioType) { |
| | | // 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("任务入出库类型错误!!![工作号:{}] [入出库类型:{}]", wrkNo, ioType); |
| | | // break; |
| | | // } |
| | | // ledCommand.setSourceLocNo(sourceLocNo); |
| | | // ledCommand.setLocNo(locNo); |
| | | // ledCommand.setStaNo(wrkStaNo); |
| | | // ledCommand.setBarcode(barcode); |
| | | // if (ioType != 110 && ioType != 10) { |
| | | // List<WrkDetl> wrkDetls = wrkDetlService.selectList(new EntityWrapper<WrkDetl>().eq("wrk_no", wrkNo)); |
| | | // if (!wrkDetls.isEmpty()) { |
| | | // wrkDetls.forEach(wrkDetl -> { |
| | | // if (wrkDetl.getAnfme() > 0D) { |
| | | // ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getAnfme(), wrkDetl.getAnfme(), wrkDetl.getSpecs(), wrkDetl.getSuppCode())); |
| | | // double remainNum = wrkDetl.getStock() - wrkDetl.getAnfme();//剩余数量 |
| | | // if (remainNum < 0) { |
| | | // remainNum = 0; |
| | | // } |
| | | // }); |
| | | // |
| | | // if (wrkDetls.isEmpty()) {//从历史档查询 |
| | | // List<WrkDetlLog> wrkDetlLogs = wrkDetlLogService.selectLatestByWorkNo(wrkNo, barcode); |
| | | // for (WrkDetlLog wrkDetlLog : wrkDetlLogs) { |
| | | // if (wrkDetlLog.getAnfme() > 0D) { |
| | | // ledCommand.getMatDtos().add(new MatDto(wrkDetlLog.getMatnr(), wrkDetlLog.getMaktx(), wrkDetlLog.getAnfme(), wrkDetlLog.getAnfme(), wrkDetlLog.getSpecs(), wrkDetlLog.getSuppCode())); |
| | | // String matnr = wrkDetl.getMatnr(); |
| | | // Mat mat = matService.selectByMatnr(wrkDetl.getMatnr()); |
| | | // if (mat != null) { |
| | | // if (!mat.getMatnr().equals(mat.getMatnr2())) { |
| | | // matnr += " - " + mat.getMatnr2(); |
| | | // } |
| | | // } |
| | | // ledCommand.getMatDtos().add(new MatDto(matnr, wrkDetl.getMaktx(), wrkDetl.getAnfme(), remainNum, wrkDetl.getSpecs(), wrkDetl.getSuppCode(), wrkDetl.getOrderNo())); |
| | | // }); |
| | | // }else { |
| | | // List<WrkDetlLog> wrkDetlLogs = wrkDetlLogService.selectLatestByWorkNo(wrkNo, barcode); |
| | | // for (WrkDetlLog wrkDetlLog : wrkDetlLogs) { |
| | | // double remainNum = wrkDetlLog.getStock() - wrkDetlLog.getAnfme();//剩余数量 |
| | | // if (remainNum < 0) { |
| | | // remainNum = 0; |
| | | // } |
| | | // String matnr = wrkDetlLog.getMatnr(); |
| | | // Mat mat = matService.selectByMatnr(wrkDetlLog.getMatnr()); |
| | | // if (mat != null) { |
| | | // if (!mat.getMatnr().equals(mat.getMatnr2())) { |
| | | // matnr += " - " + mat.getMatnr2(); |
| | | // } |
| | | // } |
| | | // ledCommand.getMatDtos().add(new MatDto(matnr, wrkDetlLog.getMaktx(), wrkDetlLog.getAnfme(), remainNum, wrkDetlLog.getSpecs(), wrkDetlLog.getSuppCode())); |
| | | // } |
| | | // } |
| | | } |
| | | |
| | | commands.add(ledCommand); |
| | | } |
| | | Set<Integer> workNos = null; |
| | | if (!wrkMasts.isEmpty()) { |
| | | workNos = wrkMasts.stream().map(WrkMast::getWrkNo).collect(Collectors.toSet()); |
| | | }else { |
| | | workNos = wrkMastLogs.stream().map(WrkMastLog::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))) { |
| | | log.error("{}号LED命令下发失败!!![ip:{}] [port:{}]", led.getId(), led.getIp(), led.getPort()); |
| | | continue; |
| | | } else { |
| | | ledThread.setLedMk(false); |
| | | } |
| | | } |
| | | |
| | | 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(); |
| | | } |
| | | |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | // commands.add(ledCommand); |
| | | // } |
| | | // Set<Integer> workNos = null; |
| | | // if (!wrkMasts.isEmpty()) { |
| | | // workNos = wrkMasts.stream().map(WrkMast::getWrkNo).collect(Collectors.toSet()); |
| | | // }else { |
| | | // workNos = wrkMastLogs.stream().map(WrkMastLog::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))) { |
| | | // log.error("{}号LED命令下发失败!!![ip:{}] [port:{}]", led.getId(), led.getIp(), led.getPort()); |
| | | // continue; |
| | | // } else { |
| | | // ledThread.setLedMk(false); |
| | | // } |
| | | // } |
| | | // |
| | | // 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(); |
| | | // } |
| | | // |
| | | // } |
| | | // } catch (Exception e) { |
| | | // e.printStackTrace(); |
| | | // } |
| | | } |
| | | |
| | | /** |