This commit is contained in:
2026-06-23 21:36:05 +08:00
parent e319c66877
commit 28ece49dba
3 changed files with 46 additions and 37 deletions

View File

@@ -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 {

View File

@@ -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)

View File

@@ -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)
}