| | |
| | | import com.zy.acs.common.utils.Utils; |
| | | import com.zy.acs.manager.common.domain.TaskDto; |
| | | import com.zy.acs.manager.common.exception.BusinessException; |
| | | import com.zy.acs.manager.common.utils.CommonUtil; |
| | | import com.zy.acs.manager.core.domain.AgvBackpackDto; |
| | | import com.zy.acs.manager.core.domain.TaskPosDto; |
| | | import com.zy.acs.manager.core.service.astart.MapDataDispatcher; |
| | |
| | | taskList.sort(new Comparator<Task>() { |
| | | @Override |
| | | public int compare(Task o1, Task o2) { |
| | | return o1.getPriority() - o2.getPriority(); |
| | | return o2.getPriority() - o1.getPriority(); |
| | | } |
| | | }); |
| | | Integer backpack = agvService.getBackpack(agv); |
| | |
| | | taskList = taskList.subList(0, backpack); |
| | | } |
| | | |
| | | AgvDetail agvDetail = agvDetailService.selectByAgvId(agvId); |
| | | List<AgvBackpackDto> backpackDtoList = new ArrayList<>(); |
| | | |
| | | /** |
| | |
| | | taskPosDtoList.sort((o1, o2) -> (int) (o1.getSecondWeight(sameGroupXy) * 100 - o2.getSecondWeight(sameGroupXy) * 100)); |
| | | } |
| | | |
| | | // re-order by agv current position |
| | | Code currCode = codeService.getById(agvDetail.getRecentCode()); |
| | | Double[] currPosition = new Double[] {currCode.getX(), currCode.getY()}; |
| | | |
| | | List<TaskPosDto> theFirstOne = list.get(0); |
| | | List<TaskPosDto> theLastOne = list.get(list.size() - 1); |
| | | |
| | | if (list.size() == 1) { |
| | | TaskPosDto head = theFirstOne.get(0); |
| | | TaskPosDto tail = theFirstOne.get(theFirstOne.size() - 1); |
| | | |
| | | int distanceByHead = CommonUtil.calcDistance(currPosition, head.getXy()); |
| | | int distanceByTail = CommonUtil.calcDistance(currPosition, tail.getXy()); |
| | | |
| | | if (distanceByTail < distanceByHead) { |
| | | Collections.reverse(theFirstOne); |
| | | } |
| | | |
| | | } else { |
| | | TaskPosDto headOfFirst = theFirstOne.get(0); |
| | | TaskPosDto tailOfFirst = theFirstOne.get(theFirstOne.size() - 1); |
| | | |
| | | TaskPosDto headOfLast = theLastOne.get(0); |
| | | TaskPosDto tailOfLast = theLastOne.get(theLastOne.size() - 1); |
| | | |
| | | int distanceByHeadOfFirst = CommonUtil.calcDistance(currPosition, headOfFirst.getXy()); |
| | | int distanceByTailOfFirst = CommonUtil.calcDistance(currPosition, tailOfFirst.getXy()); |
| | | |
| | | int distanceByHeadOfLast = CommonUtil.calcDistance(currPosition, headOfLast.getXy()); |
| | | int distanceByTailOfLast = CommonUtil.calcDistance(currPosition, tailOfLast.getXy()); |
| | | |
| | | if (Math.min(distanceByHeadOfLast, distanceByTailOfLast) < Math.min(distanceByHeadOfFirst, distanceByTailOfFirst)) { |
| | | Collections.reverse(list); |
| | | |
| | | if (distanceByTailOfLast < distanceByHeadOfLast) { |
| | | Collections.reverse(theLastOne); |
| | | } |
| | | } else { |
| | | if (distanceByTailOfFirst < distanceByHeadOfFirst) { |
| | | Collections.reverse(theFirstOne); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // generate travel |
| | | Travel travel = new Travel(); |
| | | travel.setUuid(String.valueOf(snowflakeIdWorker.nextId()).substring(3)); |
| | |
| | | FuncSta funcSta = funcStaService.checkoutClosestFunSta(agvDetail.getRecentCode(), idleFunStaList); |
| | | endCode = codeService.getById(funcSta.getCode()); |
| | | } |
| | | if (null == endCode) { |
| | | log.warn("AGV[{}] failed to search destination,there hadn't any idle funSta,TaskTypeType:{}", agv.getUuid(), taskType.toString()); |
| | | } |
| | | break; |
| | | case MOVE: |
| | | endCode = codeService.selectByData(destination); |
| | |
| | | } |
| | | |
| | | if (null == endCode) { |
| | | log.error("{}号车辆建立功能任务失败,无法检索到目标定位,TaskTypeType:{}", agv.getUuid(), taskType.toString()); |
| | | return false; |
| | | } |
| | | |
| | |
| | | task.setIoTime(now); |
| | | task.setStartTime(now); |
| | | if (!taskService.save(task)) { |
| | | throw new BusinessException(task.getSeqNum() + "任务保存失败"); |
| | | throw new BusinessException(task.getSeqNum() + " failed to save"); |
| | | } |
| | | |
| | | // generate travel |
| | |
| | | travel.setTaskIds(JSON.toJSONString(Collections.singletonList(task.getId()))); |
| | | travel.setState(TravelStateType.RUNNING.toString()); |
| | | if (!travelService.save(travel)) { |
| | | throw new BusinessException("任务组保存失败"); |
| | | throw new BusinessException("travel failed to save"); |
| | | } |
| | | |
| | | // generate segment |
| | |
| | | next.setState(SegmentStateType.WAITING.toString()); |
| | | } |
| | | if (!segmentService.save(next)) { |
| | | throw new BusinessException("任务组保存失败"); |
| | | throw new BusinessException("segment failed to save"); |
| | | } |
| | | } |
| | | |
| | |
| | | destFuncSta.setState(FuncStaStateType.OCCUPIED.toString()); |
| | | destFuncSta.setUpdateTime(now); |
| | | if (!funcStaService.updateById(destFuncSta)) { |
| | | log.error("FuncSta [{}] 更新状态失败 !!!", destFuncSta.getName()); |
| | | log.error("FuncSta [{}] failed to update !!!", destFuncSta.getName()); |
| | | } |
| | | break; |
| | | case MOVE: |