| | |
| | | int backpackLev = 0; |
| | | int backpack = agvService.getBackpack(agvId); |
| | | List<Integer> usedBackpacks = segmentService.selectUsedBackpacks(currSeg.getTravelId(), agvId); |
| | | if (usedBackpacks.size() == backpackLev) { |
| | | if (usedBackpacks.size() >= backpack) { |
| | | throw new CoolException("[Agv:" + agvNo + "] allocate inbound segment failed: no idle backpack to use"); |
| | | } |
| | | for (int lev = 1; lev <= backpack; lev++) { |
| | |
| | | currSeg.setState(SegmentStateType.INIT.toString()); |
| | | currSeg.setUpdateTime(now); |
| | | if (!segmentService.updateById(currSeg)) { |
| | | log.error("Segment [{}] failed to update !!!", currSeg.getGroupId() + " - " + currSeg.getSerial()); |
| | | // log.error("Segment [{}] failed to update !!!", currSeg.getGroupId() + " - " + currSeg.getSerial()); |
| | | throw new CoolException("failed to update segment [" + currSeg.getGroupId() + "-" + currSeg.getSerial() + "] failed"); |
| | | } |
| | | |
| | | // new oriSta seg |
| | |
| | | loadSeg.setCreateTime(now); |
| | | loadSeg.setUpdateTime(now); |
| | | if (!segmentService.save(loadSeg)) { |
| | | log.error("Segment [{}] failed to save !!!", loadSeg.getTravelId() + " - " + loadSeg.getSerial()); |
| | | // log.error("Segment [{}] failed to save !!!", loadSeg.getTravelId() + " - " + loadSeg.getSerial()); |
| | | throw new CoolException("failed to save segment [" + loadSeg.getGroupId() + "-" + loadSeg.getSerial() + "] failed"); |
| | | } |
| | | |
| | | // place segment |
| | |
| | | newDto.setCodeId(endCode.getId()); |
| | | destPosList.add(newDto); |
| | | |
| | | // sort - reference to buildMarjoTask |
| | | final String sameGroupXy = configService.getVal("sameGroupXy", String.class); |
| | | |
| | | // DEST-only sort |
| | | destPosList.sort((a, b) -> { |
| | | int c1 = Double.compare(a.getXy()[0], b.getXy()[0]); // X |
| | | if (c1 != 0) return c1; |
| | | int c2 = Double.compare(a.getXy()[1], b.getXy()[1]); // Y |
| | | if (c2 != 0) return c2; |
| | | // 同坐标时用 taskId 打散(避免排序不稳定) |
| | | |
| | | // 主轴 |
| | | double aFirst = a.getFirstWeight(sameGroupXy); |
| | | double bFirst = b.getFirstWeight(sameGroupXy); |
| | | int c = Double.compare(aFirst, bFirst); |
| | | if (c != 0) return c; |
| | | |
| | | // 副轴 |
| | | double aSecond = a.getSecondWeight(sameGroupXy); |
| | | double bSecond = b.getSecondWeight(sameGroupXy); |
| | | c = Double.compare(aSecond, bSecond); |
| | | if (c != 0) return c; |
| | | |
| | | return Long.compare(a.getTaskId(), b.getTaskId()); |
| | | }); |
| | | |
| | | // get placeSeg serial |
| | | int placeSegSerial = 9999; |
| | | int placeSegSerial; |
| | | // query placeSeg idx |
| | | int idx = -1; |
| | | for (int i = 0; i < destPosList.size(); i++) { |
| | |
| | | } |
| | | |
| | | // 后继点 |
| | | TaskPosDto afterTaskPos = ((idx + 1) < destPosList.size()) ? destPosList.get(idx + 1) : null; |
| | | if (null == afterTaskPos) { |
| | | // loadSeg is the last one |
| | | if (idx + 1 == destPosList.size()) { |
| | | placeSegSerial = destSegList.get(destSegList.size() - 1).getSerial() + 1; |
| | | } else { |
| | | TaskPosDto afterTaskPos = destPosList.get(idx + 1); |
| | | Segment afterSeg = destSegList.stream() |
| | | .filter(destSeg -> Objects.equals(destSeg.getId(), afterTaskPos.getSegId())) |
| | | .findFirst() |
| | |
| | | placeSeg.setCreateTime(now); |
| | | placeSeg.setUpdateTime(now); |
| | | if (!segmentService.save(placeSeg)) { |
| | | log.error("Segment [{}] failed to save !!!", placeSeg.getTravelId() + " - " + placeSeg.getSerial()); |
| | | // log.error("Segment [{}] failed to save !!!", placeSeg.getTravelId() + " - " + placeSeg.getSerial()); |
| | | throw new CoolException("failed to save segment [" + placeSeg.getGroupId() + "-" + placeSeg.getSerial() + "] failed"); |
| | | } |
| | | |
| | | // update task |
| | |
| | | * val: new TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType) |
| | | */ |
| | | Map<String, List<TaskPosDto>> groups = new HashMap<>(); |
| | | final String sameGroupXy = configService.getVal( "sameGroupXy", String.class); |
| | | final String sameGroupXy = configService.getVal("sameGroupXy", String.class); |
| | | |
| | | int backpackLev = 0; |
| | | for (Task task : taskList) { |