Commit 0f664202 by 章家宝

fixbug: 门店提成方案名称按照测试给的格式进行修正

1 parent 01298176
......@@ -29,4 +29,6 @@ public class PerformanceConfigPageByMerchantDTO implements Serializable {
@ApiModelProperty(notes = "业务类型(0:轻改,1:权益;2:延保), 多个以逗号分隔")
private String businessTypes;
private String refIds;
}
......@@ -6,6 +6,7 @@ import org.apache.ibatis.annotations.Mapper;
import org.oreframework.datasource.mybatis.mapper.OreMapper;
import java.util.List;
import java.util.Set;
@Mapper
public interface PerformanceConfigMerchantBrandRefMapper extends OreMapper<PerformanceConfigMerchantBrandRef> {
......@@ -16,4 +17,6 @@ public interface PerformanceConfigMerchantBrandRefMapper extends OreMapper<Perfo
void invalidByBusinessTypeAndMerchantBrand(PerformanceConfigMerchantBrandRefDTO merchantBrandRef);
List<PerformanceConfigMerchantBrandRefDTO> getMerchantBrandListByMerchantIdFromValidPerformanceConfig(PerformanceConfigMerchantBrandRefDTO dto);
List<PerformanceConfigMerchantBrandRefDTO> selectByIdList(Set<Long> idSet);
}
\ No newline at end of file
......@@ -6,8 +6,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.*;
/**
*
......@@ -46,4 +45,8 @@ public class PerformanceConfigMerchantBrandRefService {
public List<PerformanceConfigMerchantBrandRefDTO> getMerchantBrandListByMerchantIdFromValidPerformanceConfig(PerformanceConfigMerchantBrandRefDTO dto) {
return performanceConfigMerchantBrandRefMapper.getMerchantBrandListByMerchantIdFromValidPerformanceConfig(dto);
}
public List<PerformanceConfigMerchantBrandRefDTO> selectByIdList(Set<Long> idSet) {
return performanceConfigMerchantBrandRefMapper.selectByIdList(idSet);
}
}
......@@ -2,6 +2,7 @@ package cn.com.glsx.dj.staff.service.staffPerformance;
import cn.com.glsx.dj.staff.dto.*;
import cn.com.glsx.dj.staff.dto.performance.*;
import cn.com.glsx.dj.staff.enums.PerformanceConfigStatusEnum;
import cn.com.glsx.dj.staff.mapper.PerformanceConfigMapper;
import cn.com.glsx.dj.staff.model.PerformanceConfig;
import cn.com.glsx.framework.core.beans.rpc.RpcPagination;
......@@ -9,14 +10,16 @@ import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.framework.core.enums.DefaultErrorEnum;
import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.com.glsx.framework.core.util.RpcAssert;
import cn.hutool.core.collection.CollectionUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
/**
* 提成配置Service
......@@ -101,6 +104,13 @@ public class PerformanceConfigService {
.effectiveMonth(config.getEffectiveMonth())
.build();
if (result == null) {
return null;
}
if (!config.getStatus().equals(PerformanceConfigStatusEnum.DRAFT.getCode())) {
result.setId(null);
result.setOriginPerformanceConfigId(config.getId());
}
// 查询rule
PerformanceConfigRuleDTO ruleDTO = performanceConfigRuleService
.listByConfigId(dto.getId());
......@@ -119,7 +129,52 @@ public class PerformanceConfigService {
public Page<PerformanceConfigPageByMerchantDTO> pageByMerchant(RpcPagination<PerformanceConfigPageByMerchantDTO> pagination) {
try{
Page<PerformanceConfigPageByMerchantDTO> page = PageHelper.startPage(pagination.getPageNum(), pagination.getPageSize(),pagination.isNeedCount());
performanceConfigMapper.listByMerchant(pagination.getCondition());
List<PerformanceConfigPageByMerchantDTO> dtoList = performanceConfigMapper.listByMerchant(pagination.getCondition());
Set<Long> refIdSet = new HashSet<>();
for (PerformanceConfigPageByMerchantDTO dto : dtoList) {
if (StringUtils.isBlank(dto.getRefIds())) {
continue;
}
for (String id : dto.getRefIds().split(",")) {
refIdSet.add(Long.parseLong(id));
}
}
if (CollectionUtil.isEmpty(refIdSet)) {
return page;
}
List<PerformanceConfigMerchantBrandRefDTO> refList = performanceConfigMerchantBrandRefService.selectByIdList(refIdSet);
Map<Long, PerformanceConfigMerchantBrandRefDTO> refMap = refList.stream().collect(Collectors.toMap(PerformanceConfigMerchantBrandRefDTO::getId, ref -> ref));
for (PerformanceConfigPageByMerchantDTO dto : dtoList) {
String brandNames = "";
Map<String, Set<String>> nameMap = new HashMap<>();
for (String id : dto.getRefIds().split(",")) {
PerformanceConfigMerchantBrandRefDTO refDTO = refMap.get(Long.parseLong(id));
if (refDTO == null) {
continue;
}
Set<String> childs = nameMap.computeIfAbsent(refDTO.getBrandName(), k -> new HashSet<>());
String child = refDTO.getChildName();
if (StringUtils.isNotBlank(child)) {
childs.add(child);
}
}
List<String> brandList = new ArrayList<>();
for (Map.Entry<String, Set<String>> entry : nameMap.entrySet()) {
String firstBrand = entry.getKey();
Set<String> secondBrands = entry.getValue();
if (secondBrands == null || secondBrands.isEmpty()) {
brandList.add(firstBrand);
}
else {
String secondBrandStr = String.join("/", secondBrands);
String brandItem = firstBrand + "-" + secondBrandStr;
brandList.add(brandItem);
}
}
brandNames = String.join(",", brandList);
dto.setBrandNames(brandNames);
}
return page;
} catch (Exception e) {
log.error(e.getMessage(), e);
......
......@@ -117,7 +117,7 @@
ref.merchant_id AS merchantId,
IFNULL(s.merchant_name, '') AS merchantNames,
IFNULL(GROUP_CONCAT(DISTINCT cfg.scheme_name SEPARATOR ','), '') AS schemeNames,
IFNULL(GROUP_CONCAT(DISTINCT ref.brand_name SEPARATOR ','), '') AS brandNames,
IFNULL(GROUP_CONCAT(DISTINCT ref.id SEPARATOR ','), '') AS refIds,
IFNULL(GROUP_CONCAT(DISTINCT cfg.business_type SEPARATOR ','), '') AS businessTypes
FROM
dj_car_life_performance_config_merchant_brand_ref ref
......
......@@ -90,4 +90,18 @@
AND config.enable_flag = 'Y'
AND config.deleted_flag = 'N'
</select>
<select id="selectByIdList" parameterType="java.util.Set" resultMap="DTOResultMap">
SELECT
<include refid="Base_Column_List"/>
FROM
dj_car_life_performance_config_merchant_brand_ref
WHERE
deleted_flag = 'N'
AND id IN
<foreach collection="collection" item="id" open="(" separator="," close=")">
#{id}
</foreach>
ORDER BY
id DESC
</select>
</mapper>
\ No newline at end of file
  • @wangxw1
    commented
    Master

    你好,我是代码审查员。针对你提交的代码,我重点关注了逻辑一致性、数据处理的准确性以及工程规范。

    以下是审查结果:

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

    1. 存在隐蔽的业务逻辑变更,且未在提交信息中体现 (严重性: 高)

    • 问题描述:在 PerformanceConfigService.detail 方法中,新增了一段逻辑:当状态非 DRAFT 时,强制将返回对象的 id 设为 null,并设置 originPerformanceConfigId。
    • 影响分析:
      1. 原子性破坏:Commit 信息仅描述了“修正门店提成方案名称格式”,却包含了修改详情接口返回 ID 的重大逻辑变更,严重误导审查者和后续维护人员。
      2. 副作用风险:detail 方法通常用于查看详情或回显。如果前端或其他服务依赖此接口获取 ID 进行更新操作,此变更会导致 ID 丢失,可能引发新建数据而非更新数据的 Bug,或者导致前端报错。
    • 优化建议:
      • 拆分提交:将格式修正与详情逻辑变更拆分为两个 Commits。
      • 明确意图:如果是为了实现“非草稿状态只能复制/另存为”的功能,建议在 Service 层单独封装 copy 或 getForCopy 方法,而不是修改通用的 detail 方法契约。

    2. 集合类型选择不当导致输出顺序不确定 (严重性: 中)

    • 问题描述:在 pageByMerchant 方法中,使用了 HashMap (nameMap) 和 HashSet (childs) 来聚合品牌和子品牌名称。
    • 影响分析:HashMap 和 HashSet 是无序的(或顺序不可预测)。这会导致 brandNames 字段生成的字符串(如 "奥迪-A4,宝马-X5")在每次刷新或不同数据量下顺序可能跳变,导致前端列表展示忽前忽后,用户体验差。
    • 优化建议:使用 LinkedHashMap 和 LinkedHashSet,或者在输出前对 Key 进行排序,确保展示顺序的确定性(如按品牌名称首字母或 ID 顺序)。 java // 示例优化 Map<String, Set<String>> nameMap = new LinkedHashMap<>(); // 保持插入顺序 // ... Set<String> childs = nameMap.computeIfAbsent(refDTO.getBrandName(), k -> new LinkedHashSet<>());

    3. 循环内重复进行字符串分割与解析,代码冗余 (严重性: 低)

    • 问题描述:在 pageByMerchant 方法中,对同一个 dto.getRefIds() 进行了两次 split(",") 操作。第一次是在收集 refIdSet 时,第二次是在构建 nameMap 时。
    • 影响分析:虽然对性能影响有限,但代码显得啰嗦且维护性较差。如果分隔符变更,需要修改两处。
    • 优化建议:在第一次循环时,将解析后的 ID 列表暂存(例如存入 List<Long> currentRefIds),第二次循环直接使用该列表,或者在一个大循环中完成所有逻辑(虽然分步处理逻辑更清晰,但解析动作应复用)。

    二、评分明细

    1. 功能实现的正确性与健壮性 (30/40)
      • 扣分项:detail 方法的逻辑变更风险较高;pageByMerchant 中使用无序集合导致展示顺序随机;Long.parseLong 在遇到脏数据(如双逗号 ,, 产生的空字符串)时会抛出异常,缺乏容错处理。
    2. 安全性与潜在风险 (30/30)
      • MyBatis 的 IN 查询使用了 <foreach> 和 #{id},无 SQL 注入风险。
      • Service 层对空集合进行了判空处理,避免了 SQL 语法错误。
    3. 最佳实践与可维护性 (10/20)
      • 扣分项:detail 方法违背单一职责原则;代码中存在重复的 split 操作;变量命名尚可但逻辑略显堆砌。
    4. 性能与资源利用 (4/5)
      • 采用了“先查列表,再批量查关联,最后内存组装”的方案,有效避免了 N+1 查询问题,性能表现良好。
    5. 提交信息质量 (1/5)
      • 扣分项:提交信息完全未覆盖 detail 方法的逻辑变更,属于严重的提交规范问题。

    三、总分

    总分:75分

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