You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

getadapterrelationlogic.go 2.4 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package adapters
  2. import (
  3. "context"
  4. "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
  5. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
  6. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
  7. "github.com/zeromicro/go-zero/core/logx"
  8. )
  9. type GetAdapterRelationLogic struct {
  10. logx.Logger
  11. ctx context.Context
  12. svcCtx *svc.ServiceContext
  13. }
  14. func NewGetAdapterRelationLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetAdapterRelationLogic {
  15. return &GetAdapterRelationLogic{
  16. Logger: logx.WithContext(ctx),
  17. ctx: ctx,
  18. svcCtx: svcCtx,
  19. }
  20. }
  21. func (l *GetAdapterRelationLogic) GetAdapterRelation(req *types.AdapterRelationQueryReq) (resp *types.PageResult, err error) {
  22. resp = &types.PageResult{}
  23. var list []types.AdapterInfo
  24. db := l.svcCtx.DbEngin.Model(&types.AdapterInfo{}).Table("t_adapter")
  25. if req.Name != "" {
  26. db = db.Where("name LIKE ?", "%"+req.Name+"%")
  27. }
  28. if req.Nickname != "" {
  29. db = db.Where("nickname LIKE ?", "%"+req.Nickname+"%")
  30. }
  31. if req.Type != "" {
  32. db = db.Where("type = ?", req.Type)
  33. }
  34. if req.Version != "" {
  35. db = db.Where("version = ?", req.Version)
  36. }
  37. err = db.Where("deleted_at is null").Order("create_time desc").Find(&list).Error
  38. if err != nil {
  39. return resp, err
  40. }
  41. rlist := make([]*types.ClusterRelationInfo, 0)
  42. for _, v := range list {
  43. cr := &types.ClusterRelationInfo{}
  44. utils.Convert(&v, &cr)
  45. clusters := make([]*types.ClusterInfo, 0)
  46. l.svcCtx.DbEngin.Raw("select * from t_cluster where `deleted_at` IS NULL and adapter_id = ? ORDER BY create_time Desc", v.Id).Scan(&clusters)
  47. for _, c := range clusters {
  48. cr = &types.ClusterRelationInfo{}
  49. utils.Convert(&v, &cr)
  50. cr.CId = c.Id
  51. cr.CAdapterId = string(c.AdapterId)
  52. cr.CName = c.Name
  53. cr.CNickname = c.Nickname
  54. cr.CDescription = c.Description
  55. cr.CServer = c.Server
  56. cr.CMonitorServer = c.MonitorServer
  57. cr.CUsername = c.Username
  58. cr.CPassword = c.Password
  59. cr.CToken = c.Token
  60. cr.CAk = c.Ak
  61. cr.CSk = c.Sk
  62. cr.CRegion = c.Region
  63. cr.CProjectId = c.ProjectId
  64. cr.CVersion = c.Version
  65. cr.CLabel = c.Label
  66. cr.COwnerId = c.OwnerId
  67. cr.CAuthType = c.AuthType
  68. cr.CRegionDict = c.RegionDict
  69. cr.CProducerDict = c.ProducerDict
  70. cr.CCreateTime = c.CreateTime
  71. rlist = append(rlist, cr)
  72. }
  73. if len(clusters) == 0 {
  74. rlist = append(rlist, cr)
  75. }
  76. }
  77. resp.List = rlist
  78. return resp, nil
  79. }

PCM is positioned as Software stack over Cloud, aiming to build the standards and ecology of heterogeneous cloud collaboration for JCC in a non intrusive and autonomous peer-to-peer manner.