|
@@ -50,6 +50,9 @@ type RankResult struct{} |
|
@@ -50,6 +50,9 @@ type RankResult struct{} |
50
|
|
50
|
|
51
|
//计算排行分
|
51
|
//计算排行分
|
52
|
func ComputeRankScore() (err error) {
|
52
|
func ComputeRankScore() (err error) {
|
|
|
53
|
+ var (
|
|
|
54
|
+ periods []*models.RankPeriod
|
|
|
55
|
+ )
|
53
|
defer func() {
|
56
|
defer func() {
|
54
|
if p := recover(); p != nil {
|
57
|
if p := recover(); p != nil {
|
55
|
log.Error(p)
|
58
|
log.Error(p)
|
|
@@ -64,12 +67,16 @@ func ComputeRankScore() (err error) { |
|
@@ -64,12 +67,16 @@ func ComputeRankScore() (err error) { |
64
|
defer func() {
|
67
|
defer func() {
|
65
|
atomic.CompareAndSwapInt32(&ComputeRankScoreFlag, 1, 0)
|
68
|
atomic.CompareAndSwapInt32(&ComputeRankScoreFlag, 1, 0)
|
66
|
}()
|
69
|
}()
|
|
|
70
|
+ //1.l 查询进行中的赛季
|
|
|
71
|
+ if periods, err = models.GetRankPeriods(0, 0, []int{protocol.RankPeriodBegin}); err != nil {
|
|
|
72
|
+ return
|
|
|
73
|
+ }
|
67
|
//启用多个协程执行
|
74
|
//启用多个协程执行
|
68
|
var wg sync.WaitGroup
|
75
|
var wg sync.WaitGroup
|
69
|
for i := 0; i < RankGoroutineNum; i++ {
|
76
|
for i := 0; i < RankGoroutineNum; i++ {
|
70
|
index := i
|
77
|
index := i
|
71
|
work := func() {
|
78
|
work := func() {
|
72
|
- if err = computeRankScore(index, wg); err != nil {
|
79
|
+ if err = computeRankScore(index, wg, RankGoroutineNum, periods); err != nil {
|
73
|
log.Error(err)
|
80
|
log.Error(err)
|
74
|
}
|
81
|
}
|
75
|
}
|
82
|
}
|
|
@@ -92,15 +99,14 @@ func updateRankPeriodStatus(fromStatus int, toStatus int) { |
|
@@ -92,15 +99,14 @@ func updateRankPeriodStatus(fromStatus int, toStatus int) { |
92
|
sql = `update rank_period set status=?,update_at=NOW() where status=? and UNIX_TIMESTAMP(begin_time)>? `
|
99
|
sql = `update rank_period set status=?,update_at=NOW() where status=? and UNIX_TIMESTAMP(begin_time)>? `
|
93
|
}
|
100
|
}
|
94
|
orm := orm.NewOrm()
|
101
|
orm := orm.NewOrm()
|
95
|
- if err := utils.ExecuteSQLWithOrmer(orm, sql, toStatus, fromStatus, time.Now().Unix()); err != nil {
|
102
|
+ if _, err := orm.Raw(sql, toStatus, fromStatus, time.Now().Unix()).Exec(); err != nil {
|
96
|
log.Error(err)
|
103
|
log.Error(err)
|
97
|
return
|
104
|
return
|
98
|
}
|
105
|
}
|
99
|
}
|
106
|
}
|
100
|
|
107
|
|
101
|
-func computeRankScore(index int, wg sync.WaitGroup) (err error) {
|
108
|
+func computeRankScore(index int, wg sync.WaitGroup, gNum int, periods []*models.RankPeriod) (err error) {
|
102
|
var (
|
109
|
var (
|
103
|
- periods []*models.RankPeriod
|
|
|
104
|
rankRanges []*models.RankRange
|
110
|
rankRanges []*models.RankRange
|
105
|
rankRangeDatas []*models.RankRangeData
|
111
|
rankRangeDatas []*models.RankRangeData
|
106
|
)
|
112
|
)
|
|
@@ -112,14 +118,10 @@ func computeRankScore(index int, wg sync.WaitGroup) (err error) { |
|
@@ -112,14 +118,10 @@ func computeRankScore(index int, wg sync.WaitGroup) (err error) { |
112
|
log.Error(p)
|
118
|
log.Error(p)
|
113
|
}
|
119
|
}
|
114
|
}()
|
120
|
}()
|
115
|
- //1.l 查询进行中的赛季
|
|
|
116
|
- if periods, err = models.GetRankPeriods(0, 0, []int{protocol.RankPeriodBegin}); err != nil {
|
|
|
117
|
- return
|
|
|
118
|
- }
|
|
|
119
|
//2.查询对应 rank_type_id 的rank_data
|
121
|
//2.查询对应 rank_type_id 的rank_data
|
120
|
for i := range periods {
|
122
|
for i := range periods {
|
121
|
period := periods[i]
|
123
|
period := periods[i]
|
122
|
- if (period.Id % RankGoroutineNum) != index {
|
124
|
+ if (period.Id % gNum) != index {
|
123
|
return
|
125
|
return
|
124
|
}
|
126
|
}
|
125
|
if rankRanges, err = models.GetRankRanges(period.CompanyId, period.RankTypeId); err == orm.ErrNoRows {
|
127
|
if rankRanges, err = models.GetRankRanges(period.CompanyId, period.RankTypeId); err == orm.ErrNoRows {
|
|
@@ -139,6 +141,7 @@ func computeRankScore(index int, wg sync.WaitGroup) (err error) { |
|
@@ -139,6 +141,7 @@ func computeRankScore(index int, wg sync.WaitGroup) (err error) { |
139
|
}
|
141
|
}
|
140
|
//按类型
|
142
|
//按类型
|
141
|
//3.查询用户列表/部门列表
|
143
|
//3.查询用户列表/部门列表
|
|
|
144
|
+ logProcessInfo(period)
|
142
|
for j := range rankRanges {
|
145
|
for j := range rankRanges {
|
143
|
var relationIds []int64
|
146
|
var relationIds []int64
|
144
|
rankRange := rankRanges[j]
|
147
|
rankRange := rankRanges[j]
|
|
@@ -156,7 +159,6 @@ func computeRankScore(index int, wg sync.WaitGroup) (err error) { |
|
@@ -156,7 +159,6 @@ func computeRankScore(index int, wg sync.WaitGroup) (err error) { |
156
|
}
|
159
|
}
|
157
|
updateRankByRelationIds(relationIds, period, rankRange)
|
160
|
updateRankByRelationIds(relationIds, period, rankRange)
|
158
|
}
|
161
|
}
|
159
|
- logProcessInfo(period)
|
|
|
160
|
}
|
162
|
}
|
161
|
|
163
|
|
162
|
//4.调用统计接口列表
|
164
|
//4.调用统计接口列表
|
|
@@ -227,6 +229,7 @@ func updateRank(o RankOption) { |
|
@@ -227,6 +229,7 @@ func updateRank(o RankOption) { |
227
|
if _, e = models.AddRank(rank); e != nil {
|
229
|
if _, e = models.AddRank(rank); e != nil {
|
228
|
log.Error(e)
|
230
|
log.Error(e)
|
229
|
}
|
231
|
}
|
|
|
232
|
+ log.Debug(fmt.Sprintf("【排行榜统计】 新增加 周期编号:%v 公司:%v 评分者编号:%v (榜单类型:%v 参与类型:%v) ", rank.RankPeriodId, rank.CompanyId, rank.RelationId, rank.RankTypeId, rank.RankRangeId))
|
230
|
} else {
|
233
|
} else {
|
231
|
//数据有变化的时候才更新到表
|
234
|
//数据有变化的时候才更新到表
|
232
|
if !reflect.DeepEqual(rankTmp, *rank) {
|
235
|
if !reflect.DeepEqual(rankTmp, *rank) {
|
|
@@ -234,6 +237,7 @@ func updateRank(o RankOption) { |
|
@@ -234,6 +237,7 @@ func updateRank(o RankOption) { |
234
|
if e = models.UpdateRankById(rank); e != nil {
|
237
|
if e = models.UpdateRankById(rank); e != nil {
|
235
|
log.Error(e)
|
238
|
log.Error(e)
|
236
|
}
|
239
|
}
|
|
|
240
|
+ log.Debug(fmt.Sprintf("【排行榜统计】 更新 周期编号:%v 公司:%v 评分者编号:%v (榜单类型:%v 参与类型:%v)", rank.RankPeriodId, rank.CompanyId, rank.RelationId, rank.RankTypeId, rank.RankRangeId))
|
237
|
}
|
241
|
}
|
238
|
}
|
242
|
}
|
239
|
|
243
|
|
|
@@ -266,10 +270,27 @@ company_id=%v and rank_type_id=%v and rank_period_id=%v` |
|
@@ -266,10 +270,27 @@ company_id=%v and rank_type_id=%v and rank_period_id=%v` |
266
|
scoreConfig.SumScore.DiscoveryFactor,
|
270
|
scoreConfig.SumScore.DiscoveryFactor,
|
267
|
scoreConfig.SumScore.CatchFactor, o.CompanyId, o.RankTypeId, o.RankPeriodId)
|
271
|
scoreConfig.SumScore.CatchFactor, o.CompanyId, o.RankTypeId, o.RankPeriodId)
|
268
|
orm := orm.NewOrm()
|
272
|
orm := orm.NewOrm()
|
269
|
- if err := utils.ExecuteSQLWithOrmer(orm, sql); err != nil {
|
273
|
+ if _, err := orm.Raw(sql).Exec(); err != nil {
|
|
|
274
|
+ log.Error(err)
|
|
|
275
|
+ return
|
|
|
276
|
+ }
|
|
|
277
|
+}
|
|
|
278
|
+
|
|
|
279
|
+//手动单赛季统计
|
|
|
280
|
+func ComputeRankScoreByPeriod(periodId int) (err error) {
|
|
|
281
|
+ //启用多个协程执行
|
|
|
282
|
+ var (
|
|
|
283
|
+ wg sync.WaitGroup
|
|
|
284
|
+ period *models.RankPeriod
|
|
|
285
|
+ )
|
|
|
286
|
+ if period, err = models.GetRankPeriodById(periodId); err != nil {
|
270
|
log.Error(err)
|
287
|
log.Error(err)
|
|
|
288
|
+ err = protocol.NewCustomMessage(1, "赛季不存在")
|
271
|
return
|
289
|
return
|
272
|
}
|
290
|
}
|
|
|
291
|
+ computeRankScore(0, wg, 1, []*models.RankPeriod{period})
|
|
|
292
|
+ wg.Wait()
|
|
|
293
|
+ return
|
273
|
}
|
294
|
}
|
274
|
|
295
|
|
275
|
//发现计算规则
|
296
|
//发现计算规则
|