You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Premium Partner资质校验优化:需验证3名技术人员持3种不同有效资质

Fixing Premium Partner (PPP) Validation Logic for Distinct Qualifications

Got it, let's tackle this problem step by step. Your current code checks for at least 3 valid technicians, but it doesn't account for the requirement that those 3 technicians must hold 3 distinct qualification groups (and each group must be covered by a different person). Plus, your initial technician filter was missing some statute IDs (like 25, 5, 26) from the official PPP rules—we'll fix that too.

Key Issues in the Original Code

  1. Only counts valid technicians, not whether they cover distinct qualification groups
  2. Filters technicians using an incomplete set of statute IDs (misses 25, 5, 26 from your PPP rules)
  3. Doesn't prevent a single technician from "covering" multiple groups and skewing the count

Optimized Solution

Here's the revised code with comments explaining each improvement:

public async Task<bool> ValidateThirdPartyTypeRuleAsync(Partner partner, SpecializationExecutionThirdPartyType thirdPartyType)
{
    try
    {
        if (!string.IsNullOrEmpty(thirdPartyType.CRPValidationRule))
        {
            using (var rule = new Evaluate(typeof(Partner), thirdPartyType.CRPValidationRule))
            {
                if (partner == null)
                {
                    throw new ArgumentNullException(nameof(partner), "Partner cannot be null for ValidateThirdTypeRule execution");
                }

                var ruleResult = await rule.RunAsync(partner);
                
                // For non-PPP partners, return the rule result immediately
                if ((bool)ruleResult == false || partner.ThirdPartyType != "PPP")
                {
                    return (bool)ruleResult;
                }

                // --- PPP Specific Validation ---
                // First, define the 5 required qualification groups (matches your official rules)
                var qualificationGroups = new List<HashSet<int>>
                {
                    new HashSet<int> {6, 11},      // Group 1: 6 or 11
                    new HashSet<int> {12},         // Group 2: 12
                    new HashSet<int> {8},          // Group 3: 8
                    new HashSet<int> {9, 25},      // Group 4: 9 or 25
                    new HashSet<int> {5, 26}       // Group 5: 5 or 26
                };

                // Get all technicians who have at least one active valid qualification
                var techniciansWithQualifications = partner.Technicians
                    .Where(t => t.StatutesHistory.Any(s => s.Active)) // Only active technicians
                    .Select(t => new 
                    {
                        Technician = t,
                        // List which qualification groups this technician satisfies
                        QualifiedGroups = qualificationGroups
                            .Where(group => t.StatutesHistory.Any(s => group.Contains(s.StatuteID) && s.Active))
                            .ToList()
                    })
                    .Where(tq => tq.QualifiedGroups.Any()) // Filter out technicians with no valid qualifications
                    .ToList();

                // Now verify we have at least 3 distinct qualification groups, each covered by a unique technician
                var coveredGroupIndices = new HashSet<int>();
                var usedTechnicians = new HashSet<Technician>();

                foreach (var group in qualificationGroups)
                {
                    int groupIndex = qualificationGroups.IndexOf(group);
                    if (coveredGroupIndices.Contains(groupIndex))
                        continue; // Skip groups we already have covered

                    // Find an unused technician who qualifies for this group
                    var matchingTech = techniciansWithQualifications
                        .FirstOrDefault(tq => tq.QualifiedGroups.Contains(group) && !usedTechnicians.Contains(tq.Technician));

                    if (matchingTech != null)
                    {
                        coveredGroupIndices.Add(groupIndex);
                        usedTechnicians.Add(matchingTech.Technician);
                    }

                    // Stop early once we have 3 distinct groups covered
                    if (coveredGroupIndices.Count >= 3)
                        break;
                }

                // PPP is valid only if the base rule passed AND we have 3+ distinct groups from unique technicians
                return coveredGroupIndices.Count >= 3;
            }
        }

        // No validation rule defined—adjust this default as needed for your system
        return false;
    }
    catch (Exception ex)
    {
        // Add your error logging/handling here (e.g., log to your system, rethrow with context)
        throw new InvalidOperationException("Failed to validate third party type rule", ex);
    }
}

What This Fixes

  • Distinct Group Coverage: Ensures 3 different qualification groups are covered by 3 different technicians (no single tech can cover multiple groups to "cheat" the requirement)
  • Complete Statute Filter: Includes all statute IDs from your official PPP rules (25, 5, 26 were missing before)
  • Maintainable Structure: Qualification groups are defined in a single list, so updating rules later is easy
  • Performance: Stops checking once we've found 3 valid groups/technicians, avoiding unnecessary processing

Test Scenarios to Verify

Let's confirm this works for edge cases:

  • ❌ Bad Case: 1 tech with all 5 groups, 2 techs with no qualifications → Fails (only 1 unique tech covering groups)
  • ✅ Good Case: 3 techs, each holding a different group (e.g., Group 1, Group 2, Group 3) → Passes
  • ✅ Good Case: 4 techs: 2 with Group 1, 1 with Group 2, 1 with Group 3 → Passes (picks one Group 1 tech, plus the other two)
  • ❌ Bad Case: 2 techs: 1 with Group 1+2, 1 with Group 3 → Fails (only 2 unique techs)

内容的提问来源于stack exchange,提问作者Miguel Vale

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:13:03