Commit 1b8a7c23 by 章家宝

feat:统计未完成数量去任务中心查询专项带教未完成数量,然后加上

1 parent cb389ef0
...@@ -11,6 +11,9 @@ public class UnfinishedTaskCountReqDTO implements Serializable { ...@@ -11,6 +11,9 @@ public class UnfinishedTaskCountReqDTO implements Serializable {
@ApiModelProperty(notes = "督导手机号", required = true) @ApiModelProperty(notes = "督导手机号", required = true)
private String supervisorPhone; private String supervisorPhone;
@ApiModelProperty(notes = "督导UUID")
private String supervisorUuid;
@ApiModelProperty(notes = "开始日期(yyyy-MM-dd,可为空)") @ApiModelProperty(notes = "开始日期(yyyy-MM-dd,可为空)")
private String startDate; private String startDate;
......
...@@ -12,6 +12,10 @@ import cn.com.glsx.dj.supervisor.enums.TaskStatusEnum; ...@@ -12,6 +12,10 @@ import cn.com.glsx.dj.supervisor.enums.TaskStatusEnum;
import cn.com.glsx.dj.supervisor.enums.TaskTypeEnum; import cn.com.glsx.dj.supervisor.enums.TaskTypeEnum;
import cn.com.glsx.dj.supervisor.mapper.*; import cn.com.glsx.dj.supervisor.mapper.*;
import cn.com.glsx.dj.supervisor.model.*; import cn.com.glsx.dj.supervisor.model.*;
import cn.com.glsx.dj.taskcenter.dto.taskcenter.TaskQueryConditionDTO;
import cn.com.glsx.dj.taskcenter.dto.taskcenter.request.TaskCountRequest;
import cn.com.glsx.dj.taskcenter.dto.taskcenter.response.TaskCountResponse;
import cn.com.glsx.dj.taskcenter.remote.TaskCenterRemote;
import cn.com.glsx.framework.core.beans.BaseModel; import cn.com.glsx.framework.core.beans.BaseModel;
import cn.com.glsx.framework.core.beans.rpc.RpcPagination; import cn.com.glsx.framework.core.beans.rpc.RpcPagination;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse; import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
...@@ -114,6 +118,9 @@ public class SupervisorTaskInfoService { ...@@ -114,6 +118,9 @@ public class SupervisorTaskInfoService {
@Autowired @Autowired
private ExcellentCaseReviewMapper excellentCaseReviewMapper; private ExcellentCaseReviewMapper excellentCaseReviewMapper;
@Autowired
private TaskCenterRemote taskCenterRemote;
/** /**
* 生成日报信息 * 生成日报信息
* @param startTimeStr 日报的开始时间,yyyy-MM-dd * @param startTimeStr 日报的开始时间,yyyy-MM-dd
...@@ -1245,9 +1252,60 @@ public class SupervisorTaskInfoService { ...@@ -1245,9 +1252,60 @@ public class SupervisorTaskInfoService {
result.setSpecialCount(sumAllValues(specialMap)); result.setSpecialCount(sumAllValues(specialMap));
} }
// 增加任务中心专项带教任务(biz_type = spec-coach)的未完成数量
int taskCenterSpecialCount = getTaskCenterSpecialCoachUnfinishedCount(request.getSupervisorUuid());
result.setSpecialCount(result.getSpecialCount() + taskCenterSpecialCount);
return result; return result;
} }
/**
* 获取任务中心专项带教任务(biz_type = spec-coach)的未完成数量
* 未完成任务数 = 总数 - 已完成数
*
* @param uuid 督导
* @return 未完成任务数量
*/
private int getTaskCenterSpecialCoachUnfinishedCount(String uuid) {
if (StringUtils.isBlank(uuid)) {
return 0;
}
try {
// 构建查询条件
TaskQueryConditionDTO condition = new TaskQueryConditionDTO();
condition.setAssigneeIds(Collections.singletonList(uuid));
condition.setBizType("spec-coach");
// 构建统计请求
TaskCountRequest countRequest = new TaskCountRequest();
countRequest.setCondition(condition);
RpcResponse<TaskCountResponse> response = taskCenterRemote.countTask(countRequest);
if (response.hasError()) {
log.error("获取任务中心专项带教任务数量失败,uuid={}, error={}, message={}",
uuid, response.getError(), response.getMessage());
return 0;
}
TaskCountResponse countResponse = response.getResult();
if (countResponse == null) {
return 0;
}
// 未完成任务数 = 总数 - 已完成数(除了完成状态的任务其他状态都是未完成)
long totalCount = countResponse.getTotalCount() != null ? countResponse.getTotalCount() : 0;
long finishedCount = countResponse.getFinishedCount() != null ? countResponse.getFinishedCount() : 0;
long unfinishedCount = totalCount - finishedCount;
log.info("获取任务中心专项带教任务数量成功,uuid={}, totalCount={}, finishedCount={}, unfinishedCount={}",
uuid, totalCount, finishedCount, unfinishedCount);
return (int) Math.max(unfinishedCount, 0);
} catch (Exception e) {
log.error("获取任务中心专项带教任务数量异常,uuid={}", uuid, e);
return 0;
}
}
private Map<Integer, Integer> toCountMap(List<Map<String, Object>> list) { private Map<Integer, Integer> toCountMap(List<Map<String, Object>> list) {
if (CollectionUtils.isEmpty(list)) { if (CollectionUtils.isEmpty(list)) {
return Collections.emptyMap(); return Collections.emptyMap();
......
  • @wangxw1
    commented
    Master

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

    1. 降级策略存在业务数据误导风险(RPC 异常处理)

    • 问题描述:在 getTaskCenterSpecialCoachUnfinishedCount 方法中,当 RPC 调用失败(response.hasError())或发生异常(catch (Exception e))时,代码选择记录日志并直接返回 0。
    • 影响分析:这是一种“静默失败”的降级策略。如果任务中心服务不可用或网络超时,系统会告诉督导其未完成的专项带教任务数为 0。这会导致严重的业务数据不一致,督导可能会因此漏掉必须完成的任务。
    • 优化建议:应根据实际业务容忍度调整策略。如果该数据是强依赖的,建议抛出业务异常(如 RpcException 或自定义异常),让前端提示“获取任务数据失败,请重试”;如果允许降级,建议在返回结果中增加状态标识,告知前端部分数据未加载成功。 java // 建议方案:抛出明确的业务异常,交由上层统一处理并提示用户 if (response.hasError()) { log.error("获取任务中心专项带教任务数量失败,uuid={}, error={}, message={}", uuid, response.getError(), response.getMessage()); throw new BusinessException("获取专项带教任务失败,请稍后重试"); }

    2. 魔法字符串(Magic String)降低代码可维护性

    • 问题描述:代码中直接硬编码了业务类型字符串 "spec-coach"。
    • 影响分析:硬编码字符串在后续业务扩展或多处引用时极易出现拼写错误,且无法通过 IDE 的重构功能统一修改,降低了代码的可读性和可维护性。
    • 优化建议:将其提取为常量类或枚举类中统一管理。 ```java // 定义常量或枚举 public static final String BIZ_TYPE_SPEC_COACH = "spec-coach";

    // 使用 condition.setBizType(BIZ_TYPE_SPEC_COACH);

    
    **3. 新增参数的兼容性与校验缺失**
    - **问题描述**:`UnfinishedTaskCountReqDTO` 中新增了 `supervisorUuid` 字段,且核心逻辑强依赖此字段(为空直接返回 0)。但该字段未添加类似 `@NotBlank` 的参数校验,且 `@ApiModelProperty` 中也未标注 `required = true`(对比上方的 `supervisorPhone`)。
    - **影响分析**:
      1. **发布依赖风险**:作为 Dubbo 接口的 DTO,如果消费端(如 Web/BFF 层)未同步升级并传入该字段,底层逻辑将静默失效(始终加 0)。
      2. **校验缺失**:缺乏明确的参数约束,可能导致调用方遗漏传参而不自知。
    - **优化建议**:确认该参数是否为必传项。如果是,需在 DTO 中添加 `@NotBlank` 校验,并在 `@ApiModelProperty` 加上 `required = true`;同时需确保提供者和消费者的发布顺序一致。
    
    ---
    
    #### 二、评分明细
    
    - **功能实现的正确性与健壮性(35/40分)**:
      - **理由**:核心计算逻辑(总数减已完成数)正确,且考虑了防空指针和负数(`Math.max`)。扣分点在于 RPC 调用的异常降级策略(直接返回 0)在业务上不够健壮,容易引发用户认知错误。无 MyBatis 子查询,Dubbo 接口新增 DTO 字段属于兼容性变更,未直接修改已有参数签名。
    
    - **安全性与潜在风险(28/30分)**:
      - **理由**:代码中无明显的 SQL 注入、越权或 XSS 风险。扣分点在于静默吞掉异常可能掩盖线上隐患,且未对外部传入的 UUID 格式进行严格校验(仅判空)。
    
    - **最佳实践与可维护性(17/20分)**:
      - **理由**:方法的拆分合理,日志打印详细(包含了关键的入参和出参),注释清晰。扣分点在于使用了魔法字符串 `"spec-coach"`,不符合规范。
    
    - **性能与资源利用(5/5分)**:
      - **理由**:RPC 调用按需发起,未发现循环调用或明显的内存浪费情况。集合创建(`Collections.singletonList`)使用了最优解。
    
    - **提交信息质量(4/5分)**:
      - **理由**:Commit 信息(`feat:统计未完成数量去任务中心...`)清晰地说明了“做了什么”和“为什么做”。扣分点在于缺少关联的需求/缺陷 Issue ID,不利于后续的版本追溯。
    
    总分:89分
    
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!