正在显示
12 个修改的文件
包含
64 行增加
和
19 行删除
@@ -35,7 +35,7 @@ func (this *RankController) GetRankList() { | @@ -35,7 +35,7 @@ func (this *RankController) GetRankList() { | ||
35 | } | 35 | } |
36 | 36 | ||
37 | //GetRankType 获取榜单类型列表 (年榜/赛季榜) | 37 | //GetRankType 获取榜单类型列表 (年榜/赛季榜) |
38 | -// @router /getRankType [post] | 38 | +// @router /getRankTypes [post] |
39 | func (this *RankController) GetRankType() { | 39 | func (this *RankController) GetRankType() { |
40 | var msg *protocol.ResponseMessage | 40 | var msg *protocol.ResponseMessage |
41 | defer func() { | 41 | defer func() { |
@@ -56,7 +56,7 @@ func (this *RankController) GetRankType() { | @@ -56,7 +56,7 @@ func (this *RankController) GetRankType() { | ||
56 | } | 56 | } |
57 | 57 | ||
58 | //GetRankRange 获取榜单竞争范围列表 | 58 | //GetRankRange 获取榜单竞争范围列表 |
59 | -//@router /getRankRange [post] | 59 | +//@router /getRankRanges [post] |
60 | func (this *RankController) GetRankRange() { | 60 | func (this *RankController) GetRankRange() { |
61 | var msg *protocol.ResponseMessage | 61 | var msg *protocol.ResponseMessage |
62 | defer func() { | 62 | defer func() { |
@@ -13,7 +13,6 @@ import ( | @@ -13,7 +13,6 @@ import ( | ||
13 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/websocket" | 13 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/websocket" |
14 | "opp/internal/utils" | 14 | "opp/internal/utils" |
15 | _ "opp/routers" | 15 | _ "opp/routers" |
16 | - "opp/services/contrab" | ||
17 | "os" | 16 | "os" |
18 | "strings" | 17 | "strings" |
19 | "time" | 18 | "time" |
@@ -92,7 +91,7 @@ func main() { | @@ -92,7 +91,7 @@ func main() { | ||
92 | //beego.BConfig.Listen.HTTPSPort = 8089 | 91 | //beego.BConfig.Listen.HTTPSPort = 8089 |
93 | //beego.BConfig.Listen.HTTPSCertFile = "conf/server.crt" | 92 | //beego.BConfig.Listen.HTTPSCertFile = "conf/server.crt" |
94 | //beego.BConfig.Listen.HTTPSKeyFile = "conf/server.key" | 93 | //beego.BConfig.Listen.HTTPSKeyFile = "conf/server.key" |
95 | - contrab.Run() | 94 | + //contrab.Run() |
96 | 95 | ||
97 | beego.Run() | 96 | beego.Run() |
98 | } | 97 | } |
@@ -76,3 +76,33 @@ func GetRank(companyId, rankTypeId, rankRangeId, rankPeriodId int, relationId in | @@ -76,3 +76,33 @@ func GetRank(companyId, rankTypeId, rankRangeId, rankPeriodId int, relationId in | ||
76 | } | 76 | } |
77 | return nil, err | 77 | return nil, err |
78 | } | 78 | } |
79 | + | ||
80 | +//func GetRanksByUser(companyId, rankTypeId, rankRangeId, rankPeriodId int, relationId int64,v interface{})(total int, err error) { | ||
81 | +// //var filterDepartment string = getFilterSqlByDIds(dIds) | ||
82 | +// sql := fmt.Sprintf(`select a.*,b.nick_name name from ( | ||
83 | +//select ranking,score,relation_id,user_id from( | ||
84 | +//select a.discovery_score score,a.relation_id,(@rowno:=@rowno+1) as ranking,user_id from rank a inner join user_company c on a.relation_id=c.id,(select (@rowno:=0)) b | ||
85 | +//where a.company_id=%v and rank_type_id=%v and rank_range_id=%v and rank_period_id=%v | ||
86 | +//order by a.discovery_score desc,c.create_at asc | ||
87 | +//) a | ||
88 | +//#where relation_id=? | ||
89 | +//limit %v,%v | ||
90 | +//)a inner join user b on a.user_id = b.id | ||
91 | +//`, companyId,rankTypeId,rankRangeId,rankPeriodId,) | ||
92 | +// | ||
93 | +// //if public==protocol.pu | ||
94 | +// | ||
95 | +// sqlCount := fmt.Sprintf(`select count(0) from ( | ||
96 | +//select id from chance | ||
97 | +//where company_id=? and review_status=3 and (%v=0 or chance_type_id =%v) and enable_status=1 and status=1 %v | ||
98 | +//) a left JOIN chance_data b on a.id =b.chance_id`, chanceTypeId, chanceTypeId, filterDepartment) | ||
99 | +// if err = utils.ExecuteQueryOne(&total, sqlCount, cid); err != nil { | ||
100 | +// return | ||
101 | +// } | ||
102 | +// if v != nil { | ||
103 | +// if err = utils.ExecuteQueryAll(v, sql, cid, chanceTypeId, chanceTypeId, lastId, lastId, pageSize); err != nil { | ||
104 | +// return | ||
105 | +// } | ||
106 | +// } | ||
107 | +// return | ||
108 | +//} |
@@ -81,9 +81,15 @@ func DeleteRankPeriod(id int) (err error) { | @@ -81,9 +81,15 @@ func DeleteRankPeriod(id int) (err error) { | ||
81 | } | 81 | } |
82 | 82 | ||
83 | //获取进行中的赛季周期 状态 0:未开始 1:开始 2:结束 | 83 | //获取进行中的赛季周期 状态 0:未开始 1:开始 2:结束 |
84 | -func GetRankPeriods(status []int) (v []*RankPeriod, err error) { | 84 | +func GetRankPeriods(companyId int, rankTypeId int, status []int) (v []*RankPeriod, err error) { |
85 | sql := mybeego.NewSqlExutor() | 85 | sql := mybeego.NewSqlExutor() |
86 | sql.Table((&RankPeriod{}).TableName()) | 86 | sql.Table((&RankPeriod{}).TableName()) |
87 | + if companyId > 0 { | ||
88 | + sql.Where(fmt.Sprintf("company_id=%v", companyId)) | ||
89 | + } | ||
90 | + if rankTypeId > 0 { | ||
91 | + sql.Where(fmt.Sprintf("rank_type_id=%v", rankTypeId)) | ||
92 | + } | ||
87 | if len(status) > 0 { | 93 | if len(status) > 0 { |
88 | sql.Where(fmt.Sprintf("status in (%v)", utils.JoinInts(status, ","))) | 94 | sql.Where(fmt.Sprintf("status in (%v)", utils.JoinInts(status, ","))) |
89 | } | 95 | } |
@@ -79,12 +79,15 @@ func DeleteRankRange(id int) (err error) { | @@ -79,12 +79,15 @@ func DeleteRankRange(id int) (err error) { | ||
79 | } | 79 | } |
80 | 80 | ||
81 | //获取榜单范围数据 | 81 | //获取榜单范围数据 |
82 | -func GetRankRanges(companyId int) (v []*RankRange, err error) { | 82 | +func GetRankRanges(companyId int, rankTypeId int) (v []*RankRange, err error) { |
83 | sql := mybeego.NewSqlExutor() | 83 | sql := mybeego.NewSqlExutor() |
84 | sql.Table((&RankRange{}).TableName()) | 84 | sql.Table((&RankRange{}).TableName()) |
85 | if companyId > 0 { | 85 | if companyId > 0 { |
86 | sql.Where(fmt.Sprintf("company_id=%v", companyId)) | 86 | sql.Where(fmt.Sprintf("company_id=%v", companyId)) |
87 | } | 87 | } |
88 | + if rankTypeId > 0 { | ||
89 | + sql.Where(fmt.Sprintf("rank_type_id=%v", rankTypeId)) | ||
90 | + } | ||
88 | sql.Order("sort_num") | 91 | sql.Order("sort_num") |
89 | _, err = sql.Querys(&v) | 92 | _, err = sql.Querys(&v) |
90 | return | 93 | return |
@@ -45,6 +45,7 @@ type RankType struct { | @@ -45,6 +45,7 @@ type RankType struct { | ||
45 | 45 | ||
46 | /*GetRankRange */ | 46 | /*GetRankRange */ |
47 | type GetRankRangeRequest struct { | 47 | type GetRankRangeRequest struct { |
48 | + RankTypeId int `json:"rankTypeId" valid:"Required"` | ||
48 | } | 49 | } |
49 | type GetRankRangeResponse struct { | 50 | type GetRankRangeResponse struct { |
50 | List []NameItem `json:"rankRanges"` | 51 | List []NameItem `json:"rankRanges"` |
@@ -52,6 +53,7 @@ type GetRankRangeResponse struct { | @@ -52,6 +53,7 @@ type GetRankRangeResponse struct { | ||
52 | 53 | ||
53 | /*GetRankPeriods 获取榜单竞争范围列表*/ | 54 | /*GetRankPeriods 获取榜单竞争范围列表*/ |
54 | type GetRankPeriodsRequest struct { | 55 | type GetRankPeriodsRequest struct { |
56 | + RankTypeId int `json:"rankTypeId" valid:"Required"` | ||
55 | } | 57 | } |
56 | type GetRankPeriodsResponse struct { | 58 | type GetRankPeriodsResponse struct { |
57 | List []RankPeriod `json:"rankPeriods"` | 59 | List []RankPeriod `json:"rankPeriods"` |
@@ -474,7 +474,7 @@ func init() { | @@ -474,7 +474,7 @@ func init() { | ||
474 | beego.GlobalControllerRouter["opp/controllers/v1:RankController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:RankController"], | 474 | beego.GlobalControllerRouter["opp/controllers/v1:RankController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:RankController"], |
475 | beego.ControllerComments{ | 475 | beego.ControllerComments{ |
476 | Method: "GetRankRange", | 476 | Method: "GetRankRange", |
477 | - Router: `/getRankRange`, | 477 | + Router: `/getRankRanges`, |
478 | AllowHTTPMethods: []string{"post"}, | 478 | AllowHTTPMethods: []string{"post"}, |
479 | MethodParams: param.Make(), | 479 | MethodParams: param.Make(), |
480 | Params: nil}) | 480 | Params: nil}) |
@@ -482,7 +482,7 @@ func init() { | @@ -482,7 +482,7 @@ func init() { | ||
482 | beego.GlobalControllerRouter["opp/controllers/v1:RankController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:RankController"], | 482 | beego.GlobalControllerRouter["opp/controllers/v1:RankController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:RankController"], |
483 | beego.ControllerComments{ | 483 | beego.ControllerComments{ |
484 | Method: "GetRankType", | 484 | Method: "GetRankType", |
485 | - Router: `/getRankType`, | 485 | + Router: `/getRankTypes`, |
486 | AllowHTTPMethods: []string{"post"}, | 486 | AllowHTTPMethods: []string{"post"}, |
487 | MethodParams: param.Make(), | 487 | MethodParams: param.Make(), |
488 | Params: nil}) | 488 | Params: nil}) |
@@ -25,6 +25,7 @@ func init() { | @@ -25,6 +25,7 @@ func init() { | ||
25 | beego.NSNamespace("config", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.ConfigController{})), | 25 | beego.NSNamespace("config", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.ConfigController{})), |
26 | beego.NSNamespace("file", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.FileController{})), | 26 | beego.NSNamespace("file", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.FileController{})), |
27 | beego.NSNamespace("achievement", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.AchievementController{})), | 27 | beego.NSNamespace("achievement", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.AchievementController{})), |
28 | + beego.NSNamespace("rank", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.RankController{})), | ||
28 | ) | 29 | ) |
29 | beego.AddNamespace(nsV1) | 30 | beego.AddNamespace(nsV1) |
30 | 31 |
@@ -3,7 +3,7 @@ package contrab | @@ -3,7 +3,7 @@ package contrab | ||
3 | import "github.com/astaxie/beego/toolbox" | 3 | import "github.com/astaxie/beego/toolbox" |
4 | 4 | ||
5 | var ( | 5 | var ( |
6 | - taskComputeRankScore = "0 5 0 * * *" //每0:5分 计算排行榜分数 | 6 | + taskComputeRankScore = "0 46 8 * * *" //每0:5分 计算排行榜分数 |
7 | ) | 7 | ) |
8 | 8 | ||
9 | func Run() { | 9 | func Run() { |
@@ -51,6 +51,7 @@ func ComputeRankScore() error { | @@ -51,6 +51,7 @@ func ComputeRankScore() error { | ||
51 | } | 51 | } |
52 | }() | 52 | }() |
53 | if !atomic.CompareAndSwapInt32(&ComputeRankScoreFlag, 0, 1) { | 53 | if !atomic.CompareAndSwapInt32(&ComputeRankScoreFlag, 0, 1) { |
54 | + log.Warn("ComputeRankScore is working", ComputeRankScoreFlag) | ||
54 | return fmt.Errorf("ComputeRankScore is working. try later") | 55 | return fmt.Errorf("ComputeRankScore is working. try later") |
55 | } else { | 56 | } else { |
56 | defer utils.Profiling("ComputeRankScore 执行耗时")() | 57 | defer utils.Profiling("ComputeRankScore 执行耗时")() |
@@ -73,13 +74,13 @@ func computeRankScore() (err error) { | @@ -73,13 +74,13 @@ func computeRankScore() (err error) { | ||
73 | } | 74 | } |
74 | }() | 75 | }() |
75 | //1.l 查询进行中的赛季 | 76 | //1.l 查询进行中的赛季 |
76 | - if periods, err = models.GetRankPeriods([]int{protocol.RankPeriodBegin}); err != nil { | 77 | + if periods, err = models.GetRankPeriods(0, 0, []int{protocol.RankPeriodBegin}); err != nil { |
77 | return | 78 | return |
78 | } | 79 | } |
79 | //2.查询对应 rank_type_id 的rank_data | 80 | //2.查询对应 rank_type_id 的rank_data |
80 | for i := range periods { | 81 | for i := range periods { |
81 | period := periods[i] | 82 | period := periods[i] |
82 | - if rankRanges, err = models.GetRankRanges(period.CompanyId); err == orm.ErrNoRows { | 83 | + if rankRanges, err = models.GetRankRanges(period.CompanyId, period.RankTypeId); err == orm.ErrNoRows { |
83 | continue | 84 | continue |
84 | } | 85 | } |
85 | //所有部门 | 86 | //所有部门 |
@@ -229,7 +230,7 @@ type RankDiscovery struct{} | @@ -229,7 +230,7 @@ type RankDiscovery struct{} | ||
229 | 230 | ||
230 | func (rank RankDiscovery) RankUser(o RankOption) (err error, result RankResult) { | 231 | func (rank RankDiscovery) RankUser(o RankOption) (err error, result RankResult) { |
231 | var ( | 232 | var ( |
232 | - sql = `select sum(discovery_score) score,count(0) total from chance where user_id =? and review_status=3 | 233 | + sql = `select sum(discovery_score) score,count(0) total from chance where user_id =? and review_status=3 and status=1 |
233 | and UNIX_TIMESTAMP(approve_time)>=? and UNIX_TIMESTAMP(approve_time)<?` | 234 | and UNIX_TIMESTAMP(approve_time)>=? and UNIX_TIMESTAMP(approve_time)<?` |
234 | score float64 | 235 | score float64 |
235 | total int | 236 | total int |
@@ -245,7 +246,7 @@ func (rank RankDiscovery) RankUser(o RankOption) (err error, result RankResult) | @@ -245,7 +246,7 @@ func (rank RankDiscovery) RankUser(o RankOption) (err error, result RankResult) | ||
245 | } | 246 | } |
246 | func (rank RankDiscovery) RankDepartment(o RankOption) (err error, result RankResult) { | 247 | func (rank RankDiscovery) RankDepartment(o RankOption) (err error, result RankResult) { |
247 | var ( | 248 | var ( |
248 | - sql = `select sum(discovery_score) score,count(0) total from chance where department_id =? and review_status=3 | 249 | + sql = `select sum(discovery_score) score,count(0) total from chance where department_id =? and review_status=3 and status=1 |
249 | and UNIX_TIMESTAMP(approve_time)>=? and UNIX_TIMESTAMP(approve_time)<? | 250 | and UNIX_TIMESTAMP(approve_time)>=? and UNIX_TIMESTAMP(approve_time)<? |
250 | ` | 251 | ` |
251 | score float64 | 252 | score float64 |
@@ -43,9 +43,9 @@ func Departments(header *protocol.RequestHeader, request *protocol.DepartmentsRe | @@ -43,9 +43,9 @@ func Departments(header *protocol.RequestHeader, request *protocol.DepartmentsRe | ||
43 | } | 43 | } |
44 | rsp.Departments = tmpDepartment.Departments | 44 | rsp.Departments = tmpDepartment.Departments |
45 | rsp.Departments = rsp.GetRootDepartment() | 45 | rsp.Departments = rsp.GetRootDepartment() |
46 | - for i := range rsp.Departments { | ||
47 | - rsp.Departments[i].Departments = make([]*protocol.Department, 0) | ||
48 | - } | 46 | + //for i := range rsp.Departments { |
47 | + // rsp.Departments[i].Departments = make([]*protocol.Department, 0) | ||
48 | + //} | ||
49 | default: | 49 | default: |
50 | break | 50 | break |
51 | } | 51 | } |
@@ -9,7 +9,10 @@ import ( | @@ -9,7 +9,10 @@ import ( | ||
9 | 9 | ||
10 | //排行榜 | 10 | //排行榜 |
11 | func GetRankList(header *protocol.RequestHeader, request *protocol.GetRankListRequest) (rsp *protocol.GetRankListResponse, err error) { | 11 | func GetRankList(header *protocol.RequestHeader, request *protocol.GetRankListRequest) (rsp *protocol.GetRankListResponse, err error) { |
12 | - var () | 12 | + var ( |
13 | + ranks []*models.Rank | ||
14 | + ) | ||
15 | + | ||
13 | rsp = &protocol.GetRankListResponse{} | 16 | rsp = &protocol.GetRankListResponse{} |
14 | return | 17 | return |
15 | } | 18 | } |
@@ -39,7 +42,7 @@ func GetRankRange(header *protocol.RequestHeader, request *protocol.GetRankRange | @@ -39,7 +42,7 @@ func GetRankRange(header *protocol.RequestHeader, request *protocol.GetRankRange | ||
39 | var ( | 42 | var ( |
40 | lists []*models.RankRange | 43 | lists []*models.RankRange |
41 | ) | 44 | ) |
42 | - if lists, err = models.GetRankRanges(int(header.CompanyId)); err != nil { | 45 | + if lists, err = models.GetRankRanges(int(header.CompanyId), request.RankTypeId); err != nil { |
43 | if err == orm.ErrNoRows { | 46 | if err == orm.ErrNoRows { |
44 | err = nil | 47 | err = nil |
45 | return | 48 | return |
@@ -60,7 +63,7 @@ func GetRankPeriods(header *protocol.RequestHeader, request *protocol.GetRankPer | @@ -60,7 +63,7 @@ func GetRankPeriods(header *protocol.RequestHeader, request *protocol.GetRankPer | ||
60 | lists []*models.RankPeriod | 63 | lists []*models.RankPeriod |
61 | ) | 64 | ) |
62 | rsp = &protocol.GetRankPeriodsResponse{List: make([]protocol.RankPeriod, 0)} | 65 | rsp = &protocol.GetRankPeriodsResponse{List: make([]protocol.RankPeriod, 0)} |
63 | - if lists, err = models.GetRankPeriods([]int{protocol.RankPeriodBegin, protocol.RankPeriodEnd}); err != nil { | 66 | + if lists, err = models.GetRankPeriods(int(header.CompanyId), request.RankTypeId, []int{protocol.RankPeriodBegin, protocol.RankPeriodEnd}); err != nil { |
64 | if err == orm.ErrNoRows { | 67 | if err == orm.ErrNoRows { |
65 | err = nil | 68 | err = nil |
66 | return | 69 | return |
-
请 注册 或 登录 后发表评论