Commit 40154d03 by 章家宝

fixbug:修复提交审批的时候方案名称重复的bug

1 parent ed91466f
...@@ -20,6 +20,9 @@ public class PerformanceConfigDetailDTO implements Serializable { ...@@ -20,6 +20,9 @@ public class PerformanceConfigDetailDTO implements Serializable {
@ApiModelProperty(notes = "源提成方案配置ID(dj_car_life_performance_config.id)") @ApiModelProperty(notes = "源提成方案配置ID(dj_car_life_performance_config.id)")
private Integer originPerformanceConfigId; private Integer originPerformanceConfigId;
@ApiModelProperty(notes = "状态")
private Integer status;
@ApiModelProperty(notes = "方案名称") @ApiModelProperty(notes = "方案名称")
private String schemeName; private String schemeName;
......
...@@ -16,7 +16,7 @@ public interface PerformanceConfigMerchantBrandRefMapper extends OreMapper<Perfo ...@@ -16,7 +16,7 @@ public interface PerformanceConfigMerchantBrandRefMapper extends OreMapper<Perfo
void invalidByBusinessTypeAndMerchantBrand(PerformanceConfigMerchantBrandRefDTO merchantBrandRef); void invalidByBusinessTypeAndMerchantBrand(PerformanceConfigMerchantBrandRefDTO merchantBrandRef);
List<PerformanceConfigMerchantBrandRefDTO> getMerchantBrandListByMerchantIdFromValidPerformanceConfig(PerformanceConfigMerchantBrandRefDTO dto); List<PerformanceConfigMerchantBrandRefDTO> getMerchantValidPerformance(PerformanceConfigMerchantBrandRefDTO dto);
List<PerformanceConfigMerchantBrandRefDTO> selectByIdList(Set<Long> idSet); List<PerformanceConfigMerchantBrandRefDTO> selectByIdList(Set<Long> idSet);
} }
\ No newline at end of file \ No newline at end of file
...@@ -83,11 +83,15 @@ public class PerformanceConfigApproveService { ...@@ -83,11 +83,15 @@ public class PerformanceConfigApproveService {
} }
// 2. 如果手机号码是查询人,则将查询人状态更新为已查看 // 2. 如果手机号码是查询人,则将查询人状态更新为已查看
performanceConfigApproveOperationRecordService.updateReadStatusByMobile(dto.getMobile()); performanceConfigApproveOperationRecordService.updateReadStatusByMobile(dto.getMobile());
// 审批人审批情况 不包含查看人记录
List<PerformanceConfigApproveOperationRecordDTO> approveOperationRecordList = new ArrayList<>();
List<PerformanceConfigApproveOperationRecordDTO> recordDTOList = performanceConfigApproveOperationRecordService.listByPerformanceConfigApproveId(dto.getId()); List<PerformanceConfigApproveOperationRecordDTO> recordDTOList = performanceConfigApproveOperationRecordService.listByPerformanceConfigApproveId(dto.getId());
performanceConfigApproveDetailAndPermission.setPerformanceConfigApproveOperationRecordList(recordDTOList);
// 3. 该手机号的权限 0:无权限 1:可查阅 2:可审批 3:已通过 4:已驳回 // 3. 该手机号的权限 0:无权限 1:可查阅 2:可审批 3:已通过 4:已驳回
int approvePermission = 0; int approvePermission = 0;
for (PerformanceConfigApproveOperationRecordDTO record : recordDTOList) { for (PerformanceConfigApproveOperationRecordDTO record : recordDTOList) {
if (record.getApproverType().equals(PerformanceApproverTypeEnum.APPROVER.getCode())) {
approveOperationRecordList.add(record);
}
if (!record.getApproverMobile().equals(dto.getMobile())) { if (!record.getApproverMobile().equals(dto.getMobile())) {
continue; continue;
} }
...@@ -105,6 +109,7 @@ public class PerformanceConfigApproveService { ...@@ -105,6 +109,7 @@ public class PerformanceConfigApproveService {
approvePermission = 4; approvePermission = 4;
} }
} }
performanceConfigApproveDetailAndPermission.setPerformanceConfigApproveOperationRecordList(approveOperationRecordList);
// 4. 设置方案名称 // 4. 设置方案名称
PerformanceConfigDTO performanceConfig = performanceConfigService.selectById(performanceConfigApproveDetailAndPermission.getPerformanceConfigId()); PerformanceConfigDTO performanceConfig = performanceConfigService.selectById(performanceConfigApproveDetailAndPermission.getPerformanceConfigId());
if (performanceConfig == null) { if (performanceConfig == null) {
...@@ -136,7 +141,11 @@ public class PerformanceConfigApproveService { ...@@ -136,7 +141,11 @@ public class PerformanceConfigApproveService {
// 2 保存审批记录 // 2 保存审批记录
List<PerformanceConfigMerchantBrandRefDTO> merchantBrandRefs = performanceConfigMerchantBrandRefService List<PerformanceConfigMerchantBrandRefDTO> merchantBrandRefs = performanceConfigMerchantBrandRefService
.listByConfigId(performanceConfigId); .listByConfigId(performanceConfigId);
String merchantNames = merchantBrandRefs.stream().map(PerformanceConfigMerchantBrandRefDTO::getMerchantName).collect(Collectors.joining(",")); String merchantNames = merchantBrandRefs.stream()
.map(PerformanceConfigMerchantBrandRefDTO::getMerchantName)
.filter(Objects::nonNull)
.distinct()
.collect(Collectors.joining(","));
Map<String, Set<String>> nameMap = new HashMap<>(); Map<String, Set<String>> nameMap = new HashMap<>();
for (PerformanceConfigMerchantBrandRefDTO merchantBrandRef : merchantBrandRefs) { for (PerformanceConfigMerchantBrandRefDTO merchantBrandRef : merchantBrandRefs) {
Set<String> childs = nameMap.computeIfAbsent(merchantBrandRef.getBrandName(), k -> new HashSet<>()); Set<String> childs = nameMap.computeIfAbsent(merchantBrandRef.getBrandName(), k -> new HashSet<>());
...@@ -177,12 +186,10 @@ public class PerformanceConfigApproveService { ...@@ -177,12 +186,10 @@ public class PerformanceConfigApproveService {
// 4 发送企微审批通知 // 4 发送企微审批通知
List<PerformanceApproveConfigDTO> performanceApproveConfigDTOS = performanceApproveConfigService.listAll(); List<PerformanceApproveConfigDTO> performanceApproveConfigDTOS = performanceApproveConfigService.listAll();
boolean sendResult = false;
// 5 保存审批记录 // 5 保存审批记录
List<PerformanceConfigApproveOperationRecordDTO> recordDTOList = new ArrayList<>(); List<PerformanceConfigApproveOperationRecordDTO> recordDTOList = new ArrayList<>();
for (PerformanceApproveConfigDTO performanceApproveConfigDTO : performanceApproveConfigService.listAll()) { for (PerformanceApproveConfigDTO performanceApproveConfigDTO : performanceApproveConfigService.listAll()) {
sendResult = sendMessage(config, performanceApproveConfigDTO, id, isUpdate); boolean sendResult = sendMessage(config, performanceApproveConfigDTO, id, isUpdate);
PerformanceConfigApproveOperationRecordDTO record = PerformanceConfigApproveOperationRecordDTO PerformanceConfigApproveOperationRecordDTO record = PerformanceConfigApproveOperationRecordDTO
.builder() .builder()
.performanceConfigApproveId(id) .performanceConfigApproveId(id)
...@@ -218,6 +225,10 @@ public class PerformanceConfigApproveService { ...@@ -218,6 +225,10 @@ public class PerformanceConfigApproveService {
String titleEnv = env.getProperty("performance.approve.send.qw.notice.title", String.class); String titleEnv = env.getProperty("performance.approve.send.qw.notice.title", String.class);
String descriptionEvn = env.getProperty("performance.approve.send.qw.notice.description", String.class); String descriptionEvn = env.getProperty("performance.approve.send.qw.notice.description", String.class);
String urlEvn = env.getProperty("performance.approve.send.qw.notice.url", String.class); String urlEvn = env.getProperty("performance.approve.send.qw.notice.url", String.class);
if (StringUtils.isBlank(urlEvn) || StringUtils.isBlank(titleEnv) || StringUtils.isBlank(descriptionEvn)) {
log.warn("未配置企微审批通知参数");
return false;
}
String userId = qwManager.getUserId(merchantId, performanceApproveConfigDTO.getApproverMobile()); String userId = qwManager.getUserId(merchantId, performanceApproveConfigDTO.getApproverMobile());
if (StringUtils.isBlank(userId)) { if (StringUtils.isBlank(userId)) {
return false; return false;
......
...@@ -43,7 +43,7 @@ public class PerformanceConfigMerchantBrandRefService { ...@@ -43,7 +43,7 @@ public class PerformanceConfigMerchantBrandRefService {
} }
public List<PerformanceConfigMerchantBrandRefDTO> getMerchantValidPerformance(PerformanceConfigMerchantBrandRefDTO dto) { public List<PerformanceConfigMerchantBrandRefDTO> getMerchantValidPerformance(PerformanceConfigMerchantBrandRefDTO dto) {
return performanceConfigMerchantBrandRefMapper.getMerchantBrandListByMerchantIdFromValidPerformanceConfig(dto); return performanceConfigMerchantBrandRefMapper.getMerchantValidPerformance(dto);
} }
public List<PerformanceConfigMerchantBrandRefDTO> selectByIdList(Set<Long> idSet) { public List<PerformanceConfigMerchantBrandRefDTO> selectByIdList(Set<Long> idSet) {
......
...@@ -99,6 +99,7 @@ public class PerformanceConfigService { ...@@ -99,6 +99,7 @@ public class PerformanceConfigService {
} }
PerformanceConfigDetailDTO result = PerformanceConfigDetailDTO.builder() PerformanceConfigDetailDTO result = PerformanceConfigDetailDTO.builder()
.id(config.getId()) .id(config.getId())
.status(config.getStatus())
.schemeName(config.getSchemeName()) .schemeName(config.getSchemeName())
.schemeType(config.getSchemeType()) .schemeType(config.getSchemeType())
.businessType(config.getBusinessType()) .businessType(config.getBusinessType())
...@@ -146,7 +147,7 @@ public class PerformanceConfigService { ...@@ -146,7 +147,7 @@ public class PerformanceConfigService {
List<PerformanceConfigMerchantBrandRefDTO> refList = performanceConfigMerchantBrandRefService.selectByIdList(refIdSet); List<PerformanceConfigMerchantBrandRefDTO> refList = performanceConfigMerchantBrandRefService.selectByIdList(refIdSet);
Map<Long, PerformanceConfigMerchantBrandRefDTO> refMap = refList.stream().collect(Collectors.toMap(PerformanceConfigMerchantBrandRefDTO::getId, ref -> ref)); Map<Long, PerformanceConfigMerchantBrandRefDTO> refMap = refList.stream().collect(Collectors.toMap(PerformanceConfigMerchantBrandRefDTO::getId, ref -> ref));
for (PerformanceConfigPageByMerchantDTO dto : dtoList) { for (PerformanceConfigPageByMerchantDTO dto : dtoList) {
String brandNames = ""; String brandNames;
Map<String, Set<String>> nameMap = new HashMap<>(); Map<String, Set<String>> nameMap = new HashMap<>();
for (String id : dto.getRefIds().split(",")) { for (String id : dto.getRefIds().split(",")) {
PerformanceConfigMerchantBrandRefDTO refDTO = refMap.get(Long.parseLong(id)); PerformanceConfigMerchantBrandRefDTO refDTO = refMap.get(Long.parseLong(id));
...@@ -245,6 +246,7 @@ public class PerformanceConfigService { ...@@ -245,6 +246,7 @@ public class PerformanceConfigService {
return null; return null;
} }
PerformanceConfigDetailDTO result = new PerformanceConfigDetailDTO(); PerformanceConfigDetailDTO result = new PerformanceConfigDetailDTO();
result.setStatus(performanceConfigDTO.getStatus());
result.setOriginPerformanceConfigId(performanceConfigDTO.getId()); result.setOriginPerformanceConfigId(performanceConfigDTO.getId());
result.setSchemeType(2); result.setSchemeType(2);
result.setId(null); result.setId(null);
......
...@@ -133,12 +133,10 @@ ...@@ -133,12 +133,10 @@
AND s.deleted_flag = 'N' AND s.deleted_flag = 'N'
WHERE WHERE
ref.deleted_flag = 'N' ref.deleted_flag = 'N'
AND cfg.status = 2
<if test="merchantId != null"> <if test="merchantId != null">
AND ref.merchant_id = #{merchantId} AND ref.merchant_id = #{merchantId}
</if> </if>
<if test="status != null">
AND cfg.status = #{status}
</if>
<if test="businessType != null"> <if test="businessType != null">
AND EXISTS ( AND EXISTS (
SELECT 1 SELECT 1
......
...@@ -75,7 +75,7 @@ ...@@ -75,7 +75,7 @@
</if> </if>
</update> </update>
<select id="getMerchantBrandListByMerchantIdFromValidPerformanceConfig" <select id="getMerchantValidPerformance"
parameterType="cn.com.glsx.dj.staff.dto.PerformanceConfigMerchantBrandRefDTO" parameterType="cn.com.glsx.dj.staff.dto.PerformanceConfigMerchantBrandRefDTO"
resultMap="DTOResultMap"> resultMap="DTOResultMap">
SELECT SELECT
...@@ -87,7 +87,6 @@ ...@@ -87,7 +87,6 @@
ref.merchant_id = #{merchantId} ref.merchant_id = #{merchantId}
AND ref.deleted_flag = 'N' AND ref.deleted_flag = 'N'
AND config.status = 2 AND config.status = 2
AND config.enable_flag = 'Y'
AND config.deleted_flag = 'N' AND config.deleted_flag = 'N'
</select> </select>
<select id="selectByIdList" parameterType="java.util.Set" resultMap="DTOResultMap"> <select id="selectByIdList" parameterType="java.util.Set" resultMap="DTOResultMap">
......
  • @wangxw1
    commented
    Master

    你好,我是负责本次代码审查的资深软件开发工程师。我已仔细阅读了你提交的代码变更。

    本次提交包含修复方案名称重复的逻辑,但也夹带了大量关于 SQL 查询条件调整、审批流状态过滤以及通知逻辑的修改。这种“胖提交(Big Commit)”增加了回归测试的风险。

    以下是本次审查的核心问题与优化建议:

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

    1. SQL 查询逻辑硬编码与参数失效(严重性:高)

    • 问题描述:
      • 在 PerformanceConfigMapper.xml 中,你删除了 <if test="status != null"> 的动态判断,直接硬编码了 AND cfg.status = 2。
      • 在 PerformanceConfigMerchantBrandRefMapper.xml 中,你移除了 AND config.enable_flag = 'Y' 的过滤条件。
    • 影响分析:
      • 功能受限:Mapper 接口定义的入参 status 实际上已失效,调用方无法再查询非 2(假设为生效/已审核)状态的数据,这可能导致后台管理列表或其他业务场景查询不到数据。
      • 业务风险:移除 enable_flag = 'Y' 可能导致已停用(软删除之外的停用状态)的配置被错误地加载到业务中。
      • 维护性差:SQL 中直接使用魔法数字 2,缺乏语义,难以维护。
    • 优化建议:
      • 恢复动态 SQL 判断,或确认业务是否确实只需要查询状态为 2 的数据。
      • 如果必须固定查询状态,请在 Service 层传入常量,而不是在 XML 中硬编码。
      • 确认移除 enable_flag 是否符合业务需求,防止脏数据泄露。
    <!-- 建议回退或优化为 -->
    WHERE ref.deleted_flag = 'N'
    <if test="status != null">
        AND cfg.status = #{status}
    </if>
    <!-- 必须保留 enable_flag 除非业务明确变更 -->
    AND config.enable_flag = 'Y' 
    

    2. 提交信息与代码变更范围严重不符(严重性:中)

    • 问题描述:Commit 信息仅为 fixbug:修复提交审批的时候方案名称重复的bug,但代码变更涉及了 SQL 逻辑修改、DTO 字段新增、审批记录过滤逻辑变更、企微通知参数校验等多个互不相关的领域。
    • 影响分析:
      • 可追溯性缺失:其他开发人员无法通过 Log 知道 SQL 逻辑被修改了,排查 Bug 时会忽略此提交。
      • Code Review 困难:掩盖了高风险的 SQL 变更,容易导致生产事故。
    • 优化建议:
      • 遵守 Atomic Commit 原则,将修复 Bug、重构 SQL、修改通知逻辑拆分为 3 个不同的 Commit。
      • 如果必须合并提交,Commit Message 必须列出所有变更点。例如: text fix: 修复方案名称重复并优化审批查询逻辑 1. 审批时过滤重复的商户名称 (fix bug) 2. Mapper SQL调整:固定查询 status=2 的配置,移除 enable_flag 校验 3. 审批详情仅展示审批人记录,过滤查看人 4. 增加企微通知配置参数的空值校验

    3. 循环内的 RPC 调用与配置检查(严重性:中)

    • 问题描述:在 PerformanceConfigApproveService 中,遍历 performanceApproveConfigService.listAll() 的循环内调用了 qwManager.getUserId(...)。同时,配置参数(urlEvn 等)的检查逻辑似乎被放在了循环体调用的方法中(根据上下文推断)。
    • 影响分析:
      • 性能瓶颈:getUserId 通常涉及远程 RPC 或数据库查询。如果审批配置较多,会导致严重的 N+1 问题,显著增加接口响应时间。
      • 资源浪费:环境变量配置应该在循环外检查一次即可,无需每次发送前都检查。
    • 优化建议:
      • 在循环外批量获取所需的 UserId(例如使用 Map<Mobile, UserId>)。
      • 将环境变量的非空检查移至循环外部,如果配置缺失直接阻断或记录日志,避免无效循环。

    二、评分明细

    1. 功能实现的正确性与健壮性(25/40分)

      • 扣分点:SQL 中移除 enable_flag 和硬编码 status=2 风险较高,且未看到对应的业务解释;入参 status 被静默忽略是典型的逻辑陷阱。
      • 得分点:Stream 流处理中增加了 filter(Objects::nonNull) 和 distinct(),有效防止了空指针和数据重复。
    2. 安全性与潜在风险(28/30分)

      • 得分点:使用 MyBatis 预编译参数,无明显 SQL 注入风险。
      • 扣分点:SQL 过滤条件的放宽(移除 enable_flag)可能导致越权访问已停用的敏感数据。
    3. 最佳实践与可维护性(10/20分)

      • 扣分点:SQL 中存在魔法数字 2;Commit Message 质量极差,未能反映真实变更;Mapper 方法重命名尚可,但 XML 修改逻辑混乱。
    4. 性能与资源利用(3/5分)

      • 扣分点:循环内存在潜在的 RPC/DB 调用风险。
    5. 提交信息质量(1/5分)

      • 扣分点:提交信息严重失真,属于“掩耳盗铃”式的提交,极大地增加了维护成本。

    三、总分

    总分:67分

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