Commit 6e9cd6ab by 周立明

swagger注解属性修改

1 parent c587732a
......@@ -20,6 +20,7 @@ import cn.com.glsx.dj.smartcarlife.service.smartcarlife.ReconciliationBillImport
import cn.com.glsx.dj.smartcarlife.service.smartcarlife.ReconciliationBillService;
import cn.com.glsx.dj.smartcarlife.util.CommonUtil;
import cn.com.glsx.dj.smartcarlife.util.excel.EasyExcelUtil;
import cn.com.glsx.framework.core.annotation.ApiMethod;
import cn.com.glsx.framework.core.beans.rpc.RpcPagination;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.framework.core.exception.RpcServiceException;
......@@ -290,6 +291,7 @@ public class ReconciliationBillController {
/**
* 市场费转账
*/
@ApiMethod("dj.api.smartcarlife.reconciliationBill.transfer.market.fee")
@ApiOperation("市场费转账")
@ServiceMethod(method = "dj.api.smartcarlife.reconciliationBill.transfer.market.fee", needInSession = NeedInSessionType.YES)
public RopResponse<Boolean> transferMarketFee(ReconciliationBillTransferMarketFeeRequest request) {
......
......@@ -6,6 +6,7 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
......@@ -163,15 +164,17 @@ public class ReconciliationBillTransferMarketFeeRequest extends AbstractRopReque
@ApiModelProperty(notes = "转账凭证文件url列表")
private List<String> fileUrlList;
@ApiModelProperty(notes = "转账账号类型 1-银企账号 2-特殊银行账号")
@NotNull
@ApiModelProperty(value = "转账账号类型 1-银企账号 2-特殊银行账号(v5.8.5新增)")
private Byte bankAccountType;
@ApiModelProperty(notes = "银企账号id或特殊银行账号id")
@NotNull
@ApiModelProperty(value = "银企账号id或特殊银行账号id(v5.8.5新增)")
private Integer bankAccountId;
/**
* 调整费用
*/
@ApiModelProperty(notes = "调整费用")
@ApiModelProperty(value = "调整费用(v5.8.5新增)")
private BigDecimal adjustmentFee;
}
  • @wangxw1
    commented
    Master

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

    1. 【功能正确性与健壮性】JSR-303 参数校验注解(@NotNull)未生效(严重)

    • 问题描述:在 ReconciliationBillTransferMarketFeeRequest 中新增了 @NotNull 注解用于校验 bankAccountType 和 bankAccountId。但是,在 ReconciliationBillController 的 transferMarketFee 方法入参中,未添加 @Valid 或 @Validated 注解。这会导致 Spring/框架的参数校验拦截器不会执行,新增的 @NotNull 注解形同虚设,存在空指针或非法数据入库的风险。
    • 优化建议:在 Controller 方法的 request 参数前添加 @Validated 注解。 java // 修改前 public RopResponse<Boolean> transferMarketFee(ReconciliationBillTransferMarketFeeRequest request) // 修改后 public RopResponse<Boolean> transferMarketFee(@Validated ReconciliationBillTransferMarketFeeRequest request)

    2. 【可维护性与规范】存在重复的“魔法字符串”(中等)

    • 问题描述:在 ReconciliationBillController 中,新增的 @ApiMethod 与原有的 @ServiceMethod 使用了完全相同的硬编码字符串 "dj.api.smartcarlife.reconciliationBill.transfer.market.fee"。违反了《阿里巴巴 Java 开发手册》中关于“不允许任何魔法值直接出现在代码中”的规约。如果未来接口名变更,极易造成漏改。
    • 优化建议:将该接口路由名称提取为常量,并在注解中引用。

      // 在类中定义常量
      private static final String TRANSFER_MARKET_FEE_METHOD = "dj.api.smartcarlife.reconciliationBill.transfer.market.fee";
      
      // 注解引用常量
      @ApiMethod(TRANSFER_MARKET_FEE_METHOD)
      @ServiceMethod(method = TRANSFER_MARKET_FEE_METHOD, needInSession = NeedInSessionType.YES)
      public RopResponse<Boolean> transferMarketFee(@Validated ReconciliationBillTransferMarketFeeRequest request)
      

    3. 【提交信息质量】Commit Message 描述不完整(轻微)

    • 问题描述:本次提交的代码包含了三个维度的修改:1. 增加了 @ApiMethod 路由注解;2. 增加了 @NotNull 参数校验;3. 修改了 Swagger 注解属性(notes 改为 value)。但提交信息仅为 swagger注解属性修改,未能准确涵盖核心的业务逻辑(参数校验和路由配置)变更,不利于后续的代码追溯和 Review。
    • 优化建议:建议按照规范化的 Commit 格式编写,例如:feat(finance): 完善市场费转账接口配置,增加参数校验与Swagger版本说明。

    二、评分明细

    1. 功能实现的正确性与健壮性(40分):30分
      • 扣分原因:DTO 增加了 @NotNull 但 Controller 未配合使用 @Validated,导致核心的数据校验功能失效(扣10分)。
    2. 安全性与潜在风险(30分):28分
      • 扣分原因:参数校验未生效可能导致下游业务处理时抛出 NullPointerException,缺乏防御性编程保障(扣2分)。
    3. 最佳实践与可维护性(20分):16分
      • 扣分原因:注解中存在重复的魔法字符串,违反代码规范,增加了后续维护成本(扣4分)。
    4. 性能与资源利用(5分):5分
      • 得分说明:本次修改不涉及复杂的逻辑运算或资源调用,无性能损耗风险。
    5. 提交信息质量(5分):3分
      • 扣分原因:提交信息以偏概全,遗漏了关键的校验和路由配置说明(扣2分)。

    总分:82分

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