| | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.core.common.Cools; |
| | | import com.core.common.R; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.controller.CrnController; |
| | | import com.zy.asrs.controller.OpenController; |
| | | import com.zy.asrs.controller.SiteController; |
| | | import com.zy.asrs.domain.dto.NotifyCustomDataDto; |
| | | import com.zy.asrs.domain.enums.NotifyMsgType; |
| | | import com.zy.asrs.domain.enums.TaskStatusType; |
| | | 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.TaskOverToWms; |
| | | import com.zy.asrs.entity.param.Result; |
| | | import com.zy.asrs.mapper.*; |
| | | import com.zy.asrs.service.*; |
| | | import com.zy.asrs.utils.CommandUtils; |
| | | import com.zy.asrs.utils.CrnOperaUtils; |
| | | import com.zy.asrs.utils.NotifyUtils; |
| | | import com.zy.asrs.utils.Utils; |
| | | import com.zy.common.service.CommonService; |
| | | import com.zy.common.utils.HttpHandler; |
| | |
| | | import com.zy.core.model.CrnSlave; |
| | | import com.zy.core.model.DevpSlave; |
| | | import com.zy.core.model.Task; |
| | | import com.zy.core.model.command.CommandPackage; |
| | | import com.zy.core.model.command.CrnCommand; |
| | | import com.zy.core.model.protocol.CrnProtocol; |
| | | import com.zy.core.model.protocol.StaProtocol; |
| | | import com.zy.core.properties.SlaveProperties; |
| | | import com.zy.core.thread.BarcodeThread; |
| | | import com.zy.core.thread.SiemensDevpThread; |
| | | import com.zy.system.entity.Config; |
| | | import com.zy.system.service.ConfigService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | private StaDescMapper staDescMapper; |
| | | @Autowired |
| | | private CommandInfoService commandInfoService; |
| | | |
| | | @Autowired |
| | | private OpenServiceImpl openServiceImpl; |
| | | @Autowired |
| | | private StaDescService staDescService; |
| | | |
| | | @Autowired |
| | | private ApiLogService apiLogService; |
| | | @Autowired |
| | | private CommonService commonService; |
| | | |
| | | @Autowired |
| | | private CrnOperaUtils crnOperaUtils; |
| | | @Autowired |
| | | private NotifyUtils notifyUtils; |
| | | @Value("${wms.count}") |
| | | private Integer maxCount; |
| | | @Autowired |
| | | private WrkMastService wrkMastService; |
| | | @Value("${wms.url}") |
| | | private String wmsUrl; |
| | | @Value("${wms.inboundTaskApplyPath}") |
| | | private String inboundTaskApplyPath; |
| | | @Value("${wms.movePath}") |
| | | private String movePath; |
| | | @Value("${wms.TaskExecCallback}") |
| | | private String TaskExecCallback; |
| | | @Value("${wms.taskStatusFeedbackPath}") |
| | | private String taskStatusFeedbackPath; |
| | | @Autowired |
| | | private CrnController crnController; |
| | | @Autowired |
| | | private SiteController siteController; |
| | | |
| | | |
| | | public void generateStoreWrkFile() throws IOException, InterruptedException { |
| | | public synchronized void generateStoreWrkFile1() { |
| | | 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 (staProtocol.isAutoing() && staProtocol.isLoading() |
| | | && staProtocol.isInEnable() |
| | | && !staProtocol.isEmptyMk() && workNo >= 9790 |
| | | && staProtocol.isPakMk()) { |
| | | // 获取条码扫描仪信息 |
| | | BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, inSta.getBarcode()); |
| | | if (barcodeThread == null) { |
| | | continue; |
| | | } |
| | | |
| | | String barcode = barcodeThread.getBarcode(); |
| | | TaskWrk taskWrk1 = taskWrkService.selectOne(new EntityWrapper<TaskWrk>().eq("barcode", barcode)); |
| | | if (taskWrk1 != null) { |
| | | log.info("托盘码:" + barcode + "任务档存在"); |
| | | continue; |
| | | } |
| | | |
| | | HashMap<String, Object> requestParam = new HashMap<>(); |
| | | requestParam.put("BoxNo", barcode);//托盘码 |
| | | requestParam.put("TerminalNo", inSta.getStaNo());//入库口 |
| | | if (back) { |
| | | requestParam.put("WCSStatus", 1);//失败 |
| | | requestParam.put("WCSErrorMessage", errMsg);//失败原因 |
| | | }else { |
| | | requestParam.put("WCSStatus", 0);//成功 |
| | | } |
| | | |
| | | String response = ""; |
| | | Boolean success = false; |
| | | try { |
| | | response = new HttpHandler.Builder() |
| | | .setUri(wmsUrl) |
| | | .setPath(inboundTaskApplyPath) |
| | | .setJson(JSON.toJSONString(requestParam)) |
| | | .build() |
| | | .doPost(); |
| | | JSONObject jsonObject = JSON.parseObject(response); |
| | | |
| | | if (back) { |
| | | devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | | MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | | continue; |
| | | } |
| | | |
| | | int returnStatus = Integer.parseInt(jsonObject.get("ReturnStatus").toString()); |
| | | if (returnStatus == 0) { |
| | | Result result = JSON.parseObject(jsonObject.get("Result").toString(), Result.class); |
| | | // 创新一个入库工作档 |
| | | TaskWrk taskWrk = taskWrkService.selectByTaskNo(result.getTaskNo()); |
| | | if(taskWrk != null) { |
| | | log.info("任务:" + result.getTaskNo() + "已经存在"); |
| | | continue; |
| | | } |
| | | |
| | | taskWrk = createTask1(result, barcode); |
| | | if (!taskWrkService.insert(taskWrk)) { |
| | | log.info("任务:" + result.getTaskNo() + "任务创建失败"); |
| | | continue; |
| | | } |
| | | |
| | | 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()); |
| | | |
| | | NotifyCustomDataDto customDataDto = new NotifyCustomDataDto(); |
| | | customDataDto.setUri(wmsUrl); |
| | | customDataDto.setPath(taskStatusFeedbackPath); |
| | | customDataDto.setData(JSON.toJSONString(hashMap)); |
| | | boolean notifyResult = notifyUtils.notify("task", 1, String.valueOf(taskWrk.getWrkNo()), taskWrk.getTaskNo(), NotifyMsgType.TASK_START, JSON.toJSONString(taskWrk), true, customDataDto); |
| | | if(notifyResult) { |
| | | taskWrk.setStatus(2); |
| | | taskWrkService.updateById(taskWrk); |
| | | } |
| | | } |
| | | } 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(requestParam) |
| | | , response |
| | | , success |
| | | ); |
| | | } |
| | | log.info("入库请求参数=" + JSON.toJSONString(barcode)); |
| | | log.info("入库请求返回参数=" + JSON.toJSONString(response)); |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("generateStoreWrkFile e", e); |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | } |
| | | } |
| | | |
| | | public synchronized void generateStoreWrkFile() throws IOException, InterruptedException { |
| | | try { |
| | | // 根据输送线plc遍历 |
| | | for (DevpSlave devp : slaveProperties.getDevp()) { |
| | | // 遍历入库口 |
| | |
| | | } |
| | | // 退回 |
| | | if (back) { |
| | | if (stano == inSta.getBackSta().shortValue()){ |
| | | if (stano == inSta.getBackSta().shortValue()) { |
| | | continue; |
| | | } |
| | | if (workNo == 0 && stano == 0){ |
| | | if (workNo == 0 && stano == 0) { |
| | | continue; |
| | | } |
| | | if (!staProtocol.isPakMk()){ |
| | | if (!staProtocol.isPakMk()) { |
| | | continue; |
| | | } |
| | | // News.warn("扫码入库失败,{}入库站因{}异常,托盘已被退回", inSta.getStaNo(), errMsg); |
| | |
| | | // 判断是否满足入库条件 |
| | | if (staProtocol.isAutoing() && staProtocol.isLoading() |
| | | && staProtocol.isInEnable() |
| | | && !staProtocol.isEmptyMk() && (workNo == 9991 ) |
| | | && !staProtocol.isEmptyMk() && (workNo >= 9899) |
| | | && staProtocol.isPakMk()) { |
| | | // 获取条码扫描仪信息 |
| | | BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, inSta.getBarcode()); |
| | |
| | | continue; |
| | | } |
| | | String barcode = barcodeThread.getBarcode(); |
| | | if(!Cools.isEmpty(barcode) && !barcode.equals("99999999")) { |
| | | 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())){ |
| | | 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+"任务档存在"); |
| | | .eq("crn_no", taskWrk1.getCrnNo()).eq("type_no", 1).eq("stn_no", staProtocol.getSiteId())); |
| | | if (Cools.isEmpty(staDesc)) { |
| | | log.info("托盘码:" + barcode + "任务档存在"); |
| | | return; |
| | | }else { |
| | | } 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"); |
| | | headParam.put("Content-Type", "application/json"); |
| | | System.out.println(JSON.toJSONString(toWmsDTO)); |
| | | String response; |
| | | try{ |
| | | try { |
| | | response = new HttpHandler.Builder() |
| | | // .setHeaders(headParam) |
| | | .setUri(wmsUrl) |
| | |
| | | .setJson(JSON.toJSONString(toWmsDTO)) |
| | | .build() |
| | | .doPost(); |
| | | }catch (Exception e){ |
| | | } catch (Exception e) { |
| | | log.error("请求入库调用接口失败"); |
| | | log.error("异常信息打印:"+e); |
| | | try{ |
| | | log.error("异常信息打印:" + e); |
| | | try { |
| | | BasDevp basDevp = basDevpService.selectById(inSta.getStaNo()); |
| | | if (Cools.isEmpty(basDevp)){ |
| | | log.error("站点号异常"+inSta.getStaNo()); |
| | | } else if (basDevp.getStaErr()!=0){ |
| | | if (Cools.isEmpty(basDevp)) { |
| | | log.error("站点号异常" + inSta.getStaNo()); |
| | | } else if (basDevp.getStaErr() != 0) { |
| | | basDevp.setStaErr(2); |
| | | basDevpService.updateById(basDevp); |
| | | } |
| | | }catch (Exception e1){ |
| | | } catch (Exception e1) { |
| | | // 退回 |
| | | log.error("扫码检测程序异常"+inSta.getStaNo()+"异常信息"+e1); |
| | | log.error("扫码检测程序异常" + inSta.getStaNo() + "异常信息" + e1); |
| | | } |
| | | staProtocol.setWorkNo((short)9999); |
| | | staProtocol.setWorkNo((short) 9999); |
| | | staProtocol.setStaNo(inSta.getStaNo().shortValue()); |
| | | devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | | MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | |
| | | } |
| | | |
| | | JSONObject jsonObject = JSON.parseObject(response); |
| | | apiLogService.save("wms请求入库货位接口" |
| | | ,wmsUrl+inboundTaskApplyPath |
| | | ,null |
| | | ,"127.0.0.1" |
| | | ,JSON.toJSONString(toWmsDTO) |
| | | ,response |
| | | ,true |
| | | ); |
| | | 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{ |
| | | try { |
| | | BasDevp basDevp = basDevpService.selectById(inSta.getStaNo()); |
| | | if (Cools.isEmpty(basDevp)){ |
| | | log.error("站点号异常1"+inSta.getStaNo()); |
| | | throw new CoolException("站点号异常1,未查询到站点信息"+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){ |
| | | if (staNoCrnNo == 0) { |
| | | basDevp.setStaErr(1); |
| | | basDevpService.updateById(basDevp); |
| | | log.error("站点号异常2"+inSta.getStaNo()); |
| | | throw new CoolException("站点号异常2,站点号不存在"+inSta.getStaNo()); |
| | | }else { |
| | | 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)){ |
| | | if (Cools.isEmpty(locMast)) { |
| | | basDevp.setStaErr(1); |
| | | basDevpService.updateById(basDevp); |
| | | log.error("站点号异常3"+inSta.getStaNo()); |
| | | throw new CoolException("站点号异常3:此巷道不存在目标库位"+inSta.getStaNo()); |
| | | log.error("站点号异常3" + inSta.getStaNo()); |
| | | throw new CoolException("站点号异常3:此巷道不存在目标库位" + inSta.getStaNo()); |
| | | } |
| | | } |
| | | } catch (Exception e){ |
| | | } catch (Exception e) { |
| | | // log.error("扫码检测程序异常"+inSta.getStaNo()+"异常信息"+e); |
| | | // 退回 |
| | | log.error("扫码检测程序异常"+inSta.getStaNo()+errMsg); |
| | | log.error("扫码检测程序异常,异常信息"+e); |
| | | log.error("扫码检测程序异常" + inSta.getStaNo() + errMsg); |
| | | log.error("扫码检测程序异常,异常信息" + e); |
| | | |
| | | staProtocol.setWorkNo((short)9999); |
| | | staProtocol.setWorkNo((short) 9999); |
| | | staProtocol.setStaNo(inSta.getStaNo().shortValue()); |
| | | devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | | MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | |
| | | continue; |
| | | } |
| | | //查看该库位是否为空库位 |
| | | LocMast locMast=locMastService.selectOne(new EntityWrapper<LocMast>() |
| | | .eq("loc_sts","O") |
| | | .eq("loc_no",getWmsDto.getLocNo())); |
| | | if(Cools.isEmpty(locMast)){ |
| | | try{ |
| | | 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); |
| | | 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) |
| | |
| | | .doPost(); |
| | | JSONObject jsonObject1 = JSON.parseObject(response2); |
| | | apiLogService.save("wcs派发库位==》不为空《==上报wms" |
| | | ,wmsUrl+taskStatusFeedbackPath |
| | | ,null |
| | | ,"127.0.0.1" |
| | | ,JSON.toJSONString(headParam1) |
| | | ,response |
| | | ,true |
| | | , wmsUrl + taskStatusFeedbackPath |
| | | , null |
| | | , "127.0.0.1" |
| | | , JSON.toJSONString(headParam1) |
| | | , response |
| | | , true |
| | | ); |
| | | }catch (Exception e){ |
| | | } catch (Exception e) { |
| | | log.error("wcs派发库位==》不为空《==上报wms", getWmsDto.getWrkNo()); |
| | | throw new CoolException("wcs派发入库任务上报wms失败,派发库位==》不为空《==,异常信息:"+e); |
| | | throw new CoolException("wcs派发入库任务上报wms失败,派发库位==》不为空《==,异常信息:" + e); |
| | | } |
| | | } |
| | | |
| | | // 创新一个入库工作档 |
| | | TaskWrk taskWrk = taskWrkService.selectByTaskNo(getWmsDto.getWrkNo()); |
| | | if(Cools.isEmpty(taskWrk)) { |
| | | taskWrk = createTask(getWmsDto,barcode); |
| | | if (Cools.isEmpty(taskWrk)){ |
| | | if (Cools.isEmpty(taskWrk)) { |
| | | taskWrk = createTask(getWmsDto, barcode); |
| | | if (Cools.isEmpty(taskWrk)) { |
| | | log.error("库位异常,库位号:{}", getWmsDto.getTargetLocationCode()); |
| | | }else { |
| | | } 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())); |
| | | .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 { |
| | | } 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.setWorkNo((short) 9999); |
| | | staProtocol.setStaNo(inSta.getStaNo().shortValue()); |
| | | devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | | MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); |
| | |
| | | /** |
| | | * 堆垛机站出库到出库站 |
| | | */ |
| | | public void crnStnToOutStn() { |
| | | public synchronized void crnStnToOutStn() { |
| | | for (CrnSlave crnSlave : slaveProperties.getCrn()) { |
| | | // 遍历堆垛机出库站 |
| | | for (CrnSlave.CrnStn crnStn : crnSlave.getCrnOutStn()) { |
| | | List<StaDesc> staDescs = staDescMapper.selectList(new EntityWrapper<StaDesc>().eq("crn_no", crnSlave.getId()).eq("crn_stn", crnStn.getStaNo())); |
| | | for (StaDesc staDesc : staDescs){ |
| | | try{ |
| | | for (StaDesc staDesc : staDescs) { |
| | | try { |
| | | // 获取堆垛机出库站信息 |
| | | DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, crnStn.getDevpPlcId()); |
| | | StaProtocol staProtocol = devpThread.getStation().get(crnStn.getStaNo()); |
| | |
| | | if (taskWrk == null) { |
| | | continue; |
| | | } |
| | | log.info("下发输送线任务:taskWrk:"+JSON.toJSONString(taskWrk)); |
| | | log.info("下发输送线任务:taskWrk:" + JSON.toJSONString(taskWrk)); |
| | | // R r = siteController.siteDetlUpdate(Integer.valueOf(taskWrk.getTargetPoint()), taskWrk.getWrkNo().shortValue(), (short) 0, "Y", false, false); |
| | | staProtocol.setWorkNo(taskWrk.getWrkNo().shortValue()); |
| | | staProtocol.setStaNo(staDesc.getCrnStn().shortValue()); |
| | | staProtocol.setStaNo(staDesc.getStnNo().shortValue()); |
| | | boolean offer = false; |
| | | try{ |
| | | try { |
| | | offer = MessageQueue.offer(SlaveType.Devp, 1, new Task(2, staProtocol)); |
| | | }catch (Exception e){ |
| | | log.error("下发输送线任务失败:异常:"+e); |
| | | log.error("下发输送线任务失败:异常:offer:"+offer); |
| | | } catch (Exception e) { |
| | | log.error("下发输送线任务失败:异常:" + e); |
| | | log.error("下发输送线任务失败:异常:offer:" + offer); |
| | | } |
| | | // JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(r)); |
| | | if (offer){ |
| | | log.info("下发输送线任务成功:taskWrk:"+JSON.toJSONString(taskWrk)); |
| | | if (offer) { |
| | | log.info("下发输送线任务成功:taskWrk:" + JSON.toJSONString(taskWrk)); |
| | | taskWrk.setStatus(5); |
| | | taskWrk.setWrkSts(14); |
| | | taskWrkService.updateById(taskWrk); |
| | | }else { |
| | | log.error("下发输送线任务失败:taskWrk:"+JSON.toJSONString(taskWrk)); |
| | | |
| | | } else { |
| | | log.error("下发输送线任务失败:taskWrk:" + JSON.toJSONString(taskWrk)); |
| | | // log.error("下发输送线任务失败:异常信息:"+JSON.toJSONString(r)); |
| | | } |
| | | } |
| | | }catch (Exception e){ |
| | | log.error("出库到出库站异常:异常信息:"+e); |
| | | } catch (Exception e) { |
| | | log.error("出库到出库站异常:异常信息:" + e); |
| | | } |
| | | } |
| | | |
| | |
| | | // 获取堆垛机信息 |
| | | CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crn.getId()); |
| | | CrnProtocol crnProtocol = crnThread.getCrnProtocol(); |
| | | if (crnProtocol == null) { continue; } |
| | | if (crnProtocol == null) { |
| | | continue; |
| | | } |
| | | BasCrnp basCrnp = basCrnpService.selectById(crn.getId()); |
| | | if (basCrnp == null) { |
| | | log.error("{}号堆垛机尚未在数据库进行维护!", crn.getId()); |
| | | continue; |
| | | } |
| | | |
| | | // 库位移转 |
| | | this.locToLoc(crn, crnProtocol); |
| | | |
| | | // 只有当堆垛机空闲 并且 无任务时才继续执行 |
| | | if (crnProtocol.getStatusType() == CrnStatusType.IDLE && crnProtocol.getTaskNo() == 0 && crnProtocol.getModeType() == CrnModeType.AUTO |
| | |
| | | crnProtocol.setLastIo("O"); |
| | | } |
| | | } |
| | | |
| | | // 库位移转 |
| | | this.locToLoc(crn, crnProtocol); |
| | | } |
| | | |
| | | } |
| | |
| | | /** |
| | | * 入库 ===>> 堆垛机站到库位 |
| | | */ |
| | | public void crnStnToLoc(CrnSlave slave, CrnProtocol crnProtocol) throws IOException { |
| | | public synchronized void crnStnToLoc(CrnSlave slave, CrnProtocol crnProtocol) throws IOException { |
| | | for (CrnSlave.CrnStn crnStn : slave.getCrnInStn()) { |
| | | List<StaDesc> staDescs = staDescMapper.selectList(new EntityWrapper<StaDesc>().eq("crn_no", slave.getId()).eq("crn_stn", crnStn.getStaNo())); |
| | | for (StaDesc staDesc : staDescs) { |
| | |
| | | continue; |
| | | } |
| | | if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.getWorkNo() > 0 && staProtocol.isInEnable() |
| | | && staDetl.getCanining()!=null && staDetl.getCanining().equals("Y")) { |
| | | && staDetl.getCanining() != null && staDetl.getCanining().equals("Y")) { |
| | | flag = true; |
| | | } |
| | | if (!flag) { |
| | | continue; |
| | | } |
| | | |
| | | |
| | | // 获取工作状态为2(设备上走)的入库工作档 |
| | | TaskWrk taskWrk = taskWrkMapper.selectPakIn(slave.getId(), staProtocol.getWorkNo().intValue(), staDesc.getStnNo().toString()); |
| | | if(null == taskWrk) { |
| | | if (null == taskWrk) { |
| | | continue; |
| | | } |
| | | |
| | |
| | | continue; |
| | | } |
| | | |
| | | // int workNo = commonService.getWorkNo(WorkNoType.PAKIN.type);//获取入库工作号 |
| | | // taskWrk.setWrkNo(workNo);//工作号 |
| | | taskWrk.setStatus(TaskStatusType.DISTRIBUTE.id);//派发状态 |
| | | taskWrk.setAssignTime(new Date());//派发时间 |
| | | taskWrk.setWrkSts(3);//工作状态 3.吊车入库 |
| | | taskWrk.setCrnNo(staDesc.getCrnNo());//堆垛机号 |
| | | taskWrk.setModiTime(new Date()); |
| | | taskWrk.setModiUser(9988L); |
| | | |
| | | // //取出命令 |
| | | // List<CommandInfo> commandInfos = commandInfoService.selectByTaskNo(taskWrk.getTaskNo()); |
| | | // Integer commandStep = taskWrk.getCommandStep(); |
| | | // if (commandInfos.isEmpty()) { |
| | | // continue;//命令空 |
| | | // } |
| | | // CommandInfo commandInfo = commandInfos.get(commandStep); |
| | | // CommandPackage commandPackage = JSON.parseObject(commandInfo.getCommand(), CommandPackage.class);//取出命令报文 |
| | | // CrnCommand crnCommand = JSON.parseObject(commandPackage.getCommand().toString(), CrnCommand.class); |
| | | // |
| | | // if (!MessageQueue.offer(SlaveType.Crn, taskWrk.getCrnNo(), new Task(2, crnCommand))) { |
| | | // log.error("堆垛机命令下发失败,堆垛机号={},任务数据={}", taskWrk.getCrnNo(), JSON.toJSON(crnCommand)); |
| | | // } else { |
| | | // // 修改工作档状态 2.设备上走 => 3.吊车入库中 |
| | | // Date now = new Date(); |
| | | // taskWrk.setWrkSts(3); |
| | | // taskWrk.setModiTime(now); |
| | | // if (taskWrkMapper.updateById(taskWrk) == 0) { |
| | | // log.error("修改工作档状态 2.设备上走 => 3.吊车入库中 失败!!,工作号={}", taskWrk.getWrkNo()); |
| | | // } |
| | | // //开始运行 |
| | | // String response = CrnStartRunning(taskWrk); |
| | | // JSONObject jsonObject = JSON.parseObject(response); |
| | | // if (jsonObject.getInteger("code").equals(200)) { |
| | | // |
| | | // }else { |
| | | // log.error("入库开始运行通讯失败,"+jsonObject.get("msg")); |
| | | // |
| | | // } |
| | | // } |
| | | |
| | | // 命令下发区 -------------------------------------------------------------------------- |
| | | CrnCommand crnCommand = new CrnCommand(); |
| | |
| | | crnCommand.setDestinationPosX(Utils.getRowShort(taskWrk.getTargetPoint())); // 目标库位列 |
| | | crnCommand.setDestinationPosY(Utils.getBayShort(taskWrk.getTargetPoint())); // 目标库位层 |
| | | crnCommand.setDestinationPosZ(Utils.getLevShort(taskWrk.getTargetPoint())); // 目标库位排 |
| | | crnCommand.setCommand((short)1); |
| | | if (!CommandUtils.offer(SlaveType.Crn, taskWrk.getCrnNo(), new Task(2, crnCommand),false)) { |
| | | crnCommand.setCommand((short) 1); |
| | | log.info("堆垛机入库任务下发={}",crnCommand); |
| | | if (!CommandUtils.offer(SlaveType.Crn, taskWrk.getCrnNo(), new Task(2, crnCommand), false)) { |
| | | log.error("堆垛机命令生成失败,堆垛机号={},任务数据={}", taskWrk.getCrnNo(), JSON.toJSON(crnCommand)); |
| | | throw new CoolException("堆垛机命令生成失败"); |
| | | }else{ |
| | | try{ |
| | | } else { |
| | | try { |
| | | taskWrkService.updateById(taskWrk); |
| | | }catch (Exception e){ |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error("修改工作档状态 2.设备上走 => 3.吊车入库中 失败!!,工作号={}", taskWrk.getWrkNo()); |
| | | log.error("修改工作档状态 2.设备上走 => 3.吊车入库中 失败!!,异常:"+e); |
| | | } |
| | | try{ |
| | | HashMap<String, Object> headParam = new HashMap<>(); |
| | | headParam.put("taskNo",taskWrk.getTaskNo()); |
| | | headParam.put("status",taskWrk.getStatus()); |
| | | headParam.put("ioType",taskWrk.getIoType()); |
| | | headParam.put("barcode",taskWrk.getBarcode()); |
| | | String response; |
| | | response = new HttpHandler.Builder() |
| | | // .setHeaders(headParam) |
| | | .setUri(wmsUrl) |
| | | .setPath(taskStatusFeedbackPath) |
| | | .setJson(JSON.toJSONString(headParam)) |
| | | .build() |
| | | .doPost(); |
| | | JSONObject jsonObject = JSON.parseObject(response); |
| | | apiLogService.save("wcs派发入库任务上报wms" |
| | | ,wmsUrl+taskStatusFeedbackPath |
| | | ,null |
| | | ,"127.0.0.1" |
| | | ,JSON.toJSONString(headParam) |
| | | ,response |
| | | ,true |
| | | ); |
| | | } catch (Exception e){ |
| | | log.error("wcs派发入库任务上报wms失败", JSON.toJSONString(taskWrk)); |
| | | // throw new CoolException("wcs派发入库任务上报wms失败"); |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | // return; |
| | | } |
| | | } |
| | | |
| | |
| | | * 出库 ===>> 库位到堆垛机站 |
| | | * 2022-06-09 TQS修改,查询工作档LIST,遍历下发,防止第一个任务堵塞出库 |
| | | */ |
| | | public void locToCrnStn(CrnSlave slave, CrnProtocol crnProtocol){ |
| | | public synchronized void locToCrnStn(CrnSlave slave, CrnProtocol crnProtocol) { |
| | | List<TaskWrk> taskWrksInitial = taskWrkMapper.selectPakOut(slave.getId(), null); |
| | | if (taskWrksInitial.size()==0){ |
| | | if (taskWrksInitial.isEmpty()) { |
| | | return; |
| | | } |
| | | for (CrnSlave.CrnStn crnStn : slave.getCrnOutStn()) { |
| | | List<StaDesc> staDescs = staDescMapper.selectList(new EntityWrapper<StaDesc>().eq("crn_no", slave.getId()).eq("crn_stn", crnStn.getStaNo())); |
| | | for (StaDesc staDesc : staDescs){ |
| | | for (StaDesc staDesc : staDescs) { |
| | | // 获取工作状态为11(生成出库ID)的出库工作档 |
| | | List<TaskWrk> taskWrks = taskWrkMapper.selectPakOut(slave.getId(),staDesc.getStnNo().toString()); |
| | | for (TaskWrk taskWrk : taskWrks){ |
| | | List<TaskWrk> taskWrks = taskWrkMapper.selectPakOut(slave.getId(), staDesc.getStnNo().toString()); |
| | | for (TaskWrk taskWrk : taskWrks) { |
| | | if (taskWrk == null) { |
| | | continue; |
| | | } |
| | |
| | | log.error("查询工作档数据不符合条件--入出类型/站点, 工作号={},源库位={},入出类型={}", taskWrk.getWrkNo(), taskWrk.getStartPoint(), taskWrk.getIoType()); |
| | | continue; |
| | | } |
| | | |
| | | LocMast locMast=locMastService.selectByLocNo(taskWrk.getStartPoint()); |
| | | //判断其库位是否为深库位,如果为深库位找其浅库位是都有货 |
| | | if(locMast.getRow1()==1||locMast.getRow1()==5){ |
| | | LocMast locMast1=locMastService.selectOne(new EntityWrapper<LocMast>() |
| | | .eq("row1", (locMast.getRow1()+1)) |
| | | .eq("bay1",locMast.getBay1()) |
| | | .eq("lev1",locMast.getLev1()).eq("loc_sts","F")); |
| | | if (!Cools.isEmpty(locMast1)){ |
| | | log.info(locMast.getLocNo()+"出深库位,浅库位有货"); |
| | | continue; |
| | | } |
| | | }else if(locMast.getRow1()==4||locMast.getRow1()==8){ |
| | | LocMast locMast1=locMastService.selectOne(new EntityWrapper<LocMast>() |
| | | .eq("row1", (locMast.getRow1()-1)) |
| | | .eq("bay1",locMast.getBay1()) |
| | | .eq("lev1",locMast.getLev1()).eq("loc_sts","F")); |
| | | if (!Cools.isEmpty(locMast1)){ |
| | | log.info(locMast.getLocNo()+"出深库位,浅库位有货"); |
| | | continue; |
| | | } |
| | | } |
| | | |
| | | // 获取堆垛机出库站信息 |
| | | SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, crnStn.getDevpPlcId()); |
| | | StaProtocol staProtocol = devpThread.getStation().get(crnStn.getStaNo()); |
| | |
| | | } |
| | | |
| | | // 判断堆垛机出库站状态 |
| | | if (staProtocol.isAutoing() && !staProtocol.isLoading() && staDetl.getCanouting() !=null && staDetl.getCanouting().equals("Y") |
| | | if (staProtocol.isAutoing() && !staProtocol.isLoading() && staDetl.getCanouting() != null && staDetl.getCanouting().equals("Y") |
| | | && staProtocol.getWorkNo() == 0 && staProtocol.isOutEnable()) { |
| | | // 命令下发区 -------------------------------------------------------------------------- |
| | | |
| | |
| | | if (!crnProtocol.getStatusType().equals(CrnStatusType.IDLE) || crnProtocol.getTaskNo() != 0) { |
| | | break; |
| | | } |
| | | int storeCount = basDevpService.getStoreCount(); |
| | | if(storeCount >= maxCount){ |
| | | log.error("输送线暂存数达到上限{}",storeCount); |
| | | break; |
| | | } |
| | | |
| | | |
| | | // 已经存在吊车执行任务时,则过滤 |
| | | if (taskWrkMapper.selectCrnWorking(slave.getId()) != null) { |
| | | break; |
| | | } |
| | | |
| | | CrnCommand command = new CrnCommand(); |
| | | command.setCrnNo(taskWrk.getCrnNo()); // 堆垛机编号 |
| | | command.setTaskNo(taskWrk.getWrkNo().shortValue()); // 工作号 |
| | |
| | | command.setDestinationPosX(crnStn.getRow().shortValue()); // 目标库位排 |
| | | command.setDestinationPosY(crnStn.getBay().shortValue()); // 目标库位列 |
| | | command.setDestinationPosZ(crnStn.getLev().shortValue()); // 目标库位层 |
| | | command.setCommand((short)1); |
| | | if (!CommandUtils.offer(SlaveType.Crn, taskWrk.getCrnNo(), new Task(2, command),false)) { |
| | | command.setCommand((short) 1); |
| | | |
| | | if (!CommandUtils.offer(SlaveType.Crn, taskWrk.getCrnNo(), new Task(2, command), false)) { |
| | | log.error("堆垛机命令生成失败,堆垛机号={},任务数据={}", taskWrk.getCrnNo(), JSON.toJSON(command)); |
| | | throw new CoolException("堆垛机命令生成失败"); |
| | | }else{ |
| | | try{ |
| | | } else { |
| | | try { |
| | | // 修改工作档状态 11.生成出库ID => 12.吊车出库中 |
| | | Date now = new Date(); |
| | | taskWrk.setWrkSts(12); |
| | | taskWrk.setStatus(2); |
| | | taskWrk.setModiTime(now); |
| | | if (taskWrkMapper.updateById(taskWrk) == 0) { |
| | | log.error("修改工作档状态 11.生成出库ID => 12.吊车出库中 失败!!,工作号={}", taskWrk.getWrkNo()); |
| | | } |
| | | }catch (Exception e){ |
| | | } catch (Exception e) { |
| | | log.error("修改工作档状态 11.生成出库ID => 12.吊车出库中 失败!!,工作号={}", taskWrk.getWrkNo()); |
| | | log.error("修改工作档状态 11.生成出库ID => 12.吊车出库中 失败!!,异常:"+e); |
| | | log.error("修改工作档状态 11.生成出库ID => 12.吊车出库中 失败!!,异常:" + e); |
| | | } |
| | | try{ |
| | | HashMap<String, Object> headParam = new HashMap<>(); |
| | | headParam.put("taskNo",taskWrk.getTaskNo()); |
| | | headParam.put("status",taskWrk.getStatus()); |
| | | headParam.put("ioType",taskWrk.getIoType()); |
| | | headParam.put("barcode",taskWrk.getBarcode()); |
| | | String response; |
| | | response = new HttpHandler.Builder() |
| | | // .setHeaders(headParam) |
| | | .setUri(wmsUrl) |
| | | .setPath(taskStatusFeedbackPath) |
| | | .setJson(JSON.toJSONString(headParam)) |
| | | .build() |
| | | .doPost(); |
| | | JSONObject jsonObject = JSON.parseObject(response); |
| | | apiLogService.save("wcs派发出库任务上报wms" |
| | | ,wmsUrl+taskStatusFeedbackPath |
| | | ,null |
| | | ,"127.0.0.1" |
| | | ,JSON.toJSONString(headParam) |
| | | ,response |
| | | ,true |
| | | ); |
| | | }catch (Exception e){ |
| | | log.error("wcs派发出库任务上报wms失败", JSON.toJSONString(taskWrk)); |
| | | // throw new CoolException("wcs派发入库任务上报wms失败"); |
| | | |
| | | //上报-出库任务开始时,WCS回调WMS |
| | | HashMap<String, Object> hashMap = new HashMap<>(); |
| | | hashMap.put("TaskNo", taskWrk.getTaskNo()); |
| | | |
| | | NotifyCustomDataDto customDataDto = new NotifyCustomDataDto(); |
| | | customDataDto.setUri(wmsUrl); |
| | | customDataDto.setPath(taskStatusFeedbackPath); |
| | | customDataDto.setData(JSON.toJSONString(hashMap)); |
| | | boolean notifyResult = notifyUtils.notify("task", 1, String.valueOf(taskWrk.getWrkNo()), taskWrk.getTaskNo(), NotifyMsgType.TASK_START, JSON.toJSONString(taskWrk), true, customDataDto); |
| | | if(notifyResult) { |
| | | taskWrk.setStatus(2); |
| | | taskWrkService.updateById(taskWrk); |
| | | } |
| | | } |
| | | } |
| | |
| | | /** |
| | | * 库位移转 |
| | | */ |
| | | public void locToLoc(CrnSlave slave, CrnProtocol crnProtocol){ |
| | | public synchronized void locToLoc(CrnSlave slave, CrnProtocol crnProtocol) { |
| | | for (CrnSlave.CrnStn crnStn : slave.getCrnOutStn()) { |
| | | // 获取工作状态为11(生成出库ID)的移库工作档 |
| | | List<TaskWrk> taskWrks = taskWrkMapper.selectList(new EntityWrapper<TaskWrk>() |
| | | .eq("crn_no",slave.getId()) |
| | | .eq("wrk_sts",11) |
| | | .eq("io_type",3)); |
| | | for (TaskWrk taskWrk : taskWrks){ |
| | | .eq("crn_no", slave.getId()) |
| | | .eq("wrk_sts", 11) |
| | | .eq("io_type", 3) |
| | | .orderBy("io_pri", false)); |
| | | for (TaskWrk taskWrk : taskWrks) { |
| | | |
| | | // 双深库位且浅库位有货,则需先对浅库位进行库位移转 |
| | | // if (Utils.isDeepLoc(slaveProperties, taskWrk.getStartPoint())) { |
| | |
| | | // 命令下发区 -------------------------------------------------------------------------- |
| | | |
| | | |
| | | |
| | | |
| | | // 1.堆垛机开始移动 |
| | | CrnCommand crnCommand = new CrnCommand(); |
| | | crnCommand.setCrnNo(slave.getId()); // 堆垛机编号 |
| | |
| | | crnCommand.setDestinationPosY(Utils.getBayShort(taskWrk.getTargetPoint())); // 目标库位列 |
| | | crnCommand.setDestinationPosZ(Utils.getLevShort(taskWrk.getTargetPoint())); // 目标库位层 |
| | | crnCommand.setCommand((short) 1); |
| | | if (!CommandUtils.offer(SlaveType.Crn, taskWrk.getCrnNo(), new Task(2, crnCommand),false)) { |
| | | if (!CommandUtils.offer(SlaveType.Crn, taskWrk.getCrnNo(), new Task(2, crnCommand), false)) { |
| | | log.error("堆垛机命令下发失败,堆垛机号={},任务数据={}", taskWrk.getCrnNo(), JSON.toJSON(crnCommand)); |
| | | } else { |
| | | // 修改工作档状态 11.生成出库ID => 12.吊车出库中 |
| | | Date now = new Date(); |
| | | taskWrk.setWrkSts(12); |
| | | taskWrk.setStatus(2); |
| | | taskWrk.setModiTime(now); |
| | | if (taskWrkMapper.updateById(taskWrk) == 0) { |
| | | log.error("修改工作档状态 11.生成出库ID => 12.吊车出库中 失败!!,工作号={}", taskWrk.getWrkNo()); |
| | | } |
| | | try{ |
| | | HashMap<String, Object> headParam = new HashMap<>(); |
| | | headParam.put("taskNo",taskWrk.getTaskNo()); |
| | | headParam.put("status",taskWrk.getStatus()); |
| | | headParam.put("ioType",taskWrk.getIoType()); |
| | | headParam.put("barcode",taskWrk.getBarcode()); |
| | | String response; |
| | | String response = ""; |
| | | Boolean bool=false; |
| | | HashMap<String, Object> headParam = new HashMap<>(); |
| | | headParam.put("TaskNo", taskWrk.getTaskNo()); |
| | | try { |
| | | response = new HttpHandler.Builder() |
| | | // .setHeaders(headParam) |
| | | .setUri(wmsUrl) |
| | |
| | | .build() |
| | | .doPost(); |
| | | JSONObject jsonObject = JSON.parseObject(response); |
| | | apiLogService.save("wcs派发移库任务上报wms" |
| | | ,wmsUrl+taskStatusFeedbackPath |
| | | ,null |
| | | ,"127.0.0.1" |
| | | ,JSON.toJSONString(headParam) |
| | | ,response |
| | | ,true |
| | | ); |
| | | }catch (Exception e){ |
| | | if(jsonObject.get("ReturnStatus").equals(0)){ |
| | | bool = true; |
| | | taskWrk.setStatus(2); |
| | | taskWrkMapper.updateById(taskWrk); |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | log.error("wcs派发移库库任务上报wms失败", taskWrk); |
| | | // throw new CoolException("wcs派发移库库任务上报wms失败"); |
| | | }finally { |
| | | apiLogService.save("wcs派发移库任务上报wms" |
| | | , wmsUrl + taskStatusFeedbackPath |
| | | , null |
| | | , "127.0.0.1" |
| | | , JSON.toJSONString(headParam) |
| | | , response |
| | | , bool |
| | | ); |
| | | } |
| | | |
| | | } |
| | |
| | | /** |
| | | * 执行对工作档的完成操作 |
| | | */ |
| | | public void storeFinished() throws InterruptedException { |
| | | public synchronized void storeFinished() throws InterruptedException { |
| | | for (CrnSlave crn : slaveProperties.getCrn()) { |
| | | // 获取堆垛机信息 |
| | | CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crn.getId()); |
| | | CrnProtocol crnProtocol = crnThread.getCrnProtocol(); |
| | | if (crnProtocol == null) { continue; } |
| | | if (crnProtocol == null) { |
| | | continue; |
| | | } |
| | | |
| | | // 状态:等待确认 并且 任务完成位 = 1 |
| | | if (crnProtocol.getTaskFinish() == 0 && crnProtocol.statusType == CrnStatusType.HANDLING_COMPLETED && crnProtocol.getTaskNo() != 0) { |
| | | //获取入库待确认工作档 |
| | | TaskWrk taskWrk = taskWrkMapper.selectCrnNoInWorking(crn.getId(),crnProtocol.getTaskNo().intValue()); |
| | | if (Cools.isEmpty(taskWrk)&&crnProtocol.getTaskNo() !=999) { |
| | | TaskWrk taskWrk = taskWrkMapper.selectCrnNoInWorking(crn.getId(), crnProtocol.getTaskNo().intValue()); |
| | | if (Cools.isEmpty(taskWrk) && crnProtocol.getTaskNo() != 999) { |
| | | log.error("堆垛机处于等待确认且任务完成状态,但未找到工作档。堆垛机号={},工作号={}", crn.getId(), crnProtocol.getTaskNo()); |
| | | continue; |
| | | } |
| | | Thread.sleep(300); |
| | | //确认完成信号 |
| | | CrnOperatorParam crnOperatorParam=new CrnOperatorParam(); |
| | | crnOperatorParam.setCrnNo(crn.getId()); |
| | | |
| | | crnController.crnTaskComplete(crnOperatorParam); |
| | | if(!Cools.isEmpty(taskWrk)){ |
| | | if(taskWrk.getIoType()==1 && taskWrk.getWrkSts()==3){ |
| | | boolean result = crnOperaUtils.crnTaskComplete(crn.getId()); |
| | | Thread.sleep(1000); |
| | | if(!result){ |
| | | return; |
| | | } |
| | | if (!Cools.isEmpty(taskWrk)) { |
| | | if (taskWrk.getIoType() == 1 && taskWrk.getWrkSts() == 3) { |
| | | taskWrk.setWrkSts(4);//入库完成 |
| | | taskWrk.setStatus(5);//完结 |
| | | |
| | | //更新库位状态 |
| | | LocMast locMast = locMastService.selectByLocNo(taskWrk.getTargetPoint()); |
| | | locMast.setLocSts("F");//F.在库 |
| | |
| | | locMast.setModiTime(new Date()); |
| | | locMast.setModiUser(9999L); |
| | | locMastService.updateById(locMast); |
| | | }else if(taskWrk.getIoType()==2&&taskWrk.getWrkSts()==12){ |
| | | } else if (taskWrk.getIoType() == 2 && taskWrk.getWrkSts() == 12) { |
| | | taskWrk.setWrkSts(13);//出库完成 |
| | | taskWrk.setStatus(5);//完结 |
| | | |
| | | //更新库位状态 |
| | | LocMast locMast = locMastService.selectByLocNo(taskWrk.getStartPoint()); |
| | | locMast.setLocSts("O");//O.空库位 |
| | |
| | | locMast.setModiTime(new Date()); |
| | | locMast.setModiUser(9999L); |
| | | locMastService.updateById(locMast); |
| | | }else if(taskWrk.getIoType()==3&&taskWrk.getWrkSts()==12){ |
| | | } else if (taskWrk.getIoType() == 3 && taskWrk.getWrkSts() == 12) { |
| | | taskWrk.setWrkSts(4);//入库完成 |
| | | taskWrk.setStatus(5);//完结 |
| | | //更新库位状态 |
| | |
| | | locMastService.updateById(locMast1); |
| | | } |
| | | taskWrkService.updateById(taskWrk); |
| | | |
| | | |
| | | try{ |
| | | HashMap<String, Object> headParam = new HashMap<>(); |
| | | headParam.put("taskNo",taskWrk.getTaskNo()); |
| | | headParam.put("status",taskWrk.getStatus()); |
| | | headParam.put("ioType",taskWrk.getIoType()); |
| | | headParam.put("barcode",taskWrk.getBarcode()); |
| | | String response; |
| | | log.error("wcs完结任务上报wms==》", headParam); |
| | | |
| | | response = new HttpHandler.Builder() |
| | | // .setHeaders(headParam) |
| | | .setUri(wmsUrl) |
| | | .setPath(taskStatusFeedbackPath) |
| | | .setJson(JSON.toJSONString(headParam)) |
| | | .build() |
| | | .doPost(); |
| | | log.error("wcs完结任务上报wms==》", response); |
| | | |
| | | // JSONObject jsonObject = JSON.parseObject(response); |
| | | // log.error("wcs完结任务上报wms==》", jsonObject); |
| | | |
| | | apiLogService.save("wcs派发入库任务上报wms" |
| | | ,wmsUrl+taskStatusFeedbackPath |
| | | ,null |
| | | ,"127.0.0.1" |
| | | ,JSON.toJSONString(headParam) |
| | | ,response |
| | | ,true |
| | | ); |
| | | }catch (Exception e){ |
| | | log.error("wcs完结任务上报wms失败", taskWrk); |
| | | log.error("wcs完结任务上报wms失败,报错信息:", e); |
| | | // throw new CoolException("wcs派发入库任务上报wms失败"); |
| | | } |
| | | } |
| | | |
| | | } |
| | |
| | | /** |
| | | * 堆垛机异常信息记录 |
| | | */ |
| | | public void recCrnErr(){ |
| | | public synchronized void recCrnErr() { |
| | | Date now = new Date(); |
| | | for (CrnSlave crn : slaveProperties.getCrn()) { |
| | | // 获取堆垛机信息 |
| | |
| | | continue; |
| | | } |
| | | BasCrnError crnError = basCrnErrorMapper.selectById(crnProtocol.getAlarm()); |
| | | String errName = crnError==null? String.valueOf(crnProtocol.getAlarm()):crnError.getErrName(); |
| | | String errName = crnError == null ? String.valueOf(crnProtocol.getAlarm()) : crnError.getErrName(); |
| | | BasErrLog basErrLog = new BasErrLog( |
| | | null, // 编号 |
| | | wrkMast.getWrkNo(), // 工作号 |
| | |
| | | // 记录新异常 |
| | | if (latest == null || (latest.getErrCode() != crnProtocol.getAlarm().intValue())) { |
| | | BasCrnError crnError = basCrnErrorMapper.selectById(crnProtocol.getAlarm()); |
| | | String errName = crnError==null? String.valueOf(crnProtocol.getAlarm()):crnError.getErrName(); |
| | | String errName = crnError == null ? String.valueOf(crnProtocol.getAlarm()) : crnError.getErrName(); |
| | | BasErrLog basErrLog = new BasErrLog( |
| | | null, // 编号 |
| | | null, // 工作号 |
| | |
| | | null, // 源站 |
| | | null, // 源库位 |
| | | null, // 条码 |
| | | (int)crnProtocol.getAlarm1(), // 异常码 |
| | | (int) crnProtocol.getAlarm1(), // 异常码 |
| | | errName, // 异常 |
| | | 1, // 异常情况 |
| | | now, // 添加时间 |
| | |
| | | } |
| | | } |
| | | |
| | | //自动派发任务 |
| | | public void autoDistribute() { |
| | | Config config = configService.selectByCode("autoDistribute"); |
| | | if (config == null) { |
| | | return; |
| | | } |
| | | // //自动派发任务 |
| | | // public synchronized void autoDistribute() { |
| | | // Config config = configService.selectByCode("autoDistribute"); |
| | | // if (config == null) { |
| | | // return; |
| | | // } |
| | | // |
| | | // if (config.getValue().equals("false")) {//判断是否开启自动派发任务 |
| | | // return; |
| | | // } |
| | | // |
| | | // for (TaskWrk taskWrk : taskWrkService.selectReceive()) { |
| | | // |
| | | // try { |
| | | // taskWrkService.distribute(taskWrk.getTaskNo(), 9527L); |
| | | // } catch (CoolException e) { |
| | | // log.info(e.getMessage()); |
| | | // } |
| | | // } |
| | | // } |
| | | |
| | | if (config.getValue().equals("false")) {//判断是否开启自动派发任务 |
| | | return; |
| | | } |
| | | |
| | | for (TaskWrk taskWrk : taskWrkService.selectReceive()) { |
| | | |
| | | try { |
| | | taskWrkService.distribute(taskWrk.getTaskNo(), 9527L); |
| | | } catch (CoolException e) { |
| | | log.info(e.getMessage()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | //agv取放货任务完成 |
| | | public synchronized void autoCompleteAGV() { |
| | | List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<>()); |
| | | try{ |
| | | Thread.sleep(500); |
| | | }catch (Exception e){ |
| | | |
| | | } |
| | | |
| | | for (BasDevp basDevp:basDevps){ |
| | | DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, 1); |
| | | StaProtocol staProtocol = devpThread.getStation().get(basDevp.getDevNo()); |
| | | if (staProtocol == null) { |
| | | continue; |
| | | } else { |
| | | staProtocol = staProtocol.clone(); |
| | | } |
| | | if (basDevp.getWrkNo()!=0){ |
| | | if (basDevp.getAgvTargetPick()!=0){//取货 |
| | | staProtocol.setAgvTypeSign((short)0); |
| | | staProtocol.setStaNo(basDevp.getDevNo().shortValue()); |
| | | MessageQueue.offer(SlaveType.Devp, 1, new Task(4, staProtocol)); |
| | | } |
| | | boolean sign = true; |
| | | if (basDevp.getAgvTargetPlace()!=0){ |
| | | sign = false; |
| | | basDevp.setAgvTargetPlace(0); |
| | | basDevpService.updateById(basDevp); |
| | | staProtocol.setAgvTypeSign((short)3);//1 |
| | | staProtocol.setStaNo(basDevp.getDevNo().shortValue()); |
| | | MessageQueue.offer(SlaveType.Devp, 1, new Task(4, staProtocol)); |
| | | } |
| | | }else { |
| | | if (basDevp.getAgvTargetPlace()!=0){ |
| | | if (basDevp.getLoading().equals("Y")){ |
| | | staProtocol.setAgvTypeSign((short)1); |
| | | staProtocol.setStaNo(basDevp.getDevNo().shortValue()); |
| | | MessageQueue.offer(SlaveType.Devp, 1, new Task(4, staProtocol)); |
| | | }else { |
| | | log.error("AGV放货完成但输送线无物,复位信号 ===>> [staNo:{}] [basDevp:{}]", basDevp.getDevNo(), basDevp); |
| | | basDevp.setAgvTargetPlace(0); |
| | | basDevpService.updateById(basDevp); |
| | | staProtocol.setAgvTypeSign((short)3);//1 |
| | | staProtocol.setStaNo(basDevp.getDevNo().shortValue()); |
| | | MessageQueue.offer(SlaveType.Devp, 1, new Task(4, staProtocol)); |
| | | } |
| | | |
| | | } |
| | | if (basDevp.getAgvTargetPick()!=0){ |
| | | basDevp.setAgvTargetPick(0); |
| | | basDevpService.updateById(basDevp); |
| | | staProtocol.setAgvTypeSign((short)2);//0 |
| | | staProtocol.setStaNo(basDevp.getDevNo().shortValue()); |
| | | MessageQueue.offer(SlaveType.Devp, 1, new Task(4, staProtocol)); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | public synchronized void autoCompleteTask() { |
| | | List<TaskWrk> taskWrks = taskWrkMapper.selectWorkingTask(); |
| | | for (TaskWrk taskWrk : taskWrks) { |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | public synchronized String CrnStartRunning(TaskWrk taskWrk){ |
| | | String tasktype = null; |
| | | switch (taskWrk.getIoType()){ |
| | | case 1: |
| | | tasktype= "RK"; |
| | | break; |
| | | case 2: |
| | | tasktype= "CK"; |
| | | break; |
| | | case 3: |
| | | tasktype= "YK"; |
| | | break; |
| | | default: |
| | | tasktype= "未知"; |
| | | } |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("x-api-key","7a15b5db-29b6-552c-8cff-0cfec3756da2"); |
| | | TaskOverToWms taskOverToWms = new TaskOverToWms(); |
| | | taskOverToWms.setFeedbackFrom("WCS"); //来源 |
| | | taskOverToWms.setWarehouseId("1688469798893297665"); //仓库标识 |
| | | taskOverToWms.setTaskNo(taskWrk.getTaskNo()); //任务号 |
| | | taskOverToWms.setTaskType(tasktype); // 任务类型 |
| | | taskOverToWms.setContainerCode(taskWrk.getBarcode()); // 容器编码 |
| | | if (taskWrk.getIoType() ==1 || taskWrk.getIoType() == 3){ |
| | | taskOverToWms.setEquipmentCode(String.valueOf(taskWrk.getCrnNo())); //设备编码 |
| | | taskOverToWms.setTargetLocationCode(taskWrk.getOriginTargetPoint()); //目标库位 |
| | | }else if (taskWrk.getIoType() ==2){ |
| | | Map<Integer,String> map1 = new HashMap<>(); |
| | | map1.put(102,"J-1101"); |
| | | map1.put(106,"J-1103"); |
| | | map1.put(110,"J-1105"); |
| | | map1.put(114,"J-1107"); |
| | | map1.put(118,"J-1109"); |
| | | map1.put(122,"J-1111"); |
| | | map1.put(305,"H-1101"); |
| | | map1.put(405,"G-1101"); |
| | | taskOverToWms.setEquipmentCode(map1.get(taskWrk.getTargetPoint())); //设备编码 |
| | | taskOverToWms.setSourceLocationCode(taskWrk.getOriginStartPoint()); //源库位 |
| | | private TaskWrk createTask1(Result result, String barcode) { |
| | | String locNo = Utils.getLocNo(result.getRow(), result.getFloor(), result.getColumn()); |
| | | LocMast locMast = locMastService.selectByLocNo(locNo); |
| | | if (locMast == null) { |
| | | throw new CoolException("库位不存在"); |
| | | } |
| | | |
| | | taskOverToWms.setTaskStatus("executing"); //任务状态 |
| | | String response = null; |
| | | try { |
| | | response = new HttpHandler.Builder() |
| | | .setHeaders(map) |
| | | .setUri(wmsUrl) |
| | | .setPath("wcsManager/wcsInterface/taskStatusFeedback") |
| | | .setJson(JSON.toJSONString(taskOverToWms)) |
| | | .build() |
| | | .doPost(); |
| | | }catch (Exception e){ |
| | | log.error("堆垛机任务完成,请求wms任务完成接口失败"); |
| | | 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.setCrnNo(locMast.getCrnNo()); |
| | | taskWrk.setTargetPoint(locNo); |
| | | taskWrk.setStartPoint("116"); |
| | | if (result.getAlley().equals("1")) { |
| | | taskWrk.setCrnNo(1); |
| | | } else { |
| | | taskWrk.setCrnNo(2); |
| | | } |
| | | apiLogService.save("堆垛机开始运行" |
| | | ,wmsUrl+"wcsManager/wcsInterface/taskStatusFeedback" |
| | | ,null |
| | | ,"127.0.0.1" |
| | | ,JSON.toJSONString(taskOverToWms) |
| | | ,response |
| | | ,true |
| | | ); |
| | | return response; |
| | | 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){ |
| | | private TaskWrk createTask(GetWmsDto dto, String barcode) { |
| | | String wcsLocNo = dto.getLocNo(); |
| | | if(Cools.isEmpty(wcsLocNo)){ |
| | | if (Cools.isEmpty(wcsLocNo)) { |
| | | return null; |
| | | } |
| | | Date now = new Date(); |
| | |
| | | taskWrk.setCrnNo(locMast.getCrnNo()); |
| | | taskWrk.setTargetPoint(wcsLocNo); |
| | | taskWrk.setStartPoint(dto.getStaNo().toString()); |
| | | if(taskWrk.getIoType() == 1){ |
| | | if (taskWrk.getIoType() == 1) { |
| | | taskWrk.setWrkSts(2); |
| | | if (!Cools.isEmpty(taskWrk.getTargetPoint())) { |
| | | taskWrk.setOriginTargetPoint(taskWrk.getTargetPoint()); |
| | |
| | | } |
| | | return taskWrk; |
| | | } |
| | | |
| | | |
| | | } |