| | |
| | | String code = sdf.format(new Date()) + UUIDUtil.getNumberRandom(5); |
| | | xpTask.setTaskCode(code); |
| | | xpTask.setTaskCategory(2); |
| | | String[] split = dto.getTaskTypeId().split(","); |
| | | List<String> typeIds = new ArrayList<>(); |
| | | for (String s : split) { |
| | | typeIds.add(s.trim()); |
| | | } |
| | | StringBuilder temp = new StringBuilder(dto.getTaskTypeId()); |
| | | List<Long> children = typeIds.stream().map(Long::parseLong).collect(Collectors.toList()); |
| | | List<Long> parentIds = errorTypeMapper.selectList(new LambdaQueryWrapper<XpErrorType>() |
| | | .in(XpErrorType::getId, children)).stream().map(XpErrorType::getParentId).distinct().collect(Collectors.toList()); |
| | | for (Long parentId : parentIds) { |
| | | temp.append(",").append(parentId); |
| | | } |
| | | xpTask.setTaskTypeId(temp.toString()); |
| | | xpTask.setTaskTypeId(normalizeAccidentTaskTypeId(dto.getTaskTypeId())); |
| | | xpTask.setTaskUrgencyLevel(dto.getTaskUrgencyLevel()); |
| | | xpTask.setTaskDescription(dto.getTaskDescription()); |
| | | xpTask.setTaskImage(dto.getTaskImage()); |
| | | xpTask.setVehicleId(dto.getId()); |
| | | XpVehicle vehicle = xpVehicleClient.queryById(xpTask.getVehicleId()).getData(); |
| | | // if (vehicle!=null){ |
| | | // VehiclePosition vehiclePosition = mongoTemplate.findOne(new Query(Criteria.where("vin").is(vehicle.getVehicleVin())), VehiclePosition.class); |
| | | // if (vehiclePosition != null) { |
| | | // double x = vehiclePosition.getPoint().getX(); |
| | | // double y = vehiclePosition.getPoint().getY(); |
| | | // xpTask.setVehicleLon(new BigDecimal(x)); |
| | | // xpTask.setVehicleLat(new BigDecimal(y)); |
| | | // } |
| | | // } |
| | | if (Objects.isNull(vehicle)) { |
| | | throw new ServiceException("上报失败,未获取到车辆信息", I18nKeyConstant.TASK_VEHICLE_NOT_EXIST); |
| | | } |
| | | VehiclePosition vehiclePosition = mongoTemplate.findOne(new Query(Criteria.where("vin").is(vehicle.getVehicleVin())), VehiclePosition.class); |
| | | if (Objects.isNull(vehiclePosition)) { |
| | | log.error("事故上报未获取到车辆当前定位"); |
| | | throw new ServiceException("获取车辆实时定位信息失败,请稍后重试", I18nKeyConstant.TASK_SAVE_ERROR); |
| | | } |
| | | xpTask.setVehicleLon(new BigDecimal(vehiclePosition.getPoint().getX())); |
| | | xpTask.setVehicleLat(new BigDecimal(vehiclePosition.getPoint().getY())); |
| | | Map<String, String> geocode = gdMapGeocodingUtil.geocode(xpTask.getVehicleLon().toString(), xpTask.getVehicleLat().toString()); |
| | | String address = geocode == null ? null : geocode.get("address"); |
| | | if (StringUtils.isBlank(address)) { |
| | | log.error("事故上报通过车辆定位从高德获取地址信息失败"); |
| | | throw new ServiceException("获取车辆实时定位信息失败,请稍后重试", I18nKeyConstant.TASK_SAVE_ERROR); |
| | | } |
| | | xpTask.setVehicleLocation(address); |
| | | // 临时处理 |
| | | xpTask.setVehicleLon(new BigDecimal("104.055683")); |
| | | xpTask.setVehicleLat(new BigDecimal("30.585991")); |
| | | xpTask.setVehicleLocation("四川省成都市武侯区石羊街道天府新谷"); |
| | | // xpTask.setVehicleLon(new BigDecimal("104.055683")); |
| | | // xpTask.setVehicleLat(new BigDecimal("30.585991")); |
| | | // xpTask.setVehicleLocation("四川省成都市武侯区石羊街道天府新谷"); |
| | | xpTask.setVehicleId(dto.getId()); |
| | | xpTask.setReportUserId(xpOperationsUser.getId()); |
| | | xpTask.setReportTime(LocalDateTime.now()); |
| | |
| | | taskManagementPageListVO.setHandleUserName(handleUserName.toString()); |
| | | } |
| | | } |
| | | if (taskManagementPageListVO.getTaskCategory() == 1) { |
| | | switch (taskManagementPageListVO.getTaskTypeId()) { |
| | | case "1": |
| | | taskManagementPageListVO.setTaskTypeName("车辆检查"); |
| | | break; |
| | | case "2": |
| | | taskManagementPageListVO.setTaskTypeName("车辆充电"); |
| | | break; |
| | | case "3": |
| | | taskManagementPageListVO.setTaskTypeName("车辆整备"); |
| | | break; |
| | | case "4": |
| | | taskManagementPageListVO.setTaskTypeName("整备洗车"); |
| | | break; |
| | | case "5": |
| | | taskManagementPageListVO.setTaskTypeName("车辆维修"); |
| | | break; |
| | | case "6": |
| | | taskManagementPageListVO.setTaskTypeName("车辆保养"); |
| | | break; |
| | | case "7": |
| | | taskManagementPageListVO.setTaskTypeName("车辆保险到期"); |
| | | break; |
| | | case "8": |
| | | taskManagementPageListVO.setTaskTypeName("车辆年检到期"); |
| | | break; |
| | | case "9": |
| | | taskManagementPageListVO.setTaskTypeName("车辆运营资质到期"); |
| | | break; |
| | | default: |
| | | taskManagementPageListVO.setTaskTypeName(""); |
| | | break; |
| | | } |
| | | } else { |
| | | StringBuilder taskTypeName = new StringBuilder(); |
| | | String[] typeIds = taskManagementPageListVO.getTaskTypeId().split(","); |
| | | List<XpErrorType> xpErrorTypes = errorTypeMapper.selectList(new LambdaQueryWrapper<XpErrorType>() |
| | | .in(XpErrorType::getId, Arrays.asList(typeIds)).orderByAsc(XpErrorType::getParentId)); |
| | | List<XpErrorType> parents = new ArrayList<>(); |
| | | for (XpErrorType xpErrorType : xpErrorTypes) { |
| | | if (xpErrorType.getParentId() == 0) { |
| | | parents.add(xpErrorType); |
| | | } |
| | | } |
| | | for (XpErrorType parent : parents) { |
| | | List<XpErrorType> children = xpErrorTypes.stream().filter(e -> e.getParentId().equals(parent.getId())).collect(Collectors.toList()); |
| | | taskTypeName.append(parent.getErrorName()).append(">"); |
| | | for (XpErrorType child : children) { |
| | | taskTypeName.append(child.getErrorName()).append(";"); |
| | | } |
| | | } |
| | | |
| | | taskManagementPageListVO.setTaskTypeName(taskTypeName.substring(0, taskTypeName.length() - 1)); |
| | | } |
| | | taskManagementPageListVO.setTaskTypeName(resolveManagementTaskTypeName(taskManagementPageListVO)); |
| | | } |
| | | pageInfo.setRecords(list); |
| | | return pageInfo; |
| | |
| | | taskManagementPageListVO.setHandleUserName(handleUserName.toString()); |
| | | } |
| | | } |
| | | if (taskManagementPageListVO.getTaskCategory() == 1) { |
| | | switch (taskManagementPageListVO.getTaskTypeId()) { |
| | | case "1": |
| | | taskManagementPageListVO.setTaskTypeName("车辆检查"); |
| | | break; |
| | | case "2": |
| | | taskManagementPageListVO.setTaskTypeName("车辆充电"); |
| | | break; |
| | | case "3": |
| | | taskManagementPageListVO.setTaskTypeName("车辆整备"); |
| | | break; |
| | | case "4": |
| | | taskManagementPageListVO.setTaskTypeName("整备洗车"); |
| | | break; |
| | | case "5": |
| | | taskManagementPageListVO.setTaskTypeName("车辆维修"); |
| | | break; |
| | | case "6": |
| | | taskManagementPageListVO.setTaskTypeName("车辆保养"); |
| | | break; |
| | | case "7": |
| | | taskManagementPageListVO.setTaskTypeName("车辆保险到期"); |
| | | break; |
| | | case "8": |
| | | taskManagementPageListVO.setTaskTypeName("车辆年检到期"); |
| | | break; |
| | | case "9": |
| | | taskManagementPageListVO.setTaskTypeName("车辆运营资质到期"); |
| | | break; |
| | | default: |
| | | taskManagementPageListVO.setTaskTypeName(""); |
| | | break; |
| | | } |
| | | } else { |
| | | StringBuilder taskTypeName = new StringBuilder(); |
| | | String[] typeIds = taskManagementPageListVO.getTaskTypeId().split(","); |
| | | List<XpErrorType> xpErrorTypes = errorTypeMapper.selectList(new LambdaQueryWrapper<XpErrorType>() |
| | | .in(XpErrorType::getId, Arrays.asList(typeIds)).orderByAsc(XpErrorType::getParentId)); |
| | | List<XpErrorType> parents = new ArrayList<>(); |
| | | for (XpErrorType xpErrorType : xpErrorTypes) { |
| | | if (xpErrorType.getParentId() == 0) { |
| | | parents.add(xpErrorType); |
| | | } |
| | | } |
| | | for (XpErrorType parent : parents) { |
| | | List<XpErrorType> children = xpErrorTypes.stream().filter(e -> e.getParentId().equals(parent.getId())).collect(Collectors.toList()); |
| | | taskTypeName.append(parent.getErrorName()).append(">"); |
| | | for (XpErrorType child : children) { |
| | | taskTypeName.append(child.getErrorName()).append(";"); |
| | | } |
| | | } |
| | | |
| | | taskManagementPageListVO.setTaskTypeName(taskTypeName.substring(0, taskTypeName.length() - 1)); |
| | | } |
| | | taskManagementPageListVO.setTaskTypeName(resolveManagementTaskTypeName(taskManagementPageListVO)); |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | private String resolveManagementTaskTypeName(TaskManagementPageListVO taskManagementPageListVO) { |
| | | if (Integer.valueOf(1).equals(taskManagementPageListVO.getTaskCategory())) { |
| | | return resolveRoutineTaskTypeName(taskManagementPageListVO.getTaskTypeId()); |
| | | } |
| | | if (Integer.valueOf(2).equals(taskManagementPageListVO.getTaskCategory())) { |
| | | return resolveAccidentTaskTypeName(taskManagementPageListVO.getTaskTypeId()); |
| | | } |
| | | return ""; |
| | | } |
| | | |
| | | private String resolveRoutineTaskTypeName(String taskTypeId) { |
| | | if (StringUtils.isBlank(taskTypeId)) { |
| | | return ""; |
| | | } |
| | | switch (taskTypeId) { |
| | | case "1": |
| | | return "车辆检查"; |
| | | case "2": |
| | | return "车辆充电"; |
| | | case "3": |
| | | return "车辆整备"; |
| | | case "4": |
| | | return "整备洗车"; |
| | | case "5": |
| | | return "车辆维修"; |
| | | case "6": |
| | | return "车辆保养"; |
| | | case "7": |
| | | return "车辆保险到期"; |
| | | case "8": |
| | | return "车辆年检到期"; |
| | | case "9": |
| | | return "车辆运营资质到期"; |
| | | default: |
| | | return ""; |
| | | } |
| | | } |
| | | |
| | | private String resolveAccidentTaskTypeName(String taskTypeId) { |
| | | List<Long> orderedTypeIds = parseAccidentTaskTypeIds(taskTypeId); |
| | | if (orderedTypeIds.isEmpty()) { |
| | | return ""; |
| | | } |
| | | |
| | | Map<Long, XpErrorType> errorTypeMap = getAccidentErrorTypeMap(orderedTypeIds); |
| | | if (errorTypeMap.isEmpty()) { |
| | | return ""; |
| | | } |
| | | |
| | | LinkedHashSet<Long> orderedParentIds = new LinkedHashSet<>(); |
| | | LinkedHashMap<Long, List<XpErrorType>> childrenByParent = new LinkedHashMap<>(); |
| | | for (Long typeId : orderedTypeIds) { |
| | | XpErrorType errorType = errorTypeMap.get(typeId); |
| | | if (errorType == null || StringUtils.isBlank(errorType.getErrorName())) { |
| | | continue; |
| | | } |
| | | |
| | | if (isTopLevelErrorType(errorType)) { |
| | | orderedParentIds.add(errorType.getId()); |
| | | continue; |
| | | } |
| | | |
| | | Long parentId = errorType.getParentId(); |
| | | if (parentId == null) { |
| | | continue; |
| | | } |
| | | orderedParentIds.add(parentId); |
| | | childrenByParent.computeIfAbsent(parentId, key -> new ArrayList<>()).add(errorType); |
| | | } |
| | | |
| | | List<String> displayNames = new ArrayList<>(); |
| | | for (Long parentId : orderedParentIds) { |
| | | XpErrorType parent = errorTypeMap.get(parentId); |
| | | List<XpErrorType> children = childrenByParent.get(parentId); |
| | | if (CollectionUtils.isEmpty(children)) { |
| | | if (parent != null && StringUtils.isNotBlank(parent.getErrorName())) { |
| | | displayNames.add(parent.getErrorName()); |
| | | } |
| | | continue; |
| | | } |
| | | |
| | | String parentName = parent == null ? null : parent.getErrorName(); |
| | | for (XpErrorType child : children) { |
| | | if (StringUtils.isBlank(parentName)) { |
| | | displayNames.add(child.getErrorName()); |
| | | } else { |
| | | displayNames.add(parentName + ">" + child.getErrorName()); |
| | | } |
| | | } |
| | | } |
| | | return String.join(";", displayNames); |
| | | } |
| | | |
| | | private Map<Long, XpErrorType> getAccidentErrorTypeMap(List<Long> orderedTypeIds) { |
| | | Map<Long, XpErrorType> errorTypeMap = getErrorTypeMap(orderedTypeIds); |
| | | if (errorTypeMap.isEmpty()) { |
| | | return errorTypeMap; |
| | | } |
| | | |
| | | Set<Long> missingParentIds = new LinkedHashSet<>(); |
| | | for (Long typeId : orderedTypeIds) { |
| | | XpErrorType errorType = errorTypeMap.get(typeId); |
| | | if (errorType == null || isTopLevelErrorType(errorType)) { |
| | | continue; |
| | | } |
| | | if (errorType.getParentId() != null && !errorTypeMap.containsKey(errorType.getParentId())) { |
| | | missingParentIds.add(errorType.getParentId()); |
| | | } |
| | | } |
| | | if (!missingParentIds.isEmpty()) { |
| | | errorTypeMap.putAll(getErrorTypeMap(missingParentIds)); |
| | | } |
| | | return errorTypeMap; |
| | | } |
| | | |
| | | private boolean isTopLevelErrorType(XpErrorType errorType) { |
| | | return errorType.getParentId() == null || errorType.getParentId() == 0L; |
| | | } |
| | | |
| | | private String normalizeAccidentTaskTypeId(String taskTypeId) { |
| | | List<Long> orderedTypeIds = parseAccidentTaskTypeIds(taskTypeId); |
| | | if (orderedTypeIds.isEmpty()) { |
| | | return taskTypeId; |
| | | } |
| | | |
| | | LinkedHashSet<Long> normalizedTypeIds = new LinkedHashSet<>(orderedTypeIds); |
| | | Map<Long, XpErrorType> errorTypeMap = getErrorTypeMap(orderedTypeIds); |
| | | for (Long typeId : orderedTypeIds) { |
| | | XpErrorType errorType = errorTypeMap.get(typeId); |
| | | if (errorType == null || errorType.getParentId() == null || errorType.getParentId() == 0L) { |
| | | continue; |
| | | } |
| | | normalizedTypeIds.add(errorType.getParentId()); |
| | | } |
| | | return normalizedTypeIds.stream().map(String::valueOf).collect(Collectors.joining(",")); |
| | | } |
| | | |
| | | private List<Long> parseAccidentTaskTypeIds(String taskTypeId) { |
| | | if (StringUtils.isBlank(taskTypeId)) { |
| | | return Collections.emptyList(); |
| | | } |
| | | |
| | | LinkedHashSet<Long> typeIds = new LinkedHashSet<>(); |
| | | for (String typeId : taskTypeId.split(",")) { |
| | | if (StringUtils.isBlank(typeId)) { |
| | | continue; |
| | | } |
| | | try { |
| | | typeIds.add(Long.parseLong(typeId.trim())); |
| | | } catch (NumberFormatException ignored) { |
| | | } |
| | | } |
| | | return new ArrayList<>(typeIds); |
| | | } |
| | | |
| | | private Map<Long, XpErrorType> getErrorTypeMap(Collection<Long> typeIds) { |
| | | if (CollectionUtils.isEmpty(typeIds)) { |
| | | return Collections.emptyMap(); |
| | | } |
| | | |
| | | return errorTypeMapper.selectBatchIds(typeIds).stream() |
| | | .filter(Objects::nonNull) |
| | | .collect(Collectors.toMap(XpErrorType::getId, errorType -> errorType, (left, right) -> left)); |
| | | } |
| | | |
| | | @Override |
| | |
| | | public void saveTask(SaveErrorTaskDto dto, Long reportUserId) { |
| | | |
| | | List<XpTask> saveTask = new ArrayList<>(); |
| | | String normalizedTaskTypeId = normalizeAccidentTaskTypeId(dto.getTaskTypeId()); |
| | | for (Long vehicleId : dto.getVehicleIds()) { |
| | | XpTask task = new XpTask(); |
| | | BeanUtils.copyProperties(dto, task); |
| | |
| | | String code = sdf.format(new Date()) + UUIDUtil.getNumberRandom(5); |
| | | task.setTaskCode(code); |
| | | task.setTaskCategory(2); |
| | | task.setTaskTypeId(dto.getTaskTypeId()); |
| | | task.setTaskTypeId(normalizedTaskTypeId); |
| | | task.setTaskUrgencyLevel(dto.getTaskUrgencyLevel()); |
| | | task.setTaskDescription(dto.getTaskDescription()); |
| | | task.setTaskImage(dto.getTaskImage()); |