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.

resource_queue.go 3.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. package models
  2. import (
  3. "code.gitea.io/gitea/modules/timeutil"
  4. "xorm.io/builder"
  5. )
  6. type ResourceQueue struct {
  7. ID int64 `xorm:"pk autoincr"`
  8. QueueCode string
  9. Cluster string `xorm:"notnull"`
  10. AiCenterCode string
  11. ComputeResource string
  12. AccCardType string
  13. CardsTotalNum int
  14. IsAutomaticSync bool
  15. CreatedTime timeutil.TimeStamp `xorm:"created"`
  16. CreatedBy int64
  17. UpdatedTime timeutil.TimeStamp `xorm:"updated"`
  18. UpdatedBy int64
  19. }
  20. func (r ResourceQueue) ConvertToRes() *ResourceQueueRes {
  21. return &ResourceQueueRes{
  22. ID: r.ID,
  23. QueueCode: r.QueueCode,
  24. Cluster: r.Cluster,
  25. AiCenterCode: r.AiCenterCode,
  26. ComputeResource: r.ComputeResource,
  27. AccCardType: r.AccCardType,
  28. CardsTotalNum: r.CardsTotalNum,
  29. }
  30. }
  31. type ResourceQueueReq struct {
  32. QueueCode string
  33. Cluster string `binding:"Required"`
  34. AiCenterCode string
  35. ComputeResource string `binding:"Required"`
  36. AccCardType string `binding:"Required"`
  37. CardsTotalNum int
  38. CreatorId int64
  39. IsAutomaticSync bool
  40. }
  41. func (r ResourceQueueReq) ToDTO() ResourceQueue {
  42. return ResourceQueue{
  43. QueueCode: r.QueueCode,
  44. Cluster: r.Cluster,
  45. AiCenterCode: r.AiCenterCode,
  46. ComputeResource: r.ComputeResource,
  47. AccCardType: r.AccCardType,
  48. CardsTotalNum: r.CardsTotalNum,
  49. IsAutomaticSync: r.IsAutomaticSync,
  50. CreatedBy: r.CreatorId,
  51. UpdatedBy: r.CreatorId,
  52. }
  53. }
  54. type SearchResourceQueueOptions struct {
  55. ListOptions
  56. Cluster string
  57. AiCenterCode string
  58. ComputeResource string
  59. AccCardType string
  60. }
  61. type ResourceQueueListRes struct {
  62. TotalSize int64
  63. List []*ResourceQueueRes
  64. }
  65. func NewResourceQueueListRes(totalSize int64, list []ResourceQueue) *ResourceQueueListRes {
  66. resList := make([]*ResourceQueueRes, len(list))
  67. for i, v := range list {
  68. resList[i] = v.ConvertToRes()
  69. }
  70. return &ResourceQueueListRes{
  71. TotalSize: totalSize,
  72. List: resList,
  73. }
  74. }
  75. type ResourceQueueRes struct {
  76. ID int64
  77. QueueCode string
  78. Cluster string
  79. AiCenterCode string
  80. ComputeResource string
  81. AccCardType string
  82. CardsTotalNum int
  83. }
  84. func InsertResourceQueue(queue ResourceQueue) (int64, error) {
  85. return x.Insert(&queue)
  86. }
  87. func UpdateResourceQueueById(queueId int64, queue ResourceQueue) (int64, error) {
  88. return x.ID(queueId).Update(&queue)
  89. }
  90. func SearchResourceQueue(opts SearchResourceQueueOptions) (int64, []ResourceQueue, error) {
  91. var cond = builder.NewCond()
  92. if opts.Page <= 0 {
  93. opts.Page = 1
  94. }
  95. if opts.Cluster != "" {
  96. cond = cond.And(builder.Eq{"cluster": opts.Cluster})
  97. }
  98. if opts.AiCenterCode != "" {
  99. cond = cond.And(builder.Eq{"ai_center_code": opts.AiCenterCode})
  100. }
  101. if opts.ComputeResource != "" {
  102. cond = cond.And(builder.Eq{"compute_resource": opts.ComputeResource})
  103. }
  104. if opts.AccCardType != "" {
  105. cond = cond.And(builder.Eq{"acc_card_type": opts.AccCardType})
  106. }
  107. n, err := x.Where(cond).Count(&ResourceQueue{})
  108. if err != nil {
  109. return 0, nil, err
  110. }
  111. r := make([]ResourceQueue, 0)
  112. err = x.Where(cond).Desc("id").Limit(opts.PageSize, (opts.Page-1)*opts.PageSize).Find(&r)
  113. if err != nil {
  114. return 0, nil, err
  115. }
  116. return n, r, nil
  117. }