Commit c3d0afed by 叶立庆

Merge branch 'v5.8.6.2' into 'master'

上线合并

See merge request !55
2 parents e02d0eed 9d16db50
......@@ -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-SNAPSHOT</smartcarlife.api.version>
<smartcarlife.api.version>5.8.6.2-SNAPSHOT</smartcarlife.api.version>
<shopamll.api.version>5.6.4-SNAPSHOT</shopamll.api.version>
</properties>
<dependencies>
......
package cn.com.glsx.dj.smartcarlife.remote;
import cn.com.glsx.dj.smartcarlife.dto.merchant.MerchantDetailBatchQueryDTO;
import cn.com.glsx.dj.smartcarlife.dto.merchant.MerchantDetailQueryDTO;
import cn.com.glsx.dj.smartcarlife.dto.merchant.MerchantDetailResponseDTO;
import cn.com.glsx.dj.smartcarlife.dto.merchant.MerchantEditDTO;
import cn.com.glsx.dj.smartcarlife.model.SceneMerchantRefUpd;
import cn.com.glsx.framework.core.annotation.ApiMethod;
import cn.com.glsx.framework.core.annotation.ApiParam;
import cn.com.glsx.framework.core.annotation.ApiResponse;
import cn.com.glsx.framework.core.annotation.ApiService;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.merchants.model.request.MerchantRequest;
import javax.validation.constraints.NotNull;
import java.util.List;
/**
* 商户门店信息同步服务接口
*
* @author yelq
* @since 2026-09-24
*/
@ApiService(value = "商户门店信息同步服务接口", owner = "yelq", protocol = ApiService.ProtocolEnum.dubbo, version = "1.0.0")
public interface SyncMerchantInfoRemote {
/**
* 同步门店名称
*
*/
@ApiMethod("同步门店名称")
@ApiParam(name = "merchantRequest", notes = "更新参数", dataType = ApiParam.DataTypeEnum.OBJECT, required = true)
@ApiResponse("是否成功")
RpcResponse<Boolean> updateMerchantName(@NotNull MerchantRequest merchantRequest);
}
\ No newline at end of file
......@@ -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-SNAPSHOT</smartcarlife.api.version>
<smartcarlife.api.version>5.8.6.2-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>
......@@ -34,7 +34,7 @@
<dependency>
<groupId>cn.com.glsx.merchants</groupId>
<artifactId>platform-merchants-api</artifactId>
<version>5.8.0-SNAPSHOT</version>
<version>5.8.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>cn.com.glsx</groupId>
......
package cn.com.glsx.dj.smartcarlife.remote;
import cn.com.glsx.dj.smartcarlife.service.merchant.SyncMerchantInformationService;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.framework.core.enums.DefaultErrorEnum;
import cn.com.glsx.merchants.model.request.MerchantRequest;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
/**
* 商户门店信息同步服务接口
*/
@Slf4j
@DubboService(version = "1.0.0", validation = "true")
public class SyncMerchantInfoRemoteImpl implements SyncMerchantInfoRemote {
@Autowired
private SyncMerchantInformationService syncMerchantInformationService;
/**
* 同步门店名称
*
* @param merchantRequest
* @return
*/
@Override
public RpcResponse<Boolean> updateMerchantName(MerchantRequest merchantRequest) {
try {
Boolean b = syncMerchantInformationService.updateMerchantName(merchantRequest);
if (b) return RpcResponse.success(b);
return RpcResponse.error(DefaultErrorEnum.SERVICE_ERROR, "同步门店名称更新失败!");
} catch (Exception e) {
log.error(e.getMessage(),e);
return RpcResponse.error(DefaultErrorEnum.SERVICE_ERROR, "同步门店名称更新失败!");
}
}
}
package cn.com.glsx.dj.smartcarlife.service.merchant;
import cn.com.glsx.dj.smartcarlife.mapper.*;
import cn.com.glsx.dj.smartcarlife.model.*;
import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.com.glsx.merchants.model.request.MerchantRequest;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;
import java.util.Date;
/**
* 门店信息同步
*/
@Slf4j
@Service
@Transactional(propagation = Propagation.SUPPORTS, rollbackFor = RpcServiceException.class)
public class SyncMerchantInformationService {
@Autowired
private YqMerchantInfoMapper yqMerchantInfoMapper;
@Autowired
private ServiceMerchantMapper serviceMerchantMapper;
@Autowired
private SceneMerchantRefNewMapper sceneMerchantRefNewMapper;
@Autowired
private YqPartnerMerchantRefMapper yqPartnerMerchantRefMapper;
@Autowired
private YqMerchantConfigMapper yqMerchantConfigMapper;
@Autowired
private ServiceMerchantRefMapper serviceMerchantRefMapper;
@Autowired
private SceneMerchantRefMapper sceneMerchantRefMapper;
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = RpcServiceException.class)
public Boolean updateMerchantName(MerchantRequest merchantRequest) {
log.info("门店信息:{}", JSON.toJSONString(merchantRequest));
if (merchantRequest == null || merchantRequest.getMerchantNo() == null || merchantRequest.getMerchantName() == null) {
log.error("门店信息不全,无法更新!!");
return false;
}
try {
// 更新园区店名称
YqMerchantInfo updateYq = new YqMerchantInfo();
updateYq.setUpdatedDate(new Date());
updateYq.setUpdatedBy("system");
updateYq.setMerchantName(merchantRequest.getMerchantName());
Example exyq = new Example(YqMerchantInfo.class);
exyq.createCriteria().andEqualTo("merchantId", merchantRequest.getMerchantNo());
yqMerchantInfoMapper.updateByExampleSelective(updateYq, exyq);
// 更新服务门店名称
ServiceMerchant updateService = new ServiceMerchant();
updateService.setUpdatedDate(new Date());
updateService.setUpdatedBy("system");
updateService.setMerchantName(merchantRequest.getMerchantName());
Example exService = new Example(ServiceMerchant.class);
exService.createCriteria().andEqualTo("merchantId", merchantRequest.getMerchantNo());
serviceMerchantMapper.updateByExampleSelective(updateService, exService);
// 更新场景门店名称,主关联
SceneMerchantRefNew updateScene = new SceneMerchantRefNew();
updateScene.setUpdatedDate(new Date());
updateScene.setUpdatedBy("system");
updateScene.setMainMerchantName(merchantRequest.getMerchantName());
Example exScene = new Example(SceneMerchantRefNew.class);
exScene.createCriteria().andEqualTo("mainMerchantId", merchantRequest.getMerchantNo());
sceneMerchantRefNewMapper.updateByExampleSelective(updateScene, exScene);
// 更新场景门店名称,子关联
SceneMerchantRefNew updateScene1 = new SceneMerchantRefNew();
updateScene1.setUpdatedDate(new Date());
updateScene1.setUpdatedBy("system");
updateScene1.setSubMerchantName(merchantRequest.getMerchantName());
Example exScene1 = new Example(SceneMerchantRefNew.class);
exScene1.createCriteria().andEqualTo("subMerchantId", merchantRequest.getMerchantNo());
sceneMerchantRefNewMapper.updateByExampleSelective(updateScene1, exScene1);
// 更新园区店合作商户关联表名称,合作方商户
YqPartnerMerchantRef updatePartner = new YqPartnerMerchantRef();
updatePartner.setUpdatedDate(new Date());
updatePartner.setUpdatedBy("system");
updatePartner.setPartnerMerchantName(merchantRequest.getMerchantName());
Example exPartner = new Example(YqPartnerMerchantRef.class);
exPartner.createCriteria().andEqualTo("partnerMerchantId", merchantRequest.getMerchantNo());
yqPartnerMerchantRefMapper.updateByExampleSelective(updatePartner, exPartner);
// 更新园区店合作商户关联表名称,园区店商户
YqPartnerMerchantRef updateYqRef = new YqPartnerMerchantRef();
updateYqRef.setUpdatedDate(new Date());
updateYqRef.setUpdatedBy("system");
updateYqRef.setYqMerchantName(merchantRequest.getMerchantName());
Example exYqRef = new Example(YqPartnerMerchantRef.class);
exYqRef.createCriteria().andEqualTo("yqMerchantId", merchantRequest.getMerchantNo());
yqPartnerMerchantRefMapper.updateByExampleSelective(updateYqRef, exYqRef);
// 更新园区店配置表名称
YqMerchantConfig updateConfig = new YqMerchantConfig();
updateConfig.setUpdatedDate(new Date());
updateConfig.setUpdatedBy("system");
updateConfig.setPartnerMerchantName(merchantRequest.getMerchantName());
Example exConfig = new Example(YqMerchantConfig.class);
exConfig.createCriteria().andEqualTo("partnerMerchantId", merchantRequest.getMerchantNo());
yqMerchantConfigMapper.updateByExampleSelective(updateConfig, exConfig);
// 更新服务门店关联表名称,园区店商户
ServiceMerchantRef updateServiceRefYq = new ServiceMerchantRef();
updateServiceRefYq.setUpdatedDate(new Date());
updateServiceRefYq.setUpdatedBy("system");
updateServiceRefYq.setYqMerchantName(merchantRequest.getMerchantName());
Example exServiceRefYq = new Example(ServiceMerchantRef.class);
exServiceRefYq.createCriteria().andEqualTo("yqMerchantId", merchantRequest.getMerchantNo());
serviceMerchantRefMapper.updateByExampleSelective(updateServiceRefYq, exServiceRefYq);
// 更新服务门店关联表名称,服务门店商户
ServiceMerchantRef updateServiceRef = new ServiceMerchantRef();
updateServiceRef.setUpdatedDate(new Date());
updateServiceRef.setUpdatedBy("system");
updateServiceRef.setMerchantName(merchantRequest.getMerchantName());
Example exServiceRef = new Example(ServiceMerchantRef.class);
exServiceRef.createCriteria().andEqualTo("merchantId", merchantRequest.getMerchantNo());
serviceMerchantRefMapper.updateByExampleSelective(updateServiceRef, exServiceRef);
// 更新旧门店关联表门店名称
SceneMerchantRef sceneMerchantRef = new SceneMerchantRef();
sceneMerchantRef.setUpdatedDate(new Date());
sceneMerchantRef.setUpdatedBy("system");
sceneMerchantRef.setMainMerchantName(merchantRequest.getMerchantName());
Example exSceneMerchantRef = new Example(SceneMerchantRef.class);
exSceneMerchantRef.createCriteria().andEqualTo("mainMerchantId", merchantRequest.getMerchantNo());
sceneMerchantRefMapper.updateByExampleSelective(sceneMerchantRef, exSceneMerchantRef);
SceneMerchantRef sceneMerchantRef1 = new SceneMerchantRef();
sceneMerchantRef1.setUpdatedDate(new Date());
sceneMerchantRef1.setUpdatedBy("system");
sceneMerchantRef1.setSubMerchantName(merchantRequest.getMerchantName());
Example exSceneMerchantRef1 = new Example(SceneMerchantRef.class);
exSceneMerchantRef1.createCriteria().andEqualTo("subMerchantId", merchantRequest.getMerchantNo());
sceneMerchantRefMapper.updateByExampleSelective(sceneMerchantRef1, exSceneMerchantRef1);
return true;
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new RpcServiceException(e.getMessage());
}
}
}
  • @wangxw1
    commented
    Master

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

    1. 异常处理不当,丢失原始异常堆栈(重要性:高)

    • 问题描述:在 SyncMerchantInformationService.java 的 updateMerchantName 方法中,捕获了 Exception e 后,抛出异常的代码为 throw new RpcServiceException(e.getMessage());。
    • 影响分析:如果发生 NullPointerException 等运行时异常,e.getMessage() 的值为 null。这不仅会导致抛出的自定义异常缺乏描述信息,更严重的是丢失了原始异常的堆栈信息(Cause),这会让后续的线上排障变得极其困难。
    • 优化建议:在抛出自定义异常时,应将原始异常对象作为参数传入,保留完整的异常链。 java // 修改前 throw new RpcServiceException(e.getMessage()); // 修改后 throw new RpcServiceException("同步门店名称失败", e);

    2. 包装类型自动拆箱存在 NPE 风险及日志记录不规范(重要性:中)

    • 问题描述:在 SyncMerchantInfoRemoteImpl.java 中,使用了 Boolean b = syncMerchantInformationService...; if (b) { ... }。同时,日志记录使用了 log.error(e.getMessage(), e);。
    • 影响分析:
      1. 虽然当前 Service 层逻辑只返回 true 或 false,但作为包装类 Boolean,其值可能为 null。如果在后续维护中 Service 层返回了 null,if (b) 会触发自动拆箱导致 NullPointerException。
      2. log.error(e.getMessage(), e); 同样存在当 e.getMessage() 为空时(如 NPE),导致日志输出不友好的问题。通常第一个参数应为明确的错误描述常量字符串。
    • 优化建议: ```java // 建议修改如下: Boolean b = syncMerchantInformationService.updateMerchantName(merchantRequest); if (Boolean.TRUE.equals(b)) { return RpcResponse.success(b); } return RpcResponse.error(DefaultErrorEnum.SERVICE_ERROR, "同步门店名称更新失败!");

    // 日志修改: } catch (Exception e) { log.error("同步门店名称发生异常, request: {}", JSON.toJSONString(merchantRequest), e); return RpcResponse.error(DefaultErrorEnum.SERVICE_ERROR, "同步门店名称更新失败!"); }

    
    **3. 严重的“复制-粘贴”式代码冗余(重要性:中)**
    - **问题描述**:在 `SyncMerchantInformationService.java` 中,为了更新 10 张不同的表,连续编写了 10 段结构完全相同的代码(实例化对象 -> 设置时间/操作人 -> 设置名称 -> 构造 Example -> 执行更新)。
    - **影响分析**:大量的重复代码极大地降低了代码的可维护性。从提交历史 `“修复Example 对象实例化时传入了错误的实体类(复制粘贴导致的 Bug)”` 可以看出,这种写法已经导致了人为错误。此外,在一个事务中连续对 10 张表进行更新,如果表数据量大且并发高,容易导致数据库长事务和锁竞争。
    - **优化建议**:受限于 `tk.mybatis` 不同 Mapper 的类型差异,完全抽象可能需要一定的泛型设计。但至少在当前情况下,建议对代码进行仔细的 Code Review,确保每一个 `Example` 的泛型类型与 `Mapper` 严格对应。长远来看,建议审视数据库设计,核心字段 `merchantName` 冗余在 10 张表中违背了数据库范式,是导致此处代码臃肿的根源,建议引入领域事件(如 MQ)进行异步解耦同步,避免大事务。
    
    ---
    
    #### 二、评分明细
    
    - **功能实现的正确性与健壮性(32/40分)**
      - **理由**:核心业务逻辑基本正确,未发现违反“禁用子查询”和“修改已有入参”的红线规则(本次为新增接口)。但异常处理丢失堆栈、自动拆箱潜在 NPE 等问题降低了代码的健壮性。
    - **安全性与潜在风险(30/30分)**
      - **理由**:使用了 `tk.mybatis` 的 `Example` 进行参数化查询和更新,有效防止了 SQL 注入;无明显的越权和敏感信息泄露风险。
    - **最佳实践与可维护性(10/20分)**
      - **理由**:Service 层存在极其严重的面向过程的“复制-粘贴”代码,导致方法体过长,且已经引发过 Bug,不符合 DRY(Don't Repeat Yourself)原则。
    - **性能与资源利用(3/5分)**
      - **理由**:单线程同步在一个数据库事务中连续更新 10 张表,属于典型的长事务操作,在并发场景下可能造成数据库连接占用过长和锁竞争。
    - **提交信息质量(4/5分)**
      - **理由**:Commit 信息真实反映了开发过程(包括修复复制粘贴引发的 Bug),具备可追溯性,但夹杂了较多 Merge Conflict 的自动生成信息,略显杂乱。
    
    总分:79分
    
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!