Эх сурвалжийг харах

Merge branch 'develop' of 192.168.3.17:zhanghongbo/qfw into develop

wangchuanjin 9 жил өмнө
parent
commit
b1a9449fb0

+ 0 - 2
common/src/github.com/go-xweb/xweb/filter.go

@@ -58,7 +58,6 @@ func (s *LoginFilter) Do(w http.ResponseWriter, req *http.Request) bool {
 	if s.OriUrlName != "" {
 		redirect = redirect + "?" + s.OriUrlName + "=" + url.QueryEscape(req.URL.String())
 	}
-
 	for _, cr := range s.AskLoginUrls {
 		if !cr.MatchString(requestPath) {
 			continue
@@ -72,7 +71,6 @@ func (s *LoginFilter) Do(w http.ResponseWriter, req *http.Request) bool {
 		}
 		return has
 	}
-
 	if len(s.AnonymousUrls) == 0 {
 		return true
 	}

+ 2 - 3
common/src/qfw/util/mongodb/mongodbSim.go

@@ -196,9 +196,8 @@ func (m *MongodbSim) Find(c string, query interface{}, order interface{}, fields
 		}
 		if nil != err {
 			log.Println("FindError", err)
-		} else {
-			b = true
-		}
+		} 
+		b = true
 	}
 	return &res, b
 }

+ 45 - 46
common/src/qfw/util/mongodb/mongodbutil_test.go

@@ -1,14 +1,15 @@
 package mongodb
 
 import (
-	"sync"
 	"fmt"
-	. "gopkg.in/mgo.v2/bson"
 	"log"
+	"qfw/util"
 	"regexp"
+	"sync"
 	"testing"
 	"time"
-	"qfw/util"
+
+	. "gopkg.in/mgo.v2/bson"
 )
 
 func Test_orAnd(t *testing.T) {
@@ -103,19 +104,19 @@ func Test_aggregate(t *testing.T) {
 //检测query正确性
 func Test_nextQuery(t *testing.T) {
 	InitMongodbPool(2, "192.168.3.18:27080", "qfw")
-		sess := GetMgoConn()
-		defer DestoryMongoConn(sess)
+	sess := GetMgoConn()
+	defer DestoryMongoConn(sess)
 	for i := 0; i < 50; i++ {
 		log.Println("-----", i)
 
 		query := sess.DB("qfw").C("enterprise").Find(nil).Select(map[string]interface{}{
-			"_id":   1,
+			"_id": 1,
 		}).Iter()
 		res := map[ObjectId]int{}
 		for tmp := make(map[string]interface{}); query.Next(tmp); {
-			util.Try(func(){
+			util.Try(func() {
 				res[tmp["_id"].(ObjectId)]++
-			},func(e interface{}){})
+			}, func(e interface{}) {})
 			tmp = make(map[string]interface{})
 		}
 
@@ -128,58 +129,56 @@ func Test_nextQuery(t *testing.T) {
 	}
 }
 
+type Person struct {
+	Name string
+	Age  int
+}
 
-	type Person struct{
-		Name string
-		Age int
-	}
-func Test_range(t *testing.T){
+func Test_range(t *testing.T) {
 
-	for t:=0;t<100;t++{
-		log.Println("-------",t)
+	for t := 0; t < 100; t++ {
+		log.Println("-------", t)
 
-	m1:=&map[*Person]string{}
-	
-	for i:=0;i<1000000;i++{
-		p:=Person{
-			Name:fmt.Sprintf("N-%d",i),
-			Age:i,
+		m1 := &map[*Person]string{}
+
+		for i := 0; i < 1000000; i++ {
+			p := Person{
+				Name: fmt.Sprintf("N-%d", i),
+				Age:  i,
+			}
+			(*m1)[&p] = fmt.Sprintf("String-%d", i)
 		}
-		(*m1)[&p]=fmt.Sprintf("String-%d",i)
-	}
-	m2:=map[int]int{}
-	ws:=new(sync.WaitGroup)
-	sm:=new(sync.Mutex)
-	
-	for k,_:=range *m1{
-		kk:=*k
-		ws.Add(1)
-		go func(p Person){
-			defer ws.Done()
-			sm.Lock()
-			m2[p.Age]++
-			sm.Unlock()
-		}(kk)
-	}
-	ws.Wait()
-	
-	for k, v := range m2 {
+		m2 := map[int]int{}
+		ws := new(sync.WaitGroup)
+		sm := new(sync.Mutex)
+
+		for k, _ := range *m1 {
+			kk := *k
+			ws.Add(1)
+			go func(p Person) {
+				defer ws.Done()
+				sm.Lock()
+				m2[p.Age]++
+				sm.Unlock()
+			}(kk)
+		}
+		ws.Wait()
+
+		for k, v := range m2 {
 			if v > 1 {
 				log.Println(k, v)
 			}
 		}
-	
-		}
-}
 
+	}
+}
 
 func Test_Credit(t *testing.T) {
 	//InitMongodbPool(1, "10.116.86.154:27080", "qfw")
 	//u:=FindById("user","55a30cdfaf53744fca000b51",nil)
 	//cre:=util.IntAll((*u)["credit_a"])
 	//cre2:=util.Int64All((*u)["credit_a"])
-	 s :=int64(1152921504606848907)
-	log.Println(s,int(s))
+	s := int64(1152921504606848907)
+	log.Println(s, int(s))
 
 }
-

+ 12 - 3
push/src/qfw/push/dopush/dopush.go

@@ -208,13 +208,22 @@ func EachAllBidInfo(stype, TITLEA, ShortTitle string, lastTime int64, MaxPushSiz
 	}()
 	session := mongodb.GetMgoConn()
 	defer mongodb.DestoryMongoConn(session)
-	q := `{"comeintime":{"$gt":` + fmt.Sprintf("%d", lastTime) + `},"type":"` + stype + `"}`
-	n, _ := session.DB("qfw").C("bidding").Find(mongodb.ObjToOth(q)).Count()
+	//q := `{"comeintime":{"$gt":` + fmt.Sprintf("%d", lastTime) + `},"type":"` + stype + `"}`
+	q := map[string]interface{}{
+		"type": stype,
+		"comeintime": map[string]interface{}{
+			"$gt": lastTime,
+		},
+		"publishtime": map[string]interface{}{
+			"$gt": lastTime - 7*86400,
+		},
+	}
+	n, _ := session.DB("qfw").C("bidding").Find(&q).Count()
 	if n == 0 {
 		log.Println("执行推送任务", stype, "没有数据。")
 		return
 	}
-	query := session.DB("qfw").C("bidding").Find(mongodb.ObjToOth(q)).Sort("-publishtime").Iter()
+	query := session.DB("qfw").C("bidding").Find(&q).Sort("-publishtime").Iter()
 	userMap := &map[*push.MemberInterest]*list.List{}
 	var returnLastTime interface{}
 	var returnLastTimeLong int64 = 0