Commit 25e7058f by 黄炜

feat: 事项新加督导带教详情逻辑

1 parent e730db86
...@@ -23,7 +23,12 @@ public class TaskInfoDTO implements Serializable { ...@@ -23,7 +23,12 @@ public class TaskInfoDTO implements Serializable {
@ApiModelProperty(notes = "外部任务中心关联id") @ApiModelProperty(notes = "外部任务中心关联id")
private Long taskCenterId; private Long taskCenterId;
@ApiModelProperty(notes = "任务类型,人员更换评估:staff-replace-access、商务政策更新评估:policy-update-access、多品类扩张:scene-expand、流量问题改善:traffic-optimize") @ApiModelProperty(notes = "任务类型," +
"人员更换评估:staff-replace-access、" +
"商务政策更新评估:policy-update-access、" +
"多品类扩张:scene-expand、" +
"流量问题改善:traffic-optimize、" +
"专项带教:spec-coach")
private String taskType; private String taskType;
@ApiModelProperty(notes = "任务类型名称") @ApiModelProperty(notes = "任务类型名称")
...@@ -82,4 +87,40 @@ public class TaskInfoDTO implements Serializable { ...@@ -82,4 +87,40 @@ public class TaskInfoDTO implements Serializable {
@ApiModelProperty(notes = "人员更换评估执行结果,仅任务类型为staff-replace-access时返回") @ApiModelProperty(notes = "人员更换评估执行结果,仅任务类型为staff-replace-access时返回")
private TaskStaffReplaceResultDTO staffReplaceResult; private TaskStaffReplaceResultDTO staffReplaceResult;
@ApiModelProperty(notes = "带教场景编码,仅专项带教任务返回")
private String teachingSceneCode;
@ApiModelProperty(notes = "带教场景名称,仅专项带教任务返回")
private String teachingSceneName;
@ApiModelProperty(notes = "带教时间,仅专项带教任务返回")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date teachingTime;
@ApiModelProperty(notes = "带教方式编码,仅专项带教任务返回")
private String teachingMethodCode;
@ApiModelProperty(notes = "带教方式名称,仅专项带教任务返回")
private String teachingMethodName;
@ApiModelProperty(notes = "带教主题编码,仅专项带教任务返回")
private String teachingTopicCode;
@ApiModelProperty(notes = "带教主题名称,仅专项带教任务返回")
private String teachingTopicName;
@ApiModelProperty(notes = "带教目标,仅专项带教任务返回")
private String teachingTarget;
@ApiModelProperty(notes = "带教门店ID,仅专项带教任务返回")
private String taskMerchantId;
@ApiModelProperty(notes = "带教门店名称,仅专项带教任务返回")
private String taskMerchantName;
@ApiModelProperty(notes = "参与人员名称列表,仅专项带教任务返回")
private List<String> taskStaffList;
} }
package cn.com.glsx.dj.staff.model;
import lombok.Data;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.Date;
/**
* 事项-督导专项带教扩展表。
*/
@Data
@Table(name = "dj_car_life_task_supervisor_coach")
public class TaskSupervisorCoach implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "task_id")
private Long taskId;
@Column(name = "task_center_id")
private Long taskCenterId;
@Column(name = "teaching_scene_code")
private String teachingSceneCode;
@Column(name = "teaching_scene_name")
private String teachingSceneName;
@Column(name = "teaching_time")
private Date teachingTime;
@Column(name = "teaching_method_code")
private String teachingMethodCode;
@Column(name = "teaching_method_name")
private String teachingMethodName;
@Column(name = "teaching_topic_code")
private String teachingTopicCode;
@Column(name = "teaching_topic_name")
private String teachingTopicName;
@Column(name = "teaching_target")
private String teachingTarget;
@Column(name = "task_merchant_id")
private String taskMerchantId;
@Column(name = "task_merchant_name")
private String taskMerchantName;
@Column(name = "task_staff_list")
private String taskStaffList;
@Column(name = "created_by")
private String createdBy;
@Column(name = "created_date")
private Date createdDate;
@Column(name = "updated_by")
private String updatedBy;
@Column(name = "updated_date")
private Date updatedDate;
@Column(name = "deleted_flag")
private String deletedFlag;
}
package cn.com.glsx.dj.staff.converter;
import cn.com.glsx.dj.staff.dto.taskcenter.TaskInfoDTO;
import cn.com.glsx.dj.staff.model.TaskSupervisorCoach;
import cn.hutool.json.JSONUtil;
import org.apache.commons.lang3.StringUtils;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
import org.mapstruct.Mappings;
import org.mapstruct.Named;
import java.util.List;
/**
* 督导专项带教扩展信息转换器。
*/
@Mapper(componentModel = "spring")
public interface TaskSupervisorCoachConvert {
@Mappings({
@Mapping(source = "taskStaffList", target = "taskStaffList", qualifiedByName = "jsonToStringList"),
@Mapping(target = "id", ignore = true),
@Mapping(target = "taskCenterId", ignore = true),
@Mapping(target = "createdDate", ignore = true)
})
void updateTaskInfo(TaskSupervisorCoach source, @MappingTarget TaskInfoDTO target);
@Named("jsonToStringList")
default List<String> jsonToStringList(String json) {
if (StringUtils.isBlank(json)) {
return null;
}
try {
return JSONUtil.toList(json, String.class);
} catch (Exception e) {
return null;
}
}
}
...@@ -5,6 +5,7 @@ import cn.com.glsx.dj.staff.dto.taskcenter.TaskInfoQueryDTO; ...@@ -5,6 +5,7 @@ import cn.com.glsx.dj.staff.dto.taskcenter.TaskInfoQueryDTO;
import cn.com.glsx.dj.staff.dto.taskcenter.TaskStaffRelDTO; import cn.com.glsx.dj.staff.dto.taskcenter.TaskStaffRelDTO;
import cn.com.glsx.dj.staff.model.TaskInfo; import cn.com.glsx.dj.staff.model.TaskInfo;
import cn.com.glsx.dj.staff.model.TaskStaffRel; import cn.com.glsx.dj.staff.model.TaskStaffRel;
import cn.com.glsx.dj.staff.model.TaskSupervisorCoach;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
...@@ -75,4 +76,9 @@ public interface TaskInfoMapper { ...@@ -75,4 +76,9 @@ public interface TaskInfoMapper {
* 根据task_center_id查询本地任务主键id * 根据task_center_id查询本地任务主键id
*/ */
Long getIdByTaskCenterId(@Param("taskCenterId") Long taskCenterId); Long getIdByTaskCenterId(@Param("taskCenterId") Long taskCenterId);
/**
* 根据本地事项ID查询督导专项带教扩展信息。
*/
TaskSupervisorCoach getSupervisorCoachByTaskId(@Param("taskId") Long taskId);
} }
package cn.com.glsx.dj.staff.service; package cn.com.glsx.dj.staff.service;
import cn.com.glsx.dj.staff.converter.TaskStaffReplaceResultConvert; import cn.com.glsx.dj.staff.converter.TaskStaffReplaceResultConvert;
import cn.com.glsx.dj.staff.converter.TaskSupervisorCoachConvert;
import cn.com.glsx.dj.staff.dto.taskcenter.TaskCountStatDTO; import cn.com.glsx.dj.staff.dto.taskcenter.TaskCountStatDTO;
import cn.com.glsx.dj.staff.dto.taskcenter.TaskInfoDTO; import cn.com.glsx.dj.staff.dto.taskcenter.TaskInfoDTO;
import cn.com.glsx.dj.staff.dto.taskcenter.TaskInfoQueryDTO; import cn.com.glsx.dj.staff.dto.taskcenter.TaskInfoQueryDTO;
...@@ -12,6 +13,7 @@ import cn.com.glsx.dj.staff.mapper.TaskInfoMapper; ...@@ -12,6 +13,7 @@ import cn.com.glsx.dj.staff.mapper.TaskInfoMapper;
import cn.com.glsx.dj.staff.mapper.TaskStaffReplaceResultMapper; import cn.com.glsx.dj.staff.mapper.TaskStaffReplaceResultMapper;
import cn.com.glsx.dj.staff.model.RecruitmentDemand; import cn.com.glsx.dj.staff.model.RecruitmentDemand;
import cn.com.glsx.dj.staff.model.TaskStaffReplaceResult; import cn.com.glsx.dj.staff.model.TaskStaffReplaceResult;
import cn.com.glsx.dj.staff.model.TaskSupervisorCoach;
import cn.com.glsx.dj.smartcarlife.dto.StaffInfoDTO; import cn.com.glsx.dj.smartcarlife.dto.StaffInfoDTO;
import cn.com.glsx.dj.smartcarlife.remote.StaffInfoRemote; import cn.com.glsx.dj.smartcarlife.remote.StaffInfoRemote;
import cn.com.glsx.dj.taskcenter.dto.taskcenter.TaskDTO; import cn.com.glsx.dj.taskcenter.dto.taskcenter.TaskDTO;
...@@ -44,6 +46,7 @@ import java.util.List; ...@@ -44,6 +46,7 @@ import java.util.List;
public class TaskInfoService { public class TaskInfoService {
private static final String STAFF_REPLACE_TASK_TYPE = "staff-replace-access"; private static final String STAFF_REPLACE_TASK_TYPE = "staff-replace-access";
private static final String SUPERVISOR_COACH_TASK_TYPE = "spec-coach";
private static final int REPLACE_NO = 0; private static final int REPLACE_NO = 0;
private static final int REPLACE_YES = 1; private static final int REPLACE_YES = 1;
private static final int METHOD_CREATE_RECRUITMENT = 1; private static final int METHOD_CREATE_RECRUITMENT = 1;
...@@ -66,6 +69,8 @@ public class TaskInfoService { ...@@ -66,6 +69,8 @@ public class TaskInfoService {
private final StaffInfoRemote staffInfoRemote; private final StaffInfoRemote staffInfoRemote;
private final TaskSupervisorCoachConvert taskSupervisorCoachConvert;
/** /**
* 分页查询事项列表,列表中同时带出每条任务关联的人员 * 分页查询事项列表,列表中同时带出每条任务关联的人员
*/ */
...@@ -97,6 +102,12 @@ public class TaskInfoService { ...@@ -97,6 +102,12 @@ public class TaskInfoService {
fillResultDisplayName(result); fillResultDisplayName(result);
dto.setStaffReplaceResult(result); dto.setStaffReplaceResult(result);
} }
if (SUPERVISOR_COACH_TASK_TYPE.equals(dto.getTaskType())) {
TaskSupervisorCoach supervisorCoach = taskInfoMapper.getSupervisorCoachByTaskId(id);
if (supervisorCoach != null) {
taskSupervisorCoachConvert.updateTaskInfo(supervisorCoach, dto);
}
}
return dto; return dto;
} }
......
...@@ -30,6 +30,28 @@ ...@@ -30,6 +30,28 @@
<result column="user_position" property="userPosition" jdbcType="INTEGER"/> <result column="user_position" property="userPosition" jdbcType="INTEGER"/>
</resultMap> </resultMap>
<resultMap id="TaskSupervisorCoachMap" type="cn.com.glsx.dj.staff.model.TaskSupervisorCoach">
<id column="id" property="id" jdbcType="BIGINT"/>
<result column="task_id" property="taskId" jdbcType="BIGINT"/>
<result column="task_center_id" property="taskCenterId" jdbcType="BIGINT"/>
<result column="teaching_scene_code" property="teachingSceneCode" jdbcType="VARCHAR"/>
<result column="teaching_scene_name" property="teachingSceneName" jdbcType="VARCHAR"/>
<result column="teaching_time" property="teachingTime" jdbcType="TIMESTAMP"/>
<result column="teaching_method_code" property="teachingMethodCode" jdbcType="VARCHAR"/>
<result column="teaching_method_name" property="teachingMethodName" jdbcType="VARCHAR"/>
<result column="teaching_topic_code" property="teachingTopicCode" jdbcType="VARCHAR"/>
<result column="teaching_topic_name" property="teachingTopicName" jdbcType="VARCHAR"/>
<result column="teaching_target" property="teachingTarget" jdbcType="VARCHAR"/>
<result column="task_merchant_id" property="taskMerchantId" jdbcType="VARCHAR"/>
<result column="task_merchant_name" property="taskMerchantName" jdbcType="VARCHAR"/>
<result column="task_staff_list" property="taskStaffList" jdbcType="LONGVARCHAR"/>
<result column="created_by" property="createdBy" jdbcType="VARCHAR"/>
<result column="created_date" property="createdDate" jdbcType="TIMESTAMP"/>
<result column="updated_by" property="updatedBy" jdbcType="VARCHAR"/>
<result column="updated_date" property="updatedDate" jdbcType="TIMESTAMP"/>
<result column="deleted_flag" property="deletedFlag" jdbcType="CHAR"/>
</resultMap>
<!-- 分页查询事项列表 --> <!-- 分页查询事项列表 -->
<select id="pageTaskInfo" parameterType="cn.com.glsx.dj.staff.dto.taskcenter.TaskInfoQueryDTO" <select id="pageTaskInfo" parameterType="cn.com.glsx.dj.staff.dto.taskcenter.TaskInfoQueryDTO"
resultMap="TaskInfoDTOMap"> resultMap="TaskInfoDTOMap">
...@@ -189,4 +211,17 @@ ...@@ -189,4 +211,17 @@
LIMIT 1 LIMIT 1
</select> </select>
<select id="getSupervisorCoachByTaskId" resultMap="TaskSupervisorCoachMap">
SELECT id, task_id, task_center_id,
teaching_scene_code, teaching_scene_name, teaching_time,
teaching_method_code, teaching_method_name,
teaching_topic_code, teaching_topic_name, teaching_target,
task_merchant_id, task_merchant_name,
task_staff_list,
created_by, created_date, updated_by, updated_date, deleted_flag
FROM dj_car_life_task_supervisor_coach
WHERE task_id = #{taskId} AND deleted_flag = 'N'
LIMIT 1
</select>
</mapper> </mapper>
  • @wangxw1
    commented
    Master

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

