adapter supports fuzzy name query

Signed-off-by: jagger <cossjie@foxmail.com>

Former-commit-id: fd15722cd33fd520a8be56b5fb906551307000ca
This commit is contained in:
jagger 2024-02-28 15:40:02 +08:00
parent 0121f045fb
commit 5df75a03e1
11 changed files with 50 additions and 28 deletions

View File

@ -668,6 +668,14 @@ type (
) )
type ( type (
AdapterQueryReq {
Id string `form:"id,optional" db:"id"`
Name string `form:"name,optional"`
Type string `form:"type,optional"`
Nickname string `form:"nickname,optional"`
Version string `form:"version,optional"`
Server string `form:"server,optional"`
}
AdapterReq { AdapterReq {
Id string `json:"id,optional" db:"id"` Id string `json:"id,optional" db:"id"`
Name string `json:"name,optional"` Name string `json:"name,optional"`

View File

@ -582,7 +582,7 @@ service pcm {
service pcm { service pcm {
@handler AdaptersListHandler @handler AdaptersListHandler
get /adapter/list (AdapterReq) returns (AdapterListResp) get /adapter/list (AdapterQueryReq) returns (AdapterListResp)
@handler CreateAdapterHandler @handler CreateAdapterHandler
post /adapter/create (AdapterReq) returns (AdapterResp) post /adapter/create (AdapterReq) returns (AdapterResp)
@ -611,8 +611,8 @@ service pcm {
@handler GetClusterHandler @handler GetClusterHandler
get /adapter/cluster/get (ClusterDelReq) returns (ClusterResp) get /adapter/cluster/get (ClusterDelReq) returns (ClusterResp)
@handler GetAdapterClusterHandler @handler GetAdapterRelationHandler
get /adapter/relation (AdapterReq) returns (AdapterRelationResp) get /adapter/relation (AdapterQueryReq) returns (AdapterRelationResp)
@handler GetClusterSumHandler @handler GetClusterSumHandler
get /adapter/clusterSum (clusterSumReq) returns (clusterSumReqResp) get /adapter/clusterSum (clusterSumReq) returns (clusterSumReqResp)

View File

@ -11,7 +11,7 @@ import (
func AdaptersListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { func AdaptersListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
var req types.AdapterReq var req types.AdapterQueryReq
if err := httpx.Parse(r, &req); err != nil { if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err) result.ParamErrorResult(r, w, err)
return return

View File

@ -9,16 +9,16 @@ import (
"net/http" "net/http"
) )
func GetAdapterClusterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { func GetAdapterRelationHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
var req types.AdapterReq var req types.AdapterQueryReq
if err := httpx.Parse(r, &req); err != nil { if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err) result.ParamErrorResult(r, w, err)
return return
} }
l := adapters.NewGetAdapterClusterLogic(r.Context(), svcCtx) l := adapters.NewGetAdapterRelationLogic(r.Context(), svcCtx)
resp, err := l.GetAdapterCluster(&req) resp, err := l.GetAdapterRelation(&req)
result.HttpResult(r, w, resp, err) result.HttpResult(r, w, resp, err)
} }
} }

View File

@ -1,28 +1,24 @@
package adapters package adapters
import ( import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx" "github.com/zeromicro/go-zero/rest/httpx"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/logic/adapters" "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/logic/adapters"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc" "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types" "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/repository/result"
"net/http"
) )
func GetClusterSumHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { func GetClusterSumHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
var req types.ClusterSumReq var req types.ClusterSumReq
if err := httpx.Parse(r, &req); err != nil { if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err) result.ParamErrorResult(r, w, err)
return return
} }
l := adapters.NewGetClusterSumLogic(r.Context(), svcCtx) l := adapters.NewGetClusterSumLogic(r.Context(), svcCtx)
resp, err := l.GetClusterSum(&req) resp, err := l.GetClusterSum(&req)
if err != nil { result.HttpResult(r, w, resp, err)
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
} }
} }

View File

