2024-11-21 12:18:28 +08:00
|
|
|
package query
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"encoding/hex"
|
|
|
|
"qnc-server/app/user/cmd/api/internal/svc"
|
|
|
|
"qnc-server/app/user/cmd/api/internal/types"
|
|
|
|
"qnc-server/common/xerr"
|
|
|
|
|
2025-03-20 02:03:28 +08:00
|
|
|
"github.com/jinzhu/copier"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
|
2024-11-21 12:18:28 +08:00
|
|
|
"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) {
|
2025-03-20 02:03:28 +08:00
|
|
|
product, err := l.svcCtx.ProductModel.FindOneByProductEn(l.ctx, req.Feature)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "示例报告, 获取商品信息失败: %v", err)
|
2024-12-28 02:21:47 +08:00
|
|
|
}
|
2025-03-20 02:03:28 +08:00
|
|
|
exampleModel, err := l.svcCtx.ExampleModel.FindOneByProductId(l.ctx, product.Id)
|
2024-11-21 12:18:28 +08:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "示例报告, 获取示例报告失败: %v", err)
|
|
|
|
}
|
|
|
|
var query types.Query
|
2025-03-20 02:03:28 +08:00
|
|
|
query.CreateTime = exampleModel.CreateTime.Format("2006-01-02 15:04:05")
|
|
|
|
query.UpdateTime = exampleModel.UpdateTime.Format("2006-01-02 15:04:05")
|
2024-11-21 12:18:28 +08:00
|
|
|
|
2024-12-28 02:21:47 +08:00
|
|
|
// 解密查询数据
|
2024-11-21 12:18:28 +08:00
|
|
|
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)
|
|
|
|
}
|
2025-03-20 02:03:28 +08:00
|
|
|
processParamsErr := ProcessQueryParams(exampleModel.QueryParams, &query.QueryParams, key)
|
2024-12-28 02:21:47 +08:00
|
|
|
if processParamsErr != nil {
|
|
|
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "示例报告, 报告参数处理失败: %v", processParamsErr)
|
|
|
|
}
|
2025-03-20 02:03:28 +08:00
|
|
|
processErr := ProcessQueryData(exampleModel.QueryData, &query.QueryData, key)
|
2024-11-21 12:18:28 +08:00
|
|
|
if processErr != nil {
|
|
|
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "示例报告, 报告结果处理失败: %v", processErr)
|
|
|
|
}
|
2024-12-28 02:21:47 +08:00
|
|
|
// 复制报告数据
|
2025-03-20 02:03:28 +08:00
|
|
|
err = copier.Copy(&query, exampleModel)
|
2024-12-28 02:21:47 +08:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "示例报告, 报告结构体复制失败, %+v", err)
|
2024-11-21 12:18:28 +08:00
|
|
|
}
|
2024-12-24 11:37:25 +08:00
|
|
|
query.ProductName = product.ProductName
|
2024-11-21 12:18:28 +08:00
|
|
|
return &types.QueryExampleResp{
|
|
|
|
Query: query,
|
|
|
|
}, nil
|
|
|
|
}
|