🐛 fix bugs

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

Former-commit-id: 53a7c41f3f2d4bb67da7c6593893d63d1d4ea189
This commit is contained in:
jagger 2024-03-14 17:06:43 +08:00
parent 8abba1912b
commit 1bd68400ce
23 changed files with 281 additions and 193 deletions

View File

@ -510,6 +510,7 @@ type (
Nickname string `form:"nickname,optional"` Nickname string `form:"nickname,optional"`
Version string `form:"version,optional"` Version string `form:"version,optional"`
Server string `form:"server,optional"` Server string `form:"server,optional"`
PageInfo
} }
AdapterReq { AdapterReq {
Id string `json:"id,optional" db:"id"` Id string `json:"id,optional" db:"id"`
@ -560,54 +561,83 @@ type (
} }
) )
type ClusterReq { type (
Id string `form:"id,optional"` ClusterReq {
AdapterId string `form:"adapterId,optional"` Id string `form:"id,optional"`
Name string `json:"name,optional"` AdapterId string `form:"adapterId,optional"`
Nickname string `json:"nickname,optional"` Name string `form:"name,optional"`
Description string `json:"description,optional"` Nickname string `form:"nickname,optional"`
Server string `json:"server,optional"` Description string `form:"description,optional"`
MonitorServer string `json:"monitorServer,optional"` Server string `form:"server,optional"`
Username string `json:"username,optional"` MonitorServer string `form:"monitorServer,optional"`
Password string `json:"password,optional"` Username string `form:"username,optional"`
Token string `json:"token,optional"` Password string `form:"password,optional"`
Ak string `json:"ak,optional"` Token string `form:"token,optional"`
Sk string `json:"sk,optional"` Ak string `form:"ak,optional"`
Region string `json:"region,optional"` Sk string `form:"sk,optional"`
ProjectId string `json:"projectId,optional"` Region string `form:"region,optional"`
Version string `json:"version,optional"` ProjectId string `form:"projectId,optional"`
Label string `json:"label,optional"` Version string `form:"version,optional"`
OwnerId string `json:"ownerId,omitempty,optional"` Label string `form:"label,optional"`
AuthType string `json:"authType,optional"` OwnerId string `form:"ownerId,omitempty,optional"`
Type string `json:"type,optional"` AuthType string `form:"authType,optional"`
} Type string `form:"type,optional"`
producerDict string `form:"producerDict,optional"`
regionDict string `form:"regionDict,optional"`
PageInfo
}
ClusterCreateReq {
Id string `json:"id,optional"`
AdapterId string `json:"adapterId,optional"`
Name string `json:"name,optional"`
Nickname string `json:"nickname,optional"`
Description string `json:"description,optional"`
Server string `json:"server,optional"`
MonitorServer string `json:"monitorServer,optional"`
Username string `json:"username,optional"`
Password string `json:"password,optional"`
Token string `json:"token,optional"`
Ak string `json:"ak,optional"`
Sk string `json:"sk,optional"`
Region string `json:"region,optional"`
ProjectId string `json:"projectId,optional"`
Version string `json:"version,optional"`
Label string `json:"label,optional"`
OwnerId string `json:"ownerId,omitempty,optional"`
AuthType string `json:"authType,optional"`
producerDict string `json:"producerDict,optional"`
regionDict string `json:"regionDict,optional"`
}
ClusterInfo {
Id string `json:"id,omitempty" db:"id"`
AdapterId string `json:"adapterId,omitempty" db:"adapter_id"`
Name string `json:"name,omitempty" db:"name"`
Nickname string `json:"nickname,omitempty" db:"nickname"`
Description string `json:"description,omitempty" db:"description"`
Server string `json:"server,omitempty" db:"server"`
MonitorServer string `json:"monitorServer,omitempty" db:"monitor_server"`
Username string `json:"username,omitempty" db:"username"`
Password string `json:"password,omitempty" db:"password"`
Token string `json:"token,omitempty" db:"token"`
Ak string `json:"ak,omitempty" db:"ak"`
Sk string `json:"sk,omitempty" db:"sk"`
Region string `json:"region,omitempty" db:"region"`
ProjectId string `json:"projectId,omitempty" db:"project_id"`
Version string `json:"version,omitempty" db:"version"`
Label string `json:"label,omitempty" db:"label"`
OwnerId string `json:"ownerId,omitempty" db:"owner_id"`
AuthType string `json:"authType,omitempty" db:"auth_type"`
producerDict string `json:"producerDict,omitempty" db:"producer_dict"`
regionDict string `json:"regionDict,omitempty" db:"region_dict"`
CreateTime string `json:"createTime,omitempty" db:"created_time" gorm:"autoCreateTime"`
}
)
type ClusterDelReq { type ClusterDelReq {
Id string `form:"id,optional"` Id string `form:"id,optional"`
} }
type ClusterInfo {
Id string `json:"id,omitempty" db:"id"`
AdapterId string `json:"adapterId,omitempty" db:"adapter_id"`
Name string `json:"name,omitempty" db:"name"`
Nickname string `json:"nickname,omitempty" db:"nickname"`
Description string `json:"description,omitempty" db:"description"`
Server string `json:"server,omitempty" db:"server"`
MonitorServer string `json:"monitorServer,omitempty" db:"monitor_server"`
Username string `json:"username,omitempty" db:"username"`
Password string `json:"password,omitempty" db:"password"`
Token string `json:"token,omitempty" db:"token"`
Ak string `json:"ak,omitempty" db:"ak"`
Sk string `json:"sk,omitempty" db:"sk"`
Region string `json:"region,omitempty" db:"region"`
ProjectId string `json:"projectId,omitempty" db:"project_id"`
Version string `json:"version,omitempty" db:"version"`
Label string `json:"label,omitempty" db:"label"`
OwnerId string `json:"ownerId,omitempty" db:"owner_id"`
AuthType string `json:"authType,omitempty" db:"auth_type"`
CreateTime string `json:"createTime,omitempty" db:"created_time" gorm:"autoCreateTime"`
}
type ClusterResp { type ClusterResp {
List ClusterInfo `json:"list,omitempty"` List ClusterInfo `json:"list,omitempty"`
} }
@ -770,6 +800,10 @@ type (
CIds { CIds {
Ids []string `json:"ids,omitempty" validate:"required"` Ids []string `json:"ids,omitempty" validate:"required"`
} }
FId {
Id string `form:"id":"id,omitempty" validate:"required"`
}
) )
type ( type (

View File

@ -806,7 +806,7 @@ service pcm {
service pcm { service pcm {
@handler AdaptersListHandler @handler AdaptersListHandler
get /adapter/list (AdapterQueryReq) returns (AdapterListResp) get /adapter/list (AdapterQueryReq) returns (PageResult)
@handler CreateAdapterHandler @handler CreateAdapterHandler
post /adapter/create (AdapterCreateReq) returns (AdapterResp) post /adapter/create (AdapterCreateReq) returns (AdapterResp)
@ -821,22 +821,22 @@ service pcm {
get /adapter/get (AdapterDelReq) returns (AdapterInfo) get /adapter/get (AdapterDelReq) returns (AdapterInfo)
@handler ClusterListHandler @handler ClusterListHandler
get /adapter/cluster/list (ClusterReq) returns (ClusterListResp) get /adapter/cluster/list (ClusterReq) returns (PageResult)
@handler CreateClusterHandler @handler CreateClusterHandler
post /adapter/cluster/create (ClusterReq) returns (ClusterResp) post /adapter/cluster/create (ClusterCreateReq) returns (ClusterResp)
@handler UpdateClusterHandler @handler UpdateClusterHandler
put /adapter/cluster/update (ClusterReq) returns (ClusterResp) put /adapter/cluster/update (ClusterCreateReq) returns (ClusterResp)
@handler DeleteClusterHandler @handler DeleteClusterHandler
delete /adapter/cluster/delete (ClusterDelReq) returns (ClusterResp) delete /adapter/cluster/delete (FId) returns (ClusterResp)
@handler GetClusterHandler @handler GetClusterHandler
get /adapter/cluster/get (ClusterDelReq) returns (ClusterResp) get /adapter/cluster/get (FId) returns (ClusterResp)
@handler GetAdapterRelationHandler @handler GetAdapterRelationHandler
get /adapter/relation (AdapterQueryReq) returns (AdapterRelationResp) get /adapter/relation (AdapterQueryReq) returns (PageResult)
@handler GetClusterSumHandler @handler GetClusterSumHandler
get /adapter/clusterSum (clusterSumReq) returns (clusterSumReqResp) get /adapter/clusterSum (clusterSumReq) returns (clusterSumReqResp)

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/JointCloud/pcm-coordinator/api/internal/logic/adapters" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/adapters"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"net/http"
) )
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.AdapterQueryReq var req types.AdapterQueryReq
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.NewAdaptersListLogic(r.Context(), svcCtx) l := adapters.NewAdaptersListLogic(r.Context(), svcCtx)
resp, err := l.AdaptersList(&req) resp, err := l.AdaptersList(&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

@ -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/JointCloud/pcm-coordinator/api/internal/logic/adapters" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/adapters"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"net/http"
) )
func ClusterListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { func ClusterListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
var req types.ClusterReq var req types.ClusterReq
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.NewClusterListLogic(r.Context(), svcCtx) l := adapters.NewClusterListLogic(r.Context(), svcCtx)
resp, err := l.ClusterList(&req) resp, err := l.ClusterList(&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

@ -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/JointCloud/pcm-coordinator/api/internal/logic/adapters" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/adapters"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"net/http"
) )
func CreateAdapterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { func CreateAdapterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
var req types.AdapterCreateReq var req types.AdapterCreateReq
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.NewCreateAdapterLogic(r.Context(), svcCtx) l := adapters.NewCreateAdapterLogic(r.Context(), svcCtx)
resp, err := l.CreateAdapter(&req) resp, err := l.CreateAdapter(&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

@ -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/JointCloud/pcm-coordinator/api/internal/logic/adapters" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/adapters"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"net/http"
) )
func CreateClusterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { func CreateClusterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
var req types.ClusterReq var req types.ClusterCreateReq
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.NewCreateClusterLogic(r.Context(), svcCtx) l := adapters.NewCreateClusterLogic(r.Context(), svcCtx)
resp, err := l.CreateCluster(&req) resp, err := l.CreateCluster(&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

@ -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/JointCloud/pcm-coordinator/api/internal/logic/adapters" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/adapters"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"net/http"
) )
func DeleteAdapterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { func DeleteAdapterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
var req types.AdapterDelReq var req types.AdapterDelReq
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.NewDeleteAdapterLogic(r.Context(), svcCtx) l := adapters.NewDeleteAdapterLogic(r.Context(), svcCtx)
resp, err := l.DeleteAdapter(&req) resp, err := l.DeleteAdapter(&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

@ -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/JointCloud/pcm-coordinator/api/internal/logic/adapters" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/adapters"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"net/http"
) )
func DeleteClusterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { func DeleteClusterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
var req types.ClusterDelReq var req types.FId
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.NewDeleteClusterLogic(r.Context(), svcCtx) l := adapters.NewDeleteClusterLogic(r.Context(), svcCtx)
resp, err := l.DeleteCluster(&req) resp, err := l.DeleteCluster(&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

@ -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/JointCloud/pcm-coordinator/api/internal/logic/adapters" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/adapters"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"net/http"
) )
func GetAdapterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { func GetAdapterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
var req types.AdapterDelReq var req types.AdapterDelReq
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.NewGetAdapterLogic(r.Context(), svcCtx) l := adapters.NewGetAdapterLogic(r.Context(), svcCtx)
resp, err := l.GetAdapter(&req) resp, err := l.GetAdapter(&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

@ -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/JointCloud/pcm-coordinator/api/internal/logic/adapters" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/adapters"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"net/http"
) )
func GetAdapterRelationHandler(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.AdapterQueryReq var req types.AdapterQueryReq
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.NewGetAdapterRelationLogic(r.Context(), svcCtx) l := adapters.NewGetAdapterRelationLogic(r.Context(), svcCtx)
resp, err := l.GetAdapterRelation(&req) resp, err := l.GetAdapterRelation(&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

@ -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/JointCloud/pcm-coordinator/api/internal/logic/adapters" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/adapters"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"net/http"
) )
func GetClusterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { func GetClusterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
var req types.ClusterDelReq var req types.FId
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.NewGetClusterLogic(r.Context(), svcCtx) l := adapters.NewGetClusterLogic(r.Context(), svcCtx)
resp, err := l.GetCluster(&req) resp, err := l.GetCluster(&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

@ -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/JointCloud/pcm-coordinator/api/internal/logic/adapters" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/adapters"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
"gitlink.org.cn/JointCloud/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

@ -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/JointCloud/pcm-coordinator/api/internal/logic/adapters" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/adapters"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"net/http"
) )
func UpdateAdapterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { func UpdateAdapterHandler(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.AdapterReq
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.NewUpdateAdapterLogic(r.Context(), svcCtx) l := adapters.NewUpdateAdapterLogic(r.Context(), svcCtx)
resp, err := l.UpdateAdapter(&req) resp, err := l.UpdateAdapter(&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

@ -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/JointCloud/pcm-coordinator/api/internal/logic/adapters" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/adapters"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"net/http"
) )
func UpdateClusterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { func UpdateClusterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
var req types.ClusterReq var req types.ClusterCreateReq
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.NewUpdateClusterLogic(r.Context(), svcCtx) l := adapters.NewUpdateClusterLogic(r.Context(), svcCtx)
resp, err := l.UpdateCluster(&req) resp, err := l.UpdateCluster(&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

@ -2,8 +2,6 @@ package adapters
import ( import (
"context" "context"
"fmt"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
@ -24,16 +22,38 @@ func NewAdaptersListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Adap
} }
} }
func (l *AdaptersListLogic) AdaptersList(req *types.AdapterQueryReq) (resp *types.AdapterListResp, err error) { func (l *AdaptersListLogic) AdaptersList(req *types.AdapterQueryReq) (resp *types.PageResult, err error) {
resp = &types.AdapterListResp{} limit := req.PageSize
sqlStr := "select * from t_adapter where `deleted_at` IS NULL ORDER BY create_time Desc" offset := req.PageSize * (req.PageNum - 1)
resp = &types.PageResult{}
var list []types.AdapterInfo
db := l.svcCtx.DbEngin.Model(&types.AdapterInfo{}).Table("t_adapter")
if req.Name != "" { 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) db = db.Where("name LIKE ?", "%"+req.Name+"%")
} }
tx := l.svcCtx.DbEngin.Raw(sqlStr).Scan(&resp.List) if req.Nickname != "" {
if tx.Error != nil { db = db.Where("nickname LIKE ?", "%"+req.Nickname+"%")
logx.Errorf(tx.Error.Error())
return nil, tx.Error
} }
if req.Type != "" {
db = db.Where("type = ?", req.Type)
}
if req.Version != "" {
db = db.Where("version = ?", req.Version)
}
var total int64
err = db.Count(&total).Error
if err != nil {
return resp, err
}
db = db.Where("deleted_at is null").Limit(limit).Offset(offset)
err = db.Order("create_time desc").Find(&list).Error
resp.List = list
resp.PageSize = req.PageSize
resp.PageNum = req.PageNum
resp.Total = total
return resp, nil return resp, nil
} }

View File

@ -2,8 +2,6 @@ package adapters
import ( import (
"context" "context"
"fmt"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
@ -24,20 +22,56 @@ func NewClusterListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Clust
} }
} }
func (l *ClusterListLogic) ClusterList(req *types.ClusterReq) (resp *types.ClusterListResp, err error) { func (l *ClusterListLogic) ClusterList(req *types.ClusterReq) (resp *types.PageResult, err error) {
resp = &types.ClusterListResp{} limit := req.PageSize
offset := req.PageSize * (req.PageNum - 1)
resp = &types.PageResult{}
var list []types.ClusterInfo
db := l.svcCtx.DbEngin.Model(&types.AdapterInfo{}).Table("t_adapter")
sql := fmt.Sprintf(`select c.* from t_cluster c left join t_adapter a on c.adapter_id = a.id where c.deleted_at is null`) db = db.Joins("left join t_cluster on t_adapter.id = t_cluster.adapter_id").
Where("t_cluster.deleted_at is null")
if req.Name != "" {
db = db.Where("t_cluster.name LIKE ?", "%"+req.Name+"%")
}
if req.AdapterId != "" { if req.AdapterId != "" {
sql = fmt.Sprintf(`select * from t_cluster where adapter_id = %s and deleted_at is null `, req.AdapterId) db = db.Where("t_cluster.adapter_id = ?", "%"+req.AdapterId+"%")
}
if req.Nickname != "" {
db = db.Where("t_cluster.nickname LIKE ?", "%"+req.Nickname+"%")
}
if req.Label != "" {
db = db.Where("t_cluster.label = ?", req.Label)
}
if req.Version != "" {
db = db.Where("t_cluster.version = ?", req.Version)
}
if req.ProducerDict != "" {
db = db.Where("t_cluster.producer_dict = ?", req.ProducerDict)
}
if req.RegionDict != "" {
db = db.Where("t_cluster.region_dict = ?", req.RegionDict)
} }
if req.Type != "" { if req.Type != "" {
sql = fmt.Sprintf(`select c.* from t_cluster c left join t_adapter a on c.adapter_id = a.id where c.deleted_at is null and a.type = %s`, req.Type) db = db.Where("t_adapter.type = ?", req.Type)
} }
tx := l.svcCtx.DbEngin.Raw(sql).Scan(&resp.List)
if tx.Error != nil { //count total
logx.Errorf(tx.Error.Error()) var total int64
return nil, tx.Error err = db.Select("*").Count(&total).Error
if err != nil {
return resp, err
} }
db = db.Limit(limit).Offset(offset)
err = db.Select("t_cluster.*").Order("t_cluster.create_time desc").Scan(&list).Error
if err != nil {
return resp, err
}
resp.List = list
resp.PageSize = req.PageSize
resp.PageNum = req.PageNum
resp.Total = total
return resp, nil return resp, nil
} }

