| | |
| | | @Autowired |
| | | private StaDescService staDescService; |
| | | |
| | | @Autowired |
| | | private ApiLogService apiLogService; |
| | | |
| | | @Value("${wms.url}") |
| | | private String wmsUrl; |
| | | @Value("${wms.movePath}") |
| | |
| | | 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; |
| | | } |
| | | if (!staProtocol.isPakMk()){ |
| | | continue; |
| | | } |
| | | // News.warn("扫码入库失败,{}入库站因{}异常,托盘已被退回", inSta.getStaNo(), errMsg); |
| | | staProtocol.setWorkNo(workNo); |
| | | staProtocol.setStaNo(inSta.getBackSta().shortValue()); |
| | | devpThread.setPakMk(staProtocol.getSiteId(), false); |
| | | MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(3, staProtocol)); |
| | | |
| | | TaskWrk taskWrk = taskWrkMapper.selectByWrkNo(Integer.valueOf(workNo)); |
| | | if (taskWrk != null) { |
| | | taskWrk.setMemo(errMsg);//将错误码存入备注字段进行展示 |
| | |
| | | } |
| | | 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) { |
| | | continue; |
| | | } |
| | | String barcode = barcodeThread.getBarcode(); |
| | | staProtocol.setBarcode(barcode); |
| | | 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)); |
| | | |
| | | if (Cools.isEmpty(taskWrk)){ |
| | | continue; |
| | | } |
| | | |
| | | //StaDesc staDesc1 = staDescService.selectOne(new EntityWrapper<StaDesc>().eq("stn_no",inSta.getBackSta())); |
| | | if (taskWrk.getTargetPoint() != null && taskWrk.getStartPoint() != null && taskWrk.getWrkNo() != null && taskWrk.getWrkNo().shortValue() != workNo){ |
| | | 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); |
| | | Thread.sleep(500); |
| | | }else { |
| | | //TaskWrk taskWrk = taskWrkService.selectByTaskNo(param.getTaskNo()); |
| | | toWmsDTO.setWarehouseId("1688469798893297665"); |
| | | toWmsDTO.setContainerCode(barcode); |
| | | toWmsDTO.setApplyType("TUNNEL_LOCATION"); |
| | | toWmsDTO.setTaskTunnel(taskWrk.getCrnNo()); |
| | | List<Integer> list = new ArrayList<>(); |
| | | |
| | | if (inSta.getBarcode() == 7 || inSta.getBarcode() == 8){ |
| | | toWmsDTO.setTaskTunnel(taskWrk.getCrnNo()); |
| | | list.add(taskWrk.getCrnNo()); |
| | | }else { |
| | | toWmsDTO.setTaskTunnel(inSta.getBarcode()); |
| | | list.add(inSta.getBarcode()); |
| | | } |
| | | |
| | | |
| | | |
| | | toWmsDTO.setCanInboundTunnels(list); |
| | | String response = null; |
| | | try { |
| | |
| | | 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); |
| | |
| | | log.error("输送线命令下方失败!!! [工作号:{}]", taskWrk.getWrkNo()); |
| | | continue;//命令下发失败 |
| | | } |
| | | |
| | | // 复位堆垛机 |
| | | crnThread.setResetFlag(true); |
| | | |
| | | if (taskWrk.getIoType() == 1 || taskWrk.getIoType() == 3){ |
| | | taskWrk.setWrkSts(4); |
| | | } else if (taskWrk.getIoType() == 2) { |
| | | taskWrk.setWrkSts(14); |
| | | } |
| | | if (!taskWrkService.updateById(taskWrk)){ |
| | | log.error(taskWrk.getTaskNo()+ " 堆垛机任务完成,改变任务状态失败"); |
| | | } |
| | | |
| | | |
| | | } |
| | | } |
| | |
| | | if (taskWrkMapper.selectCrnWorking(slave.getId()) != null) { |
| | | continue; |
| | | } |
| | | // 修改工作档状态 2.设备上走 => 3.吊车入库中 |
| | | log.error("进入修改工作档流程"); |
| | | Date now = new Date(); |
| | | taskWrk.setWrkSts(3); |
| | | taskWrk.setModiTime(now); |
| | | if (taskWrkMapper.updateById(taskWrk) == 0) { |
| | | log.error("修改工作档状态 2.设备上走 => 3.吊车入库中 失败!!,工作号={}", taskWrk.getWrkNo()); |
| | | } |
| | | TaskWrk taskWrk2 = taskWrkService.selectByWrkNo(staProtocol.getWorkNo().intValue()); |
| | | |
| | | if (taskWrk2.getWrkSts() != 3){ |
| | | continue; |
| | | } |
| | | log.error("进入修改工作档流程完成,taskWrk=", JSON.toJSONString(taskWrk)); |
| | | |
| | | |
| | | //取出命令 |
| | | List<CommandInfo> commandInfos = commandInfoService.selectByTaskNo(taskWrk.getTaskNo()); |
| | |
| | | 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 (commandInfos.isEmpty()) { |
| | | continue;//命令空 |
| | | } |
| | | |
| | | //判断末端命令是否执行 |
| | | CommandInfo commandInfo2 = commandInfos.get(commandInfos.size() - 1); |
| | | if (commandInfo2.getCommandStatus() != CommandStatusType.CREATE.id) { |
| | | continue;//指令已执行 |
| | | } |
| | | |
| | | CommandInfo commandInfo = commandInfos.get(commandStep); |
| | | CommandPackage commandPackage = JSON.parseObject(commandInfo.getCommand(), CommandPackage.class);//取出命令报文 |
| | | CrnCommand crnCommand = JSON.parseObject(commandPackage.getCommand().toString(), CrnCommand.class); |
| | |
| | | .eq("wrk_sts",11) |
| | | .eq("io_type",3)); |
| | | for (TaskWrk taskWrk : taskWrks){ |
| | | |
| | | // 双深库位且浅库位有货,则需先对浅库位进行库位移转 |
| | | if (Utils.isDeepLoc(slaveProperties, taskWrk.getStartPoint())) { |
| | | String shallowLocNo = Utils.getShallowLoc(slaveProperties, taskWrk.getStartPoint()); |
| | | TaskWrk hallowLocNoTask = taskWrkMapper.selectByStartPoint(shallowLocNo); |
| | | if (!Cools.isEmpty(hallowLocNoTask)){ |
| | | continue; |
| | | } |
| | | } |
| | | // 堆垛机控制过滤 |
| | | if (!crnProtocol.getStatusType().equals(CrnStatusType.IDLE) || crnProtocol.getTaskNo() != 0) { |
| | | continue; |
| | | } |
| | | |
| | | // 已经存在吊车执行任务时,则过滤 |
| | | if (taskWrkMapper.selectCrnWorking(slave.getId()) != null) { |
| | | continue; |
| | | } |
| | | if (Cools.isEmpty(taskWrk.getTargetPoint())){ |
| | | List<Integer> list = openServiceImpl.getInEnableRoadway(); |
| | | Map<String, Object> map = new HashMap<>(); |
| | |
| | | continue; |
| | | } |
| | | |
| | | } |
| | | } |
| | | if (taskWrk == null || Cools.isEmpty(taskWrk.getTargetPoint()) || taskWrk.getTargetPoint().equals("") || taskWrk.getWrkNo() == null) { |
| | | continue; |
| | | } |
| | |
| | | |
| | | // 命令下发区 -------------------------------------------------------------------------- |
| | | |
| | | // 堆垛机控制过滤 |
| | | if (!crnProtocol.getStatusType().equals(CrnStatusType.IDLE) || crnProtocol.getTaskNo() != 0) { |
| | | continue; |
| | | } |
| | | |
| | | // 已经存在吊车执行任务时,则过滤 |
| | | if (taskWrkMapper.selectCrnWorking(slave.getId()) != null) { |
| | | continue; |
| | | } |
| | | |
| | | |
| | | // 1.堆垛机开始移动 |
| | |
| | | CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crn.getId()); |
| | | CrnProtocol crnProtocol = crnThread.getCrnProtocol(); |
| | | 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)) { |
| | | // log.error("堆垛机处于等待确认且任务完成状态,但未找到工作档。堆垛机号={},工作号={}", crn.getId(), crnProtocol.getTaskNo()); |
| | | continue; |
| | | } |
| | | |
| | | //获取指令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)) {//修改成功后复位堆垛机 |
| | | // 堆垛机复位 |
| | | crnThread.setResetFlag(true); |
| | | if (taskWrk.getIoType() == 1 || taskWrk.getIoType() == 3){ |
| | | taskWrk.setWrkSts(4); |
| | | } else if (taskWrk.getIoType() == 2) { |
| | | taskWrk.setWrkSts(14); |
| | | } |
| | | if (!taskWrkService.updateById(taskWrk)){ |
| | | log.error(taskWrk.getTaskNo()+ " 堆垛机任务完成,改变任务状态失败"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | if (crnProtocol == null) { |
| | | continue; |
| | | } |
| | | if (true) { |
| | | if (false) { |
| | | // if (crnProtocol.getModeType() != CrnModeType.STOP) { |
| | | // 有任务 |
| | | if (crnProtocol.getTaskNo() != 0) { |
| | | BasErrLog latest = basErrLogService.findLatestByTaskNo(crn.getId(), crnProtocol.getTaskNo().intValue()); |
| | | // 有异常 |
| | | if (latest == null) { |
| | | if (crnProtocol.getAlarm1() != null && crnProtocol.getAlarm1() > 0) { |
| | | if (crnProtocol.getAlarm() != null && crnProtocol.getAlarm() > 0) { |
| | | WrkMast wrkMast = wrkMastMapper.selectById(crnProtocol.getTaskNo()); |
| | | if (wrkMast == null) { |
| | | continue; |
| | | } |
| | | BasCrnError crnError = basCrnErrorMapper.selectById(crnProtocol.getAlarm1()); |
| | | String errName = crnError==null? String.valueOf(crnProtocol.getAlarm1()):crnError.getErrName(); |
| | | BasCrnError crnError = basCrnErrorMapper.selectById(crnProtocol.getAlarm()); |
| | | String errName = crnError==null? String.valueOf(crnProtocol.getAlarm()):crnError.getErrName(); |
| | | BasErrLog basErrLog = new BasErrLog( |
| | | null, // 编号 |
| | | wrkMast.getWrkNo(), // 工作号 |
| | |
| | | } else { |
| | | BasErrLog latest = basErrLogService.findLatest(crn.getId()); |
| | | // 有异常 |
| | | if (crnProtocol.getAlarm1() != null && crnProtocol.getAlarm1() > 0) { |
| | | if (crnProtocol.getAlarm1() != null && crnProtocol.getAlarm() > 0) { |
| | | // 记录新异常 |
| | | if (latest == null || (latest.getErrCode() != crnProtocol.getAlarm1().intValue())) { |
| | | BasCrnError crnError = basCrnErrorMapper.selectById(crnProtocol.getAlarm1()); |
| | | String errName = crnError==null? String.valueOf(crnProtocol.getAlarm1()):crnError.getErrName(); |
| | | if (latest == null || (latest.getErrCode() != crnProtocol.getAlarm().intValue())) { |
| | | BasCrnError crnError = basCrnErrorMapper.selectById(crnProtocol.getAlarm()); |
| | | String errName = crnError==null? String.valueOf(crnProtocol.getAlarm()):crnError.getErrName(); |
| | | BasErrLog basErrLog = new BasErrLog( |
| | | null, // 编号 |
| | | null, // 工作号 |
| | |
| | | try { |
| | | taskWrkService.distribute(taskWrk.getTaskNo(), 9527L); |
| | | } catch (CoolException e) { |
| | | log.info(e.getMessage()); |
| | | // log.info(e.getMessage()); |
| | | } |
| | | } |
| | | } |
| | |
| | | for (TaskWrk taskWrk : taskWrks) { |
| | | //获取命令集合 |
| | | List<CommandInfo> commandInfos = commandInfoService.selectByTaskNo(taskWrk.getTaskNo()); |
| | | if (taskWrk.getCommandStep() != commandInfos.size()) { |
| | | if (taskWrk.getCommandStep() < commandInfos.size()) { |
| | | continue;//当前步序没有到达最后一条命令 |
| | | } |
| | | |
| | | //判断末端命令是否执行完成 |
| | | CommandInfo commandInfo = commandInfos.get(commandInfos.size() - 1); |
| | | if (commandInfo.getCommandStatus() != CommandStatusType.COMPLETE.id) { |
| | | continue;//指令未完成 |
| | | if (!commandInfos.isEmpty()){ |
| | | CommandInfo commandInfo = commandInfos.get(commandInfos.size() - 1); |
| | | if (commandInfo.getCommandStatus() != CommandStatusType.COMPLETE.id) { |
| | | continue;//指令未完成 |
| | | } |
| | | } |
| | | |
| | | |
| | | Date now = new Date(); |
| | | //指令已完成,更新任务 |
| | | if (taskWrk.getIoType() == 1) { |
| | | //入库任务 |
| | | taskWrk.setWrkSts(4);//3.吊车入库中 => 4.入库完成 |
| | | //taskWrk.setStatus(TaskStatusType.COMPLETE.id); |
| | | // taskWrk.setWrkSts(4);//3.吊车入库中 => 4.入库完成 |
| | | taskWrk.setStatus(TaskStatusType.OVER.id); |
| | | taskWrk.setModiTime(now); |
| | | taskWrkService.updateById(taskWrk); |
| | | |
| | | //更新库位状态 |
| | | LocMast locMast = locMastService.selectByLocNo(taskWrk.getTargetPoint()); |
| | | locMast.setLocSts("F");//F.在库 |
| | | locMast.setLocSts("Z");//F.在库 |
| | | locMast.setBarcode(taskWrk.getBarcode());//托盘码 |
| | | locMast.setModiTime(now); |
| | | locMast.setModiUser(9999L); |
| | | locMastService.updateById(locMast); |
| | | } else if (taskWrk.getIoType() == 2) { |
| | | //出库任务 |
| | | taskWrk.setWrkSts(14);//12.吊车出库中 => 14.出库完成 |
| | | // taskWrk.setStatus(TaskStatusType.COMPLETE.id); |
| | | // taskWrk.setWrkSts(14);//12.吊车出库中 => 14.出库完成 |
| | | taskWrk.setStatus(TaskStatusType.OVER.id); |
| | | taskWrk.setModiTime(now); |
| | | taskWrkService.updateById(taskWrk); |
| | | |
| | | //更新库位状态 |
| | | LocMast locMast = locMastService.selectByLocNo(taskWrk.getStartPoint()); |
| | | locMast.setLocSts("O");//O.空库位 |
| | | locMast.setLocSts("K");//O.空库位 |
| | | locMast.setBarcode("");//托盘码 |
| | | locMast.setModiTime(now); |
| | | locMast.setModiUser(9999L); |
| | | locMastService.updateById(locMast); |
| | | } else if (taskWrk.getIoType() == 3) { |
| | | |
| | | //更新起始库位状态 |
| | | LocMast locMastStart = locMastService.selectByLocNo(taskWrk.getStartPoint()); |
| | | locMastStart.setLocSts("K");//O.空库位 |
| | | locMastStart.setBarcode("");//托盘码 |
| | | locMastStart.setModiTime(now); |
| | | locMastStart.setModiUser(9999L); |
| | | locMastService.updateById(locMastStart); |
| | | |
| | | //更新目标库位状态 |
| | | LocMast locMast = locMastService.selectByLocNo(taskWrk.getTargetPoint()); |
| | | locMast.setLocSts("Z");//F.在库 |
| | | locMast.setBarcode(taskWrk.getBarcode());//托盘码 |
| | | locMast.setModiTime(now); |
| | | locMast.setModiUser(9999L); |
| | | locMastService.updateById(locMast); |
| | | |
| | | taskWrk.setStatus(TaskStatusType.OVER.id); |
| | | taskWrk.setModiTime(now); |
| | | taskWrkService.updateById(taskWrk); |
| | | |
| | | |
| | | } |
| | | } |
| | | } |
| | |
| | | }catch (Exception e){ |
| | | log.error("堆垛机任务完成,请求wms任务完成接口失败"); |
| | | } |
| | | apiLogService.save("堆垛机开始运行" |
| | | ,wmsUrl+"wcsManager/wcsInterface/taskStatusFeedback" |
| | | ,null |
| | | ,"127.0.0.1" |
| | | ,JSON.toJSONString(taskOverToWms) |
| | | ,response |
| | | ,true |
| | | ); |
| | | return response; |
| | | } |
| | | |