This commit is contained in:
Mrx
2026-06-04 12:21:44 +08:00
parent 1a1d98194e
commit f08a940807
3 changed files with 124 additions and 29 deletions

View File

@@ -1,24 +0,0 @@
package flxg
import "testing"
func TestMapRiskCodeToLevel(t *testing.T) {
tests := []struct {
riskCode string
want string
}{
{"1000000000010000100100000", "A,B,D4,E"},
{"0000000000000000000000001", "0"},
{"1001000000010000100100000", "A,B,D4,E"},
{"0000000000000000100000000", "D4"},
{"0000000000000000010000000", "D2"},
{"0000000000000000001000000", "D5"},
{"0000000000000000000100000", "E"},
}
for _, tt := range tests {
got := mapRiskCodeToLevel(tt.riskCode)
if got != tt.want {
t.Errorf("mapRiskCodeToLevel(%q) = %q, want %q", tt.riskCode, got, tt.want)
}
}
}

View File

@@ -7,6 +7,7 @@ import (
"tyapi-server/internal/domains/api/dto" "tyapi-server/internal/domains/api/dto"
"tyapi-server/internal/domains/api/services/processors" "tyapi-server/internal/domains/api/services/processors"
"tyapi-server/internal/infrastructure/external/zhicha"
) )
// ProcessIVYZ4Y27Request IVYZ4Y27 API处理方法 - 教育背景(详细)查询 // ProcessIVYZ4Y27Request IVYZ4Y27 API处理方法 - 教育背景(详细)查询
@@ -19,15 +20,50 @@ func ProcessIVYZ4Y27Request(ctx context.Context, params []byte, deps *processors
if err := deps.Validator.ValidateStruct(paramsDto); err != nil { if err := deps.Validator.ValidateStruct(paramsDto); err != nil {
return nil, errors.Join(processors.ErrInvalidParam, err) return nil, errors.Join(processors.ErrInvalidParam, err)
} }
encryptedName, err := deps.ZhichaService.Encrypt(paramsDto.Name)
if deps.HuiboService == nil { if err != nil {
return nil, errors.Join(processors.ErrSystem, errors.New("汇博服务未初始化")) return nil, errors.Join(processors.ErrSystem, err)
} }
respBytes, err := deps.HuiboService.CallEducationBackgroundDetailed(ctx, paramsDto.Name, paramsDto.IDCard, paramsDto.AuthAuthorizeFileBase64) encryptedIDCard, err := deps.ZhichaService.Encrypt(paramsDto.IDCard)
if err != nil { if err != nil {
return nil, errors.Join(processors.ErrDatasource, err) return nil, errors.Join(processors.ErrSystem, err)
}
reqData := map[string]interface{}{
"name": encryptedName,
"idCard": encryptedIDCard,
"authorized": "1",
}
respData, err := deps.ZhichaService.CallAPI(ctx, "ZCI1004", reqData)
if err != nil {
if errors.Is(err, zhicha.ErrDatasource) {
return nil, errors.Join(processors.ErrDatasource, err)
}
return nil, errors.Join(processors.ErrSystem, err)
}
out, err := mapZCI1004ToIVYZ4Y27(respData)
if err != nil {
return nil, errors.Join(processors.ErrSystem, err)
}
respBytes, err := json.Marshal(out)
if err != nil {
return nil, errors.Join(processors.ErrSystem, err)
} }
return respBytes, nil return respBytes, nil
// if deps.HuiboService == nil {
// return nil, errors.Join(processors.ErrSystem, errors.New("汇博服务未初始化"))
// }
// respBytes, err := deps.HuiboService.CallEducationBackgroundDetailed(ctx, paramsDto.Name, paramsDto.IDCard, paramsDto.AuthAuthorizeFileBase64)
// if err != nil {
// return nil, errors.Join(processors.ErrDatasource, err)
// }
// return respBytes, nil
} }

View File

@@ -0,0 +1,83 @@
package ivyz
import (
"encoding/json"
"strings"
)
type ivyz4y27AbilityInfo struct {
AbilityStartDate string `json:"abilityStartDate"`
AbilityEndDate string `json:"abilityEndDate"`
AbilityType string `json:"abilityType"`
AbilityName string `json:"abilityName"`
AbilityCompetitiveDegree string `json:"abilityCompetitiveDegree"`
AbilityCompetitive string `json:"abilityCompetitive"`
AbilityField string `json:"abilityField"`
}
type ivyz4y27Response struct {
AbilityInfo []ivyz4y27AbilityInfo `json:"abilityInfo"`
}
func mapZCI1004ToIVYZ4Y27(respData interface{}) (*ivyz4y27Response, error) {
respBytes, err := json.Marshal(respData)
if err != nil {
return nil, err
}
var source []zci1004Item
if err := json.Unmarshal(respBytes, &source); err != nil {
var wrapped struct {
Data []zci1004Item `json:"data"`
}
if err2 := json.Unmarshal(respBytes, &wrapped); err2 != nil {
return nil, err
}
source = wrapped.Data
}
out := &ivyz4y27Response{
AbilityInfo: make([]ivyz4y27AbilityInfo, 0, len(source)),
}
for _, it := range source {
out.AbilityInfo = append(out.AbilityInfo, ivyz4y27AbilityInfo{
AbilityStartDate: "",
AbilityEndDate: formatDateToYYYYMMDD(it.EndDate),
AbilityType: strings.TrimSpace(it.LearningForm),
AbilityName: "",
AbilityCompetitiveDegree: mapEducationLevelToAbilityCompetitiveDegree(it.EducationLevel),
AbilityCompetitive: "",
AbilityField: "",
})
}
return out, nil
}
func mapEducationLevelToAbilityCompetitiveDegree(level string) string {
v := normalizeText(level)
switch {
case strings.Contains(v, "博士"):
return "9"
case strings.Contains(v, "硕士"):
return "8"
case strings.Contains(v, "本科"), strings.Contains(v, "第二学士"):
return "7"
case strings.Contains(v, "专科"), strings.Contains(v, "大专"):
return "6"
default:
return "5"
}
}
func formatDateToYYYYMMDD(s string) string {
digits := normalizeDateDigits(s)
switch len(digits) {
case 8:
return digits[:4] + "-" + digits[4:6] + "-" + digits[6:8]
case 6:
return digits[:4] + "-" + digits[4:6] + "-01"
default:
return ""
}
}