View File

@ -27,7 +27,7 @@ func NewCreateClusterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Cre
} }
} }
func (l *CreateClusterLogic) CreateCluster(req *types.ClusterReq) (resp *types.ClusterResp, err error) { func (l *CreateClusterLogic) CreateCluster(req *types.ClusterCreateReq) (resp *types.ClusterResp, err error) {
adapter := &types.AdapterInfo{} adapter := &types.AdapterInfo{}
result := l.svcCtx.DbEngin.Table("t_adapter").First(&adapter, req.AdapterId) result := l.svcCtx.DbEngin.Table("t_adapter").First(&adapter, req.AdapterId)
if errors.Is(result.Error, gorm.ErrRecordNotFound) { if errors.Is(result.Error, gorm.ErrRecordNotFound) {

View File

@ -24,7 +24,7 @@ func NewDeleteClusterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Del
} }
} }
func (l *DeleteClusterLogic) DeleteCluster(req *types.ClusterDelReq) (resp *types.ClusterResp, err error) { func (l *DeleteClusterLogic) DeleteCluster(req *types.FId) (resp *types.ClusterResp, err error) {
db := l.svcCtx.DbEngin.Table("t_cluster").Where("id = ?", req.Id).First(&types.ClusterInfo{}) db := l.svcCtx.DbEngin.Table("t_cluster").Where("id = ?", req.Id).First(&types.ClusterInfo{})
if db.Error != nil { if db.Error != nil {
logx.Errorf("err %v", db.Error.Error()) logx.Errorf("err %v", db.Error.Error())

View File

@ -2,7 +2,6 @@ package adapters
import ( import (
"context" "context"
"fmt"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils" "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
@ -25,19 +24,32 @@ func NewGetAdapterRelationLogic(ctx context.Context, svcCtx *svc.ServiceContext)
} }
} }
func (l *GetAdapterRelationLogic) GetAdapterRelation(req *types.AdapterQueryReq) (resp *types.AdapterRelationResp, err error) { func (l *GetAdapterRelationLogic) GetAdapterRelation(req *types.AdapterQueryReq) (resp *types.PageResult, err error) {
resp = &types.AdapterRelationResp{} resp = &types.PageResult{}
adapter := make([]types.AdapterInfo, 0) var list []types.AdapterInfo
sqlStr := "select * from t_adapter where `deleted_at` IS NULL ORDER BY create_time Desc" db := l.svcCtx.DbEngin.Model(&types.AdapterInfo{}).Table("t_adapter")
if req.Name != "" { 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) db = db.Where("name LIKE ?", "%"+req.Name+"%")
} }
tx := l.svcCtx.DbEngin.Raw(sqlStr).Scan(&adapter) if req.Nickname != "" {
if tx.Error != nil { db = db.Where("nickname LIKE ?", "%"+req.Nickname+"%")
logx.Errorf(tx.Error.Error())
return nil, tx.Error
} }
for _, v := range adapter { if req.Type != "" {
db = db.Where("type = ?", req.Type)
}
if req.Version != "" {
db = db.Where("version = ?", req.Version)
}
err = db.Where("deleted_at is null").Order("create_time desc").Find(&list).Error
if err != nil {
return resp, err
}
rlist := make([]*types.ClusterRelationInfo, 0)
for _, v := range list {
cr := &types.ClusterRelationInfo{} cr := &types.ClusterRelationInfo{}
utils.Convert(&v, &cr) utils.Convert(&v, &cr)
clusters := make([]*types.ClusterInfo, 0) clusters := make([]*types.ClusterInfo, 0)
@ -64,11 +76,12 @@ func (l *GetAdapterRelationLogic) GetAdapterRelation(req *types.AdapterQueryReq)
cr.COwnerId = c.OwnerId cr.COwnerId = c.OwnerId
cr.CAuthType = c.AuthType cr.CAuthType = c.AuthType
cr.CCreateTime = c.CreateTime cr.CCreateTime = c.CreateTime
resp.List = append(resp.List, cr) rlist = append(rlist, cr)
} }
if len(clusters) == 0 { if len(clusters) == 0 {
resp.List = append(resp.List, cr) rlist = append(rlist, cr)
} }
} }
resp.List = rlist
return resp, nil return resp, nil
} }

