forked from open-falcon/falcon-plus
/
tpl.go
48 lines (43 loc) · 1.13 KB
/
tpl.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
package falcon_portal
import (
log "github.com/Sirupsen/logrus"
"github.com/open-falcon/falcon-plus/modules/api/app/model/uic"
con "github.com/open-falcon/falcon-plus/modules/api/config"
)
type Template struct {
ID int64 `json:"id" gorm:"column:id"`
Name string `json:"tpl_name" gorm:"column:tpl_name"`
ParentID int64 `json:"parent_id" orm:"column:parent_id"`
ActionID int64 `json:"action_id" orm:"column:action_id"`
CreateUser string `json:"create_user" orm:"column:create_user"`
}
func (this Template) TableName() string {
return "tpl"
}
func (this Template) FindUserName() (name string, err error) {
var user uic.User
user.Name = this.CreateUser
db := con.Con()
dt := db.Uic.Find(&user)
if dt.Error != nil {
err = dt.Error
return
}
name = user.Name
return
}
func (this Template) FindParentName() (name string, err error) {
var ptpl Template
if this.ParentID == 0 {
return
}
ptpl.ID = this.ParentID
db := con.Con()
dt := db.Falcon.Find(&ptpl)
if dt.Error != nil {
log.Debugf("tpl_id: %v find parent: %v with error: %s", this.ID, ptpl.ID, dt.Error.Error())
return
}
name = ptpl.Name
return
}