Commit d74a483f by 黄炜

feat: 增加解析目标触客率

1 parent f7684657
......@@ -8,6 +8,7 @@ import lombok.experimental.Accessors;
import javax.persistence.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
/**
......@@ -63,6 +64,10 @@ public class TaskInfo implements Serializable {
@Column(name = "business_type_name")
private String businessTypeName;
/** 目标触客率 */
@Column(name = "target_customer_contact_rate")
private BigDecimal targetCustomerContactRate;
/** 创建人 */
@Column(name = "creator")
private String creator;
......
......@@ -25,6 +25,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.*;
/**
......@@ -37,6 +38,10 @@ public class TaskInfoSyncService {
private static final String SUPERVISOR_COACH_TASK_TYPE = "spec-coach";
private static final String TRAFFIC_OPTIMIZE_TASK_TYPE = "traffic-optimize";
private static final String TARGET_CUSTOMER_CONTACT_RATE_FIELD_ID = "target_touch_rate";
/** 督导带教事项类型名称。 */
private static final String SUPERVISOR_COACH_TASK_TYPE_NAME = "督导带教";
......@@ -204,6 +209,10 @@ public class TaskInfoSyncService {
taskInfo.setStoreId(contextFieldMap.get("merchant_id"));
taskInfo.setBusinessType(parseIntOrNull(contextFieldMap.get("business_type")));
taskInfo.setBusinessTypeName(contextFieldMap.get("business_type_name"));
if (TRAFFIC_OPTIMIZE_TASK_TYPE.equals(task.getBizType())) {
taskInfo.setTargetCustomerContactRate(parseCustomerContactRate(
contextFieldMap.get(TARGET_CUSTOMER_CONTACT_RATE_FIELD_ID)));
}
taskInfo.setCreator(task.getCreatedBy());
taskInfo.setCreatorPhone(contextFieldMap.get("creator_phone"));
taskInfo.setTaskDescription(task.getDescription());
......@@ -337,4 +346,25 @@ public class TaskInfoSyncService {
return null;
}
}
/**
* 解析目标触客率
*/
private BigDecimal parseCustomerContactRate(String value) {
if (StringUtils.isBlank(value)) {
return null;
}
try {
BigDecimal result = new BigDecimal(value.trim());
if (result.compareTo(BigDecimal.ZERO) < 0
|| result.compareTo(new BigDecimal("100")) > 0) {
log.warn("TaskInfoSync__parseCustomerContactRate__outOfRange, value={}", value);
return null;
}
return result;
} catch (NumberFormatException e) {
log.warn("TaskInfoSync__parseCustomerContactRate__invalid, value={}", value);
return null;
}
}
}
......@@ -13,6 +13,7 @@
<result column="store_id" property="storeId" jdbcType="VARCHAR"/>
<result column="business_type" property="businessType" jdbcType="TINYINT"/>
<result column="business_type_name" property="businessTypeName" jdbcType="VARCHAR"/>
<result column="target_customer_contact_rate" property="targetCustomerContactRate" jdbcType="DECIMAL"/>
<result column="creator" property="creator" jdbcType="VARCHAR"/>
<result column="creator_phone" property="creatorPhone" jdbcType="VARCHAR"/>
<result column="task_description" property="taskDescription" jdbcType="LONGVARCHAR"/>
......@@ -99,6 +100,7 @@
SELECT
t.id, t.task_center_id, t.task_type, t.task_type_name, t.status, t.due_time,
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.reply_time, t.assigned_to_id, t.assigned_to_name, t.created_date,
coach.teaching_method_code, coach.teaching_method_name,
......@@ -146,6 +148,7 @@
SELECT
t.id, t.task_center_id, t.task_type, t.task_type_name, t.status, t.due_time,
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.reply_time, t.assigned_to_id, t.assigned_to_name, t.created_date
......@@ -201,13 +204,13 @@
<insert id="insertTaskInfo" parameterType="cn.com.glsx.dj.staff.model.TaskInfo" useGeneratedKeys="true" keyProperty="id">
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, creator, creator_phone,
business_type, business_type_name, target_customer_contact_rate, creator, creator_phone,
task_description, execution_result_code, execution_result_name,
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}, #{creator}, #{creatorPhone},
#{businessType}, #{businessTypeName}, #{targetCustomerContactRate}, #{creator}, #{creatorPhone},
#{taskDescription}, #{executionResultCode}, #{executionResultName},
#{assignedToId}, #{assignedToName},
#{createdBy}, #{createdDate}, #{updatedBy}, NOW(), 'N')
......
  • @wangxw1
    commented
    Master

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

    1. 健壮性与潜在异常风险:BigDecimal 精度未控制

    • 问题描述:在 TaskInfoSyncService.java 的 parseCustomerContactRate 方法中,直接通过 new BigDecimal(value.trim()) 生成对象并返回,未限制小数位数。
    • 影响分析:如果上游传入的字符串小数位数过多(例如 "33.333333"),而数据库中对应的 target_customer_contact_rate 字段类型精度有限(例如 DECIMAL(5,2)),在 MySQL 严格模式下,插入或更新操作可能会抛出 DataTruncation 异常,导致整个事务回滚或任务同步失败。
    • 优化建议:建议在返回前使用 setScale 方法显式指定精度和舍入模式,确保与数据库字段定义保持一致。 java // 假设数据库保留2位小数 return result.setScale(2, RoundingMode.HALF_UP);

    2. 最佳实践:常量提取与对象复用

    • 问题描述:parseCustomerContactRate 方法在校验范围时,每次都会执行 new BigDecimal("100")。
    • 影响分析:虽然对性能的实际影响微乎其微,但在频繁调用的方法内部反复创建相同的不可变对象,不符合 Java 编码最佳实践。
    • 优化建议:将其提取为类的静态常量。 ```java private static final BigDecimal MAX_CONTACT_RATE = new BigDecimal("100");

    // 使用时: if (result.compareTo(BigDecimal.ZERO) < 0 || result.compareTo(MAX_CONTACT_RATE) > 0) { ... }

    
    **3. 提交信息质量:Commit Message 缺乏业务上下文**
    - **问题描述**:本次提交信息为 `feat: 增加解析目标触客率 (by huangwei);`,较为简短。
    - **影响分析**:仅说明了“做了什么”,但缺乏“为什么做”以及关联的业务需求/Issue ID,不利于后续代码维护和问题追溯。
    - **优化建议**:建议完善提交信息,补充业务背景及影响范围。例如:`feat: 增加交通优化任务的目标触客率解析,支持在任务中心展示触客率指标 (Issue #1234)`。
    
    ---
    
    #### 二、评分明细
    
    - **功能实现的正确性与健壮性(38/40分)**:
      逻辑实现整体正确,能妥善处理空值判断,并利用 `try-catch` 捕获了 `NumberFormatException`,保证了基本健壮性。扣分点在于未对 `BigDecimal` 精度进行控制,可能存在底层数据库的截断报错风险。
    
    - **安全性与潜在风险(30/30分)**:
      未发现 SQL 注入、XSS、越权或敏感信息泄露等安全风险。MyBatis XML 映射文件中也未发现禁止使用的子查询。
    
    - **最佳实践与可维护性(18/20分)**:
      代码结构清晰,命名规范,可读性良好。扣分点在于未将高频校验的固定数值提取为常量。
    
    - **性能与资源利用(5/5分)**:
      无明显性能瓶颈,资源利用合理。
    
    - **提交信息质量(4/5分)**:
      提交信息符合基本的语义化格式(feat),但过于简短,缺乏业务背景上下文。
    
    总分:95分
    
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!