Browse Source

Merge branch 'release_dev_wcj' into release

lianbingjie 6 years ago
parent
commit
a616ad5493

+ 4 - 4
src/config.json

@@ -9,8 +9,8 @@
     "strTimeNumber": 30,
     "elasticsearch": "http://192.168.3.18:9800",
     "elasticPoolSize": 30,
-    "redisaddrs": "other=192.168.3.18:3379,push=192.168.3.18:3379,sso=192.168.3.18:3379,session=192.168.3.18:3379,recovery=192.168.3.18:3379",
-    "webport": "8089",
+    "redisaddrs": "other=192.168.3.18:3379,push=192.168.3.18:3379,pushcache=192.168.3.18:3379,sso=192.168.3.18:3379,session=192.168.3.18:3379,recovery=192.168.3.18:3379",
+    "webport": "83",
     "webrpcport": "8084",
     "weixinrpc": "127.0.0.1:8083",
     "cacheflag": false,
@@ -18,8 +18,8 @@
         "192.168.3.207"
     ],
     "cassandrasize": 5,
-    "agreement": "http",
-    "webdomain": "http://webws.qmx.top",
+    "agreement": "https",
+    "webdomain": "https://web-jydev-wcj.jianyu360.cn",
     "redirect": {
         "searchinfo": "/jylab/mainSearch",
         "rssset": "/swordfish/historypush",

+ 1 - 44
src/jfw/front/front.go

@@ -30,8 +30,6 @@ import (
 
 	"github.com/go-xweb/xweb"
 	"gopkg.in/mgo.v2/bson"
-	//gocql "github.com/gocql/gocql"
-	"encoding/json"
 )
 
 type userPool struct {
@@ -859,7 +857,7 @@ func (m *Front) WxpushListInfo(_id string) error {
 			res = data
 			res["bmatch"] = true
 			//更换key
-			val := changeMapKeyForCass(res)
+			val := public.ChangeMapKeyForCass(res)
 			m.T["data"] = val
 		}
 		/*else { //查mongodb
@@ -1249,47 +1247,6 @@ func (f *Front) LimitSearchText() {
 	}
 	f.Write("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, user-scalable=no\">" + fmt.Sprintf(public.Lst.Msg, status, public.Lst.Count, public.Lst.TimeOut, public.Lst.TotalPage))
 }
-func changeMapKeyForCass(res map[string]interface{}) map[string]interface{} {
-	val := make(map[string]interface{})
-	for k, v := range res {
-		if k == "openid" {
-			k = "s_m_openid"
-		} else if k == "date" {
-			k = "l_date"
-		} else if k == "words" {
-			k = "s_words"
-		} else if k == "uid" {
-			k = "s_uid"
-		} else if k == "province" {
-			k = "s_province"
-		} else if k == "interest" {
-			k = "a_interest"
-		} else if k == "content" {
-			k = "s_content"
-		} else if k == "pushinfo" {
-			k = "o_pushinfo"
-			vv := map[string]interface{}{}
-			json.Unmarshal([]byte(v.(string)), &vv)
-			v = vv
-		} else if k == "size" {
-			k = "i_size"
-		} else if k == "appid" {
-			k = "i_appid"
-		} else if k == "ratemode" {
-			k = "i_ratemode"
-		} else if k == "sendmode" {
-			k = "i_sendmode"
-		} else if k == "smartset" {
-			k = "i_smartset"
-		} else if k == "visit" {
-			k = "a_visitedindex"
-		} else if k == "open" {
-			k = "isopen"
-		}
-		val[k] = v
-	}
-	return val
-}
 
 //设置js css 版本号,修改以后记得同步更新seo.json中的值
 func (f *Front) SetSeoVersion() {

+ 2 - 5
src/jfw/front/pchelper.go

@@ -343,16 +343,13 @@ func (l *PcHelper) PushView() error {
 	res := map[string]interface{}{}
 	res["success"] = false
 	if userid != "" && lasttime > 0 {
-		if lasttime == 1 {
-			lasttime = time.Now().Local().Unix()
-		}
 		_, openId := public.GetOldOpenid(userid)
-		thistime, list := getHistorypush(lasttime, 0, userid, openId, nil, 0, []string{})
+		thisindex, list := public.GetHistorypush(0, userid, openId)
 		log.Println(logPrefix, "PushView-getHistorypush-size", len(*list))
 		if list != nil && len(*list) > 0 {
 			res["success"] = true
 			res["data"] = &list
-			res["thistime"] = thistime
+			res["thistime"] = thisindex
 		}
 	}
 	l.ServeJson(&res)

+ 9 - 17
src/jfw/front/swordfish.go

@@ -2481,7 +2481,6 @@ func (f *Front) HasPushHistory() {
 	if user != nil {
 		o_jy, _ = (*user)["o_jy"].(map[string]interface{})
 	}
-	nowUnix := time.Now().Unix()
 	haskey := false
 	if o_jy != nil || len(o_jy) == 0 {
 		a_key, _ := o_jy["a_key"].([]interface{})
@@ -2496,14 +2495,14 @@ func (f *Front) HasPushHistory() {
 	} else {
 		haskey = true
 	}
-	thistime, list := getHistorypush(nowUnix, 0, userid, openId, nil, 0, []string{})
+	thistime, list := public.GetHistorypush(0, userid, openId)
 	if haskey && (list == nil || len(*list) == 0) {
 		list = &[]map[string]interface{}{}
 		flag, data := makeHistoryDatas(util.BsonIdToSId((*user)["_id"]), openId, o_jy)
 		if flag && data != nil {
-			tmp := changeMapKeyForCass(data)
+			tmp := public.ChangeMapKeyForCass(data)
 			if ats, ok := tmp["o_pushinfo"].(map[string]interface{}); ok {
-				thistime = util.Int64All(tmp["l_date"])
+				thistime = 0
 				tmp["count"] = len(ats)
 				*list = append(*list, tmp)
 			}
@@ -2530,11 +2529,7 @@ func (f *Front) Historypush() error {
 	userid := util.ObjToString(f.GetSession("userId"))
 	// 打开推送
 	data, ok := mongodb.FindById("user", userid, nil)
-	log.Println("data", *data)
 	i_applystatus := (*data)["i_applystatus"]
-	if i_applystatus != nil {
-		//		log.Println("i_applystatus", i_applystatus)
-	}
 
 	var o_jy map[string]interface{}
 
@@ -2565,27 +2560,24 @@ func (f *Front) Historypush() error {
 }
 
 func (f *Front) HistorypushPaging() error {
-	lasttime, _ := f.GetInt("lasttime")
+	lasttime, _ := f.GetInteger("lasttime")
 	userid := util.ObjToString(f.GetSession("userId"))
 	res := map[string]interface{}{}
 	res["success"] = false
 	if userid != "" && lasttime > 0 {
-		if lasttime == 1 {
-			lasttime = time.Now().Local().Unix()
-		}
 		_, openId := public.GetOldOpenid(userid)
-		thistime, list := getHistorypush(lasttime, 0, userid, openId, nil, 0, []string{})
+		thisindex, list := public.GetHistorypush(lasttime, userid, openId)
 		if list != nil && len(*list) > 0 {
 			res["success"] = true
 			res["data"] = &list
-			res["thistime"] = thistime
+			res["thistime"] = thisindex
 		}
 	}
 	f.ServeJson(&res)
 	return nil
 }
 
-func getHistorypush(lasttime, infotime int64, userId, openId string, res []map[string]interface{}, count int, vsidList []string) (thistime int64, list *[]map[string]interface{}) {
+func getHistorypush_old(lasttime, infotime int64, userId, openId string, res []map[string]interface{}, count int, vsidList []string) (thistime int64, list *[]map[string]interface{}) {
 	if lasttime < time.Now().Unix()-60*24*60*60 { //最多查询最近60天数据
 		return lasttime, &res
 	}
@@ -2598,7 +2590,7 @@ func getHistorypush(lasttime, infotime int64, userId, openId string, res []map[s
 	pinfo := cassandra.Search("select * from jy_push where id=? and openid=? and date<?", dateshort, openId, lasttime+infotime)
 	if len(pinfo) > 0 {
 		for _, info := range pinfo {
-			tmp := changeMapKeyForCass(info)
+			tmp := public.ChangeMapKeyForCass(info)
 			if ats, ok := tmp["o_pushinfo"].(map[string]interface{}); ok {
 				thistime = util.Int64All(tmp["l_date"])
 				//获取已浏览记录
@@ -2648,7 +2640,7 @@ func getHistorypush(lasttime, infotime int64, userId, openId string, res []map[s
 		thistime = t.Unix() - 24*60*60
 		infotime = 24 * 60 * 60
 	}
-	return getHistorypush(thistime, infotime, userId, openId, res, count, vsidList)
+	return getHistorypush_old(thistime, infotime, userId, openId, res, count, vsidList)
 }
 
 //电脑端招标订阅

+ 1 - 43
src/jfw/modules/app/src/app/front/front.go

@@ -14,7 +14,6 @@ import (
 	"sync"
 	"time"
 
-	"encoding/json"
 	uc "ucbsutil"
 	ca "ucbsutil/cassandra"
 
@@ -349,7 +348,7 @@ func (m *Front) WxpushListInfo(_id string) error {
 	res := make(map[string]interface{})
 	data["visit"] = vsidList
 	res = data
-	res = changeMapKeyForCass(res) //更换key
+	res = public.ChangeMapKeyForCass(res) //更换key
 	//如果有一条,直接跳转
 	o_pushinfo, _ := res["o_pushinfo"].(map[string]interface{})
 	if len(o_pushinfo) == 1 {
@@ -423,47 +422,6 @@ func (f *Front) Index() error {
 func (f *Front) Kicked() error {
 	return f.Redirect("/jyapp/free/login?back=index")
 }
-func changeMapKeyForCass(res map[string]interface{}) map[string]interface{} {
-	val := make(map[string]interface{})
-	for k, v := range res {
-		if k == "openid" {
-			k = "s_m_openid"
-		} else if k == "date" {
-			k = "l_date"
-		} else if k == "words" {
-			k = "s_words"
-		} else if k == "uid" {
-			k = "s_uid"
-		} else if k == "province" {
-			k = "s_province"
-		} else if k == "interest" {
-			k = "a_interest"
-		} else if k == "content" {
-			k = "s_content"
-		} else if k == "pushinfo" {
-			k = "o_pushinfo"
-			vv := map[string]interface{}{}
-			json.Unmarshal([]byte(v.(string)), &vv)
-			v = vv
-		} else if k == "size" {
-			k = "i_size"
-		} else if k == "appid" {
-			k = "i_appid"
-		} else if k == "ratemode" {
-			k = "i_ratemode"
-		} else if k == "sendmode" {
-			k = "i_sendmode"
-		} else if k == "smartset" {
-			k = "i_smartset"
-		} else if k == "visit" {
-			k = "a_visitedindex"
-		} else if k == "open" {
-			k = "isopen"
-		}
-		val[k] = v
-	}
-	return val
-}
 
 //设置js css 版本号,修改以后记得同步更新seo.json中的值
 func (f *Front) SetSeoVersion() {

+ 10 - 12
src/jfw/modules/app/src/app/front/swordfish.go

@@ -722,7 +722,6 @@ func (f *Front) HasPushHistory() {
 	if user != nil {
 		o_jy, _ = (*user)["o_jy"].(map[string]interface{})
 	}
-	nowUnix := time.Now().Unix()
 	haskey := false
 	if o_jy != nil || len(o_jy) == 0 {
 		a_key, _ := o_jy["a_key"].([]interface{})
@@ -737,14 +736,14 @@ func (f *Front) HasPushHistory() {
 	} else {
 		haskey = true
 	}
-	thistime, list := getHistorypush(nowUnix, 0, userid, openId, nil, 0, []string{})
+	thistime, list := public.GetHistorypush(0, userid, openId)
 	if haskey && (list == nil || len(*list) == 0) {
 		list = &[]map[string]interface{}{}
 		flag, data := makeHistoryDatas(userid, openId, o_jy)
 		if flag && data != nil {
-			tmp := changeMapKeyForCass(data)
+			tmp := public.ChangeMapKeyForCass(data)
 			if ats, ok := tmp["o_pushinfo"].(map[string]interface{}); ok {
-				thistime = util.Int64All(tmp["l_date"])
+				thistime = 0
 				tmp["count"] = len(ats)
 				*list = append(*list, tmp)
 			}
@@ -771,18 +770,17 @@ func (f *Front) Historypush() error {
 	return f.Render("/weixin/historypush.html")
 }
 func (f *Front) HistorypushPaging() error {
-	lasttime, _ := f.GetInt("lasttime")
+	lasttime, _ := f.GetInteger("lasttime")
 	userId, _ := f.GetSession("userId").(string)
 	res := map[string]interface{}{}
 	res["success"] = false
-	if userId != "" && lasttime > 0 {
+	if userId != "" && lasttime > 0 || lasttime == -1 {
 		isFirstPage := false
-		if lasttime == 1 {
+		if lasttime == -1 {
 			isFirstPage = true
-			lasttime = time.Now().Local().Unix()
 		}
 		_, openId := public.GetOldOpenid(userId)
-		thistime, list := getHistorypush(lasttime, 0, userId, openId, nil, 0, []string{})
+		thistime, list := public.GetHistorypush(lasttime, userId, openId)
 		if list != nil && len(*list) > 0 {
 			if isFirstPage {
 				go updateUserApppushunread(userId)
@@ -795,7 +793,7 @@ func (f *Front) HistorypushPaging() error {
 	f.ServeJson(&res)
 	return nil
 }
-func getHistorypush(lasttime, infotime int64, userId, openId string, res []map[string]interface{}, count int, vsidList []string) (thistime int64, list *[]map[string]interface{}) {
+func getHistorypush_old(lasttime, infotime int64, userId, openId string, res []map[string]interface{}, count int, vsidList []string) (thistime int64, list *[]map[string]interface{}) {
 	if lasttime < time.Now().Unix()-60*24*60*60 { //最多查询最近60天数据
 		return lasttime, &res
 	}
@@ -807,7 +805,7 @@ func getHistorypush(lasttime, infotime int64, userId, openId string, res []map[s
 	dateshort := util.FormatDateByInt64(&lasttime, util.Date_Short_Layout)
 	pinfo := ca.Search("select * from jy_push where id=? and openid=? and date<?", dateshort, openId, lasttime+infotime)
 	for _, info := range pinfo {
-		tmp := changeMapKeyForCass(info)
+		tmp := public.ChangeMapKeyForCass(info)
 		if ats, ok := tmp["o_pushinfo"].(map[string]interface{}); ok {
 			thistime = util.Int64All(tmp["l_date"])
 			//获取已浏览记录
@@ -838,7 +836,7 @@ func getHistorypush(lasttime, infotime int64, userId, openId string, res []map[s
 		thistime = t.Unix() - 24*60*60
 		infotime = 24 * 60 * 60
 	}
-	return getHistorypush(thistime, infotime, userId, openId, res, count, vsidList)
+	return getHistorypush_old(thistime, infotime, userId, openId, res, count, vsidList)
 }
 
 func MFollow(userId, pname, pcode, title string) (bool, string) {

+ 1 - 1
src/jfw/modules/app/src/config.json

@@ -6,7 +6,7 @@
     "influxdb": "jy_logs",
     "elasticsearch": "http://192.168.3.18:9800",
     "elasticPoolSize": 30,
-    "redisaddrs": "other=192.168.3.18:2379,push=192.168.3.18:2379,sso=192.168.3.18:2379,session=192.168.3.18:3379",
+    "redisaddrs": "other=192.168.3.18:2379,push=192.168.3.18:2379,pushcache=192.168.3.18:2379,sso=192.168.3.18:2379,session=192.168.3.18:3379",
     "webport": "86",
     "weixinrpc": "127.0.0.1:8083",
     "cassandra": [

BIN
src/jfw/modules/app/src/src


+ 3 - 3
src/jfw/modules/app/src/web/templates/weixin/historypush.html

@@ -84,7 +84,7 @@ function initpage(){
 			wxflag = $('.listcontent').dropload({
 		        scrollArea : window,
 				loadUpFn : function(me){
-					loadDatas(me,1);
+					loadDatas(me,-1);
 				},
 		        loadDownFn : function(me){
 					loadDatas(me,lasttime);
@@ -147,7 +147,7 @@ function initpage(){
 			wxflag = $('.listcontent').dropload({
 		        scrollArea : window,
 				loadUpFn : function(me){
-					loadDatas(me,1);
+					loadDatas(me,-1);
 				},
 		        loadDownFn : function(me){
 					loadDatas(me,lasttime);
@@ -194,7 +194,7 @@ function loadDatas(me,le){
 		data: {"lasttime": le},
 		dataType: 'json',
 		success: function(data){
-			if(le==1){
+			if(le==-1){
 				count=0;
 				dataCache = new Array();
 				$("#list>*").remove();

+ 129 - 0
src/jfw/public/public.go

@@ -4,13 +4,18 @@ import (
 	"encoding/json"
 	"fmt"
 	"io/ioutil"
+	"jfw/config"
 	"log"
 	"net/http"
 	"net/url"
 	"qfw/util"
+	"qfw/util/redis"
 	"qfw/util/sms"
 	"regexp"
+	"sort"
 	"strings"
+	"time"
+	"ucbsutil/cassandra"
 )
 
 var MatchSpace = regexp.MustCompile("\\s+")
@@ -169,3 +174,127 @@ func GetOldOpenid(userId string) (*map[string]interface{}, string) {
 	openid := util.GetOldOpenid(s_m_openid, a_m_openid, s_phone, (*user)["a_mergeorder"])
 	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 {
+		flag = false
+		lastindex = 0
+	}
+	pinfo := GetHistorypushDatas(flag, userId, openId)
+	list := []map[string]interface{}{}
+	if len(pinfo) > 0 {
+		count := 0
+		for ; lastindex < len(pinfo); lastindex++ {
+			info := pinfo[lastindex]
+			tmp, _ := info.(map[string]interface{})
+			if ats, ok := tmp["o_pushinfo"].(map[string]interface{}); ok {
+				thistime := util.Int64All(tmp["l_date"])
+				//获取已浏览记录
+				vsidList := []string{}
+				visited := cassandra.Search("select vsid from jy_pushvisit where openid=? and pdate=?", userId, thistime)
+				if len(visited) > 0 {
+					for _, v := range visited {
+						vsidList = append(vsidList, (v["vsid"]).(string))
+					}
+				}
+				tmp["a_visitedindex"] = vsidList
+				count += len(ats)
+				list = append(list, tmp)
+				if count >= 50 {
+					return lastindex + 1, &list
+				}
+			}
+		}
+	}
+	return lastindex + 1, &list
+}
+func GetHistorypushDatas(flag bool, userId, openId string) []interface{} {
+	list := []interface{}{}
+	if flag {
+		cacheDatas := redis.Get("pushcache", "jypush_"+userId)
+		if cacheDatas != nil {
+			log.Println("GetHistorypushDatas from redis", userId)
+			list = cacheDatas.([]interface{})
+			return list
+		}
+	}
+	array := []string{}
+	countDay := 15
+	now := time.Now()
+	for i := 0; i < countDay; i++ {
+		array = append(array, util.FormatDate(&now, util.Date_Short_Layout))
+		now = now.AddDate(0, 0, -1)
+	}
+	datas := cassandra.Search("select * from jy_push where id in ('"+strings.Join(array, "', '")+"') and openid=?", openId)
+	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
+}
+
+func ChangeMapKeyForCass(res map[string]interface{}) map[string]interface{} {
+	val := make(map[string]interface{})
+	for k, v := range res {
+		if k == "openid" {
+			k = "s_m_openid"
+		} else if k == "date" {
+			k = "l_date"
+		} else if k == "words" {
+			k = "s_words"
+		} else if k == "uid" {
+			k = "s_uid"
+		} else if k == "province" {
+			k = "s_province"
+		} else if k == "interest" {
+			k = "a_interest"
+		} else if k == "content" {
+			k = "s_content"
+		} else if k == "pushinfo" {
+			k = "o_pushinfo"
+			vv := map[string]interface{}{}
+			json.Unmarshal([]byte(v.(string)), &vv)
+			v = vv
+		} else if k == "size" {
+			k = "i_size"
+		} else if k == "appid" {
+			k = "i_appid"
+		} else if k == "ratemode" {
+			k = "i_ratemode"
+		} else if k == "sendmode" {
+			k = "i_sendmode"
+		} else if k == "smartset" {
+			k = "i_smartset"
+		} else if k == "visit" {
+			k = "a_visitedindex"
+		} else if k == "open" {
+			k = "isopen"
+		}
+		val[k] = v
+	}
+	return val
+}