Commit f1be2daa by HKyoma

fix(perfSalary): 添加灰度名单过滤和参数支持

- 在AttendanceDataCleansingService中为查询条件添加灰度手机号码过滤
- 在AutoPerfEvaluationService中同样添加灰度手机号码过滤逻辑
- 在EffectiveReferralReviewMapper接口及XML中添加merchantIds参数支持
- 在EffectiveReferralReviewService中使用配置的灰度商户ID列表过滤数据查询
- 统一使用Criteria对象添加所有查询条件,代码更清晰规范
1 parent cc28ffaf
...@@ -46,7 +46,7 @@ public interface EffectiveReferralReviewMapper extends OreMapper<EffectiveReferr ...@@ -46,7 +46,7 @@ public interface EffectiveReferralReviewMapper extends OreMapper<EffectiveReferr
List<Integer> getAll4sRefMerchantId(); List<Integer> getAll4sRefMerchantId();
List<MerchantBrandReportDTO> getDeliveryCount(@Param("date") String date); List<MerchantBrandReportDTO> getDeliveryCount(@Param("date") String date, @Param("merchantIds") List<String> merchantIds);
void insertOrUpdate(EffectiveReferralReview effectiveReferralReview); void insertOrUpdate(EffectiveReferralReview effectiveReferralReview);
......
...@@ -130,9 +130,14 @@ public class AttendanceDataCleansingService { ...@@ -130,9 +130,14 @@ public class AttendanceDataCleansingService {
staffBeisenBaseCondition1 = StrUtil.format(staffBeisenBaseCondition1, month); staffBeisenBaseCondition1 = StrUtil.format(staffBeisenBaseCondition1, month);
String staffBeisenBaseCondition2 = "DATE_FORMAT(entry_date, '%Y-%m') <= '{}'"; String staffBeisenBaseCondition2 = "DATE_FORMAT(entry_date, '%Y-%m') <= '{}'";
staffBeisenBaseCondition2 = StrUtil.format(staffBeisenBaseCondition2, month); staffBeisenBaseCondition2 = StrUtil.format(staffBeisenBaseCondition2, month);
staffBeisenBaseExample.createCriteria().andEqualTo("deletedFlag", 'N') Example.Criteria criteria = staffBeisenBaseExample.createCriteria();
criteria.andEqualTo("deletedFlag", 'N')
// .andEqualTo("staffPhone", "18684780942") // .andEqualTo("staffPhone", "18684780942")
.andCondition(staffBeisenBaseCondition1).andCondition(staffBeisenBaseCondition2); .andCondition(staffBeisenBaseCondition1).andCondition(staffBeisenBaseCondition2);
String staffPhones = OrePropertyConfigurer.getProperty("gray_phone_list", String.class, "");
if (StrUtil.isNotBlank(staffPhones)) {
criteria.andIn("staffPhone", Arrays.asList(staffPhones.split(",")));
}
List<StaffBeisenBaseInfo> staffBeiSenBaseInfos = staffBeisenBaseInfoMapper.selectByExample(staffBeisenBaseExample); List<StaffBeisenBaseInfo> staffBeiSenBaseInfos = staffBeisenBaseInfoMapper.selectByExample(staffBeisenBaseExample);
log.info("获取到 {} 条员工数据", staffBeiSenBaseInfos.size()); log.info("获取到 {} 条员工数据", staffBeiSenBaseInfos.size());
......
...@@ -84,9 +84,17 @@ public class AutoPerfEvaluationService { ...@@ -84,9 +84,17 @@ public class AutoPerfEvaluationService {
staffBeisenBaseCondition1 = StrUtil.format(staffBeisenBaseCondition1, lastMonth); staffBeisenBaseCondition1 = StrUtil.format(staffBeisenBaseCondition1, lastMonth);
String staffBeisenBaseCondition2 = "DATE_FORMAT(entry_date, '%Y-%m') <= '{}'"; String staffBeisenBaseCondition2 = "DATE_FORMAT(entry_date, '%Y-%m') <= '{}'";
staffBeisenBaseCondition2 = StrUtil.format(staffBeisenBaseCondition2, lastMonth); staffBeisenBaseCondition2 = StrUtil.format(staffBeisenBaseCondition2, lastMonth);
staffBeisenBaseExample.createCriteria().andEqualTo("deletedFlag", 'N')
// 使用同一个Criteria对象添加所有条件
Example.Criteria criteria = staffBeisenBaseExample.createCriteria();
criteria.andEqualTo("deletedFlag", 'N')
// .andEqualTo("staffPhone", "18684780942") // .andEqualTo("staffPhone", "18684780942")
.andCondition(staffBeisenBaseCondition1).andCondition(staffBeisenBaseCondition2); .andCondition(staffBeisenBaseCondition1)
.andCondition(staffBeisenBaseCondition2);
String staffPhones = OrePropertyConfigurer.getProperty("gray_phone_list", String.class, "");
if (StrUtil.isNotBlank(staffPhones)) {
criteria.andIn("staffPhone", Arrays.asList(staffPhones.split(",")));
}
List<StaffBeisenBaseInfo> staffBeiSenBaseInfos = staffBeisenBaseInfoMapper.selectByExample(staffBeisenBaseExample); List<StaffBeisenBaseInfo> staffBeiSenBaseInfos = staffBeisenBaseInfoMapper.selectByExample(staffBeisenBaseExample);
log.info("获取到 {} 条员工数据", staffBeiSenBaseInfos.size()); log.info("获取到 {} 条员工数据", staffBeiSenBaseInfos.size());
if (ObjectUtil.isEmpty(staffBeiSenBaseInfos)) { if (ObjectUtil.isEmpty(staffBeiSenBaseInfos)) {
......
...@@ -14,7 +14,6 @@ import cn.com.glsx.dj.staff.mapper.perfSalary.EffectiveReferralReviewMapper; ...@@ -14,7 +14,6 @@ import cn.com.glsx.dj.staff.mapper.perfSalary.EffectiveReferralReviewMapper;
import cn.com.glsx.dj.staff.model.perfSalary.EffectiveReferralReview; import cn.com.glsx.dj.staff.model.perfSalary.EffectiveReferralReview;
import cn.com.glsx.dj.staff.service.staffPerformance.PerformanceTimeCycleService; import cn.com.glsx.dj.staff.service.staffPerformance.PerformanceTimeCycleService;
import cn.com.glsx.dj.staff.util.DataUtils; import cn.com.glsx.dj.staff.util.DataUtils;
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.RpcPagination;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse; import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.framework.core.enums.DefaultErrorEnum; import cn.com.glsx.framework.core.enums.DefaultErrorEnum;
...@@ -237,7 +236,13 @@ public class EffectiveReferralReviewService { ...@@ -237,7 +236,13 @@ public class EffectiveReferralReviewService {
// 上个月 // 上个月
DateTime lastMonthDate = DateUtil.offsetMonth(new Date(), -1); DateTime lastMonthDate = DateUtil.offsetMonth(new Date(), -1);
statsMonth = StrUtil.isNotBlank(statsMonth) ? statsMonth : DateUtil.format(lastMonthDate, DatePattern.NORM_MONTH_PATTERN); statsMonth = StrUtil.isNotBlank(statsMonth) ? statsMonth : DateUtil.format(lastMonthDate, DatePattern.NORM_MONTH_PATTERN);
List<MerchantBrandReportDTO> deliveryCount = effectiveReferralReviewMapper.getDeliveryCount(statsMonth); String merchantIdList = OrePropertyConfigurer.getProperty("gray_merchantId_list", String.class, "");
List<MerchantBrandReportDTO> deliveryCount;
if (StrUtil.isNotBlank(merchantIdList)) {
deliveryCount = effectiveReferralReviewMapper.getDeliveryCount(statsMonth, Arrays.asList(merchantIdList.split(",")));
} else {
deliveryCount = effectiveReferralReviewMapper.getDeliveryCount(statsMonth, null);
}
List<EffectiveReferralReview> insertList = new ArrayList<>(); List<EffectiveReferralReview> insertList = new ArrayList<>();
if (CollUtil.isNotEmpty(deliveryCount)) { if (CollUtil.isNotEmpty(deliveryCount)) {
for (MerchantBrandReportDTO item : deliveryCount) { for (MerchantBrandReportDTO item : deliveryCount) {
......
...@@ -254,6 +254,12 @@ ...@@ -254,6 +254,12 @@
AND s.merchant_id IS NOT NULL AND s.merchant_id IS NOT NULL
AND template_type IN (0, 1, 2, 3) AND template_type IN (0, 1, 2, 3)
AND DATE_FORMAT(m.report_date, '%Y-%m') = #{date} AND DATE_FORMAT(m.report_date, '%Y-%m') = #{date}
<if test="merchantIds != null and merchantIds.size() > 0 ">
AND m.merchant_id IN
<foreach item="item" collection="merchantIds" separator="," open="(" close=")" index="">
#{item}
</foreach>
</if>
GROUP BY m.merchant_id, DATE_FORMAT(m.report_date, '%Y-%m'); GROUP BY m.merchant_id, DATE_FORMAT(m.report_date, '%Y-%m');
</select> </select>
......
  • @wangxw1
    commented
    Master

    这是一份针对您提交代码的专业审查报告。代码整体逻辑清晰,MyBatis 动态 SQL 的使用规范,且提交信息(Commit Message)非常详尽,体现了良好的工程习惯。以下是需要关注的几个优化点:

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

    1. tk.mybatis 的 andIn 条件存在潜在的空集合/脏数据风险(健壮性)

    • 问题描述:在 AttendanceDataCleansingService 和 AutoPerfEvaluationService 中,通过 staffPhones.split(",") 直接放入 criteria.andIn()。如果配置中心配置的值不规范(例如 ","、"13800000000," 或包含空格 " 13800000000 "),split 可能会产生空字符串,甚至在极端情况下导致空集合。向 tk.mybatis 的 andIn 传入空集合通常会引发 SQL 语法错误(如 IN ())或运行时异常。
    • 影响分析:配置错误时可能导致整个定时任务或核心业务流程中断。
    • 优化建议:在执行 andIn 之前,对拆分后的数组进行过滤(去除空白字符),并确保集合不为空。 java String staffPhones = OrePropertyConfigurer.getProperty("gray_phone_list", String.class, ""); if (StrUtil.isNotBlank(staffPhones)) { // 过滤空白字符串并去除首尾空格 List<String> phoneList = Arrays.stream(staffPhones.split(",")) .filter(StrUtil::isNotBlank) .map(String::trim) .collect(Collectors.toList()); if (CollUtil.isNotEmpty(phoneList)) { criteria.andIn("staffPhone", phoneList); } }

    2. 提交了被注释的本地调试代码(可维护性)

    • 问题描述:在 AttendanceDataCleansingService 和 AutoPerfEvaluationService 中,均残留了 // .andEqualTo("staffPhone", "18684780942") 这类被注释掉的测试代码。
    • 影响分析:无用的注释代码会随着时间推移变成“代码僵尸”,降低代码的可读性,干扰其他开发者的阅读。
    • 优化建议:在代码提交(Commit)前,请务必删除所有仅用于本地调试的无用注释。版本历史管理应交由 Git 负责。

    3. 魔法值硬编码与逻辑重复(最佳实践)

    • 问题描述:"gray_phone_list" 作为一个配置项 Key,在两个不同的 Service 中被硬编码。同时,读取配置、判空、切割字符串的逻辑在这两个类中完全重复。
    • 影响分析:若未来需要修改灰度名单的 Key,或者需要改变灰度名单的解析逻辑(例如改为 JSON 格式),需要在多个文件中进行修改,容易遗漏并引发 Bug。
    • 优化建议:将配置 Key 提取为全局常量(如 ConfigConstants.GRAY_PHONE_LIST_KEY)。如果条件允许,可以将“获取并解析灰度手机号”的逻辑抽离到一个专门的配置读取工具类或方法中。

    二、评分明细

    • 功能实现的正确性与健壮性(36/40分): 核心业务逻辑实现正确,XML 中的 <if test="merchantIds != null and merchantIds.size() > 0"> 很好地处理了商户 ID 列表为空的边界情况。扣分点在于 Java 代码中逗号分隔字符串转 List 时,缺乏对脏数据和空集合的防御性处理。

    • 安全性与潜在风险(30/30分): 没有任何 SQL 注入风险。MyBatis XML 中正确使用了 #{item} 进行参数绑定,避免了拼接 SQL 带来的安全隐患。

    • 最佳实践与可维护性(16/20分): 代码整体结构清晰,使用了 Criteria 统一构建查询条件,提升了整洁度。扣分点在于残留了本地调试注释代码,以及配置项 Key 的硬编码和部分逻辑重复。

    • 性能与资源利用(5/5分): 通过批量 IN 查询替代可能的循环单条查询,性能表现良好,没有明显的资源浪费。

    • 提交信息质量(5/5分): Commit Message 格式规范,使用了 fix(perfSalary): 并在正文中分条列出了具体的修改内容和目的,非常清晰、易于追溯,值得表扬。


    三、总分

    总分:92分

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