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.

homeoverviewlogic.go 1.9 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package core
  2. import (
  3. "context"
  4. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
  5. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
  6. "github.com/zeromicro/go-zero/core/logx"
  7. )
  8. type HomeOverviewLogic struct {
  9. logx.Logger
  10. ctx context.Context
  11. svcCtx *svc.ServiceContext
  12. }
  13. func NewHomeOverviewLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HomeOverviewLogic {
  14. return &HomeOverviewLogic{
  15. Logger: logx.WithContext(ctx),
  16. ctx: ctx,
  17. svcCtx: svcCtx,
  18. }
  19. }
  20. func (l *HomeOverviewLogic) HomeOverview(req *types.HomeOverviewReq) (resp *types.HomeOverviewResp, err error) {
  21. // todo: add your logic here and delete this line
  22. resp = &types.HomeOverviewResp{}
  23. var AdapterSum int //
  24. var StorageSum float32 //
  25. var ClusterSum int //
  26. var TaskSum int //
  27. //Task
  28. sqlStrTask := "SELECT COUNT(*) FROM `task`"
  29. txTask := l.svcCtx.DbEngin.Raw(sqlStrTask).Scan(&TaskSum)
  30. if txTask.Error != nil {
  31. logx.Error(err)
  32. return nil, txTask.Error
  33. }
  34. //Storage
  35. sqlStrStorage := "SELECT SUM(t.storage_space) as storageSum FROM `t_storage_device` t"
  36. txStorage := l.svcCtx.DbEngin.Raw(sqlStrStorage).Scan(&StorageSum)
  37. if txTask.Error != nil {
  38. logx.Error(err)
  39. return nil, txStorage.Error
  40. }
  41. //Cluster
  42. sqlStrCluster := "SELECT COUNT(*) FROM `t_cluster`"
  43. txCluster := l.svcCtx.DbEngin.Raw(sqlStrCluster).Scan(&ClusterSum)
  44. if txTask.Error != nil {
  45. logx.Error(err)
  46. return nil, txCluster.Error
  47. }
  48. //Adapter
  49. sqlStrAdapter := "SELECT COUNT(*) FROM `t_adapter`"
  50. txAdapter := l.svcCtx.DbEngin.Raw(sqlStrAdapter).Scan(&AdapterSum)
  51. if txTask.Error != nil {
  52. logx.Error(err)
  53. return nil, txAdapter.Error
  54. }
  55. resp.Data.TaskSum = int64(TaskSum)
  56. resp.Data.StorageSum = StorageSum
  57. resp.Data.AdaptSum = int64(AdapterSum)
  58. resp.Data.ClusterSum = int64(ClusterSum)
  59. resp.Code = 200
  60. resp.Message = "Success"
  61. return resp, nil
  62. }

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.