1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- package main
- import (
- . "activeStartTip/config"
- . "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()
- defer Mgo.DestoryMongoConn(sess)
- query := map[string]interface{}{}
- if len(Config.TestIds) > 0 {
- query["_id"] = map[string]interface{}{
- "$in": ToObjectIds(Config.TestIds),
- }
- } else {
- query["i_appid"] = 2
- }
- log.Println("start...", query)
- it := sess.DB("qfw").C("user").Find(query).Select(map[string]interface{}{
- "_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)
- go func(u map[string]interface{}) {
- defer func() {
- <-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,
- Title: "做任务赚好礼",
- Content: "7天内完成限时任务,额外赠送超级订阅7天体验。获取更多采购项目信息,快速对接项目联系人!",
- MsgType: 1,
- Link: "/page_workDesktop/work-bench/app/points/earn,/jy_mobile/points/earn,/jy_mobile/points/earn,/jy_mobile/points/earn",
- Appid: "10000",
- AppPushUrl: "/jy_mobile/points/earn",
- IosPushUrl: "/jy_mobile/points/earn",
- })
- }(m)
- }
- 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_Log.GetMgoConn()
- defer Mgo_Log.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
- }
|