audit_check.go
2.7 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package models
import (
"time"
"github.com/astaxie/beego/orm"
)
type AuditCheck struct {
Id int64 `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))
}
//AuditCheckItems 自查内容选项
// AuditCheck 表items存储的json结构
type AuditCheckItems struct {
Items []AuditCheckItem `json:"items"`
}
type AuditCheckItem struct {
Item string `json:"item"` //选项内容
NeedOther int `json:"needOther"` //是否需填写其他的内容【1:需要】【2:不需要】
}
//AuditCheck 表enable字段含义 是否有效【0:无效】【1:有效】
const (
AUDITCHECK_ENABLE_NO int8 = 0
AUDITCHECK_ENABLE_YES int8 = 1
)
// AddAuditCheck insert a new AuditCheck into database and returns
// last inserted Id on success.
func AddAuditCheck(m *AuditCheck) (id int64, err error) {
o := orm.NewOrm()
id, err = o.Insert(m)
return
}
// GetAuditCheckById retrieves AuditCheck by Id. Returns error if
// Id doesn't exist
func GetAuditCheckById(id int64) (v *AuditCheck, err error) {
o := orm.NewOrm()
v = &AuditCheck{Id: id}
if err = o.Read(v); err == nil {
return v, nil
}
return nil, err
}
// DeleteAuditCheck deletes AuditCheck by Id and returns error if
// the record to be deleted doesn't exist
// func DeleteAuditCheck(id int64) (err error) {
// o := orm.NewOrm()
// v := AuditCheck{Id: id}
// // ascertain id exists in the database
// if err = o.Read(&v); err == nil {
// var num int64
// if num, err = o.Delete(&AuditCheck{Id: id}); err == nil {
// fmt.Println("Number of records deleted in database:", num)
// }
// }
// return
// }
func GetAuditCheckByTemplate(templateId int64) ([]AuditCheck, error) {
var (
data []AuditCheck
err error
)
o := orm.NewOrm()
_, err = o.QueryTable(&AuditCheck{}).
Filter("template_id", templateId).
Filter("enable", AUDITCHECK_ENABLE_YES).
All(&data)
if err == orm.ErrNoRows {
return data, nil
}
if err != nil {
return nil, err
}
return data, nil
}
func DeleteAuditCheckByTempelate(templateId int64, om orm.Ormer) error {
var (
err error
)
_, err = om.QueryTable(&AuditCheck{}).
Filter("template_id", templateId).
Filter("enable", AUDITCHECK_ENABLE_YES).
Update(orm.Params{
"enable": AUDITCHECK_ENABLE_NO,
})
return err
}