Browse Source

Merge remote-tracking branch 'origin/point-v2' into point-v3

tags/v1.22.9.2^2
chenyifan01 3 years ago
parent
commit
ba1c8aea6b
6 changed files with 74 additions and 0 deletions
  1. +1
    -0
      models/cloudbrain_static.go
  2. +13
    -0
      models/task_config.go
  3. +2
    -0
      routers/api/v1/repo/cloudbrain_dashboard.go
  4. +12
    -0
      routers/reward/point/point.go
  5. +1
    -0
      routers/routes/routes.go
  6. +45
    -0
      services/task/task_config.go

+ 1
- 0
models/cloudbrain_static.go View File

@@ -34,6 +34,7 @@ type TaskDetail struct {
CardDuration string `json:"CardDuration"`
AiCenter string `json:"AiCenter"`
FlavorName string `json:"FlavorName"`
Spec *Specification `json:"Spec"`
}

func GetTodayCreatorCount(beginTime time.Time, endTime time.Time) (int64, error) {


+ 13
- 0
models/task_config.go View File

@@ -65,6 +65,19 @@ type TaskAndLimiterConfig struct {
LimitConfig LimitConfig `xorm:"extends"`
}

type PointRule struct {
UserDailyLimit int64
TaskRules []TaskRule
}

type TaskRule struct {
TaskCode string
AwardType string
AwardAmount int64
RefreshRate string
LimitNum int64
}

func (TaskAndLimiterConfig) TableName() string {
return "task_config"
}


+ 2
- 0
routers/api/v1/repo/cloudbrain_dashboard.go View File

@@ -733,6 +733,7 @@ func GetCloudbrainsDetailData(ctx *context.Context) {
ctx.ServerError("Get job failed:", err)
return
}
models.LoadSpecs4CloudbrainInfo(ciTasks)
nilTime := time.Time{}
tasks := []models.TaskDetail{}
for i, task := range ciTasks {
@@ -769,6 +770,7 @@ func GetCloudbrainsDetailData(ctx *context.Context) {
} else {
taskDetail.IsDelete = false
}
taskDetail.Spec = ciTasks[i].Spec
tasks = append(tasks, taskDetail)
}



+ 12
- 0
routers/reward/point/point.go View File

@@ -8,6 +8,7 @@ import (
"code.gitea.io/gitea/routers/response"
"code.gitea.io/gitea/services/reward"
"code.gitea.io/gitea/services/reward/point/account"
"code.gitea.io/gitea/services/task"
"errors"
"net/http"
)
@@ -92,6 +93,17 @@ func GetRulePage(ctx *context.Context) {
ctx.HTML(200, tplPointRule)
}

func GetRuleConfig(ctx *context.Context) {
r, err := task.GetPointRule()
if err != nil {
log.Error("GetRuleConfig error.%v", err)
ctx.JSON(http.StatusOK, response.ServerError(err.Error()))
return
}

ctx.JSON(http.StatusOK, response.SuccessWithData(r))
}

func GetAdminRewardList(ctx *context.Context) {
opts, err := buildAdminRewardRecordListOpts(ctx)
if err != nil {


+ 1
- 0
routers/routes/routes.go View File

@@ -1432,6 +1432,7 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Group("/reward/point", func() {
m.Get("", point.GetPointPage)
m.Get("/rule", point.GetRulePage)
m.Get("/rule/config", point.GetRuleConfig)
m.Get("/account", point.GetPointAccount)
m.Get("/record/list", point.GetPointRecordList)
}, reqSignIn)


+ 45
- 0
services/task/task_config.go View File

@@ -6,8 +6,10 @@ import (
"code.gitea.io/gitea/modules/redis/redis_client"
"code.gitea.io/gitea/modules/redis/redis_key"
"code.gitea.io/gitea/modules/redis/redis_lock"
"code.gitea.io/gitea/services/reward/limiter"
"encoding/json"
"errors"
"fmt"
"time"
)

@@ -181,3 +183,46 @@ func DelTaskConfig(id int64, doer *models.User) error {
redis_client.Del(redis_key.TaskConfigList())
return nil
}

func GetPointRule() (*models.PointRule, error) {
r, err := limiter.GetSingleDailyPointLimitConfig()
if err != nil {
return nil, err
}
limiters, err := limiter.GetLimitersByLimitType(models.LimitTypeTask)
if err != nil {
return nil, err
}
limiterMap := make(map[string]*models.LimitConfig, 0)
for i := 0; i < len(limiters); i++ {
limiterMap[limiters[i].LimitCode] = &limiters[i]
}

taskConfigs, err := GetTaskConfigList()
if err != nil {
return nil, err
}
taskRules := make([]models.TaskRule, len(taskConfigs))

for i, taskConfig := range taskConfigs {
rule := models.TaskRule{
TaskCode: taskConfig.TaskCode,
AwardType: taskConfig.AwardType,
AwardAmount: taskConfig.AwardAmount,
}
limiter := limiterMap[fmt.Sprint(taskConfig.TaskCode)]
if limiter != nil {
rule.RefreshRate = limiter.RefreshRate
rule.LimitNum = limiter.LimitNum
}
taskRules[i] = rule
}

pointRule := &models.PointRule{
TaskRules: taskRules,
}
if r != nil {
pointRule.UserDailyLimit = r.LimitNum
}
return pointRule, nil
}

Loading…
Cancel
Save