Commit 4e430c70 by 章家宝

feat:检测报告代码提交

1 parent d522c4e1
...@@ -25,22 +25,6 @@ import org.summerframework.orm.paging.Pagination; ...@@ -25,22 +25,6 @@ import org.summerframework.orm.paging.Pagination;
public class InspectionReportController { public class InspectionReportController {
private final InspectionReportService inspectionReportService; private final InspectionReportService inspectionReportService;
@Operation(summary = "新增检测报告", description = "添加新的检测报告")
@PostMapping("/add")
public BaseResp<Void> add(@Valid @RequestBody InspectionReportAddVO addVO) {
log.info("新增检测报告请求: {}", JSON.toJSONString(addVO));
try {
inspectionReportService.addInspectionReport(addVO);
} catch (BusinessCodeException be) {
log.error("新增检测报告失败!业务异常!", be);
return BaseResp.fail(StrUtil.toString(be.getCode()), StrUtil.toString(be.getMessage()));
} catch (Exception e) {
log.error("新增检测报告失败!系统异常!", e);
return BaseResp.fail("系统异常: " + e.getMessage());
}
return BaseResp.success();
}
@Operation(summary = "编辑检测报告", description = "编辑检测报告信息") @Operation(summary = "编辑检测报告", description = "编辑检测报告信息")
@PostMapping("/update") @PostMapping("/update")
public BaseResp<Void> update(@Valid @RequestBody InspectionReportUpdateVO vo) { public BaseResp<Void> update(@Valid @RequestBody InspectionReportUpdateVO vo) {
......
package com.glsx.usedcar.converts;
import com.glsx.usedcar.module.inspect.entity.InspectionReport;
import com.glsx.usedcar.module.inspect.vo.InspectionReportRespVO;
import org.mapstruct.Mapper;
import java.util.List;
/**
* 检测报告实体转换器
* @author yangwei
* @version 1.0
* @since 2026/03/17 15:00
*/
@Mapper(componentModel = "spring")
public interface InspectionReportConverter {
/**
* 单个实体转换为VO
*
* @param inspectionReport 检测报告实体
* @return 检测报告响应VO
*/
InspectionReportRespVO inspectionReportMapRespVO(InspectionReport inspectionReport);
/**
* 多个实体转换为VO
*
* @param inspectionReports 检测报告实体列表
* @return 检测报告响应VO列表
*/
List<InspectionReportRespVO> inspectionReportsMapRespVO(List<InspectionReport> inspectionReports);
}
\ No newline at end of file \ No newline at end of file
package com.glsx.usedcar.module.inspect.dao; package com.glsx.usedcar.module.inspect.dao;
import com.glsx.usedcar.module.inspect.entity.InspectionReport; import com.glsx.usedcar.module.inspect.entity.InspectionReport;
import com.glsx.usedcar.module.vehicle.entity.Vehicle;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import org.summerframework.orm.BaseRepository; import org.summerframework.orm.BaseRepository;
...@@ -33,20 +38,12 @@ public interface InspectionReportRepository extends BaseRepository<InspectionRep ...@@ -33,20 +38,12 @@ public interface InspectionReportRepository extends BaseRepository<InspectionRep
/** /**
* 根据车辆ID查询未删除的检测报告 * 根据车辆ID查询未删除的检测报告
* *
* @param vehicleId 车辆ID * @param vehicle 车辆
* @param deleteFlag 删除标识(N:未删除 D:已删除) * @param deleteFlag 删除标识(N:未删除 D:已删除)
* @return 检测报告列表 * @return 检测报告列表
*/ */
List<InspectionReport> findByVehicleIdAndDeleteFlag(Integer vehicleId, String deleteFlag); List<InspectionReport> findByVehicleAndDeleteFlag(Vehicle vehicle, String deleteFlag);
/**
* 根据VIN码查询未删除的检测报告
*
* @param vin VIN码
* @param deleteFlag 删除标识
* @return 检测报告列表
*/
List<InspectionReport> findByVinAndDeleteFlag(String vin, String deleteFlag);
/** /**
* 根据绑定状态查询未删除的检测报告 * 根据绑定状态查询未删除的检测报告
...@@ -66,4 +63,15 @@ public interface InspectionReportRepository extends BaseRepository<InspectionRep ...@@ -66,4 +63,15 @@ public interface InspectionReportRepository extends BaseRepository<InspectionRep
*/ */
List<InspectionReport> findByScoreLevelAndDeleteFlag(String scoreLevel, String deleteFlag); List<InspectionReport> findByScoreLevelAndDeleteFlag(String scoreLevel, String deleteFlag);
/**
* 分页查询检测报告(关联查询车辆、工单信息,避免N+1查询)
* 参考 InspectionWorkOrderRepository 的 EntityGraph 写法
*
* @param spec 查询条件
* @param pageable 分页参数
* @return 检测报告分页结果
*/
@Override
@EntityGraph(attributePaths = {"vehicle", "workOrder"})
Page<InspectionReport> findAll(Specification<InspectionReport> spec, Pageable pageable);
} }
\ No newline at end of file \ No newline at end of file
package com.glsx.usedcar.module.inspect.entity; package com.glsx.usedcar.module.inspect.entity;
import com.fasterxml.jackson.annotation.JsonView; import com.fasterxml.jackson.annotation.JsonView;
import com.glsx.usedcar.module.vehicle.entity.Vehicle;
import jakarta.persistence.*; import jakarta.persistence.*;
import jakarta.validation.constraints.*; import jakarta.validation.constraints.*;
import lombok.*; import lombok.*;
...@@ -19,6 +20,7 @@ import static jakarta.persistence.GenerationType.IDENTITY; ...@@ -19,6 +20,7 @@ import static jakarta.persistence.GenerationType.IDENTITY;
/** /**
* 检测报告(InspectionReport)实体类 * 检测报告(InspectionReport)实体类
* 严格对齐数据库表 inspection_report 结构
*/ */
@Entity @Entity
@Getter @Getter
...@@ -28,7 +30,17 @@ import static jakarta.persistence.GenerationType.IDENTITY; ...@@ -28,7 +30,17 @@ import static jakarta.persistence.GenerationType.IDENTITY;
@DynamicUpdate @DynamicUpdate
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@Table(name = "inspection_report") // 对应检测报告表名 @Table(
name = "inspection_report",
indexes = {
// 对齐数据库索引配置
@Index(name = "uk_report_no", columnList = "report_no", unique = true),
@Index(name = "idx_wo_id_del", columnList = "wo_id, delete_flag"),
@Index(name = "idx_work_order_inner_id_del", columnList = "work_order_inner_id, delete_flag"),
@Index(name = "idx_vehicle_id_del", columnList = "vehicle_id, delete_flag"),
@Index(name = "idx_score_level_bind_status_del", columnList = "score_level, bind_status, delete_flag")
}
)
@EntityListeners(AuditingEntityListener.class) @EntityListeners(AuditingEntityListener.class)
public class InspectionReport extends AuditingEntity implements Serializable { public class InspectionReport extends AuditingEntity implements Serializable {
...@@ -56,7 +68,7 @@ public class InspectionReport extends AuditingEntity implements Serializable { ...@@ -56,7 +68,7 @@ public class InspectionReport extends AuditingEntity implements Serializable {
@JsonView(value = Summary.class) @JsonView(value = Summary.class)
@NotBlank(groups = {CreateValidGroup.class, UpdateValidGroup.class}) @NotBlank(groups = {CreateValidGroup.class, UpdateValidGroup.class})
@Size(max = 50, groups = {CreateValidGroup.class, UpdateValidGroup.class}) @Size(max = 50, groups = {CreateValidGroup.class, UpdateValidGroup.class})
@Column(name = "report_no", nullable = false, length = 50, unique = true) @Column(name = "report_no", nullable = false, length = 50)
private String reportNo; private String reportNo;
/** /**
...@@ -69,83 +81,55 @@ public class InspectionReport extends AuditingEntity implements Serializable { ...@@ -69,83 +81,55 @@ public class InspectionReport extends AuditingEntity implements Serializable {
private String woId; private String woId;
/** /**
* 车辆ID(对应inspection_work_order.vehicle_id) * 关联检测工单主键ID(对应inspection_work_order.id)
*/ * 关联InspectionWorkOrder实体(懒加载,非级联)
@JsonView(value = Summary.class)
@NotNull(groups = {CreateValidGroup.class, UpdateValidGroup.class})
@Column(name = "vehicle_id", nullable = false)
private Integer vehicleId;
/**
* 车型名称(如:2023款 宝马3系 325Li M运动套装)
*/
@JsonView(value = Summary.class)
@NotBlank(groups = {CreateValidGroup.class, UpdateValidGroup.class})
@Size(max = 128, groups = {CreateValidGroup.class, UpdateValidGroup.class})
@Column(name = "car_type_name", nullable = false, length = 128)
private String carTypeName;
/**
* 车源号(车源唯一标识)
*/ */
@JsonView(value = Summary.class) @JsonView(value = Summary.class)
@NotBlank(groups = {CreateValidGroup.class, UpdateValidGroup.class}) @ManyToOne(cascade = {}, fetch = FetchType.LAZY)
@Size(max = 64, groups = {CreateValidGroup.class, UpdateValidGroup.class}) @JoinColumn(
@Column(name = "car_source_no", nullable = false, length = 64) name = "work_order_inner_id",
private String carSourceNo; referencedColumnName = "id",
nullable = false
/** )
* 车辆识别码(VIN码,固定17位) private InspectionWorkOrder workOrder;
*/
@JsonView(value = Summary.class)
@NotBlank(groups = {CreateValidGroup.class, UpdateValidGroup.class})
@Size(max = 17, groups = {CreateValidGroup.class, UpdateValidGroup.class})
@Column(name = "vin", nullable = false, length = 17)
private String vin;
/** /**
* 车牌号(如:京A12345,未上牌则为空) * 车辆ID(关联Vehicle实体)
*/ */
@JsonView(value = Summary.class) @JsonView(value = Summary.class)
@Size(max = 20, groups = {CreateValidGroup.class, UpdateValidGroup.class}) @ManyToOne(cascade = {}, fetch = FetchType.LAZY)
@Column(name = "plate_no", nullable = true, length = 20) @JoinColumn(
private String plateNo; name = "vehicle_id",
referencedColumnName = "vehicleId",
/** nullable = false
* 车辆状态 )
* 枚举值:INVENTORY(待入库)、VENUE(场地待维护)、TO_BE_PRICED(待定价)、PRICED(待关联拍场)、 private Vehicle vehicle;
* PENDING_AUCTION(待上拍)、WAIT_AUCTION(待拍卖)、PREVIEW(预展中)、AUCTIONING(拍卖中)、
* CONTRACT_UNSIGNED(待签署合同)、UNPAID(待付车款)、WAIT_PICKUP(待提车)、TRANSFERRING(待过户)、
* COMPLETED(已完成)、CANCELED(已取消)
*/
@JsonView(value = Summary.class)
@NotBlank(groups = {CreateValidGroup.class, UpdateValidGroup.class})
@Size(max = 64, groups = {CreateValidGroup.class, UpdateValidGroup.class})
@Column(name = "vehicle_status", nullable = false, length = 64)
private String vehicleStatus;
/** /**
* 评分(保留1位小数,与工单评分一致) * 评分(保留1位小数,与工单评分一致)
* 对齐数据库 decimal(4,1)
*/ */
@JsonView(value = Summary.class) @JsonView(value = Summary.class)
@Column(name = "score", nullable = true, precision = 2, scale = 1) @Column(name = "score", nullable = true, precision = 4, scale = 1)
private BigDecimal score; private BigDecimal score;
/** /**
* 评分级别(ABCDEF) * 评分级别(ABCDEF)
* 对齐数据库 char(1)
*/ */
@JsonView(value = Summary.class) @JsonView(value = Summary.class)
@NotBlank(groups = {CreateValidGroup.class, UpdateValidGroup.class}) @NotBlank(groups = {CreateValidGroup.class, UpdateValidGroup.class})
@Size(max = 1, groups = {CreateValidGroup.class, UpdateValidGroup.class}) @Size(max = 1, groups = {CreateValidGroup.class, UpdateValidGroup.class})
@Column(name = "score_level", nullable = false, length = 1) @Column(name = "score_level", nullable = false, columnDefinition = "char(1)")
private String scoreLevel; private String scoreLevel;
/** /**
* 绑定状态(1:已绑定;2:未绑定) * 绑定状态(1:已绑定;2:未绑定)
* 对齐数据库 tinyint(2)
*/ */
@JsonView(value = Summary.class) @JsonView(value = Summary.class)
@NotNull(groups = {CreateValidGroup.class, UpdateValidGroup.class}) @NotNull(groups = {CreateValidGroup.class, UpdateValidGroup.class})
@Column(name = "bind_status", nullable = false) @Column(name = "bind_status", nullable = false, columnDefinition = "tinyint(2)")
private Integer bindStatus; private Integer bindStatus;
/** /**
...@@ -158,9 +142,10 @@ public class InspectionReport extends AuditingEntity implements Serializable { ...@@ -158,9 +142,10 @@ public class InspectionReport extends AuditingEntity implements Serializable {
/** /**
* 删除标识 N:未删除 D:已删除 * 删除标识 N:未删除 D:已删除
* 对齐数据库 char(1) DEFAULT 'N'
*/ */
@Builder.Default @Builder.Default
@Column(name = "deleted_flag", nullable = false, length = 1) @Column(name = "delete_flag", nullable = false, length = 1, columnDefinition = "char(1) DEFAULT 'N'")
private String deleteFlag = "N"; private String deleteFlag = "N";
} }
\ No newline at end of file \ No newline at end of file
...@@ -136,7 +136,7 @@ public class InspectionReportOpLog extends AuditingEntity implements Serializabl ...@@ -136,7 +136,7 @@ public class InspectionReportOpLog extends AuditingEntity implements Serializabl
* 删除标识 N:未删除 D:已删除 * 删除标识 N:未删除 D:已删除
*/ */
@Builder.Default @Builder.Default
@Column(name = "deleted_flag", nullable = false, length = 1) @Column(name = "delete_flag", nullable = false, length = 1)
private String deleteFlag = "N"; private String deleteFlag = "N";
} }
\ No newline at end of file \ No newline at end of file
package com.glsx.usedcar.module.inspect.service; package com.glsx.usedcar.module.inspect.service;
import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.glsx.usedcar.consts.common.SymbolConsts;
import com.glsx.usedcar.consts.inspect.JpaQueryConstants;
import com.glsx.usedcar.converts.InspectionReportConverter;
import com.glsx.usedcar.enums.common.DeleteFlag; import com.glsx.usedcar.enums.common.DeleteFlag;
import com.glsx.usedcar.enums.inspect.InspectionReportOperationTypeEnum; import com.glsx.usedcar.enums.inspect.InspectionReportOperationTypeEnum;
import com.glsx.usedcar.module.inspect.dao.InspectionReportOpLogRepository; import com.glsx.usedcar.module.inspect.dao.InspectionReportOpLogRepository;
import com.glsx.usedcar.module.inspect.dao.InspectionReportRepository; import com.glsx.usedcar.module.inspect.dao.InspectionReportRepository;
import com.glsx.usedcar.module.inspect.entity.InspectionReport; import com.glsx.usedcar.module.inspect.entity.*;
import com.glsx.usedcar.module.inspect.entity.InspectionReportOpLog;
import com.glsx.usedcar.module.inspect.vo.*; import com.glsx.usedcar.module.inspect.vo.*;
import jakarta.validation.Valid; import com.glsx.usedcar.module.vehicle.dao.VehicleDao;
import com.glsx.usedcar.module.vehicle.entity.*;
import com.glsx.usedcar.util.RedisCacheUtil;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -21,8 +26,12 @@ import org.summerframework.core.enums.ErrorCodeEnum; ...@@ -21,8 +26,12 @@ import org.summerframework.core.enums.ErrorCodeEnum;
import org.summerframework.core.exception.BusinessCodeException; import org.summerframework.core.exception.BusinessCodeException;
import org.summerframework.orm.paging.Pagination; import org.summerframework.orm.paging.Pagination;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit;
/** /**
* 检测报告服务(含操作日志保存) * 检测报告服务(含操作日志保存)
...@@ -35,6 +44,9 @@ public class InspectionReportService { ...@@ -35,6 +44,9 @@ public class InspectionReportService {
private final InspectionReportRepository inspectionReportRepository; private final InspectionReportRepository inspectionReportRepository;
private final InspectionReportOpLogRepository inspectionReportOpLogRepository; private final InspectionReportOpLogRepository inspectionReportOpLogRepository;
private final ObjectMapper objectMapper = new ObjectMapper(); private final ObjectMapper objectMapper = new ObjectMapper();
private final RedisCacheUtil redisCacheUtil;
private final InspectionReportConverter inspectionReportConverter;
private final VehicleDao vehicleDao;
/** /**
* 获取当前操作人ID(示例:需替换为项目真实的用户上下文,如UserContext.getUserId()) * 获取当前操作人ID(示例:需替换为项目真实的用户上下文,如UserContext.getUserId())
...@@ -59,14 +71,14 @@ public class InspectionReportService { ...@@ -59,14 +71,14 @@ public class InspectionReportService {
InspectionReportOpLog opLog = InspectionReportOpLog.builder() InspectionReportOpLog opLog = InspectionReportOpLog.builder()
.reportInnerId(report.getId()) .reportInnerId(report.getId())
.reportNo(report.getReportNo()) .reportNo(report.getReportNo())
.operatorId(getCurrentOperatorId()) // 当前操作人ID .operatorId(getCurrentOperatorId())
.operatorName(getCurrentOperatorName()) // 当前操作人姓名 .operatorName(getCurrentOperatorName())
.operationType(operationType) // 操作类型编码 .operationType(operationType)
.originalData(originalData) // 变更前数据(JSON) .originalData(originalData)
.targetData(targetData) // 变更后数据(JSON) .targetData(targetData)
.operationContent(operationContent) // 操作描述 .operationContent(operationContent)
.operationTime(LocalDateTime.now()) // 操作时间 .operationTime(LocalDateTime.now())
.deleteFlag(DeleteFlag.NOT_DELETED.getCode()) // 未删除 .deleteFlag(DeleteFlag.NOT_DELETED.getCode())
.build(); .build();
inspectionReportOpLogRepository.save(opLog); inspectionReportOpLogRepository.save(opLog);
log.info("检测报告操作日志保存成功: 报告编号={}, 操作类型={}", report.getReportNo(), operationType); log.info("检测报告操作日志保存成功: 报告编号={}, 操作类型={}", report.getReportNo(), operationType);
...@@ -76,31 +88,20 @@ public class InspectionReportService { ...@@ -76,31 +88,20 @@ public class InspectionReportService {
} }
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void addInspectionReport(InspectionReportAddVO addVO) { public void addInspectionReport(InspectionWorkOrder wo, Vehicle vehicle) {
// 1. 校验报告编号唯一性 String reportNo = genReportNo();
Optional<InspectionReport> existReport = inspectionReportRepository.findByReportNo(addVO.getReportNo());
if (existReport.isPresent()) {
throw new BusinessCodeException(ErrorCodeEnum.DATA_ALREADY_EXISTS, "报告编号已存在:" + addVO.getReportNo());
}
// 2. 构建并保存报告
InspectionReport report = InspectionReport.builder() InspectionReport report = InspectionReport.builder()
.reportNo(addVO.getReportNo()) .reportNo(reportNo)
.woId(addVO.getWoId()) .woId(wo.getWoId())
.vehicleId(addVO.getVehicleId()) .vehicle(vehicle)
.carTypeName(addVO.getCarTypeName()) .workOrder(wo)
.carSourceNo(addVO.getCarSourceNo()) .score(BigDecimal.ZERO)
.vin(addVO.getVin()) .scoreLevel(" ")
.plateNo(addVO.getPlateNo()) .bindStatus(2)
.vehicleStatus(addVO.getVehicleStatus()) .h5Url(" ")
.score(addVO.getScore())
.scoreLevel(addVO.getScoreLevel())
.bindStatus(addVO.getBindStatus())
.h5Url(addVO.getH5Url())
.deleteFlag(DeleteFlag.NOT_DELETED.getCode()) .deleteFlag(DeleteFlag.NOT_DELETED.getCode())
.build(); .build();
inspectionReportRepository.save(report); inspectionReportRepository.save(report);
// 3. 保存新增日志(originalData为空,targetData为新增的报告数据) // 3. 保存新增日志(originalData为空,targetData为新增的报告数据)
String targetData = ""; String targetData = "";
try { try {
...@@ -114,6 +115,33 @@ public class InspectionReportService { ...@@ -114,6 +115,33 @@ public class InspectionReportService {
log.info("检测报告新增成功: ID={}, 报告编号={}, 关联工单号={}", report.getId(), report.getReportNo(), report.getWoId()); log.info("检测报告新增成功: ID={}, 报告编号={}, 关联工单号={}", report.getId(), report.getReportNo(), report.getWoId());
} }
private String genReportNo() {
try {
// 1. 按天生成Redis Key(yyyyMMdd),2天过期(合理过期,避免堆积)
String dateStr = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
String redisKey = "inspection:report:seq:" + dateStr;
// 2. Redis原子自增(不存在则初始化为1,设置2天过期)
Long seqNum;
if (redisCacheUtil.existsKey(redisKey)) {
seqNum = redisCacheUtil.increment(redisKey);
} else {
redisCacheUtil.setCacheWithExpire(redisKey, 1L, 2, TimeUnit.DAYS);
seqNum = 1L;
}
// 3. 4位流水号上限校验
if (seqNum > 9999) {
throw new RuntimeException("当日工单单号流水号已达上限(9999),请次日再试");
}
// 4. 按要求拼接单号:BG + 日期 + 4位流水号
return String.format("BG%s%s", dateStr, String.format("%04d", seqNum));
} catch (Exception e) {
log.error("生成工单单号失败", e);
throw new RuntimeException("生成工单单号失败", e);
}
}
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void updateInspectionReport(InspectionReportUpdateVO updateVO) { public void updateInspectionReport(InspectionReportUpdateVO updateVO) {
Long id = updateVO.getId(); Long id = updateVO.getId();
...@@ -142,11 +170,6 @@ public class InspectionReportService { ...@@ -142,11 +170,6 @@ public class InspectionReportService {
operationContent.append(String.format("报告编号从%s改为%s;", report.getReportNo(), updateVO.getReportNo())); operationContent.append(String.format("报告编号从%s改为%s;", report.getReportNo(), updateVO.getReportNo()));
report.setReportNo(updateVO.getReportNo()); report.setReportNo(updateVO.getReportNo());
} }
if (updateVO.getCarTypeName() != null && !Objects.equals(report.getCarTypeName(), updateVO.getCarTypeName())) {
operationContent.append(String.format("车型名称从%s改为%s;", report.getCarTypeName(), updateVO.getCarTypeName()));
report.setCarTypeName(updateVO.getCarTypeName());
operationType = InspectionReportOperationTypeEnum.UPDATE_CAR_TYPE_NAME.getCode();
}
if (updateVO.getScore() != null || updateVO.getScoreLevel() != null) { if (updateVO.getScore() != null || updateVO.getScoreLevel() != null) {
if (updateVO.getScore() != null && !Objects.equals(report.getScore(), updateVO.getScore())) { if (updateVO.getScore() != null && !Objects.equals(report.getScore(), updateVO.getScore())) {
operationContent.append(String.format("评分从%s改为%s;", report.getScore(), updateVO.getScore())); operationContent.append(String.format("评分从%s改为%s;", report.getScore(), updateVO.getScore()));
...@@ -166,27 +189,10 @@ public class InspectionReportService { ...@@ -166,27 +189,10 @@ public class InspectionReportService {
report.setBindStatus(updateVO.getBindStatus()); report.setBindStatus(updateVO.getBindStatus());
operationType = InspectionReportOperationTypeEnum.UPDATE_BIND_STATUS.getCode(); operationType = InspectionReportOperationTypeEnum.UPDATE_BIND_STATUS.getCode();
} }
if (updateVO.getVehicleStatus() != null && !Objects.equals(report.getVehicleStatus(), updateVO.getVehicleStatus())) {
operationContent.append(String.format("车辆状态从%s改为%s;", report.getVehicleStatus(), updateVO.getVehicleStatus()));
report.setVehicleStatus(updateVO.getVehicleStatus());
operationType = InspectionReportOperationTypeEnum.UPDATE_VEHICLE_STATUS.getCode();
}
// 其他字段更新逻辑(省略,可按需补充) // 其他字段更新逻辑(省略,可按需补充)
if (updateVO.getWoId() != null) { if (updateVO.getWoId() != null) {
report.setWoId(updateVO.getWoId()); report.setWoId(updateVO.getWoId());
} }
if (updateVO.getVehicleId() != null) {
report.setVehicleId(updateVO.getVehicleId());
}
if (updateVO.getCarSourceNo() != null) {
report.setCarSourceNo(updateVO.getCarSourceNo());
}
if (updateVO.getVin() != null) {
report.setVin(updateVO.getVin());
}
if (updateVO.getPlateNo() != null) {
report.setPlateNo(updateVO.getPlateNo());
}
if (updateVO.getH5Url() != null) { if (updateVO.getH5Url() != null) {
report.setH5Url(updateVO.getH5Url()); report.setH5Url(updateVO.getH5Url());
} }
...@@ -240,11 +246,8 @@ public class InspectionReportService { ...@@ -240,11 +246,8 @@ public class InspectionReportService {
} }
public List<InspectionReport> listByVehicleId(Integer vehicleId) { public List<InspectionReport> listByVehicleId(Integer vehicleId) {
return inspectionReportRepository.findByVehicleIdAndDeleteFlag(vehicleId, DeleteFlag.NOT_DELETED.getCode()); Vehicle vehicle = vehicleDao.findById(vehicleId).orElseThrow();
} return inspectionReportRepository.findByVehicleAndDeleteFlag(vehicle, DeleteFlag.NOT_DELETED.getCode());
public List<InspectionReport> listByVin(String vin) {
return inspectionReportRepository.findByVinAndDeleteFlag(vin, DeleteFlag.NOT_DELETED.getCode());
} }
public List<InspectionReport> listByWoId(String woId) { public List<InspectionReport> listByWoId(String woId) {
...@@ -258,10 +261,38 @@ public class InspectionReportService { ...@@ -258,10 +261,38 @@ public class InspectionReportService {
return inspectionReportRepository.findByBindStatusAndDeleteFlag(bindStatus, DeleteFlag.NOT_DELETED.getCode()); return inspectionReportRepository.findByBindStatusAndDeleteFlag(bindStatus, DeleteFlag.NOT_DELETED.getCode());
} }
public Page<InspectionReportRespVO> pageList(@Valid Pagination<InspectionReport> pagination) { public Page<InspectionReportRespVO> pageList(Pagination<InspectionReport> pagination) {
return null; // 1. 处理关键词模糊查询(复用工单查询的KEYWORD常量)
Object keyword = pagination.getFilterValueOrElseNull(JpaQueryConstants.Inspector.KEYWORD);
if (keyword instanceof String kw && StrUtil.isNotBlank(kw)) {
pagination.removeFilter(JpaQueryConstants.Inspector.KEYWORD);
String likePattern = SymbolConsts.PERCENT + kw + SymbolConsts.PERCENT;
// 2. 添加多字段模糊查询条件(报告表+关联表)
pagination.addCondition((root, query, builder) -> builder.or(
// 报告表:报告编号
builder.like(root.get(InspectionReport_.reportNo), likePattern),
// 报告表:关联工单号
builder.like(root.get(InspectionReport_.woId), likePattern),
// 关联车辆表:车源号
builder.like(root.get(InspectionReport_.vehicle).get(Vehicle_.baseInfo).get(BaseInfo_.sourceNo), likePattern),
// 关联车辆表:车牌号
builder.like(root.get(InspectionReport_.vehicle).get(Vehicle_.baseInfo).get(BaseInfo_.licensePlate), likePattern),
// 关联车辆表:VIN码
builder.like(root.get(InspectionReport_.vehicle).get(Vehicle_.baseInfo).get(BaseInfo_.vin), likePattern),
// 可选:关联工单表的工单号(双重校验,根据业务需要取舍)
builder.like(root.get(InspectionReport_.workOrder).get(InspectionWorkOrder_.woId), likePattern)
));
}
// 3. 执行分页查询
Page<InspectionReport> resultPage = inspectionReportRepository.findAll(pagination, pagination.getPageRequest());
// 4. 转换为VO分页对象
return resultPage.map(inspectionReportConverter::inspectionReportMapRespVO);
} }
public InspectionReportDetailRespVO detail(Long id) { public InspectionReportDetailRespVO detail(Long id) {
return null; return null;
} }
......
package com.glsx.usedcar.module.inspect.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
/**
* 检测报告新增请求参数
*/
@Data
@Schema(description = "检测报告新增请求参数")
public class InspectionReportAddVO implements Serializable {
@Serial
private static final long serialVersionUID = 1234567890123456789L;
@Schema(description = "报告编号(唯一)", requiredMode = Schema.RequiredMode.REQUIRED, example = "REP20260312001")
@NotBlank(message = "报告编号不能为空")
@Size(max = 50, message = "报告编号长度不能超过50个字符")
private String reportNo;
@Schema(description = "关联工单号", requiredMode = Schema.RequiredMode.REQUIRED, example = "WO20260312001")
@NotBlank(message = "关联工单号不能为空")
@Size(max = 50, message = "关联工单号长度不能超过50个字符")
private String woId;
@Schema(description = "车辆ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1001")
@NotNull(message = "车辆ID不能为空")
private Integer vehicleId;
@Schema(description = "车型名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "2023款 宝马3系 325Li M运动套装")
@NotBlank(message = "车型名称不能为空")
@Size(max = 128, message = "车型名称长度不能超过128个字符")
private String carTypeName;
@Schema(description = "车源号", requiredMode = Schema.RequiredMode.REQUIRED, example = "CS20260312001")
@NotBlank(message = "车源号不能为空")
@Size(max = 64, message = "车源号长度不能超过64个字符")
private String carSourceNo;
@Schema(description = "车辆识别码(VIN码)", requiredMode = Schema.RequiredMode.REQUIRED, example = "LVGDS123456789012")
@NotBlank(message = "VIN码不能为空")
@Size(max = 17, message = "VIN码长度不能超过17个字符")
private String vin;
@Schema(description = "车牌号", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "京A12345")
@Size(max = 20, message = "车牌号长度不能超过20个字符")
private String plateNo;
@Schema(description = "车辆状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "PREVIEW")
@NotBlank(message = "车辆状态不能为空")
@Size(max = 64, message = "车辆状态长度不能超过64个字符")
private String vehicleStatus;
@Schema(description = "评分(保留1位小数)", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "4.5")
private BigDecimal score;
@Schema(description = "评分级别(ABCDEF)", requiredMode = Schema.RequiredMode.REQUIRED, example = "A")
@NotBlank(message = "评分级别不能为空")
@Size(max = 1, message = "评分级别只能是单个字符")
private String scoreLevel;
@Schema(description = "绑定状态(1:已绑定;2:未绑定)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "绑定状态不能为空")
private Integer bindStatus;
@Schema(description = "H5链接地址", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "https://xxx.com/report/REP20260312001")
@Size(max = 512, message = "H5链接地址长度不能超过512个字符")
private String h5Url;
}
\ No newline at end of file \ No newline at end of file
package com.glsx.usedcar.module.inspect.vo; package com.glsx.usedcar.module.inspect.vo;
import com.glsx.usedcar.module.vehicle.entity.Vehicle;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
import java.math.BigDecimal;
@Data @Data
@Schema(description = "检测报告分页返回") @Schema(description = "检测报告分页返回")
public class InspectionReportRespVO { public class InspectionReportRespVO {
@Schema(description = "报告ID") @Schema(description = "报告ID", example = "10001")
private Long id; private Long id;
@Schema(description = "关联工单ID") @Schema(description = "报告编号(唯一)", example = "REPORT20260317001")
private Long workOrderId; private String reportNo;
@Schema(description = "关联工单号", example = "WO20260317001")
private String woId;
@Schema(description = "关联工单信息")
private InspectionWORespVO workOrder;
@Schema(description = "车辆信息")
private Vehicle vehicle;
@Schema(description = "检测评分(保留1位小数)", example = "95.5")
private BigDecimal score;
@Schema(description = "评分级别(ABCDEF)", example = "A")
private String scoreLevel;
@Schema(description = "绑定状态(1:已绑定;2:未绑定)", example = "1")
private Integer bindStatus;
@Schema(description = "H5报告预览链接", example = "https://report.glsx.com/h5/REPORT20260317001")
private String h5Url;
@Schema(description = "检测结论") @Schema(description = "检测结论", example = "车辆无重大事故,发动机工况良好")
private String conclusion; private String conclusion;
} }
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!