|
@@ -7,11 +7,13 @@ import (
|
|
"math/rand"
|
|
"math/rand"
|
|
"qfw/push"
|
|
"qfw/push"
|
|
"qfw/push/dfa"
|
|
"qfw/push/dfa"
|
|
|
|
+ "qfw/push/listdb"
|
|
"qfw/util"
|
|
"qfw/util"
|
|
"qfw/util/mongodb"
|
|
"qfw/util/mongodb"
|
|
qrpc "qfw/util/rpc"
|
|
qrpc "qfw/util/rpc"
|
|
"regexp"
|
|
"regexp"
|
|
"runtime"
|
|
"runtime"
|
|
|
|
+ "sort"
|
|
"strconv"
|
|
"strconv"
|
|
"strings"
|
|
"strings"
|
|
"time"
|
|
"time"
|
|
@@ -43,7 +45,45 @@ func (b *Pjob) CreateUserInterestWord() {
|
|
b.Dfa.AddWord(words...)
|
|
b.Dfa.AddWord(words...)
|
|
}
|
|
}
|
|
|
|
|
|
-//遍历数据只做标题预览
|
|
|
|
|
|
+type sortList []*map[string]interface{}
|
|
|
|
+
|
|
|
|
+func (s sortList) Len() int {
|
|
|
|
+ return len(s)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (s sortList) Less(i, j int) bool {
|
|
|
|
+ defer func() {
|
|
|
|
+ if r := recover(); r != nil {
|
|
|
|
+ log.Println("[E]", r)
|
|
|
|
+ for skip := 0; ; skip++ {
|
|
|
|
+ _, file, line, ok := runtime.Caller(skip)
|
|
|
|
+ if !ok {
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+ go log.Printf("%v,%v\n", file, line)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }()
|
|
|
|
+ return util.Int64All((*s[i])["publishtime"]) > util.Int64All((*s[j])["publishtime"])
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (s sortList) Swap(i, j int) {
|
|
|
|
+ defer func() {
|
|
|
|
+ if r := recover(); r != nil {
|
|
|
|
+ log.Println("[E]", r)
|
|
|
|
+ for skip := 0; ; skip++ {
|
|
|
|
+ _, file, line, ok := runtime.Caller(skip)
|
|
|
|
+ if !ok {
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+ go log.Printf("%v,%v\n", file, line)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }()
|
|
|
|
+ s[i], s[j] = s[j], s[i]
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+//内存数据推送
|
|
func (p *Pjob) EachInfoForView(mopenid, words string) map[string]interface{} {
|
|
func (p *Pjob) EachInfoForView(mopenid, words string) map[string]interface{} {
|
|
defer func() {
|
|
defer func() {
|
|
if r := recover(); r != nil {
|
|
if r := recover(); r != nil {
|
|
@@ -69,76 +109,59 @@ func (p *Pjob) EachInfoForView(mopenid, words string) map[string]interface{} {
|
|
words: &ss,
|
|
words: &ss,
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- *p.Cache = push.InitCache(p.Stype, mopenid,true)
|
|
|
|
|
|
+ *p.Cache = push.InitCache(p.Stype, mopenid, true)
|
|
}
|
|
}
|
|
p.CreateUserInterestWord()
|
|
p.CreateUserInterestWord()
|
|
- session := mongodb.GetMgoConn()
|
|
|
|
- defer mongodb.DestoryMongoConn(session)
|
|
|
|
- q := `{"type":"` + p.Stype + `"}`
|
|
|
|
- n, _ := session.DB("qfw").C("bidding").Find(mongodb.ObjToOth(q)).Count()
|
|
|
|
- userMap := &map[*push.MemberInterest]*list.List{}
|
|
|
|
- if n == 0 {
|
|
|
|
- log.Println("预览", p.Stype, "没有数据。")
|
|
|
|
- } else {
|
|
|
|
- query := session.DB("qfw").C("bidding").Find(mongodb.ObjToOth(q)).Sort("-publishtime").Iter()
|
|
|
|
- var returnLastTimeLong int64 = 0
|
|
|
|
- L1:
|
|
|
|
- for tmp := new(map[string]interface{}); query.Next(tmp); {
|
|
|
|
- title := util.ObjToString((*tmp)["title"])
|
|
|
|
- if title != "" {
|
|
|
|
- //返回匹配到的词组
|
|
|
|
- res := p.Dfa.Analy(title)
|
|
|
|
- if len(res) > 0 {
|
|
|
|
- province := (*tmp)["area"].(string)
|
|
|
|
-
|
|
|
|
- provinceVal := push.GetChoiceCode(province)
|
|
|
|
- if "A" != province {
|
|
|
|
- (*tmp)["title"] = `[<span class='area'>` + province + `</span>]` + title
|
|
|
|
- }
|
|
|
|
- for _, v := range res {
|
|
|
|
- //根据关键词返回用户指针
|
|
|
|
- tw := (*p.Cache)[v]
|
|
|
|
- if tw != nil {
|
|
|
|
- //遍历用户加入到此条信息上
|
|
|
|
- for _, v2 := range *tw {
|
|
|
|
- if v2.Province == "A" || v2.ProvinceVal&provinceVal > 0 {
|
|
|
|
- s := (*userMap)[v2]
|
|
|
|
- if s == nil {
|
|
|
|
- s = list.New()
|
|
|
|
- (*userMap)[v2] = s
|
|
|
|
- }
|
|
|
|
- s.PushBack(tmp)
|
|
|
|
- if s.Len() > 50 {
|
|
|
|
- break L1
|
|
|
|
- }
|
|
|
|
|
|
+ userMap := &map[*push.MemberInterest]sortList{}
|
|
|
|
+ LDB := listdb.GetDb(p.Stype)
|
|
|
|
+ LDB.Lock.Lock()
|
|
|
|
+L1:
|
|
|
|
+ for e := LDB.DB.Back(); e != nil; e = e.Prev() {
|
|
|
|
+ tmp := e.Value.(*map[string]interface{})
|
|
|
|
+ title := util.ObjToString((*tmp)["title"])
|
|
|
|
+ if title != "" {
|
|
|
|
+ //返回匹配到的词组
|
|
|
|
+ res := p.Dfa.Analy(title)
|
|
|
|
+ if len(res) > 0 {
|
|
|
|
+ province := (*tmp)["area"].(string)
|
|
|
|
+ provinceVal := push.GetChoiceCode(province)
|
|
|
|
+ for _, v := range res {
|
|
|
|
+ //根据关键词返回用户指针
|
|
|
|
+ tw := (*p.Cache)[v]
|
|
|
|
+ if tw != nil {
|
|
|
|
+ //遍历用户加入到此条信息上
|
|
|
|
+ for _, v2 := range *tw {
|
|
|
|
+ if v2.Province == "A" || v2.ProvinceVal&provinceVal > 0 {
|
|
|
|
+ s := (*userMap)[v2]
|
|
|
|
+ if s == nil {
|
|
|
|
+ s = sortList{}
|
|
|
|
+ }
|
|
|
|
+ s = append(s, tmp)
|
|
|
|
+ (*userMap)[v2] = s
|
|
|
|
+ if len(s) > 50 {
|
|
|
|
+ break L1
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if (*tmp)["comeintime"] != nil {
|
|
|
|
- ttmp := (*tmp)["comeintime"].(int64)
|
|
|
|
- if ttmp > returnLastTimeLong {
|
|
|
|
- returnLastTimeLong = ttmp
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
- tmp = new(map[string]interface{})
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ LDB.Lock.Unlock()
|
|
mcontent := map[string]interface{}{}
|
|
mcontent := map[string]interface{}{}
|
|
mcontent["s_type"] = p.Stype
|
|
mcontent["s_type"] = p.Stype
|
|
bmatch := false
|
|
bmatch := false
|
|
- for kk, vv := range *(userMap) {
|
|
|
|
|
|
+ for kk, v := range *(userMap) {
|
|
k := *kk
|
|
k := *kk
|
|
- v := *vv
|
|
|
|
str := fmt.Sprintf("<div>根据您设置的关键词(%s),给您推送以下"+p.StypeName+"信息:</div>", strings.Join(k.Interest, ";"))
|
|
str := fmt.Sprintf("<div>根据您设置的关键词(%s),给您推送以下"+p.StypeName+"信息:</div>", strings.Join(k.Interest, ";"))
|
|
//发送内容组合
|
|
//发送内容组合
|
|
i := 0
|
|
i := 0
|
|
publishTimes := map[string]interface{}{}
|
|
publishTimes := map[string]interface{}{}
|
|
publishTitle := map[string]bool{}
|
|
publishTitle := map[string]bool{}
|
|
- for ks := v.Front(); ks != nil; ks = ks.Next() {
|
|
|
|
- k2 := *(ks.Value.(*map[string]interface{}))
|
|
|
|
|
|
+ sort.Sort(v)
|
|
|
|
+ for _, kn := range v {
|
|
|
|
+ k2 := *kn
|
|
title := strings.Replace(k2["title"].(string), "\n", "", -1)
|
|
title := strings.Replace(k2["title"].(string), "\n", "", -1)
|
|
if !publishTitle[title] {
|
|
if !publishTitle[title] {
|
|
publishTitle[title] = true
|
|
publishTitle[title] = true
|
|
@@ -164,14 +187,13 @@ func (p *Pjob) EachInfoForView(mopenid, words string) map[string]interface{} {
|
|
break
|
|
break
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
return mcontent
|
|
return mcontent
|
|
}
|
|
}
|
|
|
|
|
|
func (p *Pjob) DoPush(mopenid, stime string, opr int, ltime int64) bool {
|
|
func (p *Pjob) DoPush(mopenid, stime string, opr int, ltime int64) bool {
|
|
log.Println("开始执行任务:", p.StypeName, stime)
|
|
log.Println("开始执行任务:", p.StypeName, stime)
|
|
p.Cache = new(map[string]*[]*push.MemberInterest)
|
|
p.Cache = new(map[string]*[]*push.MemberInterest)
|
|
- *p.Cache = push.InitCache(p.Stype, mopenid,false)
|
|
|
|
|
|
+ *p.Cache = push.InitCache(p.Stype, mopenid, false)
|
|
p.CreateUserInterestWord()
|
|
p.CreateUserInterestWord()
|
|
return EachAllBidInfo(p.Stype, "["+p.StypeName+"信息]", p.StypeName, ltime, p.MaxPushSize, p.Dfa, p.Cache, opr)
|
|
return EachAllBidInfo(p.Stype, "["+p.StypeName+"信息]", p.StypeName, ltime, p.MaxPushSize, p.Dfa, p.Cache, opr)
|
|
}
|
|
}
|
|
@@ -367,3 +389,130 @@ func SendWeixin(k *push.MemberInterest, TITLE, ShortTitle, str, stype string, no
|
|
Url: push.PushConfig["bidViewDomain"].(string) + "/mobile/sess/" + se.EncodeString(k.Openid+",uid,"+strconv.Itoa(int(time.Now().Unix()))+",wxpushlist") + "__" + wid})
|
|
Url: push.PushConfig["bidViewDomain"].(string) + "/mobile/sess/" + se.EncodeString(k.Openid+",uid,"+strconv.Itoa(int(time.Now().Unix()))+",wxpushlist") + "__" + wid})
|
|
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+//遍历数据只做标题预览
|
|
|
|
+func (p *Pjob) EachInfoForViewOld(mopenid, words string) map[string]interface{} {
|
|
|
|
+ defer func() {
|
|
|
|
+ if r := recover(); r != nil {
|
|
|
|
+ log.Println("[E]", r)
|
|
|
|
+ for skip := 0; ; skip++ {
|
|
|
|
+ _, file, line, ok := runtime.Caller(skip)
|
|
|
|
+ if !ok {
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+ go log.Printf("%v,%v\n", file, line)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }()
|
|
|
|
+ p.Cache = new(map[string]*[]*push.MemberInterest)
|
|
|
|
+ if words != "" {
|
|
|
|
+ pm := push.MemberInterest{
|
|
|
|
+ Province: "A",
|
|
|
|
+ ProvinceVal: 0,
|
|
|
|
+ Interest: []string{words},
|
|
|
|
+ }
|
|
|
|
+ ss := []*push.MemberInterest{&pm}
|
|
|
|
+ *p.Cache = map[string]*[]*push.MemberInterest{
|
|
|
|
+ words: &ss,
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ *p.Cache = push.InitCache(p.Stype, mopenid,true)
|
|
|
|
+ }
|
|
|
|
+ p.CreateUserInterestWord()
|
|
|
|
+ session := mongodb.GetMgoConn()
|
|
|
|
+ defer mongodb.DestoryMongoConn(session)
|
|
|
|
+ q := `{"type":"` + p.Stype + `"}`
|
|
|
|
+ n, _ := session.DB("qfw").C("bidding").Find(mongodb.ObjToOth(q)).Count()
|
|
|
|
+ userMap := &map[*push.MemberInterest]*list.List{}
|
|
|
|
+ if n == 0 {
|
|
|
|
+ log.Println("预览", p.Stype, "没有数据。")
|
|
|
|
+ } else {
|
|
|
|
+ query := session.DB("qfw").C("bidding").Find(mongodb.ObjToOth(q)).Sort("-publishtime").Iter()
|
|
|
|
+ var returnLastTimeLong int64 = 0
|
|
|
|
+ L1:
|
|
|
|
+ for tmp := new(map[string]interface{}); query.Next(tmp); {
|
|
|
|
+ title := util.ObjToString((*tmp)["title"])
|
|
|
|
+ if title != "" {
|
|
|
|
+ //返回匹配到的词组
|
|
|
|
+ res := p.Dfa.Analy(title)
|
|
|
|
+ if len(res) > 0 {
|
|
|
|
+ province := (*tmp)["area"].(string)
|
|
|
|
+
|
|
|
|
+ provinceVal := push.GetChoiceCode(province)
|
|
|
|
+ if "A" != province {
|
|
|
|
+ (*tmp)["title"] = `[<span class='area'>` + province + `</span>]` + title
|
|
|
|
+ }
|
|
|
|
+ for _, v := range res {
|
|
|
|
+ //根据关键词返回用户指针
|
|
|
|
+ tw := (*p.Cache)[v]
|
|
|
|
+ if tw != nil {
|
|
|
|
+ //遍历用户加入到此条信息上
|
|
|
|
+ for _, v2 := range *tw {
|
|
|
|
+ if v2.Province == "A" || v2.ProvinceVal&provinceVal > 0 {
|
|
|
|
+ s := (*userMap)[v2]
|
|
|
|
+ if s == nil {
|
|
|
|
+ s = list.New()
|
|
|
|
+ (*userMap)[v2] = s
|
|
|
|
+ }
|
|
|
|
+ s.PushBack(tmp)
|
|
|
|
+ if s.Len() > 50 {
|
|
|
|
+ break L1
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (*tmp)["comeintime"] != nil {
|
|
|
|
+ ttmp := (*tmp)["comeintime"].(int64)
|
|
|
|
+ if ttmp > returnLastTimeLong {
|
|
|
|
+ returnLastTimeLong = ttmp
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ tmp = new(map[string]interface{})
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ mcontent := map[string]interface{}{}
|
|
|
|
+ mcontent["s_type"] = p.Stype
|
|
|
|
+ bmatch := false
|
|
|
|
+ for kk, vv := range *(userMap) {
|
|
|
|
+ k := *kk
|
|
|
|
+ v := *vv
|
|
|
|
+ str := fmt.Sprintf("<div>根据您设置的关键词(%s),给您推送以下"+p.StypeName+"信息:</div>", strings.Join(k.Interest, ";"))
|
|
|
|
+ //发送内容组合
|
|
|
|
+ i := 0
|
|
|
|
+ publishTimes := map[string]interface{}{}
|
|
|
|
+ publishTitle := map[string]bool{}
|
|
|
|
+ for ks := v.Front(); ks != nil; ks = ks.Next() {
|
|
|
|
+ k2 := *(ks.Value.(*map[string]interface{}))
|
|
|
|
+ title := strings.Replace(k2["title"].(string), "\n", "", -1)
|
|
|
|
+ if !publishTitle[title] {
|
|
|
|
+ publishTitle[title] = true
|
|
|
|
+ i++
|
|
|
|
+ str += "<div class='tslist'><span class='xh'>" + fmt.Sprintf("%d", i) + ".</span><a class='bt' target='_blank' sid='" + util.BsonIdToSId(k2["_id"]) + "' href='" + k2["href"].(string) + "'>" + title + "</a></div>"
|
|
|
|
+ publishTimes[strconv.Itoa(i)] = k2["publishtime"]
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if len(publishTimes) > 0 {
|
|
|
|
+ bmatch = true
|
|
|
|
+ mcontent["a_publishtime"] = publishTimes
|
|
|
|
+ mcontent["s_content"] = str
|
|
|
|
+ mcontent["s_words"] = k.Interest
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ mcontent["bmatch"] = bmatch
|
|
|
|
+ if !bmatch {
|
|
|
|
+ for _, one := range *p.Cache {
|
|
|
|
+ for _, onep := range *one {
|
|
|
|
+ mcontent["s_words"] = onep.Interest
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return mcontent
|
|
|
|
+}
|
|
|
|
+**/
|