|
@@ -5,13 +5,17 @@ import (
|
|
|
. "activeStartTip/rpc"
|
|
|
"log"
|
|
|
"sync"
|
|
|
+ "sync/atomic"
|
|
|
"time"
|
|
|
|
|
|
"app.yhyue.com/moapp/MessageCenter/rpc/type/message"
|
|
|
+ "app.yhyue.com/moapp/jybase/common"
|
|
|
. "app.yhyue.com/moapp/jybase/mongodb"
|
|
|
+ "go.mongodb.org/mongo-driver/bson/primitive"
|
|
|
)
|
|
|
|
|
|
func main() {
|
|
|
+ allUser := loadAllUser()
|
|
|
pool := make(chan bool, Config.SendMsgPool)
|
|
|
wait := &sync.WaitGroup{}
|
|
|
sess := Mgo.GetMgoConn()
|
|
@@ -38,9 +42,10 @@ func main() {
|
|
|
}
|
|
|
log.Println("start...", query)
|
|
|
it := sess.DB("qfw").C("user").Find(query).Select(map[string]interface{}{
|
|
|
- "_id": 1,
|
|
|
- }).Iter()
|
|
|
- index := 0
|
|
|
+ "_id": 1,
|
|
|
+ "base_user_id": 1,
|
|
|
+ }).Sort("_id").Iter()
|
|
|
+ var index int64
|
|
|
for m := make(map[string]interface{}); it.Next(&m); {
|
|
|
pool <- true
|
|
|
wait.Add(1)
|
|
@@ -49,6 +54,14 @@ func main() {
|
|
|
<-pool
|
|
|
wait.Done()
|
|
|
}()
|
|
|
+ if !allUser[common.Int64All(u["base_user_id"])] {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ rs := atomic.AddInt64(&index, 1)
|
|
|
+ rs++
|
|
|
+ if rs%5000 == 0 {
|
|
|
+ log.Println("index", rs)
|
|
|
+ }
|
|
|
_id := BsonIdToSId(u["_id"])
|
|
|
SendMsg(&message.MultipleSaveMsgReq{
|
|
|
UserIds: _id,
|
|
@@ -61,11 +74,37 @@ func main() {
|
|
|
IosPushUrl: "/jy_mobile/points/earn",
|
|
|
})
|
|
|
}(m)
|
|
|
- index++
|
|
|
- if index%500 == 0 {
|
|
|
- log.Println("index", index)
|
|
|
- }
|
|
|
}
|
|
|
wait.Wait()
|
|
|
log.Println("over...", index)
|
|
|
}
|
|
|
+
|
|
|
+func loadAllUser() map[int64]bool {
|
|
|
+ _id := primitive.NewObjectIDFromTimestamp(time.Now().AddDate(-1, 0, 0))
|
|
|
+ log.Println("开始加载最近一年活跃用户。。。", _id)
|
|
|
+ allUser := map[int64]bool{}
|
|
|
+ sess := Mgo.GetMgoConn()
|
|
|
+ defer Mgo.DestoryMongoConn(sess)
|
|
|
+ it := sess.DB("qfw").C("jy_gateway_logs").Find(map[string]interface{}{
|
|
|
+ "_id": map[string]interface{}{
|
|
|
+ "$gt": _id,
|
|
|
+ },
|
|
|
+ }).Select(map[string]interface{}{
|
|
|
+ "_id": 0,
|
|
|
+ "userid_new": 1,
|
|
|
+ }).Iter()
|
|
|
+ var index int64
|
|
|
+ for m := make(map[string]interface{}); it.Next(&m); {
|
|
|
+ index++
|
|
|
+ if index%50000 == 0 {
|
|
|
+ log.Println("加载最近一年活跃用户", index)
|
|
|
+ }
|
|
|
+ userid_new := common.Int64All(m["userid_new"])
|
|
|
+ if userid_new <= 0 {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ allUser[userid_new] = true
|
|
|
+ }
|
|
|
+ log.Println("加载最近一年活跃用户结束。。。", _id, index)
|
|
|
+ return allUser
|
|
|
+}
|