    1. 异常被吞没(吞异常),掩盖潜在的数据错误(重要性:高)

    • 问题描述:在 TaskSupervisorCoachConvert 类的 jsonToStringList 方法中,使用了 catch (Exception e) 捕获 JSON 解析异常,但未进行任何日志记录,直接返回了 null。
    • 影响分析:如果数据库中 task_staff_list 字段存在脏数据或非标准 JSON 格式数据,系统在转换时会静默失败并返回 null。这会导致前端丢失数据,且后端排查问题时没有任何日志线索,极大地增加了问题定位的成本。
    • 优化建议:在 catch 块中加入错误日志记录,保留现场信息(如原始 JSON 串和异常堆栈)。 java @Named("jsonToStringList") default List<String> jsonToStringList(String json) { if (StringUtils.isBlank(json)) { return null; } try { return JSONUtil.toList(json, String.class); } catch (Exception e) { // 建议引入 lombok 的 @Slf4j 或直接声明 Logger log.error("解析带教参与人员列表JSON失败, 原始数据: {}", json, e); return null; // 或者根据业务需要返回 Collections.emptyList() } }

    2. 数据库设计不一致,破坏了第一范式(重要性:中)

    • 问题描述:在 TaskSupervisorCoach 实体和建表 SQL 中,task_staff_list 被设计为 LONGVARCHAR 类型,用于存储 JSON 字符串。但从 TaskInfoMapper.java 的 import 记录(cn.com.glsx.dj.staff.model.TaskStaffRel)可以看出,系统中已经存在任务与人员的关联表设计。
    • 影响分析:同一系统中对“任务-人员”关系采用了两种不同的存储方案(关联表 vs JSON字符串)。使用 JSON 字符串存储会导致后续无法直接通过 SQL 高效查询“某个员工参与了哪些带教任务”,扩展性和统计分析能力受限。
    • 优化建议:建议保持架构设计的一致性。如果业务上确实不需要反向查询且数据量极小,当前方案勉强可用;但从长远和规范角度,建议复用原有的 TaskStaffRel 关联表机制来维护专项带教任务的参与人员。

    3. DTO 职责过载,违反开闭原则(重要性:中)

    • 问题描述:TaskInfoDTO 作为一个通用的任务信息传输对象,直接在内部平铺新增了 11 个仅属于“专项带教(spec-coach)”任务的专属字段。
    • 影响分析:随着业务发展,如果未来还有 10 种不同的任务类型,TaskInfoDTO 的字段将无限膨胀,产生大量在特定场景下为 null 的冗余字段。这不仅增加了网络传输的开销(如果未做 null 过滤),也使得类的可读性和可维护性大幅下降。
    • 优化建议:对于多态/多类型的任务扩展信息,建议在 DTO 中使用泛型、多态类或统一的扩展字段集合。例如: ```java // 方案A:使用统一的扩展对象 (推荐) @ApiModelProperty(notes = "任务扩展信息,根据taskType不同反序列化为不同的子类") private TaskExtInfoDTO extInfo;

    // 方案B:使用 Map 存储非核心扩展字段 @ApiModelProperty(notes = "动态扩展字段") private Map extData;

      *(注:考虑到当前已有 `staffReplaceResult` 字段,本次可保持现状以求快速交付,但建议在下一次重构时统一收拢扩展字段。)*
    
    ---
    
    #### 二、评分明细
    
    - **功能实现的正确性与健壮性(36/40分)**:
      核心业务逻辑实现正确,MyBatis 未使用子查询,Dubbo 接口未变更已有参数,符合重要规则。扣分点在于 JSON 转换时吞没了异常,降低了系统的健壮性。
    - **安全性与潜在风险(30/30分)**:
      MyBatis 使用了 `#` 进行参数绑定,无 SQL 注入风险;未见明显的越权或敏感信息泄露问题。
    - **最佳实践与可维护性(14/20分)**:
      代码结构清晰,使用了 MapStruct 提升了对象转换效率。扣分点在于:DTO 设计存在过度膨胀的趋势(违反 OCP 原则);关系型数据库中直接存储 JSON 数组且与现有模型设计理念不一致。
    - **性能与资源利用(5/5分)**:
      SQL 查询使用了 `LIMIT 1` 优化单行查询,未发现 N+1 查询问题,资源利用合理。
    - **提交信息质量(4/5分)**:
      Commit 信息(`feat: 事项新加督导带教详情逻辑`)遵循了 Angular 规范(feat),清晰说明了意图。若能简单补充涉及的表和核心改动点会更完美。
    
    总分:89分
    
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!