正在显示
19 个修改的文件
包含
556 行增加
和
74 行删除
@@ -33,3 +33,24 @@ func (this *DepartmentController) Departments() { | @@ -33,3 +33,24 @@ func (this *DepartmentController) Departments() { | ||
33 | header := controllers.GetRequestHeader(this.Ctx) | 33 | header := controllers.GetRequestHeader(this.Ctx) |
34 | msg = protocol.NewReturnResponse(department.Departments(header, request)) | 34 | msg = protocol.NewReturnResponse(department.Departments(header, request)) |
35 | } | 35 | } |
36 | + | ||
37 | +//DepartmentStatistics 部门统计 | ||
38 | +//@router /statistics [post] | ||
39 | +func (this *DepartmentController) DepartmentStatistics() { | ||
40 | + var msg *protocol.ResponseMessage | ||
41 | + defer func() { | ||
42 | + this.Resp(msg) | ||
43 | + }() | ||
44 | + var request *protocol.DepartmentStatisticsRequest | ||
45 | + if err := json.Unmarshal(this.ByteBody, &request); err != nil { | ||
46 | + log.Error(err) | ||
47 | + msg = protocol.BadRequestParam(1) | ||
48 | + return | ||
49 | + } | ||
50 | + if b, m := this.Valid(request); !b { | ||
51 | + msg = m | ||
52 | + return | ||
53 | + } | ||
54 | + header := controllers.GetRequestHeader(this.Ctx) | ||
55 | + msg = protocol.NewReturnResponse(department.DepartmentStatistics(header, request)) | ||
56 | +} |
controllers/v1/rank.go
0 → 100644
1 | +package v1 | ||
2 | + | ||
3 | +import ( | ||
4 | + "encoding/json" | ||
5 | + "opp/controllers" | ||
6 | + "opp/protocol" | ||
7 | + "opp/services/rank" | ||
8 | + | ||
9 | + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" | ||
10 | +) | ||
11 | + | ||
12 | +type RankController struct { | ||
13 | + controllers.BaseController | ||
14 | +} | ||
15 | + | ||
16 | +//GetRankList 排行榜 | ||
17 | +// @router /getRankList [post] | ||
18 | +func (this *RankController) GetRankList() { | ||
19 | + var msg *protocol.ResponseMessage | ||
20 | + defer func() { | ||
21 | + this.Resp(msg) | ||
22 | + }() | ||
23 | + var request *protocol.GetRankListRequest | ||
24 | + if err := json.Unmarshal(this.ByteBody, &request); err != nil { | ||
25 | + log.Error(err) | ||
26 | + msg = protocol.BadRequestParam(1) | ||
27 | + return | ||
28 | + } | ||
29 | + if b, m := this.Valid(request); !b { | ||
30 | + msg = m | ||
31 | + return | ||
32 | + } | ||
33 | + header := controllers.GetRequestHeader(this.Ctx) | ||
34 | + msg = protocol.NewReturnResponse(rank.GetRankList(header, request)) | ||
35 | +} | ||
36 | + | ||
37 | +//GetRankType 获取榜单类型列表 (年榜/赛季榜) | ||
38 | +// @router /getRankType [post] | ||
39 | +func (this *RankController) GetRankType() { | ||
40 | + var msg *protocol.ResponseMessage | ||
41 | + defer func() { | ||
42 | + this.Resp(msg) | ||
43 | + }() | ||
44 | + var request *protocol.GetRankTypeRequest | ||
45 | + if err := json.Unmarshal(this.ByteBody, &request); err != nil { | ||
46 | + log.Error(err) | ||
47 | + msg = protocol.BadRequestParam(1) | ||
48 | + return | ||
49 | + } | ||
50 | + if b, m := this.Valid(request); !b { | ||
51 | + msg = m | ||
52 | + return | ||
53 | + } | ||
54 | + header := controllers.GetRequestHeader(this.Ctx) | ||
55 | + msg = protocol.NewReturnResponse(rank.GetRankType(header, request)) | ||
56 | +} | ||
57 | + | ||
58 | +//GetRankRange 获取榜单竞争范围列表 | ||
59 | +//@router /getRankRange [post] | ||
60 | +func (this *RankController) GetRankRange() { | ||
61 | + var msg *protocol.ResponseMessage | ||
62 | + defer func() { | ||
63 | + this.Resp(msg) | ||
64 | + }() | ||
65 | + var request *protocol.GetRankRangeRequest | ||
66 | + if err := json.Unmarshal(this.ByteBody, &request); err != nil { | ||
67 | + log.Error(err) | ||
68 | + msg = protocol.BadRequestParam(1) | ||
69 | + return | ||
70 | + } | ||
71 | + if b, m := this.Valid(request); !b { | ||
72 | + msg = m | ||
73 | + return | ||
74 | + } | ||
75 | + header := controllers.GetRequestHeader(this.Ctx) | ||
76 | + msg = protocol.NewReturnResponse(rank.GetRankRange(header, request)) | ||
77 | +} | ||
78 | + | ||
79 | +//GetRankPeriods 获取排行榜周期列表 | ||
80 | +//@router /getRankPeriods [post] | ||
81 | +func (this *RankController) GetRankPeriods() { | ||
82 | + var msg *protocol.ResponseMessage | ||
83 | + defer func() { | ||
84 | + this.Resp(msg) | ||
85 | + }() | ||
86 | + var request *protocol.GetRankPeriodsRequest | ||
87 | + if err := json.Unmarshal(this.ByteBody, &request); err != nil { | ||
88 | + log.Error(err) | ||
89 | + msg = protocol.BadRequestParam(1) | ||
90 | + return | ||
91 | + } | ||
92 | + if b, m := this.Valid(request); !b { | ||
93 | + msg = m | ||
94 | + return | ||
95 | + } | ||
96 | + header := controllers.GetRequestHeader(this.Ctx) | ||
97 | + msg = protocol.NewReturnResponse(rank.GetRankPeriods(header, request)) | ||
98 | +} |
1 | package utils | 1 | package utils |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | + "bytes" | ||
4 | "errors" | 5 | "errors" |
5 | "fmt" | 6 | "fmt" |
6 | "github.com/astaxie/beego/orm" | 7 | "github.com/astaxie/beego/orm" |
@@ -183,3 +184,62 @@ func ExecuteSQLWithOrmer(o orm.Ormer, sqlstr string, param ...interface{}) error | @@ -183,3 +184,62 @@ func ExecuteSQLWithOrmer(o orm.Ormer, sqlstr string, param ...interface{}) error | ||
183 | log.Debug(fmt.Sprintf("RowsAffected:%d", num)) | 184 | log.Debug(fmt.Sprintf("RowsAffected:%d", num)) |
184 | return nil | 185 | return nil |
185 | } | 186 | } |
187 | + | ||
188 | +type SqlExcutor struct { | ||
189 | + table string | ||
190 | + wherestr []string | ||
191 | + orderstr []string | ||
192 | + islimit bool | ||
193 | + offset int | ||
194 | + pagenum int | ||
195 | +} | ||
196 | + | ||
197 | +func NewSqlExutor() *SqlExcutor { | ||
198 | + return &SqlExcutor{} | ||
199 | +} | ||
200 | + | ||
201 | +func (s *SqlExcutor) Table(str string) *SqlExcutor { | ||
202 | + s.table = str | ||
203 | + return s | ||
204 | +} | ||
205 | + | ||
206 | +func (s *SqlExcutor) Where(condition ...string) *SqlExcutor { | ||
207 | + if len(condition) <= 0 { | ||
208 | + return s | ||
209 | + } | ||
210 | + s.wherestr = append(s.wherestr, condition...) | ||
211 | + return s | ||
212 | +} | ||
213 | + | ||
214 | +func (s *SqlExcutor) Order(condition ...string) *SqlExcutor { | ||
215 | + if len(condition) <= 0 { | ||
216 | + return s | ||
217 | + } | ||
218 | + s.orderstr = append(s.orderstr, condition...) | ||
219 | + return s | ||
220 | +} | ||
221 | + | ||
222 | +func (s *SqlExcutor) Limit(page, pagenum int) *SqlExcutor { | ||
223 | + offset := 0 | ||
224 | + if page > 0 { | ||
225 | + offset = (page - 1) * pagenum | ||
226 | + } | ||
227 | + s.islimit = true | ||
228 | + s.offset = offset | ||
229 | + s.pagenum = pagenum | ||
230 | + return s | ||
231 | +} | ||
232 | + | ||
233 | +func (s *SqlExcutor) WhereString() string { | ||
234 | + sql := bytes.NewBufferString("") | ||
235 | + if len(s.wherestr) > 0 { | ||
236 | + sql.WriteString(" where ") | ||
237 | + for i := range s.wherestr { | ||
238 | + if i != 0 { | ||
239 | + sql.WriteString(" AND ") | ||
240 | + } | ||
241 | + sql.WriteString(s.wherestr[i]) | ||
242 | + } | ||
243 | + } | ||
244 | + return sql.String() | ||
245 | +} |
1 | package models | 1 | package models |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | - "bytes" | ||
5 | "fmt" | 4 | "fmt" |
6 | "opp/internal/utils" | 5 | "opp/internal/utils" |
7 | "time" | 6 | "time" |
@@ -66,25 +65,30 @@ func UpdateAchievementById(m *Achievement) (err error) { | @@ -66,25 +65,30 @@ func UpdateAchievementById(m *Achievement) (err error) { | ||
66 | //@lastId 最后编号 | 65 | //@lastId 最后编号 |
67 | //@chanceTypeId 机会一级分类编号 | 66 | //@chanceTypeId 机会一级分类编号 |
68 | //@departmentId 部门编号 | 67 | //@departmentId 部门编号 |
69 | -func GetAchievementAll(uid, cid int64, chanceTypeId int, lastId int64, departmentId int, pageSize int, v interface{}) (total int, err error) { | ||
70 | - var whereString bytes.Buffer | ||
71 | - if departmentId > 0 { | ||
72 | - whereString.WriteString(fmt.Sprintf(` and %v in (select department_id from user_department where user_company_id=achievement.user_company_id and enable_status=1) `, departmentId)) | 68 | +func GetAchievementAll(uid, cid int64, chanceTypeId int, lastId int64, departmentId []int, pageSize int, v interface{}) (total int, err error) { |
69 | + var filter = utils.NewSqlExutor() | ||
70 | + filter.Where(fmt.Sprintf("company_id=%v", cid)) | ||
71 | + filter.Where("status=1") | ||
72 | + if lastId > 0 { | ||
73 | + filter.Where(fmt.Sprintf("id<%v", lastId)) | ||
73 | } | 74 | } |
74 | - if uid > 0 { | ||
75 | - whereString.WriteString(fmt.Sprintf(` and user_company_id=%v `, uid)) | 75 | + if chanceTypeId > 0 { |
76 | + filter.Where(fmt.Sprintf("chance_type_id =%v", chanceTypeId)) | ||
77 | + } | ||
78 | + if len(departmentId) > 0 { | ||
79 | + filter.Where(fmt.Sprintf("department_id in (%v)", utils.JoinInts(departmentId, ","))) | ||
76 | } | 80 | } |
77 | sql := fmt.Sprintf(` | 81 | sql := fmt.Sprintf(` |
78 | -select id,user_company_id,create_at,source_content,audit_template_id,chance_type_id,grasp_score,user_grasp_score,comment_total,zan_total,view_total,images from achievement | ||
79 | -where company_id=%v and (%v=0 or id<%v) and (%v=0 or chance_type_id =%v) and status=1 %v | 82 | +select id,user_company_id,create_at,source_content,audit_template_id,chance_type_id,grasp_score,user_grasp_score,comment_total,zan_total,view_total,images from achievement |
83 | +%v | ||
80 | order by create_at desc | 84 | order by create_at desc |
81 | -limit %v | ||
82 | -`, cid, lastId, lastId, chanceTypeId, chanceTypeId, whereString.String(), pageSize) | 85 | +limit %v |
86 | +`, filter.WhereString(), pageSize) | ||
83 | 87 | ||
84 | sqlCount := fmt.Sprintf(` | 88 | sqlCount := fmt.Sprintf(` |
85 | -select count(0) from achievement | ||
86 | -where company_id=%v and (%v=0 or chance_type_id =%v) and status=1 %v | ||
87 | -`, cid, chanceTypeId, chanceTypeId, whereString.String()) | 89 | +select count(0) from achievement |
90 | +%v | ||
91 | +`, filter.WhereString()) | ||
88 | 92 | ||
89 | if err = utils.ExecuteQueryOne(&total, sqlCount); err != nil { | 93 | if err = utils.ExecuteQueryOne(&total, sqlCount); err != nil { |
90 | return | 94 | return |
@@ -264,23 +264,23 @@ where user_id =?` | @@ -264,23 +264,23 @@ where user_id =?` | ||
264 | } | 264 | } |
265 | 265 | ||
266 | //type4 查看所有机会 | 266 | //type4 查看所有机会 |
267 | -func GetChancePoolAll(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, v interface{}) (total int, err error) { | ||
268 | - | ||
269 | - sql := `select a.*,b.images,speechs,videos | 267 | +func GetChancePoolAll(uid, cid int64, chanceTypeId int, dIds []int, lastId int64, pageSize int, v interface{}) (total int, err error) { |
268 | + var filterDepartment string = getFilterSqlByDIds(dIds) | ||
269 | + sql := fmt.Sprintf(`select a.*,b.images,speechs,videos | ||
270 | from ( | 270 | from ( |
271 | select id,user_id,approve_time create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total from chance | 271 | select id,user_id,approve_time create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total from chance |
272 | -where company_id=? and review_status=3 and (?=0 or chance_type_id =?) and (?=0 or unix_timestamp(approve_time)<?) and enable_status=1 and status=1 | 272 | +where company_id=? and review_status=3 and (?=0 or chance_type_id =?) and (?=0 or unix_timestamp(approve_time)<?) and enable_status=1 and status=1 %v |
273 | ) a left JOIN chance_data b on a.id =b.chance_id | 273 | ) a left JOIN chance_data b on a.id =b.chance_id |
274 | order by create_at desc | 274 | order by create_at desc |
275 | limit ? | 275 | limit ? |
276 | -` | 276 | +`, filterDepartment) |
277 | 277 | ||
278 | //if public==protocol.pu | 278 | //if public==protocol.pu |
279 | 279 | ||
280 | sqlCount := fmt.Sprintf(`select count(0) from ( | 280 | sqlCount := fmt.Sprintf(`select count(0) from ( |
281 | select id from chance | 281 | select id from chance |
282 | -where company_id=? and review_status=3 and (%v=0 or chance_type_id =%v) and enable_status=1 and status=1 | ||
283 | -) a left JOIN chance_data b on a.id =b.chance_id`, chanceTypeId, chanceTypeId) | 282 | +where company_id=? and review_status=3 and (%v=0 or chance_type_id =%v) and enable_status=1 and status=1 %v |
283 | +) a left JOIN chance_data b on a.id =b.chance_id`, chanceTypeId, chanceTypeId, filterDepartment) | ||
284 | if err = utils.ExecuteQueryOne(&total, sqlCount, cid); err != nil { | 284 | if err = utils.ExecuteQueryOne(&total, sqlCount, cid); err != nil { |
285 | return | 285 | return |
286 | } | 286 | } |
@@ -293,8 +293,8 @@ where company_id=? and review_status=3 and (%v=0 or chance_type_id =%v) and ena | @@ -293,8 +293,8 @@ where company_id=? and review_status=3 and (%v=0 or chance_type_id =%v) and ena | ||
293 | } | 293 | } |
294 | 294 | ||
295 | //type3 特定部门机会 | 295 | //type3 特定部门机会 |
296 | -func GetChancePoolSpecialDepartment(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, v interface{}, departmentIds []int64) (total int, err error) { | ||
297 | - | 296 | +func GetChancePoolSpecialDepartment(uid, cid int64, chanceTypeId int, dIds []int, lastId int64, pageSize int, v interface{}, departmentIds []int64) (total int, err error) { |
297 | + var filterDepartment string = getFilterSqlByDIds(dIds) | ||
298 | sql := fmt.Sprintf(` | 298 | sql := fmt.Sprintf(` |
299 | select a.*,b.images,speechs,videos from ( | 299 | select a.*,b.images,speechs,videos from ( |
300 | select * from ( | 300 | select * from ( |
@@ -318,11 +318,11 @@ select * from ( | @@ -318,11 +318,11 @@ select * from ( | ||
318 | select DISTINCT chance_id from audit_flow_process where uid =%v | 318 | select DISTINCT chance_id from audit_flow_process where uid =%v |
319 | ) a inner join chance b on a.chance_id = b.id | 319 | ) a inner join chance b on a.chance_id = b.id |
320 | 320 | ||
321 | -) a where review_status=3 and (0=%v or chance_type_id =%v) and (0=%v or unix_timestamp(create_at)<%v) and a.enable_status=1 and status=1 | 321 | +) a where review_status=3 and (0=%v or chance_type_id =%v) and (0=%v or unix_timestamp(create_at)<%v) and a.enable_status=1 and status=1 %v |
322 | ) a left JOIN chance_data b on a.id =b.chance_id | 322 | ) a left JOIN chance_data b on a.id =b.chance_id |
323 | order by create_at desc | 323 | order by create_at desc |
324 | limit %v | 324 | limit %v |
325 | -`, cid, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId, lastId, lastId, pageSize) | 325 | +`, cid, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId, lastId, lastId, filterDepartment, pageSize) |
326 | 326 | ||
327 | sqlCount := fmt.Sprintf(` | 327 | sqlCount := fmt.Sprintf(` |
328 | select count(0) from ( | 328 | select count(0) from ( |
@@ -346,8 +346,8 @@ select count(0) from ( | @@ -346,8 +346,8 @@ select count(0) from ( | ||
346 | select DISTINCT chance_id from audit_flow_process where uid =%v | 346 | select DISTINCT chance_id from audit_flow_process where uid =%v |
347 | ) a inner join chance b on a.chance_id = b.id | 347 | ) a inner join chance b on a.chance_id = b.id |
348 | 348 | ||
349 | -) a where review_status=3 and (0=%v or chance_type_id =%v) and a.enable_status=1 and status=1 | ||
350 | -`, cid, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId) | 349 | +) a where review_status=3 and (0=%v or chance_type_id =%v) and a.enable_status=1 and status=1 %v |
350 | +`, cid, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId, filterDepartment) | ||
351 | if err = utils.ExecuteQueryOne(&total, sqlCount); err != nil { | 351 | if err = utils.ExecuteQueryOne(&total, sqlCount); err != nil { |
352 | return | 352 | return |
353 | } | 353 | } |
@@ -360,8 +360,8 @@ select count(0) from ( | @@ -360,8 +360,8 @@ select count(0) from ( | ||
360 | } | 360 | } |
361 | 361 | ||
362 | //type32 特定部门机会 - 多角色时包含levl2 部门公开 | 362 | //type32 特定部门机会 - 多角色时包含levl2 部门公开 |
363 | -func GetChancePoolDepartment(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, v interface{}, departmentIds []int64, userDepartmetIds []int64) (total int, err error) { | ||
364 | - | 363 | +func GetChancePoolDepartment(uid, cid int64, chanceTypeId int, dIds []int, lastId int64, pageSize int, v interface{}, departmentIds []int64, userDepartmetIds []int64) (total int, err error) { |
364 | + var filterDepartment string = getFilterSqlByDIds(dIds) | ||
365 | sql := fmt.Sprintf(` | 365 | sql := fmt.Sprintf(` |
366 | select a.*,b.images,speechs,videos from ( | 366 | select a.*,b.images,speechs,videos from ( |
367 | select * from ( | 367 | select * from ( |
@@ -393,11 +393,11 @@ select * from ( | @@ -393,11 +393,11 @@ select * from ( | ||
393 | select DISTINCT chance_id from audit_flow_process where uid =%v | 393 | select DISTINCT chance_id from audit_flow_process where uid =%v |
394 | ) a inner join chance b on a.chance_id = b.id | 394 | ) a inner join chance b on a.chance_id = b.id |
395 | 395 | ||
396 | -) a where review_status=3 and (0=%v or chance_type_id =%v) and (0=%v or unix_timestamp(create_at)<%v) and a.enable_status=1 and status=1 | 396 | +) a where review_status=3 and (0=%v or chance_type_id =%v) and (0=%v or unix_timestamp(create_at)<%v) and a.enable_status=1 and status=1 %v |
397 | ) a left JOIN chance_data b on a.id =b.chance_id | 397 | ) a left JOIN chance_data b on a.id =b.chance_id |
398 | order by create_at desc | 398 | order by create_at desc |
399 | limit %v | 399 | limit %v |
400 | -`, utils.JoinInt64s(userDepartmetIds, ","), cid, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId, lastId, lastId, pageSize) | 400 | +`, utils.JoinInt64s(userDepartmetIds, ","), cid, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId, lastId, lastId, filterDepartment, pageSize) |
401 | 401 | ||
402 | sqlCount := fmt.Sprintf(` | 402 | sqlCount := fmt.Sprintf(` |
403 | select count(0) from ( | 403 | select count(0) from ( |
@@ -429,8 +429,8 @@ select count(0) from ( | @@ -429,8 +429,8 @@ select count(0) from ( | ||
429 | select DISTINCT chance_id from audit_flow_process where uid =%v | 429 | select DISTINCT chance_id from audit_flow_process where uid =%v |
430 | ) a inner join chance b on a.chance_id = b.id | 430 | ) a inner join chance b on a.chance_id = b.id |
431 | 431 | ||
432 | -) a where review_status=3 and (0=%v or chance_type_id =%v) and a.enable_status=1 and status=1 | ||
433 | -`, utils.JoinInt64s(userDepartmetIds, ","), cid, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId) | 432 | +) a where review_status=3 and (0=%v or chance_type_id =%v) and a.enable_status=1 and status=1 %v |
433 | +`, utils.JoinInt64s(userDepartmetIds, ","), cid, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId, filterDepartment) | ||
434 | if err = utils.ExecuteQueryOne(&total, sqlCount); err != nil { | 434 | if err = utils.ExecuteQueryOne(&total, sqlCount); err != nil { |
435 | return | 435 | return |
436 | } | 436 | } |
@@ -443,7 +443,8 @@ select count(0) from ( | @@ -443,7 +443,8 @@ select count(0) from ( | ||
443 | } | 443 | } |
444 | 444 | ||
445 | //type2 对我所在部门公开的机会 公司公开的机会 | 445 | //type2 对我所在部门公开的机会 公司公开的机会 |
446 | -func GetChancePoolPublicCompany(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, v interface{}, departmentIds []int64) (total int, err error) { | 446 | +func GetChancePoolPublicCompany(uid, cid int64, chanceTypeId int, dIds []int, lastId int64, pageSize int, v interface{}, departmentIds []int64) (total int, err error) { |
447 | + var filterDepartment string = getFilterSqlByDIds(dIds) | ||
447 | sql := fmt.Sprintf(` | 448 | sql := fmt.Sprintf(` |
448 | select a.*,b.images,speechs,videos from ( | 449 | select a.*,b.images,speechs,videos from ( |
449 | select * from ( | 450 | select * from ( |
@@ -470,11 +471,11 @@ select * from ( | @@ -470,11 +471,11 @@ select * from ( | ||
470 | select DISTINCT chance_id from audit_flow_process where uid =%v | 471 | select DISTINCT chance_id from audit_flow_process where uid =%v |
471 | ) a inner join chance b on a.chance_id = b.id | 472 | ) a inner join chance b on a.chance_id = b.id |
472 | 473 | ||
473 | -) a where review_status=3 and (0=%v or chance_type_id =%v) and (0=%v or unix_timestamp(create_at)<%v) and a.enable_status=1 and status=1 | 474 | +) a where review_status=3 and (0=%v or chance_type_id =%v) and (0=%v or unix_timestamp(create_at)<%v) and a.enable_status=1 and status=1 %v |
474 | ) a left JOIN chance_data b on a.id =b.chance_id | 475 | ) a left JOIN chance_data b on a.id =b.chance_id |
475 | order by create_at desc | 476 | order by create_at desc |
476 | limit %v | 477 | limit %v |
477 | -`, cid, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId, lastId, lastId, pageSize) | 478 | +`, cid, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId, lastId, lastId, filterDepartment, pageSize) |
478 | 479 | ||
479 | sqlCount := fmt.Sprintf(` | 480 | sqlCount := fmt.Sprintf(` |
480 | select count(0) from ( | 481 | select count(0) from ( |
@@ -501,8 +502,8 @@ select count(0) from ( | @@ -501,8 +502,8 @@ select count(0) from ( | ||
501 | select DISTINCT chance_id from audit_flow_process where uid =%v | 502 | select DISTINCT chance_id from audit_flow_process where uid =%v |
502 | ) a inner join chance b on a.chance_id = b.id | 503 | ) a inner join chance b on a.chance_id = b.id |
503 | 504 | ||
504 | -) a where review_status=3 and (0=%v or chance_type_id =%v) and a.enable_status=1 and status=1 | ||
505 | -`, cid, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId) | 505 | +) a where review_status=3 and (0=%v or chance_type_id =%v) and a.enable_status=1 and status=1 %v |
506 | +`, cid, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId, filterDepartment) | ||
506 | if err = utils.ExecuteQueryOne(&total, sqlCount); err != nil { | 507 | if err = utils.ExecuteQueryOne(&total, sqlCount); err != nil { |
507 | return | 508 | return |
508 | } | 509 | } |
@@ -513,9 +514,16 @@ select count(0) from ( | @@ -513,9 +514,16 @@ select count(0) from ( | ||
513 | } | 514 | } |
514 | return | 515 | return |
515 | } | 516 | } |
517 | +func getFilterSqlByDIds(dIds []int) string { | ||
518 | + if len(dIds) == 0 { | ||
519 | + return "" | ||
520 | + } | ||
521 | + return fmt.Sprintf(" and department_id in(%v) ", utils.JoinInts(dIds, ",")) | ||
522 | +} | ||
516 | 523 | ||
517 | //type1 禁止查看所有机会 | 524 | //type1 禁止查看所有机会 |
518 | -func GetChancePoolMyself(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, v interface{}) (total int, err error) { | 525 | +func GetChancePoolMyself(uid, cid int64, chanceTypeId int, dIds []int, lastId int64, pageSize int, v interface{}) (total int, err error) { |
526 | + var filterDepartment string = getFilterSqlByDIds(dIds) | ||
519 | sql := fmt.Sprintf(` | 527 | sql := fmt.Sprintf(` |
520 | select a.*,b.images,speechs,videos from ( | 528 | select a.*,b.images,speechs,videos from ( |
521 | select * from ( | 529 | select * from ( |
@@ -529,11 +537,11 @@ select * from ( | @@ -529,11 +537,11 @@ select * from ( | ||
529 | select DISTINCT chance_id from audit_flow_process where uid =%v | 537 | select DISTINCT chance_id from audit_flow_process where uid =%v |
530 | ) a inner join chance b on a.chance_id = b.id | 538 | ) a inner join chance b on a.chance_id = b.id |
531 | 539 | ||
532 | -) a where review_status=3 and (0=%v or chance_type_id =%v) and (0=%v or unix_timestamp(create_at)<%v) and a.enable_status=1 and status=1 | 540 | +) a where review_status=3 and (0=%v or chance_type_id =%v) and (0=%v or unix_timestamp(create_at)<%v) and a.enable_status=1 and status=1 %v |
533 | ) a left JOIN chance_data b on a.id =b.chance_id | 541 | ) a left JOIN chance_data b on a.id =b.chance_id |
534 | order by create_at desc | 542 | order by create_at desc |
535 | limit %v | 543 | limit %v |
536 | -`, uid, uid, chanceTypeId, chanceTypeId, lastId, lastId, pageSize) | 544 | +`, uid, uid, chanceTypeId, chanceTypeId, lastId, lastId, filterDepartment, pageSize) |
537 | 545 | ||
538 | sqlCount := fmt.Sprintf(` | 546 | sqlCount := fmt.Sprintf(` |
539 | select count(0) from ( | 547 | select count(0) from ( |
@@ -547,8 +555,8 @@ select count(0) from ( | @@ -547,8 +555,8 @@ select count(0) from ( | ||
547 | select DISTINCT chance_id from audit_flow_process where uid =%v | 555 | select DISTINCT chance_id from audit_flow_process where uid =%v |
548 | ) a inner join chance b on a.chance_id = b.id | 556 | ) a inner join chance b on a.chance_id = b.id |
549 | 557 | ||
550 | -) a where review_status=3 and (0=%v or chance_type_id =%v) and a.enable_status=1 and status=1 | ||
551 | -`, uid, uid, chanceTypeId, chanceTypeId) | 558 | +) a where review_status=3 and (0=%v or chance_type_id =%v) and a.enable_status=1 and status=1 %v |
559 | +`, uid, uid, chanceTypeId, chanceTypeId, filterDepartment) | ||
552 | if err = utils.ExecuteQueryOne(&total, sqlCount); err != nil { | 560 | if err = utils.ExecuteQueryOne(&total, sqlCount); err != nil { |
553 | return | 561 | return |
554 | } | 562 | } |
@@ -648,3 +656,14 @@ func ExitsChanceByAuditUser(chanceId int64, auditUserId int64) (v *Chance, err e | @@ -648,3 +656,14 @@ func ExitsChanceByAuditUser(chanceId int64, auditUserId int64) (v *Chance, err e | ||
648 | } | 656 | } |
649 | return | 657 | return |
650 | } | 658 | } |
659 | + | ||
660 | +//是否存在发布机会的部门编号查询 | ||
661 | +func GetChanceStatisticByDepartment(companyId int64, departmentIds []int, reviewStatus int) (v int, err error) { | ||
662 | + sql := fmt.Sprintf(`select count(0) from chance where company_id=%v and review_status=%v and department_id in (%v)`, | ||
663 | + companyId, reviewStatus, utils.JoinInts(departmentIds, ",")) | ||
664 | + o := orm.NewOrm() | ||
665 | + if err = o.Raw(sql).QueryRow(&v); err != nil { | ||
666 | + return | ||
667 | + } | ||
668 | + return | ||
669 | +} |
@@ -90,3 +90,13 @@ order by parent_id,id` | @@ -90,3 +90,13 @@ order by parent_id,id` | ||
90 | } | 90 | } |
91 | return | 91 | return |
92 | } | 92 | } |
93 | + | ||
94 | +func GetSubDepartmentIds(companyId int64, relation string) (v []int, err error) { | ||
95 | + o := orm.NewOrm() | ||
96 | + sql := fmt.Sprintf(` | ||
97 | +select id from department where company_id=? and relation like '%v%%' and delete_at =0`, relation) | ||
98 | + if _, err = o.Raw(sql, companyId).QueryRows(&v); err == nil { | ||
99 | + return | ||
100 | + } | ||
101 | + return | ||
102 | +} |
@@ -9,12 +9,13 @@ const ( | @@ -9,12 +9,13 @@ const ( | ||
9 | 9 | ||
10 | //成果项 | 10 | //成果项 |
11 | type AchievementItem struct { | 11 | type AchievementItem struct { |
12 | - Id int64 `json:"id"` | ||
13 | - CreateTime int64 `json:"createTime"` | ||
14 | - Provider *BaseUserInfo `json:"provider"` | ||
15 | - Content string `json:"content"` | ||
16 | - Pictures []Picture `json:"pictures"` | ||
17 | - GraspScore float64 `json:"graspScore"` //把握分 | 12 | + Id int64 `json:"id"` |
13 | + CreateTime int64 `json:"createTime"` | ||
14 | + Provider *BaseUserInfo `json:"provider"` | ||
15 | + Content string `json:"content"` | ||
16 | + Pictures []Picture `json:"pictures"` | ||
17 | + GraspScore float64 `json:"graspScore"` //把握分 | ||
18 | + GraspScorePercent float64 `json:"graspScorePercent"` //把握分百分比 | ||
18 | } | 19 | } |
19 | 20 | ||
20 | //机会列表 通用项 | 21 | //机会列表 通用项 |
@@ -105,9 +106,10 @@ type AchievementDetailResponse struct { | @@ -105,9 +106,10 @@ type AchievementDetailResponse struct { | ||
105 | } | 106 | } |
106 | 107 | ||
107 | type UserGraspInfo struct { | 108 | type UserGraspInfo struct { |
108 | - Provider *BaseUserInfo `json:"provider"` | ||
109 | - GraspScore float64 `json:"graspScore"` //把握分 | ||
110 | - Type int `json:"type"` //1:把握人 2:提供者 | 109 | + Provider *BaseUserInfo `json:"provider"` |
110 | + GraspScore float64 `json:"graspScore"` //把握分 | ||
111 | + GraspScorePercent float64 `json:"graspScorePercent"` //把握分百分比 | ||
112 | + Type int `json:"type"` //1:把握人 2:提供者 | ||
111 | } | 113 | } |
112 | 114 | ||
113 | type SourceChanceItemOrm struct { | 115 | type SourceChanceItemOrm struct { |
@@ -168,6 +168,7 @@ type ChancePoolRequest struct { | @@ -168,6 +168,7 @@ type ChancePoolRequest struct { | ||
168 | LastId int64 `json:"lastId"` | 168 | LastId int64 `json:"lastId"` |
169 | PageSize int `json:"pageSize" valid:"Required"` | 169 | PageSize int `json:"pageSize" valid:"Required"` |
170 | ChanceTypeId int `json:"chanceTypeId"` //0:所有机会 编号:对应机会类型编号的机会 | 170 | ChanceTypeId int `json:"chanceTypeId"` //0:所有机会 编号:对应机会类型编号的机会 |
171 | + DepartmentId int `json:"departmentId"` //部门编号 | ||
171 | } | 172 | } |
172 | type ChancePoolResponse struct { | 173 | type ChancePoolResponse struct { |
173 | List []CommonListItem `json:"list"` | 174 | List []CommonListItem `json:"list"` |
@@ -9,6 +9,11 @@ const ( | @@ -9,6 +9,11 @@ const ( | ||
9 | DepartmentAll //公司所有部门 | 9 | DepartmentAll //公司所有部门 |
10 | ) | 10 | ) |
11 | 11 | ||
12 | +const ( | ||
13 | + StatisticApproved = 1 //统计已审核 | ||
14 | + StatisticApproving = 2 //统计审核中 | ||
15 | +) | ||
16 | + | ||
12 | /*Departments */ | 17 | /*Departments */ |
13 | type DepartmentsRequest struct { | 18 | type DepartmentsRequest struct { |
14 | //Type int `json:"type" valid:"Required"` //1:公司所有部门 2:用户所在部门 | 19 | //Type int `json:"type" valid:"Required"` //1:公司所有部门 2:用户所在部门 |
@@ -59,3 +64,20 @@ type Department struct { | @@ -59,3 +64,20 @@ type Department struct { | ||
59 | Managers []int `json:"-"` | 64 | Managers []int `json:"-"` |
60 | Departments []*Department `json:"departments,omitempty"` | 65 | Departments []*Department `json:"departments,omitempty"` |
61 | } | 66 | } |
67 | + | ||
68 | +/*DepartmentStatistics 部门统计*/ | ||
69 | +type DepartmentStatisticsRequest struct { | ||
70 | + //DId int `json:"did"`//部门编号 //查询所有部门 查询特定部门 | ||
71 | + Type int `json:"type"` //1:已审核 2:待审核 | ||
72 | +} | ||
73 | +type DepartmentStatisticsResponse struct { | ||
74 | + List []*DepartmentStatistics `json:"departmentStatistics"` | ||
75 | +} | ||
76 | + | ||
77 | +//部门统计项 | ||
78 | +type DepartmentStatistics struct { | ||
79 | + Dep Dep `json:"dep"` //部门 | ||
80 | + ChanceApprovedTotal int `json:"chanceApprovedTotal"` //已审核的机会 | ||
81 | + ChanceApprovingTotal int `json:"chanceApprovingTotal"` //待审核的机会 | ||
82 | + AchievementTotal int `json:"achievementTotal"` //已创建的成果 (显示) | ||
83 | +} |
@@ -37,6 +37,7 @@ const ( | @@ -37,6 +37,7 @@ const ( | ||
37 | MyAuditChanceWait //我审核的机会-待我审批 | 37 | MyAuditChanceWait //我审核的机会-待我审批 |
38 | MyAuditChancePass //我审核的机会-已通过 | 38 | MyAuditChancePass //我审核的机会-已通过 |
39 | MyAuditChanceReturn //我审核的机会-已退回 | 39 | MyAuditChanceReturn //我审核的机会-已退回 |
40 | + MyAchievements //我的成就 | ||
40 | MyGraspAchievement //我把握的成果 | 41 | MyGraspAchievement //我把握的成果 |
41 | ) | 42 | ) |
42 | 43 |
protocol/rank.go
0 → 100644
1 | +package protocol | ||
2 | + | ||
3 | +/*GetRankList 排行榜*/ | ||
4 | +type GetRankListRequest struct { | ||
5 | + RankTypeId int `json:"rankTypeId" valid:"Required"` //榜单类型编号(赛季榜、年榜) | ||
6 | + RankRangeId int `json:"rankRangeId" valid:"Required"` //排行榜范围编号(员工/部门) | ||
7 | + RankPeriodId int `json:"rankPeriodId" valid:"Required"` //排行榜周期范围编号 (开始结束时间) | ||
8 | + PageIndex int64 `json:"pageIndex" valid:"Required"` //页码(默认0代表第1页) | ||
9 | + PageSize int `json:"pageSize" valid:"Required"` //每页数量 | ||
10 | +} | ||
11 | +type GetRankListResponse struct { | ||
12 | + Self RankItem `json:"self"` //自己或所在部门的排名分数 | ||
13 | + Lists []RankItem `json:"lists"` //排名列表 | ||
14 | +} | ||
15 | + | ||
16 | +type RankItem struct { | ||
17 | + Name string `json:"name,omitempty"` //名称 | ||
18 | + Score string `json:"score"` //分数 | ||
19 | + Ranking string `json:"ranking"` //排名 | ||
20 | +} | ||
21 | + | ||
22 | +/*GetRankType */ | ||
23 | +type GetRankTypeRequest struct { | ||
24 | +} | ||
25 | +type GetRankTypeResponse struct { | ||
26 | + List []RankType | ||
27 | +} | ||
28 | +type RankType struct { | ||
29 | + Id int `json:"id"` | ||
30 | + Name string `json:"name"` | ||
31 | +} | ||
32 | + | ||
33 | +/*GetRankRange */ | ||
34 | +type GetRankRangeRequest struct { | ||
35 | +} | ||
36 | +type GetRankRangeResponse struct { | ||
37 | +} | ||
38 | +type RankRange struct { | ||
39 | +} | ||
40 | + | ||
41 | +/*GetRankPeriods 获取榜单竞争范围列表*/ | ||
42 | +type GetRankPeriodsRequest struct { | ||
43 | +} | ||
44 | +type GetRankPeriodsResponse struct { | ||
45 | +} |
@@ -311,6 +311,14 @@ func init() { | @@ -311,6 +311,14 @@ func init() { | ||
311 | MethodParams: param.Make(), | 311 | MethodParams: param.Make(), |
312 | Params: nil}) | 312 | Params: nil}) |
313 | 313 | ||
314 | + beego.GlobalControllerRouter["opp/controllers/v1:DepartmentController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:DepartmentController"], | ||
315 | + beego.ControllerComments{ | ||
316 | + Method: "DepartmentStatistics", | ||
317 | + Router: `/statistics`, | ||
318 | + AllowHTTPMethods: []string{"post"}, | ||
319 | + MethodParams: param.Make(), | ||
320 | + Params: nil}) | ||
321 | + | ||
314 | beego.GlobalControllerRouter["opp/controllers/v1:FileController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:FileController"], | 322 | beego.GlobalControllerRouter["opp/controllers/v1:FileController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:FileController"], |
315 | beego.ControllerComments{ | 323 | beego.ControllerComments{ |
316 | Method: "GetPlayInfo", | 324 | Method: "GetPlayInfo", |
@@ -415,6 +423,38 @@ func init() { | @@ -415,6 +423,38 @@ func init() { | ||
415 | MethodParams: param.Make(), | 423 | MethodParams: param.Make(), |
416 | Params: nil}) | 424 | Params: nil}) |
417 | 425 | ||
426 | + beego.GlobalControllerRouter["opp/controllers/v1:RankController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:RankController"], | ||
427 | + beego.ControllerComments{ | ||
428 | + Method: "GetRankList", | ||
429 | + Router: `/getRankList`, | ||
430 | + AllowHTTPMethods: []string{"post"}, | ||
431 | + MethodParams: param.Make(), | ||
432 | + Params: nil}) | ||
433 | + | ||
434 | + beego.GlobalControllerRouter["opp/controllers/v1:RankController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:RankController"], | ||
435 | + beego.ControllerComments{ | ||
436 | + Method: "GetRankPeriods", | ||
437 | + Router: `/getRankPeriods`, | ||
438 | + AllowHTTPMethods: []string{"post"}, | ||
439 | + MethodParams: param.Make(), | ||
440 | + Params: nil}) | ||
441 | + | ||
442 | + beego.GlobalControllerRouter["opp/controllers/v1:RankController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:RankController"], | ||
443 | + beego.ControllerComments{ | ||
444 | + Method: "GetRankRange", | ||
445 | + Router: `/getRankRange`, | ||
446 | + AllowHTTPMethods: []string{"post"}, | ||
447 | + MethodParams: param.Make(), | ||
448 | + Params: nil}) | ||
449 | + | ||
450 | + beego.GlobalControllerRouter["opp/controllers/v1:RankController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:RankController"], | ||
451 | + beego.ControllerComments{ | ||
452 | + Method: "GetRankType", | ||
453 | + Router: `/getRankType`, | ||
454 | + AllowHTTPMethods: []string{"post"}, | ||
455 | + MethodParams: param.Make(), | ||
456 | + Params: nil}) | ||
457 | + | ||
418 | beego.GlobalControllerRouter["opp/controllers/v1:UcenterController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:UcenterController"], | 458 | beego.GlobalControllerRouter["opp/controllers/v1:UcenterController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:UcenterController"], |
419 | beego.ControllerComments{ | 459 | beego.ControllerComments{ |
420 | Method: "UCenterLogin", | 460 | Method: "UCenterLogin", |
@@ -8,7 +8,7 @@ import ( | @@ -8,7 +8,7 @@ import ( | ||
8 | ) | 8 | ) |
9 | 9 | ||
10 | //机会池 | 10 | //机会池 |
11 | -func GetChancePool(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, v interface{}) (total int, err error) { | 11 | +func GetChancePool(uid, cid int64, chanceTypeId int, departmentId int, lastId int64, pageSize int, v interface{}) (total int, err error) { |
12 | var ( | 12 | var ( |
13 | check int | 13 | check int |
14 | checkMap map[int]int | 14 | checkMap map[int]int |
@@ -16,6 +16,7 @@ func GetChancePool(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, | @@ -16,6 +16,7 @@ func GetChancePool(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, | ||
16 | userDIds []int64 | 16 | userDIds []int64 |
17 | user *models.User | 17 | user *models.User |
18 | chance *models.Chance | 18 | chance *models.Chance |
19 | + dIds []int | ||
19 | ) | 20 | ) |
20 | if user, err = models.GetUserByCompanyId(cid); err != nil { | 21 | if user, err = models.GetUserByCompanyId(cid); err != nil { |
21 | log.Error(err) | 22 | log.Error(err) |
@@ -43,29 +44,32 @@ func GetChancePool(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, | @@ -43,29 +44,32 @@ func GetChancePool(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, | ||
43 | } | 44 | } |
44 | lastId = chance.ApproveTime.Unix() | 45 | lastId = chance.ApproveTime.Unix() |
45 | } | 46 | } |
47 | + if departmentId > 0 { | ||
48 | + dIds, _ = GetDepartmentIds(cid, departmentId) | ||
49 | + } | ||
46 | log.Debug(fmt.Sprintf("user:%v check:%v is_amdin:%v", uid, check, user.Id == uid)) | 50 | log.Debug(fmt.Sprintf("user:%v check:%v is_amdin:%v", uid, check, user.Id == uid)) |
47 | switch check { | 51 | switch check { |
48 | case OpportunityCheckLv1: | 52 | case OpportunityCheckLv1: |
49 | - return models.GetChancePoolMyself(uid, cid, chanceTypeId, lastId, pageSize, v) | 53 | + return models.GetChancePoolMyself(uid, cid, chanceTypeId, dIds, lastId, pageSize, v) |
50 | case OpportunityCheckLv2: | 54 | case OpportunityCheckLv2: |
51 | if err = models.GetUserDepartmentIds(uid, cid, &userDIds); err != nil { | 55 | if err = models.GetUserDepartmentIds(uid, cid, &userDIds); err != nil { |
52 | log.Error(err) | 56 | log.Error(err) |
53 | return | 57 | return |
54 | } | 58 | } |
55 | - return models.GetChancePoolPublicCompany(uid, cid, chanceTypeId, lastId, pageSize, v, userDIds) | 59 | + return models.GetChancePoolPublicCompany(uid, cid, chanceTypeId, dIds, lastId, pageSize, v, userDIds) |
56 | case OpportunityCheckLv3: | 60 | case OpportunityCheckLv3: |
57 | if _, ok := checkMap[OpportunityCheckLv2]; ok { //同时存在对部门公开的机会 | 61 | if _, ok := checkMap[OpportunityCheckLv2]; ok { //同时存在对部门公开的机会 |
58 | if err = models.GetUserDepartmentIds(uid, cid, &userDIds); err != nil { | 62 | if err = models.GetUserDepartmentIds(uid, cid, &userDIds); err != nil { |
59 | log.Error(err) | 63 | log.Error(err) |
60 | return | 64 | return |
61 | } | 65 | } |
62 | - return models.GetChancePoolDepartment(uid, cid, chanceTypeId, lastId, pageSize, v, specialDIds, userDIds) | 66 | + return models.GetChancePoolDepartment(uid, cid, chanceTypeId, dIds, lastId, pageSize, v, specialDIds, userDIds) |
63 | } | 67 | } |
64 | - return models.GetChancePoolSpecialDepartment(uid, cid, chanceTypeId, lastId, pageSize, v, specialDIds) | 68 | + return models.GetChancePoolSpecialDepartment(uid, cid, chanceTypeId, dIds, lastId, pageSize, v, specialDIds) |
65 | case OpportunityCheckLv4: | 69 | case OpportunityCheckLv4: |
66 | - return models.GetChancePoolAll(uid, cid, chanceTypeId, lastId, pageSize, v) | 70 | + return models.GetChancePoolAll(uid, cid, chanceTypeId, dIds, lastId, pageSize, v) |
67 | default: | 71 | default: |
68 | - return models.GetChancePoolAll(uid, cid, chanceTypeId, lastId, pageSize, v) | 72 | + return models.GetChancePoolAll(uid, cid, chanceTypeId, dIds, lastId, pageSize, v) |
69 | } | 73 | } |
70 | return | 74 | return |
71 | } | 75 | } |
@@ -49,7 +49,7 @@ func MyApproveEnableStatic(header *protocol.RequestHeader, reviewStatus ...int8) | @@ -49,7 +49,7 @@ func MyApproveEnableStatic(header *protocol.RequestHeader, reviewStatus ...int8) | ||
49 | //我把握的统计 | 49 | //我把握的统计 |
50 | func MyGraspStatic(header *protocol.RequestHeader) (total int, err error) { | 50 | func MyGraspStatic(header *protocol.RequestHeader) (total int, err error) { |
51 | var () | 51 | var () |
52 | - if total, err = models.GetAchievementAll(header.UserId, header.CompanyId, 0, 0, 0, 0, nil); err != nil { | 52 | + if total, err = models.GetAchievementAll(header.UserId, header.CompanyId, 0, 0, []int{}, 0, nil); err != nil { |
53 | if err == orm.ErrNoRows { | 53 | if err == orm.ErrNoRows { |
54 | err = nil | 54 | err = nil |
55 | return | 55 | return |
@@ -59,3 +59,59 @@ func MyGraspStatic(header *protocol.RequestHeader) (total int, err error) { | @@ -59,3 +59,59 @@ func MyGraspStatic(header *protocol.RequestHeader) (total int, err error) { | ||
59 | } | 59 | } |
60 | return | 60 | return |
61 | } | 61 | } |
62 | + | ||
63 | +//我把握的统计 | ||
64 | +func AchievementDepartmentStatic(header *protocol.RequestHeader, chanceTypeId int, departmentIds []int) (total int, err error) { | ||
65 | + //var ( | ||
66 | + // departmentIds []int | ||
67 | + //) | ||
68 | + //if dId>0{ | ||
69 | + // departmentIds,_=GetDepartmentIds(header.CompanyId,dId) | ||
70 | + //} | ||
71 | + if total, err = models.GetAchievementAll(0, header.CompanyId, chanceTypeId, 0, departmentIds, 0, nil); err != nil { | ||
72 | + if err == orm.ErrNoRows { | ||
73 | + err = nil | ||
74 | + return | ||
75 | + } | ||
76 | + log.Error(err) | ||
77 | + return | ||
78 | + } | ||
79 | + return | ||
80 | +} | ||
81 | + | ||
82 | +//机会待审核统计 | ||
83 | +func ChanceApprovingStatistic(header *protocol.RequestHeader, departmentIds []int) (total int, err error) { | ||
84 | + //var ( | ||
85 | + // departmentIds []int | ||
86 | + //) | ||
87 | + //if dId>0{ | ||
88 | + // departmentIds,_=GetDepartmentIds(header.CompanyId,dId) | ||
89 | + //} | ||
90 | + //if len(departmentIds)==0{ | ||
91 | + // return | ||
92 | + //} | ||
93 | + if total, err = models.GetChanceStatisticByDepartment(header.CompanyId, departmentIds, protocol.ReviewStatusAuditging); err != nil { | ||
94 | + if err == orm.ErrNoRows { | ||
95 | + err = nil | ||
96 | + return | ||
97 | + } | ||
98 | + log.Error(err) | ||
99 | + return | ||
100 | + } | ||
101 | + return | ||
102 | +} | ||
103 | + | ||
104 | +//获取部门以及子部门编号 | ||
105 | +func GetDepartmentIds(companyId int64, dId int) (departmentIds []int, err error) { | ||
106 | + if d, e := models.GetDepartmentById(dId); e != nil { | ||
107 | + log.Error(err) | ||
108 | + err = e | ||
109 | + return | ||
110 | + } else { | ||
111 | + if departmentIds, err = models.GetSubDepartmentIds(companyId, d.Relation); err != nil { | ||
112 | + log.Error(err) | ||
113 | + return | ||
114 | + } | ||
115 | + } | ||
116 | + return | ||
117 | +} |
@@ -13,12 +13,25 @@ import ( | @@ -13,12 +13,25 @@ import ( | ||
13 | //成果池 | 13 | //成果池 |
14 | func AchievementPool(header *protocol.RequestHeader, request *protocol.AchievementPoolRequest) (rsp *protocol.AchievementPoolResponse, err error) { | 14 | func AchievementPool(header *protocol.RequestHeader, request *protocol.AchievementPoolRequest) (rsp *protocol.AchievementPoolResponse, err error) { |
15 | var ( | 15 | var ( |
16 | - ormItems []protocol.CommAchievementItemOrm | ||
17 | - total int | 16 | + ormItems []protocol.CommAchievementItemOrm |
17 | + total int | ||
18 | + departmentIds []int | ||
18 | ) | 19 | ) |
19 | rsp = &protocol.AchievementPoolResponse{} | 20 | rsp = &protocol.AchievementPoolResponse{} |
20 | rsp.List = make([]*protocol.AchievementCommonListItem, 0) | 21 | rsp.List = make([]*protocol.AchievementCommonListItem, 0) |
21 | - if total, err = models.GetAchievementAll(request.UserId, header.CompanyId, request.ChanceTypeId, request.LastId, request.DepartmentId, request.PageSize, &ormItems); err != nil { | 22 | + if request.DepartmentId > 0 { |
23 | + if d, e := models.GetDepartmentById(request.DepartmentId); e != nil { | ||
24 | + log.Error(err) | ||
25 | + err = e | ||
26 | + return | ||
27 | + } else { | ||
28 | + if departmentIds, err = models.GetSubDepartmentIds(header.CompanyId, d.Relation); err != nil { | ||
29 | + log.Error(err) | ||
30 | + return | ||
31 | + } | ||
32 | + } | ||
33 | + } | ||
34 | + if total, err = models.GetAchievementAll(request.UserId, header.CompanyId, request.ChanceTypeId, request.LastId, departmentIds, request.PageSize, &ormItems); err != nil { | ||
22 | if err == orm.ErrNoRows { | 35 | if err == orm.ErrNoRows { |
23 | err = nil | 36 | err = nil |
24 | return | 37 | return |
@@ -52,11 +65,12 @@ func GetAchievementItem(header *protocol.RequestHeader, from protocol.CommAchiev | @@ -52,11 +65,12 @@ func GetAchievementItem(header *protocol.RequestHeader, from protocol.CommAchiev | ||
52 | return | 65 | return |
53 | } else { | 66 | } else { |
54 | item = protocol.AchievementItem{ | 67 | item = protocol.AchievementItem{ |
55 | - Id: from.AchievementId, | ||
56 | - Provider: provider, | ||
57 | - CreateTime: from.CreateTime.Unix() * 1000, | ||
58 | - Content: from.SourceContent, | ||
59 | - GraspScore: from.GraspScore, | 68 | + Id: from.AchievementId, |
69 | + Provider: provider, | ||
70 | + CreateTime: from.CreateTime.Unix() * 1000, | ||
71 | + Content: from.SourceContent, | ||
72 | + GraspScore: from.GraspScore, | ||
73 | + GraspScorePercent: from.GraspScore, | ||
60 | } | 74 | } |
61 | jsonUnmarshal(from.Images, &item.Pictures) | 75 | jsonUnmarshal(from.Images, &item.Pictures) |
62 | } | 76 | } |
@@ -124,9 +138,10 @@ func AchievementDetail(header *protocol.RequestHeader, request *protocol.Achieve | @@ -124,9 +138,10 @@ func AchievementDetail(header *protocol.RequestHeader, request *protocol.Achieve | ||
124 | } | 138 | } |
125 | newParticipant := func(user *protocol.BaseUserInfo, score float64, t int) protocol.UserGraspInfo { | 139 | newParticipant := func(user *protocol.BaseUserInfo, score float64, t int) protocol.UserGraspInfo { |
126 | return protocol.UserGraspInfo{ | 140 | return protocol.UserGraspInfo{ |
127 | - Provider: user, | ||
128 | - GraspScore: score, | ||
129 | - Type: t, | 141 | + Provider: user, |
142 | + GraspScore: score, | ||
143 | + GraspScorePercent: score, | ||
144 | + Type: t, | ||
130 | } | 145 | } |
131 | } | 146 | } |
132 | addParticipants := func(item protocol.UserGraspInfo) { | 147 | addParticipants := func(item protocol.UserGraspInfo) { |
@@ -1281,7 +1281,7 @@ func ChanceStatistics(header *protocol.RequestHeader, request *protocol.ChanceSt | @@ -1281,7 +1281,7 @@ func ChanceStatistics(header *protocol.RequestHeader, request *protocol.ChanceSt | ||
1281 | rsp = &protocol.ChanceStatisticsResponse{} | 1281 | rsp = &protocol.ChanceStatisticsResponse{} |
1282 | for i := range chanceType { | 1282 | for i := range chanceType { |
1283 | item := chanceType[i] | 1283 | item := chanceType[i] |
1284 | - if total, err = agg.GetChancePool(header.UserId, header.CompanyId, item.Id, 0, 0, nil); err != nil { | 1284 | + if total, err = agg.GetChancePool(header.UserId, header.CompanyId, item.Id, 0, 0, 0, nil); err != nil { |
1285 | log.Error(err) | 1285 | log.Error(err) |
1286 | return | 1286 | return |
1287 | } | 1287 | } |
@@ -1369,7 +1369,7 @@ func ChancePool(header *protocol.RequestHeader, request *protocol.ChancePoolRequ | @@ -1369,7 +1369,7 @@ func ChancePool(header *protocol.RequestHeader, request *protocol.ChancePoolRequ | ||
1369 | provider *protocol.BaseUserInfo | 1369 | provider *protocol.BaseUserInfo |
1370 | flag int | 1370 | flag int |
1371 | ) | 1371 | ) |
1372 | - if total, err = agg.GetChancePool(header.UserId, header.CompanyId, request.ChanceTypeId, request.LastId, request.PageSize, &myChances); err != nil { | 1372 | + if total, err = agg.GetChancePool(header.UserId, header.CompanyId, request.ChanceTypeId, request.DepartmentId, request.LastId, request.PageSize, &myChances); err != nil { |
1373 | if err == orm.ErrNoRows { | 1373 | if err == orm.ErrNoRows { |
1374 | err = nil | 1374 | err = nil |
1375 | return | 1375 | return |
@@ -2,9 +2,11 @@ package department | @@ -2,9 +2,11 @@ package department | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "encoding/json" | 4 | "encoding/json" |
5 | + "github.com/astaxie/beego/orm" | ||
5 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" | 6 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" |
6 | "opp/models" | 7 | "opp/models" |
7 | "opp/protocol" | 8 | "opp/protocol" |
9 | + "opp/services/agg" | ||
8 | ) | 10 | ) |
9 | 11 | ||
10 | func Departments(header *protocol.RequestHeader, request *protocol.DepartmentsRequest) (rsp *protocol.DepartmentsResponse, err error) { | 12 | func Departments(header *protocol.RequestHeader, request *protocol.DepartmentsRequest) (rsp *protocol.DepartmentsResponse, err error) { |
@@ -56,3 +58,49 @@ func walkDepartment(to *protocol.Department, dfrom *models.Department) (err erro | @@ -56,3 +58,49 @@ func walkDepartment(to *protocol.Department, dfrom *models.Department) (err erro | ||
56 | } | 58 | } |
57 | return nil | 59 | return nil |
58 | } | 60 | } |
61 | + | ||
62 | +//部门统计 | ||
63 | +func DepartmentStatistics(header *protocol.RequestHeader, request *protocol.DepartmentStatisticsRequest) (rsp *protocol.DepartmentStatisticsResponse, err error) { | ||
64 | + var ( | ||
65 | + departmentsResponse *protocol.DepartmentsResponse | ||
66 | + ) | ||
67 | + rsp = &protocol.DepartmentStatisticsResponse{} | ||
68 | + if departmentsResponse, err = Departments(header, &protocol.DepartmentsRequest{Type: 1}); err != nil && err != orm.ErrNoRows { | ||
69 | + log.Error(err) | ||
70 | + return | ||
71 | + } | ||
72 | + departments := departmentsResponse.GetRootDepartment() | ||
73 | + iterateDepartments := func(call func(d *protocol.Department) *protocol.DepartmentStatistics) { | ||
74 | + for i := range departments { | ||
75 | + department := departments[i] | ||
76 | + item := call(department) | ||
77 | + item.Dep = protocol.Dep{ | ||
78 | + Id: department.DepartmentId, | ||
79 | + Name: department.Name, | ||
80 | + } | ||
81 | + rsp.List = append(rsp.List, item) | ||
82 | + } | ||
83 | + } | ||
84 | + switch request.Type { | ||
85 | + case protocol.StatisticApproved: | ||
86 | + iterateDepartments(func(d *protocol.Department) *protocol.DepartmentStatistics { | ||
87 | + rsp := &protocol.DepartmentStatistics{} | ||
88 | + dIds := departmentsResponse.GetChildDepartmentIds(d, true) | ||
89 | + rsp.AchievementTotal, _ = agg.AchievementDepartmentStatic(header, 0, dIds) | ||
90 | + rsp.ChanceApprovedTotal, _ = agg.GetChancePool(header.UserId, header.CompanyId, 0, d.DepartmentId, 0, 0, nil) | ||
91 | + return rsp | ||
92 | + }) | ||
93 | + break | ||
94 | + case protocol.StatisticApproving: | ||
95 | + iterateDepartments(func(d *protocol.Department) *protocol.DepartmentStatistics { | ||
96 | + rsp := &protocol.DepartmentStatistics{} | ||
97 | + rsp.ChanceApprovingTotal, _ = agg.ChanceApprovingStatistic(header, departmentsResponse.GetChildDepartmentIds(d, true)) | ||
98 | + return rsp | ||
99 | + }) | ||
100 | + break | ||
101 | + default: | ||
102 | + err = protocol.NewErrWithMessage(2) | ||
103 | + return | ||
104 | + } | ||
105 | + return | ||
106 | +} |
services/rank/rank.go
0 → 100644
1 | +package rank | ||
2 | + | ||
3 | +import "opp/protocol" | ||
4 | + | ||
5 | +//排行榜 | ||
6 | +func GetRankList(header *protocol.RequestHeader, request *protocol.GetRankListRequest) (rsp *protocol.GetRankListResponse, err error) { | ||
7 | + var () | ||
8 | + rsp = &protocol.GetRankListResponse{} | ||
9 | + return | ||
10 | +} | ||
11 | + | ||
12 | +//获取榜单类型列表 | ||
13 | +func GetRankType(header *protocol.RequestHeader, request *protocol.GetRankTypeRequest) (rsp *protocol.GetRankTypeResponse, err error) { | ||
14 | + var () | ||
15 | + rsp = &protocol.GetRankTypeResponse{} | ||
16 | + return | ||
17 | +} | ||
18 | + | ||
19 | +//获取榜单范围列表 | ||
20 | +func GetRankRange(header *protocol.RequestHeader, request *protocol.GetRankRangeRequest) (rsp *protocol.GetRankRangeResponse, err error) { | ||
21 | + var () | ||
22 | + rsp = &protocol.GetRankRangeResponse{} | ||
23 | + return | ||
24 | +} | ||
25 | + | ||
26 | +//获取排行榜周期列表 | ||
27 | +func GetRankPeriods(header *protocol.RequestHeader, request *protocol.GetRankPeriodsRequest) (rsp *protocol.GetRankPeriodsResponse, err error) { | ||
28 | + var () | ||
29 | + rsp = &protocol.GetRankPeriodsResponse{} | ||
30 | + return | ||
31 | +} |
@@ -434,7 +434,12 @@ func UserStatistics(header *protocol.RequestHeader, request *protocol.UserStatis | @@ -434,7 +434,12 @@ func UserStatistics(header *protocol.RequestHeader, request *protocol.UserStatis | ||
434 | log.Error(err) | 434 | log.Error(err) |
435 | } | 435 | } |
436 | break | 436 | break |
437 | - case protocol.MyGraspAchievement: | 437 | + case protocol.MyAchievements: //我提交的 |
438 | + if total, err = agg.MyGraspStatic(header); err != nil { | ||
439 | + log.Error(err) | ||
440 | + } | ||
441 | + break | ||
442 | + case protocol.MyGraspAchievement: //我把握的成果 | ||
438 | if total, err = agg.MyGraspStatic(header); err != nil { | 443 | if total, err = agg.MyGraspStatic(header); err != nil { |
439 | log.Error(err) | 444 | log.Error(err) |
440 | } | 445 | } |
-
请 注册 或 登录 后发表评论