Commit 902e5bdb by 叶立庆

Merge branch 'v5.8.6.3' into 'master'

上线合并

See merge request !28
2 parents b98ba605 c1038038
...@@ -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.residentDirectSaleMerchant1Check 方法中,当发现配置为空时,抛出了 RpcServiceException("服务商未配置")。但由于整个逻辑被包裹在一个大的 try-catch(Exception e) 块中,这个被抛出的异常会立即被下方的 catch 捕获,并被强行转换为 "门店号是否是直营门店校验数据库查询异常" 抛出。
    • 影响分析:这会导致线上出现配置缺失问题时,日志和调用方收到的却是“数据库查询异常”,严重误导问题排查方向,掩盖了真实的错误原因。
    • 优化建议:区分业务异常和系统异常的捕获。 java // 建议的异常处理结构 try { // 业务逻辑... } catch (RpcServiceException e) { // 业务异常直接抛出 throw e; } catch (Exception e) { log.error("门店号是否是直营门店校验异常", e); throw new RpcServiceException("门店号是否是直营门店校验异常"); }

    2. 循环内执行数据库查询及重复解析配置(性能与资源利用)

    • 问题描述:在 residentDirectSaleMerchant1Check 方法中,使用 for 循环遍历 merchantIds,并在循环内部调用 residentPointRecordMapper.residentDirectSaleMerchantCheck 进行数据库查询。此外,每次方法调用都会执行字符串的 split 和 Stream 转换解析。
    • 影响分析:这是典型的 N+1 性能缺陷。如果配置了多个门店 ID,会导致对数据库发起多次网络请求和查询,极大地浪费数据库连接资源并增加接口响应时间。每次请求都解析静态配置也消耗了不必要的 CPU 资源。
    • 优化建议:
      1. 将配置的解析结果缓存到类的成员变量中(如使用 @Value 或在配置更新时刷新),避免每次请求重复解析。
      2. 修改 Mapper 接口,支持传入 List<Integer>,在 MyBatis 中使用 <foreach> 标签进行 IN 查询,将多次 DB 交互合并为一次。

    3. 接口命名极不规范且存在入参副作用(最佳实践)

    • 问题描述:
      1. 接口与方法命名使用了数字后缀 1(如 residentDirectSaleMerchantCheck1Remote 和 residentDirectSaleMerchant1Check)。
      2. 在 for 循环中直接修改了外部传入的参数对象:requestDTO.setMainMerchantId(m)。
      3. 业务代码中遗留了被注释掉的废弃代码。
    • 影响分析:数字后缀命名毫无语义,严重破坏了代码的可读性和可维护性;修改外部传入的 DTO 对象(副作用)是一种危险的实践,如果调用方在 RPC 调用后继续使用了这个 requestDTO,其内部的 MainMerchantId 已经被篡改,极易引发隐藏 Bug。
    • 优化建议:
      1. 根据注释的业务含义重命名方法,例如:residentDirectSaleUjiaMerchantCheckRemote。
      2. 避免修改入参。如果无法修改底层 Mapper 改用 IN 查询,至少应该在循环内部克隆或新建查询对象,而不是复用并修改 requestDTO。
      3. 提交代码前清理掉无用的注释代码。

    二、评分明细

    • 功能实现的正确性与健壮性(32/40分)
      • 理由:未违反“已有请求参数变更”的红线(新增了接口)。但异常处理逻辑存在明显缺陷,自己抛出的业务异常被自己的 catch 块吞噬并篡改;直接修改外部传入的 DTO 存在引入潜在 Bug 的风险。扣除 8 分。
    • 安全性与潜在风险(30/30分)
      • 理由:代码主要涉及内部逻辑判断与查询,未见明显的 SQL 注入(假设 Mapper 层实现规范)、XSS 或越权等安全漏洞。满分。
    • 最佳实践与可维护性(12/20分)
      • 理由:方法命名使用 1 作为后缀是严重的命名坏味道;代码中存在未清理的无效注释代码块。扣除 8 分。
    • 性能与资源利用(2/5分)
      • 理由:存在在 for 循环中调用数据库查询的严重性能隐患,且高频接口每次调用都在解析字符串配置。扣除 3 分。
    • 提交信息质量(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!