package com.xiaopeng.maintenance.service.impl; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson2.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.xiaopeng.api.dto.pushMessage.AliPushMessageDTO; import com.xiaopeng.api.feignClient.account.SysUserClient; import com.xiaopeng.api.feignClient.account.XpOperationUserClient; import com.xiaopeng.api.feignClient.account.XpOperationUserNotificationClient; import com.xiaopeng.api.feignClient.pushMessage.XpAliPushMessageClient; import com.xiaopeng.api.feignClient.vehicleConvoy.XpVehicleClient; import com.xiaopeng.api.model.account.SysUser; import com.xiaopeng.api.model.account.XpOperationsRole; import com.xiaopeng.api.model.account.XpOperationsUser; import com.xiaopeng.api.model.account.XpOperationsUserNotification; import com.xiaopeng.api.model.maintenance.*; import com.xiaopeng.api.model.vehicleConvoy.XpVehicle; import com.xiaopeng.api.vo.automaticPilot.VehiclePosition; import com.xiaopeng.common.core.constant.AliPushTypeConstant; import com.xiaopeng.common.core.domain.R; import com.xiaopeng.common.core.enums.NotificationTypeEnum; import com.xiaopeng.common.core.enums.TaskTypeEnum; import com.xiaopeng.common.core.enums.TaskTypeNotificationEnum; import com.xiaopeng.common.core.exception.ServiceException; import com.xiaopeng.common.core.web.page.PageInfo; import com.xiaopeng.maintenance.constant.I18nKeyConstant; import com.xiaopeng.maintenance.dto.HandleVehicleAccidentDto; import com.xiaopeng.maintenance.dto.SaveErrorTaskDto; import com.xiaopeng.maintenance.dto.SaveRoutineDetailDto; import com.xiaopeng.maintenance.dto.SaveVehicleAccidentDto; import com.xiaopeng.maintenance.mapper.*; import com.xiaopeng.maintenance.model.query.TaskManagementPageListQuery; import com.xiaopeng.maintenance.model.query.TaskPageListQuery; import com.xiaopeng.maintenance.model.query.WorkBenchQuery; import com.xiaopeng.maintenance.model.query.XpTaskRecordPageQuery; import com.xiaopeng.maintenance.model.vo.*; import com.xiaopeng.maintenance.service.IXpTaskRuleRoleService; import com.xiaopeng.maintenance.service.IXpTaskRuleService; import com.xiaopeng.maintenance.service.XpTaskService; import com.xiaopeng.maintenance.utils.UUIDUtil; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.redisson.api.RLock; import org.redisson.api.RedissonClient; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Query; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import javax.annotation.Resource; import java.math.BigDecimal; import java.text.SimpleDateFormat; import java.time.LocalDateTime; import java.time.LocalTime; import java.time.format.DateTimeFormatter; import java.util.*; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; /** *

* 任务管理 服务实现类 *

* * @author WuGuanFengYue * @since 2026-02-03 */ @Slf4j @Service public class XpTaskServiceImpl extends ServiceImpl implements XpTaskService { @Autowired private RedissonClient redissonClient; @Autowired private XpErrorTypeMapper errorTypeMapper; @Resource private XpOperationUserClient operationUserClient; @Autowired private XpTaskHandleDetailMapper xpTaskHandleDetailMapper; @Autowired private XpChargingRecordMapper chargingRecordMapper; @Autowired private XpVehicleRepairMapper vehicleRepairMapper; @Autowired private XpVehiclePreparationMapper vehiclePreparationMapper; @Autowired private XpVehicleDetectionMapper vehicleDetectionMapper; @Autowired private XpVehicleCleanMapper vehicleCleanMapper; @Autowired private XpOperationUserClient xpOperationUserClient; @Autowired private SysUserClient sysUserClient; @Autowired private XpTaskHandleDetailRoutineMapper xpTaskHandleDetailRoutineMapper; @Autowired private XpVehicleClient xpVehicleClient; @Autowired private XpTaskRuleMapper xpTaskRuleMapper; @Autowired private MongoTemplate mongoTemplate; @Autowired private XpAliPushMessageClient xpAliPushMessageClient; @Autowired private XpOperationUserNotificationClient xpOperationUserNotificationClient; @Autowired private IXpTaskRuleRoleService xpTaskRuleRoleService; @Autowired private IXpTaskRuleService xpTaskRuleService; @Override public PageInfo workbench(WorkBenchQuery query) { PageInfo pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize()); List list = this.baseMapper.workbench(pageInfo, query); pageInfo.setRecords(list); return pageInfo; } @Override public PageInfo pageList(TaskPageListQuery query) { if (query.getDistributeType() != null) { LocalDateTime now = LocalDateTime.now(); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); switch (query.getDistributeType()) { case 1: // 今天 query.setStartTime(now.with(LocalTime.MIN).format(formatter)); query.setEndTime(now.with(LocalTime.MAX).format(formatter)); break; case 2: // 昨天 LocalDateTime yesterdayStart = now.minusDays(1).with(LocalTime.MIN); LocalDateTime yesterdayEnd = now.minusDays(1).with(LocalTime.MAX); query.setStartTime(yesterdayStart.format(formatter)); query.setEndTime(yesterdayEnd.format(formatter)); break; case 3: // 近一周 LocalDateTime weekAgoStart = now.minusDays(7).with(LocalTime.MIN); query.setStartTime(weekAgoStart.format(formatter)); query.setEndTime(now.with(LocalTime.MAX).format(formatter)); break; case 4: // 近一月 LocalDateTime monthAgoStart = now.minusDays(30).with(LocalTime.MIN); query.setStartTime(monthAgoStart.format(formatter)); query.setEndTime(now.with(LocalTime.MAX).format(formatter)); break; default: // 默认不设置时间范围 break; } } PageInfo pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize()); List list = this.baseMapper.pageList(pageInfo, query); XpTaskRule xpTaskRule = xpTaskRuleMapper.selectOne(new LambdaQueryWrapper().last("limit 1")); // if (Objects.nonNull(xpTaskRule)) { // list.stream().filter(item -> item.getTaskCategory().equals(2)).forEach(item -> { // item.setCanArriveRange(xpTaskRule.getCanArriveRange()); // }); // } pageInfo.setRecords(list); return pageInfo; } @Transactional(rollbackFor = Exception.class) @Override public void saveVehicleAccident(SaveVehicleAccidentDto dto, XpOperationsUser xpOperationsUser) { XpTask xpTask = new XpTask(); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); String code = sdf.format(new Date()) + UUIDUtil.getNumberRandom(5); xpTask.setTaskCode(code); xpTask.setTaskCategory(2); String[] split = dto.getTaskTypeId().split(","); List typeIds = new ArrayList<>(); for (String s : split) { typeIds.add(s.trim()); } StringBuilder temp = new StringBuilder(dto.getTaskTypeId()); List children = typeIds.stream().map(Long::parseLong).collect(Collectors.toList()); List parentIds = errorTypeMapper.selectList(new LambdaQueryWrapper() .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.setTaskUrgencyLevel(dto.getTaskUrgencyLevel()); xpTask.setTaskDescription(dto.getTaskDescription()); 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.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()); xpTask.setStatus(0); xpTask.setCreateBy(xpOperationsUser.getNickName()); 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> xpOperationsRoleResult = xpOperationUserClient.getXpOperationsRoleByRoleId(taskRuleRole.getRoleId()); if (CollUtil.isNotEmpty(xpOperationsRoleResult.getData())) { List 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); // 异步发送消息通知 String plateNumber = Objects.nonNull(vehicle) ? vehicle.getPlateNumber() : ""; sendAccidentNotificationAsync(xpTask, plateNumber, taskRule.getProcessingTimeLimit()); } /** * 异步发送事故通知 * @param xpTask 任务信息 * @param plateNumber 车牌号 * @param processingTimeLimit 处理时限(分钟) */ private void sendAccidentNotificationAsync(XpTask xpTask, String plateNumber, Integer processingTimeLimit) { ThreadPoolExecutor executor = new ThreadPoolExecutor( 1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue() ); executor.execute(() -> { try { List userIds = Arrays.stream(xpTask.getHandleUserId().split(",")).map(Long::valueOf).collect(Collectors.toList()); if (CollUtil.isEmpty(userIds)) { return; } R> xpOperationUserResult = xpOperationUserClient.listByIds(userIds); List data = xpOperationUserResult.getData(); if (CollUtil.isEmpty(data)) { return; } // 构建通知内容 String content = String.format("车辆%s在%s发生了紧急事故,请在%d分钟内到达现场!", plateNumber, xpTask.getVehicleLocation(), processingTimeLimit); String bodyJson = buildAccidentPushBodyJson(content, xpTask); // 构建通知记录(包含 notificationExt) List notifications = data.stream().map(item -> { XpOperationsUserNotification notification = new XpOperationsUserNotification(); notification.setOperationsUserId(item.getId()); notification.setNotificationType(NotificationTypeEnum.ACCIDENT_NEW.getCode()); notification.setNotificationContent(content); notification.setDataId(xpTask.getId()); notification.setReadStatus(0); notification.setNotificationExt(bodyJson); return notification; }).collect(Collectors.toList()); // 批量保存通知记录 xpOperationUserNotificationClient.addNotificationBatch(notifications); log.info("事故通知记录保存成功,共 {} 条", notifications.size()); // 按设备类型分组发送阿里云推送 Map> operationUserMap = data.stream() .filter(u -> u.getDeviceType() != null && u.getPhoneNumber() != null) .collect(Collectors.groupingBy(XpOperationsUser::getDeviceType)); for (Map.Entry> entry : operationUserMap.entrySet()) { pushAliMessage(entry.getValue(), content, xpTask); } } catch (Exception e) { log.error("发送事故通知失败,任务ID={}", xpTask.getId(), e); } }); executor.shutdown(); } /** * 构建事故推送 body JSON * @param content 消息内容 * @param xpTask 任务信息 * @return JSON 字符串 */ private String buildAccidentPushBodyJson(String content, XpTask xpTask) { Map param = new HashMap<>(); param.put("content", content); param.put("strategy", NotificationTypeEnum.ACCIDENT_NEW.getCode()); param.put("type", TaskTypeNotificationEnum.ACCIDENT_TASK.getCode()); param.put("id", xpTask.getId().toString()); return JSONObject.toJSONString(param); } /** * 推送阿里云通知 * * @param data * @param content * @param xpTask */ private void pushAliMessage(List data, String content, XpTask xpTask) { String account = data.stream().map(XpOperationsUser::getPhoneNumber).filter(Objects::nonNull).collect(Collectors.joining(",")); Map param = new HashMap<>(); param.put("content", content); param.put("strategy", NotificationTypeEnum.ACCIDENT_NEW.getCode()); param.put("type", TaskTypeNotificationEnum.ACCIDENT_TASK.getCode()); param.put("id", xpTask.getId().toString()); xpAliPushMessageClient.pushMessage(AliPushMessageDTO.builder() .body(JSONObject.toJSONString(param)) .account(account).title("车辆事故警示") .pushType(AliPushTypeConstant.NOTICE) .deviceType(data.get(0).getDeviceType()) .build()); } @Override public R vehicleAccidentDetail(Long id) { TaskAccidentDetailVO res = new TaskAccidentDetailVO(); XpTask task = this.getById(id); if (task == null) { throw new ServiceException( "任务不存在", I18nKeyConstant.TASK_NOT_EXIST ); } XpVehicle vehicle = xpVehicleClient.queryById(task.getVehicleId()).getData(); if (vehicle == null) { throw new ServiceException( "车辆不存在", I18nKeyConstant.VEHICLE_NOT_EXIST ); } res.setId(id); res.setVehicleId(vehicle.getId()); res.setTaskUrgencyLevel(task.getTaskUrgencyLevel()); res.setEndTime(task.getEndTime()); res.setPlateNumber(vehicle.getPlateNumber()); res.setVehicleColor(vehicle.getVehicleColor()); res.setVehicleCode(vehicle.getVehicleCode()); res.setVehicleLocation(task.getVehicleLocation()); res.setCreateBy(task.getCreateBy()); res.setCreateTime(task.getCreateTime()); res.setTaskCode(task.getTaskCode()); res.setTaskCategory(task.getTaskCategory()); res.setTaskTypeId(task.getTaskTypeId()); res.setVehicleLon(task.getVehicleLon()); res.setVehicleLat(task.getVehicleLat()); Map> errorType = errorTypeMapper.selectList(new LambdaQueryWrapper() .in(XpErrorType::getId, Arrays.asList(task.getTaskTypeId().split(",")))) .stream().collect(Collectors.groupingBy(XpErrorType::getParentId)); List xpErrorTypes = errorType.get(0L); for (XpErrorType xpErrorType : xpErrorTypes) { xpErrorType.setChild(errorType.get(xpErrorType.getId())); } res.setErrorTypeList(xpErrorTypes); res.setStatus(task.getStatus()); res.setTaskDescription(task.getTaskDescription()); res.setTaskImage(task.getTaskImage()); XpTaskRule xpTaskRule = xpTaskRuleMapper.selectOne(new LambdaQueryWrapper().last("limit 1")); if (Objects.nonNull(xpTaskRule)) { res.setCanArriveRange(xpTaskRule.getCanArriveRange()); } return R.ok(res); } @Override public R handleVehicleAccident(HandleVehicleAccidentDto dto, XpOperationsUser xpOperationsUser) { XpTask task = this.getById(dto.getId()); if (task == null) { throw new ServiceException( "任务不存在", I18nKeyConstant.TASK_NOT_EXIST ); } task.setHandleTime(LocalDateTime.now()); task.setHandleUserId(xpOperationsUser.getId().toString()); task.setStatus(2); // 存储事故处理日志 XpTaskHandleDetail xpTaskHandleDetail = new XpTaskHandleDetail(); xpTaskHandleDetail.setTaskId(task.getId()); xpTaskHandleDetail.setDeathCount(dto.getDeathCount()); xpTaskHandleDetail.setSevereCount(dto.getSevereCount()); xpTaskHandleDetail.setMinorCount(dto.getMinorCount()); xpTaskHandleDetail.setResponsibilityJudgment(dto.getResponsibilityJudgment()); xpTaskHandleDetail.setResponsibleDescription(dto.getResponsibleDescription()); xpTaskHandleDetail.setResponsibleImage(dto.getResponsibleImage()); xpTaskHandleDetail.setDisposalDescription(dto.getDisposalDescription()); xpTaskHandleDetail.setDisposalImage(dto.getDisposalImage()); xpTaskHandleDetail.setSituationDescription(dto.getSituationDescription()); xpTaskHandleDetail.setSituationImage(dto.getSituationImage()); xpTaskHandleDetailMapper.insert(xpTaskHandleDetail); return R.ok(); } @Override public R vehicleRoutineDetail(Long id) { TaskRoutineDetailVO res = new TaskRoutineDetailVO(); XpTask task = this.getById(id); if (task == null) { throw new ServiceException( "任务不存在", I18nKeyConstant.TASK_NOT_EXIST ); } XpVehicle vehicle = xpVehicleClient.queryById(task.getVehicleId()).getData(); if (vehicle == null) { throw new ServiceException( "车辆不存在", I18nKeyConstant.VEHICLE_NOT_EXIST ); } res.setId(id); res.setTaskUrgencyLevel(task.getTaskUrgencyLevel()); res.setEndTime(task.getEndTime()); res.setVehicleId(task.getVehicleId()); res.setVehicleLat(task.getVehicleLat()); res.setVehicleLon(task.getVehicleLon()); res.setPlateNumber(vehicle.getPlateNumber()); res.setVehicleColor(vehicle.getVehicleColor()); res.setVehicleCode(vehicle.getVehicleCode()); res.setVehicleLocation(task.getVehicleLocation()); res.setCreateBy(task.getCreateBy()); res.setCreateTime(task.getCreateTime()); res.setTaskCode(task.getTaskCode()); res.setTaskCategory(task.getTaskCategory()); res.setTaskTypeId(task.getTaskTypeId()); res.setStatus(task.getStatus()); res.setTaskDescription(task.getTaskDescription()); res.setTaskImage(task.getTaskImage()); res.setHandleUserId(task.getHandleUserId()); res.setHandleTime(task.getHandleTime()); if (Objects.nonNull(task.getHandleUserId()) && task.getHandleUserId().split(",").length == 1) { XpOperationsUser data = xpOperationUserClient.queryById(Long.valueOf(task.getHandleUserId())).getData(); if (Objects.nonNull(data)) { res.setHandleUserName(data.getNickName()); } } return R.ok(res); } @Override public R chargingDetail(Long id) { TaskChargingDetailVO res = new TaskChargingDetailVO(); XpTask task = this.getById(id); if (task == null) { throw new ServiceException( "任务不存在", I18nKeyConstant.TASK_NOT_EXIST ); } XpVehicle vehicle = xpVehicleClient.queryById(task.getVehicleId()).getData(); if (vehicle == null) { throw new ServiceException( "车辆不存在", I18nKeyConstant.VEHICLE_NOT_EXIST ); } res.setVehicleId(task.getVehicleId()); res.setId(id); res.setTaskUrgencyLevel(task.getTaskUrgencyLevel()); res.setPlateNumber(vehicle.getPlateNumber()); res.setVehicleColor(vehicle.getVehicleColor()); res.setVehicleCode(vehicle.getVehicleCode()); res.setVehicleLocation(task.getVehicleLocation()); res.setCreateBy(task.getCreateBy()); res.setCreateTime(task.getCreateTime()); res.setTaskCode(task.getTaskCode()); res.setTaskCategory(task.getTaskCategory()); res.setTaskTypeId(task.getTaskTypeId()); res.setStatus(task.getStatus()); XpChargingRecord chargingRecord = chargingRecordMapper.selectOne(new LambdaQueryWrapper() .eq(XpChargingRecord::getTaskId, id).last("limit 1")); if (chargingRecord != null) { res.setStartRemainingBattery(chargingRecord.getStartRemainingBattery()); res.setStartChargingPicture(chargingRecord.getStartChargingPicture()); res.setStartTime(chargingRecord.getStartTime()); res.setEndRemainingBattery(chargingRecord.getEndRemainingBattery()); res.setEndChargingPicture(chargingRecord.getEndChargingPicture()); res.setEndTime(chargingRecord.getEndTime()); res.setStartOperationsUserId(chargingRecord.getStartOperationsUserId()); res.setEndOperationsUserId(chargingRecord.getEndOperationsUserId()); if (chargingRecord.getStartOperationsUserId() != null) { XpOperationsUser operationsUser = xpOperationUserClient.queryById(chargingRecord.getStartOperationsUserId()).getData(); if (operationsUser != null) { res.setStartOperationsUserName(operationsUser.getNickName()); } } if (chargingRecord.getEndOperationsUserId() != null) { XpOperationsUser operationsUser = xpOperationUserClient.queryById(chargingRecord.getEndOperationsUserId()).getData(); if (operationsUser != null) { res.setEndOperationsUserName(operationsUser.getNickName()); } } } return R.ok(res); } @Override public R repairDetail(Long id) { com.xiaopeng.maintenance.vo.TaskRepairDetailVO res = new com.xiaopeng.maintenance.vo.TaskRepairDetailVO(); XpTask task = this.getById(id); if (task == null) { throw new ServiceException( "任务不存在", I18nKeyConstant.TASK_NOT_EXIST ); } XpVehicle vehicle = xpVehicleClient.queryById(task.getVehicleId()).getData(); if (vehicle == null) { throw new ServiceException( "车辆不存在", I18nKeyConstant.VEHICLE_NOT_EXIST ); } res.setVehicleId(task.getVehicleId()); res.setId(id); res.setTaskUrgencyLevel(task.getTaskUrgencyLevel()); res.setPlateNumber(vehicle.getPlateNumber()); res.setVehicleColor(vehicle.getVehicleColor()); res.setVehicleCode(vehicle.getVehicleCode()); res.setVehicleLocation(task.getVehicleLocation()); res.setCreateBy(task.getCreateBy()); res.setCreateTime(task.getCreateTime()); res.setTaskCode(task.getTaskCode()); res.setTaskCategory(task.getTaskCategory()); res.setTaskTypeId(task.getTaskTypeId()); res.setStatus(task.getStatus()); XpVehicleRepair vehicleRepair = vehicleRepairMapper.selectOne(new LambdaQueryWrapper() .eq(XpVehicleRepair::getTaskId, id).last("limit 1")); if (vehicleRepair != null) { res.setStartTime(vehicleRepair.getStartTime()); res.setEndTime(vehicleRepair.getEndTime()); res.setRepairReason(vehicleRepair.getRepairReason()); res.setStartRepairPicture(vehicleRepair.getStartRepairPicture()); res.setRepairMoney(vehicleRepair.getRepairMoney()); res.setRepairMoneyDetail(vehicleRepair.getRepairMoneyDetail()); res.setSendUserId(vehicleRepair.getSendUserId()); res.setSendTime(vehicleRepair.getSendTime()); res.setReturnUserId(vehicleRepair.getReturnUserId()); res.setReturnTime(vehicleRepair.getReturnTime()); if (vehicleRepair.getReturnUserId() != null) { XpOperationsUser operationsUser = xpOperationUserClient.queryById(vehicleRepair.getReturnUserId()).getData(); if (operationsUser != null) { res.setReturnUserName(operationsUser.getNickName()); } } if (vehicleRepair.getSendUserId() != null) { XpOperationsUser operationsUser = xpOperationUserClient.queryById(vehicleRepair.getSendUserId()).getData(); if (operationsUser != null) { res.setSendUserName(operationsUser.getNickName()); } } } return R.ok(res); } @Override public R preparationDetail(Long id) { com.xiaopeng.maintenance.vo.TaskPreparationDetailVO res = new com.xiaopeng.maintenance.vo.TaskPreparationDetailVO(); XpTask task = this.getById(id); if (task == null) { throw new ServiceException( "任务不存在", I18nKeyConstant.TASK_NOT_EXIST ); } XpVehicle vehicle = xpVehicleClient.queryById(task.getVehicleId()).getData(); if (vehicle == null) { throw new ServiceException( "车辆不存在", I18nKeyConstant.VEHICLE_NOT_EXIST ); } res.setVehicleId(task.getVehicleId()); res.setId(id); res.setTaskUrgencyLevel(task.getTaskUrgencyLevel()); res.setPlateNumber(vehicle.getPlateNumber()); res.setVehicleColor(vehicle.getVehicleColor()); res.setVehicleCode(vehicle.getVehicleCode()); res.setVehicleLocation(task.getVehicleLocation()); res.setCreateBy(task.getCreateBy()); res.setCreateTime(task.getCreateTime()); res.setTaskCode(task.getTaskCode()); res.setTaskCategory(task.getTaskCategory()); res.setTaskTypeId(task.getTaskTypeId()); res.setStatus(task.getStatus()); XpVehiclePreparation vehiclePreparation = vehiclePreparationMapper.selectOne(new LambdaQueryWrapper() .eq(XpVehiclePreparation::getTaskId, id).last("limit 1")); if (vehiclePreparation != null) { res.setLeftFrontWheel(vehiclePreparation.getLeftFrontWheel()); res.setRightFrontWheel(vehiclePreparation.getRightFrontWheel()); res.setLeftRearWheel(vehiclePreparation.getLeftRearWheel()); res.setRightRearWheel(vehiclePreparation.getRightRearWheel()); res.setHeadLight(vehiclePreparation.getHeadLight()); res.setTurnSignal(vehiclePreparation.getTurnSignal()); res.setBrakeLight(vehiclePreparation.getBrakeLight()); res.setFogLight(vehiclePreparation.getFogLight()); res.setBodyEmblem(vehiclePreparation.getBodyEmblem()); res.setCabinCleaning(vehiclePreparation.getCabinCleaning()); res.setLostItems(vehiclePreparation.getLostItems()); res.setRemarks(vehiclePreparation.getRemarks()); res.setOperationsUserId(vehiclePreparation.getOperationsUserId()); res.setOperationsTime(vehiclePreparation.getCreateTime()); if (vehiclePreparation.getOperationsUserId() != null) { XpOperationsUser operationsUser = xpOperationUserClient.queryById(vehiclePreparation.getOperationsUserId()).getData(); if (operationsUser != null) { res.setOperationsUserName(operationsUser.getNickName()); } } } return R.ok(res); } @Override public R detectionDetail(Long id) { com.xiaopeng.maintenance.vo.TaskDetectionDetailVO res = new com.xiaopeng.maintenance.vo.TaskDetectionDetailVO(); XpTask task = this.getById(id); if (task == null) { throw new ServiceException( "任务不存在", I18nKeyConstant.TASK_NOT_EXIST ); } XpVehicle vehicle = xpVehicleClient.queryById(task.getVehicleId()).getData(); if (vehicle == null) { throw new ServiceException( "车辆不存在", I18nKeyConstant.VEHICLE_NOT_EXIST ); } res.setVehicleId(task.getVehicleId()); res.setId(id); res.setTaskUrgencyLevel(task.getTaskUrgencyLevel()); res.setPlateNumber(vehicle.getPlateNumber()); res.setVehicleColor(vehicle.getVehicleColor()); res.setVehicleCode(vehicle.getVehicleCode()); res.setVehicleLocation(task.getVehicleLocation()); res.setCreateBy(task.getCreateBy()); res.setCreateTime(task.getCreateTime()); res.setTaskCode(task.getTaskCode()); res.setTaskCategory(task.getTaskCategory()); res.setTaskTypeId(task.getTaskTypeId()); res.setStatus(task.getStatus()); XpVehicleDetection vehicleDetection = vehicleDetectionMapper.selectOne(new LambdaQueryWrapper() .eq(XpVehicleDetection::getTaskId, id).last("limit 1")); if (vehicleDetection != null) { res.setNetworkDetection(vehicleDetection.getNetworkDetection()); res.setVersionVerification(vehicleDetection.getVersionVerification()); res.setCommunicationSelfCheck(vehicleDetection.getCommunicationSelfCheck()); res.setRemoteSelfCheck(vehicleDetection.getRemoteSelfCheck()); res.setCollisionPrevention(vehicleDetection.getCollisionPrevention()); res.setSensorSelfCheck(vehicleDetection.getSensorSelfCheck()); res.setSensorCleaning(vehicleDetection.getSensorCleaning()); res.setSensorCleaningPicture(vehicleDetection.getSensorCleaningPicture()); res.setInteractiveScreen(vehicleDetection.getInteractiveScreen()); res.setInteractiveScreenPicture(vehicleDetection.getInteractiveScreenPicture()); res.setHelpButton(vehicleDetection.getHelpButton()); res.setHelpButtonPicture(vehicleDetection.getHelpButtonPicture()); res.setPaymentFunction(vehicleDetection.getPaymentFunction()); res.setPaymentFunctionPicture(vehicleDetection.getPaymentFunctionPicture()); res.setSystemCheck(vehicleDetection.getSystemCheck()); res.setSystemCheckPicture(vehicleDetection.getSystemCheckPicture()); res.setCheckTime(vehicleDetection.getCheckTime()); res.setOperationsUserId(vehicleDetection.getOperationsUserId()); if (vehicleDetection.getOperationsUserId() != null) { XpOperationsUser operationsUser = xpOperationUserClient.queryById(vehicleDetection.getOperationsUserId()).getData(); if (operationsUser != null) { res.setOperationsUserName(operationsUser.getNickName()); } } } return R.ok(res); } @Override public R saveRoutineDetail(SaveRoutineDetailDto dto, Long id) { XpTask task = this.getById(dto.getId()); if (task == null) { throw new ServiceException( "任务不存在", I18nKeyConstant.TASK_NOT_EXIST ); } XpTaskHandleDetailRoutine xpTaskHandleDetailRoutine = new XpTaskHandleDetailRoutine(); xpTaskHandleDetailRoutine.setTaskId(task.getId()); String taskTypeId = task.getTaskTypeId(); switch (taskTypeId) { case "6": xpTaskHandleDetailRoutine.setTaskType(1); break; case "7": xpTaskHandleDetailRoutine.setTaskType(2); break; case "8": xpTaskHandleDetailRoutine.setTaskType(3); break; case "9": xpTaskHandleDetailRoutine.setTaskType(4); break; } xpTaskHandleDetailRoutine.setTaskDescription(dto.getTaskDescription()); xpTaskHandleDetailRoutine.setTaskImage(dto.getTaskImage()); xpTaskHandleDetailRoutine.setOperationsUserId(id); xpTaskHandleDetailRoutineMapper.insert(xpTaskHandleDetailRoutine); //更新任务状态为已完成 lambdaUpdate().set(XpTask::getStatus, 2).eq(XpTask::getId, dto.getId()).update(); return R.ok(); } @Override public R cleanDetail(Long id) { com.xiaopeng.maintenance.vo.TaskCleanDetailVO res = new com.xiaopeng.maintenance.vo.TaskCleanDetailVO(); XpTask task = this.getById(id); if (task == null) { throw new ServiceException( "任务不存在", I18nKeyConstant.TASK_NOT_EXIST ); } XpVehicle vehicle = xpVehicleClient.queryById(task.getVehicleId()).getData(); if (vehicle == null) { throw new ServiceException( "车辆不存在", I18nKeyConstant.VEHICLE_NOT_EXIST ); } res.setVehicleId(task.getVehicleId()); res.setId(id); res.setTaskUrgencyLevel(task.getTaskUrgencyLevel()); res.setPlateNumber(vehicle.getPlateNumber()); res.setVehicleColor(vehicle.getVehicleColor()); res.setVehicleCode(vehicle.getVehicleCode()); res.setVehicleLocation(task.getVehicleLocation()); res.setCreateBy(task.getCreateBy()); res.setCreateTime(task.getCreateTime()); res.setTaskCode(task.getTaskCode()); res.setTaskCategory(task.getTaskCategory()); res.setTaskTypeId(task.getTaskTypeId()); res.setStatus(task.getStatus()); XpVehicleClean vehicleDetection = vehicleCleanMapper.selectOne(new LambdaQueryWrapper() .eq(XpVehicleClean::getTaskId, id).last("limit 1")); if (vehicleDetection != null) { res.setTaskImage(vehicleDetection.getTaskImage()); res.setOperationUserId(vehicleDetection.getOperationsUserId()); if (vehicleDetection.getOperationsUserId() != null) { XpOperationsUser operationsUser = xpOperationUserClient.queryById(vehicleDetection.getOperationsUserId()).getData(); if (operationsUser != null) { res.setOperationsUserName(operationsUser.getNickName()); } } } return R.ok(res); } @Override public R confirmArrive(Long id, Long userId) { RLock lock = redissonClient.getLock("TASK_CONFIRM_" + id); try { // 尝试获取锁,最多等待3秒 boolean isLocked = lock.tryLock(3, 10, TimeUnit.SECONDS); if (!isLocked) { return R.fail("系统繁忙,请稍后重试"); } // 查询任务 XpTask task = this.getById(id); if (task == null) { return R.fail("任务不存在"); } // 检查任务状态 if (task.getStatus() != 0) { return R.fail("任务已被处理"); } // 更新任务 task.setStatus(1); task.setVehicleId(null); task.setHandleUserId(userId.toString()); this.updateById(task); return R.ok(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); return R.fail("操作被中断"); } finally { // 确保锁被释放 if (lock.isHeldByCurrentThread()) { lock.unlock(); } } } @Override public PageInfo queryTaskByVehicleId(XpTaskRecordPageQuery query) { // 1. 构建查询条件 LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.eq(XpTask::getVehicleId, query.getVehicleId()); if (query.getTaskCategory() != null) { wrapper.eq(XpTask::getTaskCategory, query.getTaskCategory()); } if (Objects.nonNull(query.getTaskGeneralId())) { wrapper.eq(XpTask::getTaskTypeId, query.getTaskGeneralId()).eq(XpTask::getTaskCategory, 1); } if (Objects.nonNull(query.getTaskErrorId())) { wrapper.apply("find_in_set({0}, task_type_id)", query.getTaskErrorId()) .eq(XpTask::getTaskCategory, 2); } if (query.getStartTime() != null) { wrapper.ge(XpTask::getCreateTime, query.getStartTime().atStartOfDay()); } if (query.getEndTime() != null) { wrapper.le(XpTask::getCreateTime, query.getEndTime().atTime(23, 59, 59)); } wrapper.orderByDesc(XpTask::getCreateTime); // 2. 执行分页查询 Page page = new Page<>(query.getPageNum(), query.getPageSize()); Page resultPage = this.page(page, wrapper); // 3. 转换为 VO 并填充 typeName List records = new ArrayList<>(); if (!CollectionUtils.isEmpty(resultPage.getRecords())) { // 3.1 收集所有事故任务的 errorType ID Set errorTypeIds = new HashSet<>(); for (XpTask task : resultPage.getRecords()) { if (task.getTaskCategory() != null && task.getTaskCategory() == 2 && StringUtils.isNotBlank(task.getTaskTypeId())) { String[] ids = task.getTaskTypeId().split(","); for (String id : ids) { try { errorTypeIds.add(Long.parseLong(id.trim())); } catch (NumberFormatException e) { // 忽略格式错误的ID } } } } // 3.2 批量查询 errorType Map errorTypeMap = new HashMap<>(); if (!errorTypeIds.isEmpty()) { List errorTypes = errorTypeMapper.selectBatchIds(errorTypeIds); for (XpErrorType errorType : errorTypes) { errorTypeMap.put(errorType.getId(), errorType.getErrorName()); } } // 3.3 填充 typeName for (XpTask task : resultPage.getRecords()) { XpTaskRecordVO vo = new XpTaskRecordVO(); BeanUtils.copyProperties(task, vo); // 填充 typeName if (task.getTaskCategory() != null && task.getTaskCategory() == 1) { // 常规任务: 使用枚举映射 vo.setTypeName(TaskTypeEnum.getEnumDescByCode(Integer.valueOf(task.getTaskTypeId()))); } else if (task.getTaskCategory() != null && task.getTaskCategory() == 2) { // 事故任务: 拼接父子级名称 if (StringUtils.isNotBlank(task.getTaskTypeId())) { String[] ids = task.getTaskTypeId().split(","); if (ids.length >= 2) { try { String parentName = errorTypeMap.get(Long.parseLong(ids[0].trim())); String childName = errorTypeMap.get(Long.parseLong(ids[1].trim())); if (parentName != null && childName != null) { vo.setTypeName(parentName + "->" + childName); } } catch (NumberFormatException e) { // 忽略格式错误的ID } } } } records.add(vo); } } // 4. 构建分页结果 PageInfo pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize()); pageInfo.setRecords(records); pageInfo.setTotal(resultPage.getTotal()); return pageInfo; } @Override public void deleteTaskById(Long id) { removeById(id); } @Override public void updateTaskStatus(Long taskId, Integer status) { if (Objects.nonNull(taskId)) { XpTask task = this.getById(taskId); if (Objects.nonNull(task)) { this.lambdaUpdate().set(XpTask::getStatus, status).eq(XpTask::getId, taskId).update(); } } } @Override public PageInfo pageListManagement(TaskManagementPageListQuery query) { PageInfo pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize()); List list = this.baseMapper.pageListManagement(pageInfo, query); for (TaskManagementPageListVO taskManagementPageListVO : list) { if (org.springframework.util.StringUtils.hasLength(taskManagementPageListVO.getHandleUserId())){ String[] split = taskManagementPageListVO.getHandleUserId().split(","); List 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 xpErrorTypes = errorTypeMapper.selectList(new LambdaQueryWrapper() .in(XpErrorType::getId, Arrays.asList(typeIds)).orderByAsc(XpErrorType::getParentId)); List parents = new ArrayList<>(); for (XpErrorType xpErrorType : xpErrorTypes) { if (xpErrorType.getParentId() == 0) { parents.add(xpErrorType); } } for (XpErrorType parent : parents) { List 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)); } } pageInfo.setRecords(list); return pageInfo; } @Override public List exportList(TaskManagementPageListQuery query) { List list = this.baseMapper.exportList(query); for (TaskManagementPageListVO taskManagementPageListVO : list) { if (org.springframework.util.StringUtils.hasLength(taskManagementPageListVO.getHandleUserId())){ String[] split = taskManagementPageListVO.getHandleUserId().split(","); List 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 xpErrorTypes = errorTypeMapper.selectList(new LambdaQueryWrapper() .in(XpErrorType::getId, Arrays.asList(typeIds)).orderByAsc(XpErrorType::getParentId)); List parents = new ArrayList<>(); for (XpErrorType xpErrorType : xpErrorTypes) { if (xpErrorType.getParentId() == 0) { parents.add(xpErrorType); } } for (XpErrorType parent : parents) { List 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> xpOperationsRoleResult = xpOperationUserClient.getXpOperationsRoleByRoleId(taskRuleRole.getRoleId()); if (CollUtil.isNotEmpty(xpOperationsRoleResult.getData())) { List 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); // 异步发送消息通知 String plateNumber = Objects.nonNull(vehicle) ? vehicle.getPlateNumber() : ""; sendAccidentNotificationAsync(xpTask, plateNumber, taskRule.getProcessingTimeLimit()); } @Override public R assigneeTask(Long id, Long handlerUserId, Long assigneeUserId) { XpTask task = this.getById(id); task.setAssigneeTime(LocalDateTime.now()); task.setHandleUserId(handlerUserId.toString()); task.setVehicleId(null); task.setAssigneeUserId(assigneeUserId); this.updateById(task); return R.ok(); } @Override public void saveTask(SaveErrorTaskDto dto, Long reportUserId) { List saveTask = new ArrayList<>(); for (Long vehicleId : dto.getVehicleIds()) { XpTask task = new XpTask(); BeanUtils.copyProperties(dto, task); task.setReportTime(LocalDateTime.now()); task.setStatus(0); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); String code = sdf.format(new Date()) + UUIDUtil.getNumberRandom(5); task.setTaskCode(code); // 查询规则 XpTaskRule taskRule = xpTaskRuleMapper.selectOne(null); if (taskRule != null) { task.setEndTime(LocalDateTime.now().plusMinutes(taskRule.getProcessingTimeLimit())); } task.setTaskCategory(2); // todo 临时处理 task.setHandleUserId("1"); task.setTaskTypeId(dto.getTaskTypeId()); task.setTaskUrgencyLevel(dto.getTaskUrgencyLevel()); task.setTaskDescription(dto.getTaskDescription()); task.setTaskImage(dto.getTaskImage()); task.setVehicleId(vehicleId); task.setVehicleLocation(dto.getVehicleLocation()); task.setVehicleLon(dto.getVehicleLon()); task.setVehicleLat(dto.getVehicleLat()); task.setReportUserId(reportUserId); task.setReportTime(LocalDateTime.now()); saveTask.add(task); } this.saveBatch(saveTask); } @Override public R taskDetail(Long id) { TaskManagementDetailVO managementDetailVO = new TaskManagementDetailVO(); XpTask task = this.getById(id); if (task == null) { throw new ServiceException( "任务不存在", I18nKeyConstant.TASK_NOT_EXIST ); } XpVehicle vehicle = xpVehicleClient.queryById(task.getVehicleId()).getData(); if (vehicle == null) { throw new ServiceException( "车辆不存在", I18nKeyConstant.VEHICLE_NOT_EXIST ); } if (task.getTaskCategory() == 1) { // 常规任务 switch (task.getTaskTypeId()) { case "1": // 检测 TaskManagementDetectionDetailVO taskManagementDetectionDetailVO = new TaskManagementDetectionDetailVO(); taskManagementDetectionDetailVO.setId(task.getId()); taskManagementDetectionDetailVO.setVehicleId(vehicle.getId()); taskManagementDetectionDetailVO.setTaskUrgencyLevel(task.getTaskUrgencyLevel()); taskManagementDetectionDetailVO.setPlateNumber(vehicle.getPlateNumber()); taskManagementDetectionDetailVO.setVehicleColor(vehicle.getVehicleColor()); taskManagementDetectionDetailVO.setVehicleCode(vehicle.getVehicleCode()); taskManagementDetectionDetailVO.setVehicleVin(vehicle.getVehicleVin()); taskManagementDetectionDetailVO.setVehicleLocation(task.getVehicleLocation()); taskManagementDetectionDetailVO.setVehiclePictures(vehicle.getVehiclePictures()); taskManagementDetectionDetailVO.setTaskCode(task.getTaskCode()); XpVehicleDetection vehicleDetection = vehicleDetectionMapper.selectOne(new LambdaQueryWrapper() .eq(XpVehicleDetection::getTaskId, id).last("limit 1")); if (vehicleDetection != null) { taskManagementDetectionDetailVO.setNetworkDetection(vehicleDetection.getNetworkDetection()); taskManagementDetectionDetailVO.setVersionVerification(vehicleDetection.getVersionVerification()); taskManagementDetectionDetailVO.setCommunicationSelfCheck(vehicleDetection.getCommunicationSelfCheck()); taskManagementDetectionDetailVO.setRemoteSelfCheck(vehicleDetection.getRemoteSelfCheck()); taskManagementDetectionDetailVO.setCollisionPrevention(vehicleDetection.getCollisionPrevention()); taskManagementDetectionDetailVO.setSensorSelfCheck(vehicleDetection.getSensorSelfCheck()); taskManagementDetectionDetailVO.setSensorCleaning(vehicleDetection.getSensorCleaning()); taskManagementDetectionDetailVO.setSensorCleaningPicture(vehicleDetection.getSensorCleaningPicture()); taskManagementDetectionDetailVO.setInteractiveScreen(vehicleDetection.getInteractiveScreen()); taskManagementDetectionDetailVO.setInteractiveScreenPicture(vehicleDetection.getInteractiveScreenPicture()); taskManagementDetectionDetailVO.setHelpButton(vehicleDetection.getHelpButton()); taskManagementDetectionDetailVO.setHelpButtonPicture(vehicleDetection.getHelpButtonPicture()); taskManagementDetectionDetailVO.setPaymentFunction(vehicleDetection.getPaymentFunction()); taskManagementDetectionDetailVO.setPaymentFunctionPicture(vehicleDetection.getPaymentFunctionPicture()); taskManagementDetectionDetailVO.setSystemCheck(vehicleDetection.getSystemCheck()); taskManagementDetectionDetailVO.setSystemCheckPicture(vehicleDetection.getSystemCheckPicture()); taskManagementDetectionDetailVO.setCheckTime(vehicleDetection.getCheckTime()); taskManagementDetectionDetailVO.setOperationsUserId(vehicleDetection.getOperationsUserId()); if (vehicleDetection.getOperationsUserId() != null) { XpOperationsUser operationsUser = xpOperationUserClient.queryById(vehicleDetection.getOperationsUserId()).getData(); if (operationsUser != null) { taskManagementDetectionDetailVO.setOperationsUserName(operationsUser.getNickName()); } } } managementDetailVO.setDetectionDetailVO(taskManagementDetectionDetailVO); break; case "2": // 充电 TaskManagementChargingDetailVO taskManagementChargingDetailVO = new TaskManagementChargingDetailVO(); taskManagementChargingDetailVO.setId(task.getId()); taskManagementChargingDetailVO.setVehicleId(vehicle.getId()); taskManagementChargingDetailVO.setTaskUrgencyLevel(task.getTaskUrgencyLevel()); taskManagementChargingDetailVO.setPlateNumber(vehicle.getPlateNumber()); taskManagementChargingDetailVO.setVehicleColor(vehicle.getVehicleColor()); taskManagementChargingDetailVO.setVehicleCode(vehicle.getVehicleCode()); taskManagementChargingDetailVO.setVehicleVin(vehicle.getVehicleVin()); taskManagementChargingDetailVO.setVehicleLocation(task.getVehicleLocation()); taskManagementChargingDetailVO.setTaskCode(task.getTaskCode()); taskManagementChargingDetailVO.setVehiclePictures(vehicle.getVehiclePictures()); XpChargingRecord chargingRecord = chargingRecordMapper.selectOne(new LambdaQueryWrapper() .eq(XpChargingRecord::getTaskId, id).last("limit 1")); if (chargingRecord != null) { taskManagementChargingDetailVO.setStartRemainingBattery(chargingRecord.getStartRemainingBattery()); taskManagementChargingDetailVO.setStartChargingPicture(chargingRecord.getStartChargingPicture()); taskManagementChargingDetailVO.setStartTime(chargingRecord.getStartTime()); taskManagementChargingDetailVO.setEndRemainingBattery(chargingRecord.getEndRemainingBattery()); taskManagementChargingDetailVO.setEndChargingPicture(chargingRecord.getEndChargingPicture()); taskManagementChargingDetailVO.setEndTime(chargingRecord.getEndTime()); taskManagementChargingDetailVO.setStartOperationsUserId(chargingRecord.getStartOperationsUserId()); taskManagementChargingDetailVO.setEndOperationsUserId(chargingRecord.getEndOperationsUserId()); if (chargingRecord.getStartOperationsUserId() != null) { XpOperationsUser operationsUser = xpOperationUserClient.queryById(chargingRecord.getStartOperationsUserId()).getData(); if (operationsUser != null) { taskManagementChargingDetailVO.setStartOperationsUserName(operationsUser.getNickName()); } } if (chargingRecord.getEndOperationsUserId() != null) { XpOperationsUser operationsUser = xpOperationUserClient.queryById(chargingRecord.getEndOperationsUserId()).getData(); if (operationsUser != null) { taskManagementChargingDetailVO.setEndOperationsUserName(operationsUser.getNickName()); } } } managementDetailVO.setChargingDetailVO(taskManagementChargingDetailVO); break; case "3": // 整备 TaskManagementPreparationDetailVO taskManagementPreparationDetailVO = new TaskManagementPreparationDetailVO(); taskManagementPreparationDetailVO.setId(task.getId()); taskManagementPreparationDetailVO.setVehicleId(vehicle.getId()); taskManagementPreparationDetailVO.setTaskUrgencyLevel(task.getTaskUrgencyLevel()); taskManagementPreparationDetailVO.setPlateNumber(vehicle.getPlateNumber()); taskManagementPreparationDetailVO.setVehicleColor(vehicle.getVehicleColor()); taskManagementPreparationDetailVO.setVehicleCode(vehicle.getVehicleCode()); taskManagementPreparationDetailVO.setVehicleVin(vehicle.getVehicleVin()); taskManagementPreparationDetailVO.setVehicleLocation(task.getVehicleLocation()); taskManagementPreparationDetailVO.setTaskCode(task.getTaskCode()); taskManagementPreparationDetailVO.setVehiclePictures(vehicle.getVehiclePictures()); XpVehiclePreparation vehiclePreparation = vehiclePreparationMapper.selectOne(new LambdaQueryWrapper() .eq(XpVehiclePreparation::getTaskId, id).last("limit 1")); if (vehiclePreparation != null) { taskManagementPreparationDetailVO.setLeftFrontWheel(vehiclePreparation.getLeftFrontWheel()); taskManagementPreparationDetailVO.setRightFrontWheel(vehiclePreparation.getRightFrontWheel()); taskManagementPreparationDetailVO.setLeftRearWheel(vehiclePreparation.getLeftRearWheel()); taskManagementPreparationDetailVO.setRightRearWheel(vehiclePreparation.getRightRearWheel()); taskManagementPreparationDetailVO.setHeadLight(vehiclePreparation.getHeadLight()); taskManagementPreparationDetailVO.setTurnSignal(vehiclePreparation.getTurnSignal()); taskManagementPreparationDetailVO.setBrakeLight(vehiclePreparation.getBrakeLight()); taskManagementPreparationDetailVO.setFogLight(vehiclePreparation.getFogLight()); taskManagementPreparationDetailVO.setBodyEmblem(vehiclePreparation.getBodyEmblem()); taskManagementPreparationDetailVO.setCabinCleaning(vehiclePreparation.getCabinCleaning()); taskManagementPreparationDetailVO.setLostItems(vehiclePreparation.getLostItems()); taskManagementPreparationDetailVO.setRemarks(vehiclePreparation.getRemarks()); taskManagementPreparationDetailVO.setOperationsUserId(vehiclePreparation.getOperationsUserId()); taskManagementPreparationDetailVO.setOperationsTime(vehiclePreparation.getCreateTime()); if (vehiclePreparation.getOperationsUserId() != null) { XpOperationsUser operationsUser = xpOperationUserClient.queryById(vehiclePreparation.getOperationsUserId()).getData(); if (operationsUser != null) { taskManagementPreparationDetailVO.setOperationsUserName(operationsUser.getNickName()); } } } managementDetailVO.setPreparationDetailVO(taskManagementPreparationDetailVO); break; case "4": // 洗车 TaskManagementCleanDetailVO taskManagementCleanDetailVO = new TaskManagementCleanDetailVO(); taskManagementCleanDetailVO.setId(task.getId()); taskManagementCleanDetailVO.setVehicleId(vehicle.getId()); taskManagementCleanDetailVO.setTaskUrgencyLevel(task.getTaskUrgencyLevel()); taskManagementCleanDetailVO.setPlateNumber(vehicle.getPlateNumber()); taskManagementCleanDetailVO.setVehicleColor(vehicle.getVehicleColor()); taskManagementCleanDetailVO.setVehicleCode(vehicle.getVehicleCode()); taskManagementCleanDetailVO.setVehicleVin(vehicle.getVehicleVin()); taskManagementCleanDetailVO.setVehicleLocation(task.getVehicleLocation()); taskManagementCleanDetailVO.setTaskCode(task.getTaskCode()); taskManagementCleanDetailVO.setVehiclePictures(vehicle.getVehiclePictures()); XpVehicleClean vehicleClean = vehicleCleanMapper.selectOne(new LambdaQueryWrapper() .eq(XpVehicleClean::getTaskId, id).last("limit 1")); if (vehicleClean != null) { taskManagementCleanDetailVO.setTaskImage(vehicleClean.getTaskImage()); taskManagementCleanDetailVO.setOperationUserId(vehicleClean.getOperationsUserId()); if (vehicleClean.getOperationsUserId() != null) { XpOperationsUser operationsUser = xpOperationUserClient.queryById(vehicleClean.getOperationsUserId()).getData(); if (operationsUser != null) { taskManagementCleanDetailVO.setOperationsUserName(operationsUser.getNickName()); } } } managementDetailVO.setCleanDetailVO(taskManagementCleanDetailVO); break; case "5": // 维修 TaskManagementRepairDetailVO taskManagementRepairDetailVO = new TaskManagementRepairDetailVO(); taskManagementRepairDetailVO.setId(task.getId()); taskManagementRepairDetailVO.setVehicleId(vehicle.getId()); taskManagementRepairDetailVO.setTaskUrgencyLevel(task.getTaskUrgencyLevel()); taskManagementRepairDetailVO.setPlateNumber(vehicle.getPlateNumber()); taskManagementRepairDetailVO.setVehicleColor(vehicle.getVehicleColor()); taskManagementRepairDetailVO.setVehicleCode(vehicle.getVehicleCode()); taskManagementRepairDetailVO.setVehicleVin(vehicle.getVehicleVin()); taskManagementRepairDetailVO.setVehicleLocation(task.getVehicleLocation()); taskManagementRepairDetailVO.setTaskCode(task.getTaskCode()); taskManagementRepairDetailVO.setVehiclePictures(vehicle.getVehiclePictures()); XpVehicleRepair vehicleRepair = vehicleRepairMapper.selectOne(new LambdaQueryWrapper() .eq(XpVehicleRepair::getTaskId, id).last("limit 1")); if (vehicleRepair != null) { taskManagementRepairDetailVO.setStartTime(vehicleRepair.getStartTime()); taskManagementRepairDetailVO.setEndTime(vehicleRepair.getEndTime()); taskManagementRepairDetailVO.setRepairReason(vehicleRepair.getRepairReason()); taskManagementRepairDetailVO.setStartRepairPicture(vehicleRepair.getStartRepairPicture()); taskManagementRepairDetailVO.setRepairMoney(vehicleRepair.getRepairMoney()); taskManagementRepairDetailVO.setRepairMoneyDetail(vehicleRepair.getRepairMoneyDetail()); taskManagementRepairDetailVO.setSendUserId(vehicleRepair.getSendUserId()); taskManagementRepairDetailVO.setSendTime(vehicleRepair.getSendTime()); taskManagementRepairDetailVO.setReturnUserId(vehicleRepair.getReturnUserId()); taskManagementRepairDetailVO.setReturnTime(vehicleRepair.getReturnTime()); if (vehicleRepair.getReturnUserId() != null) { XpOperationsUser operationsUser = xpOperationUserClient.queryById(vehicleRepair.getReturnUserId()).getData(); if (operationsUser != null) { taskManagementRepairDetailVO.setReturnUserName(operationsUser.getNickName()); } } if (vehicleRepair.getSendUserId() != null) { XpOperationsUser operationsUser = xpOperationUserClient.queryById(vehicleRepair.getSendUserId()).getData(); if (operationsUser != null) { taskManagementRepairDetailVO.setSendUserName(operationsUser.getNickName()); } } } managementDetailVO.setRepairDetailVO(taskManagementRepairDetailVO); break; default: // 保养、年检、保险、营运资质 TaskManagementRoutineDetailVO res = new TaskManagementRoutineDetailVO(); res.setId(task.getId()); res.setTaskUrgencyLevel(task.getTaskUrgencyLevel()); res.setPlateNumber(vehicle.getPlateNumber()); res.setVehicleColor(vehicle.getVehicleColor()); res.setVehicleCode(vehicle.getVehicleCode()); res.setVehicleLocation(task.getVehicleLocation()); res.setVehicleVin(vehicle.getVehicleVin()); res.setTaskCode(task.getTaskCode()); res.setVehiclePictures(vehicle.getVehiclePictures()); XpTaskHandleDetailRoutine xpTaskHandleDetailRoutine = xpTaskHandleDetailRoutineMapper.selectOne(new LambdaQueryWrapper() .eq(XpTaskHandleDetailRoutine::getTaskId, id)); if (xpTaskHandleDetailRoutine != null) { res.setTaskDescription(xpTaskHandleDetailRoutine.getTaskDescription()); res.setTaskImage(xpTaskHandleDetailRoutine.getTaskImage()); res.setHandleUserId(task.getHandleUserId()); XpOperationsUser operationsUser = xpOperationUserClient.queryById(xpTaskHandleDetailRoutine.getOperationsUserId()).getData(); if (operationsUser != null) { res.setHandleUserId(operationsUser.getId().toString()); res.setHandleUserName(operationsUser.getNickName()); } } res.setHandleTime(task.getHandleTime()); res.setId(id); res.setTaskUrgencyLevel(task.getTaskUrgencyLevel()); res.setPlateNumber(vehicle.getPlateNumber()); res.setVehicleColor(vehicle.getVehicleColor()); res.setVehicleCode(vehicle.getVehicleCode()); res.setVehicleLocation(task.getVehicleLocation()); res.setVehicleVin(vehicle.getVehicleVin()); managementDetailVO.setRoutineDetailVO(res); break; } } else { // 事故任务 TaskManagementAccidentDetailVO res = new TaskManagementAccidentDetailVO(); Map> errorType = errorTypeMapper.selectList(new LambdaQueryWrapper() .in(XpErrorType::getId, Arrays.asList(task.getTaskTypeId().split(",")))) .stream().collect(Collectors.groupingBy(XpErrorType::getParentId)); List xpErrorTypes = errorType.get(0L); for (XpErrorType xpErrorType : xpErrorTypes) { xpErrorType.setChild(errorType.get(xpErrorType.getId())); } res.setCreateTime(task.getCreateTime()); res.setHandleTime(task.getHandleTime()); res.setErrorTypeList(xpErrorTypes); res.setStatus(task.getStatus()); res.setTaskDescription(task.getTaskDescription()); res.setTaskImage(task.getTaskImage()); res.setId(id); res.setVehicleId(vehicle.getId()); res.setTaskUrgencyLevel(task.getTaskUrgencyLevel()); res.setPlateNumber(vehicle.getPlateNumber()); res.setVehicleColor(vehicle.getVehicleColor()); res.setVehicleCode(vehicle.getVehicleCode()); res.setVehicleLocation(task.getVehicleLocation()); res.setVehicleVin(vehicle.getVehicleVin()); if (task.getReportUserId().equals(0L)){ // 系统补偿上传车辆异常任务 为系统创建 res.setReportUserId(0L); res.setReportUserName("系统"); // todo 临时设置 待客户确认默认头像和电话号码 res.setReportUserPhone("111111"); res.setReportUserAvatar("[]"); }else{ List reportUserIds = new ArrayList<>(); reportUserIds.add(task.getReportUserId()); List sysUsers = sysUserClient.listByIds(reportUserIds).getData(); if (sysUsers != null && !sysUsers.isEmpty()) { SysUser sysUser = sysUsers.get(0); res.setReportUserId(sysUser.getId()); res.setReportUserName(sysUser.getNickName()); res.setReportUserPhone(sysUser.getPhoneNumber()); res.setReportUserAvatar(sysUser.getAvatar()); } } if (task.getHandleUserId().split(",").length == 1) { XpOperationsUser operationsUser = xpOperationUserClient.queryById(Long.valueOf(task.getHandleUserId())).getData(); if (operationsUser != null) { res.setHandleUserId(operationsUser.getId()); res.setHandleUserName(operationsUser.getNickName()); res.setHandleUserPhone(operationsUser.getPhoneNumber()); res.setHandleUserAvatar(operationsUser.getAvatar()); } } XpTaskHandleDetail xpTaskHandleDetail = xpTaskHandleDetailMapper.selectOne(new LambdaQueryWrapper() .eq(XpTaskHandleDetail::getTaskId, id)); if (xpTaskHandleDetail != null) { res.setDeathCount(xpTaskHandleDetail.getDeathCount()); res.setSevereCount(xpTaskHandleDetail.getSevereCount()); res.setMinorCount(xpTaskHandleDetail.getMinorCount()); res.setResponsibilityJudgment(xpTaskHandleDetail.getResponsibilityJudgment()); res.setResponsibleDescription(xpTaskHandleDetail.getResponsibleDescription()); res.setResponsibleImage(xpTaskHandleDetail.getResponsibleImage()); res.setDisposalDescription(xpTaskHandleDetail.getDisposalDescription()); res.setDisposalImage(xpTaskHandleDetail.getDisposalImage()); res.setSituationDescription(xpTaskHandleDetail.getSituationDescription()); res.setSituationImage(xpTaskHandleDetail.getSituationImage()); } managementDetailVO.setAccidentDetailVO(res); } return R.ok(managementDetailVO); } }