View File

@ -24,7 +24,7 @@ func NewGetClusterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetClu
} }
} }
func (l *GetClusterLogic) GetCluster(req *types.ClusterDelReq) (resp *types.ClusterInfo, err error) { func (l *GetClusterLogic) GetCluster(req *types.FId) (resp *types.ClusterInfo, err error) {
resp = &types.ClusterInfo{} resp = &types.ClusterInfo{}
db := l.svcCtx.DbEngin.Table("t_cluster").Where("id = ?", req.Id).First(&resp) db := l.svcCtx.DbEngin.Table("t_cluster").Where("id = ?", req.Id).First(&resp)
if db.Error != nil { if db.Error != nil {

View File

@ -26,7 +26,7 @@ func NewUpdateClusterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Upd
} }
} }
func (l *UpdateClusterLogic) UpdateCluster(req *types.ClusterReq) (resp *types.ClusterResp, err error) { func (l *UpdateClusterLogic) UpdateCluster(req *types.ClusterCreateReq) (resp *types.ClusterResp, err error) {
cluster := &types.ClusterInfo{} cluster := &types.ClusterInfo{}
result := l.svcCtx.DbEngin.Table("t_cluster").First(&cluster, req.Id) result := l.svcCtx.DbEngin.Table("t_cluster").First(&cluster, req.Id)
if errors.Is(result.Error, gorm.ErrRecordNotFound) { if errors.Is(result.Error, gorm.ErrRecordNotFound) {

View File

@ -38,6 +38,7 @@ import (
"gitlink.org.cn/jcce-pcm/pcm-participant-octopus/octopusclient" "gitlink.org.cn/jcce-pcm/pcm-participant-octopus/octopusclient"
"gorm.io/driver/mysql" "gorm.io/driver/mysql"
"gorm.io/gorm" "gorm.io/gorm"
"gorm.io/gorm/logger"
"gorm.io/gorm/schema" "gorm.io/gorm/schema"
"time" "time"
) )
@ -84,6 +85,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
NamingStrategy: schema.NamingStrategy{ NamingStrategy: schema.NamingStrategy{
SingularTable: true, // 使用单数表名,启用该选项,此时,`User` 的表名应该是 `t_user` SingularTable: true, // 使用单数表名,启用该选项,此时,`User` 的表名应该是 `t_user`
}, },
Logger: logger.Default.LogMode(logger.Info),
}) })
if err != nil { if err != nil {
logx.Errorf("数据库连接失败, err%v", err) logx.Errorf("数据库连接失败, err%v", err)

View File

@ -485,6 +485,7 @@ type AdapterQueryReq struct {
Nickname string `form:"nickname,optional"` Nickname string `form:"nickname,optional"`
Version string `form:"version,optional"` Version string `form:"version,optional"`
Server string `form:"server,optional"` Server string `form:"server,optional"`
PageInfo
} }
type AdapterReq struct { type AdapterReq struct {
@ -545,6 +546,31 @@ type AdapterRelation struct {
type ClusterReq struct { type ClusterReq struct {
Id string `form:"id,optional"` Id string `form:"id,optional"`
AdapterId string `form:"adapterId,optional"` AdapterId string `form:"adapterId,optional"`
Name string `form:"name,optional"`
Nickname string `form:"nickname,optional"`
Description string `form:"description,optional"`
Server string `form:"server,optional"`
MonitorServer string `form:"monitorServer,optional"`
Username string `form:"username,optional"`
Password string `form:"password,optional"`
Token string `form:"token,optional"`
Ak string `form:"ak,optional"`
Sk string `form:"sk,optional"`
Region string `form:"region,optional"`
ProjectId string `form:"projectId,optional"`
Version string `form:"version,optional"`
Label string `form:"label,optional"`
OwnerId string `form:"ownerId,omitempty,optional"`
AuthType string `form:"authType,optional"`
Type string `form:"type,optional"`
ProducerDict string `form:"producerDict,optional"`
RegionDict string `form:"regionDict,optional"`
PageInfo
}
type ClusterCreateReq struct {
Id string `json:"id,optional"`
AdapterId string `json:"adapterId,optional"`
Name string `json:"name,optional"` Name string `json:"name,optional"`
Nickname string `json:"nickname,optional"` Nickname string `json:"nickname,optional"`
Description string `json:"description,optional"` Description string `json:"description,optional"`
@ -561,11 +587,8 @@ type ClusterReq struct {
Label string `json:"label,optional"` Label string `json:"label,optional"`
OwnerId string `json:"ownerId,omitempty,optional"` OwnerId string `json:"ownerId,omitempty,optional"`
AuthType string `json:"authType,optional"` AuthType string `json:"authType,optional"`
Type string `json:"type,optional"` ProducerDict string `json:"producerDict,optional"`
} RegionDict string `json:"regionDict,optional"`
type ClusterDelReq struct {
Id string `form:"id,optional"`
} }
type ClusterInfo struct { type ClusterInfo struct {
@ -587,9 +610,15 @@ type ClusterInfo struct {
Label string `json:"label,omitempty" db:"label"` Label string `json:"label,omitempty" db:"label"`
OwnerId string `json:"ownerId,omitempty" db:"owner_id"` OwnerId string `json:"ownerId,omitempty" db:"owner_id"`
AuthType string `json:"authType,omitempty" db:"auth_type"` AuthType string `json:"authType,omitempty" db:"auth_type"`
ProducerDict string `json:"producerDict,omitempty" db:"producer_dict"`
RegionDict string `json:"regionDict,omitempty" db:"region_dict"`
CreateTime string `json:"createTime,omitempty" db:"created_time" gorm:"autoCreateTime"` CreateTime string `json:"createTime,omitempty" db:"created_time" gorm:"autoCreateTime"`
} }
type ClusterDelReq struct {
Id string `form:"id,optional"`
}
type ClusterResp struct { type ClusterResp struct {
List ClusterInfo `json:"list,omitempty"` List ClusterInfo `json:"list,omitempty"`
} }
@ -748,6 +777,10 @@ type CIds struct {
Ids []string `json:"ids,omitempty" validate:"required"` Ids []string `json:"ids,omitempty" validate:"required"`
} }
type FId struct {
Id string `form:"id":"id,omitempty" validate:"required"`
}
type PageInfo struct { type PageInfo struct {
PageNum int `form:"pageNum"` PageNum int `form:"pageNum"`
PageSize int `form:"pageSize"` PageSize int `form:"pageSize"`