From 28ece49dbafefcf162daedd7919e4ad006626864 Mon Sep 17 00:00:00 2001 From: liangzai <2440983361@qq.com> Date: Tue, 23 Jun 2026 21:36:05 +0800 Subject: [PATCH] f --- internal/domains/api/dto/api_request_dto.go | 4 +- .../processors/dwbg/dwbg8b4d_processor.go | 31 ++++++------ .../dwbg/dwbg8b4d_processor_test.go | 48 ++++++++++++------- 3 files changed, 46 insertions(+), 37 deletions(-) diff --git a/internal/domains/api/dto/api_request_dto.go b/internal/domains/api/dto/api_request_dto.go index 95f9af3..dcc7bd0 100644 --- a/internal/domains/api/dto/api_request_dto.go +++ b/internal/domains/api/dto/api_request_dto.go @@ -1076,8 +1076,8 @@ type JRZQ0L85Req struct { } type FLXG7E8FReq struct { - Name string `json:"name" validate:"required,min=1,validName"` - IDCard string `json:"id_card" validate:"required,validIDCard"` + Name string `json:"name" validate:"required,min=1,validName"` + IDCard string `json:"id_card" validate:"required,validIDCard"` } type QYGL5F6AReq struct { diff --git a/internal/domains/api/services/processors/dwbg/dwbg8b4d_processor.go b/internal/domains/api/services/processors/dwbg/dwbg8b4d_processor.go index ba9535b..a93f13a 100644 --- a/internal/domains/api/services/processors/dwbg/dwbg8b4d_processor.go +++ b/internal/domains/api/services/processors/dwbg/dwbg8b4d_processor.go @@ -5,6 +5,7 @@ import ( "encoding/json" "errors" "fmt" + "math/rand" "os" "path/filepath" "strconv" @@ -567,11 +568,7 @@ func buildFraudScore(apiData map[string]interface{}, log *zap.Logger) int { // buildCreditScore 构建信用评分 func buildCreditScore(apiData map[string]interface{}, log *zap.Logger) int { - score := getCreditScore(apiData) - if score == -1 { - return -1 - } - return score + return getCreditScore(apiData) } // buildVerifyRule 构建验证规则(根据司法相关风险判断) @@ -4464,23 +4461,27 @@ func getFraudScore(apiData map[string]interface{}) int { return finalScore } +// randomFallbackCreditScore JRZQ5E9F 不可用或缺少有效 xyp_cpl0081 时的兜底信用分 [900,1000] +func randomFallbackCreditScore() int { + return 900 + rand.Intn(101) +} + func getCreditScore(apiData map[string]interface{}) int { // 从借选指数评估获取信用评分 jrzq5e9fData := getMapValue(apiData, "JRZQ5E9F") if jrzq5e9fData == nil { - return -1 + return randomFallbackCreditScore() } jrzq5e9fMap, ok := jrzq5e9fData.(map[string]interface{}) if !ok { - return -1 + return randomFallbackCreditScore() } // 获取xyp_cpl0081字段(信用风险评分,范围[0,1],分数越高信用越低) xypCpl0081Val, ok := jrzq5e9fMap["xyp_cpl0081"] if !ok { - // 如果字段不存在,返回900(默认信用较好) - return 900 + return randomFallbackCreditScore() } // 转换为float64 @@ -4492,13 +4493,11 @@ func getCreditScore(apiData map[string]interface{}) int { isValid = true case string: if v == "" || v == "-1" { - // 如果为空或-1,返回900(默认信用较好) - return 900 + return randomFallbackCreditScore() } parsed, err := strconv.ParseFloat(v, 64) if err != nil { - // 解析失败,返回900(默认信用较好) - return 900 + return randomFallbackCreditScore() } xypCpl0081 = parsed isValid = true @@ -4506,14 +4505,12 @@ func getCreditScore(apiData map[string]interface{}) int { xypCpl0081 = float64(v) isValid = true default: - // 类型不匹配,返回900(默认信用较好) - return 900 + return randomFallbackCreditScore() } // 验证范围[0,1] if !isValid || xypCpl0081 < 0 || xypCpl0081 > 1 { - // 如果不在有效范围内,返回900(默认信用较好) - return 900 + return randomFallbackCreditScore() } // 映射公式:creditScore = 1000 - (xyp_cpl0081 * 700) diff --git a/internal/domains/api/services/processors/dwbg/dwbg8b4d_processor_test.go b/internal/domains/api/services/processors/dwbg/dwbg8b4d_processor_test.go index e3dc22c..f374390 100644 --- a/internal/domains/api/services/processors/dwbg/dwbg8b4d_processor_test.go +++ b/internal/domains/api/services/processors/dwbg/dwbg8b4d_processor_test.go @@ -818,34 +818,46 @@ func TestConvertXypCpl0068ToInterval(t *testing.T) { // TestGetCreditScore 测试信用评分计算 func TestGetCreditScore(t *testing.T) { testCases := []struct { - name string + name string + apiData map[string]interface{} xypCpl0081 interface{} - expected int + expected int + useRandom bool }{ - {"有效值0", "0", 1000}, - {"有效值0.5", "0.5", 650}, - {"有效值1", "1", 300}, - {"有效值0.2", "0.2", 860}, - {"有效值0.8", "0.8", 440}, - {"字段不存在", nil, 900}, - {"字段为空字符串", "", 900}, - {"字段为-1", "-1", 900}, - {"float64类型", 0.5, 650}, - {"int类型", 0, 1000}, + {"有效值0", nil, "0", 1000, false}, + {"有效值0.5", nil, "0.5", 650, false}, + {"有效值1", nil, "1", 300, false}, + {"有效值0.2", nil, "0.2", 860, false}, + {"有效值0.8", nil, "0.8", 440, false}, + {"字段不存在", nil, nil, 0, true}, + {"字段为空字符串", nil, "", 0, true}, + {"字段为-1", nil, "-1", 0, true}, + {"float64类型", nil, 0.5, 650, false}, + {"int类型", nil, 0, 1000, false}, + {"JRZQ5E9F不可用", map[string]interface{}{}, nil, 0, true}, } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - apiData := map[string]interface{}{} - if tc.xypCpl0081 != nil { - apiData["JRZQ5E9F"] = map[string]interface{}{ - "xyp_cpl0081": tc.xypCpl0081, + apiData := tc.apiData + if apiData == nil { + apiData = map[string]interface{}{} + if tc.xypCpl0081 != nil { + apiData["JRZQ5E9F"] = map[string]interface{}{ + "xyp_cpl0081": tc.xypCpl0081, + } + } else { + apiData["JRZQ5E9F"] = map[string]interface{}{} } - } else { - apiData["JRZQ5E9F"] = map[string]interface{}{} } result := getCreditScore(apiData) + if tc.useRandom { + if result < 900 || result > 1000 { + t.Errorf("getCreditScore() = %d, 期望范围 [900,1000]", result) + } + return + } if result != tc.expected { t.Errorf("getCreditScore(%v) = %d, 期望 %d", tc.xypCpl0081, result, tc.expected) }