Commit c1038038 by 叶立庆

新增判断直营(加优加服务商)接口

1 parent b98ba605
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
</parent> </parent>
<groupId>cn.com.glsx</groupId> <groupId>cn.com.glsx</groupId>
<artifactId>rpc-dj-mindworkplate-api</artifactId> <artifactId>rpc-dj-mindworkplate-api</artifactId>
<version>5.8.5-SNAPSHOT</version> <version>5.8.6.3-SNAPSHOT</version>
<name>rpc-dj-mindworkplate-api</name> <name>rpc-dj-mindworkplate-api</name>
<properties> <properties>
<deploy.scanPackage>cn.com.glsx.remote</deploy.scanPackage> <deploy.scanPackage>cn.com.glsx.remote</deploy.scanPackage>
......
...@@ -164,6 +164,11 @@ public interface ResidentPointRemote { ...@@ -164,6 +164,11 @@ public interface ResidentPointRemote {
@ApiResponse("校验结果") @ApiResponse("校验结果")
RpcResponse<Boolean> residentDirectSaleMerchantCheckRemote(DirectSaleMerchantCheckRequestDTO requestDTO); RpcResponse<Boolean> residentDirectSaleMerchantCheckRemote(DirectSaleMerchantCheckRequestDTO requestDTO);
@ApiMethod("门店号是否是直营门店(加优加服务商)校验")
@ApiParam(name="requestDTO",notes="参数",dataType= ApiParam.DataTypeEnum.OBJECT,required=true)
@ApiResponse("校验结果")
RpcResponse<Boolean> residentDirectSaleMerchantCheck1Remote(DirectSaleMerchantCheckRequestDTO requestDTO);
@ApiMethod("查询海威卡券列表") @ApiMethod("查询海威卡券列表")
@ApiParam(name="requestDTO",notes="参数",dataType= ApiParam.DataTypeEnum.OBJECT,required=true) @ApiParam(name="requestDTO",notes="参数",dataType= ApiParam.DataTypeEnum.OBJECT,required=true)
@ApiResponse("查询结果") @ApiResponse("查询结果")
......
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
<dependency> <dependency>
<groupId>cn.com.glsx</groupId> <groupId>cn.com.glsx</groupId>
<artifactId>rpc-dj-mindworkplate-api</artifactId> <artifactId>rpc-dj-mindworkplate-api</artifactId>
<version>5.8.5-SNAPSHOT</version> <version>5.8.6.3-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>cn.com.glsx.dj</groupId> <groupId>cn.com.glsx.dj</groupId>
......
...@@ -453,6 +453,22 @@ public class ResidentPointRemoteImpl implements ResidentPointRemote { ...@@ -453,6 +453,22 @@ public class ResidentPointRemoteImpl implements ResidentPointRemote {
} }
@Override @Override
public RpcResponse<Boolean> residentDirectSaleMerchantCheck1Remote(DirectSaleMerchantCheckRequestDTO requestDTO) {
try {
RpcAssert.assertNotNull(requestDTO, DefaultErrorEnum.PARAMETER_NULL, "参数不能为空");
RpcAssert.assertNotNull(requestDTO.getMerchantId(), DefaultErrorEnum.PARAMETER_NULL, "门店号参数不能为空");
RpcAssert.assertNotNull(requestDTO.getScene(), DefaultErrorEnum.PARAMETER_NULL, "场景参数不能为空");
return RpcResponse.success(residentPointService.residentDirectSaleMerchant1Check(requestDTO));
} catch (RpcServiceException e) {
log.error(e.getMessage(), e);
throw e;
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new RpcServiceException(DefaultErrorEnum.SERVICE_ERROR, e.getMessage());
}
}
@Override
public RpcResponse<List<HwCouponGoodsResponse>> findAllHwProduct(ResidentPointGrantCouponRecordDTO requestDTO) { public RpcResponse<List<HwCouponGoodsResponse>> findAllHwProduct(ResidentPointGrantCouponRecordDTO requestDTO) {
try { try {
return RpcResponse.success(storePointsLevelService.findAllHwProduct()); return RpcResponse.success(storePointsLevelService.findAllHwProduct());
......
...@@ -818,6 +818,35 @@ public class ResidentPointService { ...@@ -818,6 +818,35 @@ public class ResidentPointService {
} }
} }
/**
* 门店号是否是直营门店(加优加服务商)校验
*
* @param requestDTO
* @return
*/
public Boolean residentDirectSaleMerchant1Check(DirectSaleMerchantCheckRequestDTO requestDTO) {
try {
String merchantIdsStr = env.getProperty("direct.sale.merchantIds", String.class);
if (merchantIdsStr == null || merchantIdsStr.isEmpty()) {
log.error("服务商未配置");
throw new RpcServiceException("服务商未配置");
}
List<Integer> list = Arrays.stream(merchantIdsStr.split(",")).map(Integer::valueOf).collect(Collectors.toList());
for (Integer m : list) {
requestDTO.setMainMerchantId(m);
boolean f1 = residentPointRecordMapper.residentDirectSaleMerchantCheck(requestDTO).isEmpty();
if (!f1) return true;
}
// Integer mainMerchantId = env.getProperty("direct.sale.merchantId", Integer.class, 44206988);
// requestDTO.setMainMerchantId(mainMerchantId);
// return !residentPointRecordMapper.residentDirectSaleMerchantCheck(requestDTO).isEmpty();
return false;
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new RpcServiceException("门店号是否是直营门店校验数据库查询异常");
}
}
public HwCouponOrderApiResponse getOrderByProductId(HwOrderRequest hwOrderRequest) { public HwCouponOrderApiResponse getOrderByProductId(HwOrderRequest hwOrderRequest) {
String productId = hwOrderRequest.getProductId(); String productId = hwOrderRequest.getProductId();
String outTradeNo = hwOrderRequest.getOutTradeNo(); String outTradeNo = hwOrderRequest.getOutTradeNo();
......
  • @wangxw1
    commented
    Master

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

    1. 循环内执行数据库查询(严重的性能隐患)

    • 问题描述:在 ResidentPointService.java 的 residentDirectSaleMerchant1Check 方法中,通过 for 循环遍历 merchantIdsStr,并在循环内部频繁调用 residentPointRecordMapper.residentDirectSaleMerchantCheck 进行数据库查询。
    • 影响分析:这是典型的 N+1 查询问题。如果配置的服务商 ID 数量较多,将导致与数据库建立多次网络交互,极大地消耗数据库连接资源并拖慢接口响应时间,甚至可能在高并发下引发连接池耗尽。
    • 优化建议:应将循环查询改为批量查询。在 MyBatis 层新增或修改方法,接收 List<Integer> 参数,使用 IN 关键字一次性查出结果。 代码示例: java // 建议的 Service 层优化逻辑 List<Integer> list = Arrays.stream(merchantIdsStr.split(",")).map(Integer::valueOf).collect(Collectors.toList()); // 建议在 Mapper 中新增支持 List<Integer> 的查询方法,避免在循环中查库 requestDTO.setMainMerchantIdList(list); return !residentPointRecordMapper.residentDirectSaleMerchantCheckBatch(requestDTO).isEmpty();

    2. 异常掩盖与入参对象状态被意外篡改(健壮性缺陷)

    • 问题描述:
      1. 在 ResidentPointService 中,如果抛出了 new RpcServiceException("服务商未配置"),随后会被外层的 catch (Exception e) 捕获,并被强行重新包装为 "门店号是否是直营门店校验数据库查询异常"。
      2. 在循环中使用了 requestDTO.setMainMerchantId(m) 直接修改了传入的 DTO 对象。
    • 影响分析:异常掩盖会导致排查线上问题时日志信息严重误导开发者(明明是没配置,却报数据库异常)。修改入参对象(副作用)违反了无状态编程原则,若上层调用方后续继续使用该 requestDTO,其内部的 mainMerchantId 已经被污染为循环的最后一个值,可能引发难以排查的 Bug。
    • 优化建议:区分异常捕获类型;避免修改入参,可使用局部变量或克隆对象。 代码示例: java } catch (RpcServiceException re) { throw re; // 避免自定义的 RpcServiceException 被掩盖 } catch (Exception e) { log.error("门店直营校验异常", e); throw new RpcServiceException("门店号是否是直营门店校验系统异常"); }

    3. 接口命名极度不规范与遗留无用代码(可维护性问题)

    • 问题描述:新增的 API 接口名为 residentDirectSaleMerchantCheck1Remote,Service 方法名为 residentDirectSaleMerchant1Check。此外,Service 方法中遗留了被注释掉的旧逻辑代码。
    • 影响分析:使用数字 1 作为方法后缀是工程命名中的反模式(Anti-pattern)。这使得调用方完全无法从方法名判断 Check 与 Check1 的业务区别,严重降低代码可读性与可维护性。遗留注释代码会造成代码库的无意义膨胀和视觉干扰。
    • 优化建议:根据业务实际含义重命名,例如该接口是针对“加优加服务商”的,可命名为 residentDirectSaleMerchantPlusCheckRemote 或 checkUPlusDirectSaleMerchantRemote。同时,清理掉被 // 注释掉的无用历史代码。

    二、评分明细

    • 功能实现的正确性与健壮性(32/40分) 扣分理由:虽然业务逻辑可以跑通,且遵守了 Dubbo 接口不修改已有请求参数的规则(采用新增接口的方式),但存在严重的异常掩盖逻辑缺陷,以及对入参 DTO 进行副作用修改的问题,降低了代码的健壮性。

    • 安全性与潜在风险(30/30分) 评分理由:未发现明显的 SQL 注入、越权、XSS 或敏感信息泄露等安全风险。

    • 最佳实践与可维护性(12/20分) 扣分理由:方法命名(后缀加 1)严重违反 Clean Code 命名规范;代码中提交了未清理的注释死代码。

    • 性能与资源利用(2/5分) 扣分理由:在 for 循环中直接进行数据库查询(N+1 反模式),存在明显的性能瓶颈,未合理利用数据库的批量查询能力。

    • 提交信息质量(4/5分) 扣分理由:Commit 信息 "新增判断直营(加优加服务商)接口" 表达了主要意图,但未能解释为何需要新建一个带 1 的接口而不是复用或扩展原有逻辑,缺乏部分上下文。

    总分:80分

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