diff --git a/internal/domains/api/services/processors/flxg/flxgdea9_transform_test.go b/internal/domains/api/services/processors/flxg/flxgdea9_transform_test.go deleted file mode 100644 index a20e720..0000000 --- a/internal/domains/api/services/processors/flxg/flxgdea9_transform_test.go +++ /dev/null @@ -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) - } - } -} diff --git a/internal/domains/api/services/processors/ivyz/ivyz4y27_processor.go b/internal/domains/api/services/processors/ivyz/ivyz4y27_processor.go index 9a5efdf..b035e61 100644 --- a/internal/domains/api/services/processors/ivyz/ivyz4y27_processor.go +++ b/internal/domains/api/services/processors/ivyz/ivyz4y27_processor.go @@ -7,6 +7,7 @@ import ( "tyapi-server/internal/domains/api/dto" "tyapi-server/internal/domains/api/services/processors" + "tyapi-server/internal/infrastructure/external/zhicha" ) // ProcessIVYZ4Y27Request IVYZ4Y27 API处理方法 - 教育背景(详细)查询 @@ -19,15 +20,50 @@ func ProcessIVYZ4Y27Request(ctx context.Context, params []byte, deps *processors if err := deps.Validator.ValidateStruct(paramsDto); err != nil { return nil, errors.Join(processors.ErrInvalidParam, err) } - - if deps.HuiboService == nil { - return nil, errors.Join(processors.ErrSystem, errors.New("汇博服务未初始化")) + encryptedName, err := deps.ZhichaService.Encrypt(paramsDto.Name) + if err != nil { + 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 { - 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 + + // 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 } diff --git a/internal/domains/api/services/processors/ivyz/ivyz4y27_transform.go b/internal/domains/api/services/processors/ivyz/ivyz4y27_transform.go new file mode 100644 index 0000000..3e950d6 --- /dev/null +++ b/internal/domains/api/services/processors/ivyz/ivyz4y27_transform.go @@ -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 "" + } +}