new feature
This commit is contained in:
@@ -154,7 +154,7 @@ func (l *QueryDetailByOrderIdLogic) QueryDetailByOrderId(req *types.QueryDetailB
|
||||
}
|
||||
|
||||
// ProcessQueryData 解密和反序列化 QueryData
|
||||
func ProcessQueryData(queryData sql.NullString, target *[]map[string]interface{}, key []byte) error {
|
||||
func ProcessQueryData(queryData sql.NullString, target *[]types.QueryItem, key []byte) error {
|
||||
queryDataStr := lzUtils.NullStringToString(queryData)
|
||||
if queryDataStr == "" {
|
||||
return nil
|
||||
|
||||
@@ -6,8 +6,9 @@ import (
|
||||
"tyc-server/app/user/cmd/api/internal/svc"
|
||||
"tyc-server/app/user/cmd/api/internal/types"
|
||||
"tyc-server/common/xerr"
|
||||
"tyc-server/pkg/lzkit/crypto"
|
||||
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/bytedance/sonic"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
@@ -28,38 +29,86 @@ func NewQueryExampleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Quer
|
||||
}
|
||||
|
||||
func (l *QueryExampleLogic) QueryExample(req *types.QueryExampleReq) (resp *types.QueryExampleResp, err error) {
|
||||
// 根据产品特性标识获取产品信息
|
||||
product, err := l.svcCtx.ProductModel.FindOneByProductEn(l.ctx, req.Feature)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "示例报告, 获取商品信息失败: %v", err)
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "示例报告, 获取商品信息失败, %v", err)
|
||||
}
|
||||
exampleModel, err := l.svcCtx.ExampleModel.FindOneByProductId(l.ctx, product.Id)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "示例报告, 获取示例报告失败: %v", err)
|
||||
}
|
||||
var query types.Query
|
||||
query.CreateTime = exampleModel.CreateTime.Format("2006-01-02 15:04:05")
|
||||
query.UpdateTime = exampleModel.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)
|
||||
// 创建一个空的Query结构体来存储结果
|
||||
query := types.Query{
|
||||
ProductName: product.ProductName,
|
||||
QueryData: make([]types.QueryItem, 0),
|
||||
QueryParams: make(map[string]interface{}),
|
||||
}
|
||||
processParamsErr := ProcessQueryParams(exampleModel.QueryParams, &query.QueryParams, key)
|
||||
if processParamsErr != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "示例报告, 报告参数处理失败: %v", processParamsErr)
|
||||
}
|
||||
processErr := ProcessQueryData(exampleModel.QueryData, &query.QueryData, key)
|
||||
if processErr != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "示例报告, 报告结果处理失败: %v", processErr)
|
||||
}
|
||||
// 复制报告数据
|
||||
err = copier.Copy(&query, exampleModel)
|
||||
exampleParams, err := l.svcCtx.ExampleParamsModel.FindOneByProductId(l.ctx, product.Id)
|
||||
if err != 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
|
||||
// 将字符串类型的QueryParams解析为map[string]interface{}
|
||||
var queryParams map[string]interface{}
|
||||
if err := sonic.Unmarshal([]byte(exampleParams.QueryParams), &queryParams); err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "示例报告, 解析示例参数失败, %v", err)
|
||||
}
|
||||
query.QueryParams = queryParams
|
||||
// 查询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
|
||||
|
||||
Reference in New Issue
Block a user