| | |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.zy.asrs.domain.enums.TaskStatusType; |
| | | import com.zy.asrs.entity.*; |
| | | import com.zy.asrs.entity.param.TaskOverToWms; |
| | | import com.zy.asrs.entity.param.WMSAndAGVInterfaceParam; |
| | | import com.zy.asrs.entity.param.taskCreateParam; |
| | | import com.zy.asrs.mapper.*; |
| | |
| | | |
| | | @Autowired |
| | | private OpenServiceImpl openServiceImpl; |
| | | @Autowired |
| | | private StaDescService staDescService; |
| | | |
| | | @Autowired |
| | | private ApiLogService apiLogService; |
| | | |
| | | @Value("${wms.url}") |
| | | private String wmsUrl; |
| | |
| | | private String movePath; |
| | | |
| | | |
| | | public void generateStoreWrkFile() throws IOException { |
| | | public void generateStoreWrkFile() throws IOException, InterruptedException { |
| | | // 根据输送线plc遍历 |
| | | for (DevpSlave devp : slaveProperties.getDevp()) { |
| | | // 遍历入库口 |
| | |
| | | staProtocol = staProtocol.clone(); |
| | | } |
| | | Short workNo = staProtocol.getWorkNo(); |
| | | // 判断是否满足入库条件 |
| | | if (staProtocol.isAutoing() && staProtocol.isLoading() |
| | | && staProtocol.isInEnable() |
| | | && !staProtocol.isEmptyMk() && (workNo >= 0) |
| | | && staProtocol.isPakMk()) { |
| | | Short stano = staProtocol.getStaNo(); |
| | | |
| | | |
| | | |
| | | // 尺寸检测异常 |
| | | boolean back = false; |
| | |
| | | } |
| | | // 退回 |
| | | if (back) { |
| | | if (stano == inSta.getBackSta().shortValue()){ |
| | | continue; |
| | | } |
| | | if (workNo == 0 && stano == 0){ |
| | | continue; |
| | | } |
| | | // News.warn("扫码入库失败,{}入库站因{}异常,托盘已被退回", inSta.getStaNo(), errMsg); |
| | | staProtocol.setWorkNo(workNo); |
| | | staProtocol.setStaNo(inSta.getBackSta().shortValue()); |
| | |
| | | } |
| | | continue; |
| | | } |
| | | // 判断是否满足入库条件 |
| | | if (staProtocol.isAutoing() && staProtocol.isLoading() |
| | | && staProtocol.isInEnable() |
| | | && !staProtocol.isEmptyMk() && (workNo >= 0) |
| | | && staProtocol.isPakMk()) { |
| | | // 获取条码扫描仪信息 |
| | | BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, inSta.getBarcode()); |
| | | if (barcodeThread == null) { |
| | |
| | | } |
| | | String barcode = barcodeThread.getBarcode(); |
| | | if(!Cools.isEmpty(barcode)) { |
| | | StaDescService staDescService = SpringUtils.getBean(StaDescService.class); |
| | | |
| | | ToWmsDTO toWmsDTO = new ToWmsDTO(); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("x-api-key","7a15b5db-29b6-552c-8cff-0cfec3756da2"); |
| | | List<Integer> list = openServiceImpl.getInEnableRoadway(); |
| | | TaskWrk taskWrk = taskWrkService.selectOne(new EntityWrapper<TaskWrk>().eq("barcode", barcode).eq("crn_no",inSta.getBarcode())); |
| | | TaskWrk taskWrk = taskWrkService.selectOne(new EntityWrapper<TaskWrk>().eq("barcode", barcode)); |
| | | |
| | | if (Cools.isEmpty(taskWrk)){ |
| | | continue; |
| | | } |
| | | if (taskWrk.getTargetPoint() != null && taskWrk.getStartPoint() != null && taskWrk.getWrkNo() != null && taskWrk.getWrkNo().shortValue() != workNo){ |
| | | //获取堆垛机站点 |
| | | StaDescService staDescService = SpringUtils.getBean(StaDescService.class); |
| | | //StaDesc staDesc1 = staDescService.selectOne(new EntityWrapper<StaDesc>().eq("stn_no",inSta.getBackSta())); |
| | | if (taskWrk.getTargetPoint() != null && taskWrk.getStartPoint() != null){ |
| | | if ( taskWrk.getWrkNo() != null && taskWrk.getWrkNo().shortValue() == workNo ){ |
| | | continue; |
| | | } |
| | | //获取堆垛机站点 |
| | | StaDesc staDesc = new StaDesc(); |
| | | if (devp.getId() <= 1){ |
| | | staDesc = staDescService.selectOne(new EntityWrapper<StaDesc>() |
| | | .eq("crn_no", taskWrk.getCrnNo()).eq("type_no",1).lt("crn_stn", 200)); |
| | | .eq("crn_no", taskWrk.getCrnNo()).eq("type_no",1).lt("stn_no", 200)); |
| | | }else { |
| | | staDesc = staDescService.selectOne(new EntityWrapper<StaDesc>() |
| | | .eq("crn_no", taskWrk.getCrnNo()).eq("type_no",1).ge("crn_stn", 200)); |
| | | .eq("crn_no", taskWrk.getCrnNo()).eq("type_no",1).lt("stn_no", 400).ge("stn_no", 250)); |
| | | } |
| | | staProtocol.setWorkNo(taskWrk.getWrkNo().shortValue()); |
| | | staProtocol.setStaNo(staDesc.getCrnStn().shortValue()); |
| | | MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(3, staProtocol)); |
| | | Thread.sleep(200); |
| | | }else { |
| | | //TaskWrk taskWrk = taskWrkService.selectByTaskNo(param.getTaskNo()); |
| | | toWmsDTO.setWarehouseId("1688469798893297665"); |
| | |
| | | log.error("wms通讯失败,"+e.getMessage()); |
| | | continue; |
| | | } |
| | | apiLogService.save("wms请求入库货位接口" |
| | | ,wmsUrl+"wcsManager/wcsInterface/inboundTaskApply" |
| | | ,null |
| | | ,"127.0.0.1" |
| | | ,JSON.toJSONString(toWmsDTO) |
| | | ,response |
| | | ,true |
| | | ); |
| | | JSONObject jsonObject = JSON.parseObject(response); |
| | | if (jsonObject.getInteger("code").equals(200)) { |
| | | GetWmsDto getWmsDto = JSON.parseObject(jsonObject.get("data").toString(), GetWmsDto.class); |
| | |
| | | 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")); |
| | | |
| | | } |
| | | } |
| | | |
| | | // // 命令下发区 -------------------------------------------------------------------------- |
| | |
| | | // } |
| | | } |
| | | |
| | | return; |
| | | // return; |
| | | } |
| | | } |
| | | |
| | |
| | | String shallowLocNo = Utils.getShallowLoc(slaveProperties, taskWrk.getStartPoint()); |
| | | TaskWrk hallowLocNoTask = taskWrkMapper.selectByStartPoint(shallowLocNo); |
| | | if (!Cools.isEmpty(hallowLocNoTask)){ |
| | | if (!Cools.isEmpty(hallowLocNoTask.getTargetPoint())){ |
| | | continue; |
| | | } |
| | | // new PostMesDataUtils().postMesData("移库任务分配库位",wmsUrl,movePath,hallowLocNoTask); |
| | | try { |
| | | String response = new HttpHandler.Builder() |
| | | .setUri(wmsUrl) |
| | | .setPath(movePath) |
| | | .setJson(JSON.toJSONString(hallowLocNoTask)) |
| | | .build() |
| | | .doPost(); |
| | | System.out.println("response:"+response); |
| | | JSONObject jsonObject = JSON.parseObject(response); |
| | | if (jsonObject.getInteger("code").equals(200)) { |
| | | //解析 |
| | | } |
| | | }catch (Exception e){ |
| | | log.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl+"/"+movePath, JSON.toJSONString(hallowLocNoTask), "请求移库任务分配库位"); |
| | | } |
| | | // if (!Cools.isEmpty(hallowLocNoTask.getTargetPoint())){ |
| | | // continue; |
| | | // } |
| | | //// new PostMesDataUtils().postMesData("移库任务分配库位",wmsUrl,movePath,hallowLocNoTask); |
| | | // try { |
| | | // String response = new HttpHandler.Builder() |
| | | // .setUri(wmsUrl) |
| | | // .setPath(movePath) |
| | | // .setJson(JSON.toJSONString(hallowLocNoTask)) |
| | | // .build() |
| | | // .doPost(); |
| | | // System.out.println("response:"+response); |
| | | // JSONObject jsonObject = JSON.parseObject(response); |
| | | // if (jsonObject.getInteger("code").equals(200)) { |
| | | // //解析 |
| | | // } |
| | | // }catch (Exception e){ |
| | | // log.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl+"/"+movePath, JSON.toJSONString(hallowLocNoTask), "请求移库任务分配库位"); |
| | | // } |
| | | continue; |
| | | } |
| | | } |
| | |
| | | if (taskWrkMapper.updateById(taskWrk) == 0) { |
| | | log.error("修改工作档状态 11.生成出库ID => 12.吊车出库中 失败!!,工作号={}", taskWrk.getWrkNo()); |
| | | } |
| | | //开始运行 |
| | | String response = CrnStartRunning(taskWrk); |
| | | JSONObject jsonObject = JSON.parseObject(response); |
| | | if (jsonObject.getInteger("code").equals(200)) { |
| | | |
| | | }else { |
| | | log.error("出库开始运行通讯失败,"+jsonObject.get("msg")); |
| | | |
| | | } |
| | | } |
| | | return; |
| | | |
| | | } |
| | | } |
| | | } |
| | |
| | | public void locToLoc(CrnSlave slave, CrnProtocol crnProtocol){ |
| | | for (CrnSlave.CrnStn crnStn : slave.getCrnOutStn()) { |
| | | // 获取工作状态为11(生成出库ID)的移库工作档 |
| | | List<TaskWrk> taskWrks = taskWrkMapper.selectPakOut3(slave.getId(), crnStn.getStaNo().toString()); |
| | | 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){ |
| | | if (taskWrk == null || Cools.isEmpty(taskWrk.getTargetPoint()) || taskWrk.getTargetPoint().equals("")) { |
| | | if (Cools.isEmpty(taskWrk.getTargetPoint())){ |
| | | List<Integer> list = openServiceImpl.getInEnableRoadway(); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("x-api-key","7a15b5db-29b6-552c-8cff-0cfec3756da2"); |
| | | ToWmsDTO toWmsDTO = new ToWmsDTO(); |
| | | toWmsDTO.setWarehouseId("1688469798893297665"); |
| | | toWmsDTO.setContainerCode(taskWrk.getBarcode()); |
| | | toWmsDTO.setApplyType("TUNNEL_LOCATION"); |
| | | toWmsDTO.setTaskTunnel(taskWrk.getCrnNo()); |
| | | toWmsDTO.setCanInboundTunnels(list); |
| | | String response = null; |
| | | try { |
| | | response = new HttpHandler.Builder() |
| | | .setHeaders(map) |
| | | .setUri(wmsUrl) |
| | | .setPath("wcsManager/wcsInterface/inboundTaskApply") |
| | | .setJson(JSON.toJSONString(toWmsDTO)) |
| | | .build() |
| | | .doPost(); |
| | | }catch (Exception e){ |
| | | log.error("wms通讯失败,"+e.getMessage()); |
| | | continue; |
| | | } |
| | | JSONObject jsonObject = JSON.parseObject(response); |
| | | if (jsonObject.getInteger("code").equals(200)) { |
| | | GetWmsDto getWmsDto = JSON.parseObject(jsonObject.get("data").toString(), GetWmsDto.class); |
| | | taskWrk.setOriginTargetPoint(getWmsDto.getTargetLocationCode()); |
| | | taskWrk.setTargetPoint(Utils.getWcsLocNo(getWmsDto.getTargetLocationCode())); |
| | | if (!taskWrkService.updateById(taskWrk)){ |
| | | log.error("保存wms库位号失败"); |
| | | } |
| | | continue; |
| | | }else { |
| | | log.error("wms通讯失败,"+jsonObject.get("msg")); |
| | | continue; |
| | | } |
| | | |
| | | } |
| | | if (taskWrk == null || Cools.isEmpty(taskWrk.getTargetPoint()) || taskWrk.getTargetPoint().equals("") || taskWrk.getWrkNo() == null) { |
| | | continue; |
| | | } |
| | | // 工作档状态判断 |
| | |
| | | crnCommand.setTaskNo(taskWrk.getWrkNo().shortValue()); // 工作号 |
| | | crnCommand.setAckFinish((short) 0); // 任务完成确认位 |
| | | crnCommand.setTaskMode(CrnTaskModeType.LOC_MOVE); // 任务模式: 库位移转 |
| | | crnCommand.setSourcePosX(Utils.getRowShort(taskWrk.getStartPoint())); // 源库位排 |
| | | crnCommand.setSourcePosY(Utils.getBayShort(taskWrk.getStartPoint())); // 源库位列 |
| | | crnCommand.setSourcePosZ(Utils.getLevShort(taskWrk.getStartPoint())); // 源库位层 |
| | | crnCommand.setDestinationPosX(Utils.getRowShort(taskWrk.getTargetPoint())); // 目标库位排 |
| | | crnCommand.setDestinationPosY(Utils.getBayShort(taskWrk.getTargetPoint())); // 目标库位列 |
| | | crnCommand.setDestinationPosZ(Utils.getLevShort(taskWrk.getTargetPoint())); // 目标库位层 |
| | | if (!CommandUtils.offer(SlaveType.Crn, taskWrk.getCrnNo(), new Task(2, crnCommand))) { |
| | | crnCommand.setSourcePosZ(Utils.getRowShort(taskWrk.getStartPoint())); // 源库位排 |
| | | crnCommand.setSourcePosX(Utils.getBayShort(taskWrk.getStartPoint())); // 源库位列 |
| | | crnCommand.setSourcePosY(Utils.getLevShort(taskWrk.getStartPoint())); // 源库位层 |
| | | crnCommand.setDestinationPosZ(Utils.getRowShort(taskWrk.getTargetPoint())); // 目标库位排 |
| | | crnCommand.setDestinationPosX(Utils.getBayShort(taskWrk.getTargetPoint())); // 目标库位列 |
| | | crnCommand.setDestinationPosY(Utils.getLevShort(taskWrk.getTargetPoint())); // 目标库位层 |
| | | crnCommand.setCommand((short) 1); |
| | | if (!CommandUtils.offer(SlaveType.Crn, taskWrk.getCrnNo(), new Task(2, crnCommand),false)) { |
| | | log.error("堆垛机命令下发失败,堆垛机号={},任务数据={}", taskWrk.getCrnNo(), JSON.toJSON(crnCommand)); |
| | | } else { |
| | | // 修改工作档状态 11.生成出库ID => 12.吊车出库中 |
| | |
| | | taskWrk.setModiTime(now); |
| | | if (taskWrkMapper.updateById(taskWrk) == 0) { |
| | | log.error("修改工作档状态 11.生成出库ID => 12.吊车出库中 失败!!,工作号={}", taskWrk.getWrkNo()); |
| | | } |
| | | //开始运行 |
| | | String response = CrnStartRunning(taskWrk); |
| | | JSONObject jsonObject = JSON.parseObject(response); |
| | | if (jsonObject.getInteger("code").equals(200)) { |
| | | |
| | | }else { |
| | | log.error("移库任务开始运行通讯失败,"+jsonObject.get("msg")); |
| | | continue; |
| | | } |
| | | break; |
| | | } |
| | |
| | | |
| | | //获取指令ID |
| | | Integer commandId = crnProtocol.getCommandId(); |
| | | CommandInfo commandInfo = commandInfoService.selectById(commandId); |
| | | CommandInfo commandInfo = new CommandInfo(); |
| | | if (Cools.isEmpty(commandId)){ |
| | | commandInfo = commandInfoService.selectOne(new EntityWrapper<CommandInfo>() |
| | | .eq("wrk_no",crnProtocol.getTaskNo()) |
| | | .eq("device","Crn")); |
| | | }else { |
| | | commandInfo = commandInfoService.selectById(commandId); |
| | | } |
| | | |
| | | |
| | | if (commandInfo == null) { |
| | | //指令不存在 |
| | | continue; |
| | | } |
| | | |
| | | if (commandInfo.getCommandStatus() == 3){ |
| | | continue; |
| | | } |
| | | commandInfo.setCommandStatus(CommandStatusType.COMPLETE.id);//指令完成 |
| | | commandInfo.setCompleteTime(new Date());//指令完成时间 |
| | | if (commandInfoService.updateById(commandInfo)) {//修改成功后复位堆垛机 |
| | |
| | | } else if (taskWrk.getIoType() == 2) { |
| | | //出库任务 |
| | | taskWrk.setWrkSts(14);//12.吊车出库中 => 14.出库完成 |
| | | taskWrk.setStatus(TaskStatusType.COMPLETE.id); |
| | | // taskWrk.setStatus(TaskStatusType.COMPLETE.id); |
| | | taskWrk.setModiTime(now); |
| | | taskWrkService.updateById(taskWrk); |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | 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()); //源库位 |
| | | } |
| | | |
| | | 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任务完成接口失败"); |
| | | } |
| | | apiLogService.save("堆垛机开始运行" |
| | | ,wmsUrl+"wcsManager/wcsInterface/taskStatusFeedback" |
| | | ,null |
| | | ,"127.0.0.1" |
| | | ,JSON.toJSONString(taskOverToWms) |
| | | ,response |
| | | ,true |
| | | ); |
| | | return response; |
| | | } |
| | | |
| | | |
| | | } |