|
@@ -12,7 +12,6 @@ import (
|
|
|
"qfw/util"
|
|
|
"qfw/util/mail"
|
|
|
"qfw/util/mongodb"
|
|
|
- "qfw/util/redis"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"sync"
|
|
@@ -42,7 +41,6 @@ type PushJob struct {
|
|
|
lock *sync.Mutex
|
|
|
minutePushPool chan bool
|
|
|
fastigiumMinutePushPool chan bool
|
|
|
- savePool chan bool
|
|
|
}
|
|
|
|
|
|
//taskType 1--一天三次推送 2--九点推送
|
|
@@ -58,7 +56,9 @@ func (p *PushJob) startPush(taskType int) {
|
|
|
defer util.Catch()
|
|
|
var pusher Pusher
|
|
|
if taskType == 1 || taskType == 2 {
|
|
|
- pusher = &NormalPush{}
|
|
|
+ pusher = &NormalPush{
|
|
|
+ SavePool: make(chan bool, Config.SavePoolSize),
|
|
|
+ }
|
|
|
} else if taskType == 3 {
|
|
|
pusher = &SpecialPush{}
|
|
|
} else {
|
|
@@ -132,7 +132,7 @@ func (p *PushJob) startPush(taskType int) {
|
|
|
mailPush = 0
|
|
|
}
|
|
|
}
|
|
|
- pushResult := p.selectPush(p.taskType, wxPush, appPush, mailPush, u, list)
|
|
|
+ pushResult := p.selectPush(pusher, p.taskType, wxPush, appPush, mailPush, u, list)
|
|
|
log.Println(pushResult)
|
|
|
pusher.AfterPush(pushResult, u, v)
|
|
|
}(temp, isTake)
|
|
@@ -146,126 +146,18 @@ func (p *PushJob) startPush(taskType int) {
|
|
|
}
|
|
|
|
|
|
//满足条件进行推送
|
|
|
-func (p *PushJob) selectPush(taskType int, wxPush, appPush, mailPush int, u *UserInfo, list SortList) (pushResult *putil.PushResult) {
|
|
|
+func (p *PushJob) selectPush(pusher Pusher, taskType int, wxPush, appPush, mailPush int, u *UserInfo, list SortList) (pushResult *putil.PushResult) {
|
|
|
if wxPush == 1 || appPush == 1 || mailPush == 1 || u.PchelperPush == 1 {
|
|
|
- pushResult = p.doPush(taskType, true, wxPush, appPush, mailPush, u, &list)
|
|
|
+ pushResult = p.doPush(pusher, taskType, wxPush, appPush, mailPush, u, &list)
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//进入具体推送
|
|
|
-func (p *PushJob) doPush(taskType int, isSave bool, wxPush, appPush, mailPush int, k *UserInfo, sl *SortList) (pushResult *putil.PushResult) {
|
|
|
+func (p *PushJob) doPush(pusher Pusher, taskType int, wxPush, appPush, mailPush int, u *UserInfo, sl *SortList) (pushResult *putil.PushResult) {
|
|
|
defer util.Catch()
|
|
|
pushResult = &putil.PushResult{}
|
|
|
- mailContent := ""
|
|
|
- jpushtitle := ""
|
|
|
- lastInfoDate := int64(0)
|
|
|
- TitleArray := []string{}
|
|
|
- infos := []*MatchInfo{}
|
|
|
- infosLength := 0
|
|
|
- publishTitle := map[string]bool{}
|
|
|
- dateymd := util.NowFormat(util.Date_yyyyMMdd)
|
|
|
- dayCountKey := DayCountKey(dateymd, k.Id)
|
|
|
- onceCountKey := OnceCountKey(dateymd, k.Id)
|
|
|
- dayCount := redis.GetInt("pushcache_2_a", dayCountKey)
|
|
|
- isVipUser := IsVipUser(k.VipStatus)
|
|
|
now := time.Now()
|
|
|
- for _, ks := range *sl {
|
|
|
- k2 := *ks.Info
|
|
|
- title := strings.Replace(k2["title"].(string), "\n", "", -1)
|
|
|
- title = Re.ReplaceAllString(title, "$1")
|
|
|
- area := util.ObjToString(k2["area"])
|
|
|
- if area == "A" {
|
|
|
- area = "全国"
|
|
|
- }
|
|
|
- newTitle := fmt.Sprintf("[%s]%s", area, title)
|
|
|
- if publishTitle[newTitle] {
|
|
|
- continue
|
|
|
- }
|
|
|
- publishTitle[newTitle] = true
|
|
|
- infosLength++
|
|
|
- infos = append(infos, ks)
|
|
|
- TitleArray = append(TitleArray, newTitle)
|
|
|
- if infosLength == 1 {
|
|
|
- jpushtitle = title
|
|
|
- lastInfoDate = util.Int64All(k2["publishtime"])
|
|
|
- }
|
|
|
- //增加行业的处理
|
|
|
- industry := ""
|
|
|
- industryclass := "industry"
|
|
|
- if k2["s_subscopeclass"] != nil {
|
|
|
- k2sub := strings.Split(util.ObjToString(k2["s_subscopeclass"]), ",")
|
|
|
- if len(k2sub) > 0 {
|
|
|
- industry = k2sub[0]
|
|
|
- if industry != "" {
|
|
|
- ss := strings.Split(industry, "_")
|
|
|
- if len(ss) > 1 {
|
|
|
- industry = ss[0]
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if mailPush == 1 { //关于邮件的处理
|
|
|
- mailSid := util.CommonEncodeArticle("mailprivate", util.ObjToString(k2["_id"]))
|
|
|
- url := fmt.Sprintf("%s/article/mailprivate/%s.html", Config.JianyuDomain, mailSid)
|
|
|
- classArea := "area"
|
|
|
- classType := "type"
|
|
|
- infotype := util.ObjToString(k2["subtype"])
|
|
|
- if infotype == "" {
|
|
|
- infotype = util.ObjToString(k2["toptype"])
|
|
|
- }
|
|
|
- if infotype == "" {
|
|
|
- infotype = util.ObjToString(k2["type"])
|
|
|
- if infotype == "tender" {
|
|
|
- infotype = "招标"
|
|
|
- } else if infotype == "bid" {
|
|
|
- infotype = "中标"
|
|
|
- }
|
|
|
- }
|
|
|
- dates := util.LongToDate(k2["publishtime"], false)
|
|
|
- //标题替换
|
|
|
- otitle := title
|
|
|
- for _, kw := range k.Keys {
|
|
|
- kws := strings.Split(kw, "+")
|
|
|
- n := 0
|
|
|
- otitle2 := otitle
|
|
|
- for _, kwn := range kws {
|
|
|
- ot := strings.Replace(otitle2, kwn, "<span class='keys'>"+kwn+"</span>", 1)
|
|
|
- if ot != otitle {
|
|
|
- n++
|
|
|
- otitle2 = ot
|
|
|
- } else {
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
- if n == len(kws) {
|
|
|
- otitle = otitle2
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
- if industry == "" {
|
|
|
- industryclass = ""
|
|
|
- }
|
|
|
- mailContent += fmt.Sprintf(Config.Mail_content, infosLength, url, otitle, classArea, area, classType, infotype, industryclass, industry, dates)
|
|
|
- }
|
|
|
- if isVipUser {
|
|
|
- if dayCount >= Config.VipMaxPushSize {
|
|
|
- break
|
|
|
- }
|
|
|
- } else {
|
|
|
- //限制最大信息条数
|
|
|
- if infosLength >= Config.MaxPushSize {
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
- dayCount++
|
|
|
- }
|
|
|
- if infosLength == 0 {
|
|
|
- logger.Info("推送任务", taskType, "没有要推送的数据!", k.Id)
|
|
|
- return
|
|
|
- }
|
|
|
- redis.Put("pushcache_2_a", dayCountKey, dayCount, 86400)
|
|
|
- redis.Put("pushcache_2_a", onceCountKey, infosLength, 86400)
|
|
|
//限制一分钟最大的推送数量
|
|
|
if p.fastigiumMinutePushPool != nil {
|
|
|
if hour := now.Hour(); hour >= FastigiumStart && hour <= FastigiumEnd {
|
|
@@ -274,44 +166,37 @@ func (p *PushJob) doPush(taskType int, isSave bool, wxPush, appPush, mailPush in
|
|
|
} else if p.minutePushPool != nil {
|
|
|
<-p.minutePushPool //正常期
|
|
|
}
|
|
|
- pushDate := ""
|
|
|
- if taskType != 0 && isSave {
|
|
|
- //推送记录id
|
|
|
- pushDate = p.save(k, infos)
|
|
|
- if pushDate == "" {
|
|
|
- logger.Info("推送任务", taskType, "保存出错", k.Id)
|
|
|
- return
|
|
|
- }
|
|
|
- logger.Info("推送任务", taskType, "保存成功", pushDate, k.Id)
|
|
|
- pushResult.IsSaveSuccess = true
|
|
|
+ pushParam := pusher.GetPushParam(mailPush, u, sl)
|
|
|
+ if pushParam == nil {
|
|
|
+ logger.Info("推送任务", taskType, "没有要推送的数据!", u.Id)
|
|
|
+ return nil
|
|
|
}
|
|
|
- if isVipUser && (k.RateMode == 3 || k.RateMode == 4) {
|
|
|
- if now.Day() != Config.VipPushDay && now.Weekday().String() != Config.VipPushWeek {
|
|
|
- pushResult.IsVipTempSave = true
|
|
|
- return
|
|
|
- } else {
|
|
|
- }
|
|
|
+ pushResult.Infos = pushParam.Infos
|
|
|
+ pushResult.PushDate = pushParam.PushDate
|
|
|
+ pushResult.IsVipTempSave = pushParam.IsVipTempSave
|
|
|
+ if !pushParam.IsPush {
|
|
|
+ return pushResult
|
|
|
}
|
|
|
- logger.Info("推送任务", taskType, "开始进行终端推送", k.Id)
|
|
|
- if pushResult.IsSaveSuccess {
|
|
|
+ logger.Info("推送任务", taskType, "开始进行终端推送", u.Id)
|
|
|
+ if pushResult.PushDate > 0 {
|
|
|
//pc端助手推送
|
|
|
- if k.S_m_openid != "" {
|
|
|
- logger.Info("推送任务", taskType, "开始助手推送", k.Id, "s_m_openid", k.S_m_openid)
|
|
|
- isPushOk := putil.SendPcHelper(map[string]interface{}{"clientCode": k.S_m_openid})
|
|
|
- logger.Info("推送任务", taskType, "助手推送结束", isPushOk, k.Id, "s_m_openid", k.S_m_openid)
|
|
|
+ if u.S_m_openid != "" {
|
|
|
+ logger.Info("推送任务", taskType, "开始助手推送", u.Id, "s_m_openid", u.S_m_openid)
|
|
|
+ isPushOk := putil.SendPcHelper(map[string]interface{}{"clientCode": u.S_m_openid})
|
|
|
+ logger.Info("推送任务", taskType, "助手推送结束", isPushOk, u.Id, "s_m_openid", u.S_m_openid)
|
|
|
}
|
|
|
- if k.Phone != "" {
|
|
|
- logger.Info("推送任务", taskType, "开始助手推送", k.Id, "phone", k.Phone)
|
|
|
- isPushOk := putil.SendPcHelper(map[string]interface{}{"clientCode": k.Phone})
|
|
|
- logger.Info("推送任务", taskType, "助手推送结束", isPushOk, k.Id, "phone", k.Phone)
|
|
|
+ if u.Phone != "" {
|
|
|
+ logger.Info("推送任务", taskType, "开始助手推送", u.Id, "phone", u.Phone)
|
|
|
+ isPushOk := putil.SendPcHelper(map[string]interface{}{"clientCode": u.Phone})
|
|
|
+ logger.Info("推送任务", taskType, "助手推送结束", isPushOk, u.Id, "phone", u.Phone)
|
|
|
}
|
|
|
}
|
|
|
if wxPush == 1 {
|
|
|
- logger.Info("推送任务", taskType, "开始微信推送", k.ApplyStatus, k.Id)
|
|
|
+ logger.Info("推送任务", taskType, "开始微信推送", u.ApplyStatus, u.Id)
|
|
|
isPushOk := true
|
|
|
- if k.ApplyStatus == 1 {
|
|
|
+ if u.ApplyStatus == 1 {
|
|
|
TmpTip := ""
|
|
|
- minute := now.Unix() - lastInfoDate
|
|
|
+ minute := now.Unix() - pushParam.LastInfoDate
|
|
|
if minute > -1 && minute < 61 {
|
|
|
TmpTip = fmt.Sprintf("%d秒前发布的", minute)
|
|
|
} else {
|
|
@@ -325,13 +210,13 @@ func (p *PushJob) doPush(taskType int, isSave bool, wxPush, appPush, mailPush in
|
|
|
}
|
|
|
tip := util.If(TmpTip == "", "", TmpTip+":\n").(string)
|
|
|
lastTip := ""
|
|
|
- if infosLength > 1 {
|
|
|
- lastTip = fmt.Sprintf("...(共%d条)", infosLength)
|
|
|
+ if pushParam.InfosLength > 1 {
|
|
|
+ lastTip = fmt.Sprintf("...(共%d条)", pushParam.InfosLength)
|
|
|
}
|
|
|
LastTipLen := len([]rune(lastTip))
|
|
|
wxTitle := Config.VipWxTitle
|
|
|
- if !isVipUser {
|
|
|
- wxTitleKeys := strings.Join(k.Keys, ";")
|
|
|
+ if !pushParam.IsVipUser {
|
|
|
+ wxTitleKeys := strings.Join(u.Keys, ";")
|
|
|
if len([]rune(wxTitleKeys)) > 8 {
|
|
|
wxTitleKeys = string([]rune(wxTitleKeys)[:8]) + "..."
|
|
|
}
|
|
@@ -341,12 +226,12 @@ func (p *PushJob) doPush(taskType int, isSave bool, wxPush, appPush, mailPush in
|
|
|
reLen := 200 - TitleLen - 10 - WxGroupLen - len([]rune(tip))
|
|
|
wxTplTitle := ""
|
|
|
bshow := false
|
|
|
- for n := 1; n < len(TitleArray)+1; n++ {
|
|
|
- curTitle := TitleArray[n-1]
|
|
|
+ for n := 1; n < len(pushParam.TitleArray)+1; n++ {
|
|
|
+ curTitle := pushParam.TitleArray[n-1]
|
|
|
tmptitle := wxTplTitle + fmt.Sprintf("%d %s\n", n, curTitle)
|
|
|
ch := reLen - len([]rune(tmptitle))
|
|
|
if ch < LastTipLen { //加上后大于后辍,则没有完全显示
|
|
|
- if ch == 0 && n == len(TitleArray) {
|
|
|
+ if ch == 0 && n == len(pushParam.TitleArray) {
|
|
|
wxTplTitle = tmptitle
|
|
|
bshow = true
|
|
|
} else {
|
|
@@ -361,12 +246,12 @@ func (p *PushJob) doPush(taskType int, isSave bool, wxPush, appPush, mailPush in
|
|
|
}
|
|
|
} else if ch == LastTipLen {
|
|
|
wxTplTitle = tmptitle
|
|
|
- if n == len(TitleArray) {
|
|
|
+ if n == len(pushParam.TitleArray) {
|
|
|
bshow = true
|
|
|
}
|
|
|
} else {
|
|
|
wxTplTitle = tmptitle
|
|
|
- if n == len(TitleArray) {
|
|
|
+ if n == len(pushParam.TitleArray) {
|
|
|
bshow = true
|
|
|
}
|
|
|
}
|
|
@@ -375,57 +260,57 @@ func (p *PushJob) doPush(taskType int, isSave bool, wxPush, appPush, mailPush in
|
|
|
lastTip = ""
|
|
|
}
|
|
|
//推送微信
|
|
|
- isPushOk = putil.SendWeixin(k, tip+wxTplTitle+lastTip, wxTitle, pushDate)
|
|
|
+ isPushOk = putil.SendWeixin(u, tip+wxTplTitle+lastTip, wxTitle, pushParam.PushDate)
|
|
|
if isPushOk {
|
|
|
pushResult.WxStatus = 1
|
|
|
} else {
|
|
|
pushResult.WxStatus = -1
|
|
|
}
|
|
|
}
|
|
|
- logger.Info("推送任务", taskType, "微信推送结束", k.ApplyStatus, isPushOk, k.Id)
|
|
|
+ logger.Info("推送任务", taskType, "微信推送结束", u.ApplyStatus, isPushOk, u.Id)
|
|
|
}
|
|
|
if appPush == 1 {
|
|
|
- logger.Info("推送任务", taskType, "开始app推送", k.Id)
|
|
|
+ logger.Info("推送任务", taskType, "开始app推送", u.Id)
|
|
|
descriptAppend := ""
|
|
|
- if infosLength > 1 {
|
|
|
- descriptAppend = fmt.Sprintf("\n...(共%d条)", infosLength)
|
|
|
- jpushtitle = fmt.Sprintf("1. %s", jpushtitle)
|
|
|
+ if pushParam.InfosLength > 1 {
|
|
|
+ descriptAppend = fmt.Sprintf("\n...(共%d条)", pushParam.InfosLength)
|
|
|
+ pushParam.JpushTitle = fmt.Sprintf("1. %s", pushParam.JpushTitle)
|
|
|
}
|
|
|
go mongodb.Update("user", map[string]interface{}{
|
|
|
- "_id": bson.ObjectIdHex(k.Id),
|
|
|
+ "_id": bson.ObjectIdHex(u.Id),
|
|
|
}, map[string]interface{}{
|
|
|
"$inc": map[string]interface{}{
|
|
|
"i_apppushunread": 1,
|
|
|
},
|
|
|
}, false, false)
|
|
|
isPushOk := putil.SendApp(map[string]interface{}{
|
|
|
- "phoneType": k.AppPhoneType,
|
|
|
- "descript": jpushtitle,
|
|
|
+ "phoneType": u.AppPhoneType,
|
|
|
+ "descript": pushParam.JpushTitle,
|
|
|
"descriptAppend": descriptAppend,
|
|
|
"type": "bid",
|
|
|
- "userId": k.Id,
|
|
|
- "url": "/jyapp/free/sess/" + Se.EncodeString(k.Id+",_id,"+strconv.Itoa(int(now.Unix()))+",historypush"),
|
|
|
- "otherPushId": k.Opushid,
|
|
|
- "jgPushId": k.Jpushid, //极光-推送id
|
|
|
+ "userId": u.Id,
|
|
|
+ "url": "/jyapp/free/sess/" + Se.EncodeString(u.Id+",_id,"+strconv.Itoa(int(now.Unix()))+",historypush"),
|
|
|
+ "otherPushId": u.Opushid,
|
|
|
+ "jgPushId": u.Jpushid, //极光-推送id
|
|
|
})
|
|
|
if isPushOk {
|
|
|
pushResult.AppStatus = 1
|
|
|
} else {
|
|
|
pushResult.AppStatus = -1
|
|
|
}
|
|
|
- logger.Info("推送任务", taskType, "app推送结束", isPushOk, k.Id)
|
|
|
+ logger.Info("推送任务", taskType, "app推送结束", isPushOk, u.Id)
|
|
|
}
|
|
|
//发送邮件
|
|
|
if mailPush == 1 {
|
|
|
- logger.Info("推送任务", taskType, "开始邮箱推送", k.Id)
|
|
|
- html := fmt.Sprintf(Config.Mail_html, strings.Replace(strings.Join(k.Keys, ";"), "+", " ", -1), mailContent)
|
|
|
- isPushOk := p.sendMail(k.Email, Config.Mail_title, html, nil)
|
|
|
+ logger.Info("推送任务", taskType, "开始邮箱推送", u.Id)
|
|
|
+ html := fmt.Sprintf(Config.Mail_html, strings.Replace(strings.Join(u.Keys, ";"), "+", " ", -1), pushParam.MailContent)
|
|
|
+ isPushOk := p.sendMail(u.Email, Config.Mail_title, html, nil)
|
|
|
if isPushOk {
|
|
|
pushResult.MailStatus = 1
|
|
|
} else {
|
|
|
pushResult.MailStatus = -1
|
|
|
}
|
|
|
- logger.Info("推送任务", taskType, "邮箱推送结束", isPushOk, k.Id)
|
|
|
+ logger.Info("推送任务", taskType, "邮箱推送结束", isPushOk, u.Id)
|
|
|
}
|
|
|
return
|
|
|
}
|
|
@@ -463,24 +348,3 @@ func (p *PushJob) sendMail(email, subject, html string, fmdatas []map[string]int
|
|
|
}
|
|
|
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)
|
|
|
-}
|