f
This commit is contained in:
@@ -16,6 +16,10 @@ service main {
|
||||
@handler AdminGetQueryDetailByOrderId
|
||||
get /detail/:order_id (AdminGetQueryDetailByOrderIdReq) returns (AdminGetQueryDetailByOrderIdResp)
|
||||
|
||||
@doc "生成报告分享链接(供后台预览 H5)"
|
||||
@handler AdminGenerateQueryShareLink
|
||||
post /generate_share_link (AdminGenerateQueryShareLinkReq) returns (QueryGenerateShareLinkResp)
|
||||
|
||||
@doc "获取清理日志列表"
|
||||
@handler AdminGetQueryCleanupLogList
|
||||
get /cleanup/logs (AdminGetQueryCleanupLogListReq) returns (AdminGetQueryCleanupLogListResp)
|
||||
@@ -37,6 +41,10 @@ service main {
|
||||
OrderId string `path:"order_id"`
|
||||
}
|
||||
|
||||
type AdminGenerateQueryShareLinkReq {
|
||||
OrderId string `json:"order_id"`
|
||||
}
|
||||
|
||||
type AdminGetQueryDetailByOrderIdResp {
|
||||
Id string `json:"id"` // 主键ID
|
||||
OrderId string `json:"order_id"` // 订单ID
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package admin_query
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"qnc-server/app/main/api/internal/logic/admin_query"
|
||||
"qnc-server/app/main/api/internal/svc"
|
||||
"qnc-server/app/main/api/internal/types"
|
||||
"qnc-server/common/result"
|
||||
"qnc-server/pkg/lzkit/validator"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
func AdminGenerateQueryShareLinkHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.AdminGenerateQueryShareLinkReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
result.ParamErrorResult(r, w, err)
|
||||
return
|
||||
}
|
||||
if err := validator.Validate(req); err != nil {
|
||||
result.ParamValidateErrorResult(r, w, err)
|
||||
return
|
||||
}
|
||||
l := admin_query.NewAdminGenerateQueryShareLinkLogic(r.Context(), svcCtx)
|
||||
resp, err := l.AdminGenerateQueryShareLink(&req)
|
||||
result.HttpResult(r, w, resp, err)
|
||||
}
|
||||
}
|
||||
@@ -491,6 +491,12 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
Path: "/detail/:order_id",
|
||||
Handler: admin_query.AdminGetQueryDetailByOrderIdHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 生成报告分享链接(供后台预览 H5)
|
||||
Method: http.MethodPost,
|
||||
Path: "/generate_share_link",
|
||||
Handler: admin_query.AdminGenerateQueryShareLinkHandler(serverCtx),
|
||||
},
|
||||
}...,
|
||||
),
|
||||
rest.WithPrefix("/api/v1/admin/query"),
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
package admin_query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"qnc-server/app/main/api/internal/svc"
|
||||
"qnc-server/app/main/api/internal/types"
|
||||
"qnc-server/app/main/model"
|
||||
"qnc-server/common/xerr"
|
||||
"qnc-server/pkg/lzkit/crypto"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AdminGenerateQueryShareLinkLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewAdminGenerateQueryShareLinkLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminGenerateQueryShareLinkLogic {
|
||||
return &AdminGenerateQueryShareLinkLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AdminGenerateQueryShareLinkLogic) AdminGenerateQueryShareLink(req *types.AdminGenerateQueryShareLinkReq) (resp *types.QueryGenerateShareLinkResp, err error) {
|
||||
if req.OrderId == "" {
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg("订单ID不能为空"), "")
|
||||
}
|
||||
|
||||
order, err := l.svcCtx.OrderModel.FindOne(l.ctx, req.OrderId)
|
||||
if err != nil {
|
||||
if errors.Is(err, model.ErrNotFound) {
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg("订单不存在"), "")
|
||||
}
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "生成分享链接, 获取订单失败: %v", err)
|
||||
}
|
||||
|
||||
if order.Status != model.OrderStatusPaid {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "生成分享链接, 订单未支付")
|
||||
}
|
||||
|
||||
query, err := l.svcCtx.QueryModel.FindOneByOrderId(l.ctx, order.Id)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "生成分享链接, 获取查询失败: %v", err)
|
||||
}
|
||||
|
||||
if query.QueryState != model.QueryStateSuccess {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "生成分享链接, 查询未成功")
|
||||
}
|
||||
|
||||
expireAt := time.Now().Add(time.Duration(l.svcCtx.Config.Query.ShareLinkExpire) * time.Second)
|
||||
payload := types.QueryShareLinkPayload{
|
||||
OrderId: order.Id,
|
||||
ExpireAt: expireAt.Unix(),
|
||||
}
|
||||
secretKey := l.svcCtx.Config.Encrypt.SecretKey
|
||||
key, err := hex.DecodeString(secretKey)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "生成分享链接, 解密失败: %v", err)
|
||||
}
|
||||
payloadBytes, err := json.Marshal(payload)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "生成分享链接, 序列化失败: %v", err)
|
||||
}
|
||||
encryptedPayload, err := crypto.AesEncryptURL(payloadBytes, key)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "生成分享链接, 加密失败: %v", err)
|
||||
}
|
||||
return &types.QueryGenerateShareLinkResp{
|
||||
ShareLink: encryptedPayload,
|
||||
}, nil
|
||||
}
|
||||
@@ -676,6 +676,10 @@ type AdminGetQueryDetailByOrderIdReq struct {
|
||||
OrderId string `path:"order_id"`
|
||||
}
|
||||
|
||||
type AdminGenerateQueryShareLinkReq struct {
|
||||
OrderId string `json:"order_id"`
|
||||
}
|
||||
|
||||
type AdminGetQueryDetailByOrderIdResp struct {
|
||||
Id string `json:"id"` // 主键ID
|
||||
OrderId string `json:"order_id"` // 订单ID
|
||||
|
||||
Reference in New Issue
Block a user