ff
This commit is contained in:
@@ -4,11 +4,10 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"tyapi-server/internal/domains/api/dto"
|
||||
"tyapi-server/internal/domains/api/services/processors"
|
||||
"tyapi-server/internal/infrastructure/external/xingwei"
|
||||
"tyapi-server/internal/infrastructure/external/nuoer"
|
||||
)
|
||||
|
||||
// ProcessQYGL5F6ARequest QYGL5F6A API处理方法 - 企业相关查询
|
||||
@@ -21,27 +20,34 @@ func ProcessQYGL5F6ARequest(ctx context.Context, params []byte, deps *processors
|
||||
if err := deps.Validator.ValidateStruct(paramsDto); err != nil {
|
||||
return nil, errors.Join(processors.ErrInvalidParam, err)
|
||||
}
|
||||
fmt.Println("paramsDto", paramsDto)
|
||||
|
||||
// 构建请求数据,将项目规范的字段名转换为 XingweiService 需要的字段名
|
||||
reqData := map[string]interface{}{
|
||||
"idCardNum": paramsDto.IDCard,
|
||||
body := map[string]string{
|
||||
"idCard": paramsDto.IDCard,
|
||||
}
|
||||
|
||||
// 调用行为数据API,使用指定的project_id
|
||||
projectID := "CDJ-1101695397213958144"
|
||||
fmt.Println("reqData", reqData)
|
||||
respBytes, err := deps.XingweiService.CallAPI(ctx, projectID, reqData)
|
||||
nuoerDoCheckAPIKey := "idRelationV101"
|
||||
ApiPath := "/v1/doCheck"
|
||||
|
||||
resp, err := deps.NuoerService.CallAPI(ctx, nuoerDoCheckAPIKey, ApiPath, body)
|
||||
if err != nil {
|
||||
if errors.Is(err, xingwei.ErrNotFound) {
|
||||
return nil, errors.Join(processors.ErrNotFound, err)
|
||||
} else if errors.Is(err, xingwei.ErrDatasource) {
|
||||
if errors.Is(err, nuoer.ErrDatasource) {
|
||||
return nil, errors.Join(processors.ErrDatasource, err)
|
||||
} else if errors.Is(err, xingwei.ErrSystem) {
|
||||
return nil, errors.Join(processors.ErrSystem, err)
|
||||
} else {
|
||||
return nil, errors.Join(processors.ErrSystem, 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 := mapNuoerIdRelationToEntReportResponse(rawData)
|
||||
|
||||
respBytes, err := json.Marshal(result)
|
||||
if err != nil {
|
||||
return nil, errors.Join(processors.ErrSystem, err)
|
||||
}
|
||||
|
||||
return respBytes, nil
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
package qygl
|
||||
|
||||
var qygl5f6aBasicInfoFields = []string{
|
||||
"regStatus", "estiblishTime", "regCapital", "industry", "staffList", "type",
|
||||
"regCapitalCurrency", "legalPersonName", "regNumber", "creditCode", "name",
|
||||
"companyOrgType", "base",
|
||||
}
|
||||
|
||||
// mapNuoerIdRelationToEntReportResponse 将 nuoer data(2json.md)转为 QYGL5F6A 对外结构(1json.md):
|
||||
// 解包 result,映射 datalist 项,并包装为 ent_report_001.queryResult.items。
|
||||
func mapNuoerIdRelationToEntReportResponse(data map[string]interface{}) map[string]interface{} {
|
||||
items := make([]interface{}, 0)
|
||||
if data != nil {
|
||||
payload := unwrapNuoerIdRelationData(data)
|
||||
rawList := asSlice(payload["datalist"])
|
||||
items = make([]interface{}, 0, len(rawList))
|
||||
for _, item := range rawList {
|
||||
if mapped := mapQygl5f6aItem(asMap(item)); mapped != nil {
|
||||
items = append(items, mapped)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return map[string]interface{}{
|
||||
"ent_report_001": map[string]interface{}{
|
||||
"queryResult": map[string]interface{}{
|
||||
"items": items,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func mapQygl5f6aItem(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 := mapQygl5f6aBasicInfo(asMap(item["basicInfo"])); isNonemptyMap(basicInfo) {
|
||||
out["basicInfo"] = basicInfo
|
||||
}
|
||||
stockHolder := pickFields(asMap(item["stockHolderItem"]), qygl6f2dStockHolderFields)
|
||||
if !isNonemptyMap(stockHolder) {
|
||||
stockHolder = pickFields(asMap(item["his_stockHolderItem"]), qygl6f2dStockHolderFields)
|
||||
}
|
||||
if isNonemptyMap(stockHolder) {
|
||||
out["stockHolderItem"] = stockHolder
|
||||
}
|
||||
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 mapQygl5f6aBasicInfo(src map[string]interface{}) map[string]interface{} {
|
||||
if len(src) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
basicInfo := pickFields(src, qygl5f6aBasicInfoFields)
|
||||
if staffList, ok := basicInfo["staffList"]; !ok || isEmptyValue(staffList) {
|
||||
if hisStaffList := src["his_staffList"]; !isEmptyValue(hisStaffList) {
|
||||
basicInfo["staffList"] = hisStaffList
|
||||
} else {
|
||||
delete(basicInfo, "staffList")
|
||||
}
|
||||
}
|
||||
return basicInfo
|
||||
}
|
||||
|
||||
func isEmptyValue(v interface{}) bool {
|
||||
if v == nil {
|
||||
return true
|
||||
}
|
||||
if m, ok := v.(map[string]interface{}); ok {
|
||||
return len(m) == 0
|
||||
}
|
||||
if s, ok := v.([]interface{}); ok {
|
||||
return len(s) == 0
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package qygl
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"tyapi-server/internal/domains/api/dto"
|
||||
"tyapi-server/internal/domains/api/services/processors"
|
||||
"tyapi-server/internal/infrastructure/external/nuoer"
|
||||
)
|
||||
|
||||
// ProcessQYGLVR76Request QYGLVR76 API处理方法 -人企关联诺尔
|
||||
func ProcessQYGLVR76Request(ctx context.Context, params []byte, deps *processors.ProcessorDependencies) ([]byte, error) {
|
||||
var paramsDto dto.QYGLVR76Req
|
||||
if err := json.Unmarshal(params, ¶msDto); err != nil {
|
||||
return nil, errors.Join(processors.ErrSystem, err)
|
||||
}
|
||||
|
||||
if err := deps.Validator.ValidateStruct(paramsDto); err != nil {
|
||||
return nil, errors.Join(processors.ErrInvalidParam, err)
|
||||
}
|
||||
|
||||
body := map[string]string{
|
||||
"idCard": 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)
|
||||
}
|
||||
|
||||
respBytes, err := json.Marshal(resp.Data)
|
||||
if err != nil {
|
||||
return nil, errors.Join(processors.ErrSystem, err)
|
||||
}
|
||||
|
||||
return respBytes, nil
|
||||
}
|
||||
Reference in New Issue
Block a user