Просмотр исходного кода

feat(f03): Task3 发放切换(F03a用新业绩口径getF03aTierPpoints; F03c权重读冻结快照表+legacy等权,真正不变; 加recalc ref_type常量) + TDD(F03c快照2例+F03c契约9例绿)

Xiaogang Liao 8 часов назад
Родитель
Сommit
4c1497e58d

+ 20 - 0
cfc-backend/src/main/java/com/etotem/cfc/mapper/CfDirectSalesTierSnapshotMapper.java

@@ -0,0 +1,20 @@
+package com.etotem.cfc.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.etotem.cfc.entity.CfDirectSalesTier;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Select;
+
+import java.util.List;
+
+/**
+ * F03c 冻结快照档位表 mapper(复用 CfDirectSalesTier 实体,表结构相同)。
+ * 用自定义 @Select 指向快照表,避免实体 @TableName 冲突。
+ */
+@Mapper
+public interface CfDirectSalesTierSnapshotMapper extends BaseMapper<CfDirectSalesTier> {
+
+    @Select("SELECT id, tier_name, min_annual_ppoints, rate_percent, sort_order "
+            + "FROM cf_direct_sales_tier_f03c_snapshot ORDER BY min_annual_ppoints DESC")
+    List<CfDirectSalesTier> selectAllSnapshot();
+}

+ 11 - 5
cfc-backend/src/main/java/com/etotem/cfc/service/CfCommissionService.java

