wcj 6 anos atrás
pai
commit
7ffc9f476b
1 arquivos alterados com 27 adições e 4 exclusões
  1. 27 4
      src/jfw/public/public.go

+ 27 - 4
src/jfw/public/public.go

@@ -12,6 +12,7 @@ import (
 	"qfw/util/redis"
 	"qfw/util/sms"
 	"regexp"
+	"sort"
 	"strings"
 	"time"
 	"ucbsutil/cassandra"
@@ -174,6 +175,22 @@ func GetOldOpenid(userId string) (*map[string]interface{}, string) {
 	return user, openid
 }
 
+type sortList []map[string]interface{}
+
+func (s sortList) Len() int {
+	return len(s)
+}
+
+func (s sortList) Less(i, j int) bool {
+	defer util.Catch()
+	return util.Int64All((s[i])["date"]) > util.Int64All((s[j])["date"])
+}
+
+func (s sortList) Swap(i, j int) {
+	defer util.Catch()
+	s[i], s[j] = s[j], s[i]
+}
+
 func GetHistorypush(lastindex int, userId, openId string) (int, *[]map[string]interface{}) {
 	flag := true
 	if lastindex == -1 {
@@ -214,7 +231,7 @@ func GetHistorypushDatas(flag bool, userId, openId string) []interface{} {
 		cacheDatas := redis.Get("pushcache", "jypush_"+userId)
 		if cacheDatas != nil {
 			log.Println("GetHistorypushDatas from redis", userId)
-			list, _ = cacheDatas.([]interface{})
+			list = cacheDatas.([]interface{})
 			return list
 		}
 	}
@@ -226,9 +243,15 @@ func GetHistorypushDatas(flag bool, userId, openId string) []interface{} {
 		now = now.AddDate(0, 0, -1)
 	}
 	datas := cassandra.Search("select * from jy_push where id in ('"+strings.Join(array, "', '")+"') and openid=?", openId)
-	for _, info := range datas {
-		tmp := ChangeMapKeyForCass(info)
-		list = append(list, tmp)
+	sl := sortList{}
+	if datas != nil {
+		for _, v := range datas {
+			sl = append(sl, v)
+		}
+		sort.Sort(sl)
+	}
+	for _, v := range sl {
+		list = append(list, ChangeMapKeyForCass(v))
 	}
 	redis.Put("pushcache", "jypush_"+userId, list, util.IntAllDef(config.Sysconfig["pushTimeout"], 300))
 	return list