| | |
| | | package com.xiaopeng.maintenance.service.impl; |
| | | |
| | | 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.feignClient.account.XpOperationUserClient; |
| | | import com.xiaopeng.api.feignClient.vehicleConvoy.XpVehicleClient; |
| | |
| | | import com.xiaopeng.api.model.maintenance.*; |
| | | import com.xiaopeng.api.model.vehicleConvoy.XpVehicle; |
| | | import com.xiaopeng.common.core.domain.R; |
| | | import com.xiaopeng.common.core.enums.TaskTypeEnum; |
| | | 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.model.query.XpTaskRecordPageQuery; |
| | | import com.xiaopeng.maintenance.model.vo.*; |
| | | import com.xiaopeng.maintenance.service.XpTaskService; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.time.LocalTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Service |
| | | public class XpTaskServiceImpl extends ServiceImpl<XpTaskMapper, XpTask> implements XpTaskService { |
| | | |
| | | /** |
| | | * 常规任务类型映射 |
| | | */ |
| | | private static final Map<String, String> TASK_TYPE_MAP = new java.util.HashMap<>(); |
| | | static { |
| | | TASK_TYPE_MAP.put("1", "车辆检查"); |
| | | TASK_TYPE_MAP.put("2", "车辆充电"); |
| | | TASK_TYPE_MAP.put("3", "车辆整备"); |
| | | TASK_TYPE_MAP.put("4", "整备洗车"); |
| | | TASK_TYPE_MAP.put("5", "车辆维修"); |
| | | TASK_TYPE_MAP.put("6", "车辆保养"); |
| | | TASK_TYPE_MAP.put("7", "车辆保险到期"); |
| | | TASK_TYPE_MAP.put("8", "车辆年检到期"); |
| | | TASK_TYPE_MAP.put("9", "车辆运营资质到期"); |
| | | } |
| | | |
| | | @Autowired |
| | | private XpTaskHandleDetailMapper xpTaskHandleDetailMapper; |
| | |
| | | |
| | | @Override |
| | | public PageInfo<XpTaskRecordVO> queryTaskByVehicleId(XpTaskRecordPageQuery query) { |
| | | return null; |
| | | // 1. 构建查询条件 |
| | | LambdaQueryWrapper<XpTask> wrapper = new LambdaQueryWrapper<>(); |
| | | wrapper.eq(XpTask::getVehicleId, query.getVehicleId()); |
| | | |
| | | if (query.getTaskCategory() != null) { |
| | | wrapper.eq(XpTask::getTaskCategory, query.getTaskCategory()); |
| | | } |
| | | |
| | | if (StringUtils.isNotBlank(query.getTaskTypeId())) { |
| | | wrapper.eq(XpTask::getTaskTypeId, query.getTaskTypeId()); |
| | | } |
| | | |
| | | 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<XpTask> page = new Page<>(query.getPageNum(), query.getPageSize()); |
| | | Page<XpTask> resultPage = this.page(page, wrapper); |
| | | |
| | | // 3. 转换为 VO 并填充 typeName |
| | | List<XpTaskRecordVO> records = new ArrayList<>(); |
| | | |
| | | if (!CollectionUtils.isEmpty(resultPage.getRecords())) { |
| | | // 3.1 收集所有事故任务的 errorType ID |
| | | Set<Long> 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<Long, String> errorTypeMap = new HashMap<>(); |
| | | if (!errorTypeIds.isEmpty()) { |
| | | List<XpErrorType> 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<XpTaskRecordVO> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize()); |
| | | pageInfo.setRecords(records); |
| | | pageInfo.setTotal(resultPage.getTotal()); |
| | | return pageInfo; |
| | | } |
| | | |
| | | @Override |
| | | public void deleteTaskById(Long id) { |
| | | removeById(id); |
| | | } |
| | | } |