| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | 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()? "存在":"不存在"; |
| | |
| | | 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()? "存在":"不存在"; |
| | |
| | | command.setWeight2(weight2); |
| | | |
| | | if (workNo1 == 0 && workNo2 !=0){ |
| | | if("0".equals(matnr2) && "".equals(batch2) ){ |
| | | log.error("源站"+souSta2+"工位一任务缺少信息,物料代码:"+matnr+",batch:"+batch); |
| | | continue; |
| | | } |
| | | command.setTaskMode(RgvTaskModeType.FETCH_PUT2); // 任务模式: 2取放货 |
| | | } else if (workNo1 != 0 && workNo2 ==0) { |
| | | if("0".equals(matnr) && "".equals(batch) ){ |
| | | log.error("源站"+souSta1+"工位二任务缺少信息,物料代码:"+matnr+",batch:"+batch); |
| | | continue; |
| | | } |
| | | command.setTaskMode(RgvTaskModeType.FETCH_PUT1); // 任务模式: 1取放货 |
| | | }else { |
| | | if("0".equals(matnr) && "".equals(batch) ){ |
| | | log.error("源站"+souSta1+"工位一任务缺少信息,物料代码:"+matnr+",batch:"+batch); |
| | | continue; |
| | | } |
| | | if("0".equals(matnr2) && "".equals(batch2) ){ |
| | | log.error("源站"+souSta2+"工位二任务缺少信息,物料代码:"+matnr+",batch:"+batch); |
| | | continue; |
| | | } |
| | | command.setTaskMode(RgvTaskModeType.FETCH_PUT_ALL); // 任务模式: all取放货 |
| | | } |
| | | command.setCommand(false); |
| | |
| | | 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); |