audit_form.go
3.4 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
package models
import (
"fmt"
"time"
"github.com/astaxie/beego/orm"
)
type AuditForm struct {
Id int `orm:"column(id);pk" description:"唯一编号"`
CompanyId int `orm:"column(company_id)" description:"表company.id 公司编号"`
AuditTemplateId int `orm:"column(audit_template_id)" description:"表audit_template.id 所属审批模板编号"`
Section int8 `orm:"column(section)" description:"输入项所属的版块(1.基础,2.附加)"`
SortNum int `orm:"column(sort_num)" description:"排序"`
Label string `orm:"column(label);size(100)" description:"标题"`
InputType string `orm:"column(input_type);size(50)" description:"输入类型"`
ValueList string `orm:"column(value_list);size(255)" description:"可选值列表"`
Required int8 `orm:"column(required)" description:"是否必填:【0:否】【1:是】"`
CurrentValue string `orm:"column(current_value);size(255)" description:"实际填写的值"`
Disable int8 `orm:"column(disable);null" description:"显示隐藏:【0:显示】【1:隐藏】"`
Step string `orm:"column(step);size(30)" description:"步进,输入类型是range时生效 "`
Placeholder string `orm:"column(placeholder);size(40)" description:"输入提示"`
CreateAt time.Time `orm:"column(create_at);type(timestamp);auto_now_add" description:"创建时间"`
DeleteAt time.Time `orm:"column(delete_at);type(timestamp)" description:"更新时间"`
EnableStatus int8 `orm:"column(enable_status);null" description:"有效状态 0:无效 1:有效 "`
}
func (t *AuditForm) TableName() string {
return "audit_form"
}
func init() {
orm.RegisterModel(new(AuditForm))
}
// AddAuditForm insert a new AuditForm into database and returns
// last inserted Id on success.
func AddAuditForm(m *AuditForm) (id int64, err error) {
o := orm.NewOrm()
id, err = o.Insert(m)
return
}
// GetAuditFormById retrieves AuditForm by Id. Returns error if
// Id doesn't exist
func GetAuditFormById(id int) (v *AuditForm, err error) {
o := orm.NewOrm()
v = &AuditForm{Id: id}
if err = o.Read(v); err == nil {
return v, nil
}
return nil, err
}
// UpdateAuditForm updates AuditForm by Id and returns error if
// the record to be updated doesn't exist
func UpdateAuditFormById(m *AuditForm) (err error) {
o := orm.NewOrm()
v := AuditForm{Id: m.Id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Update(m); err == nil {
fmt.Println("Number of records updated in database:", num)
}
}
return
}
// DeleteAuditForm deletes AuditForm by Id and returns error if
// the record to be deleted doesn't exist
func DeleteAuditForm(id int) (err error) {
o := orm.NewOrm()
v := AuditForm{Id: id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Delete(&AuditForm{Id: id}); err == nil {
fmt.Println("Number of records deleted in database:", num)
}
}
return
}
func GetAuditForms(companyId int64, auditTemplateId int64) (v []*AuditForm, err error) {
o := orm.NewOrm()
sql := `select * from audit_form where company_id=? and audit_template_id=? and enable_status=1
order by section,sort_num
`
if _, err = o.Raw(sql, companyId, auditTemplateId).QueryRows(&v); err == nil {
return
}
return
}