wcj 6 éve
szülő
commit
28f0dfef6b

+ 16 - 9
src/jfw/modules/pushsubscribe/src/push/job/dopush.go

@@ -77,8 +77,9 @@ func (d *doPush) Do(taskType int, isSave bool, wxPush, appPush, mailPush int, k
 	jpushtitle := ""
 	lastInfoDate := int64(0)
 	TitleArray := []string{}
+	infos := []map[string]interface{}{}
 	publishTitle := map[string]bool{}
-	pushinfo := []string{}
+	pushIds := []string{}
 	//邮件附件
 	var fmdatas = []map[string]interface{}{}
 	for _, ks := range *sl {
@@ -92,7 +93,8 @@ func (d *doPush) Do(taskType int, isSave bool, wxPush, appPush, mailPush int, k
 		if publishTitle[newTitle] {
 			continue
 		}
-		pushinfo = append(pushinfo, util.ObjToString(k2["_id"]))
+		infos = append(infos, k2)
+		pushIds = append(pushIds, util.ObjToString(k2["_id"]))
 		publishTitle[title] = true
 		i++
 		TitleArray = append(TitleArray, Re.ReplaceAllString(newTitle, "$1"))
@@ -120,11 +122,16 @@ func (d *doPush) Do(taskType int, isSave bool, wxPush, appPush, mailPush int, k
 			url := fmt.Sprintf("%s/article/mailprivate/%s.html", SysConfig.JianyuDomain, mailSid)
 			classArea := "area"
 			classType := "type"
-			types := util.ObjToString(k2["subtype"])
-			if types == "" {
-				types = util.ObjToString(k2["toptype"])
-				if types == "" {
-					types = "其他"
+			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)
@@ -151,7 +158,7 @@ func (d *doPush) Do(taskType int, isSave bool, wxPush, appPush, mailPush int, k
 			if industry == "" {
 				industryclass = ""
 			}
-			mailContent += fmt.Sprintf(SysConfig.Mail_content, i, url, otitle, classArea, area, classType, types, industryclass, industry, dates)
+			mailContent += fmt.Sprintf(SysConfig.Mail_content, i, url, otitle, classArea, area, classType, infotype, industryclass, industry, dates)
 		}
 		//附件数据
 		fmdata := map[string]interface{}{
@@ -176,7 +183,7 @@ func (d *doPush) Do(taskType int, isSave bool, wxPush, appPush, mailPush int, k
 	}
 	if isSave {
 		//推送记录id
-		pushId := putil.SaveSendInfo(k, strings.Join(pushinfo, ","))
+		pushId := putil.SaveSendInfo(k, pushIds, infos)
 		if pushId == "" {
 			logger.Info("推送任务,保存到cassandra出错", k.Id, k.S_m_openid, k.A_m_openid, k.Phone)
 			return

+ 89 - 82
src/jfw/modules/pushsubscribe/src/push/util/util.go

@@ -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 {

+ 1 - 0
src/jfw/public/historypush.go

@@ -26,6 +26,7 @@ type historyPush struct{}
 
 //获取历史推送记录入口
 func (h *historyPush) Datas(userId string, pageNum int, firstPushTime int64) (hasNextPage bool, result []map[string]interface{}, err error) {
+	defer util.Catch()
 	result = []map[string]interface{}{}
 	pc_a, ps_a_err := jy.HistoryPush.GetPushCache_A(userId)
 	if ps_a_err != nil {