audit_form.go
4.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package models
import (
"fmt"
"time"
"github.com/astaxie/beego/orm"
)
type AuditForm struct {
Id int `orm:"column(id);auto" 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:"输入类型 text"`
ValueList string `orm:"column(value_list);size(255)" description:"可选值列表json结构字符串"`
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))
}
//AuditFormValueList 表audit_form中字段value_list的结构
type AuditFormValueList struct {
Value string `json:"value"`
Type string `json:"type"` //输入的数据内容类型
}
//输入框类型
const (
InputTypeText string = "text" //单行文本宽
InputTypeRadio string = "radio" //单选框
InputTypeImageVedio string = "files" // 图片或视频输入
)
//输入框输入的数据类型
const (
InputDataTypeText string = "text" //单纯文本
InputDataTypeImage string = "image" //图片的文件url
InputDataTypeVedio string = "video" //视频的文件url
)
var (
InputDataTypeMap map[string]bool = map[string]bool{
InputDataTypeText: true,
InputDataTypeImage: true,
InputDataTypeVedio: true,
}
InputTypeMap map[string]bool = map[string]bool{
InputTypeText: true,
InputTypeRadio: true,
InputTypeImageVedio: true,
}
)
var (
DeleteAuditFormBy = `delete FROM audit_form where audit_template_id=? and company_id=?`
)
// 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
}
// GetAuditFormById retrieves AuditForm by Id. Returns error if
// Id doesn't exist
func GetAuditFormByTemplateId(id int) (v []*AuditForm, err error) {
o := orm.NewOrm()
sql := `select * from audit_form where audit_template_id =? and enable_status=1 order by sort_num`
if _, err = o.Raw(sql, id).QueryRows(&v); err == nil {
return v, nil
}
return nil, err
}