作者 yangfu

排行榜列表修改

@@ -3,12 +3,10 @@ package contrab @@ -3,12 +3,10 @@ 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 46 8 * * *" //每0:5分 计算排行榜分数 6 + taskComputeRankScore = "0 10 0 * * *" //每0:5分 计算排行榜分数
7 ) 7 )
8 8
9 func Run() { 9 func Run() {
10 - //ComputeRankScore()  
11 -  
12 taskRank := toolbox.NewTask("taskComputeRankScore", taskComputeRankScore, ComputeRankScore) 10 taskRank := toolbox.NewTask("taskComputeRankScore", taskComputeRankScore, ComputeRankScore)
13 toolbox.AddTask("taskComputeRankScore", taskRank) 11 toolbox.AddTask("taskComputeRankScore", taskRank)
14 12
1 package contrab 1 package contrab
2 2
3 import ( 3 import (
  4 + "bytes"
4 "encoding/json" 5 "encoding/json"
5 "fmt" 6 "fmt"
6 "github.com/astaxie/beego/orm" 7 "github.com/astaxie/beego/orm"
@@ -62,7 +63,7 @@ func ComputeRankScore() (err error) { @@ -62,7 +63,7 @@ func ComputeRankScore() (err error) {
62 log.Warn("ComputeRankScore is working", ComputeRankScoreFlag) 63 log.Warn("ComputeRankScore is working", ComputeRankScoreFlag)
63 return fmt.Errorf("ComputeRankScore is working. try later") 64 return fmt.Errorf("ComputeRankScore is working. try later")
64 } else { 65 } else {
65 - defer utils.Profiling("结束作业:排行榜分数计算 执行耗时")() 66 + defer utils.Profiling("【排行榜分数统计】 执行耗时")()
66 } 67 }
67 defer func() { 68 defer func() {
68 atomic.CompareAndSwapInt32(&ComputeRankScoreFlag, 1, 0) 69 atomic.CompareAndSwapInt32(&ComputeRankScoreFlag, 1, 0)
@@ -169,7 +170,11 @@ func computeRankScore(index int, wg sync.WaitGroup, gNum int, periods []*models. @@ -169,7 +170,11 @@ func computeRankScore(index int, wg sync.WaitGroup, gNum int, periods []*models.
169 } 170 }
170 171
171 func logProcessInfo(period *models.RankPeriod) { 172 func logProcessInfo(period *models.RankPeriod) {
172 - log.Debug(fmt.Sprintf("【排行榜统计】 周期编号:%v 赛季名称:%v (榜单类型:%v) ", period.Id, period.SeasonName, period.RankTypeId)) 173 + log.Debug(fmt.Sprintf("【排行榜统计】 公司:%v 周期编号:%v 赛季名称:%v (榜单类型:%v) ", period.CompanyId, period.Id, period.SeasonName, period.RankTypeId))
  174 +}
  175 +
  176 +func logScoreChanceLog(itemName string, old float64, new float64) string {
  177 + return fmt.Sprintf(" [%v %v->%v]", itemName, old, new)
173 } 178 }
174 179
175 //更新排行榜按关联id 180 //更新排行榜按关联id
@@ -214,6 +219,9 @@ func updateRank(o RankOption) { @@ -214,6 +219,9 @@ func updateRank(o RankOption) {
214 Type: int8(o.Type), 219 Type: int8(o.Type),
215 } 220 }
216 } else { 221 } else {
  222 + if rank.EnableStatus == protocol.InValid {
  223 + rank.EnableStatus = protocol.Valid
  224 + }
217 rankTmp = *rank 225 rankTmp = *rank
218 } 226 }
219 o.Rank = rank 227 o.Rank = rank
@@ -237,12 +245,33 @@ func updateRank(o RankOption) { @@ -237,12 +245,33 @@ func updateRank(o RankOption) {
237 if e = models.UpdateRankById(rank); e != nil { 245 if e = models.UpdateRankById(rank); e != nil {
238 log.Error(e) 246 log.Error(e)
239 } 247 }
240 - log.Debug(fmt.Sprintf("【排行榜统计】 更新 周期编号:%v 公司:%v 评分者编号:%v (榜单类型:%v 参与类型:%v)", rank.RankPeriodId, rank.CompanyId, rank.RelationId, rank.RankTypeId, rank.RankRangeId)) 248 + log.Debug(fmt.Sprintf("【排行榜统计】 更新 周期编号:%v 公司:%v 评分者编号:%v (榜单类型:%v 参与类型:%v) %v", rank.RankPeriodId, rank.CompanyId, rank.RelationId, rank.RankTypeId, rank.RankRangeId,
  249 + checkScoreChange(rankTmp, *rank)))
241 } 250 }
242 } 251 }
243 252
244 } 253 }
245 254
  255 +func checkScoreChange(old, new models.Rank) string {
  256 + changeLog := bytes.NewBuffer(nil)
  257 + if old.TotalScore != new.TotalScore {
  258 + changeLog.WriteString(logScoreChanceLog("总分", old.TotalScore, new.TotalScore))
  259 + }
  260 + if old.DiscoveryScore != new.DiscoveryScore {
  261 + changeLog.WriteString(logScoreChanceLog("发现分", old.DiscoveryScore, new.DiscoveryScore))
  262 + }
  263 + if old.GraspScore != new.GraspScore {
  264 + changeLog.WriteString(logScoreChanceLog("把握分", old.GraspScore, new.GraspScore))
  265 + }
  266 + if old.DiscoveryTotal != new.DiscoveryTotal {
  267 + changeLog.WriteString(logScoreChanceLog("发现总数", float64(old.DiscoveryTotal), float64(new.DiscoveryTotal)))
  268 + }
  269 + if old.CommentTotal != new.CommentTotal {
  270 + changeLog.WriteString(logScoreChanceLog("评论总数", float64(old.CommentTotal), float64(new.CommentTotal)))
  271 + }
  272 + return changeLog.String()
  273 +}
  274 +
246 //更新排行榜总分 //更新总分 系数*发现分 + 系数*把握分 275 //更新排行榜总分 //更新总分 系数*发现分 + 系数*把握分
247 func updateTotalScore(o RankOption) { 276 func updateTotalScore(o RankOption) {
248 var ( 277 var (
@@ -91,6 +91,24 @@ func GetRankList(header *protocol.RequestHeader, request *protocol.GetRankListRe @@ -91,6 +91,24 @@ func GetRankList(header *protocol.RequestHeader, request *protocol.GetRankListRe
91 rsp.Lists = append(rsp.Lists, ranks) 91 rsp.Lists = append(rsp.Lists, ranks)
92 } 92 }
93 } 93 }
  94 +
  95 + if len(itemKeys) != len(rsp.Lists) {
  96 + log.Error("数据项不匹配", itemKeys, len(rsp.Lists))
  97 + err = protocol.NewErrWithMessage(1)
  98 + return
  99 + }
  100 +
  101 + if len(rsp.Lists) > 0 {
  102 + lists := make([][]protocol.RankItem, 0)
  103 + for i := 0; i < rsp.Total; i++ {
  104 + items := make([]protocol.RankItem, 0)
  105 + for j := 0; j < len(itemKeys); j++ {
  106 + items = append(items, rsp.Lists[j][i])
  107 + }
  108 + lists = append(lists, items)
  109 + }
  110 + rsp.Lists = lists
  111 + }
94 return 112 return
95 } 113 }
96 114