| @@ -34,6 +34,7 @@ type TaskDetail struct { | |||||
| CardDuration string `json:"CardDuration"` | CardDuration string `json:"CardDuration"` | ||||
| AiCenter string `json:"AiCenter"` | AiCenter string `json:"AiCenter"` | ||||
| FlavorName string `json:"FlavorName"` | FlavorName string `json:"FlavorName"` | ||||
| Spec *Specification `json:"Spec"` | |||||
| } | } | ||||
| func GetTodayCreatorCount(beginTime time.Time, endTime time.Time) (int64, error) { | func GetTodayCreatorCount(beginTime time.Time, endTime time.Time) (int64, error) { | ||||
| @@ -65,6 +65,19 @@ type TaskAndLimiterConfig struct { | |||||
| LimitConfig LimitConfig `xorm:"extends"` | 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 { | func (TaskAndLimiterConfig) TableName() string { | ||||
| return "task_config" | return "task_config" | ||||
| } | } | ||||
| @@ -733,6 +733,7 @@ func GetCloudbrainsDetailData(ctx *context.Context) { | |||||
| ctx.ServerError("Get job failed:", err) | ctx.ServerError("Get job failed:", err) | ||||
| return | return | ||||
| } | } | ||||
| models.LoadSpecs4CloudbrainInfo(ciTasks) | |||||
| nilTime := time.Time{} | nilTime := time.Time{} | ||||
| tasks := []models.TaskDetail{} | tasks := []models.TaskDetail{} | ||||
| for i, task := range ciTasks { | for i, task := range ciTasks { | ||||
| @@ -769,6 +770,7 @@ func GetCloudbrainsDetailData(ctx *context.Context) { | |||||
| } else { | } else { | ||||
| taskDetail.IsDelete = false | taskDetail.IsDelete = false | ||||
| } | } | ||||
| taskDetail.Spec = ciTasks[i].Spec | |||||
| tasks = append(tasks, taskDetail) | tasks = append(tasks, taskDetail) | ||||
| } | } | ||||
| @@ -8,6 +8,7 @@ import ( | |||||
| "code.gitea.io/gitea/routers/response" | "code.gitea.io/gitea/routers/response" | ||||
| "code.gitea.io/gitea/services/reward" | "code.gitea.io/gitea/services/reward" | ||||
| "code.gitea.io/gitea/services/reward/point/account" | "code.gitea.io/gitea/services/reward/point/account" | ||||
| "code.gitea.io/gitea/services/task" | |||||
| "errors" | "errors" | ||||
| "net/http" | "net/http" | ||||
| ) | ) | ||||
| @@ -92,6 +93,17 @@ func GetRulePage(ctx *context.Context) { | |||||
| ctx.HTML(200, tplPointRule) | 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) { | func GetAdminRewardList(ctx *context.Context) { | ||||
| opts, err := buildAdminRewardRecordListOpts(ctx) | opts, err := buildAdminRewardRecordListOpts(ctx) | ||||
| if err != nil { | if err != nil { | ||||
| @@ -1432,6 +1432,7 @@ func RegisterRoutes(m *macaron.Macaron) { | |||||
| m.Group("/reward/point", func() { | m.Group("/reward/point", func() { | ||||
| m.Get("", point.GetPointPage) | m.Get("", point.GetPointPage) | ||||
| m.Get("/rule", point.GetRulePage) | m.Get("/rule", point.GetRulePage) | ||||
| m.Get("/rule/config", point.GetRuleConfig) | |||||
| m.Get("/account", point.GetPointAccount) | m.Get("/account", point.GetPointAccount) | ||||
| m.Get("/record/list", point.GetPointRecordList) | m.Get("/record/list", point.GetPointRecordList) | ||||
| }, reqSignIn) | }, reqSignIn) | ||||
| @@ -6,8 +6,10 @@ import ( | |||||
| "code.gitea.io/gitea/modules/redis/redis_client" | "code.gitea.io/gitea/modules/redis/redis_client" | ||||
| "code.gitea.io/gitea/modules/redis/redis_key" | "code.gitea.io/gitea/modules/redis/redis_key" | ||||
| "code.gitea.io/gitea/modules/redis/redis_lock" | "code.gitea.io/gitea/modules/redis/redis_lock" | ||||
| "code.gitea.io/gitea/services/reward/limiter" | |||||
| "encoding/json" | "encoding/json" | ||||
| "errors" | "errors" | ||||
| "fmt" | |||||
| "time" | "time" | ||||
| ) | ) | ||||
| @@ -181,3 +183,46 @@ func DelTaskConfig(id int64, doer *models.User) error { | |||||
| redis_client.Del(redis_key.TaskConfigList()) | redis_client.Del(redis_key.TaskConfigList()) | ||||
| return nil | 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 | |||||
| } | |||||