|
@@ -11,6 +11,7 @@ import (
|
|
"qfw/util/mail"
|
|
"qfw/util/mail"
|
|
"qfw/util/mongodb"
|
|
"qfw/util/mongodb"
|
|
"qfw/util/redis"
|
|
"qfw/util/redis"
|
|
|
|
+ "sort"
|
|
"strconv"
|
|
"strconv"
|
|
"strings"
|
|
"strings"
|
|
"sync"
|
|
"sync"
|
|
@@ -38,25 +39,30 @@ type pushJob struct {
|
|
pool chan bool
|
|
pool chan bool
|
|
wait *sync.WaitGroup
|
|
wait *sync.WaitGroup
|
|
lock *sync.Mutex
|
|
lock *sync.Mutex
|
|
- lastId string
|
|
|
|
- users *[]map[string]interface{}
|
|
|
|
- vipTempSave bool
|
|
|
|
minutePushPool chan bool
|
|
minutePushPool chan bool
|
|
fastigiumMinutePushPool chan bool
|
|
fastigiumMinutePushPool chan bool
|
|
|
|
+ savePool chan bool
|
|
}
|
|
}
|
|
|
|
|
|
//taskType 1--一天三次推送 2--九点推送
|
|
//taskType 1--一天三次推送 2--九点推送
|
|
func (p *pushJob) Execute(taskType int) {
|
|
func (p *pushJob) Execute(taskType int) {
|
|
defer util.Catch()
|
|
defer util.Catch()
|
|
|
|
+ var pusher Pusher
|
|
|
|
+ if taskType == 1 || taskType == 2 {
|
|
|
|
+ pusher = &NormalPush{}
|
|
|
|
+ } else if taskType == 3 {
|
|
|
|
+ pusher = &SpecialPush{}
|
|
|
|
+ }
|
|
p.lock.Lock()
|
|
p.lock.Lock()
|
|
defer p.lock.Unlock()
|
|
defer p.lock.Unlock()
|
|
p.taskType = taskType
|
|
p.taskType = taskType
|
|
logger.Info("推送任务", p.taskType, "开始推送。。。")
|
|
logger.Info("推送任务", p.taskType, "开始推送。。。")
|
|
- batch_index := 0
|
|
|
|
|
|
+ batchIndex := 0
|
|
|
|
+ startId := ""
|
|
for {
|
|
for {
|
|
- batch_index++
|
|
|
|
- batch_size := p.OncePushBatch(batch_index)
|
|
|
|
- for _, temp := range *p.users {
|
|
|
|
|
|
+ batchIndex++
|
|
|
|
+ batch_size, users := pusher.OncePushBatch(taskType, batchIndex, &startId)
|
|
|
|
+ for _, temp := range *users {
|
|
isTake := true
|
|
isTake := true
|
|
select {
|
|
select {
|
|
case <-time.After(5 * time.Minute):
|
|
case <-time.After(5 * time.Minute):
|
|
@@ -114,11 +120,11 @@ func (p *pushJob) Execute(taskType int) {
|
|
if u.MailPush == 1 {
|
|
if u.MailPush == 1 {
|
|
mailPush = 1
|
|
mailPush = 1
|
|
}
|
|
}
|
|
- list := putil.ToSortList(v["list"])
|
|
|
|
logger.Info("推送任务", p.taskType, "用户接收方式", "userId", u.Id, "wxPush", wxPush, "appPush", appPush, "mailPush", mailPush, "pchelperPush", u.PchelperPush)
|
|
logger.Info("推送任务", p.taskType, "用户接收方式", "userId", u.Id, "wxPush", wxPush, "appPush", appPush, "mailPush", mailPush, "pchelperPush", u.PchelperPush)
|
|
if wxPush != 1 && appPush != 1 && mailPush != 1 {
|
|
if wxPush != 1 && appPush != 1 && mailPush != 1 {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
+ list := putil.ToSortList(v["list"])
|
|
//再对取消关注以及app没有登录的用户进行过滤,但是依然可以进行助手推送
|
|
//再对取消关注以及app没有登录的用户进行过滤,但是依然可以进行助手推送
|
|
if u.Subscribe == 0 {
|
|
if u.Subscribe == 0 {
|
|
wxPush = 0
|
|
wxPush = 0
|
|
@@ -135,7 +141,7 @@ func (p *pushJob) Execute(taskType int) {
|
|
mailPush = 0
|
|
mailPush = 0
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- isSaveSuccess, wxStatus, appStatus, mailStatus := p.Push(p.taskType, wxPush, appPush, mailPush, u, list)
|
|
|
|
|
|
+ isSaveSuccess, isVipTempSave, wxStatus, appStatus, mailStatus := p.push(p.taskType, wxPush, appPush, mailPush, u, list)
|
|
if isSaveSuccess {
|
|
if isSaveSuccess {
|
|
if u.FirstPushTime == 0 {
|
|
if u.FirstPushTime == 0 {
|
|
go mongodb.Update("user", map[string]interface{}{
|
|
go mongodb.Update("user", map[string]interface{}{
|
|
@@ -146,6 +152,9 @@ func (p *pushJob) Execute(taskType int) {
|
|
},
|
|
},
|
|
}, false, false)
|
|
}, false, false)
|
|
}
|
|
}
|
|
|
|
+ if isVipTempSave {
|
|
|
|
+ p.vipTempSave(u.Id, v)
|
|
|
|
+ }
|
|
} else {
|
|
} else {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
@@ -157,41 +166,19 @@ func (p *pushJob) Execute(taskType int) {
|
|
logger.Error("推送任务", p.taskType, "remove error", err)
|
|
logger.Error("推送任务", p.taskType, "remove error", err)
|
|
}
|
|
}
|
|
if wxStatus == -1 || appStatus == -1 || mailStatus == -1 {
|
|
if wxStatus == -1 || appStatus == -1 || mailStatus == -1 {
|
|
- f_count, err := sess.DB(DbName).C("pushspace").FindId(v["_id"]).Count()
|
|
|
|
- if err != nil {
|
|
|
|
- logger.Error("推送任务", p.taskType, "find count error", err)
|
|
|
|
- return
|
|
|
|
|
|
+ v["failtime"] = time.Now().Unix()
|
|
|
|
+ if wxStatus == -1 {
|
|
|
|
+ v["wxfail"] = 1
|
|
}
|
|
}
|
|
- if f_count == 0 {
|
|
|
|
- v["failtime"] = time.Now().Unix()
|
|
|
|
- if wxStatus == -1 {
|
|
|
|
- v["wxfail"] = 1
|
|
|
|
- }
|
|
|
|
- if appStatus == -1 {
|
|
|
|
- v["appfail"] = 1
|
|
|
|
- }
|
|
|
|
- if mailStatus == -1 {
|
|
|
|
- v["mailfail"] = 1
|
|
|
|
- }
|
|
|
|
- err := sess.DB(DbName).C("pushspace_fail").Insert(v)
|
|
|
|
- if err != nil {
|
|
|
|
- logger.Error("推送任务", p.taskType, "update error", err)
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- f_update := map[string]interface{}{}
|
|
|
|
- if wxStatus == -1 {
|
|
|
|
- f_update["wxfail"] = 1
|
|
|
|
- }
|
|
|
|
- if appStatus == -1 {
|
|
|
|
- f_update["appfail"] = 1
|
|
|
|
- }
|
|
|
|
- if mailStatus == -1 {
|
|
|
|
- f_update["mailfail"] = 1
|
|
|
|
- }
|
|
|
|
- err := sess.DB(DbName).C("pushspace_fail").UpdateId(v["_id"], map[string]interface{}{"$set": f_update})
|
|
|
|
- if err != nil {
|
|
|
|
- logger.Error("推送任务", p.taskType, "update error", err)
|
|
|
|
- }
|
|
|
|
|
|
+ if appStatus == -1 {
|
|
|
|
+ v["appfail"] = 1
|
|
|
|
+ }
|
|
|
|
+ if mailStatus == -1 {
|
|
|
|
+ v["mailfail"] = 1
|
|
|
|
+ }
|
|
|
|
+ _, err := sess.DB(DbName).C("pushspace_fail").UpsertId(v["_id"], map[string]interface{}{"$set": v})
|
|
|
|
+ if err != nil {
|
|
|
|
+ logger.Error("推送任务", p.taskType, "update error", err)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}(temp, isTake)
|
|
}(temp, isTake)
|
|
@@ -201,63 +188,16 @@ func (p *pushJob) Execute(taskType int) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
p.wait.Wait()
|
|
p.wait.Wait()
|
|
- p.lastId = ""
|
|
|
|
- p.users = nil
|
|
|
|
logger.Info("推送任务结束。。。", p.taskType)
|
|
logger.Info("推送任务结束。。。", p.taskType)
|
|
}
|
|
}
|
|
-func (p *pushJob) OncePushBatch(batch_index int) int {
|
|
|
|
- p.users = &[]map[string]interface{}{}
|
|
|
|
- i := 0
|
|
|
|
- sess := mongodb.GetMgoConn()
|
|
|
|
- defer mongodb.DestoryMongoConn(sess)
|
|
|
|
- var query map[string]interface{}
|
|
|
|
- //根据任务类型,查找ratemode
|
|
|
|
- if p.taskType == 1 {
|
|
|
|
- query = map[string]interface{}{
|
|
|
|
- "ratemode": 1,
|
|
|
|
- }
|
|
|
|
- } else if p.taskType == 2 {
|
|
|
|
- query = map[string]interface{}{
|
|
|
|
- "ratemode": 2,
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- logger.Error("taskType error", p.taskType)
|
|
|
|
- return i
|
|
|
|
- }
|
|
|
|
- if len(Config.TestIds) > 0 {
|
|
|
|
- query["userid"] = map[string]interface{}{
|
|
|
|
- "$in": Config.TestIds,
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if p.lastId != "" {
|
|
|
|
- query["_id"] = map[string]interface{}{
|
|
|
|
- "$gt": bson.ObjectIdHex(p.lastId),
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- logger.Info("推送任务", p.taskType, "开始加载第", batch_index, "批用户", query)
|
|
|
|
- it := sess.DB(DbName).C("pushspace").Find(query).Sort("_id").Iter()
|
|
|
|
- for temp := make(map[string]interface{}); it.Next(&temp); {
|
|
|
|
- i++
|
|
|
|
- p.lastId = util.BsonIdToSId(temp["_id"])
|
|
|
|
- *p.users = append(*p.users, temp)
|
|
|
|
- temp = make(map[string]interface{})
|
|
|
|
- if i == Config.PushBatch {
|
|
|
|
- break
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- logger.Info("推送任务", p.taskType, "第", batch_index, "批用户加载结束", p.lastId)
|
|
|
|
- return i
|
|
|
|
-}
|
|
|
|
|
|
|
|
-func (p *pushJob) Push(taskType int, wxPush, appPush, mailPush int, u *UserInfo, list SortList) (isSaveSuccess bool, wxStatus, appStatus, mailStatus int) {
|
|
|
|
|
|
+func (p *pushJob) push(taskType int, wxPush, appPush, mailPush int, u *UserInfo, list SortList) (isSaveSuccess, isVipTempSave bool, wxStatus, appStatus, mailStatus int) {
|
|
if wxPush == 1 || appPush == 1 || mailPush == 1 || u.PchelperPush == 1 {
|
|
if wxPush == 1 || appPush == 1 || mailPush == 1 || u.PchelperPush == 1 {
|
|
- if list != nil {
|
|
|
|
- isSaveSuccess, wxStatus, appStatus, mailStatus = p.DoPush(taskType, true, wxPush, appPush, mailPush, u, &list)
|
|
|
|
- }
|
|
|
|
|
|
+ isSaveSuccess, isVipTempSave, wxStatus, appStatus, mailStatus = p.doPush(taskType, true, wxPush, appPush, mailPush, u, &list)
|
|
}
|
|
}
|
|
- return isSaveSuccess, wxStatus, appStatus, mailStatus
|
|
|
|
|
|
+ return isSaveSuccess, isVipTempSave, wxStatus, appStatus, mailStatus
|
|
}
|
|
}
|
|
-func (p *pushJob) DoPush(taskType int, isSave bool, wxPush, appPush, mailPush int, k *UserInfo, sl *SortList) (isSaveSuccess bool, wxStatus, appStatus, mailStatus int) {
|
|
|
|
|
|
+func (p *pushJob) doPush(taskType int, isSave bool, wxPush, appPush, mailPush int, k *UserInfo, sl *SortList) (isSaveSuccess, isVipTempSave bool, wxStatus, appStatus, mailStatus int) {
|
|
defer util.Catch()
|
|
defer util.Catch()
|
|
mailContent := ""
|
|
mailContent := ""
|
|
jpushtitle := ""
|
|
jpushtitle := ""
|
|
@@ -351,7 +291,7 @@ func (p *pushJob) DoPush(taskType int, isSave bool, wxPush, appPush, mailPush in
|
|
mailContent += fmt.Sprintf(Config.Mail_content, infosLength, url, otitle, classArea, area, classType, infotype, industryclass, industry, dates)
|
|
mailContent += fmt.Sprintf(Config.Mail_content, infosLength, url, otitle, classArea, area, classType, infotype, industryclass, industry, dates)
|
|
}
|
|
}
|
|
if isVipUser {
|
|
if isVipUser {
|
|
- if dayCount >= Config.VipOneDayMaxPushSize {
|
|
|
|
|
|
+ if dayCount >= Config.VipMaxPushSize {
|
|
break
|
|
break
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
@@ -379,7 +319,7 @@ func (p *pushJob) DoPush(taskType int, isSave bool, wxPush, appPush, mailPush in
|
|
pushDate := ""
|
|
pushDate := ""
|
|
if taskType != 0 && isSave {
|
|
if taskType != 0 && isSave {
|
|
//推送记录id
|
|
//推送记录id
|
|
- pushDate = putil.SaveSendInfo(k, infos)
|
|
|
|
|
|
+ pushDate = p.save(k, infos)
|
|
if pushDate == "" {
|
|
if pushDate == "" {
|
|
logger.Info("推送任务", taskType, "保存出错", k.Id)
|
|
logger.Info("推送任务", taskType, "保存出错", k.Id)
|
|
return
|
|
return
|
|
@@ -387,8 +327,12 @@ func (p *pushJob) DoPush(taskType int, isSave bool, wxPush, appPush, mailPush in
|
|
logger.Info("推送任务", taskType, "保存成功", pushDate, k.Id)
|
|
logger.Info("推送任务", taskType, "保存成功", pushDate, k.Id)
|
|
isSaveSuccess = true
|
|
isSaveSuccess = true
|
|
}
|
|
}
|
|
- if isVipUser && (now.Day() == 28 || now.Weekday().String() == "Friday") && (k.RateMode == 3 || k.RateMode == 4) {
|
|
|
|
-
|
|
|
|
|
|
+ if isVipUser && (k.RateMode == 3 || k.RateMode == 4) {
|
|
|
|
+ if now.Day() != 28 && now.Weekday().String() != "Friday" {
|
|
|
|
+ isVipTempSave = true
|
|
|
|
+ return
|
|
|
|
+ } else {
|
|
|
|
+ }
|
|
}
|
|
}
|
|
logger.Info("推送任务", taskType, "开始进行终端推送", k.Id)
|
|
logger.Info("推送任务", taskType, "开始进行终端推送", k.Id)
|
|
if isSaveSuccess {
|
|
if isSaveSuccess {
|
|
@@ -421,56 +365,59 @@ func (p *pushJob) DoPush(taskType int, isSave bool, wxPush, appPush, mailPush in
|
|
TmpTip = fmt.Sprintf("%d分钟前发布的", minute)
|
|
TmpTip = fmt.Sprintf("%d分钟前发布的", minute)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- Tip1 := util.If(TmpTip == "", "", TmpTip+":\n").(string)
|
|
|
|
- LastTip := ""
|
|
|
|
|
|
+ tip := util.If(TmpTip == "", "", TmpTip+":\n").(string)
|
|
|
|
+ lastTip := ""
|
|
if infosLength > 1 {
|
|
if infosLength > 1 {
|
|
- LastTip = fmt.Sprintf("...(共%d条)", infosLength)
|
|
|
|
|
|
+ lastTip = fmt.Sprintf("...(共%d条)", infosLength)
|
|
}
|
|
}
|
|
- LastTipLen := len([]rune(LastTip))
|
|
|
|
- wxTitleKeys := strings.Join(k.Keys, ";")
|
|
|
|
- if len([]rune(wxTitleKeys)) > 8 {
|
|
|
|
- wxTitleKeys = string([]rune(wxTitleKeys)[:8]) + "..."
|
|
|
|
|
|
+ LastTipLen := len([]rune(lastTip))
|
|
|
|
+ wxTitle := Config.VipWxTitle
|
|
|
|
+ if !isVipUser {
|
|
|
|
+ wxTitleKeys := strings.Join(k.Keys, ";")
|
|
|
|
+ if len([]rune(wxTitleKeys)) > 8 {
|
|
|
|
+ wxTitleKeys = string([]rune(wxTitleKeys)[:8]) + "..."
|
|
|
|
+ }
|
|
|
|
+ wxTitle = fmt.Sprintf(Config.WxTitle, wxTitleKeys)
|
|
}
|
|
}
|
|
- wxtitle := fmt.Sprintf(Config.WxTitle, wxTitleKeys)
|
|
|
|
- TitleLen := len([]rune(wxtitle))
|
|
|
|
- reLen := 200 - TitleLen - 10 - WxGroupLen - len([]rune(Tip1))
|
|
|
|
- WXTitle := ""
|
|
|
|
|
|
+ TitleLen := len([]rune(wxTitle))
|
|
|
|
+ reLen := 200 - TitleLen - 10 - WxGroupLen - len([]rune(tip))
|
|
|
|
+ wxTplTitle := ""
|
|
bshow := false
|
|
bshow := false
|
|
for n := 1; n < len(TitleArray)+1; n++ {
|
|
for n := 1; n < len(TitleArray)+1; n++ {
|
|
curTitle := TitleArray[n-1]
|
|
curTitle := TitleArray[n-1]
|
|
- tmptitle := WXTitle + fmt.Sprintf("%d %s\n", n, curTitle)
|
|
|
|
|
|
+ tmptitle := wxTplTitle + fmt.Sprintf("%d %s\n", n, curTitle)
|
|
ch := reLen - len([]rune(tmptitle))
|
|
ch := reLen - len([]rune(tmptitle))
|
|
if ch < LastTipLen { //加上后大于后辍,则没有完全显示
|
|
if ch < LastTipLen { //加上后大于后辍,则没有完全显示
|
|
if ch == 0 && n == len(TitleArray) {
|
|
if ch == 0 && n == len(TitleArray) {
|
|
- WXTitle = tmptitle
|
|
|
|
|
|
+ wxTplTitle = tmptitle
|
|
bshow = true
|
|
bshow = true
|
|
} else {
|
|
} else {
|
|
- ch_1 := reLen - len([]rune(WXTitle)) - LastTipLen
|
|
|
|
|
|
+ ch_1 := reLen - len([]rune(wxTplTitle)) - LastTipLen
|
|
if ch_1 > 8 {
|
|
if ch_1 > 8 {
|
|
curLen := len([]rune(curTitle))
|
|
curLen := len([]rune(curTitle))
|
|
if ch_1 > curLen {
|
|
if ch_1 > curLen {
|
|
ch_1 = curLen
|
|
ch_1 = curLen
|
|
}
|
|
}
|
|
- WXTitle += fmt.Sprintf("%d %s\n", n, string([]rune(curTitle)[:ch_1-3]))
|
|
|
|
|
|
+ wxTplTitle += fmt.Sprintf("%d %s\n", n, string([]rune(curTitle)[:ch_1-3]))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else if ch == LastTipLen {
|
|
} else if ch == LastTipLen {
|
|
- WXTitle = tmptitle
|
|
|
|
|
|
+ wxTplTitle = tmptitle
|
|
if n == len(TitleArray) {
|
|
if n == len(TitleArray) {
|
|
bshow = true
|
|
bshow = true
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- WXTitle = tmptitle
|
|
|
|
|
|
+ wxTplTitle = tmptitle
|
|
if n == len(TitleArray) {
|
|
if n == len(TitleArray) {
|
|
bshow = true
|
|
bshow = true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if bshow {
|
|
if bshow {
|
|
- LastTip = ""
|
|
|
|
|
|
+ lastTip = ""
|
|
}
|
|
}
|
|
//推送微信
|
|
//推送微信
|
|
- isPushOk = putil.SendWeixin(k, Tip1+WXTitle+LastTip, wxtitle, pushDate)
|
|
|
|
|
|
+ isPushOk = putil.SendWeixin(k, tip+wxTplTitle+lastTip, wxTitle, pushDate)
|
|
if isPushOk {
|
|
if isPushOk {
|
|
wxStatus = 1
|
|
wxStatus = 1
|
|
} else {
|
|
} else {
|
|
@@ -514,7 +461,7 @@ func (p *pushJob) DoPush(taskType int, isSave bool, wxPush, appPush, mailPush in
|
|
if mailPush == 1 {
|
|
if mailPush == 1 {
|
|
logger.Info("推送任务", taskType, "开始邮箱推送", k.Id)
|
|
logger.Info("推送任务", taskType, "开始邮箱推送", k.Id)
|
|
html := fmt.Sprintf(Config.Mail_html, strings.Replace(strings.Join(k.Keys, ";"), "+", " ", -1), mailContent)
|
|
html := fmt.Sprintf(Config.Mail_html, strings.Replace(strings.Join(k.Keys, ";"), "+", " ", -1), mailContent)
|
|
- isPushOk := p.SendMail(k.Email, Config.Mail_title, html, nil)
|
|
|
|
|
|
+ isPushOk := p.sendMail(k.Email, Config.Mail_title, html, nil)
|
|
if isPushOk {
|
|
if isPushOk {
|
|
mailStatus = 1
|
|
mailStatus = 1
|
|
} else {
|
|
} else {
|
|
@@ -526,7 +473,7 @@ func (p *pushJob) DoPush(taskType int, isSave bool, wxPush, appPush, mailPush in
|
|
}
|
|
}
|
|
|
|
|
|
//推送邮件(含附件)
|
|
//推送邮件(含附件)
|
|
-func (p *pushJob) SendMail(email, subject, html string, fmdatas []map[string]interface{}) bool {
|
|
|
|
|
|
+func (p *pushJob) sendMail(email, subject, html string, fmdatas []map[string]interface{}) bool {
|
|
if !Config.IsPushMail || len(Gmails) == 0 {
|
|
if !Config.IsPushMail || len(Gmails) == 0 {
|
|
return true
|
|
return true
|
|
}
|
|
}
|
|
@@ -558,3 +505,78 @@ func (p *pushJob) SendMail(email, subject, html string, fmdatas []map[string]int
|
|
}
|
|
}
|
|
return status
|
|
return status
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+//保存发送信息
|
|
|
|
+func (p *pushJob) save(k *UserInfo, matchInfos []*MatchInfo) string {
|
|
|
|
+ p.savePool <- true
|
|
|
|
+ defer func() {
|
|
|
|
+ <-p.savePool
|
|
|
|
+ }()
|
|
|
|
+ if Config.SaveSleep > 0 {
|
|
|
|
+ time.Sleep(time.Duration(Config.SaveSleep) * time.Millisecond)
|
|
|
|
+ }
|
|
|
|
+ unix := time.Now().Unix()
|
|
|
|
+ values := []interface{}{}
|
|
|
|
+ for _, matchInfo := range matchInfos {
|
|
|
|
+ values = append(values, k.Id, util.ObjToString((*matchInfo.Info)["_id"]), unix, strings.Join(matchInfo.Keys, " "), util.ObjToString((*matchInfo.Info)["area"]), util.ObjToString((*matchInfo.Info)["city"]), util.ObjToString((*matchInfo.Info)["buyerclass"]))
|
|
|
|
+ }
|
|
|
|
+ savecount := putil.Mysql.InsertBatch("pushsubscribe", []string{"userid", "infoid", "date", "matchkeys", "area", "city", "buyerclass"}, values)
|
|
|
|
+ if int(savecount) != len(values) {
|
|
|
|
+ logger.Error(k.Id, "批量保存有问题", len(values), savecount)
|
|
|
|
+ }
|
|
|
|
+ return fmt.Sprint(unix)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+//vip 每周 每月推送 暂时保存
|
|
|
|
+func (p *pushJob) vipTempSave(userId string, v map[string]interface{}) {
|
|
|
|
+ newList := putil.ToSortList(v["list"])
|
|
|
|
+ pLength := len(newList)
|
|
|
|
+ if pLength == 0 {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ sess := mongodb.GetMgoConn()
|
|
|
|
+ defer mongodb.DestoryMongoConn(sess)
|
|
|
|
+ var data map[string]interface{}
|
|
|
|
+ coll := sess.DB(DbName).C("pushspace_vip")
|
|
|
|
+ err := coll.Find(map[string]interface{}{"userid": userId}).Select(map[string]interface{}{"size": 1, "list": 1, "date": 1, "userid": 1}).One(&data)
|
|
|
|
+ if err != nil {
|
|
|
|
+ logger.Error(userId, "获取用户pushspace_vip数据出错", err)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ nowymd := util.NowFormat(util.Date_yyyyMMdd)
|
|
|
|
+ if data == nil { //批量新增
|
|
|
|
+ err = coll.Insert(map[string]interface{}{
|
|
|
|
+ "userid": v["userid"],
|
|
|
|
+ "size": v["size"],
|
|
|
|
+ "list": v["list"],
|
|
|
|
+ "date": nowymd,
|
|
|
|
+ "createtime": time.Now().Unix(),
|
|
|
|
+ })
|
|
|
|
+ if err != nil {
|
|
|
|
+ logger.Error(userId, "保存pushspace_vip出错", err)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ } else { //批量更新
|
|
|
|
+ upSet := map[string]interface{}{}
|
|
|
|
+ if nowymd != util.ObjToString(data["date"]) {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ oldList := putil.ToSortList(data["list"])
|
|
|
|
+ if len(oldList)+pLength > Config.MaxPushSize {
|
|
|
|
+ newList = append(newList, oldList...)
|
|
|
|
+ sort.Sort(newList)
|
|
|
|
+ v["list"] = newList[:Config.MaxPushSize]
|
|
|
|
+ } else { //追加
|
|
|
|
+ upSet["$pushAll"] = map[string]interface{}{
|
|
|
|
+ "list": newList,
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ v["size"] = util.IntAll(v["size"]) + pLength
|
|
|
|
+ upSet["$set"] = v
|
|
|
|
+ err = coll.UpdateId(data["_id"], upSet)
|
|
|
|
+ if err != nil {
|
|
|
|
+ logger.Error(userId, "更新pushspace_vip出错", err)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|