From 7b6d7fcb50694ccddb972aac6b96ed05bf575319 Mon Sep 17 00:00:00 2001 From: liangzai <2440983361@qq.com> Date: Thu, 24 Apr 2025 18:28:24 +0800 Subject: [PATCH] new feature --- .../logic/query/querydetailbyordernologic.go | 1 - .../internal/logic/query/queryexamplelogic.go | 64 ----- .../api/internal/service/apirequestService.go | 227 +++++++++++++++++- 3 files changed, 226 insertions(+), 66 deletions(-) diff --git a/app/user/cmd/api/internal/logic/query/querydetailbyordernologic.go b/app/user/cmd/api/internal/logic/query/querydetailbyordernologic.go index 0364fb5..cf8be9d 100644 --- a/app/user/cmd/api/internal/logic/query/querydetailbyordernologic.go +++ b/app/user/cmd/api/internal/logic/query/querydetailbyordernologic.go @@ -195,7 +195,6 @@ func (l *QueryDetailByOrderNoLogic) UpdateFeatureAndProductFeature(productID int if pf.FeatureId == feature.Id { // 确保和 Feature 关联 sort = int(pf.Sort) break // 找到第一个符合条件的就退出循环 - } } featureData = map[string]interface{}{ diff --git a/app/user/cmd/api/internal/logic/query/queryexamplelogic.go b/app/user/cmd/api/internal/logic/query/queryexamplelogic.go index 8cab545..6f7555a 100644 --- a/app/user/cmd/api/internal/logic/query/queryexamplelogic.go +++ b/app/user/cmd/api/internal/logic/query/queryexamplelogic.go @@ -108,67 +108,3 @@ func (l *QueryExampleLogic) QueryExample(req *types.QueryExampleReq) (resp *type Query: query, }, nil } - -// 如果有重复声明的问题,可能需要将这个函数移动到公共位置或者确认是否已存在 -// 暂时保留,如果仍有问题可以考虑将其移到其他文件 -/* func (l *QueryExampleLogic) UpdateFeatureAndProductFeature(productID int64, target *[]types.QueryItem) error { - // 遍历 target 数组,使用倒序遍历,以便删除元素时不影响索引 - for i := len(*target) - 1; i >= 0; i-- { - queryItem := &(*target)[i] - - // 确保 Data 为 map 类型 - data, ok := queryItem.Data.(map[string]interface{}) - if !ok { - return fmt.Errorf("queryItem.Data 必须是 map[string]interface{} 类型") - } - - // 从 Data 中获取 apiID - apiID, ok := data["apiID"].(string) - if !ok { - return fmt.Errorf("queryItem.Data 中的 apiID 必须是字符串类型") - } - - // 查询 Feature - feature, err := l.svcCtx.FeatureModel.FindOneByApiId(l.ctx, apiID) - if err != nil { - // 如果 Feature 查不到,也要删除当前 QueryItem - *target = append((*target)[:i], (*target)[i+1:]...) - continue - } - - // 查询 ProductFeatureModel - builder := l.svcCtx.ProductFeatureModel.SelectBuilder().Where("product_id = ?", productID) - productFeatures, err := l.svcCtx.ProductFeatureModel.FindAll(l.ctx, builder, "") - if err != nil { - return fmt.Errorf("查询 ProductFeatureModel 错误: %v", err) - } - - // 遍历 productFeatures,找到与 feature.ID 关联且 enable == 1 的项 - var featureData map[string]interface{} - foundFeature := false - - for _, pf := range productFeatures { - if pf.FeatureId == feature.Id { // 确保和 Feature 关联 - foundFeature = true - if pf.Enable == 1 { - featureData = map[string]interface{}{ - "featureName": feature.Name, - "sort": pf.Sort, - } - break // 找到第一个符合条件的就退出循环 - } - } - } - - // 如果没有符合条件的 feature 或者 featureData 为空,则删除当前 queryItem - if !foundFeature || featureData == nil { - *target = append((*target)[:i], (*target)[i+1:]...) - continue - } - - // 更新 queryItem 的 Feature 字段(不是数组) - queryItem.Feature = featureData - } - - return nil -} */ diff --git a/app/user/cmd/api/internal/service/apirequestService.go b/app/user/cmd/api/internal/service/apirequestService.go index 276cc46..749fe98 100644 --- a/app/user/cmd/api/internal/service/apirequestService.go +++ b/app/user/cmd/api/internal/service/apirequestService.go @@ -206,6 +206,10 @@ var requestProcessors = map[string]func(*ApiRequestService, []byte) ([]byte, err "G31BJ05": (*ApiRequestService).ProcessG31BJ05Request, "G32BJ05": (*ApiRequestService).ProcessG32BJ05Request, "RIS031": (*ApiRequestService).ProcessRIS031Request, + "G09XM02": (*ApiRequestService).ProcessG09XM02Request, + "G10XM02": (*ApiRequestService).ProcessG10XM02Request, + "G11BJ06": (*ApiRequestService).ProcessG11BJ06Request, + "G29BJ05": (*ApiRequestService).ProcessG29BJ05Request, } // PreprocessRequestApi 调用指定的请求处理函数 @@ -1624,7 +1628,7 @@ func (a *ApiRequestService) ProcessBehaviorRiskScanRequest(params []byte) ([]byt results := make(chan apiResult, 5) // 5个风险检测项 // 并行调用五个不同的风险检测API - wg.Add(4) + wg.Add(5) // 黑灰产检测 go func() { @@ -1850,3 +1854,224 @@ func (a *ApiRequestService) ProcessRIS031Request(params []byte) ([]byte, error) return []byte(Value.Raw), nil } +func (a *ApiRequestService) ProcessG09XM02Request(params []byte) ([]byte, error) { + idCard := gjson.GetBytes(params, "id_card") + name := gjson.GetBytes(params, "name") + if !idCard.Exists() || !name.Exists() { + return nil, errors.New("api请求, G09XM02, 获取相关参数失败") + } + request := map[string]interface{}{ + "data": map[string]interface{}{ + "idCard": a.westDexService.Encrypt(idCard.String()), + "name": a.westDexService.Encrypt(name.String()), + }, + } + resp, err := a.westDexService.CallAPI("G09XM02", request) + if err != nil && resp == nil { + return nil, fmt.Errorf("婚姻状态查询失败: %v", err) + } + result := gjson.GetBytes(resp, "data.data") + if !result.Exists() { + return nil, fmt.Errorf("婚姻状态查询失败") + } + + // 获取原始结果 + rawResult := result.String() + + // 根据结果转换状态码 + var statusCode string + switch { + case strings.HasPrefix(rawResult, "INR"): + statusCode = "0" // 匹配不成功 + case strings.HasPrefix(rawResult, "IA"): + statusCode = "1" // 结婚 + case strings.HasPrefix(rawResult, "IB"): + statusCode = "2" // 离婚 + default: + return nil, fmt.Errorf("婚姻状态查询失败,未知状态码: %s", statusCode) + } + + // 构建新的返回结果 + response := map[string]string{ + "status": statusCode, + } + + // 序列化为JSON + jsonResponse, err := json.Marshal(response) + if err != nil { + return nil, fmt.Errorf("序列化结果失败: %v", err) + } + + return jsonResponse, nil +} + +func (a *ApiRequestService) ProcessG10XM02Request(params []byte) ([]byte, error) { + // 提取男方和女方信息 + nameMan := gjson.GetBytes(params, "nameMan") + idCardMan := gjson.GetBytes(params, "idCardMan") + nameWoman := gjson.GetBytes(params, "nameWoman") + idCardWoman := gjson.GetBytes(params, "idCardWoman") + + // 校验是否存在必要参数 + if !nameMan.Exists() || !idCardMan.Exists() || !nameWoman.Exists() || !idCardWoman.Exists() { + return nil, errors.New("请求参数缺失:需要提供男方和女方的姓名及身份证号") + } + + // 构造请求数据 + request := map[string]interface{}{ + "data": map[string]interface{}{ + "idCardMan": a.westDexService.Encrypt(idCardMan.String()), + "nameMan": a.westDexService.Encrypt(nameMan.String()), + "idCardWoman": a.westDexService.Encrypt(idCardWoman.String()), + "nameWoman": a.westDexService.Encrypt(nameWoman.String()), + }, + } + + // 调用 API + resp, callApiErr := a.westDexService.CallAPI("G10XM02", request) + if callApiErr != nil && resp == nil { + return nil, callApiErr + } + + result := gjson.GetBytes(resp, "data.data") + if !result.Exists() { + return nil, fmt.Errorf("婚姻状态查询失败") + } + + // 获取原始结果 + rawResult := result.String() + + // 根据结果转换状态码 + var statusCode string + switch { + case strings.HasPrefix(rawResult, "INR"): + statusCode = "0" // 匹配不成功 + case strings.HasPrefix(rawResult, "IA"): + statusCode = "1" // 结婚 + case strings.HasPrefix(rawResult, "IB"): + statusCode = "2" // 离婚 + default: + return nil, fmt.Errorf("婚姻状态查询失败,未知状态码: %s", statusCode) + } + + // 构建新的返回结果 + response := map[string]string{ + "status": statusCode, + } + + // 序列化为JSON + jsonResponse, err := json.Marshal(response) + if err != nil { + return nil, fmt.Errorf("序列化结果失败: %v", err) + } + + return jsonResponse, nil +} +func (a *ApiRequestService) ProcessG11BJ06Request(params []byte) ([]byte, error) { + idCard := gjson.GetBytes(params, "id_card") + name := gjson.GetBytes(params, "name") + if !idCard.Exists() || !name.Exists() { + return nil, errors.New("api请求, G11BJ06, 获取相关参数失败") + } + request := map[string]interface{}{ + "data": map[string]interface{}{ + "id_card_value": a.westDexService.Encrypt(idCard.String()), + "name_value": a.westDexService.Encrypt(name.String()), + }, + } + resp, err := a.westDexService.CallAPI("G11BJ06", request) + if err != nil && resp == nil { + return nil, fmt.Errorf("教育经历核验查询失败: %v", err) + } + + // 解析响应 + codeResult := gjson.GetBytes(resp, "data.education_background.code") + if !codeResult.Exists() { + return nil, fmt.Errorf("教育经历核验查询失败: 返回数据缺少code字段") + } + + code := codeResult.String() + + var result map[string]interface{} + + switch code { + case "9100": + // 查询成功有结果 + eduResultArray := gjson.GetBytes(resp, "data.education_background.data").Array() + var processedEduData []interface{} + + // 提取每个元素中Raw字段的实际内容 + for _, item := range eduResultArray { + var eduInfo interface{} + if err := json.Unmarshal([]byte(item.Raw), &eduInfo); err != nil { + return nil, fmt.Errorf("解析教育信息失败: %v", err) + } + processedEduData = append(processedEduData, eduInfo) + } + + result = map[string]interface{}{ + "data": processedEduData, + "status": 1, + } + case "9000": + // 查询成功无结果 + result = map[string]interface{}{ + "data": []interface{}{}, + "status": 0, + } + default: + // 其他情况视为错误 + errMsg := gjson.GetBytes(resp, "data.education_background.msg").String() + return nil, fmt.Errorf("教育经历核验查询失败: %s (code: %s)", errMsg, code) + } + + // 将结果转为JSON字节 + jsonResult, err := json.Marshal(result) + if err != nil { + return nil, fmt.Errorf("处理教育经历查询结果失败: %v", err) + } + + return jsonResult, nil +} +func (a *ApiRequestService) ProcessG29BJ05Request(params []byte) ([]byte, error) { + idCard := gjson.GetBytes(params, "id_card") + name := gjson.GetBytes(params, "name") + mobile := gjson.GetBytes(params, "mobile") + if !idCard.Exists() || !name.Exists() || !mobile.Exists() { + return nil, errors.New("api请求, G29BJ05, 获取相关参数失败") + } + request := map[string]interface{}{ + "data": map[string]interface{}{ + "id": a.westDexService.Encrypt(idCard.String()), + "name": a.westDexService.Encrypt(name.String()), + "cell": a.westDexService.Encrypt(mobile.String()), + }, + } + resp, err := a.westDexService.CallAPI("G29BJ05", request) + if err != nil && resp == nil { + return nil, fmt.Errorf("偿贷压力查询失败: %v", err) + } + // 获取响应码和偿贷压力标志 + code := gjson.GetBytes(resp, "code").String() + flagDebtRepayStress := gjson.GetBytes(resp, "flag_debtrepaystress").String() + + // 判断是否成功 + if code != "00" || flagDebtRepayStress != "1" { + return nil, fmt.Errorf("偿贷压力查询失败: %+v", resp) + } + // 获取偿贷压力分数 + drsNoDebtScore := gjson.GetBytes(resp, "drs_nodebtscore").String() + + // 构建结果 + result := map[string]interface{}{ + "score": drsNoDebtScore, + } + + // 将结果转为JSON + jsonResult, err := json.Marshal(result) + if err != nil { + return nil, fmt.Errorf("处理偿贷压力查询结果失败: %v", err) + } + + return jsonResult, nil +}