fix
This commit is contained in:
@@ -28,11 +28,17 @@ func NewQueryExampleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Quer
|
||||
}
|
||||
}
|
||||
|
||||
func (l *QueryExampleLogic) QueryExample(req *types.QueryExampleReq) (resp *types.QueryExampleResp, err error) {
|
||||
func (l *QueryExampleLogic) QueryExample(req *types.QueryExampleReq) (resp string, err error) {
|
||||
// 根据产品特性标识获取产品信息
|
||||
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)
|
||||
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "示例报告, 获取商品信息失败, %v", err)
|
||||
}
|
||||
|
||||
secretKeyHex := l.svcCtx.Config.Encrypt.SecretKey
|
||||
key, decodeErr := hex.DecodeString(secretKeyHex)
|
||||
if decodeErr != nil {
|
||||
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "示例报告, 解析AES密钥失败, %v", decodeErr)
|
||||
}
|
||||
|
||||
// 创建一个空的Query结构体来存储结果
|
||||
@@ -51,7 +57,7 @@ func (l *QueryExampleLogic) QueryExample(req *types.QueryExampleReq) (resp *type
|
||||
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)
|
||||
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "示例报告, 查询 ProductFeatureModel 错误: %v", err)
|
||||
}
|
||||
// 从每个启用的特性获取示例数据并合并
|
||||
for _, pf := range productFeatures {
|
||||
@@ -76,11 +82,6 @@ func (l *QueryExampleLogic) QueryExample(req *types.QueryExampleReq) (resp *type
|
||||
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
|
||||
@@ -88,11 +89,11 @@ func (l *QueryExampleLogic) QueryExample(req *types.QueryExampleReq) (resp *type
|
||||
// 解密数据
|
||||
decryptedData, decryptErr := crypto.AesDecrypt(example.Content, key)
|
||||
if decryptErr != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "示例报告, 解密数据失败: %v", decryptErr)
|
||||
return "", 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)
|
||||
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "示例报告, 解析示例内容失败: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,7 +106,15 @@ func (l *QueryExampleLogic) QueryExample(req *types.QueryExampleReq) (resp *type
|
||||
query.QueryData = append(query.QueryData, queryItem)
|
||||
}
|
||||
|
||||
return &types.QueryExampleResp{
|
||||
Query: query,
|
||||
}, nil
|
||||
queryBytes, marshalErr := sonic.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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user