Commit c03d2a29 by 黄炜

feat: 事项任务执行结果转换

1 parent d74a483f
......@@ -88,10 +88,6 @@ public class TaskInfo implements Serializable {
@Column(name = "execution_result_code")
private String executionResultCode;
/** 任务执行结果名称 */
@Column(name = "execution_result_name")
private String executionResultName;
/** 回复时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@Column(name = "reply_time")
......
......@@ -42,7 +42,6 @@ public interface TaskInfoMapper {
int updateTaskReply(@Param("id") Long id,
@Param("replyContent") String replyContent,
@Param("executionResultCode") String executionResultCode,
@Param("executionResultName") String executionResultName,
@Param("updatedBy") String updatedBy);
/**
......
......@@ -103,6 +103,8 @@ public class TaskInfoService {
*/
public TaskInfoDTO getTaskInfoDetail(Long id) {
TaskInfoDTO dto = getBaseTaskInfoDetail(id);
dto.setExecutionResultName(resolveExecutionResultName(
dto.getTaskType(), dto.getExecutionResultCode()));
if (STAFF_REPLACE_TASK_TYPE.equals(dto.getTaskType())) {
TaskStaffReplaceResult result = taskStaffReplaceResultMapper.selectByTaskId(id);
dto.setStaffReplaceResult(buildStaffReplaceResultDetail(result));
......@@ -215,7 +217,7 @@ public class TaskInfoService {
int rows = taskInfoMapper.updateTaskReply(
dto.getId(), dto.getReplyContent(), executionResultCode,
executionResultName, dto.getUpdatedBy());
dto.getUpdatedBy());
if (rows == 0) {
throw new RpcServiceException("任务已完成或任务更新失败");
}
......@@ -568,6 +570,31 @@ public class TaskInfoService {
}
/**
* 根据事项类型和执行结果编码转换详情展示名称
*/
private String resolveExecutionResultName(String taskType, String executionResultCode) {
if (StringUtils.isBlank(executionResultCode)) {
return null;
}
if (STAFF_REPLACE_TASK_TYPE.equals(taskType)) {
StaffReplaceExecutionResultEnum result =
StaffReplaceExecutionResultEnum.getByCode(executionResultCode);
return result == null ? null : result.getName();
}
if (MULTI_SCENE_EXPAND_TASK_TYPE.equals(taskType)) {
MultiSceneExpandExecutionResultEnum result =
MultiSceneExpandExecutionResultEnum.getByCode(executionResultCode);
return result == null ? null : result.getName();
}
if (NEW_STORE_TRAFFIC_TASK_TYPE.equals(taskType)) {
NewStoreTrafficExecutionResultEnum result =
NewStoreTrafficExecutionResultEnum.getByCode(executionResultCode);
return result == null ? null : result.getName();
}
return null;
}
/**
* 将督导带教执行结果写入任务中心bizContext,供任务详情回显
*/
private void upsertSupervisorCoachContext(JSONArray contextArray,
......
......@@ -28,7 +28,6 @@
type="cn.com.glsx.dj.staff.dto.taskcenter.TaskInfoDTO"
extends="TaskInfoBaseMap">
<result column="execution_result_code" property="executionResultCode" jdbcType="VARCHAR"/>
<result column="execution_result_name" property="executionResultName" jdbcType="VARCHAR"/>
<result column="teaching_method_code" property="teachingMethodCode" jdbcType="VARCHAR"/>
<result column="teaching_method_name" property="teachingMethodName" jdbcType="VARCHAR"/>
<result column="teaching_target" property="teachingTarget" jdbcType="VARCHAR"/>
......@@ -150,7 +149,7 @@
t.store_name, t.store_id, t.business_type, t.business_type_name,
t.target_customer_contact_rate,
t.creator, t.creator_phone, t.task_description, t.reply_content,
t.execution_result_code, t.execution_result_name,
t.execution_result_code,
t.reply_time, t.assigned_to_id, t.assigned_to_name, t.created_date
FROM dj_car_life_task_info t
WHERE t.id = #{id} AND t.deleted_flag = 'N'
......@@ -169,7 +168,6 @@
SET reply_content = #{replyContent},
<if test="executionResultCode != null">
execution_result_code = #{executionResultCode},
execution_result_name = #{executionResultName},
</if>
reply_time = NOW(),
status = 1,
......@@ -205,13 +203,13 @@
INSERT INTO dj_car_life_task_info
(task_center_id, task_type, task_type_name, status, due_time, store_name, store_id,
business_type, business_type_name, target_customer_contact_rate, creator, creator_phone,
task_description, execution_result_code, execution_result_name,
task_description, execution_result_code,
assigned_to_id, assigned_to_name,
created_by, created_date, updated_by, updated_date, deleted_flag)
VALUES
(#{taskCenterId}, #{taskType}, #{taskTypeName}, #{status}, #{dueTime}, #{storeName}, #{storeId},
#{businessType}, #{businessTypeName}, #{targetCustomerContactRate}, #{creator}, #{creatorPhone},
#{taskDescription}, #{executionResultCode}, #{executionResultName},
#{taskDescription}, #{executionResultCode},
#{assignedToId}, #{assignedToName},
#{createdBy}, #{createdDate}, #{updatedBy}, NOW(), 'N')
</insert>
......
  • @wangxw1
    commented
    Master

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

    1. 潜在的数据库兼容性与发布风险(重要)

    • 问题描述:在 TaskInfoMapper.xml 中,INSERT 和 UPDATE 语句移除了 execution_result_name 字段。
    • 影响分析:如果数据库表中该字段尚未被删除(或未设置允许为 NULL 且无默认值),应用部署后执行 INSERT 操作时会直接抛出 SQLException(字段未提供默认值异常),导致核心业务阻断。
    • 优化建议: 请确认是否配套了相应的数据库 DDL 脚本(如 Flyway/Liquibase)。在灰度发布或滚动发布期间,建议遵循“先允许为空/设默认值,再改代码,最后删字段”的平滑演进原则,确保新老代码对数据库的兼容性。

    2. 违反开闭原则(OCP),代码可扩展性不足

    • 问题描述:TaskInfoService.java 中的 resolveExecutionResultName 方法使用了连续的 if 分支来判断 taskType 并执行相应的枚举转换。
    • 影响分析:随着后续业务的发展,每增加一种新的任务类型(Task Type),都必须修改这个方法。这违反了面向对象设计的开闭原则,增加了代码维护成本和出错概率。
    • 优化建议: 建议使用策略模式或通过 Map 配合 Java 8 的 Function 接口进行重构,将映射逻辑静态化。 代码示例: ```java // 在类中定义静态映射表 private static final Map> RESULT_RESOLVER_MAP = new HashMap<>();

    static { RESULT_RESOLVER_MAP.put(STAFF_REPLACE_TASK_TYPE, code -> { StaffReplaceExecutionResultEnum e = StaffReplaceExecutionResultEnum.getByCode(code); return e != null ? e.getName() : null; }); RESULT_RESOLVER_MAP.put(MULTI_SCENE_EXPAND_TASK_TYPE, code -> { MultiSceneExpandExecutionResultEnum e = MultiSceneExpandExecutionResultEnum.getByCode(code); return e != null ? e.getName() : null; }); // 其他类型... }

    private String resolveExecutionResultName(String taskType, String executionResultCode) { if (StringUtils.isBlank(executionResultCode)) { return null; } Function resolver = RESULT_RESOLVER_MAP.get(taskType); return resolver != null ? resolver.apply(executionResultCode) : null; }

    
    **3. 边界场景下的静默失败处理不当**
    - **问题描述**:在 `resolveExecutionResultName` 方法的末尾,如果传入的 `taskType` 不匹配任何已知的类型,方法直接返回了 `null`。
    - **影响分析**:如果未来其他开发人员新增了任务类型,但忘记在此处添加映射逻辑,系统会静默返回 `null`,前端展示缺失,且没有任何日志提示,极大地增加了排查问题的难度。
    - **优化建议**:
      在最后的 `return null;` 之前,建议添加一行警告级别的日志,以便在出现未覆盖的枚举映射时能够快速定位问题。
      *代码示例*:
      ```java
      log.warn("未知的任务类型映射, taskType:{}, executionResultCode:{}", taskType, executionResultCode);
      return null;
    

    二、评分明细

    • 功能实现的正确性与健壮性(37 / 40分) 理由:将冗余的名称字段从数据库移除,改为通过 Code 动态实时计算,逻辑方向完全正确,避免了数据不一致的问题。扣分点在于未知 taskType 的静默返回缺乏健壮的日志追踪机制。没有触发 MyBatis 子查询和 Dubbo 接口变更的红线。

    • 安全性与潜在风险(27 / 30分) 理由:代码中不存在 SQL 注入(规范使用了 #{})、XSS 等常规安全漏洞。扣分点主要在于移除数据库插入字段带来的潜在上下游依赖断裂及数据库 DDL 不兼容的发布风险。

    • 最佳实践与可维护性(16 / 20分) 理由:去除数据库冗余字段符合数据库设计范式(第三范式),值得肯定。但 Service 层的多重 if 判断不够优雅,可扩展性较弱,未很好地贯彻设计模式。

    • 性能与资源利用(5 / 5分) 理由:减少了数据库 IO 传输和存储开销,内存中的枚举匹配性能极高,资源利用合理,表现优秀。

    • 提交信息质量(4 / 5分) 理由:feat: 事项任务执行结果转换 能够说明本次提交的核心动作,但稍微缺乏上下文(如:移除冗余字段,改为动态计算)。整体尚算清晰可追溯。

    总分:89分

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