fix
This commit is contained in:
@@ -93,11 +93,11 @@ service main {
|
|||||||
|
|
||||||
@doc "查询详情 按订单号 付款查询时"
|
@doc "查询详情 按订单号 付款查询时"
|
||||||
@handler queryDetailByOrderId
|
@handler queryDetailByOrderId
|
||||||
get /query/orderId/:order_id (QueryDetailByOrderIdReq) returns (QueryDetailByOrderIdResp)
|
get /query/orderId/:order_id (QueryDetailByOrderIdReq) returns (string)
|
||||||
|
|
||||||
@doc "查询详情 按订单号"
|
@doc "查询详情 按订单号"
|
||||||
@handler queryDetailByOrderNo
|
@handler queryDetailByOrderNo
|
||||||
get /query/orderNo/:order_no (QueryDetailByOrderNoReq) returns (QueryDetailByOrderNoResp)
|
get /query/orderNo/:order_no (QueryDetailByOrderNoReq) returns (string)
|
||||||
|
|
||||||
@doc "重试查询"
|
@doc "重试查询"
|
||||||
@handler queryRetry
|
@handler queryRetry
|
||||||
@@ -150,27 +150,18 @@ type (
|
|||||||
QueryExampleReq {
|
QueryExampleReq {
|
||||||
Feature string `form:"feature"`
|
Feature string `form:"feature"`
|
||||||
}
|
}
|
||||||
QueryExampleResp {
|
|
||||||
Query
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
QueryDetailByOrderIdReq {
|
QueryDetailByOrderIdReq {
|
||||||
OrderId int64 `path:"order_id"`
|
OrderId int64 `path:"order_id"`
|
||||||
}
|
}
|
||||||
QueryDetailByOrderIdResp {
|
|
||||||
Query
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
QueryDetailByOrderNoReq {
|
QueryDetailByOrderNoReq {
|
||||||
OrderNo string `path:"order_no"`
|
OrderNo string `path:"order_no"`
|
||||||
}
|
}
|
||||||
QueryDetailByOrderNoResp {
|
|
||||||
Query
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
@@ -203,21 +194,17 @@ service main {
|
|||||||
|
|
||||||
@doc "查询详情"
|
@doc "查询详情"
|
||||||
@handler queryShareDetail
|
@handler queryShareDetail
|
||||||
get /query/share/:id (QueryShareDetailReq) returns (QueryShareDetailResp)
|
get /query/share/:id (QueryShareDetailReq) returns (string)
|
||||||
|
|
||||||
@doc "查询示例"
|
@doc "查询示例"
|
||||||
@handler queryExample
|
@handler queryExample
|
||||||
get /query/example (QueryExampleReq) returns (QueryExampleResp)
|
get /query/example (QueryExampleReq) returns (string)
|
||||||
}
|
}
|
||||||
|
|
||||||
type (
|
type (
|
||||||
QueryShareDetailReq {
|
QueryShareDetailReq {
|
||||||
Id string `path:"id"`
|
Id string `path:"id"`
|
||||||
}
|
}
|
||||||
QueryShareDetailResp {
|
|
||||||
Status string `json:"status"`
|
|
||||||
Query
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type QuerySingleTestReq {
|
type QuerySingleTestReq {
|
||||||
|
|||||||
@@ -35,41 +35,41 @@ func NewQueryDetailByOrderIdLogic(ctx context.Context, svcCtx *svc.ServiceContex
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *QueryDetailByOrderIdLogic) QueryDetailByOrderId(req *types.QueryDetailByOrderIdReq) (resp *types.QueryDetailByOrderIdResp, err error) {
|
func (l *QueryDetailByOrderIdLogic) QueryDetailByOrderId(req *types.QueryDetailByOrderIdReq) (resp string, err error) {
|
||||||
// 获取当前用户ID
|
// 获取当前用户ID
|
||||||
userId, err := ctxdata.GetUidFromCtx(l.ctx)
|
userId, err := ctxdata.GetUidFromCtx(l.ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "获取用户ID失败: %v", err)
|
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "获取用户ID失败: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取订单信息
|
// 获取订单信息
|
||||||
order, err := l.svcCtx.OrderModel.FindOne(l.ctx, req.OrderId)
|
order, err := l.svcCtx.OrderModel.FindOne(l.ctx, req.OrderId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, model.ErrNotFound) {
|
if errors.Is(err, model.ErrNotFound) {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.LOGIC_QUERY_NOT_FOUND), "报告查询, 订单不存在: %v", err)
|
return "", errors.Wrapf(xerr.NewErrCode(xerr.LOGIC_QUERY_NOT_FOUND), "报告查询, 订单不存在: %v", err)
|
||||||
}
|
}
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "报告查询, 查找报告错误: %v", err)
|
return "", errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "报告查询, 查找报告错误: %v", err)
|
||||||
}
|
}
|
||||||
user, err := l.svcCtx.UserModel.FindOne(l.ctx, userId)
|
user, err := l.svcCtx.UserModel.FindOne(l.ctx, userId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "报告查询, 查找用户错误: %v", err)
|
return "", errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "报告查询, 查找用户错误: %v", err)
|
||||||
}
|
}
|
||||||
if user.Inside != 1 {
|
if user.Inside != 1 {
|
||||||
// 安全验证:确保订单属于当前用户
|
// 安全验证:确保订单属于当前用户
|
||||||
if order.UserId != userId {
|
if order.UserId != userId {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.LOGIC_QUERY_NOT_FOUND), "无权查看此订单报告")
|
return "", errors.Wrapf(xerr.NewErrCode(xerr.LOGIC_QUERY_NOT_FOUND), "无权查看此订单报告")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查订单状态
|
// 检查订单状态
|
||||||
if order.Status != "paid" {
|
if order.Status != "paid" {
|
||||||
return nil, errors.Wrapf(xerr.NewErrMsg("订单未支付,无法查看报告"), "")
|
return "", errors.Wrapf(xerr.NewErrMsg("订单未支付,无法查看报告"), "")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取报告信息
|
// 获取报告信息
|
||||||
queryModel, err := l.svcCtx.QueryModel.FindOneByOrderId(l.ctx, req.OrderId)
|
queryModel, err := l.svcCtx.QueryModel.FindOneByOrderId(l.ctx, req.OrderId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "报告查询, 查找报告错误: %v", err)
|
return "", errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "报告查询, 查找报告错误: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var query types.Query
|
var query types.Query
|
||||||
@@ -80,34 +80,42 @@ func (l *QueryDetailByOrderIdLogic) QueryDetailByOrderId(req *types.QueryDetailB
|
|||||||
secretKey := l.svcCtx.Config.Encrypt.SecretKey
|
secretKey := l.svcCtx.Config.Encrypt.SecretKey
|
||||||
key, decodeErr := hex.DecodeString(secretKey)
|
key, decodeErr := hex.DecodeString(secretKey)
|
||||||
if decodeErr != nil {
|
if decodeErr != nil {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 获取AES解密解药失败, %v", err)
|
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 获取AES解密解药失败, %v", decodeErr)
|
||||||
}
|
}
|
||||||
processParamsErr := ProcessQueryParams(queryModel.QueryParams, &query.QueryParams, key)
|
processParamsErr := ProcessQueryParams(queryModel.QueryParams, &query.QueryParams, key)
|
||||||
if processParamsErr != nil {
|
if processParamsErr != nil {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 报告参数处理失败: %v", processParamsErr)
|
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 报告参数处理失败: %v", processParamsErr)
|
||||||
}
|
}
|
||||||
processErr := ProcessQueryData(queryModel.QueryData, &query.QueryData, key)
|
processErr := ProcessQueryData(queryModel.QueryData, &query.QueryData, key)
|
||||||
if processErr != nil {
|
if processErr != nil {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 报告结果处理失败: %v", processErr)
|
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 报告结果处理失败: %v", processErr)
|
||||||
}
|
}
|
||||||
updateFeatureAndProductFeatureErr := l.UpdateFeatureAndProductFeature(queryModel.ProductId, &query.QueryData)
|
updateFeatureAndProductFeatureErr := l.UpdateFeatureAndProductFeature(queryModel.ProductId, &query.QueryData)
|
||||||
if updateFeatureAndProductFeatureErr != nil {
|
if updateFeatureAndProductFeatureErr != nil {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 报告结果处理失败: %v", updateFeatureAndProductFeatureErr)
|
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 报告结果处理失败: %v", updateFeatureAndProductFeatureErr)
|
||||||
}
|
}
|
||||||
// 复制报告数据
|
// 复制报告数据
|
||||||
err = copier.Copy(&query, queryModel)
|
err = copier.Copy(&query, queryModel)
|
||||||
if err != nil {
|
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)
|
||||||
}
|
}
|
||||||
product, err := l.svcCtx.ProductModel.FindOne(l.ctx, queryModel.ProductId)
|
product, err := l.svcCtx.ProductModel.FindOne(l.ctx, queryModel.ProductId)
|
||||||
if err != nil {
|
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)
|
||||||
}
|
}
|
||||||
query.ProductName = product.ProductName
|
query.ProductName = product.ProductName
|
||||||
query.Product = product.ProductEn
|
query.Product = product.ProductEn
|
||||||
return &types.QueryDetailByOrderIdResp{
|
queryBytes, marshalErr := json.Marshal(query)
|
||||||
Query: query,
|
if marshalErr != nil {
|
||||||
}, 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
|
||||||
}
|
}
|
||||||
|
|
||||||
// ProcessQueryData 解密和反序列化 QueryData
|
// ProcessQueryData 解密和反序列化 QueryData
|
||||||
|
|||||||
@@ -3,9 +3,11 @@ package query
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"qnc-server/common/ctxdata"
|
"qnc-server/common/ctxdata"
|
||||||
"qnc-server/common/xerr"
|
"qnc-server/common/xerr"
|
||||||
|
"qnc-server/pkg/lzkit/crypto"
|
||||||
|
|
||||||
"github.com/jinzhu/copier"
|
"github.com/jinzhu/copier"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@@ -31,36 +33,36 @@ func NewQueryDetailByOrderNoLogic(ctx context.Context, svcCtx *svc.ServiceContex
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *QueryDetailByOrderNoLogic) QueryDetailByOrderNo(req *types.QueryDetailByOrderNoReq) (resp *types.QueryDetailByOrderNoResp, err error) {
|
func (l *QueryDetailByOrderNoLogic) QueryDetailByOrderNo(req *types.QueryDetailByOrderNoReq) (resp string, err error) {
|
||||||
// 获取当前用户ID
|
// 获取当前用户ID
|
||||||
userId, err := ctxdata.GetUidFromCtx(l.ctx)
|
userId, err := ctxdata.GetUidFromCtx(l.ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "获取用户ID失败: %v", err)
|
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "获取用户ID失败: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取订单信息
|
// 获取订单信息
|
||||||
order, err := l.svcCtx.OrderModel.FindOneByOrderNo(l.ctx, req.OrderNo)
|
order, err := l.svcCtx.OrderModel.FindOneByOrderNo(l.ctx, req.OrderNo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, model.ErrNotFound) {
|
if errors.Is(err, model.ErrNotFound) {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.LOGIC_QUERY_NOT_FOUND), "报告查询, 订单不存在: %v", err)
|
return "", errors.Wrapf(xerr.NewErrCode(xerr.LOGIC_QUERY_NOT_FOUND), "报告查询, 订单不存在: %v", err)
|
||||||
}
|
}
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "报告查询, 查找报告错误: %v", err)
|
return "", errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "报告查询, 查找报告错误: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 安全验证:确保订单属于当前用户
|
// 安全验证:确保订单属于当前用户
|
||||||
if order.UserId != userId {
|
if order.UserId != userId {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.LOGIC_QUERY_NOT_FOUND), "无权查看此订单报告")
|
return "", errors.Wrapf(xerr.NewErrCode(xerr.LOGIC_QUERY_NOT_FOUND), "无权查看此订单报告")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查订单状态
|
// 检查订单状态
|
||||||
if order.Status != "paid" {
|
if order.Status != "paid" {
|
||||||
return nil, errors.Wrapf(xerr.NewErrMsg("订单未支付,无法查看报告"), "")
|
return "", errors.Wrapf(xerr.NewErrMsg("订单未支付,无法查看报告"), "")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取报告信息
|
// 获取报告信息
|
||||||
queryModel, err := l.svcCtx.QueryModel.FindOneByOrderId(l.ctx, order.Id)
|
queryModel, err := l.svcCtx.QueryModel.FindOneByOrderId(l.ctx, order.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "报告查询, 查找报告错误: %v", err)
|
return "", errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "报告查询, 查找报告错误: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var query types.Query
|
var query types.Query
|
||||||
@@ -71,34 +73,42 @@ func (l *QueryDetailByOrderNoLogic) QueryDetailByOrderNo(req *types.QueryDetailB
|
|||||||
secretKey := l.svcCtx.Config.Encrypt.SecretKey
|
secretKey := l.svcCtx.Config.Encrypt.SecretKey
|
||||||
key, decodeErr := hex.DecodeString(secretKey)
|
key, decodeErr := hex.DecodeString(secretKey)
|
||||||
if decodeErr != nil {
|
if decodeErr != nil {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 获取AES解密解药失败, %v", err)
|
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 获取AES解密解药失败, %v", decodeErr)
|
||||||
}
|
}
|
||||||
processParamsErr := ProcessQueryParams(queryModel.QueryParams, &query.QueryParams, key)
|
processParamsErr := ProcessQueryParams(queryModel.QueryParams, &query.QueryParams, key)
|
||||||
if processParamsErr != nil {
|
if processParamsErr != nil {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 报告参数处理失败: %v", processParamsErr)
|
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 报告参数处理失败: %v", processParamsErr)
|
||||||
}
|
}
|
||||||
processErr := ProcessQueryData(queryModel.QueryData, &query.QueryData, key)
|
processErr := ProcessQueryData(queryModel.QueryData, &query.QueryData, key)
|
||||||
if processErr != nil {
|
if processErr != nil {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 报告结果处理失败: %v", processErr)
|
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 报告结果处理失败: %v", processErr)
|
||||||
}
|
}
|
||||||
updateFeatureAndProductFeatureErr := l.UpdateFeatureAndProductFeature(queryModel.ProductId, &query.QueryData)
|
updateFeatureAndProductFeatureErr := l.UpdateFeatureAndProductFeature(queryModel.ProductId, &query.QueryData)
|
||||||
if updateFeatureAndProductFeatureErr != nil {
|
if updateFeatureAndProductFeatureErr != nil {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 报告结果处理失败: %v", updateFeatureAndProductFeatureErr)
|
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 报告结果处理失败: %v", updateFeatureAndProductFeatureErr)
|
||||||
}
|
}
|
||||||
// 复制报告数据
|
// 复制报告数据
|
||||||
err = copier.Copy(&query, queryModel)
|
err = copier.Copy(&query, queryModel)
|
||||||
if err != nil {
|
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)
|
||||||
}
|
}
|
||||||
product, err := l.svcCtx.ProductModel.FindOne(l.ctx, queryModel.ProductId)
|
product, err := l.svcCtx.ProductModel.FindOne(l.ctx, queryModel.ProductId)
|
||||||
if err != nil {
|
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)
|
||||||
}
|
}
|
||||||
query.Product = product.ProductEn
|
query.Product = product.ProductEn
|
||||||
query.ProductName = product.ProductName
|
query.ProductName = product.ProductName
|
||||||
return &types.QueryDetailByOrderNoResp{
|
queryBytes, marshalErr := json.Marshal(query)
|
||||||
Query: query,
|
if marshalErr != nil {
|
||||||
}, 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
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *QueryDetailByOrderNoLogic) UpdateFeatureAndProductFeature(productID int64, target *[]types.QueryItem) error {
|
func (l *QueryDetailByOrderNoLogic) UpdateFeatureAndProductFeature(productID int64, target *[]types.QueryItem) error {
|
||||||
|
|||||||
@@ -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)
|
product, err := l.svcCtx.ProductModel.FindOneByProductEn(l.ctx, req.Feature)
|
||||||
if err != nil {
|
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结构体来存储结果
|
// 创建一个空的Query结构体来存储结果
|
||||||
@@ -51,7 +57,7 @@ func (l *QueryExampleLogic) QueryExample(req *types.QueryExampleReq) (resp *type
|
|||||||
builder := l.svcCtx.ProductFeatureModel.SelectBuilder().Where("product_id = ?", product.Id)
|
builder := l.svcCtx.ProductFeatureModel.SelectBuilder().Where("product_id = ?", product.Id)
|
||||||
productFeatures, err := l.svcCtx.ProductFeatureModel.FindAll(l.ctx, builder, "")
|
productFeatures, err := l.svcCtx.ProductFeatureModel.FindAll(l.ctx, builder, "")
|
||||||
if err != nil {
|
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 {
|
for _, pf := range productFeatures {
|
||||||
@@ -76,11 +82,6 @@ func (l *QueryExampleLogic) QueryExample(req *types.QueryExampleReq) (resp *type
|
|||||||
var queryItem types.QueryItem
|
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" {
|
if example.Content == "000" {
|
||||||
queryItem.Data = example.Content
|
queryItem.Data = example.Content
|
||||||
@@ -88,11 +89,11 @@ func (l *QueryExampleLogic) QueryExample(req *types.QueryExampleReq) (resp *type
|
|||||||
// 解密数据
|
// 解密数据
|
||||||
decryptedData, decryptErr := crypto.AesDecrypt(example.Content, key)
|
decryptedData, decryptErr := crypto.AesDecrypt(example.Content, key)
|
||||||
if decryptErr != nil {
|
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)
|
err = sonic.Unmarshal([]byte(decryptedData), &queryItem.Data)
|
||||||
if err != nil {
|
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)
|
query.QueryData = append(query.QueryData, queryItem)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &types.QueryExampleResp{
|
queryBytes, marshalErr := sonic.Marshal(query)
|
||||||
Query: query,
|
if marshalErr != nil {
|
||||||
}, 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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,49 +32,59 @@ func NewQueryShareDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *QueryShareDetailLogic) QueryShareDetail(req *types.QueryShareDetailReq) (resp *types.QueryShareDetailResp, err error) {
|
func (l *QueryShareDetailLogic) QueryShareDetail(req *types.QueryShareDetailReq) (resp string, err error) {
|
||||||
secretKey := l.svcCtx.Config.Encrypt.SecretKey
|
secretKey := l.svcCtx.Config.Encrypt.SecretKey
|
||||||
key, decodeErr := hex.DecodeString(secretKey)
|
key, decodeErr := hex.DecodeString(secretKey)
|
||||||
if decodeErr != nil {
|
if decodeErr != nil {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 获取AES解密解药失败, %v", err)
|
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 获取AES解密解药失败, %v", decodeErr)
|
||||||
}
|
}
|
||||||
decryptedID, decryptErr := crypto.AesDecryptURL(req.Id, key)
|
decryptedID, decryptErr := crypto.AesDecryptURL(req.Id, key)
|
||||||
if decryptErr != nil {
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
var payload types.QueryShareLinkPayload
|
var payload types.QueryShareLinkPayload
|
||||||
err = sonic.Unmarshal(decryptedID, &payload)
|
err = sonic.Unmarshal(decryptedID, &payload)
|
||||||
if err != nil {
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
type shareDetail struct {
|
||||||
|
Status string `json:"status"`
|
||||||
|
Query *types.Query `json:"query,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查分享链接是否过期
|
// 检查分享链接是否过期
|
||||||
now := time.Now().Unix()
|
now := time.Now().Unix()
|
||||||
if now > payload.ExpireAt {
|
if now > payload.ExpireAt {
|
||||||
return &types.QueryShareDetailResp{
|
expiredResp := shareDetail{
|
||||||
Status: "expired",
|
Status: "expired",
|
||||||
}, nil
|
}
|
||||||
|
encryptedExpired, encryptErr := l.encryptShareDetail(expiredResp, key)
|
||||||
|
if encryptErr != nil {
|
||||||
|
return "", encryptErr
|
||||||
|
}
|
||||||
|
return encryptedExpired, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取订单信息
|
// 获取订单信息
|
||||||
order, err := l.svcCtx.OrderModel.FindOne(l.ctx, payload.OrderId)
|
order, err := l.svcCtx.OrderModel.FindOne(l.ctx, payload.OrderId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, model.ErrNotFound) {
|
if errors.Is(err, model.ErrNotFound) {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.LOGIC_QUERY_NOT_FOUND), "报告查询, 订单不存在: %v", err)
|
return "", errors.Wrapf(xerr.NewErrCode(xerr.LOGIC_QUERY_NOT_FOUND), "报告查询, 订单不存在: %v", err)
|
||||||
}
|
}
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "报告查询, 查找报告错误: %v", err)
|
return "", errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "报告查询, 查找报告错误: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查订单状态
|
// 检查订单状态
|
||||||
if order.Status != "paid" {
|
if order.Status != "paid" {
|
||||||
return nil, errors.Wrapf(xerr.NewErrMsg("订单未支付,无法查看报告"), "")
|
return "", errors.Wrapf(xerr.NewErrMsg("订单未支付,无法查看报告"), "")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取报告信息
|
// 获取报告信息
|
||||||
queryModel, err := l.svcCtx.QueryModel.FindOneByOrderId(l.ctx, order.Id)
|
queryModel, err := l.svcCtx.QueryModel.FindOneByOrderId(l.ctx, order.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "报告查询, 查找报告错误: %v", err)
|
return "", errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "报告查询, 查找报告错误: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var query types.Query
|
var query types.Query
|
||||||
@@ -83,31 +93,51 @@ func (l *QueryShareDetailLogic) QueryShareDetail(req *types.QueryShareDetailReq)
|
|||||||
|
|
||||||
processParamsErr := ProcessQueryParams(queryModel.QueryParams, &query.QueryParams, key)
|
processParamsErr := ProcessQueryParams(queryModel.QueryParams, &query.QueryParams, key)
|
||||||
if processParamsErr != nil {
|
if processParamsErr != nil {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 报告参数处理失败: %v", processParamsErr)
|
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 报告参数处理失败: %v", processParamsErr)
|
||||||
}
|
}
|
||||||
processErr := ProcessQueryData(queryModel.QueryData, &query.QueryData, key)
|
processErr := ProcessQueryData(queryModel.QueryData, &query.QueryData, key)
|
||||||
if processErr != nil {
|
if processErr != nil {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 报告结果处理失败: %v", processErr)
|
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 报告结果处理失败: %v", processErr)
|
||||||
}
|
}
|
||||||
updateFeatureAndProductFeatureErr := l.UpdateFeatureAndProductFeature(queryModel.ProductId, &query.QueryData)
|
updateFeatureAndProductFeatureErr := l.UpdateFeatureAndProductFeature(queryModel.ProductId, &query.QueryData)
|
||||||
if updateFeatureAndProductFeatureErr != nil {
|
if updateFeatureAndProductFeatureErr != nil {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 报告结果处理失败: %v", updateFeatureAndProductFeatureErr)
|
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 报告结果处理失败: %v", updateFeatureAndProductFeatureErr)
|
||||||
}
|
}
|
||||||
// 复制报告数据
|
// 复制报告数据
|
||||||
err = copier.Copy(&query, queryModel)
|
err = copier.Copy(&query, queryModel)
|
||||||
if err != nil {
|
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)
|
||||||
}
|
}
|
||||||
product, err := l.svcCtx.ProductModel.FindOne(l.ctx, queryModel.ProductId)
|
product, err := l.svcCtx.ProductModel.FindOne(l.ctx, queryModel.ProductId)
|
||||||
if err != nil {
|
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)
|
||||||
}
|
}
|
||||||
query.ProductName = product.ProductName
|
query.ProductName = product.ProductName
|
||||||
query.Product = product.ProductEn
|
query.Product = product.ProductEn
|
||||||
return &types.QueryShareDetailResp{
|
successResp := shareDetail{
|
||||||
Status: "success",
|
Status: "success",
|
||||||
Query: query,
|
Query: &query,
|
||||||
}, nil
|
}
|
||||||
|
encryptedSuccess, encryptErr := l.encryptShareDetail(successResp, key)
|
||||||
|
if encryptErr != nil {
|
||||||
|
return "", encryptErr
|
||||||
|
}
|
||||||
|
|
||||||
|
return encryptedSuccess, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *QueryShareDetailLogic) encryptShareDetail(detail interface{}, key []byte) (string, error) {
|
||||||
|
payloadBytes, marshalErr := sonic.Marshal(detail)
|
||||||
|
if marshalErr != nil {
|
||||||
|
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 序列化查询结果失败: %v", marshalErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
encrypted, encryptErr := crypto.AesEncrypt(payloadBytes, key)
|
||||||
|
if encryptErr != nil {
|
||||||
|
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 加密查询结果失败: %v", encryptErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
return encrypted, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *QueryShareDetailLogic) UpdateFeatureAndProductFeature(productID int64, target *[]types.QueryItem) error {
|
func (l *QueryShareDetailLogic) UpdateFeatureAndProductFeature(productID int64, target *[]types.QueryItem) error {
|
||||||
|
|||||||
@@ -1751,26 +1751,14 @@ type QueryDetailByOrderIdReq struct {
|
|||||||
OrderId int64 `path:"order_id"`
|
OrderId int64 `path:"order_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type QueryDetailByOrderIdResp struct {
|
|
||||||
Query
|
|
||||||
}
|
|
||||||
|
|
||||||
type QueryDetailByOrderNoReq struct {
|
type QueryDetailByOrderNoReq struct {
|
||||||
OrderNo string `path:"order_no"`
|
OrderNo string `path:"order_no"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type QueryDetailByOrderNoResp struct {
|
|
||||||
Query
|
|
||||||
}
|
|
||||||
|
|
||||||
type QueryExampleReq struct {
|
type QueryExampleReq struct {
|
||||||
Feature string `form:"feature"`
|
Feature string `form:"feature"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type QueryExampleResp struct {
|
|
||||||
Query
|
|
||||||
}
|
|
||||||
|
|
||||||
type QueryGenerateShareLinkReq struct {
|
type QueryGenerateShareLinkReq struct {
|
||||||
OrderId *int64 `json:"order_id,optional"`
|
OrderId *int64 `json:"order_id,optional"`
|
||||||
OrderNo *string `json:"order_no,optional"`
|
OrderNo *string `json:"order_no,optional"`
|
||||||
@@ -1840,11 +1828,6 @@ type QueryShareDetailReq struct {
|
|||||||
Id string `path:"id"`
|
Id string `path:"id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type QueryShareDetailResp struct {
|
|
||||||
Status string `json:"status"`
|
|
||||||
Query
|
|
||||||
}
|
|
||||||
|
|
||||||
type QuerySingleTestReq struct {
|
type QuerySingleTestReq struct {
|
||||||
Params map[string]interface{} `json:"params"`
|
Params map[string]interface{} `json:"params"`
|
||||||
Api string `json:"api"`
|
Api string `json:"api"`
|
||||||
|
|||||||
Reference in New Issue
Block a user