new feature
This commit is contained in:
@@ -33,8 +33,6 @@ func NewPaymentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PaymentLo
|
||||
}
|
||||
|
||||
func (l *PaymentLogic) Payment(req *types.PaymentReq) (resp *types.PaymentResp, err error) {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "")
|
||||
|
||||
userID, getUidErr := ctxdata.GetUidFromCtx(l.ctx)
|
||||
if getUidErr != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "生成订单, 获取用户信息失败, %+v", getUidErr)
|
||||
|
||||
@@ -3,12 +3,13 @@ package query
|
||||
import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/pkg/errors"
|
||||
"tydata-server/app/user/cmd/api/internal/svc"
|
||||
"tydata-server/app/user/cmd/api/internal/types"
|
||||
"tydata-server/common/xerr"
|
||||
"tydata-server/pkg/lzkit/crypto"
|
||||
|
||||
"github.com/bytedance/sonic"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
@@ -28,124 +29,82 @@ func NewQueryExampleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Quer
|
||||
}
|
||||
|
||||
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)
|
||||
// 根据产品特性标识获取产品信息
|
||||
product, err := l.svcCtx.ProductModel.FindOneByProductEn(l.ctx, req.Feature)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "示例报告, 获取商品信息失败, %v", err)
|
||||
}
|
||||
query.ProductName = product.ProductName
|
||||
|
||||
// 创建一个空的Query结构体来存储结果
|
||||
query := types.Query{
|
||||
ProductName: product.ProductName,
|
||||
QueryData: make([]types.QueryItem, 0),
|
||||
QueryParams: make(map[string]interface{}),
|
||||
}
|
||||
query.QueryParams = map[string]interface{}{
|
||||
"id_card": "45000000000000000",
|
||||
"mobile": "13700000000",
|
||||
"name": "张老三",
|
||||
}
|
||||
// 查询ProductFeatureModel获取产品相关的功能列表
|
||||
builder := l.svcCtx.ProductFeatureModel.SelectBuilder().Where("product_id = ?", product.Id)
|
||||
productFeatures, err := l.svcCtx.ProductFeatureModel.FindAll(l.ctx, builder, "")
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "示例报告, 查询 ProductFeatureModel 错误: %v", err)
|
||||
}
|
||||
// 从每个启用的特性获取示例数据并合并
|
||||
for _, pf := range productFeatures {
|
||||
if pf.Enable != 1 {
|
||||
continue // 跳过未启用的特性
|
||||
}
|
||||
|
||||
// 根据特性ID查找示例数据
|
||||
example, err := l.svcCtx.ExampleModel.FindOneByFeatureId(l.ctx, pf.FeatureId)
|
||||
if err != nil {
|
||||
logx.Infof("示例报告, 特性ID %d 无示例数据: %v", pf.FeatureId, err)
|
||||
continue // 如果没有示例数据就跳过
|
||||
}
|
||||
|
||||
// 获取对应的Feature信息
|
||||
feature, err := l.svcCtx.FeatureModel.FindOne(l.ctx, pf.FeatureId)
|
||||
if err != nil {
|
||||
logx.Infof("示例报告, 无法获取特性ID %d 的信息: %v", pf.FeatureId, err)
|
||||
continue
|
||||
}
|
||||
|
||||
var queryItem types.QueryItem
|
||||
|
||||
// 解密查询数据
|
||||
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)
|
||||
}
|
||||
// 解析示例内容
|
||||
if example.Content == "000" {
|
||||
queryItem.Data = example.Content
|
||||
} else {
|
||||
// 解密数据
|
||||
decryptedData, decryptErr := crypto.AesDecrypt(example.Content, key)
|
||||
if decryptErr != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "示例报告, 解密数据失败: %v", decryptErr)
|
||||
}
|
||||
err = sonic.Unmarshal([]byte(decryptedData), &queryItem.Data)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "示例报告, 解析示例内容失败: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// 添加特性信息
|
||||
queryItem.Feature = map[string]interface{}{
|
||||
"featureName": feature.Name,
|
||||
"sort": pf.Sort,
|
||||
}
|
||||
// 添加到查询数据中
|
||||
query.QueryData = append(query.QueryData, queryItem)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@@ -2,14 +2,15 @@ package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"tydata-server/app/user/cmd/api/internal/svc"
|
||||
"tydata-server/app/user/cmd/api/internal/types"
|
||||
"tydata-server/common/ctxdata"
|
||||
"tydata-server/common/xerr"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type QueryListLogic struct {
|
||||
@@ -31,34 +32,31 @@ func (l *QueryListLogic) QueryList(req *types.QueryListReq) (resp *types.QueryLi
|
||||
if getUidErr != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "报告列表查询, 获取用户信息失败, %+v", getUidErr)
|
||||
}
|
||||
build := l.svcCtx.OrderModel.SelectBuilder().Where(squirrel.Eq{
|
||||
|
||||
// 直接构建查询query表的条件
|
||||
build := l.svcCtx.QueryModel.SelectBuilder().Where(squirrel.Eq{
|
||||
"user_id": userID,
|
||||
}).Where(squirrel.NotEq{
|
||||
"status": []string{"pending", "closed"},
|
||||
})
|
||||
orderList, total, err := l.svcCtx.OrderModel.FindPageListByPageWithTotal(l.ctx, build, req.Page, req.PageSize, "create_time DESC")
|
||||
|
||||
// 直接从query表分页查询
|
||||
queryList, total, err := l.svcCtx.QueryModel.FindPageListByPageWithTotal(l.ctx, build, req.Page, req.PageSize, "create_time DESC")
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "报告列表查询, 查找订单列表错误, %v", err)
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "报告列表查询, 查找报告列表错误, %+v", err)
|
||||
}
|
||||
|
||||
var list []types.Query
|
||||
if len(orderList) > 0 {
|
||||
for _, orderModel := range orderList {
|
||||
queryModel, findQueryErr := l.svcCtx.QueryModel.FindOneByOrderId(l.ctx, orderModel.Id)
|
||||
if findQueryErr != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告列表查询, 查找报告错误, %+v", findQueryErr)
|
||||
|
||||
}
|
||||
if len(queryList) > 0 {
|
||||
for _, queryModel := range queryList {
|
||||
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")
|
||||
copyErr := copier.Copy(&query, queryModel)
|
||||
if copyErr != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告列表查询, 报告结构体复制失败, %v", err)
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告列表查询, 报告结构体复制失败, %+v", err)
|
||||
}
|
||||
product, findProductErr := l.svcCtx.ProductModel.FindOne(l.ctx, queryModel.ProductId)
|
||||
if findProductErr != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告列表查询, 获取商品信息失败, %v", err)
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告列表查询, 获取商品信息失败, %+v", err)
|
||||
}
|
||||
query.ProductName = product.ProductName
|
||||
list = append(list, query)
|
||||
|
||||
Reference in New Issue
Block a user