add updateQueryData
This commit is contained in:
parent
1df6d7c9f1
commit
5dc96899e7
@ -102,9 +102,7 @@ service main {
|
||||
@handler queryDetailByOrderNo
|
||||
get /query/orderNo/:order_no (QueryDetailByOrderNoReq) returns (QueryDetailByOrderNoResp)
|
||||
|
||||
@doc "查询详情"
|
||||
@handler queryDetail
|
||||
get /query/:id (QueryDetailReq) returns (QueryDetailResp)
|
||||
|
||||
|
||||
@doc "重试查询"
|
||||
@handler queryRetry
|
||||
@ -187,6 +185,14 @@ type (
|
||||
service main {
|
||||
@handler querySingleTest
|
||||
post /query/single/test (QuerySingleTestReq) returns (QuerySingleTestResp)
|
||||
|
||||
@doc "查询详情"
|
||||
@handler queryDetail
|
||||
get /query/:id (QueryDetailReq) returns (QueryDetailResp)
|
||||
|
||||
@doc "更新查询数据"
|
||||
@handler updateQueryData
|
||||
post /query/update_data (UpdateQueryDataReq) returns (UpdateQueryDataResp)
|
||||
}
|
||||
|
||||
type QuerySingleTestReq {
|
||||
@ -198,3 +204,14 @@ type QuerySingleTestResp {
|
||||
Data interface{} `json:"data"`
|
||||
Api string `json:"api"`
|
||||
}
|
||||
|
||||
type (
|
||||
UpdateQueryDataReq {
|
||||
Id int64 `json:"id"` // 查询ID
|
||||
QueryData string `json:"query_data"` // 查询数据(未加密的JSON)
|
||||
}
|
||||
UpdateQueryDataResp {
|
||||
Id int64 `json:"id"`
|
||||
UpdatedAt string `json:"updated_at"` // 更新时间
|
||||
}
|
||||
)
|
@ -0,0 +1,31 @@
|
||||
package query
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"tydata-server/app/user/cmd/api/internal/logic/query"
|
||||
"tydata-server/app/user/cmd/api/internal/svc"
|
||||
"tydata-server/app/user/cmd/api/internal/types"
|
||||
"tydata-server/common/result"
|
||||
"tydata-server/pkg/lzkit/validator"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
// 更新查询数据
|
||||
func UpdateQueryDataHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.UpdateQueryDataReq
|
||||
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 := query.NewUpdateQueryDataLogic(r.Context(), svcCtx)
|
||||
resp, err := l.UpdateQueryData(&req)
|
||||
result.HttpResult(r, w, resp, err)
|
||||
}
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.7.3
|
||||
|
||||
package handler
|
||||
|
||||
import (
|
||||
@ -257,12 +259,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
|
||||
server.AddRoutes(
|
||||
[]rest.Route{
|
||||
{
|
||||
// 查询详情
|
||||
Method: http.MethodGet,
|
||||
Path: "/query/:id",
|
||||
Handler: query.QueryDetailHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 查询示例
|
||||
Method: http.MethodGet,
|
||||
@ -306,11 +302,23 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
|
||||
server.AddRoutes(
|
||||
[]rest.Route{
|
||||
{
|
||||
// 查询详情
|
||||
Method: http.MethodGet,
|
||||
Path: "/query/:id",
|
||||
Handler: query.QueryDetailHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/query/single/test",
|
||||
Handler: query.QuerySingleTestHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 更新查询数据
|
||||
Method: http.MethodPost,
|
||||
Path: "/query/update_data",
|
||||
Handler: query.UpdateQueryDataHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
rest.WithPrefix("/api/v1"),
|
||||
)
|
||||
|
@ -0,0 +1,71 @@
|
||||
package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/hex"
|
||||
|
||||
"tydata-server/app/user/cmd/api/internal/svc"
|
||||
"tydata-server/app/user/cmd/api/internal/types"
|
||||
"tydata-server/app/user/model"
|
||||
"tydata-server/common/xerr"
|
||||
"tydata-server/pkg/lzkit/crypto"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UpdateQueryDataLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 更新查询数据
|
||||
func NewUpdateQueryDataLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateQueryDataLogic {
|
||||
return &UpdateQueryDataLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UpdateQueryDataLogic) UpdateQueryData(req *types.UpdateQueryDataReq) (resp *types.UpdateQueryDataResp, err error) {
|
||||
// 1. 从数据库中获取查询记录
|
||||
query, err := l.svcCtx.QueryModel.FindOne(l.ctx, req.Id)
|
||||
if err != nil {
|
||||
if err == model.ErrNotFound {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询记录不存在, 查询ID: %d", req.Id)
|
||||
}
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询数据库失败, 查询ID: %d, err: %v", req.Id, err)
|
||||
}
|
||||
|
||||
// 2. 获取加密密钥
|
||||
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", decodeErr)
|
||||
}
|
||||
|
||||
// 3. 加密数据 - 传入的是JSON,需要加密处理
|
||||
encryptData, aesEncryptErr := crypto.AesEncrypt([]byte(req.QueryData), key)
|
||||
if aesEncryptErr != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "加密查询数据失败: %v", aesEncryptErr)
|
||||
}
|
||||
|
||||
// 4. 更新数据库记录
|
||||
query.QueryData = sql.NullString{
|
||||
String: encryptData,
|
||||
Valid: true,
|
||||
}
|
||||
updateErr := l.svcCtx.QueryModel.UpdateWithVersion(l.ctx, nil, query)
|
||||
if updateErr != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "更新查询数据失败: %v", updateErr)
|
||||
}
|
||||
|
||||
// 5. 返回结果
|
||||
return &types.UpdateQueryDataResp{
|
||||
Id: query.Id,
|
||||
UpdatedAt: query.UpdateTime.Format("2006-01-02 15:04:05"),
|
||||
}, nil
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.7.3
|
||||
|
||||
package types
|
||||
|
||||
type ActiveReward struct {
|
||||
@ -398,6 +400,16 @@ type TimeRangeReport struct {
|
||||
Report int `json:"report"` // 报告量
|
||||
}
|
||||
|
||||
type UpdateQueryDataReq struct {
|
||||
Id int64 `json:"id"` // 查询ID
|
||||
QueryData string `json:"query_data"` // 查询数据(未加密的JSON)
|
||||
}
|
||||
|
||||
type UpdateQueryDataResp struct {
|
||||
Id int64 `json:"id"`
|
||||
UpdatedAt string `json:"updated_at"` // 更新时间
|
||||
}
|
||||
|
||||
type User struct {
|
||||
Id int64 `json:"id"`
|
||||
Mobile string `json:"mobile"`
|
||||
|
Loading…
Reference in New Issue
Block a user