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 (
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 {
Id string `json:"id,optional" db:"id"`
Name string `json:"name,optional"`

View File

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

View File

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

View File

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

View File

@ -1,28 +1,24 @@
package adapters
import (
"net/http"
"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/svc"
"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 {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ClusterSumReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.ParamErrorResult(r, w, err)
return
}
l := adapters.NewGetClusterSumLogic(r.Context(), svcCtx)
resp, err := l.GetClusterSum(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
result.HttpResult(r, w, resp, err)
}
}

View File

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

View File

@ -2,6 +2,7 @@ package adapters
import (
"context"
"fmt"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
"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{}
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 {
logx.Errorf(tx.Error.Error())
return nil, tx.Error

View File

@ -2,6 +2,7 @@ package adapters
import (
"context"
"fmt"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/utils"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
@ -10,24 +11,28 @@ import (
"github.com/zeromicro/go-zero/core/logx"
)
type GetAdapterClusterLogic struct {
type GetAdapterRelationLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetAdapterClusterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetAdapterClusterLogic {
return &GetAdapterClusterLogic{
func NewGetAdapterRelationLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetAdapterRelationLogic {
return &GetAdapterRelationLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
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{}
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 {
logx.Errorf(tx.Error.Error())
return nil, tx.Error

View File

@ -629,6 +629,15 @@ type AppResp struct {
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 {
Id string `json:"id,optional" db:"id"`
Name string `json:"name,optional"`

View File

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

View File

@ -16,7 +16,7 @@ package utils
import (
"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
@ -24,7 +24,7 @@ var node *snowflake.Node
func InitSnowflake(machineID int64) (err error) {
node, err = snowflake.NewNode(machineID)
if err != nil {
logger.Errorf("snowflake Init error : s%", err)
logx.Errorf("snowflake Init error : %s", err)
return
}
@ -37,7 +37,7 @@ func GenSnowflakeID() int64 {
return node.Generate().Int64()
}
// machineId 工作id
// GenSnowflakeIDStr 工作id
func GenSnowflakeIDStr() string {
return node.Generate().String()
}