renzheng 9 年 前
コミット
3f277ed57a

+ 22 - 33
core/src/web/templates/swordfish/wxsearchlist.html

@@ -7,19 +7,13 @@
 <link href="{{Msg "seo" "cdn"}}/wxswordfish/style.css" rel="stylesheet">
 {{include "/common/inc.html"}}
 <script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
-<script src="{{Msg "seo" "cdn"}}/js/jquery.js"></script>
 <script src="{{Msg "seo" "cdn"}}/wxswordfish/share.js"></script>
 <script src="{{Msg "seo" "cdn"}}/wxswordfish/main.js"></script>
 <script src="{{Msg "seo" "cdn"}}/wxswordfish/jquery.resize.js"></script>
-<script src="{{Msg "seo" "cdn"}}/js/iscroll.js"></script>
-<script>
-	var msgset= {{.T.msgset}};
-	initShare({{.T.signature}},{{.T.shareid}});
-</script>
-
 <script type="text/javascript">
+	var msgset= {{.T.msgset}};
 $(function(){
-	
+	initShare({{.T.signature}},{{.T.shareid}});
 	var s_words = [];
 	s_words = {{.T.s_name}};
 	
@@ -122,9 +116,10 @@ $(function(){
 					$(this).attr("href","javascript:void(0);")	
 				}
 			})
-			abt.click(function(){
+			abt.on("click", function(event){
 				var h=$(this).attr("s");
-				open_window(h);
+				var sid=$(this).attr("sid");
+				redirect(h,sid);
 				return false;
 			})
 		},800)
@@ -225,6 +220,7 @@ body{
 .resbm {
     display: table;
     position: fixed;
+	z-index:2000;
     left: 0px;
     right: 0px;
     bottom: 46px;
@@ -262,7 +258,7 @@ body{
     top: 65px;
 	left: 0px;
 	right: 0px;
-	overflow: hidden;
+	overflow: auto;
 	z-index: 1;
 }
 .nullcontent{
@@ -327,7 +323,7 @@ body{
 </div>
 <div class="resbm" >
 <div class="rests">确认关键词的查询结果无误</div>
-<div class="resdy"  onClick="jpmy()">
+<div class="resdy" id="zjdy">
 直接订阅
 </div>
 
@@ -367,28 +363,21 @@ body{
 		$(".searchzhao3 span").html("");
 		$(".searchzhong3 span").html("");
 	})
-	function open_window(link){
-		if(!/^http/.test(link)){
-			link="http://"+link
-		}
-		window.open("/visit/redirect?url="+escape(link));
-	}
-	function jpmy(){
-		var searchname = $(".searchname").val();
-		document.getElementById("searchnametwo").value = searchname;
-		document.forms['searchtwo'].submit();
+
+function redirect(link,sid){ 
+	if(!/^http/.test(link)){
+		link="http://"+link
 	}
-	$(function(){
-		new IScroll('#wrapper', {
-			scrollbarClass: "myScrollbar",
-			scrollbars: "custom",
-			mouseWheel: true,
-			interactiveScrollbars: true,
-			shrinkScrollbars: 'scale',
-			fadeScrollbars: true,
-			resizeScrollbars: false
-		});
-	});
+	window.location.href="/visit/redirect?id="+sid+"&url="+escape(link)
+}
+
+	$("#zjdy").click(function(){
+			var searchname = $(".searchname").val();
+			document.getElementById("searchnametwo").value = searchname;
+			document.forms['searchtwo'].submit();
+			return false	
+	})
+
 </script>
 </body>
 </html>

+ 157 - 30
push/src/qfw/push/dopush/dopush.go

@@ -1,6 +1,7 @@
 package dopush
 
 import (
+	"sort"
 	"container/list"
 	"fmt"
 	"log"
@@ -15,6 +16,7 @@ import (
 	"strconv"
 	"strings"
 	"time"
+	"qfw/push/listdb"
 )
 
 var se util.SimpleEncrypt
@@ -43,7 +45,17 @@ func (b *Pjob) CreateUserInterestWord() {
 	b.Dfa.AddWord(words...)
 }
 
-//遍历数据只做标题预览
+type sortList []map[string]interface{}
+
+func (s sortList) Less(i, j int) bool {
+    return util.Int64All(s[i]["publishtime"]) < util.Int64All(s[j]["publishtime"])
+}
+
+func (s sortList) Swap(i, j int) {
+    s[i], s[j] = s[j], s[i]
+}
+
+//内存数据推送
 func (p *Pjob) EachInfoForView(mopenid, words string) map[string]interface{} {
 	defer func() {
 		if r := recover(); r != nil {
@@ -72,28 +84,22 @@ func (p *Pjob) EachInfoForView(mopenid, words string) map[string]interface{} {
 		*p.Cache = push.InitCache(p.Stype, mopenid,true)
 	}
 	p.CreateUserInterestWord()
-	session := mongodb.GetMgoConn()
-	defer mongodb.DestoryMongoConn(session)
-	q := `{"type":"` + p.Stype + `"}`
-	n, _ := session.DB("qfw").C("bidding").Find(mongodb.ObjToOth(q)).Count()
-	userMap := &map[*push.MemberInterest]*list.List{}
-	if n == 0 {
-		log.Println("预览", p.Stype, "没有数据。")
-	} else {
-		query := session.DB("qfw").C("bidding").Find(mongodb.ObjToOth(q)).Sort("-publishtime").Iter()
-		var returnLastTimeLong int64 = 0
+	userMap := &map[*push.MemberInterest]sortList{}
+	LDB:=listdb.GetDb(p.Stype)
+	
+	LDB.Lock.Lock()
 	L1:
-		for tmp := new(map[string]interface{}); query.Next(tmp); {
-			title := util.ObjToString((*tmp)["title"])
+	for e := LDB.DB.Back(); e != nil; e = e.Prev(){
+		tmp:=e.Value.(map[string]interface{})
+			title := util.ObjToString(tmp["title"])
 			if title != "" {
 				//返回匹配到的词组
 				res := p.Dfa.Analy(title)
 				if len(res) > 0 {
-					province := (*tmp)["area"].(string)
-
+					province := tmp["area"].(string)
 					provinceVal := push.GetChoiceCode(province)
 					if "A" != province {
-						(*tmp)["title"] = `[<span class='area'>` + province + `</span>]` + title
+						tmp["title"] = `[<span class='area'>` + province + `</span>]` + title
 					}
 					for _, v := range res {
 						//根据关键词返回用户指针
@@ -104,11 +110,11 @@ func (p *Pjob) EachInfoForView(mopenid, words string) map[string]interface{} {
 								if v2.Province == "A" || v2.ProvinceVal&provinceVal > 0 {
 									s := (*userMap)[v2]
 									if s == nil {
-										s = list.New()
+										s = sortList{}
 										(*userMap)[v2] = s
 									}
-									s.PushBack(tmp)
-									if s.Len() > 50 {
+									s=append(s,tmp)
+									if len(s) > 50 {
 										break L1
 									}
 								}
@@ -116,27 +122,21 @@ func (p *Pjob) EachInfoForView(mopenid, words string) map[string]interface{} {
 						}
 					}
 				}
-				if (*tmp)["comeintime"] != nil {
-					ttmp := (*tmp)["comeintime"].(int64)
-					if ttmp > returnLastTimeLong {
-						returnLastTimeLong = ttmp
-					}
-				}
 			}
-			tmp = new(map[string]interface{})
-		}
 	}
+	LDB.Lock.Unlock()
 	mcontent := map[string]interface{}{}
 	mcontent["s_type"] = p.Stype
 	bmatch := false
 	for kk, vv := range *(userMap) {
 		k := *kk
-		v := *vv
+		v := vv
 		str := fmt.Sprintf("<div>根据您设置的关键词(%s),给您推送以下"+p.StypeName+"信息:</div>", strings.Join(k.Interest, ";"))
 		//发送内容组合
 		i := 0
 		publishTimes := map[string]interface{}{}
 		publishTitle := map[string]bool{}
+		sort.Sort(v)
 		for ks := v.Front(); ks != nil; ks = ks.Next() {
 			k2 := *(ks.Value.(*map[string]interface{}))
 			title := strings.Replace(k2["title"].(string), "\n", "", -1)
@@ -164,8 +164,7 @@ func (p *Pjob) EachInfoForView(mopenid, words string) map[string]interface{} {
 			break
 		}
 	}
-
-	return mcontent
+	return mcontent	
 }
 
 func (p *Pjob) DoPush(mopenid, stime string, opr int, ltime int64) bool {
@@ -367,3 +366,131 @@ func SendWeixin(k *push.MemberInterest, TITLE, ShortTitle, str, stype string, no
 		Url: push.PushConfig["bidViewDomain"].(string) + "/mobile/sess/" + se.EncodeString(k.Openid+",uid,"+strconv.Itoa(int(time.Now().Unix()))+",wxpushlist") + "__" + wid})
 
 }
+
+
+/**
+//遍历数据只做标题预览
+func (p *Pjob) EachInfoForViewOld(mopenid, words string) map[string]interface{} {
+	defer func() {
+		if r := recover(); r != nil {
+			log.Println("[E]", r)
+			for skip := 0; ; skip++ {
+				_, file, line, ok := runtime.Caller(skip)
+				if !ok {
+					break
+				}
+				go log.Printf("%v,%v\n", file, line)
+			}
+		}
+	}()
+	p.Cache = new(map[string]*[]*push.MemberInterest)
+	if words != "" {
+		pm := push.MemberInterest{
+			Province:    "A",
+			ProvinceVal: 0,
+			Interest:    []string{words},
+		}
+		ss := []*push.MemberInterest{&pm}
+		*p.Cache = map[string]*[]*push.MemberInterest{
+			words: &ss,
+		}
+	} else {
+		*p.Cache = push.InitCache(p.Stype, mopenid,true)
+	}
+	p.CreateUserInterestWord()
+	session := mongodb.GetMgoConn()
+	defer mongodb.DestoryMongoConn(session)
+	q := `{"type":"` + p.Stype + `"}`
+	n, _ := session.DB("qfw").C("bidding").Find(mongodb.ObjToOth(q)).Count()
+	userMap := &map[*push.MemberInterest]*list.List{}
+	if n == 0 {
+		log.Println("预览", p.Stype, "没有数据。")
+	} else {
+		query := session.DB("qfw").C("bidding").Find(mongodb.ObjToOth(q)).Sort("-publishtime").Iter()
+		var returnLastTimeLong int64 = 0
+	L1:
+		for tmp := new(map[string]interface{}); query.Next(tmp); {
+			title := util.ObjToString((*tmp)["title"])
+			if title != "" {
+				//返回匹配到的词组
+				res := p.Dfa.Analy(title)
+				if len(res) > 0 {
+					province := (*tmp)["area"].(string)
+
+					provinceVal := push.GetChoiceCode(province)
+					if "A" != province {
+						(*tmp)["title"] = `[<span class='area'>` + province + `</span>]` + title
+					}
+					for _, v := range res {
+						//根据关键词返回用户指针
+						tw := (*p.Cache)[v]
+						if tw != nil {
+							//遍历用户加入到此条信息上
+							for _, v2 := range *tw {
+								if v2.Province == "A" || v2.ProvinceVal&provinceVal > 0 {
+									s := (*userMap)[v2]
+									if s == nil {
+										s = list.New()
+										(*userMap)[v2] = s
+									}
+									s.PushBack(tmp)
+									if s.Len() > 50 {
+										break L1
+									}
+								}
+							}
+						}
+					}
+				}
+				if (*tmp)["comeintime"] != nil {
+					ttmp := (*tmp)["comeintime"].(int64)
+					if ttmp > returnLastTimeLong {
+						returnLastTimeLong = ttmp
+					}
+				}
+			}
+			tmp = new(map[string]interface{})
+		}
+	}
+	mcontent := map[string]interface{}{}
+	mcontent["s_type"] = p.Stype
+	bmatch := false
+	for kk, vv := range *(userMap) {
+		k := *kk
+		v := *vv
+		str := fmt.Sprintf("<div>根据您设置的关键词(%s),给您推送以下"+p.StypeName+"信息:</div>", strings.Join(k.Interest, ";"))
+		//发送内容组合
+		i := 0
+		publishTimes := map[string]interface{}{}
+		publishTitle := map[string]bool{}
+		for ks := v.Front(); ks != nil; ks = ks.Next() {
+			k2 := *(ks.Value.(*map[string]interface{}))
+			title := strings.Replace(k2["title"].(string), "\n", "", -1)
+			if !publishTitle[title] {
+				publishTitle[title] = true
+				i++
+				str += "<div class='tslist'><span class='xh'>" + fmt.Sprintf("%d", i) + ".</span><a class='bt' target='_blank' sid='" + util.BsonIdToSId(k2["_id"]) + "'  href='" + k2["href"].(string) + "'>" + title + "</a></div>"
+				publishTimes[strconv.Itoa(i)] = k2["publishtime"]
+			}
+		}
+		if len(publishTimes) > 0 {
+			bmatch = true
+			mcontent["a_publishtime"] = publishTimes
+			mcontent["s_content"] = str
+			mcontent["s_words"] = k.Interest
+		}
+	}
+	mcontent["bmatch"] = bmatch
+	if !bmatch {
+		for _, one := range *p.Cache {
+			for _, onep := range *one {
+				mcontent["s_words"] = onep.Interest
+				break
+			}
+			break
+		}
+	}
+
+	return mcontent
+}
+**/

+ 81 - 0
push/src/qfw/push/listdb/listdb.go

@@ -0,0 +1,81 @@
+package listdb
+
+import (
+	"time"
+	"container/list"
+	"sync"
+	"qfw/util"
+	"qfw/util/mongodb"
+)
+
+type ListDB struct{
+	Lock *sync.Mutex
+	DB *list.List
+	Stype string
+}
+var fields map[string]int=map[string]int{
+	"type" : 1,
+	"comeintime": 1, 
+    "publishtime": 1, 
+    "title": 1,
+    "area" : 1,
+    "href": 1,
+    "areaval" : 1,
+}
+
+var Bid,Tender *ListDB
+
+func init(){
+	Bid=&ListDB{
+		Lock:new(sync.Mutex),
+		DB:list.New(),
+		Stype:"bid",
+	}
+	go Bid.update()
+	
+	Tender=&ListDB{
+		Lock:new(sync.Mutex),
+		DB:list.New(),
+		Stype:"tender",
+	}
+	go Tender.update()
+}
+
+func GetDb(stype string) *ListDB{
+	switch stype{
+		case "tender":
+			return Tender
+		case "bid":
+			return Bid
+		default:
+			return nil
+	}
+}
+
+func (l *ListDB) update(){
+	l.Lock.Lock()
+	util.Try(func(){	
+		q:=map[string]interface{}{
+			"type":l.Stype,
+		}
+		if l.DB.Len()>0 {
+			data:=l.DB.Back().Value.(map[string]interface{})
+			q["comeintime"]=map[string]interface{}{
+				"$gt":util.Int64All(data["comeintime"]),
+			}
+		}
+		session := mongodb.GetMgoConn()
+		defer mongodb.DestoryMongoConn(session)
+		//此处不排序,谁查谁排序(不排序会造成发布时间乱序)
+		query := session.DB("qfw").C("bidding").Find(q).Select(fields).Sort("publishtime").Iter()
+		for tmp := new(map[string]interface{}); query.Next(tmp); {
+			l.DB.PushBack(tmp)
+			if l.DB.Len()>150000{
+				l.DB.Remove(l.DB.Front())	
+			}
+			tmp = new(map[string]interface{})
+		}
+	},func(e interface{}){})
+	l.Lock.Unlock()
+	time.AfterFunc(15*time.Minute,l.update)
+}