This commit is contained in:
Mrx
2026-05-29 12:28:08 +08:00
parent 43acbeb8f4
commit 0973bb099c
21 changed files with 2964 additions and 156 deletions

View File

@@ -7,7 +7,7 @@ import (
"tyapi-server/internal/domains/api/dto"
"tyapi-server/internal/domains/api/services/processors"
"tyapi-server/internal/infrastructure/external/westdex"
"tyapi-server/internal/infrastructure/external/nuoer"
)
// ProcessQYGL6F2DRequest QYGL6F2D API处理方法
@@ -20,26 +20,35 @@ func ProcessQYGL6F2DRequest(ctx context.Context, params []byte, deps *processors
if err := deps.Validator.ValidateStruct(paramsDto); err != nil {
return nil, errors.Join(processors.ErrInvalidParam, err)
}
body := map[string]string{
"idCard": paramsDto.IDCard,
}
encryptedIDCard, err := deps.WestDexService.Encrypt(paramsDto.IDCard)
nuoerDoCheckAPIKey := "idRelationV101"
ApiPath := "/v1/doCheck"
resp, err := deps.NuoerService.CallAPI(ctx, nuoerDoCheckAPIKey, ApiPath, body)
if err != nil {
if errors.Is(err, nuoer.ErrDatasource) {
return nil, errors.Join(processors.ErrDatasource, err)
}
if errors.Is(err, nuoer.ErrNotFound) {
return nil, errors.Join(processors.ErrNotFound, err)
}
return nil, errors.Join(processors.ErrSystem, err)
}
rawData, ok := resp.Data.(map[string]interface{})
if !ok {
return nil, errors.Join(processors.ErrSystem, errors.New("响应格式错误"))
}
result := mapNuoerIdRelationToResponse(rawData)
respBytes, err := json.Marshal(result)
if err != nil {
return nil, errors.Join(processors.ErrSystem, err)
}
reqData := map[string]interface{}{
"data": map[string]interface{}{
"idno": encryptedIDCard,
},
}
respBytes, err := deps.WestDexService.CallAPI(ctx, "G05XM02", reqData)
if err != nil {
if errors.Is(err, westdex.ErrDatasource) {
return nil, errors.Join(processors.ErrDatasource, err)
} else {
return nil, errors.Join(processors.ErrSystem, err)
}
}
return respBytes, nil
}

View File

@@ -0,0 +1,150 @@
package qygl
var qygl6f2dBasicInfoFields = []string{
"regStatus", "estiblishTime", "regCapital", "industry", "type",
"regCapitalCurrency", "legalPersonName", "regNumber", "creditCode", "name",
"companyOrgType", "base", "revdate", "apprdate", "candate", "reccap",
"reccapcur", "province", "city", "district", "regorg", "opscope",
"nic_code", "nic_name", "industry_code", "his_staffList", "tel",
}
var qygl6f2dStockHolderFields = []string{
"orgHolderType", "investDate", "investRate", "subscriptAmt", "orgHolderName",
}
var qygl6f2dAdminPenaltyFields = []string{
"departmentName", "reason", "punishNumber", "type", "content",
"decisionDate", "legalPersonName",
}
var qygl6f2dExecutedPersonFields = []string{
"caseCode", "pname", "caseCreateTime", "execCourtName", "execMoney",
}
var qygl6f2dDishonestExecutedPersonFields = []string{
"businessentity", "areaname", "courname", "unperformPart", "type",
"performedPart", "iname", "disrupttypename", "casecode", "performance",
"regdate", "duty", "gistunit", "publishdate", "gistid",
}
// mapNuoerIdRelationToResponse 将 nuoer 响应2json.md转为对外结构1json.md
// 解包 result去掉 total/fsource并按 1.md 裁剪字段。
func mapNuoerIdRelationToResponse(data map[string]interface{}) map[string]interface{} {
if data == nil {
return map[string]interface{}{"datalist": []interface{}{}}
}
payload := unwrapNuoerIdRelationData(data)
rawList := asSlice(payload["datalist"])
datalist := make([]interface{}, 0, len(rawList))
for _, item := range rawList {
if mapped := mapNuoerIdRelationItem(asMap(item)); mapped != nil {
datalist = append(datalist, mapped)
}
}
return map[string]interface{}{"datalist": datalist}
}
func unwrapNuoerIdRelationData(data map[string]interface{}) map[string]interface{} {
if _, ok := data["datalist"]; ok {
return data
}
if result, ok := data["result"].(map[string]interface{}); ok {
return result
}
return data
}
func mapNuoerIdRelationItem(item map[string]interface{}) map[string]interface{} {
if len(item) == 0 {
return nil
}
out := make(map[string]interface{}, 8)
for _, key := range []string{"orgName", "pName", "relationship"} {
if val, ok := item[key]; ok && val != nil {
out[key] = val
}
}
if basicInfo := pickFields(asMap(item["basicInfo"]), qygl6f2dBasicInfoFields); isNonemptyMap(basicInfo) {
out["basicInfo"] = basicInfo
}
if stockHolder := pickFields(asMap(item["stockHolderItem"]), qygl6f2dStockHolderFields); isNonemptyMap(stockHolder) {
out["stockHolderItem"] = stockHolder
}
if hisStockHolder := pickFields(asMap(item["his_stockHolderItem"]), qygl6f2dStockHolderFields); isNonemptyMap(hisStockHolder) {
out["his_stockHolderItem"] = hisStockHolder
}
if adminPenalty := mapNuoerIdRelationRecords(item["adminPenalty"], qygl6f2dAdminPenaltyFields); len(adminPenalty) > 0 {
out["adminPenalty"] = adminPenalty
}
if executedPerson := mapNuoerIdRelationRecords(item["executedPerson"], qygl6f2dExecutedPersonFields); len(executedPerson) > 0 {
out["executedPerson"] = executedPerson
}
if dishonestExecutedPerson := mapNuoerIdRelationRecords(item["dishonestExecutedPerson"], qygl6f2dDishonestExecutedPersonFields); len(dishonestExecutedPerson) > 0 {
out["dishonestExecutedPerson"] = dishonestExecutedPerson
}
return out
}
func mapNuoerIdRelationRecords(v interface{}, allowlist []string) []interface{} {
list := asSlice(v)
if len(list) == 0 {
return nil
}
out := make([]interface{}, 0, len(list))
for _, item := range list {
if mapped := pickFields(asMap(item), allowlist); isNonemptyMap(mapped) {
out = append(out, mapped)
}
}
return out
}
func pickFields(src map[string]interface{}, allowlist []string) map[string]interface{} {
if len(src) == 0 {
return nil
}
out := make(map[string]interface{}, len(allowlist))
for _, key := range allowlist {
val, ok := src[key]
if !ok || val == nil {
continue
}
out[key] = val
}
return out
}
func isNonemptyMap(m map[string]interface{}) bool {
return len(m) > 0
}
func asMap(v interface{}) map[string]interface{} {
if v == nil {
return nil
}
m, ok := v.(map[string]interface{})
if !ok {
return nil
}
return m
}
func asSlice(v interface{}) []interface{} {
if v == nil {
return nil
}
switch val := v.(type) {
case []interface{}:
return val
default:
return nil
}
}