v1.1
This commit is contained in:
157
app/main/api/internal/logic/query/query_common.go
Normal file
157
app/main/api/internal/logic/query/query_common.go
Normal file
@@ -0,0 +1,157 @@
|
||||
package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"ycc-server/common/xerr"
|
||||
"ycc-server/pkg/lzkit/crypto"
|
||||
"ycc-server/pkg/lzkit/lzUtils"
|
||||
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"ycc-server/app/main/api/internal/svc"
|
||||
"ycc-server/app/main/api/internal/types"
|
||||
"ycc-server/app/main/model"
|
||||
)
|
||||
|
||||
func ProcessQueryData(queryData sql.NullString, target *[]types.QueryItem, key []byte) error {
|
||||
queryDataStr := lzUtils.NullStringToString(queryData)
|
||||
if queryDataStr == "" {
|
||||
return nil
|
||||
}
|
||||
decryptedData, decryptErr := crypto.AesDecrypt(queryDataStr, key)
|
||||
if decryptErr != nil {
|
||||
return decryptErr
|
||||
}
|
||||
var decryptedArray []map[string]interface{}
|
||||
unmarshalErr := json.Unmarshal(decryptedData, &decryptedArray)
|
||||
if unmarshalErr != nil {
|
||||
return unmarshalErr
|
||||
}
|
||||
if len(*target) == 0 {
|
||||
*target = make([]types.QueryItem, len(decryptedArray))
|
||||
}
|
||||
for i := 0; i < len(decryptedArray); i++ {
|
||||
(*target)[i].Data = decryptedArray[i]
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func ProcessQueryParams(QueryParams string, target *map[string]interface{}, key []byte) error {
|
||||
decryptedData, decryptErr := crypto.AesDecrypt(QueryParams, key)
|
||||
if decryptErr != nil {
|
||||
return decryptErr
|
||||
}
|
||||
unmarshalErr := json.Unmarshal(decryptedData, target)
|
||||
if unmarshalErr != nil {
|
||||
return unmarshalErr
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func UpdateFeatureAndProductFeature(ctx context.Context, svcCtx *svc.ServiceContext, productID string, target *[]types.QueryItem) error {
|
||||
for i := len(*target) - 1; i >= 0; i-- {
|
||||
queryItem := &(*target)[i]
|
||||
data, ok := queryItem.Data.(map[string]interface{})
|
||||
if !ok {
|
||||
return fmt.Errorf("queryItem.Data 必须是 map[string]interface{} 类型")
|
||||
}
|
||||
apiID, ok := data["apiID"].(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("queryItem.Data 中的 apiID 必须是字符串类型")
|
||||
}
|
||||
feature, err := svcCtx.FeatureModel.FindOneByApiId(ctx, apiID)
|
||||
if err != nil {
|
||||
*target = append((*target)[:i], (*target)[i+1:]...)
|
||||
continue
|
||||
}
|
||||
builder := svcCtx.ProductFeatureModel.SelectBuilder().Where("product_id = ?", productID)
|
||||
productFeatures, err := svcCtx.ProductFeatureModel.FindAll(ctx, builder, "")
|
||||
if err != nil {
|
||||
return fmt.Errorf("查询 ProductFeatureModel 错误: %v", err)
|
||||
}
|
||||
sort := 0
|
||||
for _, pf := range productFeatures {
|
||||
if pf.FeatureId == feature.Id {
|
||||
sort = int(pf.Sort)
|
||||
break
|
||||
}
|
||||
}
|
||||
featureData := map[string]interface{}{
|
||||
"featureName": feature.Name,
|
||||
"sort": sort,
|
||||
}
|
||||
queryItem.Feature = featureData
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func BuildEncryptedQuery(ctx context.Context, svcCtx *svc.ServiceContext, queryModel *model.Query) (string, error) {
|
||||
var query types.Query
|
||||
query.CreateTime = queryModel.CreateTime.Format("2006-01-02 15:04:05")
|
||||
query.UpdateTime = queryModel.UpdateTime.Format("2006-01-02 15:04:05")
|
||||
secretKey := svcCtx.Config.Encrypt.SecretKey
|
||||
key, decodeErr := hex.DecodeString(secretKey)
|
||||
if decodeErr != nil {
|
||||
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 获取AES解密解药失败, %v", decodeErr)
|
||||
}
|
||||
processParamsErr := ProcessQueryParams(queryModel.QueryParams, &query.QueryParams, key)
|
||||
if processParamsErr != nil {
|
||||
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 报告参数处理失败: %v", processParamsErr)
|
||||
}
|
||||
processErr := ProcessQueryData(queryModel.QueryData, &query.QueryData, key)
|
||||
if processErr != nil {
|
||||
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 报告结果处理失败: %v", processErr)
|
||||
}
|
||||
updateErr := UpdateFeatureAndProductFeature(ctx, svcCtx, queryModel.ProductId, &query.QueryData)
|
||||
if updateErr != nil {
|
||||
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 报告结果处理失败: %v", updateErr)
|
||||
}
|
||||
err := copier.Copy(&query, queryModel)
|
||||
if err != nil {
|
||||
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 报告结构体复制失败, %v", err)
|
||||
}
|
||||
product, err := svcCtx.ProductModel.FindOne(ctx, queryModel.ProductId)
|
||||
if err != nil {
|
||||
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 获取商品信息失败, %v", err)
|
||||
}
|
||||
query.Product = product.ProductEn
|
||||
query.ProductName = product.ProductName
|
||||
queryBytes, marshalErr := json.Marshal(query)
|
||||
if marshalErr != nil {
|
||||
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 序列化查询结果失败: %v", marshalErr)
|
||||
}
|
||||
encryptedQuery, encryptErr := crypto.AesEncrypt(queryBytes, key)
|
||||
if encryptErr != nil {
|
||||
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 加密查询结果失败: %v", encryptErr)
|
||||
}
|
||||
return encryptedQuery, nil
|
||||
}
|
||||
|
||||
func IsOrderAgent(ctx context.Context, svcCtx *svc.ServiceContext, userId string, orderId string) (bool, error) {
|
||||
agent, err := svcCtx.AgentModel.FindOneByUserId(ctx, userId)
|
||||
if err != nil {
|
||||
if errors.Is(err, model.ErrNotFound) {
|
||||
return false, nil
|
||||
}
|
||||
return false, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询代理信息失败, %v", err)
|
||||
}
|
||||
if agent == nil {
|
||||
return false, nil
|
||||
}
|
||||
agentOrder, err := svcCtx.AgentOrderModel.FindOneByOrderId(ctx, orderId)
|
||||
if err != nil {
|
||||
if errors.Is(err, model.ErrNotFound) {
|
||||
return false, nil
|
||||
}
|
||||
return false, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询代理订单失败, %v", err)
|
||||
}
|
||||
if agentOrder == nil {
|
||||
return false, nil
|
||||
}
|
||||
return agentOrder.AgentId == agent.Id, nil
|
||||
}
|
||||
@@ -1,24 +1,16 @@
|
||||
package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"ycc-server/common/ctxdata"
|
||||
"ycc-server/common/xerr"
|
||||
"ycc-server/pkg/lzkit/crypto"
|
||||
"ycc-server/pkg/lzkit/lzUtils"
|
||||
"context"
|
||||
"ycc-server/common/ctxdata"
|
||||
"ycc-server/common/xerr"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/pkg/errors"
|
||||
"ycc-server/app/main/api/internal/svc"
|
||||
"ycc-server/app/main/api/internal/types"
|
||||
"ycc-server/app/main/model"
|
||||
|
||||
"ycc-server/app/main/api/internal/svc"
|
||||
"ycc-server/app/main/api/internal/types"
|
||||
"ycc-server/app/main/model"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type QueryDetailByOrderIdLogic struct {
|
||||
@@ -54,169 +46,31 @@ func (l *QueryDetailByOrderIdLogic) QueryDetailByOrderId(req *types.QueryDetailB
|
||||
if err != nil {
|
||||
return "", errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "报告查询, 查找用户错误: %v", err)
|
||||
}
|
||||
if user.Inside != 1 {
|
||||
// 安全验证:确保订单属于当前用户
|
||||
if order.UserId != userId {
|
||||
return "", errors.Wrapf(xerr.NewErrCode(xerr.LOGIC_QUERY_NOT_FOUND), "无权查看此订单报告")
|
||||
}
|
||||
}
|
||||
if user.Inside != 1 {
|
||||
// 安全验证:确保订单属于当前用户,或为该订单的代理
|
||||
if order.UserId != userId {
|
||||
isAgent, aerr := IsOrderAgent(l.ctx, l.svcCtx, userId, order.Id)
|
||||
if aerr != nil {
|
||||
return "", aerr
|
||||
}
|
||||
if !isAgent {
|
||||
return "", errors.Wrapf(xerr.NewErrCode(xerr.LOGIC_QUERY_NOT_FOUND), "无权查看此订单报告")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 检查订单状态
|
||||
if order.Status != "paid" {
|
||||
return "", errors.Wrapf(xerr.NewErrMsg("订单未支付,无法查看报告"), "")
|
||||
}
|
||||
|
||||
// 获取报告信息
|
||||
queryModel, err := l.svcCtx.QueryModel.FindOneByOrderId(l.ctx, req.OrderId)
|
||||
if err != nil {
|
||||
return "", errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "报告查询, 查找报告错误: %v", err)
|
||||
}
|
||||
|
||||
var query types.Query
|
||||
query.CreateTime = queryModel.CreateTime.Format("2006-01-02 15:04:05")
|
||||
query.UpdateTime = queryModel.UpdateTime.Format("2006-01-02 15:04:05")
|
||||
|
||||
// 解密查询数据
|
||||
secretKey := l.svcCtx.Config.Encrypt.SecretKey
|
||||
key, decodeErr := hex.DecodeString(secretKey)
|
||||
if decodeErr != nil {
|
||||
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 获取AES解密解药失败, %v", decodeErr)
|
||||
}
|
||||
processParamsErr := ProcessQueryParams(queryModel.QueryParams, &query.QueryParams, key)
|
||||
if processParamsErr != nil {
|
||||
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 报告参数处理失败: %v", processParamsErr)
|
||||
}
|
||||
processErr := ProcessQueryData(queryModel.QueryData, &query.QueryData, key)
|
||||
if processErr != nil {
|
||||
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 报告结果处理失败: %v", processErr)
|
||||
}
|
||||
updateFeatureAndProductFeatureErr := l.UpdateFeatureAndProductFeature(queryModel.ProductId, &query.QueryData)
|
||||
if updateFeatureAndProductFeatureErr != nil {
|
||||
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 报告结果处理失败: %v", updateFeatureAndProductFeatureErr)
|
||||
}
|
||||
// 复制报告数据
|
||||
err = copier.Copy(&query, queryModel)
|
||||
if err != nil {
|
||||
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 报告结构体复制失败, %v", err)
|
||||
}
|
||||
product, err := l.svcCtx.ProductModel.FindOne(l.ctx, queryModel.ProductId)
|
||||
if err != nil {
|
||||
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 获取商品信息失败, %v", err)
|
||||
}
|
||||
query.ProductName = product.ProductName
|
||||
query.Product = product.ProductEn
|
||||
queryBytes, marshalErr := json.Marshal(query)
|
||||
if marshalErr != nil {
|
||||
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 序列化查询结果失败: %v", marshalErr)
|
||||
}
|
||||
|
||||
encryptedQuery, encryptErr := crypto.AesEncrypt(queryBytes, key)
|
||||
if encryptErr != nil {
|
||||
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 加密查询结果失败: %v", encryptErr)
|
||||
}
|
||||
|
||||
return encryptedQuery, nil
|
||||
}
|
||||
|
||||
// ProcessQueryData 解密和反序列化 QueryData
|
||||
func ProcessQueryData(queryData sql.NullString, target *[]types.QueryItem, key []byte) error {
|
||||
queryDataStr := lzUtils.NullStringToString(queryData)
|
||||
if queryDataStr == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
// 解密数据
|
||||
decryptedData, decryptErr := crypto.AesDecrypt(queryDataStr, key)
|
||||
if decryptErr != nil {
|
||||
return decryptErr
|
||||
}
|
||||
|
||||
// 解析 JSON 数组
|
||||
var decryptedArray []map[string]interface{}
|
||||
unmarshalErr := json.Unmarshal(decryptedData, &decryptedArray)
|
||||
if unmarshalErr != nil {
|
||||
return unmarshalErr
|
||||
}
|
||||
|
||||
// 确保 target 具有正确的长度
|
||||
if len(*target) == 0 {
|
||||
*target = make([]types.QueryItem, len(decryptedArray))
|
||||
}
|
||||
|
||||
// 填充解密后的数据到 target
|
||||
for i := 0; i < len(decryptedArray); i++ {
|
||||
// 直接填充解密数据到 Data 字段
|
||||
(*target)[i].Data = decryptedArray[i]
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (l *QueryDetailByOrderIdLogic) 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
|
||||
sort := 0
|
||||
for _, pf := range productFeatures {
|
||||
if pf.FeatureId == feature.Id { // 确保和 Feature 关联
|
||||
sort = int(pf.Sort)
|
||||
break // 找到第一个符合条件的就退出循环
|
||||
}
|
||||
}
|
||||
featureData = map[string]interface{}{
|
||||
"featureName": feature.Name,
|
||||
"sort": sort,
|
||||
}
|
||||
|
||||
// 更新 queryItem 的 Feature 字段(不是数组)
|
||||
queryItem.Feature = featureData
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ProcessQueryParams解密和反序列化 QueryParams
|
||||
func ProcessQueryParams(QueryParams string, target *map[string]interface{}, key []byte) error {
|
||||
// 解密 QueryParams
|
||||
decryptedData, decryptErr := crypto.AesDecrypt(QueryParams, key)
|
||||
if decryptErr != nil {
|
||||
return decryptErr
|
||||
}
|
||||
|
||||
// 反序列化解密后的数据
|
||||
unmarshalErr := json.Unmarshal(decryptedData, target)
|
||||
if unmarshalErr != nil {
|
||||
return unmarshalErr
|
||||
}
|
||||
|
||||
return nil
|
||||
queryModel, err := l.svcCtx.QueryModel.FindOneByOrderId(l.ctx, req.OrderId)
|
||||
if err != nil {
|
||||
return "", errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "报告查询, 查找报告错误: %v", err)
|
||||
}
|
||||
respStr, buildErr := BuildEncryptedQuery(l.ctx, l.svcCtx, queryModel)
|
||||
if buildErr != nil {
|
||||
return "", buildErr
|
||||
}
|
||||
return respStr, nil
|
||||
}
|
||||
|
||||
@@ -2,14 +2,9 @@ package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"ycc-server/common/ctxdata"
|
||||
"ycc-server/common/xerr"
|
||||
"ycc-server/pkg/lzkit/crypto"
|
||||
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"ycc-server/app/main/api/internal/svc"
|
||||
@@ -49,9 +44,15 @@ func (l *QueryDetailByOrderNoLogic) QueryDetailByOrderNo(req *types.QueryDetailB
|
||||
return "", errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "报告查询, 查找报告错误: %v", err)
|
||||
}
|
||||
|
||||
// 安全验证:确保订单属于当前用户
|
||||
// 安全验证:确保订单属于当前用户,或为该订单的代理
|
||||
if order.UserId != userId {
|
||||
return "", errors.Wrapf(xerr.NewErrCode(xerr.LOGIC_QUERY_NOT_FOUND), "无权查看此订单报告")
|
||||
isAgent, aerr := IsOrderAgent(l.ctx, l.svcCtx, userId, order.Id)
|
||||
if aerr != nil {
|
||||
return "", aerr
|
||||
}
|
||||
if !isAgent {
|
||||
return "", errors.Wrapf(xerr.NewErrCode(xerr.LOGIC_QUERY_NOT_FOUND), "无权查看此订单报告")
|
||||
}
|
||||
}
|
||||
|
||||
// 检查订单状态
|
||||
@@ -59,108 +60,13 @@ func (l *QueryDetailByOrderNoLogic) QueryDetailByOrderNo(req *types.QueryDetailB
|
||||
return "", errors.Wrapf(xerr.NewErrMsg("订单未支付,无法查看报告"), "")
|
||||
}
|
||||
|
||||
// 获取报告信息
|
||||
queryModel, err := l.svcCtx.QueryModel.FindOneByOrderId(l.ctx, order.Id)
|
||||
if err != nil {
|
||||
return "", errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "报告查询, 查找报告错误: %v", err)
|
||||
}
|
||||
|
||||
var query types.Query
|
||||
query.CreateTime = queryModel.CreateTime.Format("2006-01-02 15:04:05")
|
||||
query.UpdateTime = queryModel.UpdateTime.Format("2006-01-02 15:04:05")
|
||||
|
||||
// 解密查询数据
|
||||
secretKey := l.svcCtx.Config.Encrypt.SecretKey
|
||||
key, decodeErr := hex.DecodeString(secretKey)
|
||||
if decodeErr != nil {
|
||||
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 获取AES解密解药失败, %v", decodeErr)
|
||||
respStr, buildErr := BuildEncryptedQuery(l.ctx, l.svcCtx, queryModel)
|
||||
if buildErr != nil {
|
||||
return "", buildErr
|
||||
}
|
||||
processParamsErr := ProcessQueryParams(queryModel.QueryParams, &query.QueryParams, key)
|
||||
if processParamsErr != nil {
|
||||
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 报告参数处理失败: %v", processParamsErr)
|
||||
}
|
||||
processErr := ProcessQueryData(queryModel.QueryData, &query.QueryData, key)
|
||||
if processErr != nil {
|
||||
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 报告结果处理失败: %v", processErr)
|
||||
}
|
||||
updateFeatureAndProductFeatureErr := l.UpdateFeatureAndProductFeature(queryModel.ProductId, &query.QueryData)
|
||||
if updateFeatureAndProductFeatureErr != nil {
|
||||
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 报告结果处理失败: %v", updateFeatureAndProductFeatureErr)
|
||||
}
|
||||
// 复制报告数据
|
||||
err = copier.Copy(&query, queryModel)
|
||||
if err != nil {
|
||||
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 报告结构体复制失败, %v", err)
|
||||
}
|
||||
product, err := l.svcCtx.ProductModel.FindOne(l.ctx, queryModel.ProductId)
|
||||
if err != nil {
|
||||
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 获取商品信息失败, %v", err)
|
||||
}
|
||||
query.Product = product.ProductEn
|
||||
query.ProductName = product.ProductName
|
||||
queryBytes, marshalErr := json.Marshal(query)
|
||||
if marshalErr != nil {
|
||||
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 序列化查询结果失败: %v", marshalErr)
|
||||
}
|
||||
|
||||
encryptedQuery, encryptErr := crypto.AesEncrypt(queryBytes, key)
|
||||
if encryptErr != nil {
|
||||
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 加密查询结果失败: %v", encryptErr)
|
||||
}
|
||||
|
||||
return encryptedQuery, nil
|
||||
}
|
||||
|
||||
func (l *QueryDetailByOrderNoLogic) 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
|
||||
sort := 0
|
||||
for _, pf := range productFeatures {
|
||||
if pf.FeatureId == feature.Id { // 确保和 Feature 关联
|
||||
sort = int(pf.Sort)
|
||||
break // 找到第一个符合条件的就退出循环
|
||||
}
|
||||
}
|
||||
featureData = map[string]interface{}{
|
||||
"featureName": feature.Name,
|
||||
"sort": sort,
|
||||
}
|
||||
|
||||
// 更新 queryItem 的 Feature 字段(不是数组)
|
||||
queryItem.Feature = featureData
|
||||
}
|
||||
|
||||
return nil
|
||||
return respStr, nil
|
||||
}
|
||||
|
||||
@@ -1,152 +0,0 @@
|
||||
package query
|
||||
|
||||
// import (
|
||||
// "context"
|
||||
// "encoding/hex"
|
||||
// "fmt"
|
||||
// "ycc-server/app/main/api/internal/svc"
|
||||
// "ycc-server/app/main/api/internal/types"
|
||||
// "ycc-server/common/xerr"
|
||||
|
||||
// "github.com/jinzhu/copier"
|
||||
// "github.com/pkg/errors"
|
||||
|
||||
// "github.com/zeromicro/go-zero/core/logx"
|
||||
// )
|
||||
|
||||
// type QueryExampleLogic struct {
|
||||
// logx.Logger
|
||||
// ctx context.Context
|
||||
// svcCtx *svc.ServiceContext
|
||||
// }
|
||||
|
||||
// func NewQueryExampleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *QueryExampleLogic {
|
||||
// return &QueryExampleLogic{
|
||||
// Logger: logx.WithContext(ctx),
|
||||
// ctx: ctx,
|
||||
// svcCtx: svcCtx,
|
||||
// }
|
||||
// }
|
||||
|
||||
// func (l *QueryExampleLogic) QueryExample(req *types.QueryExampleReq) (resp *types.QueryExampleResp, err error) {
|
||||
// var exampleID int64
|
||||
// switch req.Feature {
|
||||
// case "backgroundcheck":
|
||||
// exampleID = 508
|
||||
// case "companyinfo":
|
||||
// exampleID = 506
|
||||
// case "homeservice":
|
||||
// exampleID = 504
|
||||
// case "marriage":
|
||||
// exampleID = 501
|
||||
// case "preloanbackgroundcheck":
|
||||
// exampleID = 509
|
||||
// case "rentalinfo":
|
||||
// exampleID = 505
|
||||
// case "riskassessment":
|
||||
// exampleID = 503
|
||||
|
||||
// default:
|
||||
// return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "示例报告, 获取示例报告失败: %v", err)
|
||||
// }
|
||||
// queryModel, err := l.svcCtx.QueryModel.FindOne(l.ctx, exampleID)
|
||||
// if err != nil {
|
||||
// return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "示例报告, 获取示例报告失败: %v", err)
|
||||
// }
|
||||
// var query types.Query
|
||||
// query.CreateTime = queryModel.CreateTime.Format("2006-01-02 15:04:05")
|
||||
// query.UpdateTime = queryModel.UpdateTime.Format("2006-01-02 15:04:05")
|
||||
|
||||
// // 解密查询数据
|
||||
// secretKey := l.svcCtx.Config.Encrypt.SecretKey
|
||||
// key, decodeErr := hex.DecodeString(secretKey)
|
||||
// if decodeErr != nil {
|
||||
// return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "示例报告, 获取AES解密解药失败, %v", err)
|
||||
// }
|
||||
// processParamsErr := ProcessQueryParams(queryModel.QueryParams, &query.QueryParams, key)
|
||||
// if processParamsErr != nil {
|
||||
// return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "示例报告, 报告参数处理失败: %v", processParamsErr)
|
||||
// }
|
||||
// processErr := ProcessQueryData(queryModel.QueryData, &query.QueryData, key)
|
||||
// if processErr != nil {
|
||||
// return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "示例报告, 报告结果处理失败: %v", processErr)
|
||||
// }
|
||||
// updateFeatureAndProductFeatureErr := l.UpdateFeatureAndProductFeature(queryModel.ProductId, &query.QueryData)
|
||||
// if updateFeatureAndProductFeatureErr != nil {
|
||||
// return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 报告结果处理失败: %v", updateFeatureAndProductFeatureErr)
|
||||
// }
|
||||
// // 复制报告数据
|
||||
// err = copier.Copy(&query, queryModel)
|
||||
// if err != nil {
|
||||
// return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "示例报告, 报告结构体复制失败, %v", err)
|
||||
// }
|
||||
// product, err := l.svcCtx.ProductModel.FindOne(l.ctx, queryModel.ProductId)
|
||||
// if err != nil {
|
||||
// return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "示例报告, 获取商品信息失败, %v", err)
|
||||
// }
|
||||
// query.ProductName = product.ProductName
|
||||
// return &types.QueryExampleResp{
|
||||
// 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
|
||||
// }
|
||||
@@ -38,13 +38,13 @@ func (l *QueryGenerateShareLinkLogic) QueryGenerateShareLink(req *types.QueryGen
|
||||
}
|
||||
|
||||
// 检查参数
|
||||
if (req.OrderId == nil || *req.OrderId == 0) && (req.OrderNo == nil || *req.OrderNo == "") {
|
||||
if (req.OrderId == nil || *req.OrderId == "") && (req.OrderNo == nil || *req.OrderNo == "") {
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg("订单ID和订单号不能同时为空"), "")
|
||||
}
|
||||
|
||||
var order *model.Order
|
||||
// 优先使用OrderId查询
|
||||
if req.OrderId != nil && *req.OrderId != 0 {
|
||||
if req.OrderId != nil && *req.OrderId != "" {
|
||||
order, err = l.svcCtx.OrderModel.FindOne(l.ctx, *req.OrderId)
|
||||
if err != nil {
|
||||
if errors.Is(err, model.ErrNotFound) {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"ycc-server/app/main/api/internal/svc"
|
||||
"ycc-server/app/main/api/internal/types"
|
||||
"context"
|
||||
"ycc-server/app/main/api/internal/svc"
|
||||
"ycc-server/app/main/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type QueryServiceAgentLogic struct {
|
||||
@@ -23,5 +23,11 @@ func NewQueryServiceAgentLogic(ctx context.Context, svcCtx *svc.ServiceContext)
|
||||
}
|
||||
|
||||
func (l *QueryServiceAgentLogic) QueryServiceAgent(req *types.QueryServiceReq) (resp *types.QueryServiceResp, err error) {
|
||||
return &types.QueryServiceResp{}, nil
|
||||
if req.AgentIdentifier != "" {
|
||||
l.ctx = context.WithValue(l.ctx, "agentIdentifier", req.AgentIdentifier)
|
||||
} else if req.App {
|
||||
l.ctx = context.WithValue(l.ctx, "app", req.App)
|
||||
}
|
||||
proxy := NewQueryServiceLogic(l.ctx, l.svcCtx)
|
||||
return proxy.PreprocessLogic(req, req.Product)
|
||||
}
|
||||
|
||||
@@ -100,17 +100,17 @@ func (l *QueryServiceLogic) ProcessMarriageLogic(req *types.QueryServiceReq) (*t
|
||||
"id_card": data.IDCard,
|
||||
"mobile": data.Mobile,
|
||||
}
|
||||
userID, err := l.GetOrCreateUser()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 处理用户失败: %v", err)
|
||||
}
|
||||
userID, userType, err := l.GetOrCreateUser()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 处理用户失败: %v", err)
|
||||
}
|
||||
cacheNo, cacheDataErr := l.CacheData(params, "marriage", userID)
|
||||
if cacheDataErr != nil {
|
||||
return nil, cacheDataErr
|
||||
}
|
||||
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID, model.UserTypeNormal)
|
||||
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID, userType)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 生成token失败 : %d", userID)
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 生成token失败 : %v", err)
|
||||
}
|
||||
|
||||
// 获取当前时间戳
|
||||
@@ -160,16 +160,16 @@ func (l *QueryServiceLogic) ProcessHomeServiceLogic(req *types.QueryServiceReq)
|
||||
"id_card": data.IDCard,
|
||||
"mobile": data.Mobile,
|
||||
}
|
||||
userID, err := l.GetOrCreateUser()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 处理用户失败: %v", err)
|
||||
}
|
||||
userID, userType, err := l.GetOrCreateUser()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 处理用户失败: %v", err)
|
||||
}
|
||||
cacheNo, cacheDataErr := l.CacheData(params, "homeservice", userID)
|
||||
if cacheDataErr != nil {
|
||||
return nil, cacheDataErr
|
||||
}
|
||||
|
||||
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID, model.UserTypeNormal)
|
||||
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID, userType)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 生成token失败 : %d", userID)
|
||||
}
|
||||
@@ -221,16 +221,16 @@ func (l *QueryServiceLogic) ProcessRiskAssessmentLogic(req *types.QueryServiceRe
|
||||
"id_card": data.IDCard,
|
||||
"mobile": data.Mobile,
|
||||
}
|
||||
userID, err := l.GetOrCreateUser()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 处理用户失败: %v", err)
|
||||
}
|
||||
userID, userType, err := l.GetOrCreateUser()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 处理用户失败: %v", err)
|
||||
}
|
||||
cacheNo, cacheDataErr := l.CacheData(params, "riskassessment", userID)
|
||||
if cacheDataErr != nil {
|
||||
return nil, cacheDataErr
|
||||
}
|
||||
|
||||
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID, model.UserTypeNormal)
|
||||
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID, userType)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 生成token失败 : %d", userID)
|
||||
}
|
||||
@@ -281,16 +281,16 @@ func (l *QueryServiceLogic) ProcessCompanyInfoLogic(req *types.QueryServiceReq)
|
||||
"id_card": data.IDCard,
|
||||
"mobile": data.Mobile,
|
||||
}
|
||||
userID, err := l.GetOrCreateUser()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 处理用户失败: %v", err)
|
||||
}
|
||||
userID, userType, err := l.GetOrCreateUser()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 处理用户失败: %v", err)
|
||||
}
|
||||
cacheNo, cacheDataErr := l.CacheData(params, "companyinfo", userID)
|
||||
if cacheDataErr != nil {
|
||||
return nil, cacheDataErr
|
||||
}
|
||||
|
||||
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID, model.UserTypeNormal)
|
||||
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID, userType)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 生成token失败 : %d", userID)
|
||||
}
|
||||
@@ -342,16 +342,16 @@ func (l *QueryServiceLogic) ProcessRentalInfoLogic(req *types.QueryServiceReq) (
|
||||
"id_card": data.IDCard,
|
||||
"mobile": data.Mobile,
|
||||
}
|
||||
userID, err := l.GetOrCreateUser()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 处理用户失败: %v", err)
|
||||
}
|
||||
userID, userType, err := l.GetOrCreateUser()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 处理用户失败: %v", err)
|
||||
}
|
||||
cacheNo, cacheDataErr := l.CacheData(params, "rentalinfo", userID)
|
||||
if cacheDataErr != nil {
|
||||
return nil, cacheDataErr
|
||||
}
|
||||
|
||||
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID, model.UserTypeNormal)
|
||||
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID, userType)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 生成token失败 : %d", userID)
|
||||
}
|
||||
@@ -403,16 +403,16 @@ func (l *QueryServiceLogic) ProcessPreLoanBackgroundCheckLogic(req *types.QueryS
|
||||
"id_card": data.IDCard,
|
||||
"mobile": data.Mobile,
|
||||
}
|
||||
userID, err := l.GetOrCreateUser()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 处理用户失败: %v", err)
|
||||
}
|
||||
userID, userType, err := l.GetOrCreateUser()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 处理用户失败: %v", err)
|
||||
}
|
||||
cacheNo, cacheDataErr := l.CacheData(params, "preloanbackgroundcheck", userID)
|
||||
if cacheDataErr != nil {
|
||||
return nil, cacheDataErr
|
||||
}
|
||||
|
||||
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID, model.UserTypeNormal)
|
||||
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID, userType)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 生成token失败 : %d", userID)
|
||||
}
|
||||
@@ -463,16 +463,16 @@ func (l *QueryServiceLogic) ProcessBackgroundCheckLogic(req *types.QueryServiceR
|
||||
"id_card": data.IDCard,
|
||||
"mobile": data.Mobile,
|
||||
}
|
||||
userID, err := l.GetOrCreateUser()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 处理用户失败: %v", err)
|
||||
}
|
||||
userID, userType, err := l.GetOrCreateUser()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 处理用户失败: %v", err)
|
||||
}
|
||||
cacheNo, cacheDataErr := l.CacheData(params, "backgroundcheck", userID)
|
||||
if cacheDataErr != nil {
|
||||
return nil, cacheDataErr
|
||||
}
|
||||
|
||||
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID, model.UserTypeNormal)
|
||||
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID, userType)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 生成token失败 : %d", userID)
|
||||
}
|
||||
@@ -521,16 +521,16 @@ func (l *QueryServiceLogic) ProcessPersonalDataLogic(req *types.QueryServiceReq)
|
||||
"id_card": data.IDCard,
|
||||
"mobile": data.Mobile,
|
||||
}
|
||||
userID, err := l.GetOrCreateUser()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 处理用户失败: %v", err)
|
||||
}
|
||||
userID, userType, err := l.GetOrCreateUser()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 处理用户失败: %v", err)
|
||||
}
|
||||
cacheNo, cacheDataErr := l.CacheData(params, "personalData", userID)
|
||||
if cacheDataErr != nil {
|
||||
return nil, cacheDataErr
|
||||
}
|
||||
|
||||
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID, model.UserTypeNormal)
|
||||
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID, userType)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 生成token失败 : %d", userID)
|
||||
}
|
||||
@@ -579,16 +579,16 @@ func (l *QueryServiceLogic) ProcessConsumerFinanceReportLogic(req *types.QuerySe
|
||||
"id_card": data.IDCard,
|
||||
"mobile": data.Mobile,
|
||||
}
|
||||
userID, err := l.GetOrCreateUser()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 处理用户失败: %v", err)
|
||||
}
|
||||
userID, userType, err := l.GetOrCreateUser()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 处理用户失败: %v", err)
|
||||
}
|
||||
cacheNo, cacheDataErr := l.CacheData(params, "consumerFinanceReport", userID)
|
||||
if cacheDataErr != nil {
|
||||
return nil, cacheDataErr
|
||||
}
|
||||
|
||||
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID, model.UserTypeNormal)
|
||||
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID, userType)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 生成token失败 : %d", userID)
|
||||
}
|
||||
@@ -677,7 +677,7 @@ func (l *QueryServiceLogic) Verify(Name string, IDCard string, Mobile string) er
|
||||
}
|
||||
|
||||
// 缓存
|
||||
func (l *QueryServiceLogic) CacheData(params map[string]interface{}, Product string, userID int64) (string, error) {
|
||||
func (l *QueryServiceLogic) CacheData(params map[string]interface{}, Product string, userID string) (string, error) {
|
||||
agentIdentifier, _ := l.ctx.Value("agentIdentifier").(string)
|
||||
secretKey := l.svcCtx.Config.Encrypt.SecretKey
|
||||
key, decodeErr := hex.DecodeString(secretKey)
|
||||
@@ -714,34 +714,14 @@ func (l *QueryServiceLogic) CacheData(params map[string]interface{}, Product str
|
||||
// 1. 如果上下文中已有用户ID,直接返回
|
||||
// 2. 如果是代理查询或APP请求,创建新用户
|
||||
// 3. 其他情况返回未登录错误
|
||||
func (l *QueryServiceLogic) GetOrCreateUser() (int64, error) {
|
||||
// 尝试获取用户ID
|
||||
claims, err := ctxdata.GetClaimsFromCtx(l.ctx)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
userID := claims.UserId
|
||||
return userID, nil
|
||||
|
||||
// // 如果不是未登录错误,说明是其他错误,直接返回
|
||||
// if !ctxdata.IsNoUserIdError(err) {
|
||||
// return 0, err
|
||||
// }
|
||||
|
||||
// // 检查是否是代理查询或APP请求
|
||||
// isAgentQuery := false
|
||||
// if agentID, ok := l.ctx.Value("agentIdentifier").(string); ok && agentID != "" {
|
||||
// isAgentQuery = true
|
||||
// }
|
||||
// if app, ok := l.ctx.Value("app").(bool); ok && app {
|
||||
// isAgentQuery = true
|
||||
// }
|
||||
|
||||
// // 如果不是代理查询或APP请求,返回未登录错误
|
||||
// if !isAgentQuery {
|
||||
// return 0, ctxdata.ErrNoUserIdInCtx
|
||||
// }
|
||||
|
||||
// // 创建新用户
|
||||
// return l.svcCtx.UserService.RegisterUUIDUser(l.ctx)
|
||||
func (l *QueryServiceLogic) GetOrCreateUser() (string, int64, error) {
|
||||
claims, err := ctxdata.GetClaimsFromCtx(l.ctx)
|
||||
if err == nil && claims != nil {
|
||||
return claims.UserId, claims.UserType, nil
|
||||
}
|
||||
userID, regErr := l.svcCtx.UserService.RegisterUUIDUser(l.ctx)
|
||||
if regErr != nil {
|
||||
return "", 0, regErr
|
||||
}
|
||||
return userID, model.UserTypeTemp, nil
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ func (l *QueryShareDetailLogic) encryptShareDetail(detail interface{}, key []byt
|
||||
return encrypted, nil
|
||||
}
|
||||
|
||||
func (l *QueryShareDetailLogic) UpdateFeatureAndProductFeature(productID int64, target *[]types.QueryItem) error {
|
||||
func (l *QueryShareDetailLogic) UpdateFeatureAndProductFeature(productID string, target *[]types.QueryItem) error {
|
||||
// 遍历 target 数组,使用倒序遍历,以便删除元素时不影响索引
|
||||
for i := len(*target) - 1; i >= 0; i-- {
|
||||
queryItem := &(*target)[i]
|
||||
|
||||
Reference in New Issue
Block a user