rank_period.go
3.2 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"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/mybeego"
"opp/internal/utils"
"time"
"github.com/astaxie/beego/orm"
)
type RankPeriod struct {
Id int `orm:"column(id);auto" description:"主键"`
CompanyId int `orm:"column(company_id);null" description:"公司编号 表company.id"`
RankTypeId int `orm:"column(rank_type_id)" description:"表rank_type.id 榜单类型编号"`
SeasonName string `orm:"column(season_name);size(50);null" description:"赛季名称"`
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);null" description:"赛季结束时,备份赛季参与人设置"`
RankItemBack string `orm:"column(rank_item_back);null" description:"赛季结束时,备份赛季评比项设置"`
}
func (t *RankPeriod) TableName() string {
return "rank_period"
}
func init() {
orm.RegisterModel(new(RankPeriod))
}
// AddRankPeriod insert a new RankPeriod into database and returns
// last inserted Id on success.
func AddRankPeriod(m *RankPeriod) (id int64, err error) {
o := orm.NewOrm()
id, err = o.Insert(m)
return
}
// GetRankPeriodById retrieves RankPeriod by Id. Returns error if
// Id doesn't exist
func GetRankPeriodById(id int) (v *RankPeriod, err error) {
o := orm.NewOrm()
v = &RankPeriod{Id: id}
if err = o.Read(v); err == nil {
return v, nil
}
return nil, err
}
// UpdateRankPeriod updates RankPeriod by Id and returns error if
// the record to be updated doesn't exist
func UpdateRankPeriodById(m *RankPeriod) (err error) {
o := orm.NewOrm()
v := RankPeriod{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
}
// DeleteRankPeriod deletes RankPeriod by Id and returns error if
// the record to be deleted doesn't exist
func DeleteRankPeriod(id int) (err error) {
o := orm.NewOrm()
v := RankPeriod{Id: id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Delete(&RankPeriod{Id: id}); err == nil {
fmt.Println("Number of records deleted in database:", num)
}
}
return
}
//获取进行中的赛季周期 状态 0:未开始 1:开始 2:结束
func GetRankPeriods(companyId int, rankTypeId int, status []int) (v []*RankPeriod, err error) {
sql := mybeego.NewSqlExutor()
sql.Table((&RankPeriod{}).TableName())
if companyId > 0 {
sql.Where(fmt.Sprintf("company_id=%v", companyId))
}
if rankTypeId > 0 {
sql.Where(fmt.Sprintf("rank_type_id=%v", rankTypeId))
}
if len(status) > 0 {
sql.Where(fmt.Sprintf("status in (%v)", utils.JoinInts(status, ",")))
}
sql.Order("end_time desc")
_, err = sql.Querys(&v)
return
}