rank_period.go
2.5 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
package models
import (
"oppmg/common/log"
"time"
"github.com/astaxie/beego/orm"
)
type RankPeriod struct {
Id int64 `orm:"column(id);auto" description:"主键"`
CompanyId int64 `orm:"column(company_id);null" description:"公司编号 表company.id"`
SeasonName string `orm:"column(season_name);size(50);null" description:"赛季名称"`
RankTypeId int64 `orm:"column(rank_type_id);size(50);null" description:"赛季类型id"`
BeginTime time.Time `orm:"column(begin_time);type(timestamp);null" description:"开始时间"`
EndTime time.Time `orm:"column(end_time);type(timestamp);null" description:"结束时间"`
CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"`
UpdateAt time.Time `orm:"column(update_at);type(timestamp);null" description:"更新时间"`
Status int8 `orm:"column(status);null" description:"状态 0:未开始 1:开始 2:结束 "`
RankRangeBack string `orm:"column(rank_range_back)" description:"赛季结束时,备份赛季参与人设置"`
RankItemBack string `orm:"column(rank_item_back)" description:"赛季结束时,备份赛季评比项设置"`
IsAuto int `orm:"column(is_auto)" description:"是否是自动创建的赛季【0:不是】【1:是】"`
}
func (t *RankPeriod) TableName() string {
return "rank_period"
}
func init() {
orm.RegisterModel(new(RankPeriod))
}
//状态 0:未开始 1:开始 2:结束
const (
RANKPERIOD_STATUS_NOT int8 = 0
RANKPERIOD_STATUS_BEGIN int8 = 1
RANKPERIOD_STATUS_END int8 = 2
)
// AddNewRankPeriod insert a new RankPeriod into database and returns
// last inserted Id on success.
func AddRankPeriod(m *RankPeriod) (id int64, err error) {
o := orm.NewOrm()
m.CreateAt = time.Now()
m.UpdateAt = time.Now()
id, err = o.Insert(m)
return
}
// GetNewRankPeriodById retrieves RankPeriod by Id. Returns error if
// Id doesn't exist
func GetRankPeriodById(id int64) (v *RankPeriod, err error) {
o := orm.NewOrm()
v = &RankPeriod{Id: id}
if err = o.Read(v); err == nil {
return v, nil
}
return nil, err
}
// UpdateNewRankPeriod updates RankPeriod by Id and returns error if
// the record to be updated doesn't exist
func UpdateRankPeriodById(m *RankPeriod, cols []string) (err error) {
o := orm.NewOrm()
m.UpdateAt = time.Now()
if len(cols) > 0 {
cols = append(cols, "UpdateAt")
}
var num int64
if num, err = o.Update(m, cols...); err == nil {
log.Info("Number of records updated in database:", num)
}
return
}