audit_template.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
package models
import (
"fmt"
"time"
"github.com/astaxie/beego/orm"
)
type AuditTemplate struct {
Id int64 `orm:"column(id);pk" description:"唯一编号"`
CompanyId int `orm:"column(company_id)" description:"公司id"`
ChanceTypeId int `orm:"column(chance_type_id)" description:"机会类型 chance_type.id"`
Name string `orm:"column(name);size(20)" description:"子分类名称"`
Doc string `orm:"column(doc);size(255)" description:"说明"`
Icon string `orm:"column(icon);size(255)" description:"图标"`
Code string `orm:"column(code);size(50);null" description:" 编码"`
NoticeType int8 `orm:"column(notice_type)" description:"通知方式"`
NoApprover int8 `orm:"column(no_approver)" description:"审核人空时:【1:自动通过】【2:转交给管理员】"`
SortNum int `orm:"column(sort_num)" description:"自定义排序编号"`
VisibleType int8 `orm:"column(visible_type)" description:"可见范围 0:所有人 1:指定部门 "`
VisibleObject string `orm:"column(visible_object);size(1000);null" description:"可见的对象 部门 指定人 json"`
EnableStatus int8 `orm:"column(enable_status)" description:"是否有效 1:有效 0:无效"`
Example string `orm:"column(example);null" description:"示例"`
Videos string `orm:"column(videos);null" description:"视频"`
CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"`
UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"`
}
func (t *AuditTemplate) TableName() string {
return "audit_template"
}
func init() {
orm.RegisterModel(new(AuditTemplate))
}
// AddAuditTemplate insert a new AuditTemplate into database and returns
// last inserted Id on success.
func AddAuditTemplate(m *AuditTemplate) (id int64, err error) {
o := orm.NewOrm()
id, err = o.Insert(m)
return
}
// GetAuditTemplateById retrieves AuditTemplate by Id. Returns error if
// Id doesn't exist
func GetAuditTemplateById(id int64) (v *AuditTemplate, err error) {
o := orm.NewOrm()
v = &AuditTemplate{Id: id}
if err = o.Read(v); err == nil {
return v, nil
}
return nil, err
}
// UpdateAuditTemplate updates AuditTemplate by Id and returns error if
// the record to be updated doesn't exist
func UpdateAuditTemplateById(m *AuditTemplate) (err error) {
o := orm.NewOrm()
v := AuditTemplate{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
}
// DeleteAuditTemplate deletes AuditTemplate by Id and returns error if
// the record to be deleted doesn't exist
func DeleteAuditTemplate(id int64) (err error) {
o := orm.NewOrm()
v := AuditTemplate{Id: id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Delete(&AuditTemplate{Id: id}); err == nil {
fmt.Println("Number of records deleted in database:", num)
}
}
return
}
//按 1.公司编号 2.机会类型编号
//获取审核模板列表
func GetAuditTemplates(companyId int64, chanceTypeId int) (v []*AuditTemplate, err error) {
o := orm.NewOrm()
sql := "select id,company_id,chance_type_id,`name`,doc,icon,code,sort_num,visible_type,visible_object,LEFT(example,5) example,videos " +
" from audit_template where company_id=? and chance_type_id=? and enable_status=1 order by sort_num"
if _, err = o.Raw(sql, companyId, chanceTypeId).QueryRows(&v); err == nil {
return
}
return
}
//获取模板示例
func GetAuditTemplateExample(id int64) (v string, videos string, err error) {
o := orm.NewOrm()
sql := "select example,videos from audit_template where id=?"
if err = o.Raw(sql, id).QueryRow(&v, &videos); err == nil {
return
}
return
}
//按 1.公司编号 2.机会类型编号 3.模板编号
//获取审核模板列表
func GetAuditTemplate(companyId int64, chanceTypeId, templateId int) (v *AuditTemplate, err error) {
o := orm.NewOrm()
sql := "select id,company_id,chance_type_id,`name`,doc,icon,code,sort_num,visible_type,visible_object,LEFT(example,5) example,videos from audit_template where id=? and company_id=? and chance_type_id=? and enable_status=1"
if err = o.Raw(sql, templateId, companyId, chanceTypeId).QueryRow(&v); err == nil {
return
}
return
}