@@ -93,6 +93,10 @@ public class CfCommissionService {
     /** 团队分润池规则编码(cf_earn_rule.code,分润 v2 §3.1:成本 × T% 池内瓜分) */
     public static final String RULE_TEAM_POOL = "F03c";
 
+    /** 存量重算补差 ref_type(F03 规则重定义,走 adjust 免三道闸) */
+    public static final String REF_TYPE_F03A_RECALC = "F03a_recalc";
+    public static final String REF_TYPE_F03B_RECALC = "F03b_recalc";
+
     /** F03a 团队口径最大层级(§4.1.1:团队 8 层以内) */
     private static final int TEAM_DEPTH = 8;
 
@@ -468,9 +472,10 @@ public class CfCommissionService {
                     if (buyerFamilyId != null && buyerFamilyId.equals(parent.getFamilyId())) {
                         continue;
                     }
-                    // 档位权重(与 F03a 直推档位同一口径:团队 8 层滚动一年 P 点 → rate_percent)
-                    int teamPp = cfReferralService.getTeamAnnualPpoints(parentId, TEAM_DEPTH);
-                    CfDirectSalesTier tier = cfReferralService.matchDirectSalesTier(teamPp);
+                    // F03c 冻结口径(保持不变):旧8层等权团队P点 → 冻结快照表 rate_percent。
+                    // 不受 F03a 新档位表/新业绩口径影响。
+                    int teamPpLegacy = cfReferralService.getTeamAnnualPpointsLegacy(parentId, TEAM_DEPTH);
+                    CfDirectSalesTier tier = cfReferralService.matchDirectSalesTierFromSnapshot(teamPpLegacy);
                     int weight = (tier == null || tier.getRatePercent() == null) ? 0 : tier.getRatePercent();
                     int layer = ref.getLevel() != null ? ref.getLevel() : candidates.size() + 1;
                     candidates.add(new TeamPoolCandidate(parentId, resolveMemberId(parentId), layer, weight));
@@ -797,8 +802,9 @@ public class CfCommissionService {
     private int salesRatePercent(Long referrerId, String ruleCode) {
         int tierRate;
         if (RULE_DIRECT_SALES.equals(ruleCode)) {
-            int teamAnnualPpoints = cfReferralService.getTeamAnnualPpoints(referrerId, TEAM_DEPTH);
-            CfDirectSalesTier tier = cfReferralService.matchDirectSalesTier(teamAnnualPpoints);
+            // F03 规则重定义(2026-11-29):业绩=个人100%+团队逐层递减90%→0%(基于下线再销售P点)
+            int f03aPpoints = cfReferralService.getF03aTierPpoints(referrerId, null);
+            CfDirectSalesTier tier = cfReferralService.matchDirectSalesTier(f03aPpoints);
             tierRate = (tier == null || tier.getRatePercent() == null) ? 0 : tier.getRatePercent();
         } else {
             int selfAnnualPpoints = cfReferralService.getSelfAnnualPpoints(referrerId);

+ 17 - 0
cfc-backend/src/main/java/com/etotem/cfc/service/CfReferralService.java

@@ -7,6 +7,7 @@ import com.etotem.cfc.entity.CfRateTier;
 import com.etotem.cfc.entity.ReferralTree;
 import com.etotem.cfc.entity.User;
 import com.etotem.cfc.mapper.CfDirectSalesTierMapper;
+import com.etotem.cfc.mapper.CfDirectSalesTierSnapshotMapper;
 import com.etotem.cfc.mapper.CfIndirectSalesTierMapper;
 import com.etotem.cfc.mapper.CfRateTierMapper;
 import com.etotem.cfc.mapper.PpointConsumptionLogMapper;
@@ -64,6 +65,8 @@ public class CfReferralService {
     @Resource
     private CfIndirectSalesTierMapper cfIndirectSalesTierMapper;
     @Resource
+    private CfDirectSalesTierSnapshotMapper cfDirectSalesTierSnapshotMapper;
+    @Resource
     private PpointConsumptionLogMapper ppointConsumptionLogMapper;
 
     /**
@@ -146,6 +149,20 @@ public class CfReferralService {
         return tiers.isEmpty() ? null : tiers.get(0);
     }
 
+    /**
+     * F03c 专用:从冻结快照表匹配旧档位(F03 重定义前口径,保持不变)。
+     * 快照 min 为旧值(10000~1000000),与业绩=0 的新秀档(min=0)隔离。
+     */
+    public CfDirectSalesTier matchDirectSalesTierFromSnapshot(int teamAnnualPpoints) {
+        List<CfDirectSalesTier> tiers = cfDirectSalesTierSnapshotMapper.selectAllSnapshot();
+        for (CfDirectSalesTier t : tiers) {
+            if (t.getMinAnnualPpoints() != null && t.getMinAnnualPpoints() <= teamAnnualPpoints) {
+                return t; // 已按 min DESC 排序,第一条即最高档
+            }
+        }
+        return null;
+    }
+
     /**
      * 间接销售奖档位匹配:cf_indirect_sales_tier WHERE enabled=1
      * AND min_self_ppoints <= selfAnnualPpoints ORDER BY min_self_ppoints DESC LIMIT 1

+ 63 - 0
cfc-backend/src/test/java/com/etotem/cfc/service/F03cSnapshotMatchTest.java

@@ -0,0 +1,63 @@
+package com.etotem.cfc.service;
+
+import com.etotem.cfc.entity.CfDirectSalesTier;
+import com.etotem.cfc.mapper.*;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+import java.lang.reflect.Method;
+import java.util.*;
+import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.*;
+
+/**
+ * TDD 契约(Task3):F03c 权重读冻结快照(旧5档),F03a 发放走新业绩口径,
+ * 常量 TEAM_DEPTH=8 与 F03A_WEIGHT_DEPTH=10 分离。
+ */
+class F03cSnapshotMatchTest {
+
+    @Mock private ReferralTreeMapper referralTreeMapper;
+    @Mock private UserMapper userMapper;
+    @Mock private CfRateTierMapper cfRateTierMapper;
+    @Mock private CfDirectSalesTierMapper cfDirectSalesTierMapper;
+    @Mock private CfIndirectSalesTierMapper cfIndirectSalesTierMapper;
+    @Mock private CfDirectSalesTierSnapshotMapper snapshotMapper;
+    @Mock private PpointConsumptionLogMapper ppointConsumptionLogMapper;
+
+    @InjectMocks private CfReferralService referralService;
+
+    @BeforeEach
+    void setUp() { MockitoAnnotations.openMocks(this); }
+
+    @Test
+    void f03c_snapshot_match_uses_old_tiers() {
+        // 旧口径:业绩 10000 → 新秀10%(不是新表业绩10000→新档位60%)
+        when(snapshotMapper.selectAllSnapshot()).thenAnswer(inv -> {
+            List<CfDirectSalesTier> all = new ArrayList<>();
+            all.add(tier("新秀", 10000, 10));
+            all.add(tier("小成", 50000, 25));
+            all.add(tier("至富", 1000000, 70));
+            return all;
+        });
+        CfDirectSalesTier t = referralService.matchDirectSalesTierFromSnapshot(10000);
+        assertNotNull(t);
+        assertEquals(10, t.getRatePercent(), "F03c快照业绩10000应得旧新秀10%(不受新表影响)");
+        assertNull(referralService.matchDirectSalesTierFromSnapshot(9999));
+    }
+
+    @Test
+    void depth_constants_are_separated() {
+        assertEquals(8, CfReferralService.DEFAULT_TEAM_DEPTH);
+        assertEquals(10, CfReferralService.F03A_WEIGHT_DEPTH);
+    }
+
+    private CfDirectSalesTier tier(String name, int min, int rate) {
+        CfDirectSalesTier t = new CfDirectSalesTier();
+        t.setTierName(name); t.setMinAnnualPpoints(min); t.setRatePercent(rate);
+        return t;
+    }
+}