|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- package adapters
-
- import (
- "context"
-
- "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 GetClusterSumLogic struct {
- logx.Logger
- ctx context.Context
- svcCtx *svc.ServiceContext
- }
-
- func NewGetClusterSumLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetClusterSumLogic {
- return &GetClusterSumLogic{
- Logger: logx.WithContext(ctx),
- ctx: ctx,
- svcCtx: svcCtx,
- }
- }
-
- func (l *GetClusterSumLogic) GetClusterSum(req *types.ClusterSumReq) (resp *types.ClusterSumReqResp, err error) {
- // todo: add your logic here and delete this line
- resp = &types.ClusterSumReqResp{}
-
- var AdapterSum int //
- var ClusterSum int //
- var TaskSum int //
- //
- sqlStr := "SELECT COUNT(*) FROM `t_adapter` t where t.type = 0"
- tx := l.svcCtx.DbEngin.Raw(sqlStr).Scan(&AdapterSum)
- if tx.Error != nil {
- logx.Error(err)
- return nil, tx.Error
- }
- //
- sqlStrCluster := "SELECT COUNT(*) FROM `t_cluster`t where t.label ='openstack' || t.label='kubernetes'\n"
- txCluster := l.svcCtx.DbEngin.Raw(sqlStrCluster).Scan(&ClusterSum)
- if txCluster.Error != nil {
- logx.Error(err)
- return nil, txCluster.Error
- }
- //
- sqlStrTask := "SELECT COUNT(*) FROM `task`"
- txTask := l.svcCtx.DbEngin.Raw(sqlStrTask).Scan(&TaskSum)
- if txTask.Error != nil {
- logx.Error(err)
- return nil, txTask.Error
- }
- resp.TaskSum = TaskSum
- resp.ClusterSum = ClusterSum
- resp.AdapterSum = AdapterSum
- return resp, nil
- }
|