|
@@ -8,6 +8,7 @@ import (
|
|
|
"qfw/util"
|
|
|
"qfw/util/jy"
|
|
|
"sort"
|
|
|
+ "strings"
|
|
|
"time"
|
|
|
ca "ucbsutil/cassandra"
|
|
|
|
|
@@ -105,7 +106,7 @@ func ModeTransform(userType int, o_msgset map[string]interface{}) (int, int, int
|
|
|
}
|
|
|
|
|
|
//保存发送信息
|
|
|
-func SaveSendInfo(k *UserInfo, pushinfo string, infos []map[string]interface{}) string {
|
|
|
+func SaveSendInfo(k *UserInfo, pushIds []string, infos []map[string]interface{}) string {
|
|
|
cassandraPoll <- true
|
|
|
defer func() {
|
|
|
<-cassandraPoll
|
|
@@ -114,111 +115,117 @@ func SaveSendInfo(k *UserInfo, pushinfo string, infos []map[string]interface{})
|
|
|
time.Sleep(time.Duration(SysConfig.CassandraSleep) * time.Millisecond)
|
|
|
}
|
|
|
now := time.Now()
|
|
|
- pushid := now.Unix()
|
|
|
+ date := now.Unix()
|
|
|
wxpush := map[string]interface{}{
|
|
|
"dateymd": now.Format(util.Date_yyyyMMdd),
|
|
|
"uid": k.Id,
|
|
|
- "date": pushid,
|
|
|
- "pushinfo": pushinfo,
|
|
|
+ "date": date,
|
|
|
+ "pushinfo": strings.Join(pushIds, ","),
|
|
|
}
|
|
|
if ca.SaveCacheByTimeOut("jy_push", wxpush, 10) {
|
|
|
- updateRedis(k, infos)
|
|
|
- return fmt.Sprint(pushid)
|
|
|
+ updateRedis(date, k, infos)
|
|
|
+ return fmt.Sprint(date)
|
|
|
}
|
|
|
return ""
|
|
|
}
|
|
|
|
|
|
-func updateRedis(k *UserInfo, infos []map[string]interface{}) {
|
|
|
+func updateRedis(date int64, k *UserInfo, infos []map[string]interface{}) {
|
|
|
pc_a, pc_a_err := jy.HistoryPush.GetPushCache_A(k.Id)
|
|
|
pc_b, pc_b_err := jy.HistoryPush.GetPushCache_B(k.Id)
|
|
|
if pc_a_err != nil || pc_b_err != nil {
|
|
|
- logger.Error("redis error", k.Id, pc_a_err, pc_b_err)
|
|
|
+ logger.Error("updateRedis error", k.Id, pc_a_err, pc_b_err)
|
|
|
return
|
|
|
}
|
|
|
- if pc_a != nil {
|
|
|
- list_a := []map[string]interface{}{}
|
|
|
- list_b := []map[string]interface{}{}
|
|
|
+ if pc_a == nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ list_a := pc_a.Infos[:]
|
|
|
+ list_b := []map[string]interface{}{}
|
|
|
+ for k, info := range infos {
|
|
|
+ newInfo := jy.HistoryPush.InfoFormat(&jy.PushCa{
|
|
|
+ Date: date,
|
|
|
+ InfoId: util.ObjToString(info["_id"]),
|
|
|
+ Index: k + 1,
|
|
|
+ }, &info)
|
|
|
+ list_a = append(list_a, newInfo)
|
|
|
+ }
|
|
|
+ length_a := len(list_a) + len(pc_a.Infos)
|
|
|
+ switch pc_a.Type {
|
|
|
+ case 1:
|
|
|
list_a = append(list_a, pc_a.Infos...)
|
|
|
- for k, info := range infos {
|
|
|
- newInfo := jy.HistoryPush.InfoFormat(&jy.PushCa{
|
|
|
- Date: pushid,
|
|
|
- InfoId: util.ObjToString(info["_id"]),
|
|
|
- Index: k + 1,
|
|
|
- }, &info)
|
|
|
- list_a = append(list_a, newInfo)
|
|
|
- }
|
|
|
- length_a := len(list_a) + len(pc_a.Infos)
|
|
|
- switch pc_a.Type {
|
|
|
- case 1:
|
|
|
- list_a = append(list_a, pc_a.Infos...)
|
|
|
- if length_a > 250 {
|
|
|
- if pc_b != nil {
|
|
|
- list_b = append(list_b, list_a[250:]...)
|
|
|
- }
|
|
|
- list_a = list_a[:250]
|
|
|
- pc_a.Count = 250
|
|
|
- } else if length_a == 250 {
|
|
|
- pc_a.Count = 0
|
|
|
- } else {
|
|
|
- pc_a.Count = length_a
|
|
|
+ if length_a > 250 {
|
|
|
+ if pc_b != nil {
|
|
|
+ list_b = append(list_b, list_a[250:]...)
|
|
|
}
|
|
|
- break
|
|
|
- case 2:
|
|
|
- list_a = append(list_a, pc_a.Infos...)
|
|
|
- pc_a.Type = 3
|
|
|
- if length_a > 250 {
|
|
|
- if pc_b != nil {
|
|
|
- list_b = append(list_b, list_a[250:]...)
|
|
|
- }
|
|
|
- list_a = list_a[:250]
|
|
|
- pc_a.Count = 250 - len(infos)
|
|
|
- } else if length_a == 250 {
|
|
|
- pc_a.Count = len(pc_a.Infos)
|
|
|
+ list_a = list_a[:250]
|
|
|
+ pc_a.Count = 250
|
|
|
+ } else if length_a == 250 {
|
|
|
+ pc_a.Count = 0
|
|
|
+ } else {
|
|
|
+ pc_a.Count = length_a
|
|
|
+ }
|
|
|
+ break
|
|
|
+ case 2:
|
|
|
+ list_a = append(list_a, pc_a.Infos...)
|
|
|
+ pc_a.Type = 3
|
|
|
+ if length_a > 250 {
|
|
|
+ if pc_b != nil {
|
|
|
+ list_b = append(list_b, list_a[250:]...)
|
|
|
}
|
|
|
- break
|
|
|
- case 3:
|
|
|
- if length_a > 250 {
|
|
|
- if pc_a.Count < len(pc_a.Infos) {
|
|
|
- pc_a_a := pc_a.Infos[:pc_a.Count]
|
|
|
- pc_a_b := pc_a.Infos[pc_a.Count:]
|
|
|
- list_a = append(list_a, pc_a_a...)
|
|
|
- if len(list_a) > 250 {
|
|
|
-
|
|
|
- } else if len(list_a) == 250 {
|
|
|
- pc_a.Type = 1
|
|
|
- pc_a.Count = 0
|
|
|
- if pc_b != nil {
|
|
|
- list_b = append(list_b, pc_a_b...)
|
|
|
- }
|
|
|
- } else {
|
|
|
- needLength := 250 - len(list_a)
|
|
|
- if needLength > len(pc_a_b) {
|
|
|
- list_a = append(list_a, pc_a_b...)
|
|
|
- pc_a.Count = len(pc_a_b)
|
|
|
- } else {
|
|
|
- list_a = append(list_a, pc_a_b[:needLength])
|
|
|
- list_b = append(list_b, pc_a_b[needLength:])
|
|
|
- pc_a.Count = needLength
|
|
|
- }
|
|
|
- }
|
|
|
- if length_a-pc_a.Count+len(infos) > 250 {
|
|
|
- pc_a.Type = 1
|
|
|
+ list_a = list_a[:250]
|
|
|
+ pc_a.Count = 250 - len(infos)
|
|
|
+ } else if length_a == 250 {
|
|
|
+ pc_a.Count = len(pc_a.Infos)
|
|
|
+ }
|
|
|
+ break
|
|
|
+ case 3:
|
|
|
+ if length_a > 250 {
|
|
|
+ if pc_a.Count < len(pc_a.Infos) {
|
|
|
+ pc_a_a := pc_a.Infos[:pc_a.Count]
|
|
|
+ pc_a_b := pc_a.Infos[pc_a.Count:]
|
|
|
+ list_a = append(list_a, pc_a_a...)
|
|
|
+ if len(list_a) > 250 {
|
|
|
+ pc_a.Type = 1
|
|
|
+ pc_a.Count = 250
|
|
|
+ if pc_b != nil {
|
|
|
+ list_b = append(list_b, list_a[250:]...)
|
|
|
+ list_b = append(list_b, pc_a_b...)
|
|
|
}
|
|
|
list_a = list_a[:250]
|
|
|
+ } else if len(list_a) == 250 {
|
|
|
+ pc_a.Type = 1
|
|
|
+ pc_a.Count = 0
|
|
|
+ if pc_b != nil {
|
|
|
+ list_b = append(list_b, pc_a_b...)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ needLength := 250 - len(list_a)
|
|
|
+ if needLength > len(pc_a_b) {
|
|
|
+ list_a = append(list_a, pc_a_b...)
|
|
|
+ pc_a.Count = len(pc_a_b)
|
|
|
+ } else {
|
|
|
+ list_a = append(list_a, pc_a_b[:needLength]...)
|
|
|
+ list_b = append(list_b, pc_a_b[needLength:]...)
|
|
|
+ pc_a.Count = needLength
|
|
|
+ }
|
|
|
}
|
|
|
} else {
|
|
|
- list_a = append(list_a, pc_a.Infos...)
|
|
|
+ jy.HistoryPush.ClearPushCache(k.Id)
|
|
|
+ logger.Error(k.Id, "count in redis cache is error", pc_a.Count, len(pc_a.Infos))
|
|
|
}
|
|
|
- break
|
|
|
+ } else {
|
|
|
+ list_a = append(list_a, pc_a.Infos...)
|
|
|
}
|
|
|
- jy.HistoryPush.PutPushCache_A(k.Id, list_a)
|
|
|
- if pc_b != nil {
|
|
|
- list_b = append(list_b, pc_b...)
|
|
|
- if len(list_b) > 750 {
|
|
|
- list_b = list_b[:750]
|
|
|
- }
|
|
|
- jy.HistoryPush.PutPushCache_B(k.Id, list_b)
|
|
|
+ break
|
|
|
+ }
|
|
|
+ pc_a.Infos = list_a
|
|
|
+ jy.HistoryPush.PutPushCache_A(k.Id, pc_a)
|
|
|
+ if pc_b != nil {
|
|
|
+ list_b = append(list_b, pc_b...)
|
|
|
+ if len(list_b) > 750 {
|
|
|
+ list_b = list_b[:750]
|
|
|
}
|
|
|
+ jy.HistoryPush.PutPushCache_B(k.Id, list_b)
|
|
|
}
|
|
|
}
|
|
|
func ToObjectIds(ids []string) []bson.ObjectId {
|