|
@@ -11,6 +11,7 @@ import (
|
|
|
"qfw/util/mongodb"
|
|
|
"qfw/util/redis"
|
|
|
qrpc "qfw/util/rpc"
|
|
|
+ "regexp"
|
|
|
"rpccall"
|
|
|
"sort"
|
|
|
"strconv"
|
|
@@ -34,14 +35,15 @@ var (
|
|
|
DB = "bidding"
|
|
|
KEEPCOUNT = 100
|
|
|
MaxSearch = 10000 //缓存中总共加载这么多条
|
|
|
- searchpool = make(chan bool, 8)
|
|
|
- pushpool = make(chan bool, 50)
|
|
|
+ PushPool chan bool
|
|
|
+ EachPool chan bool
|
|
|
findpool = make(chan bool, 10)
|
|
|
- eachpool = make(chan bool, 100)
|
|
|
- Pushlock = sync.Mutex{}
|
|
|
+ lock = &sync.Mutex{}
|
|
|
+ pushWaitGroup = &sync.WaitGroup{}
|
|
|
searchWaitGroup = &sync.WaitGroup{}
|
|
|
eachInfoWaitGroup = &sync.WaitGroup{}
|
|
|
Mongodb_ShowField = `{"_id":1,"title":1,"publishtime":1,"area":1,"type":1,"toptype":1,"subtype":1,"projectname":1,"projectcode":1,"href":1,"infoformat":1,"s_subscopeclass":1}`
|
|
|
+ reg = regexp.MustCompile(`\\+"`)
|
|
|
)
|
|
|
|
|
|
type PushUser struct {
|
|
@@ -91,6 +93,7 @@ func pushByEs(_id string, lastTime int64) bool {
|
|
|
"_id": 1,
|
|
|
}).Iter()
|
|
|
users := []*PushUser{}
|
|
|
+ user_index := 0
|
|
|
for tmp := make(map[string]interface{}); cur.Next(tmp); {
|
|
|
scode := util.ObjToString(tmp["s_projectcode"])
|
|
|
sname := util.ObjToString(tmp["s_projectname"])
|
|
@@ -106,7 +109,12 @@ func pushByEs(_id string, lastTime int64) bool {
|
|
|
ProjectName: sname,
|
|
|
})
|
|
|
tmp = make(map[string]interface{})
|
|
|
+ user_index++
|
|
|
+ if user_index%500 == 0 {
|
|
|
+ log.Println("加载用户:", user_index)
|
|
|
+ }
|
|
|
}
|
|
|
+ log.Println("加载用户完成", user_index)
|
|
|
if len(users) == 0 {
|
|
|
log.Println("未查找到需要推送的用户...")
|
|
|
return false
|
|
@@ -120,14 +128,17 @@ func pushByEs(_id string, lastTime int64) bool {
|
|
|
userMap := EachAllBidInfo(&users, res)
|
|
|
//遍历用户,推送
|
|
|
for k, v := range *userMap {
|
|
|
- pushpool <- true
|
|
|
- func(tmp *[]map[string]interface{}) {
|
|
|
+ PushPool <- true
|
|
|
+ pushWaitGroup.Add(1)
|
|
|
+ go func(pushUser *PushUser, tmp *[]map[string]interface{}) {
|
|
|
defer func() {
|
|
|
- <-pushpool
|
|
|
+ <-PushPool
|
|
|
+ pushWaitGroup.Done()
|
|
|
}()
|
|
|
- push(k.Id, k.ProjectName, k.ProjectCode, k.Title, k.UserId, v, true, true)
|
|
|
- }(v)
|
|
|
+ push(pushUser.Id, pushUser.ProjectName, pushUser.ProjectCode, pushUser.Title, pushUser.UserId, tmp, true, true)
|
|
|
+ }(k, v)
|
|
|
}
|
|
|
+ pushWaitGroup.Wait()
|
|
|
Sysconfig["StartTime"] = util.FormatDateWithObj(&comeintime, util.Date_Full_Layout)
|
|
|
Sysconfig["lastid"] = lastid
|
|
|
log.Println("push-over", lastid, comeintime)
|
|
@@ -139,13 +150,13 @@ func EachAllBidInfo(users *[]*PushUser, res *[]map[string]interface{}) *map[*Pus
|
|
|
var count int
|
|
|
userMap := map[*PushUser]*[]map[string]interface{}{}
|
|
|
for _, v := range *res {
|
|
|
- eachpool <- true
|
|
|
+ EachPool <- true
|
|
|
eachInfoWaitGroup.Add(1)
|
|
|
count++
|
|
|
func(tmp map[string]interface{}) {
|
|
|
defer func() {
|
|
|
eachInfoWaitGroup.Done()
|
|
|
- <-eachpool
|
|
|
+ <-EachPool
|
|
|
}()
|
|
|
scode := util.ObjToString(tmp["projectcode"])
|
|
|
sname := util.ObjToString(tmp["projectname"])
|
|
@@ -160,23 +171,24 @@ func EachAllBidInfo(users *[]*PushUser, res *[]map[string]interface{}) *map[*Pus
|
|
|
if !flag {
|
|
|
continue
|
|
|
}
|
|
|
+ lock.Lock()
|
|
|
s := userMap[user]
|
|
|
if s == nil {
|
|
|
s = &[]map[string]interface{}{}
|
|
|
userMap[user] = s
|
|
|
}
|
|
|
- *s = append(*s, tmp)
|
|
|
- if len(*s) >= 50 {
|
|
|
- break
|
|
|
+ if len(*s) < 50 {
|
|
|
+ *s = append(*s, tmp)
|
|
|
}
|
|
|
+ lock.Unlock()
|
|
|
}
|
|
|
}(v)
|
|
|
if count%500 == 0 {
|
|
|
- log.Println("当前信息索引:", count)
|
|
|
+ log.Println("当前匹配:", count)
|
|
|
}
|
|
|
}
|
|
|
eachInfoWaitGroup.Wait()
|
|
|
- log.Println("数据遍历完成!")
|
|
|
+ log.Println("匹配结束", count)
|
|
|
return &userMap
|
|
|
}
|
|
|
|
|
@@ -226,70 +238,10 @@ func InitBiddingCache(_id, lastid string, lastTime int64) (bool, *[]map[string]i
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
- log.Println(count, "条数据已经加载完成!")
|
|
|
+ log.Println("数据加载结束", count)
|
|
|
return true, &res
|
|
|
}
|
|
|
|
|
|
-/*func InitBiddingCache(_id, lastid string, lastTime int64) (bool, *[]map[string]interface{}) {
|
|
|
- defer util.Catch()
|
|
|
- //filter全局查询
|
|
|
- c_query := fmt.Sprintf(FilterQuery, fmt.Sprintf(IDRange, _id, lastid, lastTime-7*86400))
|
|
|
- log.Println("es query:", c_query)
|
|
|
- //testquery := `{"terms":{"_id":["59cefaa12cf26913ca07fd56"]}}`
|
|
|
- //testquery := ``
|
|
|
- //c_query = fmt.Sprintf(FilterQuery, testquery)
|
|
|
- var res []map[string]interface{}
|
|
|
- count := int(elastic.Count(DB, DB, c_query))
|
|
|
- log.Println("本次推送共查到数据", count, "条")
|
|
|
- if count == 0 {
|
|
|
- return false, &res
|
|
|
- }
|
|
|
- if count > MaxSearch {
|
|
|
- count = MaxSearch
|
|
|
- log.Println("目前数据多于", MaxSearch, ",只加载了", MaxSearch, "条!")
|
|
|
- }
|
|
|
- onceSize := 400 //ES一次查询这么多条
|
|
|
- if onceSize > count {
|
|
|
- onceSize = count
|
|
|
- }
|
|
|
- totalPage := int((count + onceSize - 1) / onceSize)
|
|
|
- log.Println("数据一共", totalPage, "页!")
|
|
|
- //如果res长度和cout相差5条,重试
|
|
|
- for t := 1; t <= 3; t++ {
|
|
|
- res = []map[string]interface{}{}
|
|
|
- for i := 0; i < totalPage; i++ {
|
|
|
- searchpool <- true
|
|
|
- searchWaitGroup.Add(1)
|
|
|
- go func(start int) {
|
|
|
- defer func() {
|
|
|
- searchWaitGroup.Done()
|
|
|
- <-searchpool
|
|
|
- }()
|
|
|
- size := onceSize
|
|
|
- if start == totalPage-1 && count%onceSize != 0 {
|
|
|
- size = count % onceSize
|
|
|
- }
|
|
|
- r := elastic.GetAllByNgram(DB, DB, c_query, "", SortQuery, ShowField, start*onceSize, size, 0, false)
|
|
|
- if r != nil {
|
|
|
- res = append(res, *r...)
|
|
|
- log.Println("第", start+1, "页数据加载完成!")
|
|
|
- }
|
|
|
- }(i)
|
|
|
- }
|
|
|
- searchWaitGroup.Wait()
|
|
|
- if len(res) >= count-5 {
|
|
|
- break
|
|
|
- }
|
|
|
- log.Println("第", t, "次加载数据完成,数据总数", len(res), ",由于数据量不够,重新加载!")
|
|
|
- }
|
|
|
- resLenght := len(res)
|
|
|
- if resLenght == 0 {
|
|
|
- return false, &res
|
|
|
- }
|
|
|
- log.Println(resLenght, "条数据已经加载完成!")
|
|
|
- return true, &res
|
|
|
-}*/
|
|
|
-
|
|
|
//不保存不推送-只保存不推送-保存推送
|
|
|
func FindData(fid interface{}, title, sname, scode, userid, idrange string, bsave, bpush bool) *Arr {
|
|
|
findpool <- true
|
|
@@ -301,7 +253,8 @@ func FindData(fid interface{}, title, sname, scode, userid, idrange string, bsav
|
|
|
q1 = append(q1, fmt.Sprintf(TERM, "projectcode", strings.Replace(scode, "\\", "\\\\", -1)))
|
|
|
}
|
|
|
if sname != "" {
|
|
|
- newSname := elastic.ReplaceYH(sname)
|
|
|
+ newSname := reg.ReplaceAllString(sname, `"`)
|
|
|
+ newSname = elastic.ReplaceYH(newSname)
|
|
|
newSname = strings.Replace(newSname, "\\", "\\\\", -1)
|
|
|
q1 = append(q1, fmt.Sprintf(TERM, "projectname", newSname))
|
|
|
}
|
|
@@ -318,44 +271,18 @@ func FindData(fid interface{}, title, sname, scode, userid, idrange string, bsav
|
|
|
|
|
|
//开始推送
|
|
|
func push(fid interface{}, sname, scode, title, userId string, res *[]map[string]interface{}, bsave, bpush bool) *Arr {
|
|
|
+ defer util.Catch()
|
|
|
var pushArray = &Arr{}
|
|
|
- util.Try(func() {
|
|
|
- if !bsave {
|
|
|
- for _, info := range *res {
|
|
|
- tmp := map[string]interface{}{}
|
|
|
- sid := util.BsonIdToSId(info["_id"])
|
|
|
- if title != sid { //title在此处传的是关注信息id
|
|
|
- tmp["s_id"] = sid
|
|
|
- tmp["s_eid"] = util.EncodeArticleId2ByCheck(sid)
|
|
|
- tmp["s_title"] = info["title"]
|
|
|
- tmp["l_publishtime"] = info["publishtime"]
|
|
|
- area := util.ObjToString(info["area"])
|
|
|
- if area == "A" {
|
|
|
- area = "全国"
|
|
|
- }
|
|
|
- tmp["s_province"] = area
|
|
|
- tmp["s_type"] = util.ObjToString(info["type"])
|
|
|
- tmp["s_toptype"] = util.ObjToString(info["toptype"])
|
|
|
- tmp["s_subtype"] = util.ObjToString(info["subtype"])
|
|
|
- tmp["s_projectname"] = util.ObjToString(info["projectname"])
|
|
|
- tmp["s_projectcode"] = util.ObjToString(info["projectcode"])
|
|
|
- tmp["s_url"] = util.ObjToString(info["href"])
|
|
|
- tmp["s_subscopeclass"] = util.ObjToString(info["s_subscopeclass"])
|
|
|
- *pushArray = append(*pushArray, &tmp)
|
|
|
- }
|
|
|
+ titleMap := map[string]bool{}
|
|
|
+ if !bsave {
|
|
|
+ for _, info := range *res {
|
|
|
+ if titleMap[util.ObjToString(info["title"])] {
|
|
|
+ continue
|
|
|
}
|
|
|
- } else {
|
|
|
- Pushlock.Lock()
|
|
|
- defer Pushlock.Unlock()
|
|
|
- //1.组织信息、
|
|
|
- //a_relationinfo s_id s_title s_projectname s_projectcode l_publishtime s_url
|
|
|
- var ids []string
|
|
|
- for _, info := range *res {
|
|
|
- sid := util.BsonIdToSId(info["_id"])
|
|
|
- if title == sid && !bpush {
|
|
|
- continue
|
|
|
- }
|
|
|
- tmp := map[string]interface{}{}
|
|
|
+ titleMap[util.ObjToString(info["title"])] = true
|
|
|
+ tmp := map[string]interface{}{}
|
|
|
+ sid := util.BsonIdToSId(info["_id"])
|
|
|
+ if title != sid { //title在此处传的是关注信息id
|
|
|
tmp["s_id"] = sid
|
|
|
tmp["s_eid"] = util.EncodeArticleId2ByCheck(sid)
|
|
|
tmp["s_title"] = info["title"]
|
|
@@ -372,195 +299,222 @@ func push(fid interface{}, sname, scode, title, userId string, res *[]map[string
|
|
|
tmp["s_projectcode"] = util.ObjToString(info["projectcode"])
|
|
|
tmp["s_url"] = util.ObjToString(info["href"])
|
|
|
tmp["s_subscopeclass"] = util.ObjToString(info["s_subscopeclass"])
|
|
|
- if exists, _ := redis.Exists("push", "push_"+userId+"_"+sid); exists {
|
|
|
- continue
|
|
|
- } else {
|
|
|
- redis.PutCKV("push", "push_"+userId+"_"+sid, 1)
|
|
|
- }
|
|
|
- ids = append(ids, sid)
|
|
|
*pushArray = append(*pushArray, &tmp)
|
|
|
}
|
|
|
- go func() {
|
|
|
- //2.推送、
|
|
|
- if pushArray.Len() > 0 {
|
|
|
- sort.Sort(pushArray)
|
|
|
- //更新用户关注的a_relationinfo、保存到推送记录表、推送给用户
|
|
|
- //log.Println(fid, ids)
|
|
|
- //项目公告保留包括本身在内的最新100条
|
|
|
- updateFlag := false
|
|
|
- if fid != nil {
|
|
|
- followObject, fok := tools.MQFW.FindOneByField(FOLLOW_COLLECTION, &bson.M{"_id": fid}, `{"l_publishtime":1,"a_relationinfo":1,"s_id":1}`)
|
|
|
- if fok && followObject != nil && len(*followObject) > 0 {
|
|
|
- relationinfo, _ := (*followObject)["a_relationinfo"].([]interface{})
|
|
|
- s_id, _ := (*followObject)["s_id"].(string)
|
|
|
- rLength := len(relationinfo)
|
|
|
- pLength := pushArray.Len()
|
|
|
- setMap := bson.M{"a_lastpushids": ids}
|
|
|
- if bpush {
|
|
|
- setMap["l_lastpushtime"] = (*((*pushArray)[0]))["l_publishtime"]
|
|
|
- setMap["i_apppushunread"] = 1
|
|
|
- } else {
|
|
|
- setMap["l_lastpushtime"] = (*followObject)["l_publishtime"]
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //1.组织信息、
|
|
|
+ //a_relationinfo s_id s_title s_projectname s_projectcode l_publishtime s_url
|
|
|
+ var ids []string
|
|
|
+ for _, info := range *res {
|
|
|
+ if titleMap[util.ObjToString(info["title"])] {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ titleMap[util.ObjToString(info["title"])] = true
|
|
|
+ sid := util.BsonIdToSId(info["_id"])
|
|
|
+ if title == sid && !bpush {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ tmp := map[string]interface{}{}
|
|
|
+ tmp["s_id"] = sid
|
|
|
+ tmp["s_eid"] = util.EncodeArticleId2ByCheck(sid)
|
|
|
+ tmp["s_title"] = info["title"]
|
|
|
+ tmp["l_publishtime"] = info["publishtime"]
|
|
|
+ area := util.ObjToString(info["area"])
|
|
|
+ if area == "A" {
|
|
|
+ area = "全国"
|
|
|
+ }
|
|
|
+ tmp["s_province"] = area
|
|
|
+ tmp["s_type"] = util.ObjToString(info["type"])
|
|
|
+ tmp["s_toptype"] = util.ObjToString(info["toptype"])
|
|
|
+ tmp["s_subtype"] = util.ObjToString(info["subtype"])
|
|
|
+ tmp["s_projectname"] = util.ObjToString(info["projectname"])
|
|
|
+ tmp["s_projectcode"] = util.ObjToString(info["projectcode"])
|
|
|
+ tmp["s_url"] = util.ObjToString(info["href"])
|
|
|
+ tmp["s_subscopeclass"] = util.ObjToString(info["s_subscopeclass"])
|
|
|
+ if exists, _ := redis.Exists("push", "push_"+userId+"_"+sid); exists {
|
|
|
+ continue
|
|
|
+ } else {
|
|
|
+ redis.PutCKV("push", "push_"+userId+"_"+sid, 1)
|
|
|
+ }
|
|
|
+ ids = append(ids, sid)
|
|
|
+ *pushArray = append(*pushArray, &tmp)
|
|
|
+ }
|
|
|
+ //2.推送、
|
|
|
+ if pushArray.Len() > 0 {
|
|
|
+ sort.Sort(pushArray)
|
|
|
+ //更新用户关注的a_relationinfo、保存到推送记录表、推送给用户
|
|
|
+ //log.Println(fid, ids)
|
|
|
+ //项目公告保留包括本身在内的最新100条
|
|
|
+ updateFlag := false
|
|
|
+ if fid != nil {
|
|
|
+ followObject, fok := tools.MQFW.FindOneByField(FOLLOW_COLLECTION, &bson.M{"_id": fid}, `{"l_publishtime":1,"a_relationinfo":1,"s_id":1}`)
|
|
|
+ if fok && followObject != nil && len(*followObject) > 0 {
|
|
|
+ relationinfo, _ := (*followObject)["a_relationinfo"].([]interface{})
|
|
|
+ s_id, _ := (*followObject)["s_id"].(string)
|
|
|
+ rLength := len(relationinfo)
|
|
|
+ pLength := pushArray.Len()
|
|
|
+ setMap := bson.M{"a_lastpushids": ids}
|
|
|
+ if bpush {
|
|
|
+ setMap["l_lastpushtime"] = (*((*pushArray)[0]))["l_publishtime"]
|
|
|
+ setMap["i_apppushunread"] = 1
|
|
|
+ } else {
|
|
|
+ setMap["l_lastpushtime"] = (*followObject)["l_publishtime"]
|
|
|
+ }
|
|
|
+ updateMap := &bson.M{"$set": setMap}
|
|
|
+ if rLength > 0 && rLength+pLength > KEEPCOUNT { //保留100条
|
|
|
+ start := rLength + pLength - KEEPCOUNT
|
|
|
+ firstInfo, _ := relationinfo[0].(map[string]interface{})
|
|
|
+ firstInfoId, _ := firstInfo["s_id"].(string)
|
|
|
+ var relationinfoTemp []interface{}
|
|
|
+ //保留本身
|
|
|
+ if s_id == firstInfoId && !bpush {
|
|
|
+ relationinfoTemp = relationinfo[:1]
|
|
|
+ if start+1 < rLength {
|
|
|
+ relationinfoTemp = append(relationinfoTemp, relationinfo[start+1:]...)
|
|
|
}
|
|
|
- updateMap := &bson.M{"$set": setMap}
|
|
|
- if rLength > 0 && rLength+pLength > KEEPCOUNT { //保留100条
|
|
|
- start := rLength + pLength - KEEPCOUNT
|
|
|
- firstInfo, _ := relationinfo[0].(map[string]interface{})
|
|
|
- firstInfoId, _ := firstInfo["s_id"].(string)
|
|
|
- var relationinfoTemp []interface{}
|
|
|
- //保留本身
|
|
|
- if s_id == firstInfoId && !bpush {
|
|
|
- relationinfoTemp = relationinfo[:1]
|
|
|
- if start+1 < rLength {
|
|
|
- relationinfoTemp = append(relationinfoTemp, relationinfo[start+1:]...)
|
|
|
- }
|
|
|
- } else {
|
|
|
- if start < rLength {
|
|
|
- relationinfoTemp = append(relationinfoTemp, relationinfo[start:]...)
|
|
|
- }
|
|
|
- }
|
|
|
- for _, v := range *pushArray {
|
|
|
- relationinfoTemp = append(relationinfoTemp, v)
|
|
|
- }
|
|
|
- setMap["a_relationinfo"] = relationinfoTemp
|
|
|
- } else { //追加
|
|
|
- (*updateMap)["$pushAll"] = bson.M{"a_relationinfo": pushArray}
|
|
|
+ } else {
|
|
|
+ if start < rLength {
|
|
|
+ relationinfoTemp = append(relationinfoTemp, relationinfo[start:]...)
|
|
|
}
|
|
|
- updateFlag = tools.MQFW.Update(FOLLOW_COLLECTION, &bson.M{"_id": fid}, updateMap, false, false)
|
|
|
}
|
|
|
- }
|
|
|
- if updateFlag && bpush {
|
|
|
- userdata, userdata_ok := tools.MQFW.FindById("user", userId, `{"s_m_openid":1,"a_m_openid":1,"s_phone":1,"s_jpushid":1,"s_opushid":1,"s_appponetype":1,"i_applystatus":1,"i_ispush":1,"i_type":1,"a_mergeorder":1}`)
|
|
|
- if !userdata_ok || userdata == nil {
|
|
|
- return
|
|
|
+ for _, v := range *pushArray {
|
|
|
+ relationinfoTemp = append(relationinfoTemp, v)
|
|
|
}
|
|
|
- s_m_openid, _ := (*userdata)["s_m_openid"].(string)
|
|
|
- a_m_openid, _ := (*userdata)["a_m_openid"].(string)
|
|
|
- s_phone, _ := (*userdata)["s_phone"].(string)
|
|
|
- jpushid, _ := (*userdata)["s_jpushid"].(string)
|
|
|
- opushid, _ := (*userdata)["s_opushid"].(string)
|
|
|
- phoneType, _ := (*userdata)["s_appponetype"].(string)
|
|
|
- isPushWx := util.IntAllDef((*userdata)["i_ispush"], 1)
|
|
|
- applystatus := util.IntAll((*userdata)["i_applystatus"])
|
|
|
- a_mergeorder, _ := (*userdata)["a_mergeorder"].([]interface{})
|
|
|
- //进入推送逻辑
|
|
|
- tit := sname
|
|
|
- if tit == "" {
|
|
|
- tit = title
|
|
|
+ setMap["a_relationinfo"] = relationinfoTemp
|
|
|
+ } else { //追加
|
|
|
+ (*updateMap)["$pushAll"] = bson.M{"a_relationinfo": pushArray}
|
|
|
+ }
|
|
|
+ updateFlag = tools.MQFW.Update(FOLLOW_COLLECTION, &bson.M{"_id": fid}, updateMap, false, false)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if updateFlag && bpush {
|
|
|
+ userdata, userdata_ok := tools.MQFW.FindById("user", userId, `{"s_m_openid":1,"a_m_openid":1,"s_phone":1,"s_jpushid":1,"s_opushid":1,"s_appponetype":1,"i_applystatus":1,"i_ispush":1,"i_type":1,"a_mergeorder":1}`)
|
|
|
+ if !userdata_ok || userdata == nil {
|
|
|
+ return pushArray
|
|
|
+ }
|
|
|
+ s_m_openid, _ := (*userdata)["s_m_openid"].(string)
|
|
|
+ a_m_openid, _ := (*userdata)["a_m_openid"].(string)
|
|
|
+ s_phone, _ := (*userdata)["s_phone"].(string)
|
|
|
+ jpushid, _ := (*userdata)["s_jpushid"].(string)
|
|
|
+ opushid, _ := (*userdata)["s_opushid"].(string)
|
|
|
+ phoneType, _ := (*userdata)["s_appponetype"].(string)
|
|
|
+ isPushWx := util.IntAllDef((*userdata)["i_ispush"], 1)
|
|
|
+ applystatus := util.IntAll((*userdata)["i_applystatus"])
|
|
|
+ a_mergeorder, _ := (*userdata)["a_mergeorder"].([]interface{})
|
|
|
+ //进入推送逻辑
|
|
|
+ tit := sname
|
|
|
+ if tit == "" {
|
|
|
+ tit = title
|
|
|
+ }
|
|
|
+ if tit == "" {
|
|
|
+ tit = scode
|
|
|
+ }
|
|
|
+ if tit != "" {
|
|
|
+ followid := util.BsonIdToSId(fid)
|
|
|
+ md, _ := json.Marshal(pushArray)
|
|
|
+ tmpid := fmt.Sprint(time.Now().UnixNano())
|
|
|
+ isSaveOk := cassandra.SaveCache("jy_pushproject", bson.M{
|
|
|
+ "id": time.Now().Format(util.Date_Short_Layout),
|
|
|
+ "openid": jy.GetOldOpenid(s_m_openid, a_m_openid, s_phone, a_mergeorder),
|
|
|
+ "date": tmpid,
|
|
|
+ "info": string(md),
|
|
|
+ "title": title,
|
|
|
+ "pcode": scode,
|
|
|
+ "pname": sname,
|
|
|
+ "fid": followid,
|
|
|
+ })
|
|
|
+ if !isSaveOk {
|
|
|
+ log.Println("保存到cassandra出错!", userId)
|
|
|
+ return pushArray
|
|
|
+ }
|
|
|
+ pushnum := len(*pushArray)
|
|
|
+ //微信推送
|
|
|
+ if applystatus == 1 && isPushWx == 1 && s_m_openid != "" {
|
|
|
+ lastTime := util.Int64All((*(*pushArray)[0])["l_publishtime"])
|
|
|
+ pushtt := fmt.Sprintf(WxTitle, tit)
|
|
|
+ Tip1 := ""
|
|
|
+ minute := time.Now().Unix() - lastTime
|
|
|
+ if minute > -1 && minute < 61 {
|
|
|
+ Tip1 = fmt.Sprintf("%d秒前发布的:\n", minute)
|
|
|
+ } else {
|
|
|
+ minute = minute / 60
|
|
|
+ if minute < 121 {
|
|
|
+ if minute < 1 {
|
|
|
+ minute = 1
|
|
|
+ }
|
|
|
+ Tip1 = fmt.Sprintf("%d分钟前发布的:\n", minute)
|
|
|
+ }
|
|
|
}
|
|
|
- if tit == "" {
|
|
|
- tit = scode
|
|
|
+ LastTip := ""
|
|
|
+ if pushnum > 1 {
|
|
|
+ LastTip = fmt.Sprintf("...(共%d条)", pushnum)
|
|
|
}
|
|
|
- if tit != "" {
|
|
|
- followid := util.BsonIdToSId(fid)
|
|
|
- md, _ := json.Marshal(pushArray)
|
|
|
- tmpid := fmt.Sprint(time.Now().UnixNano())
|
|
|
- isSaveOk := cassandra.SaveCache("jy_pushproject", bson.M{
|
|
|
- "id": time.Now().Format(util.Date_Short_Layout),
|
|
|
- "openid": jy.GetOldOpenid(s_m_openid, a_m_openid, s_phone, a_mergeorder),
|
|
|
- "date": tmpid,
|
|
|
- "info": string(md),
|
|
|
- "title": title,
|
|
|
- "pcode": scode,
|
|
|
- "pname": sname,
|
|
|
- "fid": followid,
|
|
|
- })
|
|
|
- if !isSaveOk {
|
|
|
- log.Println("保存到cassandra出错!", userId)
|
|
|
- return
|
|
|
- }
|
|
|
- pushnum := len(*pushArray)
|
|
|
- //微信推送
|
|
|
- if applystatus == 1 && isPushWx == 1 && s_m_openid != "" {
|
|
|
- lastTime := util.Int64All((*(*pushArray)[0])["l_publishtime"])
|
|
|
- pushtt := fmt.Sprintf(WxTitle, tit)
|
|
|
- Tip1 := ""
|
|
|
- minute := time.Now().Unix() - lastTime
|
|
|
- if minute > -1 && minute < 61 {
|
|
|
- Tip1 = fmt.Sprintf("%d秒前发布的:\n", minute)
|
|
|
- } else {
|
|
|
- minute = minute / 60
|
|
|
- if minute < 121 {
|
|
|
- if minute < 1 {
|
|
|
- minute = 1
|
|
|
- }
|
|
|
- Tip1 = fmt.Sprintf("%d分钟前发布的:\n", minute)
|
|
|
- }
|
|
|
+ LastLen = LastLen - len([]rune(pushtt)) - len([]rune(Tip1))
|
|
|
+ Remark := ""
|
|
|
+ bshow := false
|
|
|
+ for n := 1; n < pushnum+1; n++ {
|
|
|
+ Remark += fmt.Sprintf("%d %s\n", n, (*(*pushArray)[n-1])["s_title"])
|
|
|
+ if len([]rune(Remark)) > LastLen {
|
|
|
+ if n == pushnum {
|
|
|
+ bshow = true
|
|
|
}
|
|
|
- LastTip := ""
|
|
|
- if pushnum > 1 {
|
|
|
- LastTip = fmt.Sprintf("...(共%d条)", pushnum)
|
|
|
- }
|
|
|
- LastLen = LastLen - len([]rune(pushtt)) - len([]rune(Tip1))
|
|
|
- Remark := ""
|
|
|
- bshow := false
|
|
|
- for n := 1; n < pushnum+1; n++ {
|
|
|
- Remark += fmt.Sprintf("%d %s\n", n, (*(*pushArray)[n-1])["s_title"])
|
|
|
- if len([]rune(Remark)) > LastLen {
|
|
|
- if n == pushnum {
|
|
|
- bshow = true
|
|
|
- }
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
- if bshow {
|
|
|
- LastTip = ""
|
|
|
- }
|
|
|
- log.Println("微信推送", userId, s_m_openid, pushnum, tit)
|
|
|
- lastcreatetime := ""
|
|
|
- lastdata, _ := tools.MQFW.Find(FOLLOW_COLLECTION, map[string]interface{}{
|
|
|
- "s_userid": userId,
|
|
|
- }, `{"l_createtime":-1}`, `{"l_createtime":1}`, false, 0, 1)
|
|
|
- if lastdata != nil && len(*lastdata) == 1 {
|
|
|
- if (*lastdata)[0]["l_createtime"] != nil {
|
|
|
- l_createtime, _ := (*lastdata)[0]["l_createtime"].(int64)
|
|
|
- if l_createtime > 0 {
|
|
|
- lastcreatetime = util.FormatDateByInt64(&l_createtime, util.Date_Short_Layout)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if lastcreatetime == "" {
|
|
|
- now := time.Now()
|
|
|
- lastcreatetime = util.FormatDate(&now, util.Date_Short_Layout)
|
|
|
- }
|
|
|
- rpccall.SendWinXin(&qrpc.NotifyMsg{
|
|
|
- Openid: s_m_openid,
|
|
|
- Title: fmt.Sprintf(WxTitle, tit),
|
|
|
- Remark: Tip1 + Remark + LastTip,
|
|
|
- Detail: WxGroup,
|
|
|
- Service: lastcreatetime,
|
|
|
- Color: WxColor,
|
|
|
- DetailColor: WxDetailColor,
|
|
|
- Url: ViewDomain + "/front/sess/" + se.EncodeString(s_m_openid+",uid,"+strconv.Itoa(int(time.Now().Unix()))+",wxpushfollowlist") + "__" + tmpid + "__" + followid,
|
|
|
- }, userId)
|
|
|
+ break
|
|
|
}
|
|
|
- if jpushid != "" || opushid != "" { //极光推送
|
|
|
- jpushtitle := strings.Replace((*((*pushArray)[0]))["s_title"].(string), "\n", "", -1)
|
|
|
- if len([]rune(jpushtitle)) > 80 {
|
|
|
- jpushtitle = string([]rune(jpushtitle)[:80]) + "..."
|
|
|
- }
|
|
|
- if pushnum > 1 {
|
|
|
- jpushtitle = fmt.Sprintf("1. %s\n...(共%d条)", jpushtitle, pushnum)
|
|
|
+ }
|
|
|
+ if bshow {
|
|
|
+ LastTip = ""
|
|
|
+ }
|
|
|
+ lastcreatetime := ""
|
|
|
+ lastdata, _ := tools.MQFW.Find(FOLLOW_COLLECTION, map[string]interface{}{
|
|
|
+ "s_userid": userId,
|
|
|
+ }, `{"l_createtime":-1}`, `{"l_createtime":1}`, false, 0, 1)
|
|
|
+ if lastdata != nil && len(*lastdata) == 1 {
|
|
|
+ if (*lastdata)[0]["l_createtime"] != nil {
|
|
|
+ l_createtime, _ := (*lastdata)[0]["l_createtime"].(int64)
|
|
|
+ if l_createtime > 0 {
|
|
|
+ lastcreatetime = util.FormatDateByInt64(&l_createtime, util.Date_Short_Layout)
|
|
|
}
|
|
|
- isPushOk := rpccall.AppPushServiceCall(map[string]interface{}{
|
|
|
- "phoneType": phoneType,
|
|
|
- "otherPushId": opushid,
|
|
|
- "jgPushId": jpushid,
|
|
|
- "descript": jpushtitle,
|
|
|
- "type": "project",
|
|
|
- "userId": userId,
|
|
|
- "url": "/jyapp/free/sess/" + se.EncodeString(userId+",_id,"+strconv.Itoa(int(time.Now().Unix()))+",wxpushfollowlist") + "__" + tmpid + "__" + followid,
|
|
|
- })
|
|
|
- log.Println("app推送", userId, s_m_openid, a_m_openid, s_phone, phoneType, jpushid, opushid, isPushOk, pushnum, tit)
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
+ if lastcreatetime == "" {
|
|
|
+ now := time.Now()
|
|
|
+ lastcreatetime = util.FormatDate(&now, util.Date_Short_Layout)
|
|
|
+ }
|
|
|
+ isPushOk := rpccall.SendWinXin(&qrpc.NotifyMsg{
|
|
|
+ Openid: s_m_openid,
|
|
|
+ Title: fmt.Sprintf(WxTitle, tit),
|
|
|
+ Remark: Tip1 + Remark + LastTip,
|
|
|
+ Detail: WxGroup,
|
|
|
+ Service: lastcreatetime,
|
|
|
+ Color: WxColor,
|
|
|
+ DetailColor: WxDetailColor,
|
|
|
+ Url: ViewDomain + "/front/sess/" + se.EncodeString(s_m_openid+",uid,"+strconv.Itoa(int(time.Now().Unix()))+",wxpushfollowlist") + "__" + tmpid + "__" + followid,
|
|
|
+ }, userId)
|
|
|
+ log.Println("微信推送", isPushOk, userId, s_m_openid, pushnum, tit)
|
|
|
+ }
|
|
|
+ if jpushid != "" || opushid != "" { //极光推送
|
|
|
+ jpushtitle := strings.Replace((*((*pushArray)[0]))["s_title"].(string), "\n", "", -1)
|
|
|
+ if len([]rune(jpushtitle)) > 80 {
|
|
|
+ jpushtitle = string([]rune(jpushtitle)[:80]) + "..."
|
|
|
+ }
|
|
|
+ if pushnum > 1 {
|
|
|
+ jpushtitle = fmt.Sprintf("1. %s\n...(共%d条)", jpushtitle, pushnum)
|
|
|
+ }
|
|
|
+ isPushOk := rpccall.AppPushServiceCall(map[string]interface{}{
|
|
|
+ "phoneType": phoneType,
|
|
|
+ "otherPushId": opushid,
|
|
|
+ "jgPushId": jpushid,
|
|
|
+ "descript": jpushtitle,
|
|
|
+ "type": "project",
|
|
|
+ "userId": userId,
|
|
|
+ "url": "/jyapp/free/sess/" + se.EncodeString(userId+",_id,"+strconv.Itoa(int(time.Now().Unix()))+",wxpushfollowlist") + "__" + tmpid + "__" + followid,
|
|
|
+ })
|
|
|
+ log.Println("app推送", userId, s_m_openid, a_m_openid, s_phone, phoneType, jpushid, opushid, isPushOk, pushnum, tit)
|
|
|
}
|
|
|
}
|
|
|
- }()
|
|
|
+ }
|
|
|
}
|
|
|
- }, func(e interface{}) {
|
|
|
- log.Println("给用户推送关注信息时出错:", e)
|
|
|
- })
|
|
|
+ }
|
|
|
return pushArray
|
|
|
}
|