|
@@ -6,9 +6,11 @@ import (
|
|
. "pushentniche/push/config"
|
|
. "pushentniche/push/config"
|
|
. "pushentniche/push/db"
|
|
. "pushentniche/push/db"
|
|
putil "pushentniche/push/util"
|
|
putil "pushentniche/push/util"
|
|
|
|
+ "sort"
|
|
"strconv"
|
|
"strconv"
|
|
"strings"
|
|
"strings"
|
|
"sync"
|
|
"sync"
|
|
|
|
+ "sync/atomic"
|
|
"time"
|
|
"time"
|
|
|
|
|
|
util "app.yhyue.com/moapp/jybase/common"
|
|
util "app.yhyue.com/moapp/jybase/common"
|
|
@@ -46,17 +48,14 @@ func (n *NoMsgTipJob) Execute(taskType, hour int) {
|
|
InitEnt(Mysql, Mgo, DbConf.Mongodb.Main.DbName, Config.TestQuery)
|
|
InitEnt(Mysql, Mgo, DbConf.Mongodb.Main.DbName, Config.TestQuery)
|
|
pushPool := make(chan bool, Config.PushPoolSize)
|
|
pushPool := make(chan bool, Config.PushPoolSize)
|
|
pushWait := &sync.WaitGroup{}
|
|
pushWait := &sync.WaitGroup{}
|
|
|
|
+ lock := &sync.Mutex{}
|
|
|
|
+ allTipsA, allTipsB := []*UserInfo{}, []*UserInfo{}
|
|
for _, v := range EntUsers {
|
|
for _, v := range EntUsers {
|
|
- isTake := MonitorTimeOut(pushPool, time.Minute, Config.TimeoutWarn, func() {
|
|
|
|
- logger.Error("推送任务", taskType, "推送放入通道超时,", v.Id)
|
|
|
|
- })
|
|
|
|
pushWait.Add(1)
|
|
pushWait.Add(1)
|
|
- go func(entUser *EntUser, take bool) {
|
|
|
|
|
|
+ go func(entUser *EntUser) {
|
|
defer util.Catch()
|
|
defer util.Catch()
|
|
defer func() {
|
|
defer func() {
|
|
- if take {
|
|
|
|
- <-pushPool
|
|
|
|
- }
|
|
|
|
|
|
+ <-pushPool
|
|
pushWait.Done()
|
|
pushWait.Done()
|
|
}()
|
|
}()
|
|
user, userObj := NewMyUserInfoByEntUserId(Mgo, Mysql, fmt.Sprint(entUser.Id))
|
|
user, userObj := NewMyUserInfoByEntUserId(Mgo, Mysql, fmt.Sprint(entUser.Id))
|
|
@@ -86,24 +85,46 @@ func (n *NoMsgTipJob) Execute(taskType, hour int) {
|
|
if taskType == 1 || (taskType == 2 && user.PushSet.SubSet.RateMode == 2) || (taskType == 3 && user.PushSet.SubSet.RateMode == 3) ||
|
|
if taskType == 1 || (taskType == 2 && user.PushSet.SubSet.RateMode == 2) || (taskType == 3 && user.PushSet.SubSet.RateMode == 3) ||
|
|
(taskType == 4 && user.PushSet.SubSet.RateMode == 4) || (taskType == 5 && (user.PushSet.SubSet.RateMode == 3 || user.PushSet.SubSet.RateMode == 4)) ||
|
|
(taskType == 4 && user.PushSet.SubSet.RateMode == 4) || (taskType == 5 && (user.PushSet.SubSet.RateMode == 3 || user.PushSet.SubSet.RateMode == 4)) ||
|
|
(taskType == 6 && user.PushSet.SubSet.RateMode == 0) || (taskType == 7 && user.PushSet.SubSet.RateMode == 1) {
|
|
(taskType == 6 && user.PushSet.SubSet.RateMode == 0) || (taskType == 7 && user.PushSet.SubSet.RateMode == 1) {
|
|
- n.tip(taskType, hour, user)
|
|
|
|
|
|
+ if n.isTip(taskType, hour, user) {
|
|
|
|
+ lock.Lock()
|
|
|
|
+ if int64(user.Entniche.UserId) > Task.NoMsgTipLastId {
|
|
|
|
+ allTipsA = append(allTipsA, user)
|
|
|
|
+ } else {
|
|
|
|
+ allTipsB = append(allTipsB, user)
|
|
|
|
+ }
|
|
|
|
+ lock.Unlock()
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- }(v, isTake)
|
|
|
|
|
|
+ }(v)
|
|
}
|
|
}
|
|
pushWait.Wait()
|
|
pushWait.Wait()
|
|
|
|
+ sort.Slice(allTipsA, func(i, j int) bool {
|
|
|
|
+ return allTipsA[i].Entniche.UserId < allTipsA[j].Entniche.UserId
|
|
|
|
+ })
|
|
|
|
+ sort.Slice(allTipsB, func(i, j int) bool {
|
|
|
|
+ return allTipsB[i].Entniche.UserId < allTipsB[j].Entniche.UserId
|
|
|
|
+ })
|
|
|
|
+ var noMsgTipLastId int64
|
|
|
|
+ wxTplSurplus := WxNoMsgTmplUsableNum(Mgo_Log, Config.NoMsgTip.WxNodeNum, Config.NoMsgTip.DayNum, Config.NoMsgTip.Count, Config.NoMsgTip.Retain)
|
|
|
|
+ if Config.NoMsgTip.IsRecommendNewest {
|
|
|
|
+ VarRecommend.SetNewest(1)
|
|
|
|
+ }
|
|
|
|
+ n.beforeTip(taskType, allTipsA, wxTplSurplus, &noMsgTipLastId)
|
|
|
|
+ n.beforeTip(taskType, allTipsB, wxTplSurplus, &noMsgTipLastId)
|
|
|
|
+ Task.NoMsgTipLastId = noMsgTipLastId
|
|
logger.Info("无消息提醒任务结束。。。", taskType, hour)
|
|
logger.Info("无消息提醒任务结束。。。", taskType, hour)
|
|
}
|
|
}
|
|
|
|
|
|
//提醒
|
|
//提醒
|
|
-func (n *NoMsgTipJob) tip(taskType, hour int, user *UserInfo) {
|
|
|
|
|
|
+func (n *NoMsgTipJob) isTip(taskType, hour int, user *UserInfo) bool {
|
|
now := time.Now()
|
|
now := time.Now()
|
|
if user.VipStatus != 1 && user.MemberStatus != 1 && user.NicheStatus != 1 {
|
|
if user.VipStatus != 1 && user.MemberStatus != 1 && user.NicheStatus != 1 {
|
|
if prevTipUnix, err := redis.GetNewInt(Pushcache_2_c, PrevNoMsgTipKey(user)); err != nil {
|
|
if prevTipUnix, err := redis.GetNewInt(Pushcache_2_c, PrevNoMsgTipKey(user)); err != nil {
|
|
logger.Error("无消息提醒任务", taskType, "redis判断三天前是否提醒过出错", err)
|
|
logger.Error("无消息提醒任务", taskType, "redis判断三天前是否提醒过出错", err)
|
|
- return
|
|
|
|
|
|
+ return false
|
|
} else if now.Unix() < int64(prevTipUnix+ThreeDay) {
|
|
} else if now.Unix() < int64(prevTipUnix+ThreeDay) {
|
|
logger.Info("无消息提醒任务", taskType, "三天内已经提醒过,过滤掉", user.Id)
|
|
logger.Info("无消息提醒任务", taskType, "三天内已经提醒过,过滤掉", user.Id)
|
|
- return
|
|
|
|
|
|
+ return false
|
|
}
|
|
}
|
|
}
|
|
}
|
|
startEndMd := ""
|
|
startEndMd := ""
|
|
@@ -116,7 +137,7 @@ func (n *NoMsgTipJob) tip(taskType, hour int, user *UserInfo) {
|
|
} else if user.PushSet.SubSet.RateMode == 2 {
|
|
} else if user.PushSet.SubSet.RateMode == 2 {
|
|
isOver, start, end := TimesIsOver(user.PushSet.SubSet.Times, hour)
|
|
isOver, start, end := TimesIsOver(user.PushSet.SubSet.Times, hour)
|
|
if taskType != 1 && !isOver {
|
|
if taskType != 1 && !isOver {
|
|
- return
|
|
|
|
|
|
+ return false
|
|
}
|
|
}
|
|
startUnix = start.Unix()
|
|
startUnix = start.Unix()
|
|
endUnix = end.Unix()
|
|
endUnix = end.Unix()
|
|
@@ -137,44 +158,99 @@ func (n *NoMsgTipJob) tip(taskType, hour int, user *UserInfo) {
|
|
startUnix = start.Unix()
|
|
startUnix = start.Unix()
|
|
endUnix = now.Unix()
|
|
endUnix = now.Unix()
|
|
} else {
|
|
} else {
|
|
- return
|
|
|
|
|
|
+ return false
|
|
}
|
|
}
|
|
if exists, err := redis.Exists(Pushcache_2_c, HasPushKey(user)); err != nil {
|
|
if exists, err := redis.Exists(Pushcache_2_c, HasPushKey(user)); err != nil {
|
|
logger.Error("无消息提醒任务", taskType, "redis判断今天订阅是否推送过出错", err, user.Entniche.UserId)
|
|
logger.Error("无消息提醒任务", taskType, "redis判断今天订阅是否推送过出错", err, user.Entniche.UserId)
|
|
- return
|
|
|
|
|
|
+ return false
|
|
} else if exists {
|
|
} else if exists {
|
|
logger.Info("无消息提醒任务", taskType, "redis判断今天订阅推送过,过滤掉", user.Entniche.UserId)
|
|
logger.Info("无消息提醒任务", taskType, "redis判断今天订阅推送过,过滤掉", user.Entniche.UserId)
|
|
- return
|
|
|
|
|
|
+ return false
|
|
} else if exists, err := redis.Exists(Pushcache_2_c, HasDisPushKey(user)); err != nil {
|
|
} else if exists, err := redis.Exists(Pushcache_2_c, HasDisPushKey(user)); err != nil {
|
|
logger.Error("无消息提醒任务", taskType, "redis判断今天分发是否推送过出错", err, user.Entniche.UserId)
|
|
logger.Error("无消息提醒任务", taskType, "redis判断今天分发是否推送过出错", err, user.Entniche.UserId)
|
|
- return
|
|
|
|
|
|
+ return false
|
|
} else if exists {
|
|
} else if exists {
|
|
logger.Info("无消息提醒任务", taskType, "redis判断今天分发推送过,过滤掉", user.Entniche.UserId)
|
|
logger.Info("无消息提醒任务", taskType, "redis判断今天分发推送过,过滤掉", user.Entniche.UserId)
|
|
- return
|
|
|
|
|
|
+ return false
|
|
} else if exists, err := redis.Exists(Pushcache_2_c, NoMsgTipKey(user)); err != nil {
|
|
} else if exists, err := redis.Exists(Pushcache_2_c, NoMsgTipKey(user)); err != nil {
|
|
logger.Error("无消息提醒任务", taskType, "redis判断今天是否提醒过出错", err, user.Entniche.UserId)
|
|
logger.Error("无消息提醒任务", taskType, "redis判断今天是否提醒过出错", err, user.Entniche.UserId)
|
|
- return
|
|
|
|
|
|
+ return false
|
|
} else if exists {
|
|
} else if exists {
|
|
logger.Info("无消息提醒任务", taskType, "redis判断今天提醒过,过滤掉", user.Entniche.UserId)
|
|
logger.Info("无消息提醒任务", taskType, "redis判断今天提醒过,过滤掉", user.Entniche.UserId)
|
|
- return
|
|
|
|
|
|
+ return false
|
|
} else if n.pushCount(user, startUnix, endUnix) != 0 {
|
|
} else if n.pushCount(user, startUnix, endUnix) != 0 {
|
|
logger.Info("无消息提醒任务", taskType, "mysql判断用户该时间段推送过,过滤掉", startUnix, endUnix, user.Entniche.UserId)
|
|
logger.Info("无消息提醒任务", taskType, "mysql判断用户该时间段推送过,过滤掉", startUnix, endUnix, user.Entniche.UserId)
|
|
- return
|
|
|
|
|
|
+ return false
|
|
|
|
+ }
|
|
|
|
+ user.Extend = &UserInfoExtend{
|
|
|
|
+ Object: map[string]interface{}{"startEndMd": startEndMd},
|
|
|
|
+ }
|
|
|
|
+ return true
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+//
|
|
|
|
+func (n *NoMsgTipJob) beforeTip(taskType int, allTip []*UserInfo, wxTplSurplus int64, noMsgTipLastId *int64) {
|
|
|
|
+ pushPool := make(chan bool, Config.PushPoolSize)
|
|
|
|
+ pushWait := &sync.WaitGroup{}
|
|
|
|
+ for _, v := range allTip {
|
|
|
|
+ isTake := MonitorTimeOut(pushPool, time.Minute, Config.TimeoutWarn, func() {
|
|
|
|
+ logger.Error("推送任务", taskType, "推送放入通道超时,", v.Id)
|
|
|
|
+ })
|
|
|
|
+ pushWait.Add(1)
|
|
|
|
+ go func(user *UserInfo, take bool) {
|
|
|
|
+ defer util.Catch()
|
|
|
|
+ defer func() {
|
|
|
|
+ if take {
|
|
|
|
+ <-pushPool
|
|
|
|
+ }
|
|
|
|
+ pushWait.Done()
|
|
|
|
+ }()
|
|
|
|
+ n.toTip(taskType, user, wxTplSurplus, noMsgTipLastId)
|
|
|
|
+ }(v, isTake)
|
|
}
|
|
}
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+//
|
|
|
|
+func (n *NoMsgTipJob) toTip(taskType int, user *UserInfo, wxTplSurplus int64, noMsgTipLastId *int64) {
|
|
firstTitle, area, jcly, mailContent, infoCount, firstAutoId := n.SubRecommend(user)
|
|
firstTitle, area, jcly, mailContent, infoCount, firstAutoId := n.SubRecommend(user)
|
|
if infoCount == 0 {
|
|
if infoCount == 0 {
|
|
logger.Info("无消息提醒任务", taskType, "没有要推荐的信息,过滤掉", user.Entniche.UserId)
|
|
logger.Info("无消息提醒任务", taskType, "没有要推荐的信息,过滤掉", user.Entniche.UserId)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
+ now := time.Now()
|
|
redis.Put(Pushcache_2_c, NoMsgTipKey(user), 1, OneDaySecond)
|
|
redis.Put(Pushcache_2_c, NoMsgTipKey(user), 1, OneDaySecond)
|
|
redis.Put(Pushcache_2_c, PrevNoMsgTipKey(user), time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local).Unix(), ThreeDay+OneDaySecond)
|
|
redis.Put(Pushcache_2_c, PrevNoMsgTipKey(user), time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local).Unix(), ThreeDay+OneDaySecond)
|
|
logger.Info("无消息提醒任务", taskType, "开始推送", user.Entniche.UserId, "rateMode", user.PushSet.SubSet.RateMode, "jpushid", user.Jpushid, "opushid", user.Opushid, "appponetype", user.AppPhoneType, "email", user.PushSet.Email)
|
|
logger.Info("无消息提醒任务", taskType, "开始推送", user.Entniche.UserId, "rateMode", user.PushSet.SubSet.RateMode, "jpushid", user.Jpushid, "opushid", user.Opushid, "appponetype", user.AppPhoneType, "email", user.PushSet.Email)
|
|
ut1, _, ut3 := GetUserType(user)
|
|
ut1, _, ut3 := GetUserType(user)
|
|
|
|
+ startEndMd, _ := user.Extend.Object["startEndMd"].(string)
|
|
var isWxPushOk, isAppPushOk, isMailPushOk bool
|
|
var isWxPushOk, isAppPushOk, isMailPushOk bool
|
|
if user.PushSet.SubSet.WxPush == 1 {
|
|
if user.PushSet.SubSet.WxPush == 1 {
|
|
- logger.Info("无消息提醒任务", taskType, "开始微信推送", user.Entniche.UserId)
|
|
|
|
- isWxPushOk = n.sendWeixin(user, ut3, firstTitle, area, jcly, infoCount)
|
|
|
|
- logger.Info("无消息提醒任务", taskType, "微信推送结束", isWxPushOk, user.Entniche.UserId)
|
|
|
|
|
|
+ isWxPush := false
|
|
|
|
+ if wxTplSurplus < 0 {
|
|
|
|
+ isWxPush = true
|
|
|
|
+ } else {
|
|
|
|
+ key := fmt.Sprintf(Redis_NoMsgTipWxTmplCount, FormatDate(&now, Date_yyyyMMdd))
|
|
|
|
+ maxNum, err := redis.IncrByErr(Pushcache_2_c, key)
|
|
|
|
+ if err != nil {
|
|
|
|
+ logger.Error("无消息提醒任务", taskType, "从redis获取noMsgTipWxTmplCount出错", err)
|
|
|
|
+ }
|
|
|
|
+ if maxNum == 1 {
|
|
|
|
+ redis.SetExpire(Pushcache_2_c, key, OneDaySecond)
|
|
|
|
+ }
|
|
|
|
+ if maxNum <= wxTplSurplus {
|
|
|
|
+ isWxPush = true
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if isWxPush {
|
|
|
|
+ logger.Info("无消息提醒任务", taskType, "开始微信推送", user.Entniche.UserId)
|
|
|
|
+ isWxPushOk = n.sendWeixin(user, ut3, firstTitle, area, jcly, infoCount)
|
|
|
|
+ logger.Info("无消息提醒任务", taskType, "微信推送结束", isWxPushOk, user.Entniche.UserId)
|
|
|
|
+ } else {
|
|
|
|
+ if atomic.LoadInt64(noMsgTipLastId) < int64(user.Entniche.UserId) {
|
|
|
|
+ atomic.StoreInt64(noMsgTipLastId, int64(user.Entniche.UserId))
|
|
|
|
+ }
|
|
|
|
+ logger.Info("无消息提醒任务", taskType, "超过剩余模板消息量,不再推送微信", user.Entniche.UserId)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
if user.PushSet.SubSet.AppPush == 1 {
|
|
if user.PushSet.SubSet.AppPush == 1 {
|
|
logger.Info("无消息提醒任务", taskType, "开始app推送", user.Entniche.UserId)
|
|
logger.Info("无消息提醒任务", taskType, "开始app推送", user.Entniche.UserId)
|