Commit 3b9ced6a by 周立明

新增银行账号列表接口

1 parent 629c307c
......@@ -3,6 +3,13 @@ package cn.com.glsx.dj.smartcarlife.controller.smartCarLife.bankEnterpriseAccoun
import java.util.ArrayList;
import java.util.List;
import cn.com.glsx.dj.smartcarlife.convert.bankEnterpriseAccount.SpecialBankAccountConvert;
import cn.com.glsx.dj.smartcarlife.dto.bankEnterpriseAccount.SpecialBankAccountDTO;
import cn.com.glsx.dj.smartcarlife.remote.SpecialBankAccountRemote;
import cn.com.glsx.dj.smartcarlife.response.smartcarlife.BankAccountResponse;
import cn.com.glsx.framework.core.annotation.ApiMethod;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import com.rop.AbstractRopRequest;
import org.apache.commons.collections.CollectionUtils;
import org.oreframework.boot.env.OrePropertyConfigurer;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -35,6 +42,27 @@ public class MerchantBankEnterpriseAccountController {
private MerchantBankEnterpriseAccountRemote merchantBankEnterpriseAccountRemote;
@Autowired
private ExcelAsyncImportService excelAsyncImportService;
@Autowired
private SpecialBankAccountRemote specialBankAccountRemote;
@ApiMethod("dj.api.smartcarlife.merchantBankEnterpriseAccount.listBankAccount")
@ApiOperation("查询银行账号列表")
@ServiceMethod(method = "dj.api.smartcarlife.merchantBankEnterpriseAccount.listBankAccount")
public RopResponse<List<BankAccountResponse>> listBankAccount(AbstractRopRequest request){
RpcPagination<MerchantBankEnterpriseAccountDTO> rpcPagination = new RpcPagination<>();
rpcPagination.setPageNum(1);
rpcPagination.setPageSize(OrePropertyConfigurer.getProperty("export_limit_num", Integer.class, 30000));
RpcPagination<MerchantBankEnterpriseAccountDTO> mbeaRpcPagination = merchantBankEnterpriseAccountRemote.listWithPage(rpcPagination).getResult();
List<BankAccountResponse> list = new ArrayList<>();
if(mbeaRpcPagination != null &&CollectionUtils.isNotEmpty(mbeaRpcPagination.getList())){
list.addAll(MerchantBankEnterpriseAccountConvert.INSTANCE.toBankAccountResponseList(mbeaRpcPagination.getList()));
}
List<SpecialBankAccountDTO> specialBankAccountDTOList = specialBankAccountRemote.listAll(SpecialBankAccountDTO.builder().build()).getResult();
if(CollectionUtils.isNotEmpty(specialBankAccountDTOList)){
list.addAll(SpecialBankAccountConvert.INSTANCE.toBankAccountResponseList(specialBankAccountDTOList));
}
return RopResponse.success(list);
}
@ApiOperation("分页查询银企账号记录")
@ServiceMethod(method = "dj.api.smartcarlife.merchantBankEnterpriseAccount.listWithPage")
......
package cn.com.glsx.dj.smartcarlife.convert.bankEnterpriseAccount;
import cn.com.glsx.dj.smartcarlife.response.smartcarlife.BankAccountResponse;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
import cn.com.glsx.dj.smartcarlife.dto.bankEnterpriseAccount.MerchantBankEnterpriseAccountDTO;
import cn.com.glsx.dj.smartcarlife.vo.excel.bankEnterpriseAccount.MerchantBankEnterpriseAccountExport;
@Mapper
import cn.com.glsx.dj.smartcarlife.enums.reconciliationBill.BankAccountTypeEnum;
import java.util.List;
@Mapper(imports = BankAccountTypeEnum.class)
public interface MerchantBankEnterpriseAccountConvert {
MerchantBankEnterpriseAccountConvert INSTANCE = Mappers.getMapper(MerchantBankEnterpriseAccountConvert.class);
MerchantBankEnterpriseAccountExport toMerchantBankEnterpriseAccountExport(MerchantBankEnterpriseAccountDTO dto);
List<BankAccountResponse> toBankAccountResponseList(List<MerchantBankEnterpriseAccountDTO> dtoList);
@Mapping(target = "bankAccountType", expression = "java(BankAccountTypeEnum.BANK_ENTERPRISE_ACCOUNT.getValue())")
BankAccountResponse toBankAccountResponse(MerchantBankEnterpriseAccountDTO dto);
}
package cn.com.glsx.dj.smartcarlife.convert.bankEnterpriseAccount;
import cn.com.glsx.dj.smartcarlife.response.smartcarlife.BankAccountResponse;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
import cn.com.glsx.dj.smartcarlife.dto.bankEnterpriseAccount.SpecialBankAccountDTO;
import cn.com.glsx.dj.smartcarlife.vo.excel.bankEnterpriseAccount.SpecialBankAccountExport;
import cn.com.glsx.dj.smartcarlife.enums.reconciliationBill.BankAccountTypeEnum;
import java.util.List;
@Mapper
@Mapper(imports = BankAccountTypeEnum.class)
public interface SpecialBankAccountConvert {
SpecialBankAccountConvert INSTANCE = Mappers.getMapper(SpecialBankAccountConvert.class);
SpecialBankAccountExport toSpecialBankAccountExport(SpecialBankAccountDTO dto);
List<BankAccountResponse> toBankAccountResponseList(List<SpecialBankAccountDTO> dtoList);
@Mapping(target = "bankAccountType", expression = "java(BankAccountTypeEnum.SPECIAL_BANK_ACCOUNT.getValue())")
BankAccountResponse toBankAccountResponse(SpecialBankAccountDTO dto);
}
package cn.com.glsx.dj.smartcarlife.response.smartcarlife;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
@Data
public class BankAccountResponse implements Serializable {
@ApiModelProperty(value = "主键ID")
private Integer id;
@ApiModelProperty(value = "账号类型 1-银企账号 2-特殊银行账号")
private Byte bankAccountType;
/**
* 商户号
*/
@ApiModelProperty(value = "商户号")
private Integer merchantId;
/**
* 银行帐号
*/
@ApiModelProperty(value = "银行帐号")
private String bankAccountNo;
/**
* 账户名称
*/
@ApiModelProperty(value = "账户名称")
private String bankAccountName;
/**
* 开户行名称(支行)
*/
@ApiModelProperty(value = "开户行名称(支行)")
private String openAccBankName;
}
  • @wangxw1
    commented
    Master

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

    1. 严重的OOM与性能风险(单次加载数据量过大)

    • 位置:MerchantBankEnterpriseAccountController.java 中的 listBankAccount 方法。
    • 问题:接口硬编码了 pageNum=1,并将 pageSize 设置为配置项 export_limit_num(默认高达 30000 条)。随后还全量调用了 specialBankAccountRemote.listAll。将数万条数据库记录全部加载到内存、进行 MapStruct 转换并一次性序列化返回给前端,极易导致服务器内存溢出(OOM)、接口响应严重超时以及网络带宽耗尽。
    • 建议:强烈建议将该接口改造为标准的动态分页查询接口,由客户端传入 pageNum 和 pageSize。如果该接口用于前端下拉框选择,应增加关键字模糊搜索(如按账户名/账号过滤),并严格限制单次返回的最大条数(例如不超过 100 条)。

    2. 潜在的空指针异常(NPE)风险

    • 位置:MerchantBankEnterpriseAccountController.java 中的 listBankAccount 方法。
    • 问题:在调用 RPC 接口时,直接进行了链式调用获取结果,如 merchantBankEnterpriseAccountRemote.listWithPage(rpcPagination).getResult()。如果 RPC 远程调用超时、服务降级、发生异常或返回的 Response 对象本身为 null,直接调用 .getResult() 会立即触发 NullPointerException,导致接口崩溃且无法返回友好的错误信息。
    • 建议:符合阿里巴巴Java开发手册规范,RPC 调用必须进行防御性编程。应对 RPC 返回的 Response 对象先进行判空,并检查业务状态码(如 isSuccess()),确认无误后再提取 Result 数据。

    3. 配置项语义混用与分页逻辑失效

    • 位置:MerchantBankEnterpriseAccountController.java 中的 listBankAccount 方法。
    • 问题:列表查询接口错误地复用了用于文件导出的限制配置 export_limit_num。导出操作与普通列表展示在系统资源分配上的预期是完全不同的,语义混用会导致后续修改导出配置时意外影响此接口的稳定性。此外,代码中强行写死 rpcPagination.setPageNum(1),使分页对象失去了原本的意义。
    • 建议:移除对 export_limit_num 的不当引用。如果业务场景确实需要一次性获取较多数据,应新增专属的配置项(如 list_max_limit)并设置合理的安全阈值。同时,应当清理无效的假分页逻辑,保持代码语义的准确性。

    二、评分明细

    1. 功能实现的正确性与健壮性(40分):30分

      • 扣分原因:未对 RPC 调用的响应结果进行 Null 检查和成功状态判断,存在高概率的 NPE(空指针异常)风险。(-10分)
    2. 安全性与潜在风险(30分):15分

      • 扣分原因:接口单次返回数据量过大且未作安全限制,存在极高的 OOM(内存溢出)风险。恶意用户或正常高并发下极易引发系统拒绝服务(DoS)。(-15分)
    3. 最佳实践与可维护性(20分):15分

      • 扣分原因:配置项语义混用(用导出的限制作为查询的限制);分页参数硬编码,代码逻辑与实际语义不符。(-5分)
    4. 性能与资源利用(5分):0分

      • 扣分原因:一次性从数据库加载数万条数据并在内存中进行两层全量 List 遍历与对象转换,极其消耗 CPU 与内存资源,性能表现极差。(-5分)
    5. 提交信息质量(5分):4分

      • 扣分原因:提交信息“新增银行账号列表接口”说明了变更动作,但缺乏关联的业务需求背景或 Ticket 编号。(-1分)

    总分:64分

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