Commit a872313a by 叶立庆

增加优加主服务商配置

1 parent 9c064479
...@@ -36,6 +36,7 @@ import org.springframework.core.env.Environment; ...@@ -36,6 +36,7 @@ import org.springframework.core.env.Environment;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
/** /**
* @ClassName StaffBaseInfoController * @ClassName StaffBaseInfoController
...@@ -184,7 +185,12 @@ public class StaffBaseInfoController { ...@@ -184,7 +185,12 @@ public class StaffBaseInfoController {
@ServiceMethod(method = "dj.api.smartcarlife.staffBaseInfo.pageList", needInSession = NeedInSessionType.YES) @ServiceMethod(method = "dj.api.smartcarlife.staffBaseInfo.pageList", needInSession = NeedInSessionType.YES)
public RopResponse<RpcPagination<StaffBaseInfoResponse>> listStaffBaseInfoWithPage(StaffBaseInfoRequest request) { public RopResponse<RpcPagination<StaffBaseInfoResponse>> listStaffBaseInfoWithPage(StaffBaseInfoRequest request) {
RpcPagination<StaffBaseInfoDTO> rpcPagination = CommonUtil.getRpcPagination(StaffBaseInfoDTO.class); RpcPagination<StaffBaseInfoDTO> rpcPagination = CommonUtil.getRpcPagination(StaffBaseInfoDTO.class);
rpcPagination.getCondition().setDjServiceMerchantIdList(Arrays.asList(env.getProperty("dj.specific.partner.merchant.ids", Integer.class))); String merchantIdsStr = env.getProperty("dj.specific.partner.merchant.ids", String.class);
if (merchantIdsStr == null || merchantIdsStr.isEmpty()) {
return RopResponse.error("服务商未配置");
}
List<Integer> list = Arrays.stream(merchantIdsStr.split(",")).map(Integer::valueOf).collect(Collectors.toList());
rpcPagination.getCondition().setDjServiceMerchantIdList(list);
RpcResponse<RpcPagination<StaffBaseInfoDTO>> rpcRes = staffBaseInfoRemote.listStaffBaseInfoWithPage(rpcPagination); RpcResponse<RpcPagination<StaffBaseInfoDTO>> rpcRes = staffBaseInfoRemote.listStaffBaseInfoWithPage(rpcPagination);
if(rpcRes.hasResult()){ if(rpcRes.hasResult()){
RpcPagination<StaffBaseInfoResponse> resp = CommonUtil.convertRpcPagination(rpcRes.getResult()); RpcPagination<StaffBaseInfoResponse> resp = CommonUtil.convertRpcPagination(rpcRes.getResult());
......
  • @wangxw1
    commented
    Master

    你好, 我是资深 Java 开发工程师。针对你提交的代码变更,我进行了详细 审查,以下是审查结果:

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

    1 . 潜在的运行时异常(NumberFormatException)

    • 问题:Integer.valueOf() 在 解析字符串时,如果配置项中存在空格、非数字字符或格式错误(例如 123, 456 中的空格),会直接抛出 NumberFormatException,导致接口在配置不严谨时直接崩溃 。
    • 优化:增加异常捕获机制,或在转换前使用 trim() 去除空格 ,并建议使用 StringUtils 工具类进行校验,确保健壮性。
    1. 硬编码配置读取 与耦合

      • 问题:将解析逻辑写在 Controller 方法中违反了“单一职责原则”。如果 该配置在多个接口使用,会导致逻辑重复且难以维护。
      • 优化:建议在 Spring 配置类中使用 @Value 或 @ConfigurationProperties 将其映射为 List<Integer>,由 Spring 框架 在启动时完成类型转换和校验,Controller 层直接注入使用,减少运行期解析压力。
    2. ** 缺乏配置项格式的健壮性校验**

      • 问题:仅判断了 isEmpty(),未 判断分割后的列表是否为空。若配置为逗号但无有效数字(如 ,,),转换后的 List 可能为空,导致业务逻辑行为不符合预期。
      • 优化:在转换后增加对 list 大 小的校验,并考虑如果配置项无效,是否应该记录日志或抛出自定义业务异常,而不是直接返回简单的 错误提示。

    二、评分明细

    1. 功能实现的正确性与健壮性( 25/40):实现了需求但缺乏对数据格式解析的防御性编程。
    2. 安全性 与潜在风险(20/30):存在导致程序崩溃的异常风险。
    3. 最佳 实践与可维护性(10/20):业务逻辑处理不够优雅,未充分利用 Spring 的 自动转换特性。
    4. 性能与资源利用(4/5):性能影响极小,符合标准 。
    5. 提交信息质量(4/5):描述清晰,但未提及具体的变更范围 和影响。

    总分:63分

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