audit_check.go
1.3 KB
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
package models
import (
"time"
"github.com/astaxie/beego/orm"
)
type AuditCheck struct {
Id int `orm:"column(id);pk"`
Pid int64 `orm:"column(pid)"`
TemplateId int64 `orm:"column(template_id)" description:"模板id"`
Title string `orm:"column(title);size(100)" description:"标题"`
Items string `orm:"column(items)" description:"选项数据json格式"`
Enable int8 `orm:"column(enable)" description:"是否有效【0:无效】【1:有效】"`
CreateTime time.Time `orm:"column(create_time);type(timestamp)"`
}
func (t *AuditCheck) TableName() string {
return "audit_check"
}
func init() {
orm.RegisterModel(new(AuditCheck))
}
// GetAuditCheckById retrieves AuditCheck by Id. Returns error if
// Id doesn't exist
func GetAuditCheckById(id int) (v *AuditCheck, err error) {
o := orm.NewOrm()
v = &AuditCheck{Id: id}
if err = o.Read(v); err == nil {
return v, nil
}
return nil, err
}
func GetAuditCheckBy(tpId int64, v interface{}) (err error) {
sql := `select * from(
select id,(case when pid=0 then id else pid end) pid,title,items,pid parent_id from audit_check where template_id=? and enable=1
)a
order by a.pid`
o := orm.NewOrm()
if _, err = o.Raw(sql, tpId).QueryRows(v); err != nil {
if err == orm.ErrNoRows {
err = nil
}
return
}
return
}