| | |
| | | } |
| | | } |
| | | |
| | | public synchronized void generateStoreWrkFile() throws IOException, InterruptedException { |
| | | try { |
| | | // 根据输送线plc遍历 |
| | | for (DevpSlave devp : slaveProperties.getDevp()) { |
| | | // 遍历入库口 |
| | | for (DevpSlave.Sta inSta : devp.getInSta()) { |
| | | // 获取入库站信息 |
| | | DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId()); |
| | | StaProtocol staProtocol = devpThread.getStation().get(inSta.getStaNo()); |
| | | if (staProtocol == null) { |
| | | continue; |
| | | } else { |
| | | staProtocol = staProtocol.clone(); |
| | | } |
| | | Short workNo = staProtocol.getWorkNo(); |
| | | Short stano = staProtocol.getStaNo(); |
| | | |
| | | // 尺寸检测异常 |
| | | boolean back = false; |
| | | String errMsg = ""; |
| | | if (staProtocol.isFrontErr()) { |
| | | errMsg = "前超限"; |
| | | back = true; |
| | | } |
| | | if (!back && staProtocol.isBackErr()) { |
| | | errMsg = "后超限"; |
| | | back = true; |
| | | } |
| | | if (!back && staProtocol.isHighErr()) { |
| | | errMsg = "高超限"; |
| | | back = true; |
| | | } |
| | | if (!back && staProtocol.isLeftErr()) { |
| | | errMsg = "左超限"; |
| | | back = true; |
| | | } |
| | | if (!back && staProtocol.isRightErr()) { |
| | | errMsg = "右超限"; |
| | | back = true; |
| | | } |
| | | if (!back && staProtocol.isWeightErr()) { |
| | | errMsg = "超重"; |
| | | back = true; |
| | | } |
| | | if (!back && staProtocol.isBarcodeErr()) { |
| | | errMsg = "扫码失败"; |
| | | back = true; |
| | | } |
| | | // 退回 |
| | | if (back) { |
| | | if (stano == inSta.getBackSta().shortValue()) { |
| | | continue; |
| | | } |
| | | if (workNo == 0 && stano == 0) { |
| | | continue; |
| | | } |
| | | if (!staProtocol.isPakMk()) { |
| | | continue; |
| | | } |
| | | // News.warn("扫码入库失败,{}入库站因{}异常,托盘已被退回", inSta.getStaNo(), errMsg); |
| | | staProtocol.setWorkNo(workNo); |
| | | staProtocol.setStaNo(inSta.getStaNo().shortValue()); |
| | | devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | | MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | | TaskWrk taskWrk = taskWrkMapper.selectByWrkNo(Integer.valueOf(workNo)); |
| | | if (taskWrk != null) { |
| | | taskWrk.setMemo(errMsg);//将错误码存入备注字段进行展示 |
| | | taskWrkMapper.updateById(taskWrk); |
| | | } |
| | | continue; |
| | | } |
| | | // 判断是否满足入库条件 |
| | | if (staProtocol.isAutoing() && staProtocol.isLoading() |
| | | && staProtocol.isInEnable() |
| | | && !staProtocol.isEmptyMk() && (workNo >= 9899) |
| | | && staProtocol.isPakMk()) { |
| | | // 获取条码扫描仪信息 |
| | | BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, inSta.getBarcode()); |
| | | if (barcodeThread == null) { |
| | | continue; |
| | | } |
| | | String barcode = barcodeThread.getBarcode(); |
| | | if (!Cools.isEmpty(barcode) && !barcode.equals("99999999")) { |
| | | // 请求wms接口,获取工作号和目标库位 |
| | | ToWmsDTO toWmsDTO = new ToWmsDTO(barcode, staProtocol.getSiteId(), staProtocol.isHigh() ? 2 : 1); |
| | | TaskWrk taskWrk1 = taskWrkService.selectOne(new EntityWrapper<TaskWrk>().eq("barcode", barcode)); |
| | | if (!Cools.isEmpty(taskWrk1)) { |
| | | log.info("托盘码:" + barcode + "任务档存在"); |
| | | if (taskWrk1.getIoType() == 1 && taskWrk1.getStartPoint().equals(staProtocol.getSiteId().toString())) { |
| | | StaDesc staDesc = staDescService.selectOne(new EntityWrapper<StaDesc>() |
| | | .eq("crn_no", taskWrk1.getCrnNo()).eq("type_no", 1).eq("stn_no", staProtocol.getSiteId())); |
| | | if (Cools.isEmpty(staDesc)) { |
| | | log.info("托盘码:" + barcode + "任务档存在"); |
| | | return; |
| | | } else { |
| | | staProtocol.setWorkNo(taskWrk1.getWrkNo().shortValue()); |
| | | staProtocol.setStaNo(staDesc.getCrnStn().shortValue()); |
| | | MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | | } |
| | | } |
| | | return; |
| | | } |
| | | HashMap<String, Object> headParam = new HashMap<>(); |
| | | headParam.put("Content-Type", "application/json"); |
| | | System.out.println(JSON.toJSONString(toWmsDTO)); |
| | | String response; |
| | | try { |
| | | response = new HttpHandler.Builder() |
| | | // .setHeaders(headParam) |
| | | .setUri(wmsUrl) |
| | | .setPath(inboundTaskApplyPath) |
| | | .setJson(JSON.toJSONString(toWmsDTO)) |
| | | .build() |
| | | .doPost(); |
| | | } catch (Exception e) { |
| | | log.error("请求入库调用接口失败"); |
| | | log.error("异常信息打印:" + e); |
| | | try { |
| | | BasDevp basDevp = basDevpService.selectById(inSta.getStaNo()); |
| | | if (Cools.isEmpty(basDevp)) { |
| | | log.error("站点号异常" + inSta.getStaNo()); |
| | | } else if (basDevp.getStaErr() != 0) { |
| | | basDevp.setStaErr(2); |
| | | basDevpService.updateById(basDevp); |
| | | } |
| | | } catch (Exception e1) { |
| | | // 退回 |
| | | log.error("扫码检测程序异常" + inSta.getStaNo() + "异常信息" + e1); |
| | | } |
| | | staProtocol.setWorkNo((short) 9999); |
| | | staProtocol.setStaNo(inSta.getStaNo().shortValue()); |
| | | devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | | MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | | // TaskWrk taskWrk = taskWrkMapper.selectByWrkNo(Integer.valueOf(workNo)); |
| | | // if (taskWrk != null) { |
| | | // taskWrk.setMemo(errMsg);//将错误码存入备注字段进行展示 |
| | | // taskWrkMapper.updateById(taskWrk); |
| | | // } |
| | | continue; |
| | | } |
| | | |
| | | JSONObject jsonObject = JSON.parseObject(response); |
| | | log.info("入库请求参数{}" + JSON.toJSONString(toWmsDTO)); |
| | | log.info("入库请求返回参数{}" + JSON.toJSONString(response)); |
| | | if (jsonObject.getInteger("code").equals(200) && !Cools.isEmpty(jsonObject.get("data").toString())) { |
| | | GetWmsDto getWmsDto = JSON.parseObject(jsonObject.get("data").toString(), GetWmsDto.class); |
| | | try { |
| | | BasDevp basDevp = basDevpService.selectById(inSta.getStaNo()); |
| | | if (Cools.isEmpty(basDevp)) { |
| | | log.error("站点号异常1" + inSta.getStaNo()); |
| | | throw new CoolException("站点号异常1,未查询到站点信息" + inSta.getStaNo()); |
| | | } |
| | | Integer staNoCrnNo = Utils.StaNoCrnNo(inSta.getStaNo()); |
| | | if (staNoCrnNo == 0) { |
| | | basDevp.setStaErr(1); |
| | | basDevpService.updateById(basDevp); |
| | | log.error("站点号异常2" + inSta.getStaNo()); |
| | | throw new CoolException("站点号异常2,站点号不存在" + inSta.getStaNo()); |
| | | } else { |
| | | LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>() |
| | | .eq("crn_no", staNoCrnNo.longValue()) |
| | | .eq("loc_no", getWmsDto.getLocNo())); |
| | | if (Cools.isEmpty(locMast)) { |
| | | basDevp.setStaErr(1); |
| | | basDevpService.updateById(basDevp); |
| | | log.error("站点号异常3" + inSta.getStaNo()); |
| | | throw new CoolException("站点号异常3:此巷道不存在目标库位" + inSta.getStaNo()); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | // log.error("扫码检测程序异常"+inSta.getStaNo()+"异常信息"+e); |
| | | // 退回 |
| | | log.error("扫码检测程序异常" + inSta.getStaNo() + errMsg); |
| | | log.error("扫码检测程序异常,异常信息" + e); |
| | | |
| | | staProtocol.setWorkNo((short) 9999); |
| | | staProtocol.setStaNo(inSta.getStaNo().shortValue()); |
| | | devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | | MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | | // TaskWrk taskWrk = taskWrkMapper.selectByWrkNo(Integer.valueOf(workNo)); |
| | | // if (taskWrk != null) { |
| | | // taskWrk.setMemo(errMsg);//将错误码存入备注字段进行展示 |
| | | // taskWrkMapper.updateById(taskWrk); |
| | | // } |
| | | continue; |
| | | } |
| | | //查看该库位是否为空库位 |
| | | LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>() |
| | | .eq("loc_sts", "O") |
| | | .eq("loc_no", getWmsDto.getLocNo())); |
| | | if (Cools.isEmpty(locMast)) { |
| | | try { |
| | | HashMap<String, Object> headParam1 = new HashMap<>(); |
| | | headParam1.put("taskNo", getWmsDto.getTaskNo()); |
| | | headParam1.put("status", 6); |
| | | headParam1.put("ioType", 1); |
| | | headParam1.put("barcode", barcode); |
| | | String response2; |
| | | response2 = new HttpHandler.Builder() |
| | | // .setHeaders(headParam) |
| | | .setUri(wmsUrl) |
| | | .setPath(taskStatusFeedbackPath) |
| | | .setJson(JSON.toJSONString(headParam1)) |
| | | .build() |
| | | .doPost(); |
| | | JSONObject jsonObject1 = JSON.parseObject(response2); |
| | | apiLogService.save("wcs派发库位==》不为空《==上报wms" |
| | | , wmsUrl + taskStatusFeedbackPath |
| | | , null |
| | | , "127.0.0.1" |
| | | , JSON.toJSONString(headParam1) |
| | | , response |
| | | , true |
| | | ); |
| | | } catch (Exception e) { |
| | | log.error("wcs派发库位==》不为空《==上报wms", getWmsDto.getWrkNo()); |
| | | throw new CoolException("wcs派发入库任务上报wms失败,派发库位==》不为空《==,异常信息:" + e); |
| | | } |
| | | } |
| | | |
| | | // 创新一个入库工作档 |
| | | TaskWrk taskWrk = taskWrkService.selectByTaskNo(getWmsDto.getWrkNo()); |
| | | if (Cools.isEmpty(taskWrk)) { |
| | | taskWrk = createTask(getWmsDto, barcode); |
| | | if (Cools.isEmpty(taskWrk)) { |
| | | log.error("库位异常,库位号:{}", getWmsDto.getTargetLocationCode()); |
| | | } else { |
| | | taskWrkService.insert(taskWrk); |
| | | StaDesc staDesc = staDescService.selectOne(new EntityWrapper<StaDesc>() |
| | | .eq("crn_no", taskWrk.getCrnNo()).eq("type_no", 1).eq("stn_no", staProtocol.getSiteId())); |
| | | staProtocol.setWorkNo(taskWrk.getWrkNo().shortValue()); |
| | | staProtocol.setStaNo(staDesc.getCrnStn().shortValue()); |
| | | MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | | } |
| | | } |
| | | |
| | | } else { |
| | | continue; |
| | | } |
| | | apiLogService.save("wms请求入库货位接口" |
| | | , wmsUrl + inboundTaskApplyPath |
| | | , null |
| | | , "127.0.0.1" |
| | | , JSON.toJSONString(toWmsDTO) |
| | | , response |
| | | , true |
| | | ); |
| | | |
| | | } else { |
| | | // 退回 |
| | | log.error("扫码入库失败,{}入库站因{}异常,托盘已被退回", inSta.getStaNo(), errMsg); |
| | | |
| | | staProtocol.setWorkNo((short) 9999); |
| | | staProtocol.setStaNo(inSta.getStaNo().shortValue()); |
| | | devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | | MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | | TaskWrk taskWrk = taskWrkMapper.selectByWrkNo(Integer.valueOf(workNo)); |
| | | if (taskWrk != null) { |
| | | taskWrk.setMemo(errMsg);//将错误码存入备注字段进行展示 |
| | | taskWrkMapper.updateById(taskWrk); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("generateStoreWrkFile e", e); |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 堆垛机站出库到出库站 |
| | | */ |