forked from ccfos/nightingale
-
Notifications
You must be signed in to change notification settings - Fork 0
/
task_record.go
64 lines (52 loc) · 1.75 KB
/
task_record.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package models
type TaskRecord struct {
Id int64 `json:"id" gorm:"primaryKey"`
GroupId int64 `json:"group_id"`
IbexAddress string `json:"ibex_address"`
IbexAuthUser string `json:"ibex_auth_user"`
IbexAuthPass string `json:"ibex_auth_pass"`
Title string `json:"title"`
Account string `json:"account"`
Batch int `json:"batch"`
Tolerance int `json:"tolerance"`
Timeout int `json:"timeout"`
Pause string `json:"pause"`
Script string `json:"script"`
Args string `json:"args"`
CreateAt int64 `json:"create_at"`
CreateBy string `json:"create_by"`
}
func (r *TaskRecord) TableName() string {
return "task_record"
}
// create task
func (r *TaskRecord) Add() error {
return Insert(r)
}
// list task, filter by group_id, create_by
func TaskRecordTotal(bgid, beginTime int64, createBy, query string) (int64, error) {
session := DB().Model(new(TaskRecord)).Where("create_at > ? and group_id = ?", beginTime, bgid)
if createBy != "" {
session = session.Where("create_by = ?", createBy)
}
if query != "" {
session = session.Where("title like ?", "%"+query+"%")
}
return Count(session)
}
func TaskRecordGets(bgid, beginTime int64, createBy, query string, limit, offset int) ([]*TaskRecord, error) {
session := DB().Where("create_at > ? and group_id = ?", beginTime, bgid).Order("create_at desc").Limit(limit).Offset(offset)
if createBy != "" {
session = session.Where("create_by = ?", createBy)
}
if query != "" {
session = session.Where("title like ?", "%"+query+"%")
}
var lst []*TaskRecord
err := session.Find(&lst).Error
return lst, err
}
// update is_done field
func (r *TaskRecord) UpdateIsDone(isDone int) error {
return DB().Model(r).Update("is_done", isDone).Error
}