| | |
| | | import com.zy.asrs.framework.common.Cools; |
| | | import com.zy.asrs.framework.common.R; |
| | | import com.zy.asrs.framework.common.SnowflakeIdWorker; |
| | | import com.zy.asrs.framework.exception.CoolException; |
| | | import com.zy.asrs.wcs.core.domain.dto.BasLiftStaDto; |
| | | import com.zy.asrs.wcs.core.domain.param.AgvTaskCreateParam; |
| | | import com.zy.asrs.wcs.core.domain.param.CreateInTaskParam; |
| | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.*; |
| | | |
| | |
| | | |
| | | |
| | | @Override |
| | | @Transactional |
| | | public R createInTask(CreateInTaskParam param) { |
| | | //获取入库任务类型 |
| | | TaskCtg taskCtg = taskCtgService.getOne(new LambdaQueryWrapper<TaskCtg>() |
| | | .eq(TaskCtg::getFlag, String.valueOf(TaskCtgType.IN)) |
| | | .eq(TaskCtg::getStatus, 1)); |
| | | if (taskCtg == null) { |
| | | return R.error("任务类型异常"); |
| | | throw new CoolException("任务类型异常"); |
| | | } |
| | | |
| | | Long hostId = 1L;//默认主仓库 |
| | | |
| | | Loc loc = locService.selectByLocNo(param.getDestLoc()); |
| | | if (loc == null) { |
| | | return R.error("库位号不存在"); |
| | | throw new CoolException("库位号不存在"); |
| | | } |
| | | |
| | | //获取严格模式参数 |
| | |
| | | } |
| | | |
| | | if (mapStrict && !loc.getLocStsFlag().equals("O")) { |
| | | return R.error("库位状态不满足入库条件"); |
| | | throw new CoolException("库位状态不满足入库条件"); |
| | | } |
| | | |
| | | Task one = taskService.getOne(new LambdaQueryWrapper<Task>() |
| | |
| | | .eq(Task::getDestSite, param.getDestSite()) |
| | | .eq(Task::getDestLoc, param.getDestLoc())); |
| | | if (one != null) { |
| | | return R.error("任务已存在"); |
| | | throw new CoolException("任务已存在"); |
| | | } |
| | | |
| | | String destSite = param.getDestSite(); |
| | |
| | | .eq(BasConveyorPath::getHostId, hostId) |
| | | .eq(BasConveyorPath::getStnNo, param.getOriginSite())); |
| | | if(path == null) { |
| | | return R.error("内置路径不存在"); |
| | | throw new CoolException("内置路径不存在"); |
| | | } |
| | | destSite = String.valueOf(path.getDeviceStn()); |
| | | } |
| | |
| | | .eq(TaskCtg::getFlag, String.valueOf(TaskCtgType.OUT)) |
| | | .eq(TaskCtg::getStatus, 1)); |
| | | if (taskInCtg == null) { |
| | | return R.error("任务类型异常"); |
| | | throw new CoolException("任务类型异常"); |
| | | } |
| | | List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>() |
| | | .eq(Task::getTaskCtg, taskInCtg.getId())); |
| | | if (!tasks.isEmpty()) { |
| | | return R.error("当前存在出库任务,无法切换入库模式"); |
| | | throw new CoolException("当前存在出库任务,无法切换入库模式"); |
| | | } |
| | | |
| | | BasConveyor basConveyor = basConveyorService.getOne(new LambdaQueryWrapper<BasConveyor>().eq(BasConveyor::getConveyorNo, basConveyorSta.getConveyorNo())); |
| | | if(basConveyor == null) { |
| | | return R.error("输送线不存在"); |
| | | throw new CoolException("输送线不存在"); |
| | | } |
| | | |
| | | DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Conveyor, basConveyor.getDeviceId().intValue()); |
| | | if(devpThread == null) { |
| | | return R.error("输送线线程不存在"); |
| | | throw new CoolException("输送线线程不存在"); |
| | | } |
| | | |
| | | boolean result = devpThread.switchWorkMode(Integer.parseInt(destSite), WorkModeType.PAKIN_MODE.id); |
| | | if (!result) { |
| | | return R.error("模式切换失败"); |
| | | throw new CoolException("模式切换失败"); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | boolean result = taskService.save(task); |
| | | if (!result) { |
| | | return R.error("生成入库任务失败!"); |
| | | throw new CoolException("生成入库任务失败!"); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public R createOutTask(CreateOutTaskParam param) { |
| | | //获取出库任务类型 |
| | | TaskCtg taskCtg = taskCtgService.getOne(new LambdaQueryWrapper<TaskCtg>() |
| | | .eq(TaskCtg::getFlag, String.valueOf(TaskCtgType.OUT)) |
| | | .eq(TaskCtg::getStatus, 1)); |
| | | if (taskCtg == null) { |
| | | return R.error("任务类型异常"); |
| | | throw new CoolException("任务类型异常"); |
| | | } |
| | | |
| | | Long hostId = 1L;//默认主仓库 |
| | | |
| | | Loc loc = locService.selectByLocNo(param.getOriginLoc()); |
| | | if (loc == null) { |
| | | return R.error("库位号不存在"); |
| | | throw new CoolException("库位号不存在"); |
| | | } |
| | | |
| | | //获取严格模式参数 |
| | |
| | | } |
| | | |
| | | if (mapStrict && !loc.getLocStsFlag().equals("F")) { |
| | | return R.error("库位状态不满足出库条件"); |
| | | throw new CoolException("库位状态不满足出库条件"); |
| | | } |
| | | |
| | | Task one = taskService.getOne(new LambdaQueryWrapper<Task>() |
| | |
| | | .eq(Task::getOriginLoc, param.getOriginLoc()) |
| | | .eq(Task::getDestSite, param.getDestSite())); |
| | | if (one != null) { |
| | | return R.error("任务已存在"); |
| | | throw new CoolException("任务已存在"); |
| | | } |
| | | |
| | | String originSite = param.getOriginSite(); |
| | |
| | | .eq(BasConveyorPath::getHostId, hostId) |
| | | .eq(BasConveyorPath::getStnNo, param.getDestSite())); |
| | | if(path == null) { |
| | | return R.error("内置路径不存在"); |
| | | throw new CoolException("内置路径不存在"); |
| | | } |
| | | Integer deviceNo = path.getDeviceNo();//获取提升机号 |
| | | BasLift basLift = basLiftService.getOne(new LambdaQueryWrapper<BasLift>().eq(BasLift::getLiftNo, deviceNo).eq(BasLift::getHostId, hostId)); |
| | | if(basLift == null) { |
| | | return R.error("提升机对象不存在"); |
| | | throw new CoolException("提升机对象不存在"); |
| | | } |
| | | List<BasLiftStaDto> staList = JSON.parseArray(basLift.getSta(), BasLiftStaDto.class); |
| | | BasLiftStaDto originStaDto = null; |
| | |
| | | } |
| | | |
| | | if (originStaDto == null) { |
| | | return R.error("源站不存在"); |
| | | throw new CoolException("源站不存在"); |
| | | } |
| | | |
| | | originSite = String.valueOf(originStaDto.getStaNo()); |
| | |
| | | .eq(TaskCtg::getFlag, String.valueOf(TaskCtgType.IN)) |
| | | .eq(TaskCtg::getStatus, 1)); |
| | | if (taskInCtg == null) { |
| | | return R.error("任务类型异常"); |
| | | throw new CoolException("任务类型异常"); |
| | | } |
| | | List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>() |
| | | .eq(Task::getTaskCtg, taskInCtg.getId())); |
| | | if (!tasks.isEmpty()) { |
| | | return R.error("当前存在入库任务,无法切换出库模式"); |
| | | throw new CoolException("当前存在入库任务,无法切换出库模式"); |
| | | } |
| | | |
| | | BasConveyor basConveyor = basConveyorService.getOne(new LambdaQueryWrapper<BasConveyor>().eq(BasConveyor::getConveyorNo, basConveyorSta.getConveyorNo())); |
| | | if(basConveyor == null) { |
| | | return R.error("输送线不存在"); |
| | | throw new CoolException("输送线不存在"); |
| | | } |
| | | |
| | | DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Conveyor, basConveyor.getDeviceId().intValue()); |
| | | if(devpThread == null) { |
| | | return R.error("输送线线程不存在"); |
| | | throw new CoolException("输送线线程不存在"); |
| | | } |
| | | |
| | | boolean result = devpThread.switchWorkMode(Integer.parseInt(originSite), WorkModeType.PAKOUT_MODE.id); |
| | | if (!result) { |
| | | return R.error("模式切换失败"); |
| | | throw new CoolException("模式切换失败"); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | boolean result = taskService.save(task); |
| | | if (!result) { |
| | | return R.error("生成出库任务失败!"); |
| | | throw new CoolException("生成出库任务失败!"); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public HashMap<String, Object> executeWcsTaskCache(CreateWcsTaskParam param) { |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | String sta = "06YZ"; |
| | | String loc = "0601KW"; |
| | | if (param.getFrmPos().substring(0,4).equals(sta) && param.getToPos().substring(0,6).equals(loc)){ |
| | | if (!param.getFrmPos().equals("06YZ0001")){ |
| | | try { |
| | | AgvTaskCreateParam agvTaskCreateParam = new AgvTaskCreateParam(); |
| | | getInRequestParam(agvTaskCreateParam,param); |
| | | String httpRequest = doHttpRequest(agvTaskCreateParam, "172.18.16.248:443", "/rcs/rtas/api/robot/controller/task/submit"); |
| | | if (!httpRequest.equals("SUCCESS")){ |
| | | map.put("success", "0"); |
| | | map.put("message", httpRequest); |
| | | map.put("result", ""); |
| | | map.put("requestPK", param.getRequestPK()); |
| | | log.info("返回mes信息:"+ JSONObject.toJSONString(map)); |
| | | return map; |
| | | } |
| | | }catch (Exception e){ |
| | | map.put("success", "0"); |
| | | map.put("message", "转发AGV任务出错"); |
| | | map.put("result", ""); |
| | | map.put("requestPK", param.getRequestPK()); |
| | | log.info("返回mes信息:"+JSONObject.toJSONString(map)); |
| | | return map; |
| | | } |
| | | } |
| | | |
| | | CreateInTaskParam createInTaskParam = new CreateInTaskParam(); |
| | | createInTaskParam.setTaskNo(param.getRequestPK()); |
| | |
| | | R inTask = null; |
| | | try { |
| | | inTask = this.createInTask(createInTaskParam); |
| | | }catch (Exception e){ |
| | | map.put("success", "0"); |
| | | map.put("message", "生成任务出错"); |
| | | map.put("result", ""); |
| | | map.put("requestPK", param.getRequestPK()); |
| | | log.info("返回mes信息:"+JSONObject.toJSONString(map)); |
| | | return map; |
| | | }finally { |
| | | int code = (int) inTask.get("code"); |
| | | if (code == 200){ |
| | | map.put("success", "1"); |
| | | map.put("message", inTask.get("msg")); |
| | | map.put("result", ""); |
| | | map.put("requestPK", param.getRequestPK()); |
| | | |
| | | if (!param.getFrmPos().equals("06YZ0001")){ |
| | | try { |
| | | AgvTaskCreateParam agvTaskCreateParam = new AgvTaskCreateParam(); |
| | | getInRequestParam(agvTaskCreateParam,param); |
| | | String httpRequest = doHttpRequest(agvTaskCreateParam, "172.18.16.248:443", "/rcs/rtas/api/robot/controller/task/submit"); |
| | | if (!httpRequest.equals("SUCCESS")){ |
| | | map.put("success", "0"); |
| | | map.put("message", httpRequest); |
| | | map.put("result", ""); |
| | | map.put("requestPK", param.getRequestPK()); |
| | | log.info("返回mes信息:"+ JSONObject.toJSONString(map)); |
| | | return map; |
| | | } |
| | | }catch (Exception e){ |
| | | map.put("success", "0"); |
| | | map.put("message", "转发AGV任务出错"); |
| | | map.put("result", ""); |
| | | map.put("requestPK", param.getRequestPK()); |
| | | log.info("返回mes信息:"+JSONObject.toJSONString(map)); |
| | | return map; |
| | | } |
| | | } |
| | | |
| | | }else { |
| | | map.put("success", "0"); |
| | | map.put("message", inTask.get("msg")); |
| | | map.put("result", ""); |
| | | map.put("requestPK", param.getRequestPK()); |
| | | } |
| | | }catch (Exception e){ |
| | | map.put("success", "0"); |
| | | map.put("message", e.getMessage()); |
| | | map.put("result", ""); |
| | | map.put("requestPK", param.getRequestPK()); |
| | | log.info("返回mes信息:" + JSONObject.toJSONString(map)); |
| | | return map; |
| | | } |
| | | } else if (param.getFrmPos().substring(0,6).equals(loc) && param.getToPos().substring(0,4).equals(sta)) { |
| | | CreateOutTaskParam createOutTaskParam = new CreateOutTaskParam(); |
| | |
| | | R outTask = null; |
| | | try { |
| | | outTask = this.createOutTask(createOutTaskParam); |
| | | |
| | | int code = (int) outTask.get("code"); |
| | | if (code == 200){ |
| | | map.put("success", "1"); |
| | | map.put("message", outTask.get("msg")); |
| | | map.put("result", ""); |
| | | map.put("requestPK", param.getRequestPK()); |
| | | |
| | | if (!param.getFrmPos().equals("06YZ0001")){ |
| | | try { |
| | | AgvTaskCreateParam agvTaskCreateParam = new AgvTaskCreateParam(); |
| | | getInRequestParam(agvTaskCreateParam,param); |
| | | String httpRequest = doHttpRequest(agvTaskCreateParam, "172.18.16.248:443", "/rcs/rtas/api/robot/controller/task/submit"); |
| | | if (!httpRequest.equals("SUCCESS")){ |
| | | map.put("success", "0"); |
| | | map.put("message", httpRequest); |
| | | map.put("result", ""); |
| | | map.put("requestPK", param.getRequestPK()); |
| | | log.info("返回mes信息:"+ JSONObject.toJSONString(map)); |
| | | return map; |
| | | } |
| | | }catch (Exception e){ |
| | | map.put("success", "0"); |
| | | map.put("message", "转发AGV任务出错"); |
| | | map.put("result", ""); |
| | | map.put("requestPK", param.getRequestPK()); |
| | | log.info("返回mes信息:"+JSONObject.toJSONString(map)); |
| | | return map; |
| | | } |
| | | } |
| | | |
| | | }else { |
| | | map.put("success", "0"); |
| | | map.put("message", outTask.get("msg")); |
| | | map.put("result", ""); |
| | | map.put("requestPK", param.getRequestPK()); |
| | | } |
| | | |
| | | }catch (Exception e){ |
| | | map.put("success", "0"); |
| | | map.put("message", "生成任务出错"); |
| | |
| | | map.put("requestPK", param.getRequestPK()); |
| | | log.info("返回mes信息:"+JSONObject.toJSONString(map)); |
| | | return map; |
| | | }finally { |
| | | int code = (int) outTask.get("code"); |
| | | if (code == 200){ |
| | | map.put("success", "1"); |
| | | map.put("message", outTask.get("msg")); |
| | | map.put("result", ""); |
| | | map.put("requestPK", param.getRequestPK()); |
| | | }else { |
| | | map.put("success", "0"); |
| | | map.put("message", outTask.get("msg")); |
| | | map.put("result", ""); |
| | | map.put("requestPK", param.getRequestPK()); |
| | | } |
| | | } |
| | | |
| | | } else if (param.getFrmPos().substring(0,4).equals(sta) && param.getToPos().substring(0,4).equals(sta)) { |