Commit 75232bbf by 崔彦峰

feat(clues): 新增线索录入类型字段支持销售和评估师区分

- 在 AddCluesReq 中添加 enterType 字段用于标识线索录入类型
- 在 CluesInfo 实体类中增加 enterType 数据库映射字段
- 创建 EnterTypeEnum 枚举类定义线索录入类型(销售/评估师)
- 更新 CluesInfoMapper.xml 映射文件包含 enter_type 字段
- 修改 CluesInfoService 中的创建者设置逻辑根据录入类型选择对应用户名称
- 移除控制器中的操作人名称设置逻辑改由服务层处理
1 parent 337c0738
...@@ -47,6 +47,13 @@ public class CluesInfo implements Serializable { ...@@ -47,6 +47,13 @@ public class CluesInfo implements Serializable {
private Integer cluesStatus; private Integer cluesStatus;
/** /**
* 线索录入类型:1-销售 2-评估师
*/
@TableField(value = "enter_type")
@Schema(description = "线索录入类型:1-销售 2-评估师")
private Integer enterType;
/**
* 车主名称 * 车主名称
*/ */
@TableField(value = "car_owner_name") @TableField(value = "car_owner_name")
......
package com.gsc4cloud.gsc.vpc.api.enums.clues;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* 线索录入类型枚举
*/
@Getter
@AllArgsConstructor
public enum EnterTypeEnum {
SALES(1, "销售"),
ASSESSOR(2, "评估师");
private final Integer code;
private final String desc;
public static EnterTypeEnum getByCode(Integer code) {
for (EnterTypeEnum e : values()) {
if (e.getCode().equals(code)) return e;
}
return null;
}
}
...@@ -83,7 +83,8 @@ public class AddCluesReq implements Serializable { ...@@ -83,7 +83,8 @@ public class AddCluesReq implements Serializable {
@Schema(description = "备注说明") @Schema(description = "备注说明")
private String remark; private String remark;
@Schema(description = "操作人(前端不用传)") @NotBlank(message = "线索录入类型不能为空")
private String operatorName; @Schema(description = "线索录入类型:1-销售 2-评估师")
private Integer enterType;
} }
  • @wangxw1
    commented
    Master

    一、关键问题与优化建议(仅限 Top 3)

    1. [功能正确性 - 致命] Integer 类型字段错误使用了 @NotBlank 注解

    • 问题描述:在 AddCluesReq.java 中,新增的 enterType 字段类型为 Integer,但使用了 @NotBlank 进行校验。@NotBlank 注解(JSR 380规范)仅支持 CharSequence(如 String)类型。当接口配合 @Validated 或 @Valid 进行参数校验时,该用法会在运行时抛出 javax.validation.UnexpectedTypeException,导致接口直接报错(通常为 Http 500),功能完全不可用。
    • 优化建议:将 @NotBlank(message = "线索录入类型不能为空") 修改为 @NotNull(message = "线索录入类型不能为空")。

    2. [安全性与潜在风险 - 高] 枚举转换缺乏范围校验与 NPE 隐患

    • 问题描述:AddCluesReq 仅校验了 enterType 不为空,但未校验其值是否在合法范围内(1或2)。若前端传入非法值(如 3),EnterTypeEnum.getByCode(3) 将返回 null。如果 Service 层(如 Commit 中提到的“根据录入类型选择对应用户名称”逻辑)直接调用该枚举对象的方法而未做空指针判断,将引发 NullPointerException。
    • 优化建议:
      • 在 EnterTypeEnum.getByCode 方法中,若未匹配到对应枚举,建议抛出业务异常(如 throw new IllegalArgumentException("未知的线索录入类型"))代替返回 null。
      • 推荐在 AddCluesReq.enterType 字段上使用自定义的 @EnumValid 注解,或在 Controller/Service 层前置校验合法性。

    3. [最佳实践与可维护性 - 中] 移除请求 DTO 字段可能引发向下兼容性问题

    • 问题描述:在 AddCluesReq.java 中直接删除了 operatorName 字段。虽然注释说明“前端不用传”,但在前后端分离或多微服务调用架构中,若调用方仍传递了该字段,且全局 JSON 反序列化配置较为严格(例如 Jackson 的 FAIL_ON_UNKNOWN_PROPERTIES 设为 true),会导致反序列化失败并报错。
    • 优化建议:确认当前项目的全局反序列化配置是否已忽略未知属性。若未忽略,建议暂时保留该字段并标记 @Deprecated 注解,待调用方彻底清理后再移除。

    二、评分明细

    • 功能实现的正确性与健壮性(25 / 40分):错误使用 @NotBlank 注解修饰 Integer 类型,属于阻断性 Bug,会导致接口不可用,扣除 15 分。
    • 安全性与潜在风险(25 / 30分):未对枚举入参进行越界校验,且枚举转换方法返回 null 存在 NPE 风险,扣除 5 分。
    • 最佳实践与可维护性(17 / 20分):直接移除请求参数类的字段存在一定的兼容性反序列化风险,扣除 3 分。枚举类设计基本符合阿里规范(属性私有且无 Setter)。
    • 性能与资源利用(5 / 5分):枚举数量较少,通过 values() 遍历性能损耗极小,无资源浪费问题。
    • 提交信息质量(5 / 5分):Commit Message 格式规范(使用了 feat: 前缀),且详细列出了修改点,便于追溯。

    总分:77分

Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!