|
- package adapters
-
- import (
- "context"
- "fmt"
-
- "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
- "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
-
- "github.com/zeromicro/go-zero/core/logx"
- )
-
- type ClusterListLogic struct {
- logx.Logger
- ctx context.Context
- svcCtx *svc.ServiceContext
- }
-
- func NewClusterListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ClusterListLogic {
- return &ClusterListLogic{
- Logger: logx.WithContext(ctx),
- ctx: ctx,
- svcCtx: svcCtx,
- }
- }
-
- func (l *ClusterListLogic) ClusterList(req *types.ClusterReq) (resp *types.ClusterListResp, err error) {
- resp = &types.ClusterListResp{}
-
- 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`)
- if req.AdapterId != "" {
- sql = fmt.Sprintf(`select * from t_cluster where adapter_id = %s and deleted_at is null `, req.AdapterId)
- }
- 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)
- }
- tx := l.svcCtx.DbEngin.Raw(sql).Scan(&resp.List)
- if tx.Error != nil {
- logx.Errorf(tx.Error.Error())
- return nil, tx.Error
- }
- return resp, nil
- }
|