Commit 242c0e68 by 周立明

修改园区店主服务

1 parent 9163a763
......@@ -12,7 +12,7 @@
<name>rpc-dj-smartcarlife-api</name>
<properties>
<deploy.scanPackage>cn.com.glsx.dj.smartcarlife.remote</deploy.scanPackage>
<smartcarlife.api.version>5.8.6.2-SNAPSHOT</smartcarlife.api.version>
<smartcarlife.api.version>5.8.7-SNAPSHOT</smartcarlife.api.version>
<shopamll.api.version>5.6.4-SNAPSHOT</shopamll.api.version>
</properties>
<dependencies>
......
......@@ -54,6 +54,11 @@ public interface YqMerchantConfigRemote {
@ApiResponse("更新后的园区店配置项")
RpcResponse<YqMerchantConfigDTO> updateByMerchantId(@NotNull YqMerchantConfigDTO yqMerchantConfigDTO);
@ApiMethod("更新园区店主服务商")
@ApiParam(name = "yqMerchantConfigDTO", notes = "园区店merchantId(定位条件) + partnerMerchantId/partnerMerchantName(参数传入) + 操作人updatedBy", dataType = ApiParam.DataTypeEnum.OBJECT, required = true)
@ApiResponse("更新结果")
RpcResponse<Boolean> updatePartnerMerchant(@NotNull YqMerchantConfigDTO yqMerchantConfigDTO);
@ApiMethod("获取某园区店的园区店配置项")
@ApiParam(name = "merchantId", notes = "园区店商户号", dataType = ApiParam.DataTypeEnum.OBJECT, required = true)
@ApiResponse("园区店配置项")
......
......@@ -16,7 +16,7 @@
<skipTests>true</skipTests>
<shopmall.api.version>5.8.2-SNAPSHOT</shopmall.api.version>
<stoassistant.api.version>5.6.4-SNAPSHOT</stoassistant.api.version>
<smartcarlife.api.version>5.8.6.2-SNAPSHOT</smartcarlife.api.version>
<smartcarlife.api.version>5.8.7-SNAPSHOT</smartcarlife.api.version>
<sale.api.version>5.8.4-SNAPSHOT</sale.api.version>
<mindworkplate.api.version>5.8.3-SNAPSHOT</mindworkplate.api.version>
</properties>
......
......@@ -85,6 +85,16 @@ public class YqMerchantConfigRemoteImpl implements YqMerchantConfigRemote{
}
@Override
public RpcResponse<Boolean> updatePartnerMerchant(@NotNull YqMerchantConfigDTO yqMerchantConfigDTO) {
try{
return RpcResponse.success(yqMerchantConfigService.updatePartnerMerchant(yqMerchantConfigDTO));
}catch(RpcServiceException e){
log.error(e.getMessage(),e);
return RpcResponse.error(e);
}
}
@Override
public RpcResponse<YqMerchantConfigDTO> getByMerchantId(Integer merchantId) {
try{
return RpcResponse.success(yqMerchantConfigService.getByMerchantId(merchantId));
......
......@@ -214,6 +214,41 @@ public class YqMerchantConfigService {
}
}
/**
* 更新园区店主服务商为深圳优加
* 入参 YqMerchantConfigDTO:
* merchantId 园区店商户号(定位条件,根据园区店商户条件更新)
* partnerMerchantId 深圳优加服务商商户号(主服务商商户ID,通过参数传入)
* partnerMerchantName 深圳优加服务商名称(主服务商名称,通过参数传入)
* updatedBy 操作人
* 仅更新主服务商两字段(partner_merchant_id / partner_merchant_name)+ 修改人/时间。
*/
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = RpcServiceException.class)
public Boolean updatePartnerMerchant(YqMerchantConfigDTO yqMerchantConfigDTO){
RpcAssert.assertNotNull(yqMerchantConfigDTO.getMerchantId(), DefaultErrorEnum.DATA_NULL, "merchantId(园区店) not be null");
RpcAssert.assertNotNull(yqMerchantConfigDTO.getPartnerMerchantId(), DefaultErrorEnum.DATA_NULL, "partnerMerchantId(深圳优加商户号) not be null");
RpcAssert.assertNotEmpty(yqMerchantConfigDTO.getPartnerMerchantName(), DefaultErrorEnum.DATA_NULL, "partnerMerchantName(深圳优加名称) not be empty");
RpcAssert.assertNotEmpty(yqMerchantConfigDTO.getUpdatedBy(), DefaultErrorEnum.DATA_NULL, "updatedBy not be empty");
try {
List<YqMerchantConfig> configs = yqMerchantConfigMapper.listByMerchantId(yqMerchantConfigDTO.getMerchantId());
if (CollectionUtils.isEmpty(configs)) {
throw new RpcServiceException("未关联4S店,请确认后重新操作");
}
YqMerchantConfig config = configs.get(0);
config.setPartnerMerchantId(yqMerchantConfigDTO.getPartnerMerchantId());
config.setPartnerMerchantName(yqMerchantConfigDTO.getPartnerMerchantName());
config.setUpdatedBy(yqMerchantConfigDTO.getUpdatedBy());
config.setUpdatedDate(new Date());
return yqMerchantConfigMapper.updateByPrimaryKeySelective(config) > 0;
} 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());
}
}
public Page<YqMerchantConfigDTO> page(RpcPagination<YqMerchantConfigDTO> pagination){
try{
Page<YqMerchantConfigDTO> page = PageHelper.startPage(pagination.getPageNum(), pagination.getPageSize(),pagination.isNeedCount());
......
  • @wangxw1
    commented
    Master

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

    1. 数据库操作存在“先查后改”的反模式(性能与并发风险)

    • 问题描述:在 YqMerchantConfigService.updatePartnerMerchant 方法中,代码先通过 listByMerchantId 查询出列表,取第 0 个元素在内存中修改后,再通过 updateByPrimaryKeySelective 进行更新。
    • 影响分析:
      1. 性能损耗:增加了一次不必要的 SELECT 数据库网络请求。
      2. 并发风险:在并发场景下,SELECT 和 UPDATE 之间存在时间差,如果其他线程在此期间修改了该记录,由于使用的是基于主键的更新,可能会导致“丢失更新”问题。
      3. 逻辑隐患:listByMerchantId 返回的是 List,但代码仅处理了 get(0),如果一个商户号对应多条配置,其他配置将被遗漏。
    • 优化建议:建议在 Mapper 层新增/复用一个基于 merchant_id 的直接更新方法,实现一次网络交互完成更新。 ```java // 建议的优化代码示例 YqMerchantConfig updateParam = new YqMerchantConfig(); updateParam.setMerchantId(yqMerchantConfigDTO.getMerchantId()); updateParam.setPartnerMerchantId(yqMerchantConfigDTO.getPartnerMerchantId()); updateParam.setPartnerMerchantName(yqMerchantConfigDTO.getPartnerMerchantName()); updateParam.setUpdatedBy(yqMerchantConfigDTO.getUpdatedBy()); updateParam.setUpdatedDate(new Date());

    // 直接通过 merchantId 更新,并在 Mapper 中处理 affected rows == 0 的异常情况 int rows = yqMerchantConfigMapper.updateByMerchantIdSelective(updateParam); if (rows == 0) { throw new RpcServiceException("未关联园区店,请确认后重新操作"); } return true;

    
    **2. 异常处理存在重复打印日志(工程最佳实践)**
    - **问题描述**:在 `YqMerchantConfigService` 中,`catch (RpcServiceException e)` 捕获异常后执行了 `log.error(e.getMessage(), e);` 并将异常继续抛出。而在外层的 `YqMerchantConfigRemoteImpl` 中,又一次 `catch (RpcServiceException e)` 并执行了相同的 `log.error(e.getMessage(), e);`。
    - **影响分析**:典型的日志重复打印(Log Pollution)反模式。同一个异常堆栈会被打印两次,不仅浪费磁盘空间,还会增加线上排查问题时阅读日志的干扰。
    - **优化建议**:Service 层若仅做异常透传(抛出),则无需打印 Error 日志,将日志记录职责统一收口到 Facade/Remote 接口层即可。
      ```java
      // Service 层只需这样处理(或者干脆不 catch RpcServiceException,让它自然抛出)
      } catch (RpcServiceException e) {
          throw e; // 移除 log.error
      } catch (Exception e) {
          log.error("更新园区店主服务商异常: {}", e.getMessage(), e);
          throw new RpcServiceException(DefaultErrorEnum.SERVICE_ERROR, e.getMessage());
      }
    

    3. 业务提示语与领域模型不匹配(功能正确性)

    • 问题描述:接口和注释均明确标明该方法用于“园区店”(YqMerchantConfig),但在业务校验失败时,抛出的异常提示语却是 "未关联4S店,请确认后重新操作"。
    • 影响分析:异常提示语硬编码且文案错误,抛出到前端后会导致前端用户或联调人员产生疑惑(当前操作的是园区店,却提示4S店未关联),降低系统的专业度。
    • 优化建议:将提示文案修正为与当前业务领域一致的描述。 java // 修正前 throw new RpcServiceException("未关联4S店,请确认后重新操作"); // 修正后 throw new RpcServiceException("未关联园区店,请确认后重新操作");

    二、评分明细

    • 功能实现的正确性与健壮性(36 / 40分) 理由:核心业务逻辑基本实现,Dubbo 接口新增方法符合安全规范(未破坏原有入参)。扣分点在于业务提示文案错误(4S店 vs 园区店),以及基于 List 的 get(0) 更新逻辑在数据不严谨时可能存在隐患。
    • 安全性与潜在风险(30 / 30分) 理由:代码中使用了标准的防御性编程(RpcAssert.assertNotNull),有效拦截了非法空参,未发现越权、SQL注入等明显安全漏洞。
    • 最佳实践与可维护性(15 / 20分) 理由:代码结构清晰,使用了 @Transactional。扣分点在于异常捕获后重复打印日志的反模式,增加了日志维护成本。
    • 性能与资源利用(3 / 5分) 理由:使用了“先查后改”的模式,多了一次不必要的数据库查询开销,未做到最优的资源利用。
    • 提交信息质量(3 / 5分) 理由:Commit 信息 修改园区店主服务 (by zhoulm) 过于简略,仅说明了做了什么,但缺乏业务背景(如需求号、为什么修改),可追溯性一般。

    总分:87分

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