| | |
| | | import com.zy.asrs.domain.enums.WorkNoType; |
| | | import com.zy.asrs.domain.param.CrnOperatorParam; |
| | | import com.zy.asrs.entity.*; |
| | | import com.zy.asrs.entity.param.Result; |
| | | import com.zy.asrs.entity.param.StorageEscalationParam; |
| | | import com.zy.asrs.entity.param.TaskOverToWms; |
| | | import com.zy.asrs.mapper.BasCrnErrorMapper; |
| | |
| | | } |
| | | } |
| | | |
| | | //拣料回库 |
| | | public synchronized void PickingAndReturningToTheWarehouse() throws IOException, InterruptedException { |
| | | try { |
| | | // 根据输送线plc遍历 |
| | | for (DevpSlave devp : slaveProperties.getDevp()) { |
| | | // 遍历入库口 |
| | | for (DevpSlave.Sta inSta : devp.getPickSta()) { |
| | | StorageEscalationParam storageEscalationParam = new StorageEscalationParam(); |
| | | // 获取入库站信息 |
| | | 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(); |
| | | //led |
| | | LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed()); |
| | | |
| | | // 判断是否满足入库条件 |
| | | if (staProtocol.isAutoing() && staProtocol.isLoading() |
| | | && staProtocol.isInEnable() |
| | | && staProtocol.isPakMk()) { |
| | | // 获取条码扫描仪信息 |
| | | String BoxNo = ""; |
| | | //站点拣料回库任务是会有一条 |
| | | TaskWrk taskWrkk = taskWrkService.selectOne(new EntityWrapper<TaskWrk>().eq("start_point", staProtocol.getSiteId())); |
| | | if (!Cools.isEmpty(taskWrkk)) { |
| | | continue; |
| | | } |
| | | if (!staProtocol.isEmptyMk() && staProtocol.getWorkNo() < 9990) { |
| | | |
| | | TaskWrk taskWrk1 = taskWrkService.selectOne(new EntityWrapper<TaskWrk>().eq("wrk_no", workNo)); |
| | | |
| | | if (!Cools.isEmpty(taskWrk1)) { |
| | | BoxNo = taskWrk1.getBarcode(); |
| | | } else { |
| | | TaskWrkLog taskWrkLog = taskWrkLogService.selectOne(new EntityWrapper<TaskWrkLog>().eq("wrk_no", workNo).orderBy("modi_time", false)); |
| | | if (taskWrkLog != null) { |
| | | BoxNo = taskWrkLog.getBarcode(); |
| | | } |
| | | } |
| | | } |
| | | log.info("组托入库={}", storageEscalationParam); |
| | | storageEscalationParam.setBoxNo(BoxNo); |
| | | //是否满板 1满板 0空板 |
| | | storageEscalationParam.setStaType(staProtocol.isEmptyMk() ? 0 : 1); |
| | | //库位类型 1高库位 0低库位 |
| | | storageEscalationParam.setLocType(staProtocol.isHigh() ? 1 : 0); |
| | | storageEscalationParam.setTerminalNo(staProtocol.getSiteId()); |
| | | String response = ""; |
| | | Boolean success = false; |
| | | try { |
| | | response = new HttpHandler.Builder() |
| | | .setUri(wmsUrl) |
| | | .setPath(inboundTaskApplyPath) |
| | | .setJson(JSON.toJSONString(storageEscalationParam)) |
| | | .build() |
| | | .doPost(); |
| | | JSONObject jsonObject = JSON.parseObject(response); |
| | | |
| | | if (!Cools.isEmpty(response) && !Cools.isEmpty(jsonObject.get("ReturnStatus")) && jsonObject.get("ReturnStatus").equals(0) && !Cools.isEmpty(jsonObject.get("Result").toString())) { |
| | | Result result = JSON.parseObject(jsonObject.get("Result").toString(), Result.class); |
| | | |
| | | // 创新一个入库工作档 |
| | | TaskWrk taskWrk = taskWrkService.selectByTaskNo(result.getTaskNo()); |
| | | if (Cools.isEmpty(taskWrk)) { |
| | | taskWrk = createTask1(result, BoxNo, staProtocol.getSiteId()); |
| | | if (Cools.isEmpty(taskWrk)) { |
| | | log.error("库位异常,库位号:={}", taskWrk.getOriginTargetPoint()); |
| | | } 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)); |
| | | HashMap<String, Object> hashMap = new HashMap<>(); |
| | | hashMap.put("TaskNo", taskWrk.getTaskNo()); |
| | | try { |
| | | //开始上报,任务开始时,WCS回调WMS |
| | | response = new HttpHandler.Builder() |
| | | .setUri(wmsUrl) |
| | | .setPath(taskStatusFeedbackPath) |
| | | .setJson(JSON.toJSONString(hashMap)) |
| | | .build() |
| | | .doPost(); |
| | | JSONObject jsonObject1 = JSON.parseObject(response); |
| | | Boolean bool = false; |
| | | if (jsonObject1.get("ReturnStatus").equals(0)) { |
| | | taskWrk.setStatus(2);//派发任务 |
| | | bool = true; |
| | | taskWrkService.updateById(taskWrk); |
| | | } |
| | | apiLogService.save("wcs开始入库任务上报wms" |
| | | , wmsUrl + TaskExecCallback |
| | | , null |
| | | , "127.0.0.1" |
| | | , JSON.toJSONString(hashMap) |
| | | , response |
| | | , bool |
| | | ); |
| | | } catch (Exception e) { |
| | | |
| | | } |
| | | } |
| | | } else { |
| | | // led 异常显示 |
| | | if (ledThread != null) { |
| | | String errorMsg = "任务已存在!!!!"; |
| | | MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(5, errorMsg)); |
| | | } |
| | | staProtocol.setWorkNo((short) 9991); |
| | | staProtocol.setStaNo(inSta.getBackSta().shortValue()); |
| | | devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | | MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | | } |
| | | |
| | | } else { |
| | | // led 异常显示 |
| | | if (ledThread != null) { |
| | | String errorMsg = jsonObject.getString("ErrorMessage"); |
| | | MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(5, errorMsg)); |
| | | } |
| | | staProtocol.setWorkNo((short) 9991); |
| | | staProtocol.setStaNo(inSta.getBackSta().shortValue()); |
| | | devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | | MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | | } |
| | | |
| | | } 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); |
| | | } |
| | | } finally { |
| | | apiLogService.save("wms请求入库货位接口" |
| | | , wmsUrl + inboundTaskApplyPath |
| | | , null |
| | | , "127.0.0.1" |
| | | , JSON.toJSONString(storageEscalationParam) |
| | | , response |
| | | , success |
| | | ); |
| | | } |
| | | log.info("入库请求参数=" + JSON.toJSONString(BoxNo)); |
| | | log.info("入库请求返回参数=" + JSON.toJSONString(response)); |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("generateStoreWrkFile e", e); |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | } |
| | | } |
| | | // //拣料回库 |
| | | // public synchronized void PickingAndReturningToTheWarehouse() throws IOException, InterruptedException { |
| | | // try { |
| | | // // 根据输送线plc遍历 |
| | | // for (DevpSlave devp : slaveProperties.getDevp()) { |
| | | // // 遍历入库口 |
| | | // for (DevpSlave.Sta inSta : devp.getPickSta()) { |
| | | // StorageEscalationParam storageEscalationParam = new StorageEscalationParam(); |
| | | // // 获取入库站信息 |
| | | // 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(); |
| | | // //led |
| | | // LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed()); |
| | | // |
| | | // // 判断是否满足入库条件 |
| | | // if (staProtocol.isAutoing() && staProtocol.isLoading() |
| | | // && staProtocol.isInEnable() |
| | | // && staProtocol.isPakMk()) { |
| | | // // 获取条码扫描仪信息 |
| | | // String BoxNo = ""; |
| | | // //站点拣料回库任务是会有一条 |
| | | // TaskWrk taskWrkk = taskWrkService.selectOne(new EntityWrapper<TaskWrk>().eq("start_point", staProtocol.getSiteId())); |
| | | // if (!Cools.isEmpty(taskWrkk)) { |
| | | // continue; |
| | | // } |
| | | // if (!staProtocol.isEmptyMk() && staProtocol.getWorkNo() < 9990) { |
| | | // |
| | | // TaskWrk taskWrk1 = taskWrkService.selectOne(new EntityWrapper<TaskWrk>().eq("wrk_no", workNo)); |
| | | // |
| | | // if (!Cools.isEmpty(taskWrk1)) { |
| | | // BoxNo = taskWrk1.getBarcode(); |
| | | // } else { |
| | | // TaskWrkLog taskWrkLog = taskWrkLogService.selectOne(new EntityWrapper<TaskWrkLog>().eq("wrk_no", workNo).orderBy("modi_time", false)); |
| | | // if (taskWrkLog != null) { |
| | | // BoxNo = taskWrkLog.getBarcode(); |
| | | // } |
| | | // } |
| | | // } |
| | | // log.info("组托入库={}", storageEscalationParam); |
| | | // storageEscalationParam.setBoxNo(BoxNo); |
| | | // //是否满板 1满板 0空板 |
| | | // storageEscalationParam.setStaType(staProtocol.isEmptyMk() ? 0 : 1); |
| | | // //库位类型 1高库位 0低库位 |
| | | // storageEscalationParam.setLocType(staProtocol.isHigh() ? 1 : 0); |
| | | // storageEscalationParam.setTerminalNo(staProtocol.getSiteId()); |
| | | // String response = ""; |
| | | // Boolean success = false; |
| | | // try { |
| | | // response = new HttpHandler.Builder() |
| | | // .setUri(wmsUrl) |
| | | // .setPath(inboundTaskApplyPath) |
| | | // .setJson(JSON.toJSONString(storageEscalationParam)) |
| | | // .build() |
| | | // .doPost(); |
| | | // JSONObject jsonObject = JSON.parseObject(response); |
| | | // |
| | | // if (!Cools.isEmpty(response) && !Cools.isEmpty(jsonObject.get("ReturnStatus")) && jsonObject.get("ReturnStatus").equals(0) && !Cools.isEmpty(jsonObject.get("Result").toString())) { |
| | | // Result result = JSON.parseObject(jsonObject.get("Result").toString(), Result.class); |
| | | // |
| | | // // 创新一个入库工作档 |
| | | // TaskWrk taskWrk = taskWrkService.selectByTaskNo(result.getTaskNo()); |
| | | // if (Cools.isEmpty(taskWrk)) { |
| | | // taskWrk = createTask1(result, BoxNo, staProtocol.getSiteId()); |
| | | // if (Cools.isEmpty(taskWrk)) { |
| | | // log.error("库位异常,库位号:={}", taskWrk.getOriginTargetPoint()); |
| | | // } 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)); |
| | | // HashMap<String, Object> hashMap = new HashMap<>(); |
| | | // hashMap.put("TaskNo", taskWrk.getTaskNo()); |
| | | // try { |
| | | // //开始上报,任务开始时,WCS回调WMS |
| | | // response = new HttpHandler.Builder() |
| | | // .setUri(wmsUrl) |
| | | // .setPath(taskStatusFeedbackPath) |
| | | // .setJson(JSON.toJSONString(hashMap)) |
| | | // .build() |
| | | // .doPost(); |
| | | // JSONObject jsonObject1 = JSON.parseObject(response); |
| | | // Boolean bool = false; |
| | | // if (jsonObject1.get("ReturnStatus").equals(0)) { |
| | | // taskWrk.setStatus(2);//派发任务 |
| | | // bool = true; |
| | | // taskWrkService.updateById(taskWrk); |
| | | // } |
| | | // apiLogService.save("wcs开始入库任务上报wms" |
| | | // , wmsUrl + TaskExecCallback |
| | | // , null |
| | | // , "127.0.0.1" |
| | | // , JSON.toJSONString(hashMap) |
| | | // , response |
| | | // , bool |
| | | // ); |
| | | // } catch (Exception e) { |
| | | // |
| | | // } |
| | | // } |
| | | // } else { |
| | | // // led 异常显示 |
| | | // if (ledThread != null) { |
| | | // String errorMsg = "任务已存在!!!!"; |
| | | // MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(5, errorMsg)); |
| | | // } |
| | | // staProtocol.setWorkNo((short) 9991); |
| | | // staProtocol.setStaNo(inSta.getBackSta().shortValue()); |
| | | // devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | | // MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | | // } |
| | | // |
| | | // } else { |
| | | // // led 异常显示 |
| | | // if (ledThread != null) { |
| | | // String errorMsg = jsonObject.getString("ErrorMessage"); |
| | | // MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(5, errorMsg)); |
| | | // } |
| | | // staProtocol.setWorkNo((short) 9991); |
| | | // staProtocol.setStaNo(inSta.getBackSta().shortValue()); |
| | | // devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | | // MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | | // } |
| | | // |
| | | // } 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); |
| | | // } |
| | | // } finally { |
| | | // apiLogService.save("wms请求入库货位接口" |
| | | // , wmsUrl + inboundTaskApplyPath |
| | | // , null |
| | | // , "127.0.0.1" |
| | | // , JSON.toJSONString(storageEscalationParam) |
| | | // , response |
| | | // , success |
| | | // ); |
| | | // } |
| | | // log.info("入库请求参数=" + JSON.toJSONString(BoxNo)); |
| | | // log.info("入库请求返回参数=" + JSON.toJSONString(response)); |
| | | // } |
| | | // } |
| | | // } |
| | | // } catch (Exception e) { |
| | | // log.error("generateStoreWrkFile e", e); |
| | | // TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | // } |
| | | // } |
| | | |
| | | public synchronized void generateStoreWrkFile() throws IOException, InterruptedException { |
| | | try { |
| | |
| | | return response; |
| | | } |
| | | |
| | | private TaskWrk createTask1(Result result, String barcode, Integer staNo) { |
| | | String locNo = Utils.Fusion(result.getRow(), result.getFloor(), result.getColumn()); |
| | | |
| | | Date now = new Date(); |
| | | TaskWrk taskWrk = new TaskWrk(); |
| | | int workNo1 = commonService.getWorkNo(WorkNoType.PAKIN.type);//获取入库工作号 |
| | | taskWrk.setTaskNo(result.getTaskNo());//任务号 |
| | | taskWrk.setWrkNo(workNo1); |
| | | taskWrk.setStatus(TaskStatusType.RECEIVE.id);//任务状态:接收 |
| | | taskWrk.setCreateTime(now); |
| | | taskWrk.setIoType(1);//任务类型 入库 |
| | | taskWrk.setIoPri(13);//优先级 |
| | | taskWrk.setBarcode(barcode);//条码 |
| | | taskWrk.setTargetPoint(locNo); |
| | | taskWrk.setStartPoint(staNo + ""); |
| | | taskWrk.setCrnNo(Integer.valueOf(result.getAlley()));//堆垛机号 |
| | | |
| | | if (taskWrk.getIoType() == 1) { |
| | | taskWrk.setWrkSts(2); |
| | | if (!Cools.isEmpty(taskWrk.getTargetPoint())) { |
| | | taskWrk.setOriginTargetPoint(taskWrk.getTargetPoint()); |
| | | } |
| | | } |
| | | return taskWrk; |
| | | } |
| | | // private TaskWrk createTask1(Result result, String barcode, Integer staNo) { |
| | | // String locNo = Utils.Fusion(result.getRow(), result.getFloor(), result.getColumn()); |
| | | // |
| | | // Date now = new Date(); |
| | | // TaskWrk taskWrk = new TaskWrk(); |
| | | // int workNo1 = commonService.getWorkNo(WorkNoType.PAKIN.type);//获取入库工作号 |
| | | // taskWrk.setTaskNo(result.getTaskNo());//任务号 |
| | | // taskWrk.setWrkNo(workNo1); |
| | | // taskWrk.setStatus(TaskStatusType.RECEIVE.id);//任务状态:接收 |
| | | // taskWrk.setCreateTime(now); |
| | | // taskWrk.setIoType(1);//任务类型 入库 |
| | | // taskWrk.setIoPri(13);//优先级 |
| | | // taskWrk.setBarcode(barcode);//条码 |
| | | // taskWrk.setTargetPoint(locNo); |
| | | // taskWrk.setStartPoint(staNo + ""); |
| | | // taskWrk.setCrnNo(Integer.valueOf(result.getAlley()));//堆垛机号 |
| | | // |
| | | // if (taskWrk.getIoType() == 1) { |
| | | // taskWrk.setWrkSts(2); |
| | | // if (!Cools.isEmpty(taskWrk.getTargetPoint())) { |
| | | // taskWrk.setOriginTargetPoint(taskWrk.getTargetPoint()); |
| | | // } |
| | | // } |
| | | // return taskWrk; |
| | | // } |
| | | |
| | | private TaskWrk createTask(GetWmsDto dto, String barcode) { |
| | | String wcsLocNo = dto.getLocNo(); |