rank_range.go
2.8 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
package models
import (
"fmt"
"oppmg/common/log"
"time"
"github.com/astaxie/beego/orm"
)
type RankRange struct {
Id int64 `orm:"column(id);auto"`
Name string `orm:"column(name);size(50);null" description:"名称"`
CompanyId int64 `orm:"column(company_id);null" description:"公司编号 表company.id"`
RankTypeId int64 `orm:"column(rank_type_id);null" description:""`
Type int8 `orm:"column(type);null" description:"1:所有员工 2:指定员工 3:所有部门 4:指定部门"`
Data string `orm:"column(data);size(1000);null" description:"人员范围数据(type:2,4 有值 对于人员数据/部门数据)"`
CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"`
UpdateAt time.Time `orm:"column(update_at);type(timestamp);null" description:"更新时间"`
SortNum int `orm:"column(sort_num)"`
Status int8 `orm:"column(status)"`
}
func (t *RankRange) TableName() string {
return "rank_range"
}
func init() {
orm.RegisterModel(new(RankRange))
}
//1:所有员工 2:指定员工 3:所有部门 4:指定部门
const (
RANK_RANGE_TYPE_EMPLAYEEALL int8 = 1
RANK_RANGE_TYPE_EMPLAYEE int8 = 2
RANK_RANGE_TYPE_DEPARTMENTALL int8 = 3
RANK_RANGE_TYPE_DEPARTMENT int8 = 4
)
// AddRankRange insert a new RankRange into database and returns
// last inserted Id on success.
func AddRankRange(m *RankRange, om ...orm.Ormer) (id int64, err error) {
var o orm.Ormer
if len(om) > 0 {
o = om[0]
} else {
o = orm.NewOrm()
}
m.CreateAt = time.Now()
m.UpdateAt = time.Now()
id, err = o.Insert(m)
return
}
// GetRankRangeById retrieves RankRange by Id. Returns error if
// Id doesn't exist
func GetRankRangeById(id int64) (v *RankRange, err error) {
o := orm.NewOrm()
v = &RankRange{Id: id}
if err = o.Read(v); err == nil {
return v, nil
}
return nil, err
}
// UpdateRankRangeById updates RankRange by Id and returns error if
// the record to be updated doesn't exist
func UpdateRankRangeById(m *RankRange, cols []string, om ...orm.Ormer) (err error) {
var o orm.Ormer
if len(om) > 0 {
o = om[0]
} else {
o = orm.NewOrm()
}
var num int64
m.UpdateAt = time.Now()
if len(cols) > 0 {
cols = append(cols, "UpdateAt")
}
if num, err = o.Update(m, cols...); err == nil {
log.Info("Number of records updated in database:%d", num)
}
return
}
// DeleteRankRange deletes RankRange by Id and returns error if
// the record to be deleted doesn't exist
func DeleteRankRange(id int64) (err error) {
o := orm.NewOrm()
v := RankRange{Id: id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Delete(&RankRange{Id: id}); err == nil {
fmt.Println("Number of records deleted in database:", num)
}
}
return
}