Commit 17906df9 by 杨卫

feat(smartcarlife): 添加园区店主服务商更新功能

- 新增 YqMerchantConfigUpdatePartnerMerchantRequest 请求类
- 新增 YqMerchantConfigUpdatePartnerMerchantReqDTO 数据传输对象
- 在 YqMerchantConfigController 中添加 updatePartnerMerchant 接口
- 在 YqMerchantConfigRemote 和 YqMerchantConfigRemoteImpl 中添加远程调用支持
- 在 YqMerchantConfigService 中实现更新逻辑,增加场景代码验证
- 在 SceneMerchantRefNewMapper 中新增按场景查询园区店的方法
- 更新接口文档注释和错误处理机制
- 修改 pom.xml 版本号从 5.8.6 到 5.8.7
1 parent 242c0e68
package cn.com.glsx.dj.smartcarlife.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
/**
* 更新园区店主服务商请求
*
* @author yangwei_by_claude
* @version 1.0
* @since 2026/10/08 16:00
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class YqMerchantConfigUpdatePartnerMerchantReqDTO implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 4S店商户号
*/
@ApiModelProperty(value = "4S店商户号", required = true)
@NotNull(message = "4S店商户号不能为空")
private Integer merchantId;
/**
* 主服务商商户id
*/
@ApiModelProperty(value = "主服务商商户id", required = true)
@NotNull(message = "主服务商商户id不能为空")
private Integer partnerMerchantId;
/**
* 主服务商商户名称
*/
@ApiModelProperty(value = "主服务商商户名称", required = true)
@NotBlank(message = "主服务商商户名称不能为空")
private String partnerMerchantName;
/**
* 修改人
*/
@ApiModelProperty(value = "修改人", required = true)
@NotBlank(message = "修改人不能为空")
private String updatedBy;
/**
* 场景代码
*/
@ApiModelProperty(value = "场景代码", required = true)
@NotBlank(message = "场景代码不能为空")
private String baseSceneCode;
}
...@@ -55,9 +55,9 @@ public interface YqMerchantConfigRemote { ...@@ -55,9 +55,9 @@ public interface YqMerchantConfigRemote {
RpcResponse<YqMerchantConfigDTO> updateByMerchantId(@NotNull YqMerchantConfigDTO yqMerchantConfigDTO); RpcResponse<YqMerchantConfigDTO> updateByMerchantId(@NotNull YqMerchantConfigDTO yqMerchantConfigDTO);
@ApiMethod("更新园区店主服务商") @ApiMethod("更新园区店主服务商")
@ApiParam(name = "yqMerchantConfigDTO", notes = "园区店merchantId(定位条件) + partnerMerchantId/partnerMerchantName(参数传入) + 操作人updatedBy", dataType = ApiParam.DataTypeEnum.OBJECT, required = true) @ApiParam(name = "request", notes = "4S店merchantId、主服务商信息、场景代码和操作人", dataType = ApiParam.DataTypeEnum.OBJECT, required = true)
@ApiResponse("更新结果") @ApiResponse("更新结果")
RpcResponse<Boolean> updatePartnerMerchant(@NotNull YqMerchantConfigDTO yqMerchantConfigDTO); RpcResponse<Boolean> updatePartnerMerchant(@NotNull YqMerchantConfigUpdatePartnerMerchantReqDTO request);
@ApiMethod("获取某园区店的园区店配置项") @ApiMethod("获取某园区店的园区店配置项")
@ApiParam(name = "merchantId", notes = "园区店商户号", dataType = ApiParam.DataTypeEnum.OBJECT, required = true) @ApiParam(name = "merchantId", notes = "园区店商户号", dataType = ApiParam.DataTypeEnum.OBJECT, required = true)
......
...@@ -37,7 +37,16 @@ public interface SceneMerchantRefNewMapper extends OreMapper<SceneMerchantRefNew ...@@ -37,7 +37,16 @@ public interface SceneMerchantRefNewMapper extends OreMapper<SceneMerchantRefNew
*/ */
List<SceneMerchantRefNew> findYqMerchantByShopSceneAndBaseSceneCode(@Param("mainMerchantId") Integer mainMerchantId, @Param("scene") Integer scene, @Param("baseSceneCode") String baseSceneCode); List<SceneMerchantRefNew> findYqMerchantByShopSceneAndBaseSceneCode(@Param("mainMerchantId") Integer mainMerchantId, @Param("scene") Integer scene, @Param("baseSceneCode") String baseSceneCode);
List<SceneMerchantRefNew> findByMerchantId(@Param("mainMerchantId") Integer merchantId); /**
* 根据4S店商户号和场景编码查询园区店关联关系。
*
* @param mainMerchantId 4S店商户号
* @param baseSceneCode 场景编码
* @return 园区店关联关系
*/
List<SceneMerchantRefNew> findYqMerchantByMainMerchantIdAndBaseSceneCode(
@Param("mainMerchantId") Integer mainMerchantId,
@Param("baseSceneCode") String baseSceneCode);
void deleteByMerchantIdSceneAndBaseSceneCode(@Param("mainMerchantId") Integer merchantId, @Param("scene") Integer scene,@Param("baseSceneCode") String baseSceneCode); void deleteByMerchantIdSceneAndBaseSceneCode(@Param("mainMerchantId") Integer merchantId, @Param("scene") Integer scene,@Param("baseSceneCode") String baseSceneCode);
......
...@@ -85,11 +85,14 @@ public class YqMerchantConfigRemoteImpl implements YqMerchantConfigRemote{ ...@@ -85,11 +85,14 @@ public class YqMerchantConfigRemoteImpl implements YqMerchantConfigRemote{
} }
@Override @Override
public RpcResponse<Boolean> updatePartnerMerchant(@NotNull YqMerchantConfigDTO yqMerchantConfigDTO) { public RpcResponse<Boolean> updatePartnerMerchant(@NotNull YqMerchantConfigUpdatePartnerMerchantReqDTO request) {
try{ try {
return RpcResponse.success(yqMerchantConfigService.updatePartnerMerchant(yqMerchantConfigDTO)); return RpcResponse.success(yqMerchantConfigService.updatePartnerMerchant(request));
}catch(RpcServiceException e){ } catch (RpcServiceException e) {
log.error(e.getMessage(),e); log.error("更新园区店主服务商发生RpcServiceException异常", e);
return RpcResponse.error(e);
} catch (Exception e) {
log.error("更新园区店主服务商发生系统异常", e);
return RpcResponse.error(e); return RpcResponse.error(e);
} }
} }
......
package cn.com.glsx.dj.smartcarlife.service; package cn.com.glsx.dj.smartcarlife.service;
import java.util.*;
import java.util.stream.Collectors;
import cn.com.glsx.dj.smartcarlife.config.PaymentConfig; import cn.com.glsx.dj.smartcarlife.config.PaymentConfig;
import cn.com.glsx.dj.smartcarlife.dto.*; import cn.com.glsx.dj.smartcarlife.dto.*;
import cn.com.glsx.dj.smartcarlife.enums.CarLifeEnum;
import cn.com.glsx.dj.smartcarlife.enums.SceneTypeEnum; import cn.com.glsx.dj.smartcarlife.enums.SceneTypeEnum;
import cn.com.glsx.dj.smartcarlife.enums.VinFlagEnum; import cn.com.glsx.dj.smartcarlife.enums.VinFlagEnum;
import cn.com.glsx.dj.smartcarlife.mapper.*; import cn.com.glsx.dj.smartcarlife.mapper.*;
import cn.com.glsx.dj.smartcarlife.model.*; import cn.com.glsx.dj.smartcarlife.model.*;
import cn.com.glsx.dj.smartcarlife.util.CommonUtil; import cn.com.glsx.dj.smartcarlife.util.CommonUtil;
import cn.com.glsx.framework.core.beans.BaseModel;
import cn.com.glsx.framework.core.beans.rpc.RpcPagination;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse; import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.merchants.model.request.MerchantRequest; import cn.com.glsx.framework.core.enums.DefaultErrorEnum;
import cn.com.glsx.framework.core.enums.StatusEnum;
import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.com.glsx.framework.core.util.RpcAssert;
import cn.com.glsx.merchants.model.request.MerchantStaffRequest; import cn.com.glsx.merchants.model.request.MerchantStaffRequest;
import cn.com.glsx.merchants.model.response.MerchantResponse;
import cn.com.glsx.merchants.model.response.MerchantStaffResponse; import cn.com.glsx.merchants.model.response.MerchantStaffResponse;
import cn.com.glsx.merchants.remote.MerchantStaffRemote; import cn.com.glsx.merchants.remote.MerchantStaffRemote;
import cn.com.glsx.scrm.proxy.dto.merchant.ListMerchantRequest; import cn.com.glsx.scrm.proxy.dto.merchant.ListMerchantRequest;
import cn.com.glsx.scrm.proxy.enums.AccountTypeEnum;
import cn.com.glsx.scrm.proxy.model.merchant.MerchantRopResponse; import cn.com.glsx.scrm.proxy.model.merchant.MerchantRopResponse;
import cn.com.glsx.scrm.proxy.remote.merchant.MerchantRemote;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.nacos.common.utils.CollectionUtils;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -26,22 +34,10 @@ import org.springframework.core.env.Environment; ...@@ -26,22 +34,10 @@ import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import com.alibaba.nacos.common.utils.CollectionUtils;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import cn.com.glsx.dj.smartcarlife.enums.CarLifeEnum;
import cn.com.glsx.framework.core.beans.BaseModel;
import cn.com.glsx.framework.core.beans.rpc.RpcPagination;
import cn.com.glsx.framework.core.enums.DefaultErrorEnum;
import cn.com.glsx.framework.core.enums.StatusEnum;
import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.com.glsx.framework.core.util.RpcAssert;
import cn.com.glsx.scrm.proxy.enums.AccountTypeEnum;
import lombok.extern.slf4j.Slf4j;
import tk.mybatis.mapper.entity.Example; import tk.mybatis.mapper.entity.Example;
import cn.com.glsx.scrm.proxy.remote.merchant.MerchantRemote;
import java.util.*;
import java.util.stream.Collectors;
@Slf4j @Slf4j
@Service @Service
...@@ -58,7 +54,7 @@ public class YqMerchantConfigService { ...@@ -58,7 +54,7 @@ public class YqMerchantConfigService {
private AuditYqServiceShopService auditYqServiceShopService; private AuditYqServiceShopService auditYqServiceShopService;
@Autowired @Autowired
private SceneMerchantRefMapper sceneMerchantRefMapper; private SceneMerchantRefNewMapper sceneMerchantRefNewMapper;
@Autowired @Autowired
private YqMerchantOpenSceneInfoMapper yqMerchantOpenSceneInfoMapper; private YqMerchantOpenSceneInfoMapper yqMerchantOpenSceneInfoMapper;
...@@ -224,29 +220,30 @@ public class YqMerchantConfigService { ...@@ -224,29 +220,30 @@ public class YqMerchantConfigService {
* 仅更新主服务商两字段(partner_merchant_id / partner_merchant_name)+ 修改人/时间。 * 仅更新主服务商两字段(partner_merchant_id / partner_merchant_name)+ 修改人/时间。
*/ */
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = RpcServiceException.class) @Transactional(propagation = Propagation.REQUIRED, rollbackFor = RpcServiceException.class)
public Boolean updatePartnerMerchant(YqMerchantConfigDTO yqMerchantConfigDTO){ public Boolean updatePartnerMerchant(YqMerchantConfigUpdatePartnerMerchantReqDTO request){
RpcAssert.assertNotNull(yqMerchantConfigDTO.getMerchantId(), DefaultErrorEnum.DATA_NULL, "merchantId(园区店) not be null"); RpcAssert.assertNotNull(request, DefaultErrorEnum.DATA_NULL, "request not be null");
RpcAssert.assertNotNull(yqMerchantConfigDTO.getPartnerMerchantId(), DefaultErrorEnum.DATA_NULL, "partnerMerchantId(深圳优加商户号) not be null"); RpcAssert.assertNotNull(request.getMerchantId(), DefaultErrorEnum.DATA_NULL, "merchantId(4S店) not be null");
RpcAssert.assertNotEmpty(yqMerchantConfigDTO.getPartnerMerchantName(), DefaultErrorEnum.DATA_NULL, "partnerMerchantName(深圳优加名称) not be empty"); RpcAssert.assertNotNull(request.getPartnerMerchantId(), DefaultErrorEnum.DATA_NULL, "partnerMerchantId not be null");
RpcAssert.assertNotEmpty(yqMerchantConfigDTO.getUpdatedBy(), DefaultErrorEnum.DATA_NULL, "updatedBy not be empty"); RpcAssert.assertNotEmpty(request.getPartnerMerchantName(), DefaultErrorEnum.DATA_NULL, "partnerMerchantName not be empty");
try { RpcAssert.assertNotEmpty(request.getUpdatedBy(), DefaultErrorEnum.DATA_NULL, "updatedBy not be empty");
List<YqMerchantConfig> configs = yqMerchantConfigMapper.listByMerchantId(yqMerchantConfigDTO.getMerchantId()); RpcAssert.assertNotEmpty(request.getBaseSceneCode(), DefaultErrorEnum.DATA_NULL, "baseSceneCode not be empty");
if (CollectionUtils.isEmpty(configs)) {
throw new RpcServiceException("未关联4S店,请确认后重新操作"); List<SceneMerchantRefNew> refs = sceneMerchantRefNewMapper
} .findYqMerchantByMainMerchantIdAndBaseSceneCode(request.getMerchantId(), request.getBaseSceneCode());
YqMerchantConfig config = configs.get(0); if (CollectionUtils.isEmpty(refs)) {
config.setPartnerMerchantId(yqMerchantConfigDTO.getPartnerMerchantId()); throw new RpcServiceException("未关联指定场景园区店,请确认后重新操作");
config.setPartnerMerchantName(yqMerchantConfigDTO.getPartnerMerchantName()); }
config.setUpdatedBy(yqMerchantConfigDTO.getUpdatedBy()); Integer yqMerchantId = refs.get(0).getSubMerchantId();
config.setUpdatedDate(new Date()); List<YqMerchantConfig> configs = yqMerchantConfigMapper.listByMerchantId(yqMerchantId);
return yqMerchantConfigMapper.updateByPrimaryKeySelective(config) > 0; if (CollectionUtils.isEmpty(configs)) {
} catch (RpcServiceException e) { throw new RpcServiceException("未查询到园区店配置信息,请确认后重新操作");
log.error(e.getMessage(), e); }
throw e; YqMerchantConfig config = configs.get(0);
} catch (Exception e) { config.setPartnerMerchantId(request.getPartnerMerchantId());
log.error(e.getMessage(), e); config.setPartnerMerchantName(request.getPartnerMerchantName());
throw new RpcServiceException(DefaultErrorEnum.SERVICE_ERROR, e.getMessage()); config.setUpdatedBy(request.getUpdatedBy());
} config.setUpdatedDate(new Date());
return yqMerchantConfigMapper.updateByPrimaryKeySelective(config) > 0;
} }
public Page<YqMerchantConfigDTO> page(RpcPagination<YqMerchantConfigDTO> pagination){ public Page<YqMerchantConfigDTO> page(RpcPagination<YqMerchantConfigDTO> pagination){
......
...@@ -68,8 +68,20 @@ ...@@ -68,8 +68,20 @@
and base_scene_code = #{baseSceneCode} and base_scene_code = #{baseSceneCode}
and sub_merchant_type = 6 and sub_merchant_type = 6
</select> </select>
<select id="findByMerchantId" <select id="findYqMerchantByMainMerchantIdAndBaseSceneCode" resultMap="BaseResultMap">
resultMap="BaseResultMap"> select
id, main_merchant_id, main_merchant_name, sub_merchant_id, sub_merchant_name, scene,
base_scene_code, main_merchant_type, sub_merchant_type, status, created_by, created_date, updated_by, updated_date,
deleted_flag
from dj_car_life_scene_merchant_ref_new
where main_merchant_id = #{mainMerchantId}
and main_merchant_type = 2
and sub_merchant_type = 6
and deleted_flag = 'N'
and base_scene_code = #{baseSceneCode}
order by id
</select>
select select
id, main_merchant_id, main_merchant_name, sub_merchant_id, sub_merchant_name, scene, id, main_merchant_id, main_merchant_name, sub_merchant_id, sub_merchant_name, scene,
base_scene_code, main_merchant_type, sub_merchant_type, status, created_by, created_date, updated_by, updated_date, base_scene_code, main_merchant_type, sub_merchant_type, status, created_by, created_date, updated_by, updated_date,
......
  • @wangxw1
    commented
    Master

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

    1. 严重问题:MyBatis XML 文件存在语法错误,将导致应用启动失败

    • 问题描述:在 SceneMerchantRefNewMapper.xml 的修改中,开发者删除了原有的 <select id="findByMerchantId"> 标签头,并新增了 findYqMerchantByMainMerchantIdAndBaseSceneCode 的完整标签块。但是,原 findByMerchantId 内部的 SQL 语句(select id, main_merchant_id...)并未被删除,直接裸露在 XML 结构中(没有被任何 XML 标签包裹)。
    • 影响分析:这是致命的语法错误。MyBatis 在初始化解析 XML 文件时会抛出 XML 解析异常(SAXParseException),直接导致应用启动失败或对应的 Mapper 无法加载。
    • 优化建议:清理 XML 文件中残留的无用 SQL 代码段。 xml <!-- 删除以下残留代码 --> select id, main_merchant_id, main_merchant_name, sub_merchant_id, sub_merchant_name, scene, base_scene_code, main_merchant_type, sub_merchant_type, status, created_by, created_date, updated_by, updated_date, ...

    2. 危险实现:Dubbo Remote 接口参数发生破坏性变更

    • 问题描述:在 YqMerchantConfigRemote.java 中,已有接口方法 updatePartnerMerchant 的入参从 YqMerchantConfigDTO 直接被修改为了 YqMerchantConfigUpdatePartnerMerchantReqDTO。
    • 影响分析:违反核心重要规则。Dubbo 服务提供者的接口一旦发布,直接修改已有方法的参数签名属于极其危险的破坏性变更(Breaking Change)。这会导致尚未同步更新的消费端(Consumer)在调用该接口时发生序列化异常或 NoSuchMethodException,直接引发线上生产故障。
    • 优化建议:恢复原接口方法签名。如需使用新的请求参数结构,应新增一个接口方法(例如 updatePartnerMerchantV2),并在旧方法中标记 @Deprecated 并兼容调用新逻辑,或在原 YqMerchantConfigDTO 中以兼容方式新增字段。

    3. 性能与规范问题:全量查询未限制条数(LIMIT)

    • 问题描述:在 SceneMerchantRefNewMapper.xml 的 findYqMerchantByMainMerchantIdAndBaseSceneCode 查询中使用了 order by id,但并未限制返回条数。而在 YqMerchantConfigService.java 第 231 行,业务逻辑仅获取了列表的第一个元素 refs.get(0)。
    • 影响分析:如果该条件匹配的数据量较大,数据库会将所有符合条件的数据全部扫描、排序并返回给应用层,而应用层仅仅使用了第一条。这不仅浪费数据库 I/O 和内存,还会随着数据量增长产生性能瓶颈。
    • 优化建议:在 SQL 语句末尾添加 LIMIT 1,或者在 Service 层调用查询前使用 PageHelper.startPage(1, 1) 进行物理分页拦截。

    二、评分明细

    • 功能实现的正确性与健壮性(20/40分) 理由:业务逻辑校验相对完善,没有使用子查询,符合规范。但是 XML 文件的合并/修改失误导致了严重的语法错误,代码在当前状态下无法正常运行,扣除 20 分。

    • 安全性与潜在风险(30/30分) 理由:未发现 SQL 注入、越权等明显安全漏洞。参数校验使用了 @NotNull 和 @NotBlank,防范了空指针风险。

    • 最佳实践与可维护性(10/20分) 理由:直接修改 Dubbo 已发布接口的参数签名违背了分布式服务向后兼容的最佳实践,属于高危操作,扣除 10 分。DTO 命名规范,Lombok 注解使用合理。

    • 性能与资源利用(3/5分) 理由:存在过度抓取数据的问题(查询 List 仅取 get(0) 且 SQL 无 LIMIT),造成不必要的资源浪费,扣除 2 分。

    • 提交信息质量(5/5分) 理由:Commit message 采用了标准规范(feat),清晰地列出了新增的类、修改的接口、远程调用支持及版本号变更,可追溯性极强,满分。

    总分:68分

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