作者 yangfu

互动消息 机会补充

@@ -10,6 +10,7 @@ import ( @@ -10,6 +10,7 @@ import (
10 "reflect" 10 "reflect"
11 "strconv" 11 "strconv"
12 "strings" 12 "strings"
  13 + "time"
13 ) 14 )
14 15
15 // 此函数将指定的结构体成员值更新到结构体中 16 // 此函数将指定的结构体成员值更新到结构体中
@@ -121,3 +122,13 @@ func ValidVersion(current, compare string) bool { @@ -121,3 +122,13 @@ func ValidVersion(current, compare string) bool {
121 } 122 }
122 return false 123 return false
123 } 124 }
  125 +
  126 +// 统计某函数执行时间
  127 +// 使用方式
  128 +// defer utils.Profiling("test")()
  129 +func Profiling(msg string) func() {
  130 + start := time.Now()
  131 + return func() {
  132 + log.Info(fmt.Sprintf("%s[%s]:%s", msg, "use", time.Since(start)))
  133 + }
  134 +}
@@ -91,6 +91,8 @@ func main() { @@ -91,6 +91,8 @@ func main() {
91 //beego.BConfig.Listen.HTTPSPort = 8089 91 //beego.BConfig.Listen.HTTPSPort = 8089
92 //beego.BConfig.Listen.HTTPSCertFile = "conf/server.crt" 92 //beego.BConfig.Listen.HTTPSCertFile = "conf/server.crt"
93 //beego.BConfig.Listen.HTTPSKeyFile = "conf/server.key" 93 //beego.BConfig.Listen.HTTPSKeyFile = "conf/server.key"
  94 + //contrab.Run()
  95 +
94 beego.Run() 96 beego.Run()
95 } 97 }
96 98
@@ -251,8 +251,8 @@ select a.*,b.source_content,b.enable_status,b.user_id chance_user_id,b.create_at @@ -251,8 +251,8 @@ select a.*,b.source_content,b.enable_status,b.user_id chance_user_id,b.create_at
251 select id msg_id,message content,source_type,source_id,is_read,create_at msg_time,chance_id,receive_user_id,sender_user_id from user_msg 251 select id msg_id,message content,source_type,source_id,is_read,create_at msg_time,chance_id,receive_user_id,sender_user_id from user_msg
252 where receive_user_id =? and (?=0 or id<?) and msg_type=? 252 where receive_user_id =? and (?=0 or id<?) and msg_type=?
253 )a left outer join chance b on a.chance_id = b.id 253 )a left outer join chance b on a.chance_id = b.id
254 -)a left outer join chance_data b on a.source_id = b.chance_id  
255 -order by id 254 +)a left outer join chance_data b on a.chance_id = b.chance_id
  255 +order by id desc
256 LIMIT ?` 256 LIMIT ?`
257 257
258 sqlCount := `select count(0) 258 sqlCount := `select count(0)
  1 +package contrab
  2 +
  3 +import "github.com/astaxie/beego/toolbox"
  4 +
  5 +var (
  6 + taskComputeRankScore = "0 5 0 * * *" //每0:5分 计算排行榜分数
  7 +)
  8 +
  9 +func Run() {
  10 + taskRank := toolbox.NewTask("taskComputeRankScore", taskComputeRankScore, ComputeRankScore)
  11 + toolbox.AddTask("taskComputeRankScore", taskRank)
  12 +
  13 + toolbox.StartTask()
  14 +}
  1 +package contrab
  2 +
  3 +import (
  4 + "fmt"
  5 + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
  6 + "opp/internal/utils"
  7 + "sync/atomic"
  8 + "time"
  9 +)
  10 +
  11 +var ComputeRankScoreFlag int32
  12 +
  13 +type Rank interface {
  14 + RankUser(o RankOption) error
  15 + RankDepartment(o RankOption) error
  16 +}
  17 +
  18 +type RankOption struct {
  19 + BeginTime time.Time
  20 + EndTime time.Time
  21 +}
  22 +
  23 +//计算排行分
  24 +func ComputeRankScore() error {
  25 + defer func() {
  26 + if p := recover(); p != nil {
  27 + log.Error(p)
  28 + }
  29 + }()
  30 + if !atomic.CompareAndSwapInt32(&ComputeRankScoreFlag, 0, 1) {
  31 + return fmt.Errorf("ComputeRankScore is working. try later")
  32 + } else {
  33 + defer utils.Profiling("ComputeRankScore 执行耗时")()
  34 + }
  35 + defer func() {
  36 + atomic.CompareAndSwapInt32(&ComputeRankScoreFlag, 1, 0)
  37 + }()
  38 +
  39 + return computeRankScore()
  40 +}
  41 +
  42 +func computeRankScore() error {
  43 + return nil
  44 +}