rank.go
7.0 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
package controllers
import (
"encoding/json"
"oppmg/common/log"
"oppmg/models"
"oppmg/protocol"
serverank "oppmg/services/rank"
)
type RankController struct {
BaseController
}
//GetRankType ..
//@router /rank/list
func (c RankController) GetRankType() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
companyid := c.GetCompanyId()
rspData := serverank.GetRankList(companyid)
msg = protocol.NewReturnResponse(rspData, nil)
return
}
//EditRankType ...
//@router /rank/edit
func (c RankController) EditRankType() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
type Parameter struct {
Id int64 `json:"id"`
Name string `json:"name"`
}
var param Parameter
if err := json.Unmarshal(c.Ctx.Input.RequestBody, ¶m); err != nil {
log.Error("json 解析失败 err:%s", err)
msg = protocol.BadRequestParam("1")
return
}
companyid := c.GetCompanyId()
err := serverank.UpdateRankType(param.Id, param.Name, companyid)
msg = protocol.NewReturnResponse(nil, err)
return
}
//EditRankType ...
//@router /rank/forbid_allow
func (c RankController) RankTypeForbidAllow() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
type Parameter struct {
Id int64 `json:"id"`
status int `json:"status"`
}
var param Parameter
if err := json.Unmarshal(c.Ctx.Input.RequestBody, ¶m); err != nil {
log.Error("json 解析失败 err:%s", err)
msg = protocol.BadRequestParam("1")
return
}
var err error
companyid := c.GetCompanyId()
switch param.status {
case 1:
err = serverank.ForbidRank(param.Id, companyid)
case 2:
err = serverank.AllowRank(param.Id, companyid)
}
msg = protocol.NewReturnResponse(nil, err)
return
}
//RankSeasonList ...
//@router /rank/season/list
func (c RankController) RankSeasonList() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
var param protocol.RequestPageInfo
if err := json.Unmarshal(c.Ctx.Input.RequestBody, ¶m); err != nil {
log.Error("json 解析失败 err:%s", err)
msg = protocol.BadRequestParam("1")
return
}
companyid := c.GetCompanyId()
rspData, err := serverank.RankSeasonList(param.PageIndex, param.PageSize, companyid)
msg = protocol.NewReturnResponse(rspData, err)
return
}
//RankSeasonAdd ...
//@router /rank/season/add
func (c RankController) RankSeasonAdd() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
type Parameter struct {
Name string `json:"name"`
BeginTime string `json:"begin_time"`
EndTime string `json:"end_time"`
}
var param Parameter
if err := json.Unmarshal(c.Ctx.Input.RequestBody, ¶m); err != nil {
log.Error("json 解析失败 err:%s", err)
msg = protocol.BadRequestParam("1")
return
}
var (
beginTime int64
endTime int64
)
companyid := c.GetCompanyId()
err := serverank.AddRankSeason(beginTime, endTime, param.Name, companyid)
msg = protocol.NewReturnResponse(nil, err)
return
}
//RankSeasonEdit ...
//@router /rank/season/edit
func (c RankController) RankSeasonEdit() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
type Parameter struct {
Id int64 `json:"id"`
Name string `json:"name"`
BeginTime string `json:"begin_time"`
EndTime string `json:"end_time"`
}
var param Parameter
if err := json.Unmarshal(c.Ctx.Input.RequestBody, ¶m); err != nil {
log.Error("json 解析失败 err:%s", err)
msg = protocol.BadRequestParam("1")
return
}
var (
beginTime int64
endTime int64
)
companyid := c.GetCompanyId()
err := serverank.EditRankSeason(param.Id, beginTime, endTime, param.Name, companyid)
msg = protocol.NewReturnResponse(nil, err)
return
}
//RankRangeList ...
//@router /rank/range/list
func (c RankController) RankRangeList() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
companyid := c.GetCompanyId()
rspData := serverank.GetRankRangeList(companyid)
msg = protocol.NewReturnResponse(rspData, nil)
return
}
//RankRangeAdd ...
//@router /rank/range/add
func (c RankController) RankRangeAdd() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
type Parameter struct {
Name string `json:"name"`
RangeType int8 `json:"range_type"`
RelationId []int64 `json:"relation_id"`
}
var param Parameter
if err := json.Unmarshal(c.Ctx.Input.RequestBody, ¶m); err != nil {
log.Error("json 解析失败 err:%s", err)
msg = protocol.BadRequestParam("1")
return
}
switch param.RangeType {
case 1:
//员工
if len(param.RelationId) == 0 {
param.RangeType = models.RANK_RANGE_TYPE_EMPLAYEEALL
} else {
param.RangeType = models.RANK_RANGE_TYPE_EMPLAYEE
}
case 2:
//部门
if len(param.RelationId) == 0 {
param.RangeType = models.RANK_RANGE_TYPE_DEPARTMENTALL
} else {
param.RangeType = models.RANK_RANGE_TYPE_DEPARTMENT
}
default:
log.Error("param.RangeType err")
msg = protocol.BadRequestParam("1")
return
}
companyid := c.GetCompanyId()
err := serverank.AddRankRange(param.Name, param.RangeType, param.RelationId, companyid)
msg = protocol.NewReturnResponse(nil, err)
return
}
//RankRangeEdit ...
//@router /rank/range/edit
func (c RankController) RankRangeEdit() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
type Parameter struct {
Id int64 `json:"id"`
Name string `json:"name"`
RangeType int8 `json:"range_type"`
RelationId []int64 `json:"relation_id"`
}
var param Parameter
if err := json.Unmarshal(c.Ctx.Input.RequestBody, ¶m); err != nil {
log.Error("json 解析失败 err:%s", err)
msg = protocol.BadRequestParam("1")
return
}
switch param.RangeType {
case 1:
//员工
if len(param.RelationId) == 0 {
param.RangeType = models.RANK_RANGE_TYPE_EMPLAYEEALL
} else {
param.RangeType = models.RANK_RANGE_TYPE_EMPLAYEE
}
case 2:
//部门
if len(param.RelationId) == 0 {
param.RangeType = models.RANK_RANGE_TYPE_DEPARTMENTALL
} else {
param.RangeType = models.RANK_RANGE_TYPE_DEPARTMENT
}
default:
log.Error("param.RangeType err")
msg = protocol.BadRequestParam("1")
return
}
companyid := c.GetCompanyId()
err := serverank.EditRankRange(param.Id, param.Name, param.RangeType, param.RelationId, companyid)
msg = protocol.NewReturnResponse(nil, err)
return
}
//RankRangeInfo ...
//@router /rank/range/info
func (c RankController) RankRangeInfo() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
type Parameter struct {
Id int64 `json:"id"`
}
var param Parameter
if err := json.Unmarshal(c.Ctx.Input.RequestBody, ¶m); err != nil {
log.Error("json 解析失败 err:%s", err)
msg = protocol.BadRequestParam("1")
return
}
// companyid := c.GetCompanyId()
rspData := serverank.GetRankRangeInfo(param.Id)
switch rspData.RangeType {
case models.RANK_RANGE_TYPE_DEPARTMENT, models.RANK_RANGE_TYPE_DEPARTMENTALL:
//部门
rspData.RangeType = 2
case models.RANK_RANGE_TYPE_EMPLAYEE, models.RANK_RANGE_TYPE_EMPLAYEEALL:
//员工
rspData.RangeType = 1
}
msg = protocol.NewReturnResponse(rspData, nil)
return
}