查询生效的提成配置,月份用<=过滤

* cn.com.glsx.dj.staff.mapper.PerformanceConfigMapper#selectEffectiveConfig
1 parent c1a4c51a
...@@ -1099,7 +1099,7 @@ public class StaffPerformanceCalService { ...@@ -1099,7 +1099,7 @@ public class StaffPerformanceCalService {
* @param month 月份 * @param month 月份
* @return 提成配置DTO * @return 提成配置DTO
*/ */
private PerformanceConfigDTO getEffectivePerformanceConfig(Integer merchantId, Byte businessType, public PerformanceConfigDTO getEffectivePerformanceConfig(Integer merchantId, Byte businessType,
Integer brandId, Integer brandId,
Integer childBrandId, String month) { Integer childBrandId, String month) {
RpcAssert.assertNotNull(merchantId, DefaultErrorEnum.DATA_NULL, "merchantId不能为空"); RpcAssert.assertNotNull(merchantId, DefaultErrorEnum.DATA_NULL, "merchantId不能为空");
......
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
AND c.status = 2 AND c.status = 2
AND c.enable_flag = 'Y' AND c.enable_flag = 'Y'
AND c.business_type = #{businessType} AND c.business_type = #{businessType}
AND c.effective_month = #{effectiveMonth} AND c.effective_month &lt;= #{effectiveMonth}
AND r.merchant_id = #{merchantId} AND r.merchant_id = #{merchantId}
AND r.brand_id = #{brandId} AND r.brand_id = #{brandId}
AND r.child_id = #{childBrandId} AND r.child_id = #{childBrandId}
......
## 数据要求
我需要开始集成测试的测试数据准备,数据应该满足如下要求:
- 员工
- 天明哥哥
- staffuuid:304c01b8abf14db581606ce42e35ede5
- staffname:天明哥哥
- staff_phone:15626599735
- 明明崇文园区店员工01
- staffuuid:8d3f61299d024a3dbe685687c756866d
- staffname:明明崇文园区店员工01
- staff_phone:15626599738
- 员工北森基础信息表 dj_car_life_staff_beisen_base_info
- 每个员工一条记录,entry_date分别在2025-12-15前后
- 商户
- 商户名称:明天集团4s店AG,商户号:44217734
- 商户名称:明天集团4s店AF,商户号:44217732
- 月份:2025-12
- 商品
- 商品A
- ​ "upgrade_goods_id": 102031,
- ​ "upgrade_goods_name": "权益一级260123",
- ​ "goods_type": 146,
- ​ "goods_type_name": "权益一级类目",
- ​ "secondary_goods_type": -1,
- ​ "secondary_goods_type_name": "",
- ​ "third_level_goods_type": -1,
- ​ "third_level_goods_type_name": ""
- 商品B
- "upgrade_goods_id": 102018,
- ​ "upgrade_goods_name": "权益三级至臻多规格",
- ​ "goods_type": 146,
- ​ "goods_type_name": "权益一级类目",
- ​ "secondary_goods_type": 147,
- ​ "secondary_goods_type_name": "权益二级类目",
- ​ "third_level_goods_type": 148,
- ​ "third_level_goods_type_name": "权益三级类目"
- 商品C
- "upgrade_goods_id": 101673,
- ​ "upgrade_goods_name": "权益二级25011301c",
- ​ "goods_type": 146,
- ​ "goods_type_name": "权益一级类目",
- ​ "secondary_goods_type": 147,
- ​ "secondary_goods_type_name": "权益二级类目",
- ​ "third_level_goods_type": -1,
- ​ "third_level_goods_type_name": ""
- 商品D
- "upgrade_goods_id": 101956,
- ​ "upgrade_goods_name": "20250514权益第三方商品",
- ​ "goods_type": 102,
- ​ "goods_type_name": "11122",
- ​ "secondary_goods_type": -1,
- ​ "secondary_goods_type_name": "",
- ​ "third_level_goods_type": -1,
- ​ "third_level_goods_type_name": ""
- 商品E
- "upgrade_goods_id": 101669,
- ​ "upgrade_goods_name": "延保三级25011301a",
- ​ "goods_type": 114,
- ​ "goods_type_name": "延保类",
- ​ "secondary_goods_type": 149,
- ​ "secondary_goods_type_name": "延保类二级",
- ​ "third_level_goods_type": 150,
- ​ "third_level_goods_type_name": "延保类三级"
- 品牌数据
- 品牌1
- "car_brand_id": 2978,
- ​ "car_brand": "鸿蒙智行",
- ​ "car_childs_brand_id": 3454,
- ​ "car_childs_brand_name": "AITO 问界"
- 品牌2
- "car_brand_id": 2978,
- ​ "car_brand": "鸿蒙智行",
- ​ "car_childs_brand_id": 3547,
- ​ "car_childs_brand_name": "尚界"
- 品牌3
- "car_brand_id": 2125,
- ​ "car_brand": "奥迪",
- ​ "car_childs_brand_id": 2127,
- ​ "car_childs_brand_name": "Audi Sport"
- 品牌4
- ​ "car_brand_id": 2365,
- ​ "car_brand": "比亚迪",
- ​ "car_childs_brand_id": 2695,
- ​ "car_childs_brand_name": "比亚迪"
- 订单数据
- 以上所有员工分别在以上所有门店的多笔订单
- 订单时间及支付时间在月份:2025-12内
- 订单 scene_type = 0, business_type 1 2随机
- 订单的品牌信息随机取用上面的
- 对于同一个员工同一家门店的订单 ,一个订单的子订单信息包含多种商品A-E商品信息的排列组合,例如
- 一个订单包含有商品A的子订单
- 一个订单包含有商品B的子订单
- 一个订单包含有商品C的子订单
- 一个订单包含有商品D的子订单
- 一个订单包含有商品E的子订单
- 一个订单包含有商品A、商品B的子订单
- 一个订单包含有商品A、商品C的子订单
- 一个订单包含有商品A、商品D的子订单
- 一个订单包含有商品A、商品D的子订单
- 一个订单包含有商品B、商品C的子订单
- 一个订单包含有商品B、商品D的子订单
- 一个订单包含有商品B、商品D的子订单
- 一个订单包含有商品C、商品D的子订单
- 一个订单包含有商品A、商品B、商品C的子订单
- 一个订单包含有商品A、商品B、商品D的子订单
- 一个订单包含有商品A、商品C、商品D的子订单
- 一个订单包含有商品A、商品B、商品C、商品D的子订单
- 日报数据
- 以上所有员工分别在以上所有门店的日报数据,一个员工在一家门店至少有3天的日报数据
- sceneType=0
- 日期所在月份是2025-12
- 圈定产品/套餐信息
- dj_car_life_merchant_performance_product_define及dj_car_life_merchant_performance_product_define_item是一套圈定产品/套餐的组合
- 圈定产品1
- define_name: 圈定产品1
- 相关的dj_car_life_merchant_performance_product_define_item包含商品A、商品B
- item_id的值取upgrade_goods_id
- item_name的值取upgrade_goods_name
- 圈定产品2
- define_name: 圈定产品2
- 相关的dj_car_life_merchant_performance_product_define_item包含商品C、商品D
- item_id的值取upgrade_goods_id
- item_name的值取upgrade_goods_name
- 圈定套餐3
- 包含圈定产品1、圈定产品2
- item_id的值取圈定产品2的dj_car_life_merchant_performance_product_define表的id
- item_name的值取取圈定产品2的dj_car_life_merchant_performance_product_define表的define_name
- 已生效的提成配置
- 所有商户在business_type 1、2,以上所有品牌1-4 分别于有一套已生效已启用的提成配置
- effective_month为2025-12
- 每套提成配置相关的dj_car_life_performance_param_config
- 涵盖12种assessment_factor
- goods_config_type等商品信息
- 如果goods_config_type = 0:商品分类,随机取用商品A-E的goods_type等信息
- 如果goods_config_type = 1:圈定产品,product_define_id、product_define_name随机取圈定产品1、圈定产品2信息
- 如果goods_config_type = 2圈定套餐,product_define_id、product_define_name取圈定套餐3信息
- 有效引荐数表sal_effective_referral_review
- 所有员工在所有商户所有品牌有一条数据,reviewMonth为2025-12
\ No newline at end of file \ No newline at end of file
...@@ -457,7 +457,12 @@ public class StaffPerformanceCalServiceIntegrationTest extends BaseServiceTest { ...@@ -457,7 +457,12 @@ public class StaffPerformanceCalServiceIntegrationTest extends BaseServiceTest {
@Test @Test
public void testCalStaffPerformance(){ public void testCalStaffPerformance(){
staffPerformanceCalService.calStaffPerformance("15626599735", "2025-12"); staffPerformanceCalService.calStaffPerformance("15626599735", "2026-01");
staffPerformanceCalService.calStaffPerformance("15626599738", "2025-12"); staffPerformanceCalService.calStaffPerformance("15626599738", "2026-01");
}
@Test
public void testGetEffectivePerformanceConfig(){
staffPerformanceCalService.getEffectivePerformanceConfig(44211523, (byte)2, 2125, 2127, "2026-01");
} }
} }
  • @wangxw1
    commented
    Master

    你好,我是负责本次代码审查的工程师。你提交的代码涉及提成配置查询逻辑的变更及测试数据的调整。

    以下是针对本次提交(Commit)的 Code Review 意见:

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

    1. SQL 查询逻辑严重缺陷(功能正确性)

    • 问题描述:在 PerformanceConfigMapper.xml 中,将查询条件从 effective_month = #{effectiveMonth} 修改为 effective_month <= #{effectiveMonth},但未增加排序(ORDER BY)和数量限制(LIMIT)。
    • 影响分析:
      • 运行时异常:当同一个商户/品牌在历史存在多条配置记录(例如 2025-01 和 2025-12 都有配置),且查询时间为 2026-01 时,该 SQL 会返回多条记录。若 Mapper 接口定义为返回单对象(PerformanceConfigDTO),MyBatis 将抛出 TooManyResultsException,导致生产事故。
      • 业务逻辑错误:即使 Mapper 返回列表,业务层若只取第一条,由于缺乏排序,可能会获取到错误的旧配置(例如取到了 2025-01 而非 2025-12 的配置)。
    • 优化建议:
      • 若业务意图是“获取当前时间生效的最新配置”,必须追加倒序排序并限制返回条数。
      • 代码示例: xml <!-- 修改后的 SQL 片段 --> AND c.effective_month &lt;= #{effectiveMonth} ORDER BY c.effective_month DESC LIMIT 1

    2. 破坏封装性原则(最佳实践)

    • 问题描述:在 StaffPerformanceCalService.java 中,将 getEffectivePerformanceConfig 方法的访问修饰符由 private 修改为 public,且仅为了在 IntegrationTest 中直接调用它。
    • 影响分析:
      • 接口污染:该方法似乎是内部辅助逻辑,暴露为 public 会增加 Service 的对外 API 表面积,导致其他开发者误用。
      • 维护困难:为了测试方便而牺牲封装性是反模式,后续重构内部逻辑时会受到外部依赖的掣肘。
    • 优化建议:
      • 将修饰符改回 private。
      • 测试建议:应当通过测试 calStaffPerformance(公共入口)来间接验证该私有方法的逻辑;或者使用反射/PowerMock 进行单元测试(虽然也不推荐,但优于修改源码可见性)。

    3. 资源文件目录污染(工程规范)

    • 问题描述:文件 src/main/resources/design/test_env_TEST_DATA_INIT.md 被提交到了生产代码的资源目录中。
    • 影响分析:
      • 构建冗余:Markdown 文档会被打包进最终的 JAR/WAR 包中,增加包体积,且在运行时毫无用处。
      • 规范性:设计文档、测试数据准备文档应存放于项目根目录的 doc/ 或 scripts/ 目录下,不应混入源码目录。
    • 优化建议:
      • 将该 .md 文件移动到工程根目录下的 docs 文件夹,或将其添加至 .gitignore 如果仅为个人调试记录。

    二、评分明细

    1. 功能实现的正确性与健壮性(20/40分)
      • 扣分理由:SQL 修改会导致多条数据返回异常(TooManyResultsException)或逻辑错误,这是严重的阻断性 Bug。
    2. 安全性与潜在风险(30/30分)
      • 理由:使用了 MyBatis 的预编译参数 #{},无明显的 SQL 注入风险。
    3. 最佳实践与可维护性(10/20分)
      • 扣分理由:为了测试修改方法可见性(Private -> Public);将文档误放入 src/main/resources 污染构建包。
    4. 性能与资源利用(4/5分)
      • 理由:SQL 缺失 LIMIT 1 可能会在极端数据量下造成不必要的全表扫描或多行数据传输,但目前看影响有限。
    5. 提交信息质量(5/5分)
      • 理由:Commit message 简明扼要,清晰描述了变更意图。

    三、总分

    总分:69分

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