Commit c42256f2 by 章家宝

fix:任务中心的专项任务统计未完成数量也按照时间返回统计

1 parent 107441ff
...@@ -1190,6 +1190,8 @@ public class SupervisorTaskInfoService { ...@@ -1190,6 +1190,8 @@ public class SupervisorTaskInfoService {
result.setSpecialCount(0); result.setSpecialCount(0);
boolean useCustomDate = StringUtils.isNotBlank(startDate) && StringUtils.isNotBlank(endDate); boolean useCustomDate = StringUtils.isNotBlank(startDate) && StringUtils.isNotBlank(endDate);
// 提前计算today,供后续使用
String today = cn.com.glsx.framework.core.util.DateUtils.formatDate(new Date());
if (useCustomDate) { if (useCustomDate) {
// 使用自定义时间范围,一次查询所有类型 // 使用自定义时间范围,一次查询所有类型
...@@ -1215,7 +1217,6 @@ public class SupervisorTaskInfoService { ...@@ -1215,7 +1217,6 @@ public class SupervisorTaskInfoService {
result.setSpecialCount(sumCounts(countMap, TaskTypeEnum.SPECIAL_RECORDING.getCode())); result.setSpecialCount(sumCounts(countMap, TaskTypeEnum.SPECIAL_RECORDING.getCode()));
} else { } else {
// 默认时间范围:每日=今天,每周=本周,每月=本月,专项=今天 // 默认时间范围:每日=今天,每周=本周,每月=本月,专项=今天
String today = cn.com.glsx.framework.core.util.DateUtils.formatDate(new Date());
String weekStart = cn.com.glsx.framework.core.util.DateUtils.formatDate( String weekStart = cn.com.glsx.framework.core.util.DateUtils.formatDate(
cn.com.glsx.dj.supervisor.utils.DateUtils.getMondayOfWeek(new Date())); cn.com.glsx.dj.supervisor.utils.DateUtils.getMondayOfWeek(new Date()));
String weekEnd = cn.com.glsx.framework.core.util.DateUtils.formatDate( String weekEnd = cn.com.glsx.framework.core.util.DateUtils.formatDate(
...@@ -1254,7 +1255,10 @@ public class SupervisorTaskInfoService { ...@@ -1254,7 +1255,10 @@ public class SupervisorTaskInfoService {
} }
// 增加任务中心专项带教任务(biz_type = spec-coach)的未完成数量 // 增加任务中心专项带教任务(biz_type = spec-coach)的未完成数量
int taskCenterSpecialCount = getTaskCenterSpecialCoachUnfinishedCount(request.getSupervisorUuid()); // 专项任务按每日统计,时间范围与其他专项任务保持一致
String specialStartDate = useCustomDate ? startDate : today;
String specialEndDate = useCustomDate ? endDate : today;
int taskCenterSpecialCount = getTaskCenterSpecialCoachUnfinishedCount(request.getSupervisorUuid(), specialStartDate, specialEndDate);
result.setSpecialCount(result.getSpecialCount() + taskCenterSpecialCount); result.setSpecialCount(result.getSpecialCount() + taskCenterSpecialCount);
return result; return result;
...@@ -1265,9 +1269,11 @@ public class SupervisorTaskInfoService { ...@@ -1265,9 +1269,11 @@ public class SupervisorTaskInfoService {
* 未完成任务数 = 总数 - 已完成数 * 未完成任务数 = 总数 - 已完成数
* *
* @param uuid 督导 * @param uuid 督导
* @param startDate 开始时间
* @param endDate 结束时间
* @return 未完成任务数量 * @return 未完成任务数量
*/ */
private int getTaskCenterSpecialCoachUnfinishedCount(String uuid) { private int getTaskCenterSpecialCoachUnfinishedCount(String uuid, String startDate, String endDate) {
if (StringUtils.isBlank(uuid)) { if (StringUtils.isBlank(uuid)) {
return 0; return 0;
} }
...@@ -1276,6 +1282,13 @@ public class SupervisorTaskInfoService { ...@@ -1276,6 +1282,13 @@ public class SupervisorTaskInfoService {
TaskQueryConditionDTO condition = new TaskQueryConditionDTO(); TaskQueryConditionDTO condition = new TaskQueryConditionDTO();
condition.setAssigneeIds(Collections.singletonList(uuid)); condition.setAssigneeIds(Collections.singletonList(uuid));
condition.setBizType("spec-coach"); condition.setBizType("spec-coach");
// 设置创建时间范围
if (StringUtils.isNotBlank(startDate)) {
condition.setCreatedDateStart(DateUtil.beginOfDay(DateUtil.parseDate(startDate)));
}
if (StringUtils.isNotBlank(endDate)) {
condition.setCreatedDateEnd(DateUtil.endOfDay(DateUtil.parseDate(endDate)));
}
// 构建统计请求 // 构建统计请求
TaskCountRequest countRequest = new TaskCountRequest(); TaskCountRequest countRequest = new TaskCountRequest();
......
  • @wangxw1
    commented
    Master

    一、关键问题与优化建议

    1. 日期字符串解析缺乏异常处理与格式约束(功能健壮性)

    • 问题描述:在 getTaskCenterSpecialCoachUnfinishedCount 方法中,使用了 DateUtil.parseDate(startDate) 来解析字符串。如果 startDate 或 endDate 的格式不符合预期(且在 Controller 层没有进行严格的格式校验),该方法会抛出运行时异常(如 Hutool 的 DateException),导致整个接口返回 500 错误。
    • 影响分析:过度依赖底层工具类的兼容解析能力,当遇到恶意输入或脏数据时,会导致程序不够健壮,影响可用性。
    • 优化建议:确保在 API 入口处(Controller 层)对 startDate 和 endDate 进行了严格的正则或 @Pattern 校验。如果无法保证上层校验,建议在此处捕获解析异常并做降级处理,或者使用明确格式的 DateTimeFormatter 进行解析。

    2. 日期工具类混用,代码一致性较差(工程最佳实践)

    • 问题描述:在同一个类(甚至同一个方法上下文)中,混用了多种日期工具类。原有代码使用了 cn.com.glsx.framework.core.util.DateUtils 和 cn.com.glsx.dj.supervisor.utils.DateUtils,而新增的代码引入了 DateUtil(从方法签名推测大概率为 Hutool 的 cn.hutool.core.date.DateUtil)。
    • 影响分析:引入多套职责重叠的工具类会增加代码的认知负担,降低可维护性。不同工具类在处理时区、并发安全(如内部是否复用 SimpleDateFormat)时可能存在差异,存在潜在隐患。
    • 优化建议:统一项目中的日期处理方式。建议优先使用 Java 8 原生的 java.time API(如 LocalDate / LocalDateTime),或者统一收口使用框架内定好的 DateUtils。

    注:本次修改的方法 getTaskCenterSpecialCoachUnfinishedCount 为 private 私有方法,并非 Dubbo 的 Remote 暴露接口,因此修改方法签名不违背“Dubbo服务提供者Remote接口变更”的安全规则,属于安全重构。


    二、评分明细

    • 功能实现的正确性与健壮性(36/40分): 业务逻辑修改正确,成功将专项任务的统计纳入了时间范围过滤,且复用了 today 变量,逻辑清晰。扣分点在于字符串日期解析缺乏明确的防错/容错机制,依赖外部传入数据的绝对正确性。
    • 安全性与潜在风险(30/30分): 未引入 SQL 注入、越权、XSS 等安全漏洞。修改的是私有方法,不影响外部 RPC 接口的兼容性。
    • 最佳实践与可维护性(16/20分): 代码具备基本的注释说明,变量命名(如 specialStartDate)清晰易懂。扣分点在于日期工具类的严重混用,破坏了代码的一致性。
    • 性能与资源利用(5/5分): 将 new Date() 的格式化提前计算并复用,避免了多次重复计算,是一个良好的微小性能优化习惯。无资源浪费。
    • 提交信息质量(5/5分): Commit message (fix:任务中心的专项任务统计未完成数量也按照时间返回统计) 格式规范,清晰地说明了本次修复的业务目的,具备良好的可追溯性。

    总分:92分

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