|
|
@@ -2,6 +2,8 @@ package models |
|
|
|
|
|
|
|
import ( |
|
|
|
"code.gitea.io/gitea/modules/timeutil" |
|
|
|
"fmt" |
|
|
|
"xorm.io/builder" |
|
|
|
) |
|
|
|
|
|
|
|
const ( |
|
|
@@ -106,21 +108,45 @@ func GetTaskConfigList() ([]*TaskConfig, error) { |
|
|
|
} |
|
|
|
return r, nil |
|
|
|
} |
|
|
|
func GetTaskConfigPageWithDeleted(opt ListOptions) ([]*TaskAndLimiterConfig, int64, error) { |
|
|
|
|
|
|
|
type GetTaskConfigOpts struct { |
|
|
|
ListOptions |
|
|
|
Status int //1 normal 2 deleted |
|
|
|
ActionType int |
|
|
|
} |
|
|
|
|
|
|
|
func GetTaskConfigPageWithDeleted(opt GetTaskConfigOpts) ([]*TaskAndLimiterConfig, int64, error) { |
|
|
|
if opt.Page <= 0 { |
|
|
|
opt.Page = 1 |
|
|
|
} |
|
|
|
n, err := x.Unscoped().Count(&TaskConfig{}) |
|
|
|
cond := builder.NewCond() |
|
|
|
if opt.ActionType > 0 { |
|
|
|
cond = cond.And(builder.Eq{"task_code": fmt.Sprint(opt.ActionType)}) |
|
|
|
} |
|
|
|
|
|
|
|
var count int64 |
|
|
|
var err error |
|
|
|
if opt.Status == 1 { |
|
|
|
subCond := builder.NewCond() |
|
|
|
subCond = subCond.Or(builder.IsNull{"task_config.deleted_at"}) |
|
|
|
subCond = subCond.Or(builder.Eq{"task_config.deleted_at": 0}) |
|
|
|
cond = cond.And(subCond) |
|
|
|
} else if opt.Status == 2 { |
|
|
|
cond = cond.And(builder.Gt{"task_config.deleted_at": 0}) |
|
|
|
} |
|
|
|
count, err = x.Unscoped().Where(cond).Count(&TaskConfig{}) |
|
|
|
if err != nil { |
|
|
|
return nil, 0, err |
|
|
|
} |
|
|
|
r := make([]*TaskAndLimiterConfig, 0) |
|
|
|
err = x.Join("LEFT", "limit_config", "task_config.id = limit_config.related_id").Unscoped().Limit(opt.PageSize, (opt.Page-1)*opt.PageSize).OrderBy("task_config.deleted_at desc,task_config.id desc").Find(&r) |
|
|
|
err = x.Join("LEFT", "limit_config", "task_config.id = limit_config.related_id"). |
|
|
|
Unscoped().Where(cond).Limit(opt.PageSize, (opt.Page-1)*opt.PageSize). |
|
|
|
OrderBy("task_config.deleted_at desc,task_config.id desc").Find(&r) |
|
|
|
|
|
|
|
if len(r) == 0 { |
|
|
|
return nil, 0, ErrRecordNotExist{} |
|
|
|
} |
|
|
|
return r, n, nil |
|
|
|
return r, count, nil |
|
|
|
} |
|
|
|
|
|
|
|
func EditTaskConfig(config TaskConfigWithLimit, doer *User) error { |
|
|
|