f
This commit is contained in:
80
app/main/api/desc/admin/admin_query_whitelist.api
Normal file
80
app/main/api/desc/admin/admin_query_whitelist.api
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
syntax = "v1"
|
||||||
|
|
||||||
|
info (
|
||||||
|
title: "查询白名单管理"
|
||||||
|
desc: "代理天远查询白名单接口,并记录操作日志"
|
||||||
|
version: "v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
@server (
|
||||||
|
prefix: /api/v1/admin/query-whitelist
|
||||||
|
group: admin_query_whitelist
|
||||||
|
middleware: AdminAuthInterceptor
|
||||||
|
)
|
||||||
|
service main {
|
||||||
|
// 创建规则(代理天远 /entries)
|
||||||
|
@handler AdminQueryWhitelistCreate
|
||||||
|
post /create (AdminQueryWhitelistCreateReq) returns (AdminQueryWhitelistOpResp)
|
||||||
|
|
||||||
|
// 追加接口(代理天远 /entries/append)
|
||||||
|
@handler AdminQueryWhitelistAppend
|
||||||
|
post /append (AdminQueryWhitelistAppendReq) returns (AdminQueryWhitelistOpResp)
|
||||||
|
|
||||||
|
// 操作记录分页列表
|
||||||
|
@handler AdminQueryWhitelistOpLogList
|
||||||
|
get /op-log/list (AdminQueryWhitelistOpLogListReq) returns (AdminQueryWhitelistOpLogListResp)
|
||||||
|
}
|
||||||
|
|
||||||
|
type (
|
||||||
|
AdminQueryWhitelistCreateReq {
|
||||||
|
Name string `json:"name"` // 姓名,* 表示只按身份证匹配
|
||||||
|
IdCard string `json:"id_card"` // 18位身份证号
|
||||||
|
ApiCodes []string `json:"api_codes"` // 产品编码列表
|
||||||
|
Remark string `json:"remark,optional"` // 备注
|
||||||
|
}
|
||||||
|
AdminQueryWhitelistAppendReq {
|
||||||
|
Name string `json:"name"` // 姓名,* 表示只按身份证匹配
|
||||||
|
IdCard string `json:"id_card"` // 18位身份证号
|
||||||
|
ApiCodes []string `json:"api_codes"` // 产品编码列表
|
||||||
|
Remark string `json:"remark,optional"` // 备注
|
||||||
|
}
|
||||||
|
AdminQueryWhitelistOpResp {
|
||||||
|
Success bool `json:"success"` // 天远是否业务成功
|
||||||
|
TianyuanCode int `json:"tianyuan_code"` // 天远业务码
|
||||||
|
TianyuanMessage string `json:"tianyuan_message"` // 天远返回描述
|
||||||
|
TransactionId string `json:"transaction_id,optional"` // 天远流水号
|
||||||
|
EntryId string `json:"entry_id,optional"` // 规则ID
|
||||||
|
IdCardMasked string `json:"id_card_masked,optional"` // 脱敏身份证号
|
||||||
|
EntryApiCodes []string `json:"entry_api_codes,optional"` // 规则当前产品编码
|
||||||
|
EntryStatus string `json:"entry_status,optional"` // 规则状态
|
||||||
|
}
|
||||||
|
AdminQueryWhitelistOpLogListReq {
|
||||||
|
Page int64 `form:"page,default=1"`
|
||||||
|
PageSize int64 `form:"pageSize,default=20"`
|
||||||
|
IdCard *string `form:"id_card,optional"`
|
||||||
|
Action *string `form:"action,optional"`
|
||||||
|
TianyuanCode *int `form:"tianyuan_code,optional"`
|
||||||
|
}
|
||||||
|
QueryWhitelistOpLogItem {
|
||||||
|
Id int64 `json:"id"`
|
||||||
|
AdminUserId int64 `json:"admin_user_id"`
|
||||||
|
AdminUserName string `json:"admin_user_name"`
|
||||||
|
Action string `json:"action"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
IdCard string `json:"id_card"`
|
||||||
|
IdCardMasked string `json:"id_card_masked"`
|
||||||
|
ApiCodes []string `json:"api_codes"`
|
||||||
|
Remark string `json:"remark"`
|
||||||
|
TianyuanCode int `json:"tianyuan_code"`
|
||||||
|
TianyuanMessage string `json:"tianyuan_message"`
|
||||||
|
TransactionId string `json:"transaction_id"`
|
||||||
|
EntryId string `json:"entry_id"`
|
||||||
|
EntryStatus string `json:"entry_status"`
|
||||||
|
EntryApiCodes []string `json:"entry_api_codes"`
|
||||||
|
CreateTime string `json:"create_time"`
|
||||||
|
}
|
||||||
|
AdminQueryWhitelistOpLogListResp {
|
||||||
|
Total int64 `json:"total"`
|
||||||
|
Items []QueryWhitelistOpLogItem `json:"items"`
|
||||||
|
}
|
||||||
|
)
|
||||||
@@ -30,3 +30,4 @@ import "./admin/admin_agent.api"
|
|||||||
import "./admin/admin_api.api"
|
import "./admin/admin_api.api"
|
||||||
import "./admin/admin_role_api.api"
|
import "./admin/admin_role_api.api"
|
||||||
import "./admin/admin_queue.api"
|
import "./admin/admin_queue.api"
|
||||||
|
import "./admin/admin_query_whitelist.api"
|
||||||
|
|||||||
@@ -94,6 +94,7 @@ Tianyuanapi:
|
|||||||
Key: "04c6b4c559be6d5ba5351c04c8713a64"
|
Key: "04c6b4c559be6d5ba5351c04c8713a64"
|
||||||
BaseURL: "https://api.tianyuanapi.com"
|
BaseURL: "https://api.tianyuanapi.com"
|
||||||
Timeout: 60
|
Timeout: 60
|
||||||
|
WhitelistMgmtKey: "2R12TmEc1e8P3p69RdIoN5Ykjk%H@4orPy7DZv7MXpGByoEL"
|
||||||
Authorization:
|
Authorization:
|
||||||
FileBaseURL: "https://www.tianyuandb.com/api/v1/auth-docs" # 授权书文件访问基础URL
|
FileBaseURL: "https://www.tianyuandb.com/api/v1/auth-docs" # 授权书文件访问基础URL
|
||||||
ExtensionTime: 24 # 佣金解冻延迟时间,单位:24小时
|
ExtensionTime: 24 # 佣金解冻延迟时间,单位:24小时
|
||||||
|
|||||||
@@ -99,6 +99,7 @@ Tianyuanapi:
|
|||||||
Key: "04c6b4c559be6d5ba5351c04c8713a64"
|
Key: "04c6b4c559be6d5ba5351c04c8713a64"
|
||||||
BaseURL: "https://api.tianyuanapi.com"
|
BaseURL: "https://api.tianyuanapi.com"
|
||||||
Timeout: 60
|
Timeout: 60
|
||||||
|
WhitelistMgmtKey: "2R12TmEc1e8P3p69RdIoN5Ykjk%H@4orPy7DZv7MXpGByoEL"
|
||||||
Authorization:
|
Authorization:
|
||||||
FileBaseURL: "https://www.tianyuandb.com/api/v1/auth-docs" # 授权书文件访问基础URL
|
FileBaseURL: "https://www.tianyuandb.com/api/v1/auth-docs" # 授权书文件访问基础URL
|
||||||
ExtensionTime: 24 # 佣金解冻延迟时间,单位:24小时
|
ExtensionTime: 24 # 佣金解冻延迟时间,单位:24小时
|
||||||
@@ -133,6 +133,7 @@ type TianyuanapiConfig struct {
|
|||||||
Key string
|
Key string
|
||||||
BaseURL string
|
BaseURL string
|
||||||
Timeout int64
|
Timeout int64
|
||||||
|
WhitelistMgmtKey string
|
||||||
}
|
}
|
||||||
|
|
||||||
type AuthorizationConfig struct {
|
type AuthorizationConfig struct {
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package admin_query_whitelist
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"tydata-server/app/main/api/internal/logic/admin_query_whitelist"
|
||||||
|
"tydata-server/app/main/api/internal/svc"
|
||||||
|
"tydata-server/app/main/api/internal/types"
|
||||||
|
"tydata-server/common/result"
|
||||||
|
"tydata-server/pkg/lzkit/validator"
|
||||||
|
)
|
||||||
|
|
||||||
|
func AdminQueryWhitelistAppendHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req types.AdminQueryWhitelistAppendReq
|
||||||
|
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_whitelist.NewAdminQueryWhitelistAppendLogic(r.Context(), svcCtx)
|
||||||
|
resp, err := l.AdminQueryWhitelistAppend(&req)
|
||||||
|
result.HttpResult(r, w, resp, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package admin_query_whitelist
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"tydata-server/app/main/api/internal/logic/admin_query_whitelist"
|
||||||
|
"tydata-server/app/main/api/internal/svc"
|
||||||
|
"tydata-server/app/main/api/internal/types"
|
||||||
|
"tydata-server/common/result"
|
||||||
|
"tydata-server/pkg/lzkit/validator"
|
||||||
|
)
|
||||||
|
|
||||||
|
func AdminQueryWhitelistCreateHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req types.AdminQueryWhitelistCreateReq
|
||||||
|
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_whitelist.NewAdminQueryWhitelistCreateLogic(r.Context(), svcCtx)
|
||||||
|
resp, err := l.AdminQueryWhitelistCreate(&req)
|
||||||
|
result.HttpResult(r, w, resp, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package admin_query_whitelist
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"tydata-server/app/main/api/internal/logic/admin_query_whitelist"
|
||||||
|
"tydata-server/app/main/api/internal/svc"
|
||||||
|
"tydata-server/app/main/api/internal/types"
|
||||||
|
"tydata-server/common/result"
|
||||||
|
"tydata-server/pkg/lzkit/validator"
|
||||||
|
)
|
||||||
|
|
||||||
|
func AdminQueryWhitelistOpLogListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req types.AdminQueryWhitelistOpLogListReq
|
||||||
|
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_whitelist.NewAdminQueryWhitelistOpLogListLogic(r.Context(), svcCtx)
|
||||||
|
resp, err := l.AdminQueryWhitelistOpLogList(&req)
|
||||||
|
result.HttpResult(r, w, resp, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,6 +15,7 @@ import (
|
|||||||
admin_product "tydata-server/app/main/api/internal/handler/admin_product"
|
admin_product "tydata-server/app/main/api/internal/handler/admin_product"
|
||||||
admin_promotion "tydata-server/app/main/api/internal/handler/admin_promotion"
|
admin_promotion "tydata-server/app/main/api/internal/handler/admin_promotion"
|
||||||
admin_query "tydata-server/app/main/api/internal/handler/admin_query"
|
admin_query "tydata-server/app/main/api/internal/handler/admin_query"
|
||||||
|
admin_query_whitelist "tydata-server/app/main/api/internal/handler/admin_query_whitelist"
|
||||||
admin_role "tydata-server/app/main/api/internal/handler/admin_role"
|
admin_role "tydata-server/app/main/api/internal/handler/admin_role"
|
||||||
admin_role_api "tydata-server/app/main/api/internal/handler/admin_role_api"
|
admin_role_api "tydata-server/app/main/api/internal/handler/admin_role_api"
|
||||||
admin_user "tydata-server/app/main/api/internal/handler/admin_user"
|
admin_user "tydata-server/app/main/api/internal/handler/admin_user"
|
||||||
@@ -603,6 +604,30 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||||||
rest.WithPrefix("/api/v1/admin/query"),
|
rest.WithPrefix("/api/v1/admin/query"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
server.AddRoutes(
|
||||||
|
rest.WithMiddlewares(
|
||||||
|
[]rest.Middleware{serverCtx.AdminAuthInterceptor},
|
||||||
|
[]rest.Route{
|
||||||
|
{
|
||||||
|
Method: http.MethodPost,
|
||||||
|
Path: "/append",
|
||||||
|
Handler: admin_query_whitelist.AdminQueryWhitelistAppendHandler(serverCtx),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Method: http.MethodPost,
|
||||||
|
Path: "/create",
|
||||||
|
Handler: admin_query_whitelist.AdminQueryWhitelistCreateHandler(serverCtx),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Method: http.MethodGet,
|
||||||
|
Path: "/op-log/list",
|
||||||
|
Handler: admin_query_whitelist.AdminQueryWhitelistOpLogListHandler(serverCtx),
|
||||||
|
},
|
||||||
|
}...,
|
||||||
|
),
|
||||||
|
rest.WithPrefix("/api/v1/admin/query-whitelist"),
|
||||||
|
)
|
||||||
|
|
||||||
server.AddRoutes(
|
server.AddRoutes(
|
||||||
rest.WithMiddlewares(
|
rest.WithMiddlewares(
|
||||||
[]rest.Middleware{serverCtx.AdminAuthInterceptor},
|
[]rest.Middleware{serverCtx.AdminAuthInterceptor},
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package admin_query_whitelist
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"tydata-server/app/main/api/internal/svc"
|
||||||
|
"tydata-server/app/main/api/internal/types"
|
||||||
|
tianyuanapi "tydata-server/app/main/api/internal/service/tianyuanapi_sdk"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AdminQueryWhitelistAppendLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewAdminQueryWhitelistAppendLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminQueryWhitelistAppendLogic {
|
||||||
|
return &AdminQueryWhitelistAppendLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *AdminQueryWhitelistAppendLogic) AdminQueryWhitelistAppend(req *types.AdminQueryWhitelistAppendReq) (resp *types.AdminQueryWhitelistOpResp, err error) {
|
||||||
|
return l.executeWhitelistOp(whitelistOpInput{
|
||||||
|
Action: actionAppend,
|
||||||
|
Name: req.Name,
|
||||||
|
IdCard: req.IdCard,
|
||||||
|
ApiCodes: req.ApiCodes,
|
||||||
|
Remark: req.Remark,
|
||||||
|
}, func(client *tianyuanapi.Client, payload tianyuanapi.WhitelistEntryPayload, mgmtKey string) (*tianyuanapi.WhitelistResponse, error) {
|
||||||
|
return client.AppendWhitelistEntry(payload, mgmtKey)
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package admin_query_whitelist
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"tydata-server/app/main/api/internal/svc"
|
||||||
|
"tydata-server/app/main/api/internal/types"
|
||||||
|
tianyuanapi "tydata-server/app/main/api/internal/service/tianyuanapi_sdk"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AdminQueryWhitelistCreateLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewAdminQueryWhitelistCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminQueryWhitelistCreateLogic {
|
||||||
|
return &AdminQueryWhitelistCreateLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *AdminQueryWhitelistCreateLogic) AdminQueryWhitelistCreate(req *types.AdminQueryWhitelistCreateReq) (resp *types.AdminQueryWhitelistOpResp, err error) {
|
||||||
|
return l.executeWhitelistOp(whitelistOpInput{
|
||||||
|
Action: actionCreate,
|
||||||
|
Name: req.Name,
|
||||||
|
IdCard: req.IdCard,
|
||||||
|
ApiCodes: req.ApiCodes,
|
||||||
|
Remark: req.Remark,
|
||||||
|
}, func(client *tianyuanapi.Client, payload tianyuanapi.WhitelistEntryPayload, mgmtKey string) (*tianyuanapi.WhitelistResponse, error) {
|
||||||
|
return client.CreateWhitelistEntry(payload, mgmtKey)
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -0,0 +1,109 @@
|
|||||||
|
package admin_query_whitelist
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"tydata-server/app/main/api/internal/svc"
|
||||||
|
"tydata-server/app/main/api/internal/types"
|
||||||
|
"tydata-server/app/main/model"
|
||||||
|
"tydata-server/common/globalkey"
|
||||||
|
"tydata-server/common/xerr"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
"github.com/zeromicro/go-zero/core/mr"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AdminQueryWhitelistOpLogListLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewAdminQueryWhitelistOpLogListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminQueryWhitelistOpLogListLogic {
|
||||||
|
return &AdminQueryWhitelistOpLogListLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *AdminQueryWhitelistOpLogListLogic) AdminQueryWhitelistOpLogList(req *types.AdminQueryWhitelistOpLogListReq) (resp *types.AdminQueryWhitelistOpLogListResp, err error) {
|
||||||
|
builder := l.svcCtx.QueryWhitelistOpLogModel.SelectBuilder().
|
||||||
|
Where("del_state = ?", globalkey.DelStateNo)
|
||||||
|
|
||||||
|
if req.IdCard != nil && *req.IdCard != "" {
|
||||||
|
builder = builder.Where("id_card = ?", *req.IdCard)
|
||||||
|
}
|
||||||
|
if req.Action != nil && *req.Action != "" {
|
||||||
|
builder = builder.Where("action = ?", *req.Action)
|
||||||
|
}
|
||||||
|
if req.TianyuanCode != nil {
|
||||||
|
builder = builder.Where("tianyuan_code = ?", *req.TianyuanCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
var total int64
|
||||||
|
var logs []*model.QueryWhitelistOpLog
|
||||||
|
err = mr.Finish(func() error {
|
||||||
|
var err error
|
||||||
|
total, err = l.svcCtx.QueryWhitelistOpLogModel.FindCount(l.ctx, builder, "id")
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询操作记录总数失败 err: %v", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}, func() error {
|
||||||
|
var err error
|
||||||
|
logs, err = l.svcCtx.QueryWhitelistOpLogModel.FindPageListByPage(l.ctx, builder, req.Page, req.PageSize, "id DESC")
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询操作记录列表失败 err: %v", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
adminNameMap := make(map[int64]string)
|
||||||
|
resp = &types.AdminQueryWhitelistOpLogListResp{
|
||||||
|
Total: total,
|
||||||
|
Items: make([]types.QueryWhitelistOpLogItem, 0, len(logs)),
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, log := range logs {
|
||||||
|
adminName := ""
|
||||||
|
if cached, ok := adminNameMap[log.AdminUserId]; ok {
|
||||||
|
adminName = cached
|
||||||
|
} else {
|
||||||
|
adminUser, findErr := l.svcCtx.AdminUserModel.FindOne(l.ctx, log.AdminUserId)
|
||||||
|
if findErr == nil && adminUser != nil {
|
||||||
|
adminName = adminUser.RealName
|
||||||
|
if adminName == "" {
|
||||||
|
adminName = adminUser.Username
|
||||||
|
}
|
||||||
|
}
|
||||||
|
adminNameMap[log.AdminUserId] = adminName
|
||||||
|
}
|
||||||
|
|
||||||
|
item := types.QueryWhitelistOpLogItem{
|
||||||
|
Id: log.Id,
|
||||||
|
AdminUserId: log.AdminUserId,
|
||||||
|
AdminUserName: adminName,
|
||||||
|
Action: log.Action,
|
||||||
|
Name: log.Name,
|
||||||
|
IdCard: log.IdCard,
|
||||||
|
IdCardMasked: log.IdCardMasked.String,
|
||||||
|
ApiCodes: parseJSONStringArray(log.ApiCodes),
|
||||||
|
Remark: log.Remark.String,
|
||||||
|
TianyuanCode: int(log.TianyuanCode),
|
||||||
|
TianyuanMessage: log.TianyuanMessage.String,
|
||||||
|
TransactionId: log.TransactionId.String,
|
||||||
|
EntryId: log.EntryId.String,
|
||||||
|
EntryStatus: log.EntryStatus.String,
|
||||||
|
EntryApiCodes: parseJSONStringArray(log.EntryApiCodes.String),
|
||||||
|
CreateTime: log.CreateTime.Format("2006-01-02 15:04:05"),
|
||||||
|
}
|
||||||
|
resp.Items = append(resp.Items, item)
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
157
app/main/api/internal/logic/admin_query_whitelist/ops_helper.go
Normal file
157
app/main/api/internal/logic/admin_query_whitelist/ops_helper.go
Normal file
@@ -0,0 +1,157 @@
|
|||||||
|
package admin_query_whitelist
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"database/sql"
|
||||||
|
"encoding/json"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"tydata-server/app/main/api/internal/svc"
|
||||||
|
"tydata-server/app/main/api/internal/types"
|
||||||
|
"tydata-server/app/main/model"
|
||||||
|
tianyuanapi "tydata-server/app/main/api/internal/service/tianyuanapi_sdk"
|
||||||
|
"tydata-server/common/ctxdata"
|
||||||
|
"tydata-server/common/xerr"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
actionCreate = "create"
|
||||||
|
actionAppend = "append"
|
||||||
|
)
|
||||||
|
|
||||||
|
var idCardPattern = regexp.MustCompile(`^\d{17}[\dXx]$`)
|
||||||
|
|
||||||
|
type whitelistOpInput struct {
|
||||||
|
Action string
|
||||||
|
Name string
|
||||||
|
IdCard string
|
||||||
|
ApiCodes []string
|
||||||
|
Remark string
|
||||||
|
}
|
||||||
|
|
||||||
|
func validateWhitelistInput(input whitelistOpInput) error {
|
||||||
|
name := strings.TrimSpace(input.Name)
|
||||||
|
if name == "" {
|
||||||
|
return xerr.NewErrMsg("姓名不能为空")
|
||||||
|
}
|
||||||
|
idCard := strings.TrimSpace(input.IdCard)
|
||||||
|
if !idCardPattern.MatchString(idCard) {
|
||||||
|
return xerr.NewErrMsg("身份证号格式不正确")
|
||||||
|
}
|
||||||
|
if len(input.ApiCodes) == 0 {
|
||||||
|
return xerr.NewErrMsg("产品编码不能为空")
|
||||||
|
}
|
||||||
|
for _, code := range input.ApiCodes {
|
||||||
|
if strings.TrimSpace(code) == "" {
|
||||||
|
return xerr.NewErrMsg("产品编码不能为空")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *AdminQueryWhitelistCreateLogic) executeWhitelistOp(input whitelistOpInput, call func(client *tianyuanapi.Client, payload tianyuanapi.WhitelistEntryPayload, mgmtKey string) (*tianyuanapi.WhitelistResponse, error)) (*types.AdminQueryWhitelistOpResp, error) {
|
||||||
|
return executeWhitelistOp(l.ctx, l.svcCtx, input, call)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *AdminQueryWhitelistAppendLogic) executeWhitelistOp(input whitelistOpInput, call func(client *tianyuanapi.Client, payload tianyuanapi.WhitelistEntryPayload, mgmtKey string) (*tianyuanapi.WhitelistResponse, error)) (*types.AdminQueryWhitelistOpResp, error) {
|
||||||
|
return executeWhitelistOp(l.ctx, l.svcCtx, input, call)
|
||||||
|
}
|
||||||
|
|
||||||
|
func executeWhitelistOp(
|
||||||
|
ctx context.Context,
|
||||||
|
svcCtx *svc.ServiceContext,
|
||||||
|
input whitelistOpInput,
|
||||||
|
call func(client *tianyuanapi.Client, payload tianyuanapi.WhitelistEntryPayload, mgmtKey string) (*tianyuanapi.WhitelistResponse, error),
|
||||||
|
) (*types.AdminQueryWhitelistOpResp, error) {
|
||||||
|
if err := validateWhitelistInput(input); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
adminUserId, err := ctxdata.GetUidFromCtx(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "获取管理员信息失败, %+v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
mgmtKey := strings.TrimSpace(svcCtx.Config.Tianyuanapi.WhitelistMgmtKey)
|
||||||
|
if mgmtKey == "" {
|
||||||
|
return nil, xerr.NewErrMsg("未配置天远白名单管理密钥")
|
||||||
|
}
|
||||||
|
if svcCtx.TianyuanapiClient == nil {
|
||||||
|
return nil, xerr.NewErrMsg("天远API客户端未初始化")
|
||||||
|
}
|
||||||
|
|
||||||
|
name := strings.TrimSpace(input.Name)
|
||||||
|
idCard := strings.TrimSpace(strings.ToUpper(input.IdCard))
|
||||||
|
apiCodes := make([]string, 0, len(input.ApiCodes))
|
||||||
|
for _, code := range input.ApiCodes {
|
||||||
|
apiCodes = append(apiCodes, strings.TrimSpace(code))
|
||||||
|
}
|
||||||
|
|
||||||
|
payload := tianyuanapi.WhitelistEntryPayload{
|
||||||
|
Name: name,
|
||||||
|
IdCard: idCard,
|
||||||
|
ApiCodes: apiCodes,
|
||||||
|
Remark: strings.TrimSpace(input.Remark),
|
||||||
|
}
|
||||||
|
|
||||||
|
apiResp, err := call(svcCtx.TianyuanapiClient, payload, mgmtKey)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "调用天远白名单接口失败, %+v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
apiCodesJSON, _ := json.Marshal(apiCodes)
|
||||||
|
opLog := &model.QueryWhitelistOpLog{
|
||||||
|
AdminUserId: adminUserId,
|
||||||
|
Action: input.Action,
|
||||||
|
Name: name,
|
||||||
|
IdCard: idCard,
|
||||||
|
ApiCodes: string(apiCodesJSON),
|
||||||
|
TianyuanCode: int64(apiResp.Code),
|
||||||
|
TianyuanMessage: sql.NullString{String: apiResp.Message, Valid: apiResp.Message != ""},
|
||||||
|
TransactionId: sql.NullString{String: apiResp.TransactionID, Valid: apiResp.TransactionID != ""},
|
||||||
|
}
|
||||||
|
if payload.Remark != "" {
|
||||||
|
opLog.Remark = sql.NullString{String: payload.Remark, Valid: true}
|
||||||
|
}
|
||||||
|
if apiResp.Data != nil {
|
||||||
|
opLog.IdCardMasked = sql.NullString{String: apiResp.Data.IdCardMasked, Valid: apiResp.Data.IdCardMasked != ""}
|
||||||
|
opLog.EntryId = sql.NullString{String: apiResp.Data.Id, Valid: apiResp.Data.Id != ""}
|
||||||
|
opLog.EntryStatus = sql.NullString{String: apiResp.Data.Status, Valid: apiResp.Data.Status != ""}
|
||||||
|
if len(apiResp.Data.ApiCodes) > 0 {
|
||||||
|
entryCodesJSON, _ := json.Marshal(apiResp.Data.ApiCodes)
|
||||||
|
opLog.EntryApiCodes = sql.NullString{String: string(entryCodesJSON), Valid: true}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err = svcCtx.QueryWhitelistOpLogModel.Insert(ctx, nil, opLog); err != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "保存操作记录失败, %+v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
resp := &types.AdminQueryWhitelistOpResp{
|
||||||
|
Success: apiResp.Code == 0,
|
||||||
|
TianyuanCode: apiResp.Code,
|
||||||
|
TianyuanMessage: apiResp.Message,
|
||||||
|
TransactionId: apiResp.TransactionID,
|
||||||
|
}
|
||||||
|
if apiResp.Data != nil {
|
||||||
|
resp.EntryId = apiResp.Data.Id
|
||||||
|
resp.IdCardMasked = apiResp.Data.IdCardMasked
|
||||||
|
resp.EntryApiCodes = apiResp.Data.ApiCodes
|
||||||
|
resp.EntryStatus = apiResp.Data.Status
|
||||||
|
}
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseJSONStringArray(raw string) []string {
|
||||||
|
if strings.TrimSpace(raw) == "" {
|
||||||
|
return []string{}
|
||||||
|
}
|
||||||
|
var items []string
|
||||||
|
if err := json.Unmarshal([]byte(raw), &items); err != nil {
|
||||||
|
return []string{raw}
|
||||||
|
}
|
||||||
|
return items
|
||||||
|
}
|
||||||
134
app/main/api/internal/service/tianyuanapi_sdk/query_whitelist.go
Normal file
134
app/main/api/internal/service/tianyuanapi_sdk/query_whitelist.go
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
package tianyuanapi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
whitelistEntriesPath = "query-whitelist/entries"
|
||||||
|
whitelistEntriesAppendPath = "query-whitelist/entries/append"
|
||||||
|
)
|
||||||
|
|
||||||
|
// WhitelistEntryPayload 查询白名单请求明文
|
||||||
|
type WhitelistEntryPayload struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
IdCard string `json:"id_card"`
|
||||||
|
ApiCodes []string `json:"api_codes"`
|
||||||
|
Remark string `json:"remark,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// WhitelistEntryData 查询白名单响应解密数据
|
||||||
|
type WhitelistEntryData struct {
|
||||||
|
Id string `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
IdCardMasked string `json:"id_card_masked"`
|
||||||
|
ApiCodes []string `json:"api_codes"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
Remark string `json:"remark"`
|
||||||
|
CreatedAt string `json:"created_at"`
|
||||||
|
UpdatedAt string `json:"updated_at"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// WhitelistResponse 查询白名单调用结果(保留天远原始业务码)
|
||||||
|
type WhitelistResponse struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
TransactionID string `json:"transaction_id"`
|
||||||
|
Data *WhitelistEntryData `json:"data,omitempty"`
|
||||||
|
Timeout int64 `json:"timeout"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateWhitelistEntry 创建查询白名单规则
|
||||||
|
func (c *Client) CreateWhitelistEntry(payload WhitelistEntryPayload, mgmtKey string) (*WhitelistResponse, error) {
|
||||||
|
return c.callWhitelist(whitelistEntriesPath, payload, mgmtKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AppendWhitelistEntry 向已有规则追加产品编码
|
||||||
|
func (c *Client) AppendWhitelistEntry(payload WhitelistEntryPayload, mgmtKey string) (*WhitelistResponse, error) {
|
||||||
|
return c.callWhitelist(whitelistEntriesAppendPath, payload, mgmtKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) callWhitelist(path string, payload WhitelistEntryPayload, mgmtKey string) (*WhitelistResponse, error) {
|
||||||
|
startTime := time.Now()
|
||||||
|
|
||||||
|
jsonData, err := json.Marshal(payload)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("参数序列化失败: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
encryptedData, err := c.encrypt(string(jsonData))
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("数据加密失败: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
requestBody := map[string]interface{}{
|
||||||
|
"data": encryptedData,
|
||||||
|
}
|
||||||
|
requestBodyBytes, err := json.Marshal(requestBody)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("请求体序列化失败: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
url := fmt.Sprintf("%s/api/v1/%s", c.baseURL, path)
|
||||||
|
httpReq, err := http.NewRequest(http.MethodPost, url, bytes.NewBuffer(requestBodyBytes))
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("创建HTTP请求失败: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
httpReq.Header.Set("Content-Type", "application/json")
|
||||||
|
httpReq.Header.Set("Access-Id", c.accessID)
|
||||||
|
httpReq.Header.Set("Whitelist-Mgmt-Key", mgmtKey)
|
||||||
|
httpReq.Header.Set("User-Agent", "TianyuanAPI-Go-SDK/1.0.0")
|
||||||
|
|
||||||
|
resp, err := c.client.Do(httpReq)
|
||||||
|
if err != nil {
|
||||||
|
return &WhitelistResponse{
|
||||||
|
Code: -1,
|
||||||
|
Message: "请求失败: " + err.Error(),
|
||||||
|
Timeout: time.Since(startTime).Milliseconds(),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
body, err := io.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return &WhitelistResponse{
|
||||||
|
Code: -1,
|
||||||
|
Message: "读取响应失败: " + err.Error(),
|
||||||
|
Timeout: time.Since(startTime).Milliseconds(),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var apiResp ApiResponse
|
||||||
|
if err := json.Unmarshal(body, &apiResp); err != nil {
|
||||||
|
return &WhitelistResponse{
|
||||||
|
Code: -1,
|
||||||
|
Message: "响应解析失败: " + err.Error(),
|
||||||
|
Timeout: time.Since(startTime).Milliseconds(),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
result := &WhitelistResponse{
|
||||||
|
Code: apiResp.Code,
|
||||||
|
Message: apiResp.Message,
|
||||||
|
TransactionID: apiResp.TransactionID,
|
||||||
|
Timeout: time.Since(startTime).Milliseconds(),
|
||||||
|
}
|
||||||
|
|
||||||
|
if apiResp.Data != "" {
|
||||||
|
decryptedData, err := c.decrypt(apiResp.Data)
|
||||||
|
if err == nil {
|
||||||
|
var entry WhitelistEntryData
|
||||||
|
if json.Unmarshal([]byte(decryptedData), &entry) == nil {
|
||||||
|
result.Data = &entry
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
@@ -85,6 +85,7 @@ type ServiceContext struct {
|
|||||||
ExampleModel model.ExampleModel
|
ExampleModel model.ExampleModel
|
||||||
GlobalNotificationsModel model.GlobalNotificationsModel
|
GlobalNotificationsModel model.GlobalNotificationsModel
|
||||||
AuthorizationDocumentModel model.AuthorizationDocumentModel
|
AuthorizationDocumentModel model.AuthorizationDocumentModel
|
||||||
|
QueryWhitelistOpLogModel model.QueryWhitelistOpLogModel
|
||||||
|
|
||||||
// 服务
|
// 服务
|
||||||
AlipayService *service.AliPayService
|
AlipayService *service.AliPayService
|
||||||
@@ -100,6 +101,7 @@ type ServiceContext struct {
|
|||||||
AdminPromotionLinkStatsService *service.AdminPromotionLinkStatsService
|
AdminPromotionLinkStatsService *service.AdminPromotionLinkStatsService
|
||||||
ImageService *service.ImageService
|
ImageService *service.ImageService
|
||||||
AuthorizationService *service.AuthorizationService
|
AuthorizationService *service.AuthorizationService
|
||||||
|
TianyuanapiClient *tianyuanapi.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewServiceContext 创建服务上下文
|
// NewServiceContext 创建服务上下文
|
||||||
@@ -175,6 +177,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
|||||||
exampleModel := model.NewExampleModel(db, cacheConf)
|
exampleModel := model.NewExampleModel(db, cacheConf)
|
||||||
globalNotificationsModel := model.NewGlobalNotificationsModel(db, cacheConf)
|
globalNotificationsModel := model.NewGlobalNotificationsModel(db, cacheConf)
|
||||||
authorizationDocumentModel := model.NewAuthorizationDocumentModel(db, cacheConf)
|
authorizationDocumentModel := model.NewAuthorizationDocumentModel(db, cacheConf)
|
||||||
|
queryWhitelistOpLogModel := model.NewQueryWhitelistOpLogModel(db, cacheConf)
|
||||||
|
|
||||||
// ============================== 第三方服务初始化 ==============================
|
// ============================== 第三方服务初始化 ==============================
|
||||||
tianyuanapi, err := tianyuanapi.NewClient(tianyuanapi.Config{
|
tianyuanapi, err := tianyuanapi.NewClient(tianyuanapi.Config{
|
||||||
@@ -287,6 +290,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
|||||||
ExampleModel: exampleModel,
|
ExampleModel: exampleModel,
|
||||||
GlobalNotificationsModel: globalNotificationsModel,
|
GlobalNotificationsModel: globalNotificationsModel,
|
||||||
AuthorizationDocumentModel: authorizationDocumentModel,
|
AuthorizationDocumentModel: authorizationDocumentModel,
|
||||||
|
QueryWhitelistOpLogModel: queryWhitelistOpLogModel,
|
||||||
|
|
||||||
// 服务
|
// 服务
|
||||||
AlipayService: alipayService,
|
AlipayService: alipayService,
|
||||||
@@ -302,6 +306,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
|||||||
AdminPromotionLinkStatsService: adminPromotionLinkStatsService,
|
AdminPromotionLinkStatsService: adminPromotionLinkStatsService,
|
||||||
ImageService: imageService,
|
ImageService: imageService,
|
||||||
AuthorizationService: authorizationService,
|
AuthorizationService: authorizationService,
|
||||||
|
TianyuanapiClient: tianyuanapi,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -768,6 +768,44 @@ type AdminQueryItem struct {
|
|||||||
Data interface{} `json:"data"` // 这里可以是 map 或 具体的 struct
|
Data interface{} `json:"data"` // 这里可以是 map 或 具体的 struct
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type AdminQueryWhitelistAppendReq struct {
|
||||||
|
Name string `json:"name"` // 姓名,* 表示只按身份证匹配
|
||||||
|
IdCard string `json:"id_card"` // 18位身份证号
|
||||||
|
ApiCodes []string `json:"api_codes"` // 产品编码列表
|
||||||
|
Remark string `json:"remark,optional"` // 备注
|
||||||
|
}
|
||||||
|
|
||||||
|
type AdminQueryWhitelistCreateReq struct {
|
||||||
|
Name string `json:"name"` // 姓名,* 表示只按身份证匹配
|
||||||
|
IdCard string `json:"id_card"` // 18位身份证号
|
||||||
|
ApiCodes []string `json:"api_codes"` // 产品编码列表
|
||||||
|
Remark string `json:"remark,optional"` // 备注
|
||||||
|
}
|
||||||
|
|
||||||
|
type AdminQueryWhitelistOpLogListReq struct {
|
||||||
|
Page int64 `form:"page,default=1"`
|
||||||
|
PageSize int64 `form:"pageSize,default=20"`
|
||||||
|
IdCard *string `form:"id_card,optional"`
|
||||||
|
Action *string `form:"action,optional"`
|
||||||
|
TianyuanCode *int `form:"tianyuan_code,optional"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type AdminQueryWhitelistOpLogListResp struct {
|
||||||
|
Total int64 `json:"total"`
|
||||||
|
Items []QueryWhitelistOpLogItem `json:"items"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type AdminQueryWhitelistOpResp struct {
|
||||||
|
Success bool `json:"success"` // 天远是否业务成功
|
||||||
|
TianyuanCode int `json:"tianyuan_code"` // 天远业务码
|
||||||
|
TianyuanMessage string `json:"tianyuan_message"` // 天远返回描述
|
||||||
|
TransactionId string `json:"transaction_id,optional"` // 天远流水号
|
||||||
|
EntryId string `json:"entry_id,optional"` // 规则ID
|
||||||
|
IdCardMasked string `json:"id_card_masked,optional"` // 脱敏身份证号
|
||||||
|
EntryApiCodes []string `json:"entry_api_codes,optional"` // 规则当前产品编码
|
||||||
|
EntryStatus string `json:"entry_status,optional"` // 规则状态
|
||||||
|
}
|
||||||
|
|
||||||
type AdminRefundOrderReq struct {
|
type AdminRefundOrderReq struct {
|
||||||
Id int64 `path:"id"` // 订单ID
|
Id int64 `path:"id"` // 订单ID
|
||||||
RefundAmount float64 `json:"refund_amount"` // 退款金额
|
RefundAmount float64 `json:"refund_amount"` // 退款金额
|
||||||
@@ -2075,6 +2113,25 @@ type QuerySingleTestResp struct {
|
|||||||
Api string `json:"api"`
|
Api string `json:"api"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type QueryWhitelistOpLogItem struct {
|
||||||
|
Id int64 `json:"id"`
|
||||||
|
AdminUserId int64 `json:"admin_user_id"`
|
||||||
|
AdminUserName string `json:"admin_user_name"`
|
||||||
|
Action string `json:"action"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
IdCard string `json:"id_card"`
|
||||||
|
IdCardMasked string `json:"id_card_masked"`
|
||||||
|
ApiCodes []string `json:"api_codes"`
|
||||||
|
Remark string `json:"remark"`
|
||||||
|
TianyuanCode int `json:"tianyuan_code"`
|
||||||
|
TianyuanMessage string `json:"tianyuan_message"`
|
||||||
|
TransactionId string `json:"transaction_id"`
|
||||||
|
EntryId string `json:"entry_id"`
|
||||||
|
EntryStatus string `json:"entry_status"`
|
||||||
|
EntryApiCodes []string `json:"entry_api_codes"`
|
||||||
|
CreateTime string `json:"create_time"`
|
||||||
|
}
|
||||||
|
|
||||||
type RecordLinkClickReq struct {
|
type RecordLinkClickReq struct {
|
||||||
Path string `path:"path"` // 链接路径
|
Path string `path:"path"` // 链接路径
|
||||||
}
|
}
|
||||||
@@ -2222,5 +2279,5 @@ type GetAppVersionResp struct {
|
|||||||
type SendSmsReq struct {
|
type SendSmsReq struct {
|
||||||
Mobile string `json:"mobile" validate:"required,mobile"`
|
Mobile string `json:"mobile" validate:"required,mobile"`
|
||||||
CaptchaVerifyParam string `json:"captchaVerifyParam"`
|
CaptchaVerifyParam string `json:"captchaVerifyParam"`
|
||||||
ActionType string `json:"actionType" validate:"omitempty,oneof=login register query agentApply realName bindMobile"`
|
ActionType string `json:"actionType,optional" validate:"oneof=login register query agentApply realName bindMobile"`
|
||||||
}
|
}
|
||||||
|
|||||||
24
app/main/model/queryWhitelistOpLogModel.go
Normal file
24
app/main/model/queryWhitelistOpLogModel.go
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ QueryWhitelistOpLogModel = (*customQueryWhitelistOpLogModel)(nil)
|
||||||
|
|
||||||
|
type (
|
||||||
|
QueryWhitelistOpLogModel interface {
|
||||||
|
queryWhitelistOpLogModel
|
||||||
|
}
|
||||||
|
|
||||||
|
customQueryWhitelistOpLogModel struct {
|
||||||
|
*defaultQueryWhitelistOpLogModel
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewQueryWhitelistOpLogModel(conn sqlx.SqlConn, c cache.CacheConf) QueryWhitelistOpLogModel {
|
||||||
|
return &customQueryWhitelistOpLogModel{
|
||||||
|
defaultQueryWhitelistOpLogModel: newQueryWhitelistOpLogModel(conn, c),
|
||||||
|
}
|
||||||
|
}
|
||||||
372
app/main/model/queryWhitelistOpLogModel_gen.go
Normal file
372
app/main/model/queryWhitelistOpLogModel_gen.go
Normal file
@@ -0,0 +1,372 @@
|
|||||||
|
// Code generated by goctl. DO NOT EDIT!
|
||||||
|
|
||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"database/sql"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"tydata-server/common/globalkey"
|
||||||
|
|
||||||
|
"github.com/Masterminds/squirrel"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||||
|
"github.com/zeromicro/go-zero/core/stringx"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
queryWhitelistOpLogFieldNames = builder.RawFieldNames(&QueryWhitelistOpLog{})
|
||||||
|
queryWhitelistOpLogRows = strings.Join(queryWhitelistOpLogFieldNames, ",")
|
||||||
|
queryWhitelistOpLogRowsExpectAutoSet = strings.Join(stringx.Remove(queryWhitelistOpLogFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
||||||
|
queryWhitelistOpLogRowsWithPlaceHolder = strings.Join(stringx.Remove(queryWhitelistOpLogFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||||
|
|
||||||
|
cacheHmQueryWhitelistOpLogIdPrefix = "cache:tydata:queryWhitelistOpLog:id:"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
queryWhitelistOpLogModel interface {
|
||||||
|
Insert(ctx context.Context, session sqlx.Session, data *QueryWhitelistOpLog) (sql.Result, error)
|
||||||
|
FindOne(ctx context.Context, id int64) (*QueryWhitelistOpLog, error)
|
||||||
|
Update(ctx context.Context, session sqlx.Session, data *QueryWhitelistOpLog) (sql.Result, error)
|
||||||
|
UpdateWithVersion(ctx context.Context, session sqlx.Session, data *QueryWhitelistOpLog) error
|
||||||
|
Trans(ctx context.Context, fn func(context context.Context, session sqlx.Session) error) error
|
||||||
|
SelectBuilder() squirrel.SelectBuilder
|
||||||
|
DeleteSoft(ctx context.Context, session sqlx.Session, data *QueryWhitelistOpLog) error
|
||||||
|
FindSum(ctx context.Context, sumBuilder squirrel.SelectBuilder, field string) (float64, error)
|
||||||
|
FindCount(ctx context.Context, countBuilder squirrel.SelectBuilder, field string) (int64, error)
|
||||||
|
FindAll(ctx context.Context, rowBuilder squirrel.SelectBuilder, orderBy string) ([]*QueryWhitelistOpLog, error)
|
||||||
|
FindPageListByPage(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*QueryWhitelistOpLog, error)
|
||||||
|
FindPageListByPageWithTotal(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*QueryWhitelistOpLog, int64, error)
|
||||||
|
FindPageListByIdDESC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*QueryWhitelistOpLog, error)
|
||||||
|
FindPageListByIdASC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*QueryWhitelistOpLog, error)
|
||||||
|
Delete(ctx context.Context, session sqlx.Session, id int64) error
|
||||||
|
}
|
||||||
|
|
||||||
|
defaultQueryWhitelistOpLogModel struct {
|
||||||
|
sqlc.CachedConn
|
||||||
|
table string
|
||||||
|
}
|
||||||
|
|
||||||
|
QueryWhitelistOpLog struct {
|
||||||
|
Id int64 `db:"id"`
|
||||||
|
CreateTime time.Time `db:"create_time"`
|
||||||
|
UpdateTime time.Time `db:"update_time"`
|
||||||
|
DeleteTime sql.NullTime `db:"delete_time"`
|
||||||
|
DelState int64 `db:"del_state"`
|
||||||
|
Version int64 `db:"version"`
|
||||||
|
AdminUserId int64 `db:"admin_user_id"`
|
||||||
|
Action string `db:"action"`
|
||||||
|
Name string `db:"name"`
|
||||||
|
IdCard string `db:"id_card"`
|
||||||
|
IdCardMasked sql.NullString `db:"id_card_masked"`
|
||||||
|
ApiCodes string `db:"api_codes"`
|
||||||
|
Remark sql.NullString `db:"remark"`
|
||||||
|
TianyuanCode int64 `db:"tianyuan_code"`
|
||||||
|
TianyuanMessage sql.NullString `db:"tianyuan_message"`
|
||||||
|
TransactionId sql.NullString `db:"transaction_id"`
|
||||||
|
EntryId sql.NullString `db:"entry_id"`
|
||||||
|
EntryStatus sql.NullString `db:"entry_status"`
|
||||||
|
EntryApiCodes sql.NullString `db:"entry_api_codes"`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func newQueryWhitelistOpLogModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultQueryWhitelistOpLogModel {
|
||||||
|
return &defaultQueryWhitelistOpLogModel{
|
||||||
|
CachedConn: sqlc.NewConn(conn, c),
|
||||||
|
table: "`query_whitelist_op_log`",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultQueryWhitelistOpLogModel) Insert(ctx context.Context, session sqlx.Session, data *QueryWhitelistOpLog) (sql.Result, error) {
|
||||||
|
data.DelState = globalkey.DelStateNo
|
||||||
|
hmQueryWhitelistOpLogIdKey := fmt.Sprintf("%s%v", cacheHmQueryWhitelistOpLogIdPrefix, data.Id)
|
||||||
|
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||||
|
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, queryWhitelistOpLogRowsExpectAutoSet)
|
||||||
|
if session != nil {
|
||||||
|
return session.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.AdminUserId, data.Action, data.Name, data.IdCard, data.IdCardMasked, data.ApiCodes, data.Remark, data.TianyuanCode, data.TianyuanMessage, data.TransactionId, data.EntryId, data.EntryStatus, data.EntryApiCodes)
|
||||||
|
}
|
||||||
|
return conn.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.AdminUserId, data.Action, data.Name, data.IdCard, data.IdCardMasked, data.ApiCodes, data.Remark, data.TianyuanCode, data.TianyuanMessage, data.TransactionId, data.EntryId, data.EntryStatus, data.EntryApiCodes)
|
||||||
|
}, hmQueryWhitelistOpLogIdKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultQueryWhitelistOpLogModel) FindOne(ctx context.Context, id int64) (*QueryWhitelistOpLog, error) {
|
||||||
|
hmQueryWhitelistOpLogIdKey := fmt.Sprintf("%s%v", cacheHmQueryWhitelistOpLogIdPrefix, id)
|
||||||
|
var resp QueryWhitelistOpLog
|
||||||
|
err := m.QueryRowCtx(ctx, &resp, hmQueryWhitelistOpLogIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||||
|
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", queryWhitelistOpLogRows, m.table)
|
||||||
|
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
||||||
|
})
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
return &resp, nil
|
||||||
|
case sqlc.ErrNotFound:
|
||||||
|
return nil, ErrNotFound
|
||||||
|
default:
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultQueryWhitelistOpLogModel) Update(ctx context.Context, session sqlx.Session, data *QueryWhitelistOpLog) (sql.Result, error) {
|
||||||
|
hmQueryWhitelistOpLogIdKey := fmt.Sprintf("%s%v", cacheHmQueryWhitelistOpLogIdPrefix, data.Id)
|
||||||
|
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||||
|
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, queryWhitelistOpLogRowsWithPlaceHolder)
|
||||||
|
if session != nil {
|
||||||
|
return session.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.AdminUserId, data.Action, data.Name, data.IdCard, data.IdCardMasked, data.ApiCodes, data.Remark, data.TianyuanCode, data.TianyuanMessage, data.TransactionId, data.EntryId, data.EntryStatus, data.EntryApiCodes, data.Id)
|
||||||
|
}
|
||||||
|
return conn.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.AdminUserId, data.Action, data.Name, data.IdCard, data.IdCardMasked, data.ApiCodes, data.Remark, data.TianyuanCode, data.TianyuanMessage, data.TransactionId, data.EntryId, data.EntryStatus, data.EntryApiCodes, data.Id)
|
||||||
|
}, hmQueryWhitelistOpLogIdKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultQueryWhitelistOpLogModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, data *QueryWhitelistOpLog) error {
|
||||||
|
oldVersion := data.Version
|
||||||
|
data.Version += 1
|
||||||
|
|
||||||
|
var sqlResult sql.Result
|
||||||
|
var err error
|
||||||
|
|
||||||
|
hmQueryWhitelistOpLogIdKey := fmt.Sprintf("%s%v", cacheHmQueryWhitelistOpLogIdPrefix, data.Id)
|
||||||
|
sqlResult, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||||
|
query := fmt.Sprintf("update %s set %s where `id` = ? and version = ? ", m.table, queryWhitelistOpLogRowsWithPlaceHolder)
|
||||||
|
if session != nil {
|
||||||
|
return session.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.AdminUserId, data.Action, data.Name, data.IdCard, data.IdCardMasked, data.ApiCodes, data.Remark, data.TianyuanCode, data.TianyuanMessage, data.TransactionId, data.EntryId, data.EntryStatus, data.EntryApiCodes, data.Id, oldVersion)
|
||||||
|
}
|
||||||
|
return conn.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.AdminUserId, data.Action, data.Name, data.IdCard, data.IdCardMasked, data.ApiCodes, data.Remark, data.TianyuanCode, data.TianyuanMessage, data.TransactionId, data.EntryId, data.EntryStatus, data.EntryApiCodes, data.Id, oldVersion)
|
||||||
|
}, hmQueryWhitelistOpLogIdKey)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
updateCount, err := sqlResult.RowsAffected()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if updateCount == 0 {
|
||||||
|
return ErrNoRowsUpdate
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultQueryWhitelistOpLogModel) DeleteSoft(ctx context.Context, session sqlx.Session, data *QueryWhitelistOpLog) error {
|
||||||
|
data.DelState = globalkey.DelStateYes
|
||||||
|
data.DeleteTime = sql.NullTime{Time: time.Now(), Valid: true}
|
||||||
|
if err := m.UpdateWithVersion(ctx, session, data); err != nil {
|
||||||
|
return errors.Wrapf(errors.New("delete soft failed "), "QueryWhitelistOpLogModel delete err : %+v", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultQueryWhitelistOpLogModel) FindSum(ctx context.Context, builder squirrel.SelectBuilder, field string) (float64, error) {
|
||||||
|
if len(field) == 0 {
|
||||||
|
return 0, errors.Wrapf(errors.New("FindSum Least One Field"), "FindSum Least One Field")
|
||||||
|
}
|
||||||
|
|
||||||
|
builder = builder.Columns("IFNULL(SUM(" + field + "),0)")
|
||||||
|
|
||||||
|
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var resp float64
|
||||||
|
err = m.QueryRowNoCacheCtx(ctx, &resp, query, values...)
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
return resp, nil
|
||||||
|
default:
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultQueryWhitelistOpLogModel) FindCount(ctx context.Context, builder squirrel.SelectBuilder, field string) (int64, error) {
|
||||||
|
if len(field) == 0 {
|
||||||
|
return 0, errors.Wrapf(errors.New("FindCount Least One Field"), "FindCount Least One Field")
|
||||||
|
}
|
||||||
|
|
||||||
|
builder = builder.Columns("COUNT(" + field + ")")
|
||||||
|
|
||||||
|
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var resp int64
|
||||||
|
err = m.QueryRowNoCacheCtx(ctx, &resp, query, values...)
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
return resp, nil
|
||||||
|
default:
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultQueryWhitelistOpLogModel) FindAll(ctx context.Context, builder squirrel.SelectBuilder, orderBy string) ([]*QueryWhitelistOpLog, error) {
|
||||||
|
builder = builder.Columns(queryWhitelistOpLogRows)
|
||||||
|
|
||||||
|
if orderBy == "" {
|
||||||
|
builder = builder.OrderBy("id DESC")
|
||||||
|
} else {
|
||||||
|
builder = builder.OrderBy(orderBy)
|
||||||
|
}
|
||||||
|
|
||||||
|
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var resp []*QueryWhitelistOpLog
|
||||||
|
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
return resp, nil
|
||||||
|
default:
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultQueryWhitelistOpLogModel) FindPageListByPage(ctx context.Context, builder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*QueryWhitelistOpLog, error) {
|
||||||
|
builder = builder.Columns(queryWhitelistOpLogRows)
|
||||||
|
|
||||||
|
if orderBy == "" {
|
||||||
|
builder = builder.OrderBy("id DESC")
|
||||||
|
} else {
|
||||||
|
builder = builder.OrderBy(orderBy)
|
||||||
|
}
|
||||||
|
|
||||||
|
if page < 1 {
|
||||||
|
page = 1
|
||||||
|
}
|
||||||
|
offset := (page - 1) * pageSize
|
||||||
|
|
||||||
|
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).Offset(uint64(offset)).Limit(uint64(pageSize)).ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var resp []*QueryWhitelistOpLog
|
||||||
|
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
return resp, nil
|
||||||
|
default:
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultQueryWhitelistOpLogModel) FindPageListByPageWithTotal(ctx context.Context, builder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*QueryWhitelistOpLog, int64, error) {
|
||||||
|
total, err := m.FindCount(ctx, builder, "id")
|
||||||
|
if err != nil {
|
||||||
|
return nil, 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
builder = builder.Columns(queryWhitelistOpLogRows)
|
||||||
|
|
||||||
|
if orderBy == "" {
|
||||||
|
builder = builder.OrderBy("id DESC")
|
||||||
|
} else {
|
||||||
|
builder = builder.OrderBy(orderBy)
|
||||||
|
}
|
||||||
|
|
||||||
|
if page < 1 {
|
||||||
|
page = 1
|
||||||
|
}
|
||||||
|
offset := (page - 1) * pageSize
|
||||||
|
|
||||||
|
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).Offset(uint64(offset)).Limit(uint64(pageSize)).ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return nil, total, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var resp []*QueryWhitelistOpLog
|
||||||
|
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
return resp, total, nil
|
||||||
|
default:
|
||||||
|
return nil, total, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultQueryWhitelistOpLogModel) FindPageListByIdDESC(ctx context.Context, builder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*QueryWhitelistOpLog, error) {
|
||||||
|
builder = builder.Columns(queryWhitelistOpLogRows)
|
||||||
|
|
||||||
|
if preMinId > 0 {
|
||||||
|
builder = builder.Where(" id < ? ", preMinId)
|
||||||
|
}
|
||||||
|
|
||||||
|
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).OrderBy("id DESC").Limit(uint64(pageSize)).ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var resp []*QueryWhitelistOpLog
|
||||||
|
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
return resp, nil
|
||||||
|
default:
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultQueryWhitelistOpLogModel) FindPageListByIdASC(ctx context.Context, builder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*QueryWhitelistOpLog, error) {
|
||||||
|
builder = builder.Columns(queryWhitelistOpLogRows)
|
||||||
|
|
||||||
|
if preMaxId > 0 {
|
||||||
|
builder = builder.Where(" id > ? ", preMaxId)
|
||||||
|
}
|
||||||
|
|
||||||
|
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).OrderBy("id ASC").Limit(uint64(pageSize)).ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var resp []*QueryWhitelistOpLog
|
||||||
|
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
return resp, nil
|
||||||
|
default:
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultQueryWhitelistOpLogModel) Trans(ctx context.Context, fn func(ctx context.Context, session sqlx.Session) error) error {
|
||||||
|
return m.TransactCtx(ctx, func(ctx context.Context, session sqlx.Session) error {
|
||||||
|
return fn(ctx, session)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultQueryWhitelistOpLogModel) SelectBuilder() squirrel.SelectBuilder {
|
||||||
|
return squirrel.Select().From(m.table)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultQueryWhitelistOpLogModel) Delete(ctx context.Context, session sqlx.Session, id int64) error {
|
||||||
|
hmQueryWhitelistOpLogIdKey := fmt.Sprintf("%s%v", cacheHmQueryWhitelistOpLogIdPrefix, id)
|
||||||
|
_, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||||
|
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
||||||
|
if session != nil {
|
||||||
|
return session.ExecCtx(ctx, query, id)
|
||||||
|
}
|
||||||
|
return conn.ExecCtx(ctx, query, id)
|
||||||
|
}, hmQueryWhitelistOpLogIdKey)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultQueryWhitelistOpLogModel) formatPrimary(primary interface{}) string {
|
||||||
|
return fmt.Sprintf("%s%v", cacheHmQueryWhitelistOpLogIdPrefix, primary)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultQueryWhitelistOpLogModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary interface{}) error {
|
||||||
|
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", queryWhitelistOpLogRows, m.table)
|
||||||
|
return conn.QueryRowCtx(ctx, v, query, primary, globalkey.DelStateNo)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultQueryWhitelistOpLogModel) tableName() string {
|
||||||
|
return m.table
|
||||||
|
}
|
||||||
110
deploy/sql/query_whitelist.sql
Normal file
110
deploy/sql/query_whitelist.sql
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
-- 查询白名单功能数据库迁移脚本
|
||||||
|
-- 数据库:tydata
|
||||||
|
|
||||||
|
-- ============================================
|
||||||
|
-- 1. 创建操作记录表
|
||||||
|
-- ============================================
|
||||||
|
CREATE TABLE IF NOT EXISTS `query_whitelist_op_log` (
|
||||||
|
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||||
|
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||||
|
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||||
|
`delete_time` datetime DEFAULT NULL COMMENT '删除时间',
|
||||||
|
`del_state` tinyint NOT NULL DEFAULT '0' COMMENT '删除状态:0=未删除,1=已删除',
|
||||||
|
`version` bigint NOT NULL DEFAULT '0' COMMENT '版本号(乐观锁)',
|
||||||
|
|
||||||
|
`admin_user_id` bigint NOT NULL COMMENT '操作管理员ID',
|
||||||
|
`action` varchar(20) NOT NULL COMMENT '操作类型:create=创建规则,append=追加接口',
|
||||||
|
`name` varchar(50) NOT NULL DEFAULT '*' COMMENT '姓名规则',
|
||||||
|
`id_card` varchar(50) NOT NULL COMMENT '身份证号(明文,供后台审计)',
|
||||||
|
`id_card_masked` varchar(50) DEFAULT NULL COMMENT '天远返回的脱敏身份证号',
|
||||||
|
`api_codes` varchar(2000) NOT NULL COMMENT '本次提交的产品编码(JSON数组)',
|
||||||
|
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
|
||||||
|
`tianyuan_code` int NOT NULL DEFAULT 0 COMMENT '天远 API 业务码',
|
||||||
|
`tianyuan_message` varchar(500) DEFAULT NULL COMMENT '天远 API 返回描述',
|
||||||
|
`transaction_id` varchar(64) DEFAULT NULL COMMENT '天远 API 流水号',
|
||||||
|
`entry_id` varchar(64) DEFAULT NULL COMMENT '天远规则ID(成功时)',
|
||||||
|
`entry_status` varchar(20) DEFAULT NULL COMMENT '规则状态(成功时)',
|
||||||
|
`entry_api_codes` varchar(2000) DEFAULT NULL COMMENT '规则当前产品编码列表(JSON数组,成功时)',
|
||||||
|
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
KEY `idx_admin_user_id` (`admin_user_id`),
|
||||||
|
KEY `idx_id_card` (`id_card`),
|
||||||
|
KEY `idx_action` (`action`),
|
||||||
|
KEY `idx_tianyuan_code` (`tianyuan_code`),
|
||||||
|
KEY `idx_create_time` (`create_time`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='查询白名单操作记录表';
|
||||||
|
|
||||||
|
-- ============================================
|
||||||
|
-- 2. 菜单:新增「查询白名单」
|
||||||
|
-- ============================================
|
||||||
|
|
||||||
|
-- 软删除旧「模块白名单」菜单(如存在)
|
||||||
|
UPDATE `admin_menu`
|
||||||
|
SET `del_state` = 1, `version` = `version` + 1
|
||||||
|
WHERE `path` = '/product-manage/whitelist/list' AND `del_state` = 0;
|
||||||
|
|
||||||
|
-- 软删除曾独立的「查询白名单记录」菜单(如存在)
|
||||||
|
UPDATE `admin_menu`
|
||||||
|
SET `del_state` = 1, `version` = `version` + 1
|
||||||
|
WHERE `path` = '/product-manage/query-whitelist/op-log' AND `del_state` = 0;
|
||||||
|
|
||||||
|
-- 插入「查询白名单」菜单(已存在则跳过)
|
||||||
|
INSERT INTO `admin_menu` (
|
||||||
|
`pid`, `name`, `path`, `component`, `redirect`, `meta`,
|
||||||
|
`status`, `type`, `sort`, `del_state`, `version`
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
m.`id`,
|
||||||
|
'queryWhitelist',
|
||||||
|
'/product-manage/query-whitelist/list',
|
||||||
|
'/product-manage/query-whitelist/list',
|
||||||
|
NULL,
|
||||||
|
JSON_OBJECT('icon', 'lucide:shield-off', 'title', '查询白名单'),
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
FROM `admin_menu` m
|
||||||
|
WHERE m.`path` = '/product-manage' AND m.`del_state` = 0
|
||||||
|
AND NOT EXISTS (
|
||||||
|
SELECT 1 FROM `admin_menu`
|
||||||
|
WHERE `path` = '/product-manage/query-whitelist/list' AND `del_state` = 0
|
||||||
|
)
|
||||||
|
LIMIT 1;
|
||||||
|
|
||||||
|
-- 给「超级管理员」授权
|
||||||
|
INSERT INTO `admin_role_menu` (`role_id`, `menu_id`, `del_state`, `version`)
|
||||||
|
SELECT
|
||||||
|
1,
|
||||||
|
m.`id`,
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
FROM `admin_menu` m
|
||||||
|
WHERE m.`path` = '/product-manage/query-whitelist/list'
|
||||||
|
AND m.`del_state` = 0
|
||||||
|
AND NOT EXISTS (
|
||||||
|
SELECT 1 FROM `admin_role_menu` rm
|
||||||
|
WHERE rm.`role_id` = 1
|
||||||
|
AND rm.`menu_id` = m.`id`
|
||||||
|
AND rm.`del_state` = 0
|
||||||
|
);
|
||||||
|
|
||||||
|
-- 给所有曾拥有「模块白名单」权限的角色同步授权
|
||||||
|
INSERT INTO `admin_role_menu` (`role_id`, `menu_id`, `del_state`, `version`)
|
||||||
|
SELECT
|
||||||
|
arm.`role_id`,
|
||||||
|
m.`id`,
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
FROM `admin_role_menu` arm
|
||||||
|
JOIN `admin_menu` old_m ON old_m.`path` = '/product-manage/whitelist/list'
|
||||||
|
JOIN `admin_menu` m ON m.`path` = '/product-manage/query-whitelist/list' AND m.`del_state` = 0
|
||||||
|
WHERE arm.`menu_id` = old_m.`id`
|
||||||
|
AND arm.`del_state` = 0
|
||||||
|
AND NOT EXISTS (
|
||||||
|
SELECT 1 FROM `admin_role_menu` x
|
||||||
|
WHERE x.`role_id` = arm.`role_id`
|
||||||
|
AND x.`menu_id` = m.`id`
|
||||||
|
AND x.`del_state` = 0
|
||||||
|
);
|
||||||
Reference in New Issue
Block a user