Commit eb52cc85 by 庞善天

轻改短课程代码优化

1 parent c21365a0
......@@ -30,5 +30,10 @@ public class SopShortCourseRecordingDTO implements Serializable {
*/
private String customerPhone;
/**
* 员工姓名
*/
private String employeeName;
}
......@@ -113,14 +113,15 @@ public class SopShortCourseTaskService {
}
// 获取成功下单的客户手机号码集合
Date startTime = Date.from(LocalDate.parse(checkDateStr).atTime(LocalTime.MIN).atZone(ZoneId.systemDefault()).toInstant());
log.info("查询开始时间:{}", startTime);
Date endTime = Date.from(LocalDate.parse(checkDateStr).atTime(LocalTime.MAX).atZone(ZoneId.systemDefault()).toInstant());
log.info("查询结束时间:{}", endTime);
List<String> successCustomerPhones = sopShortCourseTaskMapper.listSuccessOrderCustomerPhones(startTime, endTime);
// 根据手机号和复盘日期生成课程任务
Date checkDate = Date.from(LocalDate.parse(checkDateStr).atStartOfDay(ZoneId.systemDefault()).toInstant());
Date checkDate = java.sql.Date.valueOf(checkDateStr);
for (SopShortCourseConfigDetail staff : staffList) {
String staffPhone = StringUtils.trim(staff.getStaffPhone());
String staffName = staff.getStaffName();
if (StringUtils.isBlank(staffPhone)) {
continue;
}
......@@ -128,7 +129,7 @@ public class SopShortCourseTaskService {
Integer existCnt = sopShortCourseTaskMapper.countByPhoneAndDate(staffPhone, checkDateStr, bussinessType);
if (existCnt != null && existCnt > 0) {
log.info("短课程任务生成:任务已存在,phone: {}, checkDate: {}", staffPhone, checkDateStr);
continue;
//continue;
}
// 获取该手机号的录音列表
List<SopShortCourseRecordingDTO> recordings = sopShortCourseTaskMapper.listRecordingsByPhoneAndDate(staffPhone, startTime, endTime);
......@@ -136,16 +137,20 @@ public class SopShortCourseTaskService {
log.info("短课程任务生成:无录音,phone: {}, checkDate: {}", staffPhone, checkDateStr);
continue;
}
log.info("recordings size: {}", recordings.size());
String staffName = recordings.get(0).getEmployeeName();
// 根据录音列表生成任务明细
List<SopShortCourseTaskDetail> detailList = new ArrayList<>();
for (SopShortCourseRecordingDTO recording : recordings) {
// 成功下单的客户排除掉
log.info("customerPhone:{}", recording.getCustomerPhone());
if (!successCustomerPhones.isEmpty() && StringUtils.isNotBlank(recording.getCustomerPhone())
&& successCustomerPhones.contains(StringUtils.trim(recording.getCustomerPhone()))) {
continue;
}
SopShortCourseTaskDetail d = buildTaskDetail(recording);
if (d != null) {
log.info("添加明细:{}", d);
detailList.add(d);
}
}
......@@ -292,6 +297,7 @@ public class SopShortCourseTaskService {
* 按主键加载录音、批次、接待记录并组装明细
*/
private SopShortCourseTaskDetail buildTaskDetail(SopShortCourseRecordingDTO recording) {
log.info("SopShortCourseRecordingDTO:{}", recording);
Integer badgeRecordingsId = recording.getBadgeRecordingsId();
Integer conversationBatchId = recording.getConversationBatchId();
Integer customerInfoId = recording.getCustomerInfoId();
......
......@@ -16,6 +16,7 @@
<result column="conversationBatchId" property="conversationBatchId" />
<result column="customerInfoId" property="customerInfoId" />
<result column="customerPhone" property="customerPhone" />
<result column="employeeName" property="employeeName" />
</resultMap>
<select id="listRecordingsByPhoneAndDate" resultMap="RecordingMap">
......@@ -23,7 +24,8 @@
t2.id as badgeRecordingsId,
t3.id as conversationBatchId,
t1.id as customerInfoId,
t1.phone_number as customerPhone
t1.phone_number as customerPhone,
t4.employee_name as employeeName
from reception_customer_info t1
left join inspection_badge_recordings t2 on t2.reception_id = t1.id
left join inspection_conversation_batch t3 on t3.record_id = t2.id
......
  • @wangxw1
    commented
    Master

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

    1. 严重逻辑破坏:防重逻辑被注释(功能正确性)

    • 问题描述:在判断任务是否已存在的逻辑中,if (existCnt != null && existCnt > 0) 块内的 continue; 语句被注释掉。
    • 影响分析:这破坏了任务生成的幂等性。如果该员工在特定日期的短课程任务已经存在,系统原本会跳过以防止重复生成。将其注释后,会导致重复查询录音并可能向数据库插入重复的任务数据,引发数据冗余或违反数据库唯一约束(如抛出 DuplicateKeyException)。
    • 优化建议:恢复 continue; 语句。如果是为了本地调试测试,请勿将调试代码提交到线上;如果是业务需求变更允许重复生成,则需要配套修改后续的插入/更新逻辑。 java if (existCnt != null && existCnt > 0) { log.info("短课程任务生成:任务已存在,phone: {}, checkDate: {}", staffPhone, checkDateStr); continue; // 必须恢复此处的防重跳过逻辑 }

    2. 生产环境日志泛滥风险(性能与最佳实践)

    • 问题描述:在遍历 recordings(录音列表)的 for 循环内部,以及构建明细的方法中,新增了大量 log.info 级别的日志(如打印 customerPhone、添加明细、完整的 SopShortCourseRecordingDTO 对象)。
    • 影响分析:这是一个典型的将本地调试代码提交到生产环境的失误。在处理大量录音数据时,循环内的 log.info 会产生海量日志,导致严重的磁盘 I/O 性能损耗,甚至可能将关键的生产报错日志淹没,加速日志文件的滚动与丢失。
    • 优化建议:移除循环内的调试日志,或将其级别降低为 log.debug。 java // 建议删除或改为 debug 级别 // log.info("customerPhone:{}", recording.getCustomerPhone()); // log.info("添加明细:{}", d); // log.info("SopShortCourseRecordingDTO:{}", recording);

    3. 日期类型转换退化与潜在风险(最佳实践与健壮性)

    • 问题描述:将原本基于 Java 8 Time API 的日期转换 Date.from(LocalDate.parse(...)...) 替换为了 java.sql.Date.valueOf(checkDateStr)。
    • 影响分析:
      1. java.sql.Date 是 JDBC 遗留类,虽然继承自 java.util.Date,但它屏蔽了时间部分,如果在后续业务流转中其他组件调用了它的时间相关方法,会抛出 IllegalArgumentException。
      2. java.sql.Date.valueOf() 要求字符串必须是严格的 yyyy-[m]m-[d]d 格式,容错率较低。在现代 Java 开发中,混用新老日期 API 属于反模式。
    • 优化建议:建议回退到原来的 Java 8 转换方式,或者如果整个项目都在向 Java 8 Time API 迁移,建议直接使用 LocalDate 贯穿业务逻辑,由 MyBatis 直接映射。 java // 建议恢复原有的健壮写法,或确保下游绝对不会误用 java.sql.Date 的特性 Date checkDate = Date.from(LocalDate.parse(checkDateStr).atStartOfDay(ZoneId.systemDefault()).toInstant());

    二、评分明细

    • 功能实现的正确性与健壮性(25/40分): 扣分主要在于注释掉了防重逻辑(continue),这会直接导致业务数据重复生成的严重 Bug。此外,员工姓名(staffName)的获取方式从配置表变更为取录音列表的第一条记录,若第一条记录的 employeeName 为空,可能会引发下游业务的空指针或数据缺失隐患。
    • 安全性与潜在风险(30/30分): 未发现 SQL 注入、越权等安全漏洞。MyBatis 的 XML 修改使用的是隐式联表查询,未违反“不允许使用子查询”的规则。
    • 最佳实践与可维护性(12/20分): 混入了大量本地调试用的代码(多处无意义的 log.info),并且使用了过时的 java.sql.Date 替换了现代的日期处理 API,降低了代码的可维护性。
    • 性能与资源利用(2/5分): 在双重循环(员工列表 -> 录音列表)中频繁调用 log.info 打印大对象和字符串拼接,会对线上应用造成不必要的性能开销和磁盘 I/O 压力。
    • 提交信息质量(1/5分): Commit 信息为“轻改短课程代码优化”,描述过于模糊。实际上包含了业务逻辑变更(员工姓名来源变更)、调试代码残留以及防重逻辑的破坏,未能清晰反映变更的真实意图和影响范围。

    总分:70分

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