Commit 572d0408 by 庞善天

优秀案例录取提报取扩展表数量

1 parent fa8a0c03
package cn.com.glsx.dj.supervisor.mapper; package cn.com.glsx.dj.supervisor.mapper;
import cn.com.glsx.dj.supervisor.dto.WorkbenchAudioReviewStatDTO; import cn.com.glsx.dj.supervisor.dto.WorkbenchAudioReviewStatDTO;
import cn.com.glsx.dj.supervisor.dto.WorkbenchExcellentCaseCountDTO;
import cn.com.glsx.dj.supervisor.dto.WorkbenchReportTaskRowDTO; import cn.com.glsx.dj.supervisor.dto.WorkbenchReportTaskRowDTO;
import cn.com.glsx.dj.supervisor.dto.WorkbenchTeachingCountDTO; import cn.com.glsx.dj.supervisor.dto.WorkbenchTeachingCountDTO;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
...@@ -29,4 +30,10 @@ public interface SupervisorWorkbenchReportMapper { ...@@ -29,4 +30,10 @@ public interface SupervisorWorkbenchReportMapper {
*/ */
List<WorkbenchAudioReviewStatDTO> listAudioReviewStats(@Param("startDate") String startDate, List<WorkbenchAudioReviewStatDTO> listAudioReviewStats(@Param("startDate") String startDate,
@Param("endDate") String endDate); @Param("endDate") String endDate);
/**
* 统计优秀案例提报数量
*/
List<WorkbenchExcellentCaseCountDTO> countExcellentCaseGroupBySubmitterName(@Param("startDate") String startDate,
@Param("endDate") String endDate);
} }
...@@ -81,7 +81,15 @@ public class SupervisorWorkbenchReportService { ...@@ -81,7 +81,15 @@ public class SupervisorWorkbenchReportService {
List<WorkbenchAudioReviewStatDTO> audioStats = workbenchReportMapper.listAudioReviewStats( List<WorkbenchAudioReviewStatDTO> audioStats = workbenchReportMapper.listAudioReviewStats(
query.getStartDate(), query.getEndDate()); query.getStartDate(), query.getEndDate());
TaskDataIndex dataIndex = new TaskDataIndex(taskRows, teachingCounts, audioStats, reviewRatioThreshold); // 优秀案例录音提报
List<WorkbenchExcellentCaseCountDTO> excellentCaseCounts = null;
if (reportType == WorkbenchReportTypeEnum.WEEK || reportType == WorkbenchReportTypeEnum.MONTH) {
excellentCaseCounts = workbenchReportMapper.countExcellentCaseGroupBySubmitterName(
query.getStartDate(), query.getEndDate());
}
TaskDataIndex dataIndex = new TaskDataIndex(taskRows, teachingCounts, audioStats,
excellentCaseCounts, reviewRatioThreshold);
List<WorkbenchReportSupervisorItemDTO> allItems = new ArrayList<>(); List<WorkbenchReportSupervisorItemDTO> allItems = new ArrayList<>();
for (MerchantStaffResponse staff : allSupervisors) { for (MerchantStaffResponse staff : allSupervisors) {
...@@ -145,14 +153,12 @@ public class SupervisorWorkbenchReportService { ...@@ -145,14 +153,12 @@ public class SupervisorWorkbenchReportService {
return Arrays.asList( return Arrays.asList(
TaskTypeEnum.DAILY_REPORT.getCode(), TaskTypeEnum.DAILY_REPORT.getCode(),
TaskTypeEnum.AUDIO_RECORDING.getCode(), TaskTypeEnum.AUDIO_RECORDING.getCode(),
TaskTypeEnum.TRAINING.getCode(), TaskTypeEnum.TRAINING.getCode());
TaskTypeEnum.EXCELLENT_CASE_AUDIO.getCode());
case MONTH: case MONTH:
return Arrays.asList( return Arrays.asList(
TaskTypeEnum.DAILY_REPORT.getCode(), TaskTypeEnum.DAILY_REPORT.getCode(),
TaskTypeEnum.AUDIO_RECORDING.getCode(), TaskTypeEnum.AUDIO_RECORDING.getCode(),
TaskTypeEnum.TRAINING.getCode(), TaskTypeEnum.TRAINING.getCode(),
TaskTypeEnum.EXCELLENT_CASE_AUDIO.getCode(),
TaskTypeEnum.MONTHLY_REPORT.getCode()); TaskTypeEnum.MONTHLY_REPORT.getCode());
case SPECIAL: case SPECIAL:
return Collections.singletonList(TaskTypeEnum.SPECIAL_RECORDING.getCode()); return Collections.singletonList(TaskTypeEnum.SPECIAL_RECORDING.getCode());
...@@ -446,10 +452,12 @@ public class SupervisorWorkbenchReportService { ...@@ -446,10 +452,12 @@ public class SupervisorWorkbenchReportService {
private final Map<String, List<WorkbenchReportTaskRowDTO>> tasksByName; private final Map<String, List<WorkbenchReportTaskRowDTO>> tasksByName;
private final Map<String, Map<String, Integer>> teachingByNameAndScene; private final Map<String, Map<String, Integer>> teachingByNameAndScene;
private final Map<String, List<WorkbenchAudioReviewStatDTO>> audioByName; private final Map<String, List<WorkbenchAudioReviewStatDTO>> audioByName;
private final Map<String, Map<String, Integer>> excellentCaseCountByNameAndDate;
TaskDataIndex(List<WorkbenchReportTaskRowDTO> tasks, TaskDataIndex(List<WorkbenchReportTaskRowDTO> tasks,
List<WorkbenchTeachingCountDTO> teachingCounts, List<WorkbenchTeachingCountDTO> teachingCounts,
List<WorkbenchAudioReviewStatDTO> audioStats, List<WorkbenchAudioReviewStatDTO> audioStats,
List<WorkbenchExcellentCaseCountDTO> excellentCaseCounts,
int reviewRatioThreshold) { int reviewRatioThreshold) {
this.reviewRatioThreshold = reviewRatioThreshold; this.reviewRatioThreshold = reviewRatioThreshold;
...@@ -471,6 +479,17 @@ public class SupervisorWorkbenchReportService { ...@@ -471,6 +479,17 @@ public class SupervisorWorkbenchReportService {
audioStats.stream() audioStats.stream()
.filter(a -> StringUtils.isNotBlank(a.getSupervisorName())) .filter(a -> StringUtils.isNotBlank(a.getSupervisorName()))
.collect(Collectors.groupingBy(WorkbenchAudioReviewStatDTO::getSupervisorName)); .collect(Collectors.groupingBy(WorkbenchAudioReviewStatDTO::getSupervisorName));
this.excellentCaseCountByNameAndDate = new HashMap<>();
if (excellentCaseCounts != null) {
for (WorkbenchExcellentCaseCountDTO ec : excellentCaseCounts) {
if (StringUtils.isNotBlank(ec.getSubmitterName()) && StringUtils.isNotBlank(ec.getSubmitDate())) {
excellentCaseCountByNameAndDate
.computeIfAbsent(ec.getSubmitterName(), k -> new HashMap<>())
.put(ec.getSubmitDate(), ec.getCount() == null ? 0 : ec.getCount());
}
}
}
} }
boolean hasSpecialTask(String name) { boolean hasSpecialTask(String name) {
...@@ -555,11 +574,21 @@ public class SupervisorWorkbenchReportService { ...@@ -555,11 +574,21 @@ public class SupervisorWorkbenchReportService {
.count(); .count();
} }
/**
* 优秀案例录音提报数
*/
int countExcellentCaseRecords(String name, LocalDate start, LocalDate end) { int countExcellentCaseRecords(String name, LocalDate start, LocalDate end) {
return (int) tasksByName.getOrDefault(name, Collections.emptyList()).stream() Map<String, Integer> dateCountMap = excellentCaseCountByNameAndDate.get(name);
.filter(t -> TaskTypeEnum.EXCELLENT_CASE_AUDIO.getCode().equals(t.getTaskType())) if (dateCountMap == null || dateCountMap.isEmpty()) {
.filter(t -> isDateInRange(t.getTaskDate(), start, end)) return 0;
.count(); }
int total = 0;
for (Map.Entry<String, Integer> entry : dateCountMap.entrySet()) {
if (isDateInRange(entry.getKey(), start, end)) {
total += entry.getValue();
}
}
return total;
} }
private boolean isReviewCompleted(WorkbenchAudioReviewStatDTO stat) { private boolean isReviewCompleted(WorkbenchAudioReviewStatDTO stat) {
......
...@@ -60,4 +60,18 @@ ...@@ -60,4 +60,18 @@
GROUP BY sti.id, sti.supervisor_name, DATE_FORMAT(sti.create_time, '%Y-%m-%d') GROUP BY sti.id, sti.supervisor_name, DATE_FORMAT(sti.create_time, '%Y-%m-%d')
</select> </select>
<select id="countExcellentCaseGroupBySubmitterName" resultType="cn.com.glsx.dj.supervisor.dto.WorkbenchExcellentCaseCountDTO">
SELECT
submitter_name AS submitterName,
DATE_FORMAT(create_time, '%Y-%m-%d') AS submitDate,
COUNT(*) AS count
FROM excellent_case_review
WHERE deleted_flag = 'N'
AND submitter_name IS NOT NULL
AND submitter_name != ''
AND CAST(create_time AS DATE) &gt;= #{startDate, jdbcType=DATE}
AND CAST(create_time AS DATE) &lt;= #{endDate, jdbcType=DATE}
GROUP BY submitter_name, DATE_FORMAT(create_time, '%Y-%m-%d')
</select>
</mapper> </mapper>
  • @wangxw1
    commented
    Master

    一、关键问题与优化建议,如果必要,给出代码示例(仅限 Top 3)

    1. 功能实现的正确性:日报告(DAILY)可能丢失优秀案例统计数据的逻辑漏洞

    • 问题描述:在 getTaskTypesByReportType 方法中,EXCELLENT_CASE_AUDIO 任务类型不仅从 MONTH 中移除,也从 DAILY 报告中移除了。但在获取扩展表数据的逻辑中,仅判断了 reportType == WEEK || reportType == MONTH,完全漏掉了 DAILY 类型。
    • 影响分析:如果业务上日报告(DAILY)仍然需要展示“优秀案例提报数量”,当前的修改会导致该项数据在日报告中永远为 0,造成业务数据丢失。
    • 优化建议:确认日报告是否需要统计优秀案例。如果需要,请在条件判断中补全 DAILY 类型;如果确实不再需要,请在注释或提交信息中明确说明,确保调用方已兼容。 java // 若 DAILY 也需要统计,应修改为: if (reportType == WorkbenchReportTypeEnum.DAILY || reportType == WorkbenchReportTypeEnum.WEEK || reportType == WorkbenchReportTypeEnum.MONTH) { excellentCaseCounts = workbenchReportMapper.countExcellentCaseGroupBySubmitterName( query.getStartDate(), query.getEndDate()); }

    2. 性能与资源利用:SQL 索引失效风险

    • 问题描述:在 SupervisorWorkbenchReportMapper.xml 的查询中,使用了 CAST(create_time AS DATE) >= #{startDate}。对条件字段 create_time 使用函数进行转换。
    • 影响分析:在 SQL 中对字段使用函数(如 CAST 或 DATE_FORMAT)会导致该字段上的索引失效。随着 excellent_case_review 表数据量增加,该查询会引发全表扫描,造成明显的性能瓶颈。
    • 优化建议:避免在字段上使用函数,直接对时间范围进行比较。可以在 Java 层拼接好起止时间,或者在 SQL 中使用 CONCAT 拼接时间后缀: xml AND create_time &gt;= CONCAT(#{startDate}, ' 00:00:00') AND create_time &lt;= CONCAT(#{endDate}, ' 23:59:59')

    3. 功能实现的正确性与健壮性:使用姓名作为关联键存在数据错乱隐患

    • 问题描述:在 SQL 查询(GROUP BY submitter_name)以及 Java 内存数据聚合(excellentCaseCountByNameAndDate)中,均使用了 submitter_name 作为数据分组和匹配的唯一键。
    • 影响分析:如果 submitter_name 是员工的真实中文姓名,当公司存在同名同姓的员工时,他们的数据会被错误合并,导致最终的统计报表数据严重错乱。
    • 优化建议:强烈建议在业务表和聚合逻辑中使用用户的唯一标识(如 submitter_id、staff_id 或工号)进行 GROUP BY 和内存匹配,在最终展示时再映射为员工姓名。

    二、评分明细

    • 功能实现的正确性与健壮性(40分):30分
      • 未违反 MyBatis 子查询禁用规则,未涉及 Dubbo 参数变更。但存在日报告(DAILY)可能丢失数据的业务逻辑漏洞,以及使用姓名关联数据带来的同名同姓健壮性隐患,扣除 10 分。
    • 安全性与潜在风险(30分):30分
      • SQL 参数均使用了 #{} 预编译,无 SQL 注入风险;未发现越权或敏感信息泄露等安全隐患。
    • 最佳实践与可维护性(20分):16分
      • 代码结构相对清晰,防御了空指针异常。但 TaskDataIndex 的数据聚合逻辑略显冗余,且 Map 嵌套结构增加了理解成本,建议适当封装。
    • 性能与资源利用(5分):2分
      • SQL 过滤条件中对 create_time 使用 CAST 函数,存在明确的索引失效和全表扫描风险,影响数据库性能,扣除 3 分。
    • 提交信息质量(5分):3分
      • commit 信息“优秀案例录取提报取扩展表数量”说明了大致意图,但存在错别字(“录取”应为“录音”),且未对移除原有任务类型的背景做简要说明,不利于后续追溯。

    总分:81分

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