| | |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static com.zy.common.utils.RandomValidateCodeUtil.code; |
| | | |
| | | /** |
| | | * 立体仓库WCS系统主流程业务 |
| | | * Created by vincent on 2020/8/6 |
| | |
| | | private MatnrCodeService matnrCodeService; |
| | | @Autowired |
| | | private WaitPakinService waitPakinService; |
| | | @Autowired |
| | | private MatService matService; |
| | | |
| | | @Value("${wms.url}") |
| | | private String wmsUrl; |
| | |
| | | log.error(staProtocol.getStaNo()+"站点,空桶,非法目标站!!!!!!"+staProtocol.getStaNoEnd().toString()); |
| | | continue; |
| | | } |
| | | Integer workNo1 = commonService.getWorkNo(3); |
| | | Date now = new Date(); |
| | | // 保存工作档 |
| | | WrkMast wrkMast = new WrkMast(); |
| | | wrkMast.setWrkNo(workNo1); |
| | | wrkMast.setIoTime(now); |
| | | wrkMast.setWrkSts(101L); // 工作状态:101.初始 |
| | | wrkMast.setIoType(199); // 入出库状态: 199.转移 |
| | | wrkMast.setIoPri(15D); |
| | | wrkMast.setCrnNo(0); |
| | | wrkMast.setSourceStaNo(staProtocol.getStaNo().intValue()); // 源站 |
| | | wrkMast.setStaNo(staProtocol.getStaNoEnd().intValue()); // 目标站 |
| | | wrkMast.setFullPlt("N"); // 满板 |
| | | wrkMast.setPicking("N"); // 拣料 |
| | | wrkMast.setExitMk("N"); // 退出 |
| | | wrkMast.setEmptyMk("Y"); // 空板 |
| | | wrkMast.setBarcode("KB888888"); // 托盘码 |
| | | wrkMast.setLinkMis("N"); |
| | | wrkMast.setCtnNo("Y"); // 入库阻塞库位移转标记 |
| | | wrkMast.setAppeTime(now); |
| | | wrkMast.setModiTime(now); |
| | | int res = wrkMastMapper.insert(wrkMast); |
| | | if (res == 0) { |
| | | // 判断是否满足入库条件 |
| | | if (staProtocol.isAutoing() |
| | | && staProtocol.isLoading() |
| | | && staProtocol.isInEnable() |
| | | && !staProtocol.isEmptyMk() |
| | | && (staProtocol.getWorkNo() == 0 || staProtocol.getWorkNo() > 9990) |
| | | && staProtocol.isPakMk()) { |
| | | Integer workNo1 = commonService.getWorkNo(3); |
| | | Date now = new Date(); |
| | | // 保存工作档 |
| | | WrkMast wrkMast = new WrkMast(); |
| | | wrkMast.setWrkNo(workNo1); |
| | | wrkMast.setIoTime(now); |
| | | wrkMast.setWrkSts(101L); // 工作状态:101.初始 |
| | | wrkMast.setIoType(199); // 入出库状态: 199.转移 |
| | | wrkMast.setIoPri(15D); |
| | | wrkMast.setCrnNo(0); |
| | | wrkMast.setSourceStaNo(staProtocol.getStaNo().intValue()); // 源站 |
| | | wrkMast.setStaNo(staProtocol.getStaNoEnd().intValue()); // 目标站 |
| | | wrkMast.setFullPlt("N"); // 满板 |
| | | wrkMast.setPicking("N"); // 拣料 |
| | | wrkMast.setExitMk("N"); // 退出 |
| | | wrkMast.setEmptyMk("Y"); // 空板 |
| | | wrkMast.setBarcode("KB888888"); // 托盘码 |
| | | wrkMast.setLinkMis("N"); |
| | | wrkMast.setCtnNo("Y"); // 入库阻塞库位移转标记 |
| | | wrkMast.setAppeTime(now); |
| | | wrkMast.setModiTime(now); |
| | | int res = wrkMastMapper.insert(wrkMast); |
| | | if (res == 0) { |
| | | // throw new CoolException(""); |
| | | log.error(staProtocol.getStaNo()+"站点,空桶,保存工作档主档失败!!!!!!"+now.toString()); |
| | | continue; |
| | | } |
| | | LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed()); |
| | | log.error(staProtocol.getStaNo()+"站点,空桶,保存工作档主档失败!!!!!!"+now.toString()); |
| | | continue; |
| | | } |
| | | LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed()); |
| | | |
| | | // StaProtocol staProtocol1 = new StaProtocol(); |
| | | staProtocol.setWorkNo(workNo1.shortValue()); |
| | | staProtocol.setStaNo((short)3001); |
| | | devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | | ledThread.errorReset(); |
| | | boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | | if (!result) { |
| | | throw new CoolException("更新plc站点信息失败"); |
| | | staProtocol.setWorkNo(workNo1.shortValue()); |
| | | staProtocol.setStaNo((short)3001); |
| | | devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | | ledThread.errorReset(); |
| | | boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | | if (!result) { |
| | | throw new CoolException("更新plc站点信息失败"); |
| | | } |
| | | } |
| | | |
| | | continue; |
| | | } |
| | | |
| | |
| | | // WrkMast wrkMast = wrkMastMapper.selectPakOutStep1(slave.getId(), crnStn.getStaNo()); |
| | | List<WrkMast> wrkMasts = wrkMastMapper.selectPakOutStep11(slave.getId(), crnStn.getStaNo()); |
| | | // 获取工作状态为14的工作档 |
| | | WrkMast wrkMast1 = wrkMastMapper.selectPakOutStep14(slave.getId(), crnStn.getStaNo()); |
| | | if ( wrkMast1 !=null) { |
| | | continue; |
| | | } |
| | | // WrkMast wrkMast1 = wrkMastMapper.selectPakOutStep14(slave.getId(), crnStn.getStaNo()); |
| | | // if ( wrkMast1 !=null) { |
| | | // continue; |
| | | // } |
| | | for (WrkMast wrkMast : wrkMasts) { |
| | | if (wrkMast == null) { |
| | | continue; |
| | |
| | | short sta1 = 0; |
| | | short souSta2 = 0; |
| | | short sta2 = 0; |
| | | Integer matnr = 0; |
| | | Integer matnr2 = 0; |
| | | String matnr = "0"; |
| | | String matnr2 = "0"; |
| | | String batch = ""; |
| | | String batch2 = ""; |
| | | short type = 0; |
| | |
| | | sta1 = Utils.getRgvEndStaNo(rgvSlave.getId(),wrkMast.getStaNo()); |
| | | Integer staNo = Utils.getStaNo(rgvSlave.getId(), (int) sta1); |
| | | BasDevp devp = basDevpService.selectById(staNo); |
| | | if (devp.getWrkNo()!=0 || devp.getLoading().equals("Y")){ |
| | | if (devp.getWrkNo()!=0 || Cools.isEmpty(devp.getLoading()) || devp.getLoading().equals("Y")){ |
| | | continue; |
| | | } |
| | | work1 = true; |
| | |
| | | } |
| | | Integer staNo = Utils.getStaNo(rgvSlave.getId(), (int) sta1); |
| | | BasDevp devp = basDevpService.selectById(staNo); |
| | | if (devp.getWrkNo()!=0 || devp.getLoading().equals("Y")){ |
| | | if (devp.getWrkNo()!=0 || Cools.isEmpty(devp.getLoading()) || devp.getLoading().equals("Y")){ |
| | | continue; |
| | | } |
| | | workNo1 = commonService.getWorkNo(3); |
| | |
| | | } |
| | | Integer staNo = Utils.getStaNo(rgvSlave.getId(), (int) sta1); |
| | | BasDevp devp = basDevpService.selectById(staNo); |
| | | if (devp.getWrkNo()!=0 || devp.getLoading().equals("Y")){ |
| | | if (devp.getWrkNo()!=0 || Cools.isEmpty(devp.getLoading()) || devp.getLoading().equals("Y")){ |
| | | continue; |
| | | } |
| | | work1 = true; |
| | | if (inStn.getSourcePlcId() == 4 || inStn.getSourcePlcId() ==5){ //灌装站需要获取输送线物料代码 |
| | | matnr = staProtocol.getMatnr(); |
| | | batch = staProtocol.getBatch(); |
| | | anfme = Cools.isEmpty(staProtocol.getAnfme()) ? anfme:staProtocol.getAnfme().shortValue(); |
| | | anfme = (Cools.isEmpty(staProtocol.getAnfme()) || staProtocol.getAnfme()==0) ? anfme:staProtocol.getAnfme().shortValue(); |
| | | weight11 = staProtocol.getWeight1(); |
| | | weight = weight11; |
| | | String memoBool = staProtocol.isBan()? "存在":"不存在"; |
| | |
| | | sta2 = Utils.getRgvEndStaNo(rgvSlave.getId(),wrkMast.getStaNo()); |
| | | Integer staNo = Utils.getStaNo(rgvSlave.getId(), (int) sta2); |
| | | BasDevp devp2 = basDevpService.selectById(staNo); |
| | | if (devp2.getWrkNo()!=0 || devp2.getLoading().equals("Y")){ |
| | | if (devp2.getWrkNo()!=0 || Cools.isEmpty(devp2.getLoading()) || devp2.getLoading().equals("Y")){ |
| | | continue; |
| | | } |
| | | |
| | |
| | | } |
| | | Integer staNo = Utils.getStaNo(rgvSlave.getId(), (int) sta2); |
| | | BasDevp devp2 = basDevpService.selectById(staNo); |
| | | if (devp2.getWrkNo()!=0 || devp2.getLoading().equals("Y")){ |
| | | if (devp2.getWrkNo()!=0 || Cools.isEmpty(devp2.getLoading()) || devp2.getLoading().equals("Y")){ |
| | | continue; |
| | | } |
| | | workNo2 = commonService.getWorkNo(3); |
| | |
| | | } |
| | | Integer staNo = Utils.getStaNo(rgvSlave.getId(), (int) sta2); |
| | | BasDevp devp2 = basDevpService.selectById(staNo); |
| | | if (devp2.getWrkNo()!=0 || devp2.getLoading().equals("Y")){ |
| | | if (devp2.getWrkNo()!=0 || Cools.isEmpty(devp2.getLoading()) || devp2.getLoading().equals("Y")){ |
| | | continue; |
| | | } |
| | | |
| | |
| | | if (inStn.getSourcePlcId() == 4){ |
| | | matnr2 = staProtocol.getMatnr(); |
| | | batch2 = staProtocol.getBatch(); |
| | | anfme2 = Cools.isEmpty(staProtocol.getAnfme2()) ? anfme2:staProtocol.getAnfme2().shortValue(); |
| | | anfme2 = (Cools.isEmpty(staProtocol.getAnfme2()) || staProtocol.getAnfme2()==0) ? anfme2:staProtocol.getAnfme2().shortValue(); |
| | | |
| | | weight11 = staProtocol.getWeight1(); |
| | | weight2 = weight11; |
| | | String memoBool = staProtocol.isBan()? "存在":"不存在"; |
| | |
| | | wrkMast.setWrkSts(14L); |
| | | wrkMast.setModiTime(date); |
| | | wrkMastService.updateById(wrkMast); |
| | | } else if (wrkMast.getIoType()==199){ |
| | | } else if (wrkMast.getIoType()==199 && rgvSlave.getId()==3 && (wrkMast.getStaNo()==3007 || wrkMast.getStaNo()==3012)){ |
| | | Date date = new Date(); |
| | | wrkMast.setWrkSts(105L); |
| | | wrkMast.setModiTime(date); |
| | |
| | | wrkMast.setWrkSts(105L); |
| | | wrkMast.setModiTime(date); |
| | | wrkMastService.updateById(wrkMast); |
| | | } else if (wrkMast.getIoType() == 105){ |
| | | Date date = new Date(); |
| | | wrkMast.setWrkSts(14L); |
| | | wrkMast.setModiTime(date); |
| | | wrkMastService.updateById(wrkMast); |
| | | } |
| | | } |
| | | |
| | |
| | | // 获取入库通知档 |
| | | WaitPakin waitPakin = waitPakinService.selectOne(new EntityWrapper<WaitPakin>().eq("zpallet", barcode).eq("io_status", "N")); |
| | | if (Cools.isEmpty(waitPakin)) { |
| | | try { |
| | | CreateComb(barcode, staProtocol.getMatnr(),staProtocol.getWorkNo().intValue(),staProtocol.getBatch(),inSta); |
| | | }catch (IOException e) { |
| | | throw new CoolException(e); |
| | | WrkMast mast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("barcode", barcode).eq("io_type", 105)); |
| | | if (Cools.isEmpty(mast)) { |
| | | try { |
| | | CreateComb(barcode, staProtocol.getMatnr().toString(),staProtocol.getWorkNo().intValue(),staProtocol.getBatch(),inSta); |
| | | }catch (IOException e) { |
| | | throw new CoolException(e); |
| | | } |
| | | } else { |
| | | try { |
| | | LocTypeDto locTypeDto = new LocTypeDto(staProtocol); |
| | | SearchLocParam param = new SearchLocParam(); |
| | | param.setBarcode(barcode); |
| | | param.setBatch(staProtocol.getBatch()); |
| | | param.setIoType(105); |
| | | param.setSourceStaNo(inSta.getStaNo()); |
| | | param.setLocType1(locTypeDto.getLocType1()); |
| | | String response = new HttpHandler.Builder() |
| | | .setUri(wmsUrl) |
| | | .setPath("/rpc/process/in/loc/v1") |
| | | .setJson(JSON.toJSONString(param)) |
| | | .build() |
| | | .doPost(); |
| | | JSONObject jsonObject = JSON.parseObject(response); |
| | | LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed()); |
| | | if (jsonObject.getInteger("code").equals(200)) { |
| | | StartupDto dto = jsonObject.getObject("data", StartupDto.class); |
| | | |
| | | barcodeThread.setBarcode(""); |
| | | staProtocol.setWorkNo(dto.getWorkNo().shortValue()); |
| | | staProtocol.setStaNo(dto.getStaNo().shortValue()); |
| | | devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | | ledThread.errorReset(); |
| | | boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | | if (!result) { |
| | | throw new CoolException("更新plc站点信息失败"); |
| | | } |
| | | } else if(jsonObject.getInteger("code").equals(700)) { |
| | | log.error(barcode + "托盘识别异常,请先进行组托!"); |
| | | // led 异常显示 |
| | | ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed()); |
| | | if (ledThread != null) { |
| | | String errorMsg = barcode + "托盘识别异常,请先进行组托!"; |
| | | MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errorMsg)); |
| | | } |
| | | } else { |
| | | log.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/process/in/loc/v1", JSON.toJSONString(param), response); |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | log.error(""+e); |
| | | e.printStackTrace(); |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | } |
| | | } |
| | | } else if (waitPakin.getWeight() == null) { |
| | | WrkMastSta wrkMastSta = wrkMastStaService.selectOne(new EntityWrapper<WrkMastSta>().eq("wrk_no", staProtocol.getWorkNo().intValue())); |
| | |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | log.error(""+e); |
| | | e.printStackTrace(); |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | } |
| | |
| | | |
| | | } |
| | | |
| | | public void CreateComb(String barcode,Integer code,Integer wrkNo,String batch,DevpSlave.Sta inSta) throws IOException { |
| | | public synchronized void getNeed() { |
| | | for (DevpSlave devp : slaveProperties.getDevp()) { |
| | | if (devp.getId() != 2) { |
| | | continue; |
| | | } |
| | | SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId()); |
| | | if (devpThread.isCalled == 1) { |
| | | try { |
| | | String response = new HttpHandler.Builder() |
| | | .setUri(wmsUrl) |
| | | .setPath("/rpc/process/loc/v1") |
| | | .setJson(JSON.toJSONString("")) |
| | | .build() |
| | | .doPost(); |
| | | JSONObject jsonObject = JSON.parseObject(response); |
| | | if (jsonObject.getInteger("code").equals(200)) { |
| | | log.info("任务下发成功"); |
| | | boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(4, null)); |
| | | } else { |
| | | log.error("请求接口失败!!!url:{};response:{}", wmsUrl + "/mobile/comb/auth", response); |
| | | } |
| | | Thread.sleep(1000); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | if (devpThread.isFinish == 1) { |
| | | |
| | | Integer weight = devpThread.weight; |
| | | Integer isHalf = devpThread.isHalf; |
| | | WrkMast lastWrkMast105 = wrkMastService.getLastWrkMast105(); |
| | | if (Cools.isEmpty(lastWrkMast105)) continue; |
| | | List<WrkDetl> wrkDetls = wrkDetlService.findByWorkNo(lastWrkMast105.getWrkNo()); |
| | | if (!Cools.isEmpty(wrkDetls)) { |
| | | for (WrkDetl wrkDetl : wrkDetls) { |
| | | wrkDetl.setWeight(weight.doubleValue()); |
| | | if (isHalf == 1) { |
| | | wrkDetl.setMemo("存在半桶"); |
| | | } else { |
| | | wrkDetl.setMemo("不存在半桶"); |
| | | } |
| | | wrkDetlService.updateById(wrkDetl); |
| | | } |
| | | } |
| | | boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(5, null)); |
| | | } |
| | | } |
| | | } |
| | | public void CreateComb(String barcode,String code,Integer wrkNo,String batch,DevpSlave.Sta inSta) throws IOException { |
| | | Double anfme = 0d; |
| | | Double weight = 0d; |
| | | String memo = ""; |
| | |
| | | if (Cools.isEmpty(wrkMastSta)){ |
| | | wrkMastSta = wrkMastStaService.selectOne(new EntityWrapper<WrkMastSta>().eq("wrk_no2", wrkNo)); |
| | | if (Cools.isEmpty(wrkMastSta)){ |
| | | if (code >0 && !Cools.isEmpty(batch)){ |
| | | if (!Cools.isEmpty(batch)){ |
| | | anfme = 1d; |
| | | }else { |
| | | throw new CoolException("未找到对应的任务信息"); |
| | |
| | | weight = wrkMastSta.getWeight(); |
| | | memo = wrkMastSta.getMemo(); |
| | | } |
| | | MatnrCode matnrCode = matnrCodeService.selectByCode(code); |
| | | if (Cools.isEmpty(matnrCode)){ |
| | | //// |
| | | // MatnrCode matnrCode = matnrCodeService.selectByCode(code); |
| | | Mat mat = matService.selectByCode(code); |
| | | if (Cools.isEmpty(mat)){ |
| | | throw new CoolException("未找到对应的物料信息"); |
| | | } |
| | | CombParam combParam = new CombParam(); |
| | | ArrayList<CombParam.CombMat> combMats = new ArrayList<>(); |
| | | CombParam.CombMat combMat = new CombParam.CombMat(); |
| | | combParam.setBarcode(barcode); |
| | | combMat.setMatnr(matnrCode.getMatnr()); |
| | | combMat.setMatnr(mat.getMatnr()); |
| | | combMat.setBatch(batch); |
| | | combMat.setAnfme(anfme); |
| | | combMat.setWeight(weight); |