| | |
| | | |
| | | @SuppressWarnings("all") |
| | | @Transactional |
| | | public void generateBusAndTask(OpenBusSubmitParam busSubmitParam, String memo) { |
| | | public Bus generateBusAndTask(OpenBusSubmitParam busSubmitParam, String memo) { |
| | | String errorMsg = busService.checkoutValid(busSubmitParam); |
| | | if (!Cools.isEmpty(errorMsg)) { |
| | | throw new BusinessException(errorMsg); |
| | | } |
| | | String batch = busSubmitParam.getBatch(); |
| | | List<TaskDto> taskDtoList = busSubmitParam.getTaskList(); |
| | | if (Cools.isEmpty(taskDtoList)) { |
| | | throw new BusinessException("taskDtoList 不能为空"); |
| | | throw new BusinessException("taskList can't be empty!"); |
| | | } |
| | | |
| | | // 优先级排序 |
| | |
| | | bus.setMemo(memo); |
| | | |
| | | if (!busService.save(bus)) { |
| | | throw new BusinessException("任务保存失败"); |
| | | throw new BusinessException("Internal Server Error!"); |
| | | } |
| | | |
| | | // 保存任务 |
| | |
| | | task.setBusId(bus.getId()); |
| | | task.setTaskSts(TaskStsType.INIT.val()); |
| | | if (!taskService.save(task)) { |
| | | throw new BusinessException(task.getSeqNum() + "任务保存失败"); |
| | | throw new BusinessException("seqNum:" + task.getSeqNum() + " failed to save!"); |
| | | } |
| | | |
| | | // 修改库位状态 |
| | |
| | | case LOC_TO_LOC: |
| | | oriLoc = locService.getById(task.getOriLoc()); |
| | | if (!oriLoc.getLocSts().equals(LocStsType.STOCK.val())) { |
| | | throw new BusinessException("oriLoc:" + task.getOriLoc$() + " 不是在库状态"); |
| | | throw new BusinessException("oriLoc:" + task.getOriLoc$() + " is not in STOCK status"); |
| | | } |
| | | oriLoc.setLocSts(LocStsType.PAKOUT.val()); |
| | | oriLoc.setUpdateTime(now); |
| | | if (!locService.updateById(oriLoc)) { |
| | | throw new BusinessException("oriLoc:" + task.getOriLoc$() + " 修改库位状态失败"); |
| | | throw new BusinessException("oriLoc:" + task.getOriLoc$() + " failed to update"); |
| | | } |
| | | |
| | | destLoc = locService.getById(task.getDestLoc()); |
| | | if (!destLoc.getLocSts().equals(LocStsType.IDLE.val())) { |
| | | throw new BusinessException("destLoc:" + task.getDestLoc$() + " 不是空闲状态"); |
| | | throw new BusinessException("destLoc:" + task.getDestLoc$() + " is not in IDLE status"); |
| | | } |
| | | destLoc.setLocSts(LocStsType.PAKIN.val()); |
| | | destLoc.setUpdateTime(now); |
| | | if (!locService.updateById(destLoc)) { |
| | | throw new BusinessException("destLoc:" + task.getDestLoc$() + " 修改库位状态失败"); |
| | | throw new BusinessException("destLoc:" + task.getDestLoc$() + " failed to update"); |
| | | } |
| | | break; |
| | | case LOC_TO_STA: |
| | | oriLoc = locService.getById(task.getOriLoc()); |
| | | if (!oriLoc.getLocSts().equals(LocStsType.STOCK.val())) { |
| | | throw new BusinessException("oriLoc:" + task.getOriLoc$() + " 不是在库状态"); |
| | | throw new BusinessException("oriLoc:" + task.getOriLoc$() + " is not in STOCK status"); |
| | | } |
| | | oriLoc.setLocSts(LocStsType.PAKOUT.val()); |
| | | oriLoc.setUpdateTime(now); |
| | | if (!locService.updateById(oriLoc)) { |
| | | throw new BusinessException("oriLoc:" + task.getOriLoc$() + " 修改库位状态失败"); |
| | | throw new BusinessException("oriLoc:" + task.getOriLoc$() + " failed to update"); |
| | | } |
| | | break; |
| | | case STA_TO_LOC: |
| | | destLoc = locService.getById(task.getDestLoc()); |
| | | if (!destLoc.getLocSts().equals(LocStsType.IDLE.val())) { |
| | | throw new BusinessException("destLoc:" + task.getDestLoc$() + " 不是空闲状态"); |
| | | throw new BusinessException("destLoc:" + task.getDestLoc$() + " is not in IDLE status"); |
| | | } |
| | | destLoc.setLocSts(LocStsType.PAKIN.val()); |
| | | destLoc.setUpdateTime(now); |
| | | if (!locService.updateById(destLoc)) { |
| | | throw new BusinessException("destLoc:" + task.getDestLoc$() + " 修改库位状态失败"); |
| | | throw new BusinessException("destLoc:" + task.getDestLoc$() + " failed to update"); |
| | | } |
| | | break; |
| | | case STA_TO_STA: |
| | |
| | | } |
| | | |
| | | } |
| | | |
| | | return bus; |
| | | } |
| | | |
| | | /** |
| | |
| | | bus.setBusSts(BusStsType.PROGRESS.val()); |
| | | bus.setUpdateTime(now); |
| | | if (!busService.updateById(bus)) { |
| | | log.error("Bus [{}] 更新失败 !!!", bus.getUuid()); |
| | | log.error("Bus [{}] failed to Update !!!", bus.getUuid()); |
| | | } |
| | | return; |
| | | } |
| | |
| | | for (Task task : taskList) { |
| | | Agv agv = missionAssignService.execute(task, taskAllot, taskIds); |
| | | if (null == agv) { |
| | | log.warn("{}任务异常,无法检索空闲Agv...", task.getSeqNum()); |
| | | log.warn("Task[{}] has an issue, because it failed to checkout agv which is idle...", task.getSeqNum()); |
| | | continue; |
| | | } |
| | | |
| | |
| | | task.setIoTime(now); |
| | | task.setUpdateTime(now); |
| | | if (!taskService.updateById(task)) { |
| | | throw new BusinessException(task.getSeqNum() + "任务更新失败"); |
| | | throw new BusinessException("seqNum: " + task.getSeqNum() + " failed to update"); |
| | | } |
| | | |
| | | if (taskAllot.containsKey(agv.getUuid())) { |
| | |
| | | * 解析取放货集合任务,进行最优的排列组合顺序 ( 车辆此时是空闲且静止的 ) |
| | | */ |
| | | @Transactional |
| | | public synchronized void mergeMajorTask(Long agvId, List<Task> taskList) { |
| | | public synchronized void buildMajorTask(Long agvId, List<Task> taskList) { |
| | | if (Cools.isEmpty(taskList)) { return; } |
| | | boolean lockAcquired = false; |
| | | try { |
| | | if (!(lockAcquired = this.lock.tryLock(LOCK_TIMEOUT, TimeUnit.SECONDS))) { |
| | | throw new CoolException("generate [task] action fail, cause can not acquire lock ..."); |
| | | } |
| | | Date now = new Date(); |
| | | final String sameGroupXy = configService.getVal( "sameGroupXy", String.class); |
| | | |
| | | // valid ----------------------------------------------- |
| | | Agv agv = agvService.getById(agvId); |
| | | if (!agvService.judgeEnable(agv.getId(), agvDetail -> agvDetail.getVol() > agv.getChargeLine())) { |
| | | throw new CoolException("AGV[" + agv.getUuid() + "]当前不可用..."); |
| | | } |
| | | |
| | | if (!Cools.isEmpty(taskService.selectInSts(agvId, TaskStsType.ASSIGN, TaskStsType.PROGRESS))) { |
| | | throw new CoolException("AGV[" + agv.getUuid() + "]分配任务失败,已存在执行任务..."); |
| | | } |
| | | |
| | | AgvDetail agvDetail = agvDetailService.selectByAgvId(agvId); |
| | | assert agvDetail != null; |
| | | if (agvDetail.getPos() == 0) { |
| | | if (!agvDetail.getAgvStatus().equals(AgvStatusType.CHARGE)) { |
| | | throw new CoolException("AGV[" + agv.getUuid() + "]当前不在定位..."); |
| | | } |
| | | } |
| | | |
| | | // execute ---------------------------------------------------- |
| | | Date now = new Date(); |
| | | // sort and sub |
| | | taskList.sort(new Comparator<Task>() { |
| | | @Override |
| | |
| | | return 0; |
| | | } |
| | | }); |
| | | if (taskList.size() > agv.getStage()) { |
| | | taskList = taskList.subList(0, agv.getStage()); |
| | | Integer backpack = agvService.getBackpack(agv); |
| | | if (taskList.size() > backpack) { |
| | | taskList = taskList.subList(0, backpack); |
| | | } |
| | | |
| | | List<AgvBackpackDto> backpackDtoList = new ArrayList<>(); |
| | | |
| | | /** |
| | | * single agvId |
| | | * 同巷道归类 |
| | | * same lane for every single agvId |
| | | * |
| | | * key: y + TaskPosDto.PosType.ORI_LOC / ORI_STA / DEST_LOC / DEST_STA |
| | | * key: y(val) + TaskPosDto.PosType.ORI_LOC / ORI_STA / DEST_LOC / DEST_STA |
| | | * val: new TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType) |
| | | */ |
| | | Map<String, List<TaskPosDto>> groups = new HashMap<>(); |
| | | |
| | | List<AgvBackpackDto> backpackDtoList = new ArrayList<>(); |
| | | final String sameGroupXy = configService.getVal( "sameGroupXy", String.class); |
| | | |
| | | int backpackLev = 0; |
| | | for (Task task : taskList) { |
| | |
| | | |
| | | } |
| | | |
| | | if (backpackLev > agv.getStage()) { |
| | | if (backpackLev > backpack) { |
| | | throw new BusinessException("解析Task失败,AGV背篓已满......"); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * List<TaskPosDto>: task list on the same channel |
| | | * 1.Map<String, List<TaskPosDto>> groups |
| | | * |
| | | * key: 1000 + ORI_LOC |
| | | * val: [TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType), TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType),...] |
| | | * |
| | | * key: 3000 + ORI_LOC |
| | | * val: [TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType), TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType),...] |
| | | * |
| | | * key: 2000 + ORI_LOC |
| | | * val: [TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType), TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType),...] |
| | | * |
| | | * ...... |
| | | * |
| | | * 2.ArrayList<List<TaskPosDto>> list |
| | | * [ |
| | | * [TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType), TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType),...], |
| | | * [TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType), TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType),...], |
| | | * [TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType), TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType),...], |
| | | * ...... |
| | | * ] |
| | | */ |
| | | |
| | | /** |
| | | * 对所有巷道进行有序排序,先是针对List为一个单位,对他们进行FirstWeight排序,相当于表1的key的数值进行有序排序 |
| | | * List<TaskPosDto>: task list on the same lane |
| | | * ArrayList<List<TaskPosDto>>: all the task list by one agv |
| | | */ |
| | | ArrayList<List<TaskPosDto>> list = new ArrayList<>(groups.values()); |
| | |
| | | double o2CompVal = (o2.get(0).getFirstWeight(sameGroupXy) * 100) + o2.get(0).getPosType().compOffset; |
| | | return (int) (o1CompVal - o2CompVal); |
| | | }); |
| | | |
| | | // 针对Dto,按照SecondWeight进行排序 |
| | | for (List<TaskPosDto> taskPosDtoList : list) { |
| | | taskPosDtoList.sort((o1, o2) -> (int) (o1.getSecondWeight(sameGroupXy) * 100 - o2.getSecondWeight(sameGroupXy) * 100)); |
| | | } |
| | |
| | | |
| | | AgvDetail agvDetail = agvDetailService.selectByAgvId(agvId); |
| | | assert agvDetail != null; |
| | | if (agvDetail.getPos() == 0) { |
| | | if (!agvDetail.getAgvStatus().equals(AgvStatusType.CHARGE)) { |
| | | throw new CoolException("AGV[" + agv.getUuid() + "]当前不在定位..."); |
| | | } |
| | | } |
| | | |
| | | List<Action> actionList = new ArrayList<>(); |
| | | // start node |
| | |
| | | } |
| | | for (Action action : actionList) { |
| | | action.setActionSts(ActionStsType.ISSUED.val()); |
| | | action.setStartTime(now); |
| | | action.setUpdateTime(now); |
| | | if (!actionService.updateById(action)) { |
| | | throw new BusinessException(action.getPriority() + " - " + action.getName() + "动作更新失败"); |
| | |
| | | |
| | | if (null != action) { |
| | | action.setActionSts(ActionStsType.FINISH.val()); |
| | | action.setEndTime(now); |
| | | action.setUpdateTime(now); |
| | | if (!actionService.updateById(action)) { |
| | | log.error("Action [{}] 更新失败 !!!", action.getPriority() + " - " + action.getName()); |
| | |
| | | ); |
| | | if (null != action) { |
| | | action.setActionSts(ActionStsType.FINISH.val()); |
| | | action.setEndTime(now); |
| | | action.setUpdateTime(now); |
| | | if (!actionService.updateById(action)) { |
| | | log.error("Action [{}] 更新失败 !!!", action.getPriority() + " - " + action.getName()); |
| | |
| | | ); |
| | | for (Action action : actionList) { |
| | | action.setActionSts(ActionStsType.FINISH.val()); |
| | | action.setEndTime(now); |
| | | action.setUpdateTime(now); |
| | | if (!actionService.updateById(action)) { |
| | | log.error("Action [{}] 更新失败 !!!", action.getPriority() + " - " + action.getName()); |