Commit b3356f2a by 庞善天

督导管家工作台

1 parent ee4b259f
package cn.com.glsx.dj.supervisor.controller;
import cn.com.glsx.dj.supervisor.dto.SupervisorTaskDTO;
import cn.com.glsx.dj.supervisor.dto.WorkbenchReportDTO;
import cn.com.glsx.dj.supervisor.dto.WorkbenchReportQueryDTO;
import cn.com.glsx.dj.supervisor.remote.SupervisorTaskInfoRemote;
import cn.com.glsx.dj.supervisor.request.SupervisorTaskQueryRequest;
import cn.com.glsx.dj.supervisor.request.WorkbenchReportRequest;
import cn.com.glsx.dj.supervisor.util.CommonUtil;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.framework.rop.response.RopResponse;
import com.rop.annotation.NeedInSessionType;
import com.rop.annotation.ServiceMethod;
import com.rop.annotation.ServiceMethodBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
/**
* 督导工作台报表接口
*/
@Slf4j
@ServiceMethodBean(version = "1.0.0", needInSession = NeedInSessionType.NO)
@Api("督导工作台报表接口")
public class SupervisorWorkbenchReportController {
@Autowired
private SupervisorTaskInfoRemote supervisorTaskInfoRemote;
/**
* 工作台报表(今日动态/本周概览/月度总览/专项督办)
* <p>根据 reportType 返回不同维度的督导任务完成情况</p>
*/
@ServiceMethod(method = "dj.api.supervisor.mini.get.workbenchReport", needInSession = NeedInSessionType.NO)
@ApiOperation("工作台报表")
public RopResponse<WorkbenchReportDTO> getWorkbenchReport(WorkbenchReportRequest request) {
WorkbenchReportQueryDTO param = CommonUtil.convertRequest(WorkbenchReportQueryDTO.class);
RpcResponse<WorkbenchReportDTO> response = supervisorTaskInfoRemote.getWorkbenchReport(param);
if (response.hasError()) {
return RopResponse.error(response.getError(), response.getMessage());
}
return RopResponse.success(response.getResult());
}
/**
* 根据ID查询督导任务详情(工作台日报/月报详情等)
*/
@ServiceMethod(method = "dj.api.supervisor.mini.workbench.getTaskDetailById", needInSession = NeedInSessionType.NO)
@ApiOperation("工作台-根据ID查询督导任务详情")
public RopResponse<SupervisorTaskDTO> getTaskDetailById(SupervisorTaskQueryRequest request) {
RpcResponse<SupervisorTaskDTO> response = supervisorTaskInfoRemote.getTaskDetailById(request.getId());
if (response.hasError()) {
return RopResponse.error(response.getError(), response.getMessage());
}
return RopResponse.success(response.getResult());
}
}
package cn.com.glsx.dj.supervisor.request;
import com.rop.AbstractRopRequest;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
/**
* 工作台报表查询请求
*/
@Data
@ToString
@EqualsAndHashCode(callSuper = true)
public class WorkbenchReportRequest extends AbstractRopRequest {
@ApiModelProperty(notes = "报表类型:1-今日动态 2-本周概览 3-月度总览 4-专项督办", required = true)
private Integer reportType;
@ApiModelProperty(notes = "开始日期 yyyy-MM-dd", required = true)
private String startDate;
@ApiModelProperty(notes = "结束日期 yyyy-MM-dd", required = true)
private String endDate;
@ApiModelProperty(notes = "督导姓名(模糊搜索,仅过滤列表)")
private String supervisorName;
}
  • @wangxw1
    commented
    Master

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

    1. 功能实现缺陷:getWorkbenchReport 方法入参未被使用(严重)

    • 问题描述:在 SupervisorWorkbenchReportController 的 getWorkbenchReport 方法中,接收了 WorkbenchReportRequest request 参数,但在进行 DTO 转换时,代码为 CommonUtil.convertRequest(WorkbenchReportQueryDTO.class);。这里未将 request 对象作为数据源传入,大概率是 API 误用或笔误。这将导致客户端传递的查询条件(如 reportType, startDate)全部丢失,引发严重的业务逻辑错误。
    • 优化建议:修正对象转换逻辑,确保将入参对象映射到目标 DTO 中。例如改为:CommonUtil.convertRequest(request, WorkbenchReportQueryDTO.class); (具体取决于 CommonUtil 的方法签名)。

    2. 安全性与健壮性:请求参数缺少 JSR-303 强校验(高危)

    • 问题描述:WorkbenchReportRequest 类中使用了 @ApiModelProperty(required = true),但这仅仅对 Swagger 接口文档生效,并不能在运行期拦截非法的空参数。如果前端漏传必填项,空数据将直接打入 RPC 服务端,可能引发下游 SQL 异常或业务脏数据。
    • 优化建议:根据《阿里巴巴 Java 开发手册》规范,Controller 层必须对外部输入进行校验。
      • 在 DTO 字段增加 javax.validation 注解:例如在 reportType 上加 @NotNull,在 startDate 和 endDate 上加 @NotBlank。
      • 对于日期字符串,建议增加 @Pattern(regexp = "^\\d{4}-\\d{2}-\\d{2}$", message = "日期格式错误") 以防止非法格式注入。
      • 在 Controller 的方法入参处配合添加 @Valid 或 ROP 框架对应的参数校验拦截注解。

    3. 最佳实践与防范 NPE:缺少防御性编程(中风险)

    • 问题描述:在 getTaskDetailById 方法中,直接调用了 request.getId() 并传递给 RPC 接口。由于缺少前置校验,如果 request 对象本身为 null(取决于底层框架机制),或者 request.getId() 为 null,此处将直接引发 NullPointerException 或将 null 透传给下游,导致级联报错。
    • 优化建议:遵循《阿里巴巴 Java 开发手册》中“防止 NPE 是程序员的基本修养”的原则。在调用下游服务前进行防御性判断: java if (request == null || request.getId() == null) { return RopResponse.error("参数错误", "任务ID不能为空"); }

    二、评分明细

    • 1. 功能实现的正确性与健壮性(40分):22分
      • 扣分原因:Controller 方法中核心入参对象未被使用,属于典型的功能性 Bug(-15分);直接调用 request.getId() 存在潜在的 NPE 风险(-3分)。
    • 2. 安全性与潜在风险(30分):20分
      • 扣分原因:对外暴露的接口缺乏服务端的强参数校验(JSR-303),仅依赖 Swagger 注解,存在恶意构造请求打穿到后端的风险(-10分)。
    • 3. 最佳实践与可维护性(20分):16分
      • 扣分原因:使用了 @Autowired 字段注入,Spring 官方和阿里规范更推荐使用构造器注入以保证依赖不可变(-2分);日期参数使用 String 且无格式约束,维护性较差(-2分)。
    • 4. 性能与资源利用(5分):5分
      • 得分原因:无明显的性能瓶颈,RPC 响应处理标准,资源利用合理。
    • 5. 提交信息质量(5分):2分
      • 扣分原因:提交信息“督导管家工作台 (by pangst)”过于简略,未能说明具体的变更内容(如:新增工作台报表及详情查询接口),不利于后续的版本回溯(-3分)。

    总分:65分

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