Commit 7e176116 by zhouhaibao

feat(merchant): 添加门店关联服务商查询功能

- 新增 ServiceMerchantRefRemote 接口方法 getShopMerchantServiceRef
- 实现 ServiceMerchantRefRemoteImpl 中的 getShopMerchantServiceRef 方法
- 添加 ServiceMerchantRefService 业务逻辑层方法 getShopMerchantServiceRef
- 在 SceneMerchantRefNewMapper 中新增 getShopMerchantServiceRef 数据访问方法
- 配置 SceneMerchantRefNewMapper.xml 中的 getShopMerchantServiceRef SQL 查询
- 添加 MerchantStoreInfoRemoteTest 单元测试用例验证功能
1 parent 6aadbb06
......@@ -301,4 +301,13 @@ public interface ServiceMerchantRefRemote {
@ApiResponse("返回是否执行成功")
RpcResponse<Boolean> enableSingleMerchantRef(
CreateBusinessApproveMerchantDTO createBusinessApproveMerchantDTO);
@ApiMethod("查询单个门店关联服务商")
@ApiParams({
@ApiParam(name="shopMerchantId",notes="流量方ID",dataType= ApiParam.DataTypeEnum.INTEGER,required=true),
@ApiParam(name="refMerchantId",notes="服务商idID",dataType= ApiParam.DataTypeEnum.INTEGER,required=true),
@ApiParam(name="sceneType",notes="场景类型",dataType= ApiParam.DataTypeEnum.INTEGER,required=true)
})
@ApiResponse("返回是否执行成功")
RpcResponse<Boolean> getShopMerchantServiceRef(@NotNull Integer shopMerchantId, @NotNull Integer refMerchantId,@NotNull String baseSceneCode);
}
......@@ -36,4 +36,6 @@ public interface SceneMerchantRefNewMapper extends OreMapper<SceneMerchantRefNew
void deleteByMerchantIdSceneAndBaseSceneCode(@Param("mainMerchantId") Integer merchantId, @Param("scene") Integer scene,@Param("baseSceneCode") String baseSceneCode);
List<MerchantListDTO> querySimpleSceneRefByShopNew(@Param("merchantId") Integer merchantId,@Param("scene") Integer scene,@Param("baseSceneCode") String baseSceneCode);
List<SceneMerchantRefNew> getShopMerchantServiceRef(@Param("shopMerchantId") Integer shopMerchantId, @Param("refMerchantId") Integer refMerchantId,@Param("baseSceneCode") String baseSceneCode);
}
\ No newline at end of file
......@@ -379,4 +379,17 @@ public class ServiceMerchantRefRemoteImpl implements ServiceMerchantRefRemote {
return RpcResponse.error(e);
}
}
@Override
public RpcResponse<Boolean> getShopMerchantServiceRef(Integer shopMerchantId,
Integer refMerchantId, String baseSceneCode) {
try {
Boolean shopMerchantServiceRef = serviceMerchantRefService.getShopMerchantServiceRef(
shopMerchantId, refMerchantId, baseSceneCode);
return RpcResponse.success(shopMerchantServiceRef);
} catch (Exception e) {
log.error("enableSingleMerchantRef error", e);
return RpcResponse.error(e);
}
}
}
......@@ -2028,4 +2028,14 @@ public class ServiceMerchantRefService {
refDTO.setBaseSceneCode(merchantRefSceneAddDTO.getBaseSceneCode());
return refDTO;
}
public Boolean getShopMerchantServiceRef(Integer shopMerchantId, Integer refMerchantId, String baseSceneCode) {
List<SceneMerchantRefNew> sceneMerchantRefNews=sceneMerchantRefNewMapper.getShopMerchantServiceRef(shopMerchantId, refMerchantId, baseSceneCode);
if (CollectionUtils.isEmpty(sceneMerchantRefNews)){
return false;
}else{
return true;
}
}
}
......@@ -73,4 +73,11 @@
where main_merchant_id = #{merchantId} and scene = #{scene} and sub_merchant_type = 7 and base_scene_code = #{baseSceneCode}
and deleted_flag = 'N' and status = 1
</select>
<select id="getShopMerchantServiceRef"
resultType="cn.com.glsx.dj.smartcarlife.model.SceneMerchantRefNew">
select sub_merchant_id as subMerchantId,sub_merchant_name as subMerchantName
from dj_car_life_scene_merchant_ref_new
where main_merchant_id = #{shopMerchantId} and sub_merchant_id = #{refMerchantId} and sub_merchant_type = 7 and base_scene_code = #{baseSceneCode}
and deleted_flag = 'N' and status = 1
</select>
</mapper>
\ No newline at end of file
......@@ -152,4 +152,10 @@ public class MerchantStoreInfoRemoteTest extends BaseRemoteTest {
System.out.println("添加/更新失败: " + (response != null ? response.getMessage() : "response is null"));
}
}
@Test
public void getShopMerchantServiceRef() {
System.out.println(JSONObject.toJSONString(serviceMerchantRefRemote.getShopMerchantServiceRef(44217733,44209845,"100101").getResult()));
}
}
  • @wangxw1
    commented
    Master

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

    1. API 接口注解参数与实际方法签名不一致(功能实现与规范)

    • 问题描述:在 ServiceMerchantRefRemote.java 中,@ApiParams 注解定义了第三个参数为 sceneType(Integer 类型),但实际的方法签名中第三个参数是 baseSceneCode(String 类型)。
    • 影响分析:作为 Dubbo RPC 的提供者接口,如果上层网关(如 Swagger 自动生成、API 校验拦截器等)依赖这些注解进行参数校验或文档生成,会导致调用方看到错误的 API 文档,甚至在网关层因类型不匹配(String 传给 Integer)被直接拦截报错。
    • 优化建议:修正 @ApiParams 中的参数定义,使其与方法签名完全保持一致。 java // 修改前 @ApiParam(name="sceneType",notes="场景类型",dataType= ApiParam.DataTypeEnum.INTEGER,required=true) // 修改后 @ApiParam(name="baseSceneCode",notes="场景编码",dataType= ApiParam.DataTypeEnum.STRING,required=true)

    2. 存在性校验的 SQL 与代码实现存在性能浪费(性能与最佳实践)

    • 问题描述:在 ServiceMerchantRefService.java 中,为了判断门店关联服务商是否存在(返回 Boolean),调用了 Mapper 查询一个 List<SceneMerchantRefNew>,然后通过判断 List 是否为空来返回结果。
    • 影响分析:这是一个典型的反模式。如果满足条件的记录有多条,数据库会将所有记录查询出来并映射为 Java 对象放入内存,这不仅增加了数据库的 I/O 负担,也浪费了应用服务器的内存和 CPU 资源。存在性校验不需要获取具体数据。
    • 优化建议:修改 SQL,使用 LIMIT 1 或 COUNT(1),并在 Service 层简化布尔值的返回逻辑。 xml <!-- Mapper.xml 建议修改为查询数量或查 1 --> <select id="checkShopMerchantServiceRefExists" resultType="java.lang.Integer"> select 1 from dj_car_life_scene_merchant_ref_new where main_merchant_id = #{shopMerchantId} and sub_merchant_id = #{refMerchantId} and sub_merchant_type = 7 and base_scene_code = #{baseSceneCode} and deleted_flag = 'N' and status = 1 limit 1 </select> java // Service 层优化 public Boolean getShopMerchantServiceRef(Integer shopMerchantId, Integer refMerchantId, String baseSceneCode) { Integer exists = sceneMerchantRefNewMapper.checkShopMerchantServiceRefExists(shopMerchantId, refMerchantId, baseSceneCode); return exists != null; // 替代原来的 if-else 判断 }

    3. 异常捕获中的日志打印存在复制粘贴错误(可维护性)

    • 问题描述:在 ServiceMerchantRefRemoteImpl.java 的 getShopMerchantServiceRef 方法中,catch 块打印的错误日志是 log.error("enableSingleMerchantRef error", e);。
    • 影响分析:这是明显的 Copy-Paste 遗留问题。当生产环境发生异常时,日志会误导排查人员去检查 enableSingleMerchantRef 方法,从而增加故障定位的时间成本。
    • 优化建议:修正日志输出内容,使其与当前方法名匹配。 java // 修改前 log.error("enableSingleMerchantRef error", e); // 修改后 log.error("getShopMerchantServiceRef error", e);

    二、评分明细

    • 功能实现的正确性与健壮性(38/40分): 核心业务逻辑实现基本正确。严格遵守了“无子查询”和“不变更已有 Dubbo 接口参数”的规则。扣分点在于 API 注解与实际参数类型/名称不一致,可能引发网关层面的功能异常。

    • 安全性与潜在风险(30/30分): MyBatis 的 XML 中使用了 #{} 进行参数绑定,有效防止了 SQL 注入风险。未见明显的越权或敏感信息泄露问题,安全性良好。

    • 最佳实践与可维护性(16/20分): 扣分点主要在于:1. 日志信息的 Copy-Paste 错误误导排查;2. if (CollectionUtils.isEmpty(...)) return false; else return true; 这种写法过于冗余,应直接 return !CollectionUtils.isEmpty(...);;3. 方法名为 get... 但返回的是 Boolean,通常返回布尔值的方法建议以 is...、has... 或 check... 命名。

    • 性能与资源利用(3/5分): 使用 select *(或查询多个具体字段)映射成 List 仅仅是为了做存在性(Boolean)校验,造成了不必要的数据库和内存资源开销。

    • 提交信息质量(5/5分): Commit 信息(feat(merchant): 添加门店关联服务商查询功能)采用了标准的 Conventional Commits 格式,且主体部分清晰罗列了各层的具体修改内容,可追溯性极佳,满分。

    总分:92分

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