| | |
| | | import cn.hutool.core.date.DateUtil; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.xiaopeng.api.dto.pushMessage.AliPushMessageDTO; |
| | |
| | | private XpVehicleRepairMapper vehicleRepairMapper; |
| | | @Autowired |
| | | private XpVehiclePreparationMapper vehiclePreparationMapper; |
| | | @Autowired |
| | | private XpVehicleDescriptionMapper vehicleDescriptionMapper; |
| | | @Autowired |
| | | private XpVehicleDetectionMapper vehicleDetectionMapper; |
| | | |
| | |
| | | @Override |
| | | public List<TaskManagementPageListVO> exportList(TaskManagementPageListQuery query) { |
| | | List<TaskManagementPageListVO> list = this.baseMapper.exportList(query); |
| | | for (TaskManagementPageListVO taskManagementPageListVO : list) { |
| | | if (org.springframework.util.StringUtils.hasLength(taskManagementPageListVO.getHandleUserId())){ |
| | | String[] split = taskManagementPageListVO.getHandleUserId().split(","); |
| | | List<XpOperationsUser> users = operationUserClient.listByIds(Arrays.stream(split).map(Long::parseLong).collect(Collectors.toList())).getData(); |
| | | if (users!=null){ |
| | | StringBuilder handleUserName = new StringBuilder(); |
| | | for (XpOperationsUser user : users) { |
| | | handleUserName.append(user.getNickName()).append(";"); |
| | | } |
| | | 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)); |
| | | } |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | public XpTask queryInfoByVehicleId(Long vehicleId) { |
| | | return this.baseMapper.queryInfoByVehicleId(vehicleId); |
| | | } |
| | | |
| | | @Override |
| | | public void saveVehicleAccidentError(Long vehicleId) { |
| | | XpTask xpTask = new XpTask(); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); |
| | | String code = sdf.format(new Date()) + UUIDUtil.getNumberRandom(5); |
| | | xpTask.setTaskCode(code); |
| | | xpTask.setTaskCategory(2); |
| | | // todo 事故类型待客户确定 |
| | | xpTask.setTaskTypeId("1"); |
| | | xpTask.setTaskUrgencyLevel(0); |
| | | xpTask.setTaskDescription("车辆发生异常"); |
| | | 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)); |
| | | } |
| | | } |
| | | |
| | | xpTask.setVehicleId(vehicleId); |
| | | // 系统上传异常任务标识 |
| | | xpTask.setReportUserId(0L); |
| | | xpTask.setReportTime(LocalDateTime.now()); |
| | | xpTask.setStatus(0); |
| | | xpTask.setCreateBy("admin"); |
| | | XpTaskRule taskRule = xpTaskRuleService.lambdaQuery().last("limit 1").one(); |
| | | XpTaskRuleRole taskRuleRole = xpTaskRuleRoleService.lambdaQuery().eq(XpTaskRuleRole::getRuleType, 9).last("limit 1").one(); |
| | | if (Objects.isNull(taskRuleRole) || Objects.isNull(taskRule)) { |
| | | throw new ServiceException("未配置车辆事故任务分配规则"); |
| | | } |
| | | R<List<XpOperationsRole>> xpOperationsRoleResult = xpOperationUserClient.getXpOperationsRoleByRoleId(taskRuleRole.getRoleId()); |
| | | if (CollUtil.isNotEmpty(xpOperationsRoleResult.getData())) { |
| | | List<Long> userIds = xpOperationsRoleResult.getData().stream().map(XpOperationsRole::getOperationsUserId).collect(Collectors.toList()); |
| | | xpTask.setHandleUserId(StringUtils.join(userIds, ",")); |
| | | } |
| | | // 根据事故处理限时配置设置任务截止时间 |
| | | LocalDateTime endTime = LocalDateTime.now().plusMinutes(taskRule.getProcessingTimeLimit()); |
| | | xpTask.setEndTime(endTime); |
| | | this.save(xpTask); |
| | | |
| | | // 发送消息通知 |
| | | List<Long> userIds = Arrays.stream(xpTask.getHandleUserId().split(",")).map(Long::valueOf).collect(Collectors.toList()); |
| | | if (CollUtil.isNotEmpty(userIds)) { |
| | | R<List<XpOperationsUser>> xpOperationUserResult = xpOperationUserClient.listByIds(userIds); |
| | | List<XpOperationsUser> data = xpOperationUserResult.getData(); |
| | | if (CollUtil.isNotEmpty(data)) { |
| | | |
| | | String plateNumber = Objects.nonNull(vehicle) ? vehicle.getPlateNumber() : ""; |
| | | // 车辆${车牌号}在${车辆位置信息}发生了紧急事故,请在${到达现场限时}内到达现场!${APP链接} |
| | | String content = String.format("车辆%s在%s发生了紧急事故,请在%d分钟内到达现场!", plateNumber, xpTask.getVehicleLocation(), taskRule.getProcessingTimeLimit()); |
| | | List<XpOperationsUserNotification> notifications = data.stream().map(item -> { |
| | | XpOperationsUserNotification notification = new XpOperationsUserNotification(); |
| | | notification.setOperationsUserId(item.getId()); |
| | | notification.setNotificationContent(content); |
| | | notification.setReadStatus(0); |
| | | notification.setCreateTime(LocalDateTime.now()); |
| | | return notification; |
| | | }).collect(Collectors.toList()); |
| | | xpOperationUserNotificationClient.addNotificationBatch(notifications); |
| | | // 发送阿里云推送 |
| | | Map<Integer, List<XpOperationsUser>> operationUserMap = data.stream().collect(Collectors.groupingBy(XpOperationsUser::getDeviceType)); |
| | | for (Map.Entry<Integer, List<XpOperationsUser>> integerListEntry : operationUserMap.entrySet()) { |
| | | List<XpOperationsUser> value = integerListEntry.getValue(); |
| | | pushAliMessage(value, content, xpTask); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | @Override |
| | | public void saveTask(SaveErrorTaskDto dto, Long reportUserId) { |
| | | List<Long> vehicleIds = dto.getVehicleIds(); |
| | | List<XpVehicle> vehicles = xpVehicleClient.listByIds(vehicleIds).getData(); |
| | | |
| | | List<XpTask> saveTask = new ArrayList<>(); |
| | | for (Long vehicleId : dto.getVehicleIds()) { |
| | | XpTask task = new XpTask(); |
| | |
| | | task.setEndTime(LocalDateTime.now().plusMinutes(taskRule.getProcessingTimeLimit())); |
| | | } |
| | | task.setTaskCategory(2); |
| | | XpTaskRuleRole taskRuleRole = xpTaskRuleRoleService.lambdaQuery().eq(XpTaskRuleRole::getRuleType, 9).last("limit 1").one(); |
| | | if (Objects.isNull(taskRuleRole) || Objects.isNull(taskRule)) { |
| | | throw new ServiceException("未配置车辆事故任务分配规则"); |
| | | } |
| | | R<List<XpOperationsRole>> xpOperationsRoleResult = xpOperationUserClient.getXpOperationsRoleByRoleId(taskRuleRole.getRoleId()); |
| | | if (CollUtil.isNotEmpty(xpOperationsRoleResult.getData())) { |
| | | List<Long> userIds = xpOperationsRoleResult.getData().stream().map(XpOperationsRole::getOperationsUserId).collect(Collectors.toList()); |
| | | task.setHandleUserId(StringUtils.join(userIds, ",")); |
| | | } |
| | | // 根据事故处理限时配置设置任务截止时间 |
| | | LocalDateTime endTime = LocalDateTime.now().plusMinutes(taskRule.getProcessingTimeLimit()); |
| | | task.setEndTime(endTime); |
| | | // todo 临时处理 |
| | | task.setHandleUserId("1"); |
| | | task.setTaskTypeId(dto.getTaskTypeId()); |
| | | task.setTaskUrgencyLevel(dto.getTaskUrgencyLevel()); |
| | | task.setTaskDescription(dto.getTaskDescription()); |
| | |
| | | task.setReportUserId(reportUserId); |
| | | task.setReportTime(LocalDateTime.now()); |
| | | saveTask.add(task); |
| | | // 发送消息通知 |
| | | List<Long> userIds = Arrays.stream(task.getHandleUserId().split(",")).map(Long::valueOf).collect(Collectors.toList()); |
| | | if (CollUtil.isNotEmpty(userIds)) { |
| | | XpVehicle vehicle = vehicles.stream().filter(e -> e.getId().equals(vehicleId)).findFirst().orElse(null); |
| | | R<List<XpOperationsUser>> xpOperationUserResult = xpOperationUserClient.listByIds(userIds); |
| | | List<XpOperationsUser> data = xpOperationUserResult.getData(); |
| | | if (CollUtil.isNotEmpty(data)) { |
| | | |
| | | String plateNumber = Objects.nonNull(vehicle) ? vehicle.getPlateNumber() : ""; |
| | | // 车辆${车牌号}在${车辆位置信息}发生了紧急事故,请在${到达现场限时}内到达现场!${APP链接} |
| | | String content = String.format("车辆%s在%s发生了紧急事故,请在%d分钟内到达现场!", plateNumber, task.getVehicleLocation(), taskRule.getProcessingTimeLimit()); |
| | | List<XpOperationsUserNotification> notifications = data.stream().map(item -> { |
| | | XpOperationsUserNotification notification = new XpOperationsUserNotification(); |
| | | notification.setOperationsUserId(item.getId()); |
| | | notification.setNotificationContent(content); |
| | | notification.setReadStatus(0); |
| | | notification.setCreateTime(LocalDateTime.now()); |
| | | return notification; |
| | | }).collect(Collectors.toList()); |
| | | xpOperationUserNotificationClient.addNotificationBatch(notifications); |
| | | // 发送阿里云推送 |
| | | Map<Integer, List<XpOperationsUser>> operationUserMap = data.stream().collect(Collectors.groupingBy(XpOperationsUser::getDeviceType)); |
| | | for (Map.Entry<Integer, List<XpOperationsUser>> integerListEntry : operationUserMap.entrySet()) { |
| | | List<XpOperationsUser> value = integerListEntry.getValue(); |
| | | pushAliMessage(value, content, task); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | this.saveBatch(saveTask); |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | |
| | | |
| | | XpVehiclePreparation vehiclePreparation = vehiclePreparationMapper.selectOne(new LambdaQueryWrapper<XpVehiclePreparation>() |
| | | .eq(XpVehiclePreparation::getTaskId, id).last("limit 1")); |
| | | XpVehicleDescription xpVehicleDescription = vehicleDescriptionMapper.selectOne( |
| | | new LambdaQueryWrapper<XpVehicleDescription>().eq(XpVehicleDescription::getDescriptionType, 5) |
| | | ); |
| | | if (xpVehicleDescription != null) { |
| | | taskManagementPreparationDetailVO.setLostItemsDetail(xpVehicleDescription.getDescriptionContent()); |
| | | } |
| | | if (vehiclePreparation != null) { |
| | | taskManagementPreparationDetailVO.setLeftFrontWheel(vehiclePreparation.getLeftFrontWheel()); |
| | | taskManagementPreparationDetailVO.setRightFrontWheel(vehiclePreparation.getRightFrontWheel()); |