2025-01-10 00:09:25 +08:00
|
|
|
package query
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"encoding/hex"
|
|
|
|
"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"
|
|
|
|
|
|
|
|
"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 {
|
2025-01-20 22:50:54 +08:00
|
|
|
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
|
|
|
|
|
2025-01-10 00:09:25 +08:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
// 复制报告数据
|
|
|
|
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
|
|
|
|
}
|