@ -750,7 +750,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
{ {
Method: http.MethodGet, Method: http.MethodGet,
Path: "/adapter/relation", Path: "/adapter/relation",
Handler: adapters.GetAdapterClusterHandler(serverCtx), Handler: adapters.GetAdapterRelationHandler(serverCtx),
}, },
{ {
Method: http.MethodGet, Method: http.MethodGet,

View File

@ -2,6 +2,7 @@ package adapters
import ( import (
"context" "context"
"fmt"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc" "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types" "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
@ -23,9 +24,13 @@ func NewAdaptersListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Adap
} }
} }
func (l *AdaptersListLogic) AdaptersList(req *types.AdapterReq) (resp *types.AdapterListResp, err error) { func (l *AdaptersListLogic) AdaptersList(req *types.AdapterQueryReq) (resp *types.AdapterListResp, err error) {
resp = &types.AdapterListResp{} resp = &types.AdapterListResp{}
tx := l.svcCtx.DbEngin.Raw("select * from t_adapter where `deleted_at` IS NULL ORDER BY create_time Desc").Scan(&resp.List) sqlStr := "select * from t_adapter where `deleted_at` IS NULL ORDER BY create_time Desc"
if req.Name != "" {
sqlStr = fmt.Sprintf("select * from t_adapter where `deleted_at` IS NULL and name like '%%%s%%' ORDER BY create_time Desc", req.Name)
}
tx := l.svcCtx.DbEngin.Raw(sqlStr).Scan(&resp.List)
if tx.Error != nil { if tx.Error != nil {
logx.Errorf(tx.Error.Error()) logx.Errorf(tx.Error.Error())
return nil, tx.Error return nil, tx.Error

View File

@ -2,6 +2,7 @@ package adapters
import ( import (
"context" "context"
"fmt"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/utils" "gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/utils"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc" "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
@ -10,24 +11,28 @@ import (
"github.com/zeromicro/go-zero/core/logx" "github.com/zeromicro/go-zero/core/logx"
) )
type GetAdapterClusterLogic struct { type GetAdapterRelationLogic struct {
logx.Logger logx.Logger
ctx context.Context ctx context.Context
svcCtx *svc.ServiceContext svcCtx *svc.ServiceContext
} }
func NewGetAdapterClusterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetAdapterClusterLogic { func NewGetAdapterRelationLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetAdapterRelationLogic {
return &GetAdapterClusterLogic{ return &GetAdapterRelationLogic{
Logger: logx.WithContext(ctx), Logger: logx.WithContext(ctx),
ctx: ctx, ctx: ctx,
svcCtx: svcCtx, svcCtx: svcCtx,
} }
} }
func (l *GetAdapterClusterLogic) GetAdapterCluster(req *types.AdapterReq) (resp *types.AdapterRelationResp, err error) { func (l *GetAdapterRelationLogic) GetAdapterRelation(req *types.AdapterQueryReq) (resp *types.AdapterRelationResp, err error) {
resp = &types.AdapterRelationResp{} resp = &types.AdapterRelationResp{}
adapter := make([]types.AdapterInfo, 0) adapter := make([]types.AdapterInfo, 0)
tx := l.svcCtx.DbEngin.Raw("select * from t_adapter where `deleted_at` IS NULL ORDER BY create_time Desc").Scan(&adapter) sqlStr := "select * from t_adapter where `deleted_at` IS NULL ORDER BY create_time Desc"
if req.Name != "" {
sqlStr = fmt.Sprintf("select * from t_adapter where `deleted_at` IS NULL and name like '%%%s%%' ORDER BY create_time Desc", req.Name)
}
tx := l.svcCtx.DbEngin.Raw(sqlStr).Scan(&adapter)
if tx.Error != nil { if tx.Error != nil {
logx.Errorf(tx.Error.Error()) logx.Errorf(tx.Error.Error())
return nil, tx.Error return nil, tx.Error

View File

@ -629,6 +629,15 @@ type AppResp struct {
Data interface{} `json:"data,omitempty"` Data interface{} `json:"data,omitempty"`
} }
type AdapterQueryReq struct {
Id string `form:"id,optional" db:"id"`
Name string `form:"name,optional"`
Type string `form:"type,optional"`
Nickname string `form:"nickname,optional"`
Version string `form:"version,optional"`
Server string `form:"server,optional"`
}
type AdapterReq struct { type AdapterReq struct {
Id string `json:"id,optional" db:"id"` Id string `json:"id,optional" db:"id"`
Name string `json:"name,optional"` Name string `json:"name,optional"`

View File

@ -53,7 +53,6 @@ func NewHttpsClient() *resty.Client {
c.SetTimeout(5 * time.Second) c.SetTimeout(5 * time.Second)
c.SetRetryCount(3) c.SetRetryCount(3)
//debug := nacos.GetConfig("httpclient.debug")
debug := "true" debug := "true"
if len(debug) > 0 && debug == "ON" { if len(debug) > 0 && debug == "ON" {
c.SetDebug(true) c.SetDebug(true)

View File

@ -16,7 +16,7 @@ package utils
import ( import (
"github.com/bwmarrin/snowflake" "github.com/bwmarrin/snowflake"
"github.com/nacos-group/nacos-sdk-go/v2/common/logger" "github.com/zeromicro/go-zero/core/logx"
) )
var node *snowflake.Node var node *snowflake.Node
@ -24,7 +24,7 @@ var node *snowflake.Node
func InitSnowflake(machineID int64) (err error) { func InitSnowflake(machineID int64) (err error) {
node, err = snowflake.NewNode(machineID) node, err = snowflake.NewNode(machineID)
if err != nil { if err != nil {
logger.Errorf("snowflake Init error : s%", err) logx.Errorf("snowflake Init error : %s", err)
return return
} }
@ -37,7 +37,7 @@ func GenSnowflakeID() int64 {
return node.Generate().Int64() return node.Generate().Int64()
} }
// machineId 工作id // GenSnowflakeIDStr 工作id
func GenSnowflakeIDStr() string { func GenSnowflakeIDStr() string {
return node.Generate().String() return node.Generate().String()
} }