正在显示
8 个修改的文件
包含
713 行增加
和
27 行删除
controllers/rank.go
0 → 100644
1 | +package controllers | ||
2 | + | ||
3 | +import ( | ||
4 | + "encoding/json" | ||
5 | + "oppmg/common/log" | ||
6 | + "oppmg/protocol" | ||
7 | + serverank "oppmg/services/rank" | ||
8 | +) | ||
9 | + | ||
10 | +type RankController struct { | ||
11 | + BaseController | ||
12 | +} | ||
13 | + | ||
14 | +//GetRankType .. | ||
15 | +//@router /rank/list | ||
16 | +func (c RankController) GetRankType() { | ||
17 | + var msg *protocol.ResponseMessage | ||
18 | + defer func() { | ||
19 | + c.ResposeJson(msg) | ||
20 | + }() | ||
21 | + companyid := c.GetCompanyId() | ||
22 | + rspData := serverank.GetRankList(companyid) | ||
23 | + msg = protocol.NewReturnResponse(rspData, nil) | ||
24 | + return | ||
25 | +} | ||
26 | + | ||
27 | +//EditRankType ... | ||
28 | +//@router /rank/edit | ||
29 | +func (c RankController) EditRankType() { | ||
30 | + var msg *protocol.ResponseMessage | ||
31 | + defer func() { | ||
32 | + c.ResposeJson(msg) | ||
33 | + }() | ||
34 | + type Parameter struct { | ||
35 | + Id int64 `json:"id"` | ||
36 | + Name string `json:"name"` | ||
37 | + } | ||
38 | + var param Parameter | ||
39 | + if err := json.Unmarshal(c.Ctx.Input.RequestBody, ¶m); err != nil { | ||
40 | + log.Error("json 解析失败 err:%s", err) | ||
41 | + msg = protocol.BadRequestParam("1") | ||
42 | + return | ||
43 | + } | ||
44 | + companyid := c.GetCompanyId() | ||
45 | + err := serverank.UpdateRankType(param.Id, param.Name, companyid) | ||
46 | + msg = protocol.NewReturnResponse(nil, err) | ||
47 | + return | ||
48 | +} | ||
49 | + | ||
50 | +//EditRankType ... | ||
51 | +//@router /rank/forbid_allow | ||
52 | +func (c RankController) RankTypeForbidAllow() { | ||
53 | + var msg *protocol.ResponseMessage | ||
54 | + defer func() { | ||
55 | + c.ResposeJson(msg) | ||
56 | + }() | ||
57 | + type Parameter struct { | ||
58 | + Id int64 `json:"id"` | ||
59 | + status int `json:"status"` | ||
60 | + } | ||
61 | + var param Parameter | ||
62 | + if err := json.Unmarshal(c.Ctx.Input.RequestBody, ¶m); err != nil { | ||
63 | + log.Error("json 解析失败 err:%s", err) | ||
64 | + msg = protocol.BadRequestParam("1") | ||
65 | + return | ||
66 | + } | ||
67 | + var err error | ||
68 | + companyid := c.GetCompanyId() | ||
69 | + switch param.status { | ||
70 | + case 1: | ||
71 | + err = serverank.ForbidRank(param.Id, companyid) | ||
72 | + case 2: | ||
73 | + err = serverank.AllowRank(param.Id, companyid) | ||
74 | + } | ||
75 | + msg = protocol.NewReturnResponse(nil, err) | ||
76 | + return | ||
77 | +} | ||
78 | + | ||
79 | +//RankSeasonList ... | ||
80 | +//@router /rank/season/list | ||
81 | +func (c RankController) RankSeasonList() { | ||
82 | + var msg *protocol.ResponseMessage | ||
83 | + defer func() { | ||
84 | + c.ResposeJson(msg) | ||
85 | + }() | ||
86 | + | ||
87 | + var param protocol.RequestPageInfo | ||
88 | + if err := json.Unmarshal(c.Ctx.Input.RequestBody, ¶m); err != nil { | ||
89 | + log.Error("json 解析失败 err:%s", err) | ||
90 | + msg = protocol.BadRequestParam("1") | ||
91 | + return | ||
92 | + } | ||
93 | + companyid := c.GetCompanyId() | ||
94 | + rspData, err := serverank.RankSeasonList(param.PageIndex, param.PageSize, companyid) | ||
95 | + msg = protocol.NewReturnResponse(rspData, err) | ||
96 | + return | ||
97 | +} | ||
98 | + | ||
99 | +//RankSeasonAdd ... | ||
100 | +//@router /rank/season/add | ||
101 | +func (c RankController) RankSeasonAdd() { | ||
102 | + var msg *protocol.ResponseMessage | ||
103 | + defer func() { | ||
104 | + c.ResposeJson(msg) | ||
105 | + }() | ||
106 | + type Parameter struct { | ||
107 | + Name string `json:"name"` | ||
108 | + BeginTime string `json:"begin_time"` | ||
109 | + EndTime string `json:"end_time"` | ||
110 | + } | ||
111 | + var param Parameter | ||
112 | + if err := json.Unmarshal(c.Ctx.Input.RequestBody, ¶m); err != nil { | ||
113 | + log.Error("json 解析失败 err:%s", err) | ||
114 | + msg = protocol.BadRequestParam("1") | ||
115 | + return | ||
116 | + } | ||
117 | + var ( | ||
118 | + beginTime int64 | ||
119 | + endTime int64 | ||
120 | + ) | ||
121 | + companyid := c.GetCompanyId() | ||
122 | + err := serverank.AddRankSeason(beginTime, endTime, param.Name, companyid) | ||
123 | + msg = protocol.NewReturnResponse(nil, err) | ||
124 | + return | ||
125 | +} | ||
126 | + | ||
127 | +//RankSeasonEdit ... | ||
128 | +//@router /rank/season/edit | ||
129 | +func (c RankController) RankSeasonEdit() { | ||
130 | + var msg *protocol.ResponseMessage | ||
131 | + defer func() { | ||
132 | + c.ResposeJson(msg) | ||
133 | + }() | ||
134 | + type Parameter struct { | ||
135 | + Id int64 `json:"id"` | ||
136 | + Name string `json:"name"` | ||
137 | + BeginTime string `json:"begin_time"` | ||
138 | + EndTime string `json:"end_time"` | ||
139 | + } | ||
140 | + var param Parameter | ||
141 | + if err := json.Unmarshal(c.Ctx.Input.RequestBody, ¶m); err != nil { | ||
142 | + log.Error("json 解析失败 err:%s", err) | ||
143 | + msg = protocol.BadRequestParam("1") | ||
144 | + return | ||
145 | + } | ||
146 | + var ( | ||
147 | + beginTime int64 | ||
148 | + endTime int64 | ||
149 | + ) | ||
150 | + companyid := c.GetCompanyId() | ||
151 | + err := serverank.EditRankSeason(param.Id, beginTime, endTime, param.Name, companyid) | ||
152 | + msg = protocol.NewReturnResponse(nil, err) | ||
153 | + return | ||
154 | +} |
models/rank_period.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "time" | ||
6 | + | ||
7 | + "github.com/astaxie/beego/orm" | ||
8 | +) | ||
9 | + | ||
10 | +type RankPeriod struct { | ||
11 | + Id int64 `orm:"column(id);auto" description:"主键"` | ||
12 | + CompanyId int64 `orm:"column(company_id);null" description:"公司编号 表company.id"` | ||
13 | + SeasonName string `orm:"column(season_name);size(50);null" description:"赛季名称"` | ||
14 | + BeginTime time.Time `orm:"column(begin_time);type(timestamp);null" description:"开始时间"` | ||
15 | + EndTime time.Time `orm:"column(end_time);type(timestamp);null" description:"结束时间"` | ||
16 | + CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"` | ||
17 | + UpdateAt time.Time `orm:"column(update_at);type(timestamp);null" description:"更新时间"` | ||
18 | + Status int8 `orm:"column(status);null" description:"状态 0:未开始 1:开始 2:结束 "` | ||
19 | + RankRangeBack string `orm:"column(rank_range_back)" description:"赛季结束时,备份赛季参与人设置"` | ||
20 | + RankItemBack string `orm:"column(rank_item_back)" description:"赛季结束时,备份赛季评比项设置"` | ||
21 | +} | ||
22 | + | ||
23 | +func (t *RankPeriod) TableName() string { | ||
24 | + return "rank_period" | ||
25 | +} | ||
26 | + | ||
27 | +func init() { | ||
28 | + orm.RegisterModel(new(RankPeriod)) | ||
29 | +} | ||
30 | + | ||
31 | +//状态 0:未开始 1:开始 2:结束 | ||
32 | +const ( | ||
33 | + RANKPERIOD_STATUS_NOT int8 = 0 | ||
34 | + RANKPERIOD_STATUS_BEGIN int8 = 1 | ||
35 | + RANKPERIOD_STATUS_END int8 = 2 | ||
36 | +) | ||
37 | + | ||
38 | +// AddNewRankPeriod insert a new RankPeriod into database and returns | ||
39 | +// last inserted Id on success. | ||
40 | +func AddRankPeriod(m *RankPeriod) (id int64, err error) { | ||
41 | + o := orm.NewOrm() | ||
42 | + id, err = o.Insert(m) | ||
43 | + return | ||
44 | +} | ||
45 | + | ||
46 | +// GetNewRankPeriodById retrieves RankPeriod by Id. Returns error if | ||
47 | +// Id doesn't exist | ||
48 | +func GetRankPeriodById(id int64) (v *RankPeriod, err error) { | ||
49 | + o := orm.NewOrm() | ||
50 | + v = &RankPeriod{Id: id} | ||
51 | + if err = o.Read(v); err == nil { | ||
52 | + return v, nil | ||
53 | + } | ||
54 | + return nil, err | ||
55 | +} | ||
56 | + | ||
57 | +// UpdateNewRankPeriod updates RankPeriod by Id and returns error if | ||
58 | +// the record to be updated doesn't exist | ||
59 | +func UpdateRankPeriodById(m *RankPeriod) (err error) { | ||
60 | + o := orm.NewOrm() | ||
61 | + v := RankPeriod{Id: m.Id} | ||
62 | + // ascertain id exists in the database | ||
63 | + if err = o.Read(&v); err == nil { | ||
64 | + var num int64 | ||
65 | + if num, err = o.Update(m); err == nil { | ||
66 | + fmt.Println("Number of records updated in database:", num) | ||
67 | + } | ||
68 | + } | ||
69 | + return | ||
70 | +} |
models/rank_range.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "errors" | ||
5 | + "fmt" | ||
6 | + "reflect" | ||
7 | + "strings" | ||
8 | + "time" | ||
9 | + | ||
10 | + "github.com/astaxie/beego/orm" | ||
11 | +) | ||
12 | + | ||
13 | +type NewRankRange struct { | ||
14 | + Id int `orm:"column(id);auto"` | ||
15 | + Name string `orm:"column(name);size(50);null" description:"名称"` | ||
16 | + CompanyId int `orm:"column(company_id);null" description:"公司编号 表company.id"` | ||
17 | + Type int8 `orm:"column(type);null" description:"1:所有员工 2:指定员工 3:所有部门 4:指定部门"` | ||
18 | + Data string `orm:"column(data);size(1000);null" description:"人员范围数据(type:2,4 有值 对于人员数据/部门数据)"` | ||
19 | + CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"` | ||
20 | + UpdateAt time.Time `orm:"column(update_at);type(timestamp);null" description:"更新时间"` | ||
21 | +} | ||
22 | + | ||
23 | +func (t *NewRankRange) TableName() string { | ||
24 | + return "rank_range" | ||
25 | +} | ||
26 | + | ||
27 | +func init() { | ||
28 | + orm.RegisterModel(new(NewRankRange)) | ||
29 | +} | ||
30 | + | ||
31 | +// AddNewRankRange insert a new NewRankRange into database and returns | ||
32 | +// last inserted Id on success. | ||
33 | +func AddNewRankRange(m *NewRankRange) (id int64, err error) { | ||
34 | + o := orm.NewOrm() | ||
35 | + id, err = o.Insert(m) | ||
36 | + return | ||
37 | +} | ||
38 | + | ||
39 | +// GetNewRankRangeById retrieves NewRankRange by Id. Returns error if | ||
40 | +// Id doesn't exist | ||
41 | +func GetNewRankRangeById(id int) (v *NewRankRange, err error) { | ||
42 | + o := orm.NewOrm() | ||
43 | + v = &NewRankRange{Id: id} | ||
44 | + if err = o.Read(v); err == nil { | ||
45 | + return v, nil | ||
46 | + } | ||
47 | + return nil, err | ||
48 | +} | ||
49 | + | ||
50 | +// GetAllNewRankRange retrieves all NewRankRange matches certain condition. Returns empty list if | ||
51 | +// no records exist | ||
52 | +func GetAllNewRankRange(query map[string]string, fields []string, sortby []string, order []string, | ||
53 | + offset int64, limit int64) (ml []interface{}, err error) { | ||
54 | + o := orm.NewOrm() | ||
55 | + qs := o.QueryTable(new(NewRankRange)) | ||
56 | + // query k=v | ||
57 | + for k, v := range query { | ||
58 | + // rewrite dot-notation to Object__Attribute | ||
59 | + k = strings.Replace(k, ".", "__", -1) | ||
60 | + if strings.Contains(k, "isnull") { | ||
61 | + qs = qs.Filter(k, (v == "true" || v == "1")) | ||
62 | + } else { | ||
63 | + qs = qs.Filter(k, v) | ||
64 | + } | ||
65 | + } | ||
66 | + // order by: | ||
67 | + var sortFields []string | ||
68 | + if len(sortby) != 0 { | ||
69 | + if len(sortby) == len(order) { | ||
70 | + // 1) for each sort field, there is an associated order | ||
71 | + for i, v := range sortby { | ||
72 | + orderby := "" | ||
73 | + if order[i] == "desc" { | ||
74 | + orderby = "-" + v | ||
75 | + } else if order[i] == "asc" { | ||
76 | + orderby = v | ||
77 | + } else { | ||
78 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
79 | + } | ||
80 | + sortFields = append(sortFields, orderby) | ||
81 | + } | ||
82 | + qs = qs.OrderBy(sortFields...) | ||
83 | + } else if len(sortby) != len(order) && len(order) == 1 { | ||
84 | + // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
85 | + for _, v := range sortby { | ||
86 | + orderby := "" | ||
87 | + if order[0] == "desc" { | ||
88 | + orderby = "-" + v | ||
89 | + } else if order[0] == "asc" { | ||
90 | + orderby = v | ||
91 | + } else { | ||
92 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
93 | + } | ||
94 | + sortFields = append(sortFields, orderby) | ||
95 | + } | ||
96 | + } else if len(sortby) != len(order) && len(order) != 1 { | ||
97 | + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
98 | + } | ||
99 | + } else { | ||
100 | + if len(order) != 0 { | ||
101 | + return nil, errors.New("Error: unused 'order' fields") | ||
102 | + } | ||
103 | + } | ||
104 | + | ||
105 | + var l []NewRankRange | ||
106 | + qs = qs.OrderBy(sortFields...) | ||
107 | + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
108 | + if len(fields) == 0 { | ||
109 | + for _, v := range l { | ||
110 | + ml = append(ml, v) | ||
111 | + } | ||
112 | + } else { | ||
113 | + // trim unused fields | ||
114 | + for _, v := range l { | ||
115 | + m := make(map[string]interface{}) | ||
116 | + val := reflect.ValueOf(v) | ||
117 | + for _, fname := range fields { | ||
118 | + m[fname] = val.FieldByName(fname).Interface() | ||
119 | + } | ||
120 | + ml = append(ml, m) | ||
121 | + } | ||
122 | + } | ||
123 | + return ml, nil | ||
124 | + } | ||
125 | + return nil, err | ||
126 | +} | ||
127 | + | ||
128 | +// UpdateNewRankRange updates NewRankRange by Id and returns error if | ||
129 | +// the record to be updated doesn't exist | ||
130 | +func UpdateNewRankRangeById(m *NewRankRange) (err error) { | ||
131 | + o := orm.NewOrm() | ||
132 | + v := NewRankRange{Id: m.Id} | ||
133 | + // ascertain id exists in the database | ||
134 | + if err = o.Read(&v); err == nil { | ||
135 | + var num int64 | ||
136 | + if num, err = o.Update(m); err == nil { | ||
137 | + fmt.Println("Number of records updated in database:", num) | ||
138 | + } | ||
139 | + } | ||
140 | + return | ||
141 | +} | ||
142 | + | ||
143 | +// DeleteNewRankRange deletes NewRankRange by Id and returns error if | ||
144 | +// the record to be deleted doesn't exist | ||
145 | +func DeleteNewRankRange(id int) (err error) { | ||
146 | + o := orm.NewOrm() | ||
147 | + v := NewRankRange{Id: id} | ||
148 | + // ascertain id exists in the database | ||
149 | + if err = o.Read(&v); err == nil { | ||
150 | + var num int64 | ||
151 | + if num, err = o.Delete(&NewRankRange{Id: id}); err == nil { | ||
152 | + fmt.Println("Number of records deleted in database:", num) | ||
153 | + } | ||
154 | + } | ||
155 | + return | ||
156 | +} |
models/rank_type.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "time" | ||
6 | + | ||
7 | + "github.com/astaxie/beego/orm" | ||
8 | +) | ||
9 | + | ||
10 | +type RankType struct { | ||
11 | + Id int64 `orm:"column(id);pk"` | ||
12 | + CompanyId int64 `orm:"column(company_id)"` | ||
13 | + Name string `orm:"column(name)"` | ||
14 | + EnableStatus int8 `orm:"column(enable_status)"` | ||
15 | + CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"` | ||
16 | + UpdataAt time.Time `orm:"column(update_at);type(timestamp);null" description:"更新时间"` | ||
17 | + Type int8 `orm:"column(type)"` | ||
18 | +} | ||
19 | + | ||
20 | +func (t *RankType) TableName() string { | ||
21 | + return "rank_type" | ||
22 | +} | ||
23 | + | ||
24 | +func init() { | ||
25 | + orm.RegisterModel(new(RankType)) | ||
26 | +} | ||
27 | + | ||
28 | +//榜单类型 | ||
29 | +const ( | ||
30 | + RANK_TYPE_SEASON int8 = 1 //季赛榜 | ||
31 | + RANK_TYPE_YEAR int8 = 2 //年榜 | ||
32 | +) | ||
33 | + | ||
34 | +//榜单状态 | ||
35 | +const ( | ||
36 | + RANK_STATUS_YES int8 = 1 //启用 | ||
37 | + RANK_STATUS_NO int8 = 2 //禁用 | ||
38 | +) | ||
39 | + | ||
40 | +// AddRank insert a new Rank into database and returns | ||
41 | +// last inserted Id on success. | ||
42 | +func AddRank(m *RankType) (id int64, err error) { | ||
43 | + o := orm.NewOrm() | ||
44 | + nowTime := time.Now() | ||
45 | + m.CreateAt = nowTime | ||
46 | + m.UpdataAt = nowTime | ||
47 | + id, err = o.Insert(m) | ||
48 | + return | ||
49 | +} | ||
50 | + | ||
51 | +// GetRankById retrieves Rank by Id. Returns error if | ||
52 | +// Id doesn't exist | ||
53 | +func GetRankById(id int64) (v *RankType, err error) { | ||
54 | + o := orm.NewOrm() | ||
55 | + v = &RankType{Id: id} | ||
56 | + if err = o.Read(v); err == nil { | ||
57 | + return v, nil | ||
58 | + } | ||
59 | + return nil, err | ||
60 | +} | ||
61 | + | ||
62 | +// UpdateRank updates Rank by Id and returns error if | ||
63 | +// the record to be updated doesn't exist | ||
64 | +func UpdateRankById(m *RankType, cols []string, om ...orm.Ormer) (err error) { | ||
65 | + var o orm.Ormer | ||
66 | + if len(om) > 0 { | ||
67 | + o = om[0] | ||
68 | + } else { | ||
69 | + o = orm.NewOrm() | ||
70 | + } | ||
71 | + m.UpdataAt = time.Now() | ||
72 | + if len(cols) > 0 { | ||
73 | + cols = append(cols, "UpdateAt") | ||
74 | + } | ||
75 | + var num int64 | ||
76 | + if num, err = o.Update(m, cols...); err == nil { | ||
77 | + fmt.Println("Number of records updated in database:", num) | ||
78 | + } | ||
79 | + | ||
80 | + return | ||
81 | +} |
protocol/rank.go
0 → 100644
1 | +package protocol | ||
2 | + | ||
3 | +//获取公司的榜单类型列表 | ||
4 | +type ResponseRankType struct { | ||
5 | + Id int `json:"id" orm:"column(id)"` | ||
6 | + Name string `json:"name" orm:"column(name)"` | ||
7 | + Status int8 `json:"status" orm:"column(status)"` | ||
8 | + RankType int8 `json:"rank_type" orm:"column(rank_type)"` | ||
9 | +} | ||
10 | + | ||
11 | +// ResponseRankSeasonList 赛季列表 | ||
12 | +type ResponseRankSeasonList struct { | ||
13 | + ResponsePageInfo | ||
14 | + List []RankSeasonItem `json:"lists"` | ||
15 | +} | ||
16 | +type RankSeasonItem struct { | ||
17 | + Id int64 `json:"id" orm:"column(id)"` | ||
18 | + SeasonName string `json:"season_name" orm:"column(season_name)"` | ||
19 | + BeginTime string `json:"begin_time" orm:"column(begin_time)"` | ||
20 | + EndTime string `json:"end_time" orm:"column(end_time)"` | ||
21 | + Status int8 `json:"status" orm:"column(status)"` | ||
22 | +} |
@@ -103,6 +103,14 @@ func init() { | @@ -103,6 +103,14 @@ func init() { | ||
103 | beego.NSRouter("/info", &controllers.AuditController{}, "post:AuditInfo"), | 103 | beego.NSRouter("/info", &controllers.AuditController{}, "post:AuditInfo"), |
104 | beego.NSRouter("/allow_forbid", &controllers.AuditController{}, "post:AllowForbidAudit"), | 104 | beego.NSRouter("/allow_forbid", &controllers.AuditController{}, "post:AllowForbidAudit"), |
105 | ), | 105 | ), |
106 | + beego.NSNamespace("/rank", | ||
107 | + beego.NSRouter("/list", &controllers.RankController{}, "post:GetRankType"), | ||
108 | + beego.NSRouter("/edit", &controllers.RankController{}, "post:EditRankType"), | ||
109 | + beego.NSRouter("/forbid_allow", &controllers.RankController{}, "post:RankTypeForbidAllow"), | ||
110 | + beego.NSRouter("/season/add", &controllers.RankController{}, "post:RankSeasonAdd"), | ||
111 | + beego.NSRouter("/season/list", &controllers.RankController{}, "post:RankSeasonList"), | ||
112 | + beego.NSRouter("/season/edit", &controllers.RankController{}, "post:RankSeasonEdit"), | ||
113 | + ), | ||
106 | ) | 114 | ) |
107 | 115 | ||
108 | nsAuth := beego.NewNamespace("/auth", | 116 | nsAuth := beego.NewNamespace("/auth", |
@@ -98,33 +98,7 @@ func buildSqlForAuditList(usercompanyid int64, companyid int64, userid int64) st | @@ -98,33 +98,7 @@ func buildSqlForAuditList(usercompanyid int64, companyid int64, userid int64) st | ||
98 | unionsql = sql1 + " UNION " + sql2 | 98 | unionsql = sql1 + " UNION " + sql2 |
99 | return fmt.Sprintf(allsql, unionsql) | 99 | return fmt.Sprintf(allsql, unionsql) |
100 | } | 100 | } |
101 | - // //获取权限 | ||
102 | - // if ok := redisdata.ExistUserPermission(userid); !ok { | ||
103 | - // //尝试重数据库获取 | ||
104 | - // log.Debug("从数据库读取权限") | ||
105 | - // permissionMap, err := serverabc.GetUserPermission(usercompanyid, serverabc.M_SYSTEM_OPPORTUNITY) | ||
106 | - // if err != nil { | ||
107 | - // log.Debug("从数据库未获得对应权限 :%s", err) | ||
108 | - // unionsql = sql1 + " UNION " + sql2 | ||
109 | - // return fmt.Sprintf(allsql, unionsql) | ||
110 | - // } | ||
111 | - // if v, ok := permissionMap[serverabc.M_SYSTEM_OPPORTUNITY]; !ok { | ||
112 | - // unionsql = sql1 + " UNION " + sql2 | ||
113 | - // return fmt.Sprintf(allsql, unionsql) | ||
114 | - // } else { | ||
115 | - // permissionObject = v | ||
116 | - // } | ||
117 | - // } else { | ||
118 | - // //使用缓存 | ||
119 | - // log.Debug("从缓存读取权限") | ||
120 | - // permissionObject, err = redisdata.GetUserPermission(userid, serverabc.M_SYSTEM_OPPORTUNITY) | ||
121 | - // if err != nil { | ||
122 | - // log.Debug("从缓存未获得对应权限 :%s", err) | ||
123 | - // unionsql = sql1 + " UNION " + sql2 | ||
124 | - // return fmt.Sprintf(allsql, unionsql) | ||
125 | - // } | ||
126 | - // } | ||
127 | - // ------------------------- | 101 | + |
128 | var ( | 102 | var ( |
129 | usrPermission *serverabc.OptionOpportunity | 103 | usrPermission *serverabc.OptionOpportunity |
130 | ok bool | 104 | ok bool |
services/rank/rank.go
0 → 100644
1 | +package rank | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "oppmg/common/log" | ||
6 | + "oppmg/models" | ||
7 | + "oppmg/protocol" | ||
8 | + "oppmg/utils" | ||
9 | + "time" | ||
10 | +) | ||
11 | + | ||
12 | +//GetRankList 获取榜单类型列表 | ||
13 | +func GetRankList(companyid int64) []protocol.ResponseRankType { | ||
14 | + var ( | ||
15 | + rspData = make([]protocol.ResponseRankType, 0) | ||
16 | + err error | ||
17 | + ) | ||
18 | + sqlString := `SELECT id,name,status,rank_type FROM rank WHERE company_id=?` | ||
19 | + err = utils.ExecuteQueryAll(&rspData, sqlString, companyid) | ||
20 | + if err != nil { | ||
21 | + log.Error("获取榜单列表失败,err%s", err) | ||
22 | + return rspData | ||
23 | + } | ||
24 | + if len(rspData) >= 2 { | ||
25 | + return rspData | ||
26 | + } | ||
27 | + if len(rspData) < 2 { | ||
28 | + AddDefaultRankType(companyid) | ||
29 | + } | ||
30 | + err = utils.ExecuteQueryAll(&rspData, sqlString, companyid) | ||
31 | + if err != nil { | ||
32 | + log.Error("获取榜单列表失败,err%s", err) | ||
33 | + return rspData | ||
34 | + } | ||
35 | + return rspData | ||
36 | +} | ||
37 | + | ||
38 | +func AddDefaultRankType(companyid int64) []*models.RankType { | ||
39 | + var ( | ||
40 | + rankA *models.RankType | ||
41 | + rankB *models.RankType | ||
42 | + err error | ||
43 | + ) | ||
44 | + rankA = &models.RankType{ | ||
45 | + CompanyId: companyid, | ||
46 | + Name: "季赛榜", | ||
47 | + Type: models.RANK_TYPE_SEASON, | ||
48 | + EnableStatus: models.RANK_STATUS_YES, | ||
49 | + } | ||
50 | + rankB = &models.RankType{ | ||
51 | + CompanyId: companyid, | ||
52 | + Name: "年榜", | ||
53 | + Type: models.RANK_TYPE_YEAR, | ||
54 | + EnableStatus: models.RANK_STATUS_YES, | ||
55 | + } | ||
56 | + _, err = models.AddRank(rankA) | ||
57 | + if err != nil { | ||
58 | + log.Error("添加榜单失败:AddRank,err:%s", err) | ||
59 | + } | ||
60 | + _, err = models.AddRank(rankB) | ||
61 | + if err != nil { | ||
62 | + log.Error("添加榜单失败:AddRank,err:%s", err) | ||
63 | + } | ||
64 | + ranks := []*models.RankType{ | ||
65 | + rankA, rankB, | ||
66 | + } | ||
67 | + return ranks | ||
68 | +} | ||
69 | + | ||
70 | +func UpdateRankType(id int64, name string, companyid int64) error { | ||
71 | + var ( | ||
72 | + err error | ||
73 | + ranktype *models.RankType | ||
74 | + ) | ||
75 | + ranktype, err = models.GetRankById(id) | ||
76 | + if err != nil { | ||
77 | + log.Error("获取榜单类型数据失败:%s", err) | ||
78 | + return protocol.NewErrWithMessage("1") | ||
79 | + } | ||
80 | + if ranktype.CompanyId != companyid { | ||
81 | + log.Error("数据无法与公司id对应") | ||
82 | + return protocol.NewErrWithMessage("1") | ||
83 | + } | ||
84 | + ranktype.Name = name | ||
85 | + err = models.UpdateRankById(ranktype, []string{"Name"}) | ||
86 | + if err != nil { | ||
87 | + log.Error("更新榜单数据失败:%s", err) | ||
88 | + return protocol.NewErrWithMessage("1") | ||
89 | + } | ||
90 | + return nil | ||
91 | +} | ||
92 | + | ||
93 | +//ForbidRank 禁用榜单 | ||
94 | +func ForbidRank(id int64, companyid int64) error { | ||
95 | + var ( | ||
96 | + err error | ||
97 | + ranktype *models.RankType | ||
98 | + ) | ||
99 | + ranktype, err = models.GetRankById(id) | ||
100 | + if err != nil { | ||
101 | + log.Error("获取榜单类型数据失败:%s", err) | ||
102 | + return protocol.NewErrWithMessage("1") | ||
103 | + } | ||
104 | + if ranktype.CompanyId != companyid { | ||
105 | + log.Error("数据无法与公司id对应") | ||
106 | + return protocol.NewErrWithMessage("1") | ||
107 | + } | ||
108 | + ranktype.EnableStatus = models.RANK_STATUS_NO | ||
109 | + err = models.UpdateRankById(ranktype, []string{"EnableStatus"}) | ||
110 | + if err != nil { | ||
111 | + log.Error("更新榜单数据失败:%s", err) | ||
112 | + return protocol.NewErrWithMessage("1") | ||
113 | + } | ||
114 | + return nil | ||
115 | + | ||
116 | +} | ||
117 | + | ||
118 | +//AllowRank 启用榜单 | ||
119 | +func AllowRank(id int64, companyid int64) error { | ||
120 | + var ( | ||
121 | + err error | ||
122 | + ranktype *models.RankType | ||
123 | + ) | ||
124 | + ranktype, err = models.GetRankById(id) | ||
125 | + if err != nil { | ||
126 | + log.Error("获取榜单类型数据失败:%s", err) | ||
127 | + return protocol.NewErrWithMessage("1") | ||
128 | + } | ||
129 | + if ranktype.CompanyId != companyid { | ||
130 | + log.Error("数据无法与公司id对应") | ||
131 | + return protocol.NewErrWithMessage("1") | ||
132 | + } | ||
133 | + ranktype.EnableStatus = models.RANK_STATUS_YES | ||
134 | + err = models.UpdateRankById(ranktype, []string{"EnableStatus"}) | ||
135 | + if err != nil { | ||
136 | + log.Error("更新榜单数据失败:%s", err) | ||
137 | + return protocol.NewErrWithMessage("1") | ||
138 | + } | ||
139 | + return nil | ||
140 | + | ||
141 | +} | ||
142 | + | ||
143 | +//RankSeasonList ..获取赛季列表 | ||
144 | +func RankSeasonList(pageindex int, pagesize int, companyid int64) (protocol.ResponseRankSeasonList, error) { | ||
145 | + var ( | ||
146 | + err error | ||
147 | + listdata []protocol.RankSeasonItem | ||
148 | + cnt int64 | ||
149 | + ) | ||
150 | + rspData := protocol.ResponseRankSeasonList{ | ||
151 | + ResponsePageInfo: protocol.ResponsePageInfo{ | ||
152 | + TotalPage: 0, CurrentPage: pageindex, | ||
153 | + }, | ||
154 | + List: make([]protocol.RankSeasonItem, 0), | ||
155 | + } | ||
156 | + pageStart := (pageindex - 1) * pagesize | ||
157 | + datasql := `SELECT id,season_name,begin_time,end_time,status FROM rank_period WHERE company_id = ?` | ||
158 | + datasql = fmt.Sprintf("%s ORDER BY begin_time DESC limit %d,%d", datasql, pageStart, pagesize) | ||
159 | + countsql := `SELECT COUNT(*) FROM rank_period WHERE company_id = ?` | ||
160 | + err = utils.ExecuteQueryOne(&cnt, countsql, companyid) | ||
161 | + if err != nil { | ||
162 | + log.Error("EXCUTE SQL ERR:%s", err) | ||
163 | + return rspData, nil | ||
164 | + } | ||
165 | + if cnt <= 0 { | ||
166 | + return rspData, nil | ||
167 | + } | ||
168 | + err = utils.ExecuteQueryAll(&listdata, datasql, companyid) | ||
169 | + if err != nil { | ||
170 | + log.Error("EXCUTE SQL ERR:%s", err) | ||
171 | + return rspData, nil | ||
172 | + } | ||
173 | + return rspData, err | ||
174 | +} | ||
175 | + | ||
176 | +func AddRankSeason(beginTime int64, endTime int64, name string, companyid int64) error { | ||
177 | + var ( | ||
178 | + err error | ||
179 | + ) | ||
180 | + m := &models.RankPeriod{ | ||
181 | + CompanyId: companyid, | ||
182 | + SeasonName: name, | ||
183 | + BeginTime: time.Unix(beginTime, 0), | ||
184 | + EndTime: time.Unix(endTime, 0), | ||
185 | + Status: 0, | ||
186 | + } | ||
187 | + _, err = models.AddRankPeriod(m) | ||
188 | + if err != nil { | ||
189 | + log.Error("添加赛季失败;%s", err) | ||
190 | + } | ||
191 | + return nil | ||
192 | +} | ||
193 | + | ||
194 | +func EditRankSeason(id int64, beginTime int64, endTime int64, name string, companyid int64) error { | ||
195 | + var ( | ||
196 | + err error | ||
197 | + m *models.RankPeriod | ||
198 | + ) | ||
199 | + m, err = models.GetRankPeriodById(id) | ||
200 | + if err != nil { | ||
201 | + log.Error("获取赛季失败;%s", err) | ||
202 | + return protocol.NewErrWithMessage("1") | ||
203 | + } | ||
204 | + if m.CompanyId != companyid { | ||
205 | + log.Error("公司不匹配") | ||
206 | + return protocol.NewErrWithMessage("1") | ||
207 | + } | ||
208 | + m.SeasonName = name | ||
209 | + m.BeginTime = time.Unix(beginTime, 0) | ||
210 | + m.EndTime = time.Unix(endTime, 0) | ||
211 | + err = models.UpdateRankPeriodById(m) | ||
212 | + if err != nil { | ||
213 | + log.Error("更新赛季失败;%s", err) | ||
214 | + } | ||
215 | + return nil | ||
216 | +} | ||
217 | + | ||
218 | +//获取赛季参与人列表 | ||
219 | +func GetRankRangeList() { | ||
220 | + | ||
221 | +} |
-
请 注册 或 登录 后发表评论