Browse Source

bidding拆分

wangchuanjin 5 years ago
parent
commit
18719056ab
100 changed files with 803 additions and 4454 deletions
  1. 12 5
      src/db.json
  2. 2 1
      src/jfw/active/zqluckdraw.go
  3. 1 1
      src/jfw/front/adv.go
  4. 1 1
      src/jfw/front/applysub.go
  5. 9 5
      src/jfw/front/follow.go
  6. 11 12
      src/jfw/front/front.go
  7. 2 2
      src/jfw/front/login.go
  8. 2 2
      src/jfw/front/pchelper.go
  9. 4 3
      src/jfw/front/search.go
  10. 2 2
      src/jfw/front/shorturl.go
  11. 7 8
      src/jfw/front/singleLogin.go
  12. 6 3
      src/jfw/front/structedData.go
  13. 13 13
      src/jfw/front/swordfish.go
  14. 3 1
      src/jfw/front/ws_dataExport.go
  15. 4 4
      src/jfw/front/wxMyOrder.go
  16. 1 1
      src/jfw/front/wx_dataExport.go
  17. 3 3
      src/jfw/jyutil/sessionkeep.go
  18. 4 3
      src/jfw/modules/app/src/app/followent/followent.go
  19. 5 3
      src/jfw/modules/app/src/app/followent/myfwent.go
  20. 1 1
      src/jfw/modules/app/src/app/front/dataExport.go
  21. 13 13
      src/jfw/modules/app/src/app/front/follow.go
  22. 4 4
      src/jfw/modules/app/src/app/front/front.go
  23. 6 4
      src/jfw/modules/app/src/app/front/login.go
  24. 4 3
      src/jfw/modules/app/src/app/front/logoffuser.go
  25. 2 3
      src/jfw/modules/app/src/app/front/me.go
  26. 6 8
      src/jfw/modules/app/src/app/front/myorder.go
  27. 1 2
      src/jfw/modules/app/src/app/front/search.go
  28. 6 8
      src/jfw/modules/app/src/app/front/shorturl.go
  29. 1 2
      src/jfw/modules/app/src/app/front/structedData.go
  30. 11 9
      src/jfw/modules/app/src/app/front/swordfish.go
  31. 3 3
      src/jfw/modules/app/src/app/front/ws_dataExport.go
  32. 7 0
      src/jfw/modules/app/src/db.json
  33. 15 14
      src/jfw/modules/common/src/qfw/util/jy/entnichepush.go
  34. 15 14
      src/jfw/modules/common/src/qfw/util/jy/subscribepush.go
  35. 2 2
      src/jfw/modules/common/src/qfw/util/jy/user_merge.go
  36. 1 1
      src/jfw/modules/common/src/qfw/util/jy/user_wxMerge.go
  37. 2 7
      src/jfw/modules/pushent/src/config.json
  38. 18 2
      src/jfw/modules/pushent/src/config/config.go
  39. 26 0
      src/jfw/modules/pushent/src/db.json
  40. 67 10
      src/jfw/modules/pushent/src/db/db.go
  41. 3 3
      src/jfw/modules/pushent/src/main.go
  42. 34 44
      src/jfw/modules/pushent/src/push/push.go
  43. 2 2
      src/jfw/modules/pushent/src/rpccall/weixinrpc.go
  44. 0 25
      src/jfw/modules/pushentniche/src/match/config.json
  45. 0 51
      src/jfw/modules/pushentniche/src/match/config/config.go
  46. 0 142
      src/jfw/modules/pushentniche/src/match/dfa/interestanalysis.go
  47. 0 45
      src/jfw/modules/pushentniche/src/match/dfa/interestanalysis_test.go
  48. 0 19
      src/jfw/modules/pushentniche/src/match/job/job.go
  49. 0 793
      src/jfw/modules/pushentniche/src/match/job/matchjob.go
  50. 0 47
      src/jfw/modules/pushentniche/src/match/job/timetask.go
  51. 0 26
      src/jfw/modules/pushentniche/src/match/main.go
  52. 0 139
      src/jfw/modules/pushentniche/src/match/matcher/entmatch.go
  53. 0 53
      src/jfw/modules/pushentniche/src/match/matcher/matcher.go
  54. 0 1
      src/jfw/modules/pushentniche/src/match/task.json
  55. 0 34
      src/jfw/modules/pushentniche/src/match/util/db.go
  56. 0 29
      src/jfw/modules/pushentniche/src/match/util/entity.go
  57. 0 202
      src/jfw/modules/pushentniche/src/public/entity.go
  58. 0 30
      src/jfw/modules/pushentniche/src/public/rpccall.go
  59. 0 59
      src/jfw/modules/pushentniche/src/public/util.go
  60. 0 32
      src/jfw/modules/pushentniche/src/push/config.json
  61. 0 114
      src/jfw/modules/pushentniche/src/push/config/config.go
  62. 0 42
      src/jfw/modules/pushentniche/src/push/job/jobs.go
  63. 0 317
      src/jfw/modules/pushentniche/src/push/job/movejob.go
  64. 0 383
      src/jfw/modules/pushentniche/src/push/job/projectjob.go
  65. 0 300
      src/jfw/modules/pushentniche/src/push/job/pushjob.go
  66. 0 64
      src/jfw/modules/pushentniche/src/push/job/timetask.go
  67. 0 39
      src/jfw/modules/pushentniche/src/push/main.go
  68. 0 1
      src/jfw/modules/pushentniche/src/push/projecttask.json
  69. 0 196
      src/jfw/modules/pushentniche/src/push/pusher/normalpush.go
  70. 0 13
      src/jfw/modules/pushentniche/src/push/pusher/pusher.go
  71. 0 123
      src/jfw/modules/pushentniche/src/push/pusher/specialpush.go
  72. 0 50
      src/jfw/modules/pushentniche/src/push/util/db.go
  73. 0 199
      src/jfw/modules/pushentniche/src/push/util/entity.go
  74. 0 91
      src/jfw/modules/pushentniche/src/push/util/excel.go
  75. 0 22
      src/jfw/modules/pushentniche/src/push/util/rpccall.go
  76. 0 311
      src/jfw/modules/pushentniche/src/push/util/util.go
  77. 0 1
      src/jfw/modules/pushentniche/src/push/xlsx/readme.txt
  78. BIN
      src/jfw/modules/pushentniche/src/push/xlsx/temp.xlsx
  79. 2 7
      src/jfw/modules/pushproject/src/config.json
  80. 19 2
      src/jfw/modules/pushproject/src/config/config.go
  81. 26 0
      src/jfw/modules/pushproject/src/db.json
  82. 67 10
      src/jfw/modules/pushproject/src/db/db.go
  83. 5 6
      src/jfw/modules/pushproject/src/main.go
  84. 36 47
      src/jfw/modules/pushproject/src/push/push.go
  85. 2 2
      src/jfw/modules/pushproject/src/rpccall/weixinrpc.go
  86. 2 2
      src/jfw/modules/pushproject/src/rpcpush/findData.go
  87. 0 5
      src/jfw/modules/pushsubscribe/src/match/config.json
  88. 0 5
      src/jfw/modules/pushsubscribe/src/match/config/config.go
  89. 26 0
      src/jfw/modules/pushsubscribe/src/match/db.json
  90. 79 0
      src/jfw/modules/pushsubscribe/src/match/db/db.go
  91. 17 18
      src/jfw/modules/pushsubscribe/src/match/job/matchjob.go
  92. 10 10
      src/jfw/modules/pushsubscribe/src/match/job/movejob.go
  93. BIN
      src/jfw/modules/pushsubscribe/src/match/match
  94. 0 30
      src/jfw/modules/pushsubscribe/src/match/util/db.go
  95. 8 7
      src/jfw/modules/pushsubscribe/src/public/util.go
  96. 0 18
      src/jfw/modules/pushsubscribe/src/push/config.json
  97. 21 41
      src/jfw/modules/pushsubscribe/src/push/config/config.go
  98. 30 0
      src/jfw/modules/pushsubscribe/src/push/db.json
  99. 95 0
      src/jfw/modules/pushsubscribe/src/push/db/db.go
  100. 16 19
      src/jfw/modules/pushsubscribe/src/push/job/nothingjob.go

+ 12 - 5
src/db.json

@@ -16,12 +16,19 @@
 			"address": "192.168.3.128:27080",
 	 		"size": 5,
 	 		"dbName": "extract_v3"
+		},
+		"bidding": {
+			"address": "192.168.3.207:27092",
+	 		"size": 5,
+	 		"dbName": "qfw_data",
+			"collection": "bidding",
+			"collection_back": "bidding_back"
 		}
 	},
 	"elasticsearch": {
 		"main": {
 			"address": "http://192.168.3.128:9800,http://192.168.3.11:9800",
-	    	"size": 30
+	    	"size": 5
 		}
     },
     "redis": {
@@ -38,16 +45,16 @@
 	        "address": "192.168.3.11:3366",
 	        "userName": "root",
 	        "passWord": "Topnet123",
-			"maxOpenConns": 500,
-			"maxIdleConns": 200
+			"maxOpenConns": 5,
+			"maxIdleConns": 5
 	    },
 		"push": {
 	        "dbName": "jianyu",
 	        "address": "192.168.3.11:3366",
 	        "userName": "root",
 	        "passWord": "Topnet123",
-			"maxOpenConns": 2000,
-			"maxIdleConns": 1000
+			"maxOpenConns": 5,
+			"maxIdleConns": 5
 	    }
     }
 }

+ 2 - 1
src/jfw/active/zqluckdraw.go

@@ -2,13 +2,14 @@ package active
 
 import (
 	"fmt"
-	"gopkg.in/mgo.v2/bson"
 	"jfw/config"
 	"jfw/wx"
 	"log"
 	"math/rand"
 	"qfw/util"
 	"time"
+
+	"go.mongodb.org/mongo-driver/bson"
 )
 
 var thankYou string = "谢谢参与"

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

@@ -11,7 +11,7 @@ import (
 	"time"
 
 	"github.com/go-xweb/xweb"
-	"gopkg.in/mgo.v2/bson"
+	"go.mongodb.org/mongo-driver/bson"
 )
 
 type Adv struct {

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

@@ -15,7 +15,7 @@ import (
 	"time"
 
 	"github.com/go-xweb/xweb"
-	"gopkg.in/mgo.v2/bson"
+	"go.mongodb.org/mongo-driver/bson"
 )
 
 type Applysub struct {

+ 9 - 5
src/jfw/front/follow.go

@@ -6,7 +6,7 @@ import (
 	public "jfw/public"
 	"jfw/wx"
 	"log"
-	. "qfw/mongodb"
+	. "mongodb"
 	"qfw/util"
 	"qfw/util/elastic"
 	"qfw/util/redis"
@@ -15,7 +15,8 @@ import (
 	"time"
 
 	"github.com/go-xweb/xweb"
-	"gopkg.in/mgo.v2/bson"
+	"go.mongodb.org/mongo-driver/bson"
+	"go.mongodb.org/mongo-driver/bson/primitive"
 )
 
 type Follow struct {
@@ -318,8 +319,9 @@ func (m *Follow) Photo(tp string) error {
 	if followid != "" {
 		id := util.DecodeArticleId2ByCheck(followid)[0]
 		fields := `{"s_id":1,"i_source":1,"s_projectname":1,"s_projectcode":1,"s_url":1,"i_remind":1,"s_type":1,"l_bidopentime":1,"l_remindtime":1,"a_relationinfo":1,"a_visited":1,"l_lastpushtime":1,"a_lastpushids":1}`
+		_id, _ := primitive.ObjectIDFromHex(id)
 		data, ok := mongodb.FindOneByField("follow_project", map[string]interface{}{
-			"_id":      bson.ObjectIdHex(id),
+			"_id":      _id,
 			"s_userid": userid,
 		}, fields)
 		m.T["isDel"] = false
@@ -539,7 +541,8 @@ func (m *Follow) AjaxReq() {
 		}
 	} else if reqType == "followset" {
 		id := util.DecodeArticleId2ByCheck(m.GetString("id"))[0]
-		if mongodb.Count("follow_project", map[string]interface{}{"_id": bson.ObjectIdHex(id), "s_userid": userId}) == 1 {
+		_id, _ := primitive.ObjectIDFromHex(id)
+		if mongodb.Count("follow_project", map[string]interface{}{"_id": _id, "s_userid": userId}) == 1 {
 			data := make(map[string]interface{})
 			data["l_updatetime"] = time.Now().Unix()
 			if remind, _ := m.GetInteger("remind"); remind == 1 {
@@ -703,8 +706,9 @@ func (m *Follow) Set(tp, id string) error {
 	id = util.DecodeArticleId2ByCheck(id)[0]
 	userid := util.ObjToString(m.GetSession("userId"))
 	fields := `{"s_id":1,"i_source":1,"s_projectname":1,"s_projectcode":1,"s_url":1,"i_remind":1,"s_type":1,"l_bidopentime":1,"l_remindtime":1,"a_relationinfo":1,"a_visited":1,"l_lastpushtime":1,"a_lastpushids":1}`
+	_id, _ := primitive.ObjectIDFromHex(id)
 	data, ok := mongodb.FindOneByField("follow_project", map[string]interface{}{
-		"_id":      bson.ObjectIdHex(id),
+		"_id":      _id,
 		"s_userid": userid,
 	}, fields)
 	if ok && (data == nil || len(*data) == 0) {

+ 11 - 12
src/jfw/front/front.go

@@ -9,7 +9,7 @@ import (
 	"jfw/wx"
 	"log"
 	"math/rand"
-	. "qfw/mongodb"
+	. "mongodb"
 
 	//	"net/url"
 	"regexp"
@@ -26,7 +26,8 @@ import (
 
 	"github.com/go-xweb/httpsession"
 	"github.com/go-xweb/xweb"
-	"gopkg.in/mgo.v2/bson"
+	"go.mongodb.org/mongo-driver/bson"
+	"go.mongodb.org/mongo-driver/bson/primitive"
 )
 
 type userPool struct {
@@ -217,9 +218,9 @@ func (p *Front) PayIndex() error {
 	id := util.DecodeArticleId2ByCheck(params[1])[0]
 	title := ""
 	if id != "" {
-		data, ok := public.MQFW.FindById("bidding", id, `{"title":1}`)
+		data, ok := public.Mgo_Bidding.FindById(public.DbConf.Mongodb.Bidding.Collection, id, `{"title":1}`)
 		if ok && (data == nil || *data == nil || len(*data) == 0) {
-			data, ok = public.MQFW.FindById("bidding_back", id, `{"title":1}`)
+			data, ok = public.Mgo_Bidding.FindById(public.DbConf.Mongodb.Bidding.Collection_back, id, `{"title":1}`)
 		}
 		if ok && data != nil && len(*data) > 0 {
 			title, _ = (*data)["title"].(string)
@@ -286,9 +287,9 @@ func (f *Front) RecInof() error {
 		if ok && (*brobj) != nil && len(*brobj) == 1 && (*brobj)[0] != nil {
 			obj = (*brobj)[0]
 		} else {
-			aobj, ok := mongodb.FindById("bidding", id, nil)
+			aobj, ok := public.Mgo_Bidding.FindById(public.DbConf.Mongodb.Bidding.Collection, id, nil)
 			if ok && (aobj == nil || *aobj == nil || len(*aobj) == 0) {
-				aobj, ok = mongodb.FindById("bidding_back", id, nil)
+				aobj, ok = public.Mgo_Bidding.FindById(public.DbConf.Mongodb.Bidding.Collection_back, id, nil)
 			}
 			obj = *aobj
 		}
@@ -364,13 +365,11 @@ func updateLastWrongField(id, result string) {
 	if result == "" {
 		return
 	}
-	mongodb.Update("bidding", map[string]interface{}{
-		"_id": bson.ObjectIdHex(id),
-	}, map[string]interface{}{
+	public.Mgo_Bidding.UpdateById(public.DbConf.Mongodb.Bidding.Collection, id, map[string]interface{}{
 		"$set": map[string]interface{}{
 			"lastwrongfield": result,
 		},
-	}, false, false)
+	})
 }
 
 //轮询查登录状态
@@ -771,7 +770,7 @@ func FindUserAndCreateSess(openid string, sess *httpsession.Session) (bool, *map
 	}, sess)
 }
 
-func FindUserAndCreateSessById(userId bson.ObjectId, sess *httpsession.Session) (bool, *map[string]interface{}, map[string]interface{}) {
+func FindUserAndCreateSessById(userId primitive.ObjectID, sess *httpsession.Session) (bool, *map[string]interface{}, map[string]interface{}) {
 	return CreateSession(map[string]interface{}{
 		"_id": userId,
 	}, sess)
@@ -790,7 +789,7 @@ func CreateSession(q map[string]interface{}, sess *httpsession.Session) (bool, *
 		sess.Set("shareknow", (*person)["i_shareknow"])
 	}
 	openid, _ := (*person)["s_m_openid"].(string)
-	sess.Set("userId", ((*person)["_id"].(bson.ObjectId)).Hex())
+	sess.Set("userId", ((*person)["_id"].(primitive.ObjectID)).Hex())
 	nickName, _ := (*person)["s_nickname"].(string)
 	if nickName == "" {
 		if phone, _ := (*person)["s_phone"].(string); phone != "" && len(phone) > 3 {

+ 2 - 2
src/jfw/front/login.go

@@ -11,7 +11,7 @@ import (
 	"github.com/dchest/captcha"
 	"github.com/go-xweb/httpsession"
 	"github.com/go-xweb/xweb"
-	"gopkg.in/mgo.v2/bson"
+	"go.mongodb.org/mongo-driver/bson/primitive"
 )
 
 type Login struct {
@@ -238,5 +238,5 @@ func afterLogin(phone string, session *httpsession.Session) (bool, *map[string]i
 	if user == nil || len(user) == 0 {
 		return false, nil, nil
 	}
-	return FindUserAndCreateSessById(user["_id"].(bson.ObjectId), session)
+	return FindUserAndCreateSessById(user["_id"].(primitive.ObjectID), session)
 }

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

@@ -7,8 +7,8 @@ import (
 	"jfw/jyutil"
 	"jfw/public"
 	"log"
+	. "mongodb"
 	"net/url"
-	. "qfw/mongodb"
 	"qfw/util"
 	"qfw/util/jy"
 	"qfw/util/redis"
@@ -346,7 +346,7 @@ func (l *PcHelper) PushView() error {
 	if userid != "" {
 		user, _ := jy.SubscribePush.UserInfo(public.MQFW, userid)
 		if user != nil {
-			hasNextPage, list := jy.SubscribePush.Datas(public.MQFW, public.PushMysql, userid, pageNum, "", "")
+			hasNextPage, list := jy.SubscribePush.Datas(public.Mgo_Bidding, public.DbConf.Mongodb.Bidding.Collection, public.DbConf.Mongodb.Bidding.Collection_back, public.PushMysql, userid, pageNum, "", "")
 			//hasNextPage, list, _ := public.HistoryPush.Datas(userid, pageNum, firstPushTime, "")
 			res["hasNextPage"] = hasNextPage
 			res["data"] = &list

+ 4 - 3
src/jfw/front/search.go

@@ -2,10 +2,12 @@ package front
 
 import (
 	"fmt"
-	"github.com/go-xweb/log"
 	"jfw/jyutil"
 	"net/url"
 	"time"
+
+	"github.com/go-xweb/log"
+
 	//	"fmt"
 	"jfw/wx"
 	//	"log"
@@ -15,7 +17,6 @@ import (
 	"strings"
 
 	"github.com/go-xweb/xweb"
-	"gopkg.in/mgo.v2/bson"
 )
 
 type Search struct {
@@ -135,7 +136,7 @@ func (s *Search) GetHK() error {
 			history = strings.Split(h, ",")
 		}
 		//我的订阅
-		one, _ := mongodb.FindOneByField("user", bson.M{"_id": bson.ObjectIdHex(userid.(string))}, `{"o_jy":1}`)
+		one, _ := mongodb.FindById("user", userid.(string), `{"o_jy":1}`)
 		if one != nil && len(*one) > 0 {
 			o_jy, _ := (*one)["o_jy"].(map[string]interface{})
 			a_key, _ := o_jy["a_key"].([]interface{})

+ 2 - 2
src/jfw/front/shorturl.go

@@ -7,8 +7,8 @@ import (
 	"jfw/public"
 	"jfw/wx"
 	"math/rand"
+	. "mongodb"
 	"net/url"
-	. "qfw/mongodb"
 	"qfw/util"
 	"qfw/util/redis"
 	"regexp"
@@ -17,7 +17,7 @@ import (
 
 	"github.com/SKatiyar/qr"
 	"github.com/go-xweb/xweb"
-	"gopkg.in/mgo.v2/bson"
+	"go.mongodb.org/mongo-driver/bson"
 )
 
 type Short struct {

+ 7 - 8
src/jfw/front/singleLogin.go

@@ -2,20 +2,19 @@ package front
 
 import (
 	"fmt"
+	"jfw/config"
+	"jfw/jyutil"
 	"jfw/public"
+	"log"
 	"net/url"
+	qutil "qfw/util"
 	"qfw/util/redis"
 	"time"
 
 	"github.com/go-xweb/httpsession"
-
-	"jfw/config"
-	"jfw/jyutil"
-	"log"
-	qutil "qfw/util"
-
 	"github.com/go-xweb/xweb"
-	"gopkg.in/mgo.v2/bson"
+	"go.mongodb.org/mongo-driver/bson"
+	"go.mongodb.org/mongo-driver/bson/primitive"
 )
 
 type SingleLogin struct {
@@ -75,7 +74,7 @@ func loginCreateSess(openid string, sess *httpsession.Session) bool {
 		if person["i_shareknow"] != nil {
 			sess.Set("shareknow", person["i_shareknow"])
 		}
-		sess.Set("userId", (person["_id"].(bson.ObjectId)).Hex())
+		sess.Set("userId", (person["_id"].(primitive.ObjectID)).Hex())
 		sess.Set("s_m_openid", person["s_m_openid"])
 		sess.Set("openid", person["s_m_openid"])
 		sess.Set("s_nickname", person["s_nickname"])

+ 6 - 3
src/jfw/front/structedData.go

@@ -11,7 +11,8 @@ import (
 	"time"
 
 	"github.com/go-xweb/xweb"
-	"gopkg.in/mgo.v2/bson"
+	"go.mongodb.org/mongo-driver/bson"
+	"go.mongodb.org/mongo-driver/bson/primitive"
 )
 
 type StructedData struct {
@@ -183,7 +184,8 @@ func (t *StructedData) Pc_info() error {
 		t.DelSession("SMVerifySucess")
 		t.DelSession("CreatSMVerifyTime")
 		t.DelSession("DataSMVerifyEmail")
-		nums, ok := public.MQFW.FindOne("user", bson.M{"_id": bson.ObjectIdHex(userId)})
+		_id, _ := primitive.ObjectIDFromHex(userId)
+		nums, ok := public.MQFW.FindOne("user", bson.M{"_id": _id})
 		if !ok {
 			return t.Redirect("/front/aboutus.html")
 		}
@@ -236,7 +238,8 @@ func (t *StructedData) CheckUser() error {
 		t.DelSession("SMVerifySucess")
 		t.DelSession("CreatSMVerifyTime")
 		t.DelSession("DataSMVerifyEmail")
-		nums, ok := public.MQFW.FindOne("user", bson.M{"_id": bson.ObjectIdHex(userId)})
+		_id, _ := primitive.ObjectIDFromHex(userId)
+		nums, ok := public.MQFW.FindOne("user", bson.M{"_id": _id})
 		if !ok {
 			return t.Redirect("/swordfish/about?source=open_infocontent&o=-130")
 		}

+ 13 - 13
src/jfw/front/swordfish.go

@@ -12,8 +12,8 @@ import (
 	"jfw/wx"
 	"log"
 	"math/rand"
+	. "mongodb"
 	"net/url"
-	. "qfw/mongodb"
 	"qfw/util"
 	"qfw/util/elastic"
 	"qfw/util/redis"
@@ -29,7 +29,8 @@ import (
 	"github.com/go-xweb/httpsession"
 	"github.com/go-xweb/xweb"
 	. "github.com/thinxer/go-word2vec"
-	"gopkg.in/mgo.v2/bson"
+	"go.mongodb.org/mongo-driver/bson"
+	"go.mongodb.org/mongo-driver/bson/primitive"
 )
 
 const (
@@ -827,7 +828,7 @@ func (m *Front) WxsearchlistPaging() {
 	pageNum, _ := m.GetInteger("pageNum")
 	if userid != nil && pageNum <= wx_maxPageNum {
 		//历史记录和订阅查询
-		one, _ := mongodb.FindOneByField("user", bson.M{"_id": bson.ObjectIdHex(userid.(string))}, `{"o_jy":1}`)
+		one, _ := mongodb.FindById("user", userid.(string), `{"o_jy":1}`)
 		history := redis.GetStr("other", "s_"+userid.(string))
 		arrs := strings.Split(history, ",")
 		searchvalue := strings.TrimSpace(m.GetString("searchvalue"))
@@ -1054,9 +1055,9 @@ func wxvisitD(sid, userId, openId string) (objdata map[string]interface{}) {
 		if ok && (*brobj) != nil && len(*brobj) == 1 && (*brobj)[0] != nil {
 			obj = (*brobj)[0]
 		} else {
-			aobj, ok := mongodb.FindById("bidding", sid, nil)
+			aobj, ok := public.Mgo_Bidding.FindById(public.DbConf.Mongodb.Bidding.Collection, sid, nil)
 			if ok && (aobj == nil || *aobj == nil || len(*aobj) == 0) {
-				aobj, ok = mongodb.FindById("bidding_back", sid, nil)
+				aobj, ok = public.Mgo_Bidding.FindById(public.DbConf.Mongodb.Bidding.Collection_back, sid, nil)
 			}
 			//aobj, ok := elastic.GetByIdField("bidding", "bidding", sid, ""), true
 			obj = *aobj
@@ -1212,15 +1213,13 @@ func pcVRT(sid, industry string) (po, bo, wo []map[string]interface{}, objdata m
 	var projectOther, buyerOther, winnerOther []map[string]interface{}
 	var obj map[string]interface{}
 	if len(sid) > 5 {
-		coll := "bidding"
 		brobj, ok := mongodb.Find("bidding_rec", bson.M{"s_id": sid}, `{"l_recoverydate":-1}`, nil, false, 0, 1)
 		if ok && (*brobj) != nil && len(*brobj) == 1 && (*brobj)[0] != nil {
 			obj = (*brobj)[0]
 		} else {
-			aobj, ok := mongodb.FindById(coll, sid, nil)
+			aobj, ok := public.Mgo_Bidding.FindById(public.DbConf.Mongodb.Bidding.Collection, sid, nil)
 			if ok && (aobj == nil || *aobj == nil || len(*aobj) == 0) {
-				coll = "bidding_back"
-				aobj, ok = mongodb.FindById(coll, sid, nil)
+				aobj, ok = public.Mgo_Bidding.FindById(public.DbConf.Mongodb.Bidding.Collection_back, sid, nil)
 			}
 			obj = *aobj
 		}
@@ -1796,12 +1795,13 @@ func (m *Front) AboutSR() error {
 //手动删除30天无更新数据
 func (m *Front) DelOL() error {
 	defer util.Catch()
-	var ids []bson.ObjectId
+	var ids []primitive.ObjectID
 	var flag = "F"
 	var arrid = strings.Split(m.GetString("arrid"), ",")
 	if len(arrid) > 0 {
 		for _, chid := range arrid {
-			ids = append(ids, bson.ObjectIdHex(util.DecodeArticleId2ByCheck(chid)[0]))
+			_id, _ := primitive.ObjectIDFromHex(util.DecodeArticleId2ByCheck(chid)[0])
+			ids = append(ids, _id)
 		}
 	}
 	userId, ok := m.GetSession("userId").(string)
@@ -2491,7 +2491,7 @@ func (f *Front) HasPushHistory() {
 		pageNum = 1
 	}
 	area := f.GetString("area")
-	hasNextPage, list := jy.SubscribePush.Datas(public.MQFW, public.PushMysql, userId, pageNum, formatTime, area)
+	hasNextPage, list := jy.SubscribePush.Datas(public.Mgo_Bidding, public.DbConf.Mongodb.Bidding.Collection, public.DbConf.Mongodb.Bidding.Collection_back, public.PushMysql, userId, pageNum, formatTime, area)
 	if hasKeyFlag && len(list) == 0 && formatTime == "" && area == "" && !isVipFlag {
 		flag, data := jy.SubscribePush.MakeHistoryDatas(public.MQFW, public.PushMysql, userId, public.PushView)
 		if flag && data != nil {
@@ -2579,7 +2579,7 @@ func (f *Front) HistorypushPaging() error {
 		//		if user == nil {
 		//			return nil
 		//		}
-		hasNextPage, list := jy.SubscribePush.Datas(public.MQFW, public.PushMysql, userId, pageNum, formatTime, area)
+		hasNextPage, list := jy.SubscribePush.Datas(public.Mgo_Bidding, public.DbConf.Mongodb.Bidding.Collection, public.DbConf.Mongodb.Bidding.Collection, public.PushMysql, userId, pageNum, formatTime, area)
 		//		hasNextPage, list, _ := public.HistoryPush.Datas(userId, pageNum, firstPushTime, formatTime)
 		f.ServeJson(map[string]interface{}{
 			"hasNextPage": hasNextPage,

+ 3 - 1
src/jfw/front/ws_dataExport.go

@@ -9,7 +9,7 @@ import (
 	"strconv"
 
 	"github.com/go-xweb/xweb"
-	"gopkg.in/mgo.v2/bson"
+
 	//	"jfw/pay"
 	"jfw/public"
 	"jfw/wx"
@@ -20,6 +20,8 @@ import (
 	"qfw/util/redis"
 	"strings"
 	"time"
+
+	"go.mongodb.org/mongo-driver/bson"
 )
 
 type WsDataExport struct {

+ 4 - 4
src/jfw/front/wxMyOrder.go

@@ -3,8 +3,6 @@ package front
 import (
 	"errors"
 	"fmt"
-	"github.com/go-xweb/xweb"
-	"gopkg.in/mgo.v2/bson"
 	"jfw/config"
 	"jfw/jyutil"
 	"jfw/public"
@@ -12,6 +10,8 @@ import (
 	"log"
 	"net/url"
 	"qfw/util"
+
+	"github.com/go-xweb/xweb"
 )
 
 type WxMyOrder struct {
@@ -70,7 +70,7 @@ func (w *WxMyOrder) MyMenu() error {
 		}
 	}
 	//检测用户是否绑定邮箱
-	res, err := mongodb.FindOne("user", bson.M{"_id": bson.ObjectIdHex(util.ObjToString(w.GetSession("userId")))})
+	res, err := mongodb.FindById("user", util.ObjToString(w.GetSession("userId")), nil)
 	if len(*res) > 0 && err {
 		if util.ObjToString((*res)["s_myemail"]) == "" {
 			w.T["isNoEmail"] = true
@@ -112,7 +112,7 @@ func (w *WxMyOrder) MyEmail() {
 	if util.ObjToString(w.GetSession("userId")) != "" {
 		w.T["userId"] = util.ObjToString(w.GetSession("userId"))
 	}
-	res, err := mongodb.FindOne("user", bson.M{"_id": bson.ObjectIdHex(util.ObjToString(w.GetSession("userId")))})
+	res, err := mongodb.FindById("user", util.ObjToString(w.GetSession("userId")), nil)
 	if len(*res) > 0 && err {
 		if util.ObjToString((*res)["s_myemail"]) == "" || name != "" {
 			//未绑定邮箱 进入绑定邮箱界面

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

@@ -11,7 +11,7 @@ import (
 	"time"
 
 	"github.com/go-xweb/xweb"
-	"gopkg.in/mgo.v2/bson"
+	"go.mongodb.org/mongo-driver/bson"
 )
 
 type WxDataExport struct {

+ 3 - 3
src/jfw/jyutil/sessionkeep.go

@@ -11,7 +11,7 @@ import (
 
 	"github.com/go-xweb/httpsession"
 	"github.com/go-xweb/xweb"
-	"gopkg.in/mgo.v2/bson"
+	"go.mongodb.org/mongo-driver/bson/primitive"
 )
 
 //session保持
@@ -60,7 +60,7 @@ func (sk *SessionKeep) Do(w http.ResponseWriter, r *http.Request) bool {
 					"s_m_openid": deuserid,
 				}, `{"_id":1}`)
 				if ok && user != nil && len(*user) > 0 {
-					session.Set("userId", ((*user)["_id"].(bson.ObjectId)).Hex())
+					session.Set("userId", ((*user)["_id"].(primitive.ObjectID)).Hex())
 				}
 			}
 			flag = 1
@@ -95,7 +95,7 @@ func (sk *SessionKeep) Do(w http.ResponseWriter, r *http.Request) bool {
 					if (*user)["i_shareknow"] != nil {
 						session.Set("shareknow", (*user)["i_shareknow"])
 					}
-					deuserid = ((*user)["_id"].(bson.ObjectId)).Hex()
+					deuserid = ((*user)["_id"].(primitive.ObjectID)).Hex()
 					session.Set("userId", deuserid)
 					if (*user)["s_avatar"] == nil {
 						session.Set("s_avatar", (*user)["s_headimage"])

+ 4 - 3
src/jfw/modules/app/src/app/followent/followent.go

@@ -4,14 +4,14 @@ import (
 	"app/jylabutil"
 	"jfw/config"
 	"jfw/public"
-	. "qfw/mongodb"
+	. "mongodb"
 	"qfw/util"
 	"qfw/util/redis"
 	"strconv"
 	"strings"
 
 	"github.com/go-xweb/xweb"
-	"gopkg.in/mgo.v2/bson"
+	"go.mongodb.org/mongo-driver/bson/primitive"
 )
 
 var mongodb = public.MQFW
@@ -103,8 +103,9 @@ func (f *FollowEnt) Detail(followId string) error {
 	followId = util.DecodeArticleId2ByCheck(followId)[0]
 	winner := ""
 	var a_visited interface{}
+	_id, _ := primitive.ObjectIDFromHex(followId)
 	oneQy, ok := mongodb.FindOneByField("jylab_followent", map[string]interface{}{
-		"_id":      bson.ObjectIdHex(followId),
+		"_id":      _id,
 		"s_userid": userId,
 	}, `{"s_entname":1,"s_id":1,"a_visited":1}`)
 	follow := "n"

+ 5 - 3
src/jfw/modules/app/src/app/followent/myfwent.go

@@ -8,7 +8,8 @@ import (
 	"time"
 
 	"github.com/go-xweb/xweb"
-	"gopkg.in/mgo.v2/bson"
+	"go.mongodb.org/mongo-driver/bson"
+	"go.mongodb.org/mongo-driver/bson/primitive"
 )
 
 type Myfwent struct {
@@ -53,10 +54,11 @@ func (m *Myfwent) Addfwent() error {
 //删除30无更新数据的企业
 func (m *Myfwent) DelOvertimeCompany() error {
 	defer util.Catch()
-	var ids []bson.ObjectId
+	var ids []primitive.ObjectID
 	var flag = "F"
 	for _, chid := range strings.Split(m.GetString("arrid"), ",") {
-		ids = append(ids, bson.ObjectIdHex(util.DecodeArticleId2ByCheck(chid)[0]))
+		_id, _ := primitive.ObjectIDFromHex(util.DecodeArticleId2ByCheck(chid)[0])
+		ids = append(ids, _id)
 	}
 	userId, _ := m.GetSession("userId").(string)
 	if userId == "" || len(ids) == 0 {

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

@@ -10,7 +10,7 @@ import (
 	"time"
 
 	"github.com/go-xweb/xweb"
-	"gopkg.in/mgo.v2/bson"
+	"go.mongodb.org/mongo-driver/bson"
 )
 
 type WxDataExport struct {

+ 13 - 13
src/jfw/modules/app/src/app/front/follow.go

@@ -4,7 +4,7 @@ import (
 	"jfw/config"
 	public "jfw/public"
 	"log"
-	. "qfw/mongodb"
+	. "mongodb"
 	"qfw/util"
 	"qfw/util/elastic"
 	"qfw/util/redis"
@@ -13,7 +13,8 @@ import (
 	"time"
 
 	"github.com/go-xweb/xweb"
-	"gopkg.in/mgo.v2/bson"
+	"go.mongodb.org/mongo-driver/bson"
+	"go.mongodb.org/mongo-driver/bson/primitive"
 )
 
 type Follow struct {
@@ -191,8 +192,9 @@ func (m *Follow) Photo(tp string) error {
 	if followid != "" {
 		id := util.DecodeArticleId2ByCheck(followid)[0]
 		fields := `{"s_id":1,"i_source":1,"s_projectname":1,"s_projectcode":1,"s_url":1,"i_remind":1,"s_type":1,"l_bidopentime":1,"l_remindtime":1,"a_relationinfo":1,"a_visited":1,"l_lastpushtime":1,"a_lastpushids":1}`
+		_id, _ := primitive.ObjectIDFromHex(id)
 		data, ok := mongodb.FindOneByField("follow_project", map[string]interface{}{
-			"_id":      bson.ObjectIdHex(id),
+			"_id":      _id,
 			"s_userid": m.GetSession("userId").(string),
 		}, fields)
 		m.T["isDel"] = false
@@ -410,7 +412,8 @@ func (m *Follow) AjaxReq() {
 		}
 	} else if reqType == "followset" {
 		id := util.DecodeArticleId2ByCheck(m.GetString("id"))[0]
-		if mongodb.Count("follow_project", map[string]interface{}{"_id": bson.ObjectIdHex(id), "s_userid": userId}) == 1 {
+		_id, _ := primitive.ObjectIDFromHex(id)
+		if mongodb.Count("follow_project", map[string]interface{}{"_id": _id, "s_userid": userId}) == 1 {
 			data := make(map[string]interface{})
 			data["l_updatetime"] = time.Now().Unix()
 			if remind, _ := m.GetInteger("remind"); remind == 1 {
@@ -562,8 +565,9 @@ func (m *Follow) Set(tp, id string) error {
 	isDel := false
 	id = util.DecodeArticleId2ByCheck(id)[0]
 	fields := `{"s_id":1,"i_source":1,"s_projectname":1,"s_projectcode":1,"s_url":1,"i_remind":1,"s_type":1,"l_bidopentime":1,"l_remindtime":1,"a_relationinfo":1,"a_visited":1,"l_lastpushtime":1,"a_lastpushids":1}`
+	_id, _ := primitive.ObjectIDFromHex(id)
 	data, ok := mongodb.FindOneByField("follow_project", map[string]interface{}{
-		"_id":      bson.ObjectIdHex(id),
+		"_id":      _id,
 		"s_userid": m.GetSession("userId").(string),
 	}, fields)
 	if ok && (data == nil || len(*data) == 0) {
@@ -674,13 +678,11 @@ func (m *Follow) Set(tp, id string) error {
 			m.T["l_remindtime"] = date.Unix()
 		}
 		//
-		mongodb.Update("follow_project", map[string]interface{}{
-			"_id": bson.ObjectIdHex(id),
-		}, map[string]interface{}{
+		mongodb.UpdateById("follow_project", id, map[string]interface{}{
 			"$set": map[string]interface{}{
 				"i_apppushunread": 0,
 			},
-		}, false, false)
+		})
 	}
 	m.T["projectname"] = projectname
 	m.T["projectcode"] = projectcode
@@ -720,13 +722,11 @@ func (m *Follow) AllNotice() error {
 }
 func (m *Follow) Notice(id, followId string) error {
 	defer util.Catch()
-	go mongodb.Update("follow_project", map[string]interface{}{
-		"_id": bson.ObjectIdHex(followId),
-	}, map[string]interface{}{
+	go mongodb.UpdateById("follow_project", followId, map[string]interface{}{
 		"$set": map[string]interface{}{
 			"i_apppushunread": 0,
 		},
-	}, false, false)
+	})
 	userid, _ := m.GetSession("userId").(string)
 	var query map[string]interface{}
 	if len(id) == 19 {

+ 4 - 4
src/jfw/modules/app/src/app/front/front.go

@@ -16,7 +16,7 @@ import (
 
 	"github.com/dchest/captcha"
 	"github.com/go-xweb/xweb"
-	"gopkg.in/mgo.v2/bson"
+	"go.mongodb.org/mongo-driver/bson"
 )
 
 type Front struct {
@@ -144,7 +144,7 @@ func (m *Front) Receive() error {
 	log.Println(url_mid, "---", recType, "---", userId)
 	if recType == "D" && mid != "" && len([]rune(mid)) > 12 {
 		field := "i_delivery"
-		ok = mongodb.Update("message_app", map[string]interface{}{"_id": bson.ObjectIdHex(mid)}, map[string]interface{}{"$inc": map[string]interface{}{field: 1}}, false, false)
+		ok = mongodb.UpdateById("message_app", mid, map[string]interface{}{"$inc": map[string]interface{}{field: 1}})
 	} else if recType == "C" && mid != "" && len([]rune(mid)) > 12 {
 		field := "i_click"
 		//打开计算一次 是否已经打开过
@@ -164,7 +164,7 @@ func (m *Front) Receive() error {
 				},
 			}, false, false)
 			//信息总量打开率+1
-			ok = mongodb.Update("message_app", map[string]interface{}{"_id": bson.ObjectIdHex(mid)}, map[string]interface{}{"$inc": map[string]interface{}{field: 1}}, false, false)
+			ok = mongodb.UpdateById("message_app", mid, map[string]interface{}{"$inc": map[string]interface{}{field: 1}})
 		}
 	} else if recType == "A" && mid != "" && len([]rune(mid)) > 12 {
 		field := "i_delivery"
@@ -175,7 +175,7 @@ func (m *Front) Receive() error {
 			"s_userid": userId,
 			"i_unread": 1, //1:未打开;0:已打开
 		}); c == 1 {
-			ok = mongodb.Update("message_app", map[string]interface{}{"_id": bson.ObjectIdHex(mid)}, map[string]interface{}{"$inc": map[string]interface{}{field: 1, field1: 1}}, false, false)
+			ok = mongodb.UpdateById("message_app", mid, map[string]interface{}{"$inc": map[string]interface{}{field: 1, field1: 1}})
 			mongodb.Update("jyapp_notice", map[string]interface{}{
 				"s_id":     mid, //信息id
 				"s_userid": userId,

+ 6 - 4
src/jfw/modules/app/src/app/front/login.go

@@ -7,8 +7,8 @@ import (
 	"fmt"
 	"jfw/config"
 	"log"
+	. "mongodb"
 	"net/http"
-	. "qfw/mongodb"
 	qutil "qfw/util"
 	"qfw/util/jy"
 	"qfw/util/redis"
@@ -21,7 +21,8 @@ import (
 	"github.com/dchest/captcha"
 	"github.com/go-xweb/httpsession"
 	"github.com/go-xweb/xweb"
-	"gopkg.in/mgo.v2/bson"
+	"go.mongodb.org/mongo-driver/bson"
+	"go.mongodb.org/mongo-driver/bson/primitive"
 )
 
 //用户信息
@@ -866,7 +867,7 @@ func createSession(s *httpsession.Session, person map[string]interface{}, loginI
 		}
 		switch loginType {
 		case 0: //_id登录
-			query["_id"] = bson.ObjectIdHex(loginId)
+			query["_id"], _ = primitive.ObjectIDFromHex(loginId)
 			break
 		case 1: //s_phone登录
 			query["s_phone"] = loginId
@@ -1229,9 +1230,10 @@ func UpdateRid_C(sess *httpsession.Session, rid, oid, phoneType, version string)
 	if userid == "" {
 		return ""
 	}
+	_id, _ := primitive.ObjectIDFromHex(userid)
 	update_query := map[string]interface{}{
 		"_id": map[string]interface{}{
-			"$ne": bson.ObjectIdHex(userid),
+			"$ne": _id,
 		},
 		"i_appid": 2,
 	}

+ 4 - 3
src/jfw/modules/app/src/app/front/logoffuser.go

@@ -7,9 +7,9 @@ import (
 	qutil "qfw/util"
 	"time"
 
-	"gopkg.in/mgo.v2/bson"
-
 	"github.com/go-xweb/xweb"
+	"go.mongodb.org/mongo-driver/bson"
+	"go.mongodb.org/mongo-driver/bson/primitive"
 )
 
 //APP用户账号注销
@@ -122,8 +122,9 @@ func LogOffAppUser(user_id, cause string) bool {
 	ok := mongodb.Save("delete_user", delete_data)
 	if ok != "" {
 		//删除以前数据
+		_id, _ := primitive.ObjectIDFromHex(user_id)
 		if mongodb.Del("user", map[string]interface{}{
-			"_id": bson.ObjectIdHex(user_id),
+			"_id": _id,
 			// "_id": bson.ObjectIdHex(ok),
 		}) {
 			return true

+ 2 - 3
src/jfw/modules/app/src/app/front/me.go

@@ -14,9 +14,8 @@ import (
 	"sync"
 	"time"
 
-	"gopkg.in/mgo.v2/bson"
-
 	"github.com/go-xweb/xweb"
+	"go.mongodb.org/mongo-driver/bson"
 )
 
 type Me struct {
@@ -59,7 +58,7 @@ func (m *Me) MeIndex() error {
 	log.Println("userid:", userid)
 	//检测用户是否绑定邮箱
 	if userid != "" {
-		res, err := mongodb.FindOne("user", bson.M{"_id": bson.ObjectIdHex(userid)})
+		res, err := mongodb.FindById("user", userid, nil)
 		if len(*res) > 0 && err {
 			if qutil.ObjToString((*res)["s_myemail"]) == "" {
 				m.T["isNoEmail"] = true

+ 6 - 8
src/jfw/modules/app/src/app/front/myorder.go

@@ -7,18 +7,16 @@ import (
 	"strconv"
 	"strings"
 
-	"gopkg.in/mgo.v2/bson"
-
 	"github.com/go-xweb/xweb"
 )
 
 type MyOrder struct {
 	*xweb.Action
-	toMyOrder     xweb.Mapper `xweb:"/jyapp/front/myOrder/toMyOrder"`                  //我的订单
-	getOrderCode  xweb.Mapper `xweb:"/jyapp/front/myOrder/getOrderCode/(\\w+)"`        //申请发票获取订单编号
-	paySuccess    xweb.Mapper `xweb:"/jyapp/front/myorder/paySuccess/(\\w+)"`          //支付成功发票
-	deleteOrder   xweb.Mapper `xweb:"/jyapp/front/myorder/deleteOrder"`                //删除订单
-	getOneMore    xweb.Mapper `xweb:"/jyapp/front/myorder/getOneMore"`                 //获取额外一条数据
+	toMyOrder    xweb.Mapper `xweb:"/jyapp/front/myOrder/toMyOrder"`           //我的订单
+	getOrderCode xweb.Mapper `xweb:"/jyapp/front/myOrder/getOrderCode/(\\w+)"` //申请发票获取订单编号
+	paySuccess   xweb.Mapper `xweb:"/jyapp/front/myorder/paySuccess/(\\w+)"`   //支付成功发票
+	deleteOrder  xweb.Mapper `xweb:"/jyapp/front/myorder/deleteOrder"`         //删除订单
+	getOneMore   xweb.Mapper `xweb:"/jyapp/front/myorder/getOneMore"`          //获取额外一条数据
 	//我的邮箱
 	myEmail    xweb.Mapper `xweb:"/jyapp/front/myorder/myEmail"`    //我的邮箱
 	setSuccess xweb.Mapper `xweb:"/jyapp/front/myorder/setSuccess"` //查询订单
@@ -119,7 +117,7 @@ func (m *MyOrder) MyEmail() {
 	if util.ObjToString(m.GetSession("userId")) != "" {
 		m.T["userId"] = util.ObjToString(m.GetSession("userId"))
 	}
-	res, err := mongodb.FindOne("user", bson.M{"_id": bson.ObjectIdHex(util.ObjToString(m.GetSession("userId")))})
+	res, err := mongodb.FindById("user", util.ObjToString(m.GetSession("userId")), nil)
 	if len(*res) > 0 && err {
 		if util.ObjToString((*res)["s_myemail"]) == "" || name != "" {
 			//未绑定邮箱 进入绑定邮箱界面

+ 1 - 2
src/jfw/modules/app/src/app/front/search.go

@@ -12,7 +12,6 @@ import (
 	"time"
 
 	"github.com/go-xweb/xweb"
-	"gopkg.in/mgo.v2/bson"
 )
 
 type Search struct {
@@ -117,7 +116,7 @@ func (s *Search) GetHK() error {
 		redis.Del("other", "s_"+userid)
 		redis.Put("other", "s_"+userid, strings.Join(arrs, ","), -1)
 		//我的订阅
-		one, _ := mongodb.FindOneByField("user", bson.M{"_id": bson.ObjectIdHex(userid)}, `{"o_jy":1}`)
+		one, _ := mongodb.FindById("user", userid, `{"o_jy":1}`)
 		if one != nil && len(*one) > 0 {
 			o_jy, _ := (*one)["o_jy"].(map[string]interface{})
 			a_key, _ := o_jy["a_key"].([]interface{})

+ 6 - 8
src/jfw/modules/app/src/app/front/shorturl.go

@@ -1,20 +1,17 @@
 package front
 
 import (
-	"jfw/config"
-	"time"
-
-	//"math/rand"
 	. "app/jyutil"
+	"jfw/config"
 	"jfw/public"
 	"qfw/util"
 	"qfw/util/redis"
 	"regexp"
-
-	//"time"
+	"time"
 
 	"github.com/go-xweb/xweb"
-	"gopkg.in/mgo.v2/bson"
+	"go.mongodb.org/mongo-driver/bson"
+	"go.mongodb.org/mongo-driver/bson/primitive"
 )
 
 type Short struct {
@@ -47,7 +44,8 @@ func (s *Short) Article(stype, id string) error {
 	}
 	//判断用户是否是vip用户
 	isVip := false
-	vip_status, _ := mongodb.FindOne("user", bson.M{"_id": bson.ObjectIdHex(userId), "i_vip_status": bson.M{"$in": []int{1, 2}}}) //获取vip标志
+	_id, _ := primitive.ObjectIDFromHex(userId)
+	vip_status, _ := mongodb.FindOne("user", bson.M{"_id": _id, "i_vip_status": bson.M{"$in": []int{1, 2}}}) //获取vip标志
 
 	if len(*vip_status) > 1 {
 		isVip = true

+ 1 - 2
src/jfw/modules/app/src/app/front/structedData.go

@@ -11,7 +11,6 @@ import (
 	"time"
 
 	"github.com/go-xweb/xweb"
-	"gopkg.in/mgo.v2/bson"
 )
 
 type StructedData struct {
@@ -248,7 +247,7 @@ func (t *StructedData) WriteInfo() error {
 		t.DelSession("SMVerifySucess")
 		t.DelSession("CreatSMVerifyTime")
 		t.DelSession("DataSMVerifyEmail")
-		nums, ok := public.MQFW.FindOne("user", bson.M{"_id": bson.ObjectIdHex(userId)})
+		nums, ok := public.MQFW.FindById("user", userId, nil)
 		if !ok {
 			return t.Redirect("/jyapp/free/swordfish/about", 302)
 		}

+ 11 - 9
src/jfw/modules/app/src/app/front/swordfish.go

@@ -9,7 +9,7 @@ import (
 	"jfw/public"
 	"log"
 	"math/rand"
-	. "qfw/mongodb"
+	. "mongodb"
 	"qfw/util"
 	"qfw/util/elastic"
 	"qfw/util/jy"
@@ -21,7 +21,8 @@ import (
 
 	"github.com/go-xweb/httpsession"
 	. "github.com/thinxer/go-word2vec"
-	"gopkg.in/mgo.v2/bson"
+	"go.mongodb.org/mongo-driver/bson"
+	"go.mongodb.org/mongo-driver/bson/primitive"
 )
 
 const (
@@ -530,7 +531,7 @@ func (m *Front) WxsearchlistPaging() {
 			redis.Put("other", "s_"+userid.(string), strings.Join(arrs, ","), -1)
 			m.T["history"] = arrs
 			//订阅查询
-			one, _ := mongodb.FindOneByField("user", bson.M{"_id": bson.ObjectIdHex(userid.(string))}, `{"o_jy":1}`)
+			one, _ := mongodb.FindById("user", userid.(string), `{"o_jy":1}`)
 			if one != nil && len(*one) > 0 {
 				o_jy, _ := (*one)["o_jy"].(map[string]interface{})
 				a_key, _ := o_jy["a_key"].([]interface{})
@@ -678,7 +679,7 @@ func (f *Front) HasPushHistory() {
 	}
 	area := f.GetString("area")
 	otherFlag := false
-	hasNextPage, list := jy.SubscribePush.Datas(public.MQFW, public.PushMysql, userId, pageNum, formatTime, area)
+	hasNextPage, list := jy.SubscribePush.Datas(public.Mgo_Bidding, public.DbConf.Mongodb.Bidding.Collection, public.DbConf.Mongodb.Bidding.Collection_back, public.PushMysql, userId, pageNum, formatTime, area)
 	//首次用户推送查询“其他”
 	t, _ := time.ParseInLocation("2006-01-02", time.Now().Format("2006-01-02"), time.Local)
 	today_1 := t.Unix()
@@ -757,7 +758,7 @@ func (f *Front) HistorypushPaging() error {
 	if pageNum == 1 {
 		go updateUserApppushunread(userId)
 	}
-	hasNextPage, list := jy.SubscribePush.Datas(public.MQFW, public.PushMysql, userId, pageNum, formatTime, area)
+	hasNextPage, list := jy.SubscribePush.Datas(public.Mgo_Bidding, public.DbConf.Mongodb.Bidding.Collection, public.DbConf.Mongodb.Bidding.Collection_back, public.PushMysql, userId, pageNum, formatTime, area)
 	f.ServeJson(map[string]interface{}{
 		"hasNextPage": hasNextPage,
 		"data":        list,
@@ -787,9 +788,9 @@ func wxvisitD(sid, userId string) (objdata map[string]interface{}) {
 	defer util.Catch()
 	var obj map[string]interface{}
 	if len(sid) > 5 {
-		aobj, ok := mongodb.FindById("bidding", sid, nil)
+		aobj, ok := public.Mgo_Bidding.FindById(public.DbConf.Mongodb.Bidding.Collection, sid, nil)
 		if ok && (aobj == nil || *aobj == nil || len(*aobj) == 0) {
-			aobj, ok = mongodb.FindById("bidding_back", sid, nil)
+			aobj, ok = public.Mgo_Bidding.FindById(public.DbConf.Mongodb.Bidding.Collection_back, sid, nil)
 		}
 		//aobj, ok := elastic.GetByIdField("bidding", "bidding", sid, ""), true
 		obj = *aobj
@@ -930,13 +931,14 @@ func (m *Front) GetIndexData() {
 //手动删除30天无更新数据
 func (m *Front) DelOL() error {
 	defer util.Catch()
-	var ids []bson.ObjectId
+	var ids []primitive.ObjectID
 	var flag = "F"
 	var arrid = strings.Split(m.GetString("arrid"), ",")
 	log.Println("---->", arrid)
 	if len(arrid) > 0 {
 		for _, chid := range arrid {
-			ids = append(ids, bson.ObjectIdHex(util.DecodeArticleId2ByCheck(chid)[0]))
+			_id, _ := primitive.ObjectIDFromHex(util.DecodeArticleId2ByCheck(chid)[0])
+			ids = append(ids, _id)
 		}
 	}
 	userId, ok := m.GetSession("userId").(string)

+ 3 - 3
src/jfw/modules/app/src/app/front/ws_dataExport.go

@@ -16,7 +16,7 @@ import (
 	"time"
 
 	"github.com/go-xweb/xweb"
-	"gopkg.in/mgo.v2/bson"
+	"go.mongodb.org/mongo-driver/bson"
 )
 
 type WsDataExport struct {
@@ -29,7 +29,7 @@ type WsDataExport struct {
 	checkPhoneVerify  xweb.Mapper `xweb:"/jyapp/front/dataExport/checkPhoneVerify"`  //验证手机号
 	previewData       xweb.Mapper `xweb:"/jyapp/front/dataExport/previewData/(.*)"`  //app数据导出-数据预览页面
 	getPreview        xweb.Mapper `xweb:"/jyapp/front/dataExport/getPreview"`        //app数据导出-预览数据
-	toOrderDetail     xweb.Mapper `xweb:"/jyapp/front/dataExport/toOrderDetail"`        //订单详情
+	toOrderDetail     xweb.Mapper `xweb:"/jyapp/front/dataExport/toOrderDetail"`     //订单详情
 
 }
 
@@ -511,4 +511,4 @@ func (m *WsDataExport) ToOrderDetail() error {
 	error := m.Render("/dataExport/dataExport_toOrderDetail.html", &m.T)
 	log.Println(error)
 	return nil
-}
+}

+ 7 - 0
src/jfw/modules/app/src/db.json

@@ -16,6 +16,13 @@
 			"address": "192.168.3.128:27080",
 	 		"size": 5,
 	 		"dbName": "extract_v3"
+		},
+		"bidding": {
+			"address": "192.168.3.207:27092",
+	 		"size": 5,
+	 		"dbName": "qfw_data",
+			"collection": "bidding",
+			"collection_back": "bidding_back"
 		}
 	},
 	"elasticsearch": {

+ 15 - 14
src/jfw/modules/common/src/qfw/util/jy/entnichepush.go

@@ -4,7 +4,7 @@ import (
 	"encoding/json"
 	"fmt"
 	"log"
-	mg "qfw/mongodb"
+	mg "mongodb"
 	. "qfw/util"
 	"qfw/util/elastic"
 	"qfw/util/mysql"
@@ -12,7 +12,7 @@ import (
 	"strings"
 	"time"
 
-	"gopkg.in/mgo.v2/bson"
+	"go.mongodb.org/mongo-driver/bson/primitive"
 )
 
 var EntnichePush = &entnichePush{}
@@ -46,7 +46,7 @@ func (e *entnichePush) todayKey(entId, userId int) string {
 	return fmt.Sprintf("entnichepush_%d_%d", entId, userId)
 }
 
-func (e *entnichePush) Datas(MQFW mg.MongodbSim, PushMysql *mysql.Mysql, entId, userId int, pageNum int, selectTime, area string) (hasNextPage bool, result []*SubPushList) {
+func (e *entnichePush) Datas(Mgo_bidding mg.MongodbSim, bidding, bidding_back string, PushMysql *mysql.Mysql, entId, userId int, pageNum int, selectTime, area string) (hasNextPage bool, result []*SubPushList) {
 	if pageNum < 1 {
 		pageNum = 1
 	}
@@ -59,7 +59,7 @@ func (e *entnichePush) Datas(MQFW mg.MongodbSim, PushMysql *mysql.Mysql, entId,
 			log.Println(userId, "GetTodayCache Error", err)
 		}
 		if err != nil || subPush == nil || subPush.Date != now || len(subPush.Datas) == 0 {
-			list := e.getDatasFromMysql(MQFW, PushMysql, entId, userId, pageNum, pageSize, selectTime, area, false)
+			list := e.getDatasFromMysql(Mgo_bidding, bidding, bidding_back, PushMysql, entId, userId, pageNum, pageSize, selectTime, area, false)
 			subPush = &SubPush{
 				Date:  now,
 				Datas: list,
@@ -79,7 +79,7 @@ func (e *entnichePush) Datas(MQFW mg.MongodbSim, PushMysql *mysql.Mysql, entId,
 			log.Println(userId, "GetAllCache Error", err)
 		}
 		if err != nil || allCache == nil || len(allCache) == 0 {
-			allCache = e.getDatasFromMysql(MQFW, PushMysql, entId, userId, 1, AllSubPushCacheSize, selectTime, area, true)
+			allCache = e.getDatasFromMysql(Mgo_bidding, bidding, bidding_back, PushMysql, entId, userId, 1, AllSubPushCacheSize, selectTime, area, true)
 			e.PutAllCache(entId, userId, allCache)
 		}
 		length := len(allCache)
@@ -90,7 +90,7 @@ func (e *entnichePush) Datas(MQFW mg.MongodbSim, PushMysql *mysql.Mysql, entId,
 			result = allCache[start:end]
 		}
 	} else {
-		result = e.getDatasFromMysql(MQFW, PushMysql, entId, userId, pageNum, pageSize, selectTime, area, true)
+		result = e.getDatasFromMysql(Mgo_bidding, bidding, bidding_back, PushMysql, entId, userId, pageNum, pageSize, selectTime, area, true)
 	}
 	if result == nil {
 		result = []*SubPushList{}
@@ -98,7 +98,7 @@ func (e *entnichePush) Datas(MQFW mg.MongodbSim, PushMysql *mysql.Mysql, entId,
 	hasNextPage = len(result) >= pageSize
 	return
 }
-func (e *entnichePush) getDatasFromMysql(MQFW mg.MongodbSim, PushMysql *mysql.Mysql, entId, userId int, pageNum, myPageSize int, selectTime, area string, isLimit bool) (result []*SubPushList) {
+func (e *entnichePush) getDatasFromMysql(Mgo_bidding mg.MongodbSim, bidding, bidding_back string, PushMysql *mysql.Mysql, entId, userId int, pageNum, myPageSize int, selectTime, area string, isLimit bool) (result []*SubPushList) {
 	findSQL := "select id,date,infoid,isvisit,matchkeys,type,1 as isvip from pushentniche where entid=" + fmt.Sprint(entId) + " and userid=" + fmt.Sprint(userId)
 	findStr := ""
 	if selectTime != "" {
@@ -132,7 +132,7 @@ func (e *entnichePush) getDatasFromMysql(MQFW mg.MongodbSim, PushMysql *mysql.My
 	list := PushMysql.SelectBySql(findSQL)
 	if len(*list) > 0 {
 		pushCas := e.GetJyPushs(*list)
-		result = e.GetInfoByIds(MQFW, pushCas)
+		result = e.GetInfoByIds(Mgo_bidding, bidding, bidding_back, pushCas)
 	} else {
 		result = []*SubPushList{}
 	}
@@ -157,7 +157,7 @@ func (e *entnichePush) GetJyPushs(datas []map[string]interface{}) (pushCas []*Pu
 }
 
 //根据id取内容
-func (e *entnichePush) GetInfoByIds(MQFW mg.MongodbSim, pushCas []*PushCa) []*SubPushList {
+func (e *entnichePush) GetInfoByIds(Mgo_bidding mg.MongodbSim, bidding, bidding_back string, pushCas []*PushCa) []*SubPushList {
 	array := make([]*SubPushList, len(pushCas))
 	if len(pushCas) == 0 {
 		return array
@@ -197,14 +197,15 @@ func (e *entnichePush) GetInfoByIds(MQFW mg.MongodbSim, pushCas []*PushCa) []*Su
 		}
 	}
 	//mongodb bidding
-	mgo_ids := []bson.ObjectId{}
+	mgo_ids := []primitive.ObjectID{}
 	for _, v := range es_ids {
 		if infos[v] == nil {
-			mgo_ids = append(mgo_ids, bson.ObjectIdHex(v))
+			_id, _ := primitive.ObjectIDFromHex(v)
+			mgo_ids = append(mgo_ids, _id)
 		}
 	}
 	if len(mgo_ids) > 0 {
-		list, ok := MQFW.Find("bidding", map[string]interface{}{"_id": map[string]interface{}{"$in": mgo_ids}}, nil, mongodb_fields, false, -1, -1)
+		list, ok := Mgo_bidding.Find(bidding, map[string]interface{}{"_id": map[string]interface{}{"$in": mgo_ids}}, nil, mongodb_fields, false, -1, -1)
 		if ok && *list != nil {
 			for _, v := range *list {
 				_id := mg.BsonIdToSId(v["_id"])
@@ -214,14 +215,14 @@ func (e *entnichePush) GetInfoByIds(MQFW mg.MongodbSim, pushCas []*PushCa) []*Su
 		}
 	}
 	//mongodb bidding_back
-	mgo_back_ids := []bson.ObjectId{}
+	mgo_back_ids := []primitive.ObjectID{}
 	for _, v := range mgo_ids {
 		if infos[mg.BsonIdToSId(v)] == nil {
 			mgo_back_ids = append(mgo_back_ids, v)
 		}
 	}
 	if len(mgo_back_ids) > 0 {
-		list, ok := MQFW.Find("bidding_back", map[string]interface{}{"_id": map[string]interface{}{"$in": mgo_back_ids}}, nil, mongodb_fields, false, -1, -1)
+		list, ok := Mgo_bidding.Find(bidding_back, map[string]interface{}{"_id": map[string]interface{}{"$in": mgo_back_ids}}, nil, mongodb_fields, false, -1, -1)
 		if ok && *list != nil {
 			for _, v := range *list {
 				_id := mg.BsonIdToSId(v["_id"])

+ 15 - 14
src/jfw/modules/common/src/qfw/util/jy/subscribepush.go

@@ -4,7 +4,7 @@ import (
 	"encoding/json"
 	"fmt"
 	"log"
-	mg "qfw/mongodb"
+	mg "mongodb"
 	. "qfw/util"
 	"qfw/util/elastic"
 	"qfw/util/mysql"
@@ -12,7 +12,7 @@ import (
 	"strings"
 	"time"
 
-	"gopkg.in/mgo.v2/bson"
+	"go.mongodb.org/mongo-driver/bson/primitive"
 )
 
 const (
@@ -147,7 +147,7 @@ func (s *subscribePush) InfoFormat(p *PushCa, info *map[string]interface{}) *Sub
 	}
 }
 
-func (s *subscribePush) Datas(MQFW mg.MongodbSim, PushMysql *mysql.Mysql, userId string, pageNum int, selectTime, area string) (hasNextPage bool, result []*SubPushList) {
+func (s *subscribePush) Datas(Mgo_bidding mg.MongodbSim, bidding, bidding_back string, PushMysql *mysql.Mysql, userId string, pageNum int, selectTime, area string) (hasNextPage bool, result []*SubPushList) {
 	if userId == "" {
 		return
 	}
@@ -163,7 +163,7 @@ func (s *subscribePush) Datas(MQFW mg.MongodbSim, PushMysql *mysql.Mysql, userId
 			log.Println(userId, "GetTodayCache Error", err)
 		}
 		if err != nil || subPush == nil || subPush.Date != now || len(subPush.Datas) == 0 {
-			list := s.getDatasFromMysql(MQFW, PushMysql, userId, pageNum, pageSize, selectTime, area, false)
+			list := s.getDatasFromMysql(Mgo_bidding, bidding, bidding_back, PushMysql, userId, pageNum, pageSize, selectTime, area, false)
 			subPush = &SubPush{
 				Date:  now,
 				Datas: list,
@@ -183,7 +183,7 @@ func (s *subscribePush) Datas(MQFW mg.MongodbSim, PushMysql *mysql.Mysql, userId
 			log.Println(userId, "GetAllCache Error", err)
 		}
 		if err != nil || allCache == nil || len(allCache) == 0 {
-			allCache = s.getDatasFromMysql(MQFW, PushMysql, userId, 1, AllSubPushCacheSize, selectTime, area, true)
+			allCache = s.getDatasFromMysql(Mgo_bidding, bidding, bidding_back, PushMysql, userId, 1, AllSubPushCacheSize, selectTime, area, true)
 			s.PutAllCache(userId, allCache)
 		}
 		length := len(allCache)
@@ -194,7 +194,7 @@ func (s *subscribePush) Datas(MQFW mg.MongodbSim, PushMysql *mysql.Mysql, userId
 			result = allCache[start:end]
 		}
 	} else {
-		result = s.getDatasFromMysql(MQFW, PushMysql, userId, pageNum, pageSize, selectTime, area, true)
+		result = s.getDatasFromMysql(Mgo_bidding, bidding, bidding_back, PushMysql, userId, pageNum, pageSize, selectTime, area, true)
 	}
 	if result == nil {
 		result = []*SubPushList{}
@@ -202,7 +202,7 @@ func (s *subscribePush) Datas(MQFW mg.MongodbSim, PushMysql *mysql.Mysql, userId
 	hasNextPage = len(result) >= pageSize
 	return
 }
-func (s *subscribePush) getDatasFromMysql(MQFW mg.MongodbSim, PushMysql *mysql.Mysql, userId string, pageNum, myPageSize int, selectTime, area string, isLimit bool) (result []*SubPushList) {
+func (s *subscribePush) getDatasFromMysql(Mgo_bidding mg.MongodbSim, bidding, bidding_back string, PushMysql *mysql.Mysql, userId string, pageNum, myPageSize int, selectTime, area string, isLimit bool) (result []*SubPushList) {
 	findSQL := "select id,date,infoid,isvisit,matchkeys,type,isvip from pushsubscribe where userid = '" + userId + "'"
 	findStr := ""
 	if selectTime != "" {
@@ -240,7 +240,7 @@ func (s *subscribePush) getDatasFromMysql(MQFW mg.MongodbSim, PushMysql *mysql.M
 	list := PushMysql.SelectBySql(findSQL)
 	if len(*list) > 0 {
 		pushCas := s.GetJyPushs(*list)
-		result = s.GetInfoByIds(MQFW, pushCas)
+		result = s.GetInfoByIds(Mgo_bidding, bidding, bidding_back, pushCas)
 	} else {
 		result = []*SubPushList{}
 	}
@@ -265,7 +265,7 @@ func (s *subscribePush) GetJyPushs(datas []map[string]interface{}) (pushCas []*P
 }
 
 //根据id取内容
-func (s *subscribePush) GetInfoByIds(MQFW mg.MongodbSim, pushCas []*PushCa) []*SubPushList {
+func (s *subscribePush) GetInfoByIds(Mgo_bidding mg.MongodbSim, bidding, bidding_back string, pushCas []*PushCa) []*SubPushList {
 	array := make([]*SubPushList, len(pushCas))
 	if len(pushCas) == 0 {
 		return array
@@ -305,14 +305,15 @@ func (s *subscribePush) GetInfoByIds(MQFW mg.MongodbSim, pushCas []*PushCa) []*S
 		}
 	}
 	//mongodb bidding
-	mgo_ids := []bson.ObjectId{}
+	mgo_ids := []primitive.ObjectID{}
 	for _, v := range es_ids {
 		if infos[v] == nil {
-			mgo_ids = append(mgo_ids, bson.ObjectIdHex(v))
+			_id, _ := primitive.ObjectIDFromHex(v)
+			mgo_ids = append(mgo_ids, _id)
 		}
 	}
 	if len(mgo_ids) > 0 {
-		list, ok := MQFW.Find("bidding", map[string]interface{}{"_id": map[string]interface{}{"$in": mgo_ids}}, nil, mongodb_fields, false, -1, -1)
+		list, ok := Mgo_bidding.Find(bidding, map[string]interface{}{"_id": map[string]interface{}{"$in": mgo_ids}}, nil, mongodb_fields, false, -1, -1)
 		if ok && *list != nil {
 			for _, v := range *list {
 				_id := mg.BsonIdToSId(v["_id"])
@@ -322,14 +323,14 @@ func (s *subscribePush) GetInfoByIds(MQFW mg.MongodbSim, pushCas []*PushCa) []*S
 		}
 	}
 	//mongodb bidding_back
-	mgo_back_ids := []bson.ObjectId{}
+	mgo_back_ids := []primitive.ObjectID{}
 	for _, v := range mgo_ids {
 		if infos[mg.BsonIdToSId(v)] == nil {
 			mgo_back_ids = append(mgo_back_ids, v)
 		}
 	}
 	if len(mgo_back_ids) > 0 {
-		list, ok := MQFW.Find("bidding_back", map[string]interface{}{"_id": map[string]interface{}{"$in": mgo_back_ids}}, nil, mongodb_fields, false, -1, -1)
+		list, ok := Mgo_bidding.Find(bidding_back, map[string]interface{}{"_id": map[string]interface{}{"$in": mgo_back_ids}}, nil, mongodb_fields, false, -1, -1)
 		if ok && *list != nil {
 			for _, v := range *list {
 				_id := mg.BsonIdToSId(v["_id"])

+ 2 - 2
src/jfw/modules/common/src/qfw/util/jy/user_merge.go

@@ -5,7 +5,7 @@ import (
 	"errors"
 	"fmt"
 	"log"
-	. "qfw/mongodb"
+	. "mongodb"
 	qutil "qfw/util"
 	"qfw/util/redis"
 	"regexp"
@@ -13,7 +13,7 @@ import (
 	"time"
 
 	"github.com/go-xweb/httpsession"
-	"gopkg.in/mgo.v2/bson"
+	"go.mongodb.org/mongo-driver/bson"
 )
 
 var WxClientReg = regexp.MustCompile(`.*micromessenger.*`)

+ 1 - 1
src/jfw/modules/common/src/qfw/util/jy/user_wxMerge.go

@@ -4,7 +4,7 @@ import (
 	"errors"
 	"fmt"
 	"log"
-	. "qfw/mongodb"
+	. "mongodb"
 	qutil "qfw/util"
 	"qfw/util/mysql"
 	"qfw/util/redis"

+ 2 - 7
src/jfw/modules/pushent/src/config.json

@@ -1,14 +1,9 @@
 {
 	"appPushServiceRpc": "127.0.0.1:5566",
-	"durationMinutes": "30",
-	"elasticPoolSize": 30,
-	"elasticsearch": "http://192.168.3.128:9800",
+	"durationMinutes": 30,
 	"lastid": "",
-	"mongodbName": "qfw",
-	"mongodbPoolSize": "20",
-	"mongodbServers": "192.168.3.128:27080",
+	"startTime":"",
 	"pushPool": 30,
-	"redisServers": "push=192.168.3.128:5002",
 	"testids": ["5d6378301c298a5aac7b5402"],
 	"viewDomain": "https://web-jydev-wcj.jianyu360.cn",
 	"weixinRpcServer": "127.0.0.1:8083",

+ 18 - 2
src/jfw/modules/pushent/src/config/config.go

@@ -4,8 +4,24 @@ import (
 	"qfw/util"
 )
 
-var Sysconfig map[string]interface{}
+type config struct {
+	AppPushServiceRpc string
+	DurationMinutes   int
+	Lastid            string
+	StartTime         string
+	PushPool          int
+	Testids           []string
+	ViewDomain        string
+	WeixinRpcServer   string
+	Wxcolor           string
+	Wxcontent         string
+	Wxdetailcolor     string
+	Wxgroup           string
+	Wxtitle           string
+}
+
+var Config *config
 
 func init() {
-	util.ReadConfig(&Sysconfig)
+	util.ReadConfig(&Config)
 }

+ 26 - 0
src/jfw/modules/pushent/src/db.json

@@ -0,0 +1,26 @@
+{
+	"mongodb": {
+		"main": {
+			"address": "192.168.3.128:27080",
+	 		"size": 5,
+	 		"dbName": "qfw"
+		},
+		"bidding": {
+			"address": "192.168.3.207:27092",
+	 		"size": 5,
+	 		"dbName": "qfw_data",
+			"collection": "bidding"
+		}
+	},
+	"elasticsearch": {
+		"main": {
+			"address": "http://192.168.3.128:9800",
+	    	"size": 5
+		}
+    },
+    "redis": {
+    	"main": {
+			"address": "push=192.168.3.128:5002"
+		}
+    }
+}

+ 67 - 10
src/jfw/modules/pushent/src/db/db.go

@@ -1,22 +1,79 @@
 package db
 
 import (
-	. "config"
-	"qfw/mongodb"
+	"log"
+	m "mongodb"
 	"qfw/util"
 	"qfw/util/elastic"
 	"qfw/util/redis"
 )
 
-var MQFW mongodb.MongodbSim
+var (
+	DbConf      *dbConf
+	MQFW        m.MongodbSim
+	Mgo_Bidding m.MongodbSim
+)
+
+type dbConf struct {
+	Mongodb struct {
+		Main    *mgoConf
+		Bidding *mgoConf
+	}
+	Elasticsearch struct {
+		Main *esConf
+	}
+	Redis struct {
+		Main  *redisConf
+		Login *redisConf
+	}
+}
+type mgoConf struct {
+	Address    string
+	Size       int
+	DbName     string
+	UserName   string
+	Password   string
+	Collection string
+}
+
+type esConf struct {
+	Address string
+	Size    int
+}
+type redisConf struct {
+	Address string
+}
 
 func init() {
-	redis.InitRedisBySize(Sysconfig["redisServers"].(string), 200, 30, 300)
-	elastic.InitElasticSize(Sysconfig["elasticsearch"].(string), util.IntAllDef(Sysconfig["elasticPoolSize"], 30))
-	MQFW = mongodb.MongodbSim{
-		MongodbAddr: Sysconfig["mongodbServers"].(string),
-		Size:        util.IntAll(Sysconfig["mongodbPoolSize"]),
-		DbName:      Sysconfig["mongodbName"].(string),
+	util.ReadConfig("./db.json", &DbConf)
+	if DbConf != nil {
+		if DbConf.Elasticsearch.Main != nil {
+			elastic.InitElasticSize(DbConf.Elasticsearch.Main.Address, DbConf.Elasticsearch.Main.Size)
+			log.Println("初始化 elasticsearch")
+		}
+		//初始化redis
+		if DbConf.Redis.Main != nil {
+			log.Println("初始化 redis")
+			redis.InitRedisBySize(DbConf.Redis.Main.Address, 200, 30, 300)
+		}
+		//
+		if DbConf.Mongodb.Main != nil {
+			log.Println("初始化 mongodb main")
+			MQFW = m.MongodbSim{
+				MongodbAddr: DbConf.Mongodb.Main.Address,
+				Size:        DbConf.Mongodb.Main.Size,
+				DbName:      DbConf.Mongodb.Main.DbName,
+			}
+			MQFW.InitPool()
+		}
+		if DbConf.Mongodb.Bidding != nil {
+			log.Println("初始化 mongodb bidding")
+			Mgo_Bidding = m.MongodbSim{
+				MongodbAddr: DbConf.Mongodb.Bidding.Address,
+				Size:        DbConf.Mongodb.Bidding.Size,
+				DbName:      DbConf.Mongodb.Bidding.DbName,
+			}
+			Mgo_Bidding.InitPool()
+		}
 	}
-	MQFW.InitPool()
 }

+ 3 - 3
src/jfw/modules/pushent/src/main.go

@@ -1,7 +1,7 @@
 package main
 
 import (
-	"config"
+	. "config"
 	"log"
 	_ "net/http/pprof"
 	"push"
@@ -26,7 +26,7 @@ func main() {
 func runJob() {
 	util.Try(func() {
 		push.Job()
-		util.WriteSysConfig(config.Sysconfig)
+		util.WriteSysConfig(Config)
 	}, func(e interface{}) {})
-	time.AfterFunc(time.Duration(util.IntAll(config.Sysconfig["durationMinutes"]))*time.Minute, runJob)
+	time.AfterFunc(time.Duration(Config.DurationMinutes)*time.Minute, runJob)
 }

+ 34 - 44
src/jfw/modules/pushent/src/push/push.go

@@ -4,7 +4,7 @@ import (
 	. "config"
 	"db"
 	"fmt"
-	. "qfw/mongodb"
+	. "mongodb"
 	"qfw/util"
 	"qfw/util/elastic"
 	"qfw/util/redis"
@@ -17,7 +17,7 @@ import (
 	"time"
 
 	"github.com/donnie4w/go-logger/logger"
-	"gopkg.in/mgo.v2/bson"
+	"go.mongodb.org/mongo-driver/bson/primitive"
 )
 
 const (
@@ -27,17 +27,11 @@ const (
 var (
 	MaxId           = `{"query":{"filtered":{"filter":{"bool":{"must":{"range":{"id":{"gt":"%s"}}}}}}},"_source":["_id","comeintime"],"sort":{"id":"desc"},"from":0,"size":1}`
 	KEEPCOUNT       = 100
-	PushPool        = make(chan bool, util.IntAllDef(Sysconfig["pushPool"], 30))
+	PushPool        = make(chan bool, Config.PushPool)
 	pushWaitGroup   = &sync.WaitGroup{}
 	searchWaitGroup = &sync.WaitGroup{}
 	se              = util.SimpleEncrypt{Key: "topnet"}
-	WxTitle         = util.ObjToString(Sysconfig["wxtitle"])
-	WxContent       = util.ObjToString(Sysconfig["wxcontent"])
-	WxGroup         = util.ObjToString(Sysconfig["wxgroup"])
-	WxColor         = util.ObjToString(Sysconfig["wxcolor"])
-	WxDetailColor   = util.ObjToString(Sysconfig["wxdetailcolor"])
-	ViewDomain      = util.ObjToString(Sysconfig["viewDomain"])
-	LastLen         = 200 - len([]rune(WxContent)) - len([]rune(WxGroup))
+	LastLen         = 200 - len([]rune(Config.Wxcontent)) - len([]rune(Config.Wxgroup))
 )
 
 //构建推送时需要排序的map
@@ -64,16 +58,14 @@ type PushUser struct {
 //开始推送
 func Job() bool {
 	defer util.Catch()
-	_id := util.ObjToString(Sysconfig["lastid"])
-	StartTime, _ := Sysconfig["StartTime"].(string)
-	logger.Info("开始推送。。。", "lastid", _id, "StartTime", StartTime)
-	st, _ := time.ParseInLocation(util.Date_Full_Layout, StartTime, time.Local)
+	logger.Info("开始推送。。。", "lastid", Config.Lastid, "StartTime", Config.StartTime)
+	st, _ := time.ParseInLocation(util.Date_Full_Layout, Config.StartTime, time.Local)
 	lastTime := st.Unix()
 	idQuery := ""
-	if _id == "" {
-		idQuery = strings.Replace(fmt.Sprintf(MaxId, _id), `"gt"`, `"gte"`, -1)
+	if Config.Lastid == "" {
+		idQuery = strings.Replace(fmt.Sprintf(MaxId, Config.Lastid), `"gt"`, `"gte"`, -1)
 	} else {
-		idQuery = fmt.Sprintf(MaxId, _id)
+		idQuery = fmt.Sprintf(MaxId, Config.Lastid)
 	}
 	resId := elastic.Get("bidding", "bidding", idQuery)
 	lastid := ""
@@ -88,14 +80,12 @@ func Job() bool {
 	sess := db.MQFW.GetMgoConn()
 	defer db.MQFW.DestoryMongoConn(sess)
 	q := map[string]interface{}{}
-	testids_i, _ := Sysconfig["testids"].([]interface{})
-	testids := util.ObjArrToStringArr(testids_i)
-	if len(testids) > 0 {
+	if len(Config.Testids) > 0 {
 		q["s_userid"] = map[string]interface{}{
-			"$in": testids,
+			"$in": Config.Testids,
 		}
 	}
-	logger.Info("testids", testids)
+	logger.Info("testids", Config.Testids)
 	cur := sess.DB(db.MQFW.DbName).C(FOLLOW_COLLECTION).Find(q).Select(map[string]interface{}{
 		"s_entname":  1,
 		"s_userid":   1,
@@ -126,7 +116,7 @@ func Job() bool {
 		logger.Info("未查找到需要推送的用户...")
 		return false
 	}
-	winners := InitBiddingCache(_id, lastid, lastTime)
+	winners := InitBiddingCache(lastid, lastTime)
 	if len(winners) == 0 {
 		logger.Info("加载数据到内存中的时候,未查找到数据...")
 		return false
@@ -146,9 +136,9 @@ func Job() bool {
 		}(k, v)
 	}
 	pushWaitGroup.Wait()
-	Sysconfig["StartTime"] = util.FormatDateWithObj(&comeintime, util.Date_Full_Layout)
-	Sysconfig["lastid"] = lastid
-	logger.Info("推送结束。。。", "lastid", lastid, "StartTime", Sysconfig["StartTime"])
+	Config.StartTime = util.FormatDateWithObj(&comeintime, util.Date_Full_Layout)
+	Config.Lastid = lastid
+	logger.Info("推送结束。。。", "lastid", Config.Lastid, "StartTime", Config.StartTime)
 	return true
 }
 
@@ -182,7 +172,7 @@ func EachAllBidInfo(users *[]*PushUser, winners map[string][]map[string]interfac
 }
 
 //加载数据到内存中
-func InitBiddingCache(_id, lastid string, lastTime int64) map[string][]map[string]interface{} {
+func InitBiddingCache(lastid string, lastTime int64) map[string][]map[string]interface{} {
 	defer util.Catch()
 	c_query := map[string]interface{}{
 		"publishtime": map[string]interface{}{
@@ -191,20 +181,20 @@ func InitBiddingCache(_id, lastid string, lastTime int64) map[string][]map[strin
 		"extracttype": 1,
 	}
 	idQuery := map[string]interface{}{}
-	if _id != "" {
-		idQuery["$gt"] = bson.ObjectIdHex(_id)
+	if Config.Lastid != "" {
+		idQuery["$gt"], _ = primitive.ObjectIDFromHex(Config.Lastid)
 	}
 	if lastid != "" {
-		idQuery["$lte"] = bson.ObjectIdHex(lastid)
+		idQuery["$lte"], _ = primitive.ObjectIDFromHex(lastid)
 	}
 	if len(idQuery) > 0 {
 		c_query["_id"] = idQuery
 	}
 	logger.Info("mongodb query:", c_query)
 	winners := map[string][]map[string]interface{}{}
-	sess := db.MQFW.GetMgoConn()
-	defer db.MQFW.DestoryMongoConn(sess)
-	it := sess.DB("qfw").C("bidding").Find(c_query).Select(map[string]interface{}{
+	sess := db.Mgo_Bidding.GetMgoConn()
+	defer db.Mgo_Bidding.DestoryMongoConn(sess)
+	it := sess.DB(db.DbConf.Mongodb.Bidding.DbName).C(db.DbConf.Mongodb.Bidding.Collection).Find(c_query).Select(map[string]interface{}{
 		"_id":             1,
 		"title":           1,
 		"publishtime":     1,
@@ -294,12 +284,12 @@ func push(fid, sname, userId string, res *[]map[string]interface{}) {
 			relationinfo, _ := (*followObject)["a_relationinfo"].([]interface{})
 			rLength := len(relationinfo)
 			pLength := pushArray.Len()
-			setMap := bson.M{
+			setMap := map[string]interface{}{
 				"a_lastpushids":   ids,
 				"l_lastpushtime":  (*((*pushArray)[0]))["l_publishtime"],
 				"i_apppushunread": 1,
 			}
-			updateMap := &bson.M{"$set": setMap}
+			updateMap := &map[string]interface{}{"$set": setMap}
 			if rLength > 0 && rLength+pLength > KEEPCOUNT { //保留100条
 				start := rLength + pLength - KEEPCOUNT
 				var relationinfoTemp []interface{}
@@ -311,7 +301,7 @@ func push(fid, sname, userId string, res *[]map[string]interface{}) {
 				}
 				setMap["a_relationinfo"] = relationinfoTemp
 			} else { //追加
-				(*updateMap)["$push"] = bson.M{"a_relationinfo": bson.M{"$each": pushArray}}
+				(*updateMap)["$push"] = map[string]interface{}{"a_relationinfo": map[string]interface{}{"$each": pushArray}}
 			}
 			updateFlag = db.MQFW.UpdateById(FOLLOW_COLLECTION, fid, updateMap)
 		}
@@ -327,7 +317,7 @@ func push(fid, sname, userId string, res *[]map[string]interface{}) {
 			isPushWx := util.IntAllDef((*userdata)["i_ispush"], 1)
 			applystatus := util.IntAll((*userdata)["i_applystatus"])
 			//进入推送逻辑
-			isSaveOk := db.MQFW.Save("jy_pushent", bson.M{
+			isSaveOk := db.MQFW.Save("jy_pushent", map[string]interface{}{
 				"s_userid":       userId,
 				"l_date":         time.Now().Unix(),
 				"a_relationinfo": pushArray,
@@ -342,7 +332,7 @@ func push(fid, sname, userId string, res *[]map[string]interface{}) {
 			//微信推送
 			if applystatus == 1 && isPushWx == 1 && s_m_openid != "" {
 				lastTime := util.Int64All((*(*pushArray)[0])["l_publishtime"])
-				pushtt := fmt.Sprintf(WxTitle, sname)
+				pushtt := fmt.Sprintf(Config.Wxtitle, sname)
 				Tip1 := ""
 				minute := time.Now().Unix() - lastTime
 				if minute > -1 && minute < 61 {
@@ -393,13 +383,13 @@ func push(fid, sname, userId string, res *[]map[string]interface{}) {
 				}
 				isPushOk := rpccall.SendWinXin(&qrpc.NotifyMsg{
 					Openid:      s_m_openid,
-					Title:       fmt.Sprintf(WxTitle, sname),
+					Title:       fmt.Sprintf(Config.Wxtitle, sname),
 					Remark:      Tip1 + Remark + LastTip,
-					Detail:      WxGroup,
+					Detail:      Config.Wxgroup,
 					Service:     lastcreatetime,
-					Color:       WxColor,
-					DetailColor: WxDetailColor,
-					Url:         ViewDomain + "/front/sess/" + se.EncodeString(s_m_openid+",uid,"+strconv.Itoa(int(time.Now().Unix()))+",followEntDetail") + "__" + util.EncodeArticleId2ByCheck(fid),
+					Color:       Config.Wxcolor,
+					DetailColor: Config.Wxdetailcolor,
+					Url:         Config.ViewDomain + "/front/sess/" + se.EncodeString(s_m_openid+",uid,"+strconv.Itoa(int(time.Now().Unix()))+",followEntDetail") + "__" + util.EncodeArticleId2ByCheck(fid),
 				}, userId)
 				logger.Info("微信推送", isPushOk, userId, s_m_openid, pushnum, sname)
 			}
@@ -410,7 +400,7 @@ func push(fid, sname, userId string, res *[]map[string]interface{}) {
 					descriptAppend = fmt.Sprintf("\n...(共%d条)", pushnum)
 					jpushtitle = fmt.Sprintf("1. %s", jpushtitle)
 				}
-				isPushOk := qrpc.AppPush(Sysconfig["appPushServiceRpc"].(string), map[string]interface{}{
+				isPushOk := qrpc.AppPush(Config.AppPushServiceRpc, map[string]interface{}{
 					"phoneType":      phoneType,
 					"otherPushId":    opushid,
 					"jgPushId":       jpushid,

+ 2 - 2
src/jfw/modules/pushent/src/rpccall/weixinrpc.go

@@ -1,7 +1,7 @@
 package rpccall
 
 import (
-	"config"
+	. "config"
 	"db"
 	qrpc "qfw/util/rpc"
 	"strings"
@@ -11,7 +11,7 @@ import (
 //微信远程调用,实现模板发送消息
 func SendWinXin(p *qrpc.NotifyMsg, userId string) bool {
 	time.Sleep(10 * time.Millisecond)
-	ok, res := qrpc.WxPush(config.Sysconfig["weixinRpcServer"].(string), "WeiXinRpc.SendPushMsg", p)
+	ok, res := qrpc.WxPush(Config.WeixinRpcServer, "WeiXinRpc.SendPushMsg", p)
 	if !ok && (strings.Contains(res, "[46004]") || strings.Contains(res, "[65302]") || strings.Contains(res, "[43004]") || strings.Contains(res, "[40003]")) {
 		db.MQFW.UpdateById("user", userId, map[string]interface{}{
 			"$set": map[string]interface{}{

+ 0 - 25
src/jfw/modules/pushentniche/src/match/config.json

@@ -1,25 +0,0 @@
-{
-	"elasticPoolSize":1,
-	"elasticSearch":"http://127.0.0.1:9800",
-	"redisServers": "pushcache_1=127.0.0.1:1379",
-	"mgoAddr":"127.0.0.1:27080",
-	"mgoSize":2,
-	"testQuery":{},
-	"filterReg":"^(项目|中标|公告)$",
-	"retainReg":"[\\p{Han}a-zA-Z0-9]",
-	"matchPoolSize":60,
-	"savePoolSize":5,
-	"matchDuration":60,
-	"notMatchHour":[19,20,21,23,0,1,2,4,5],
-	"maxMatchSize":50,
-	"bulkSize":10,
-	"bigBulkSize":100,
-	"mysql":{
-        "dbName":"jianyu",
-        "address":"127.0.0.1:3366",
-        "userName":"root",
-        "passWord":"Topnet123",
-		"maxOpenConns": 2,
-		"maxIdleConns": 2
-    }
-}

+ 0 - 51
src/jfw/modules/pushentniche/src/match/config/config.go

@@ -1,51 +0,0 @@
-package config
-
-import (
-	"qfw/util"
-	"regexp"
-)
-
-type config struct {
-	ElasticPoolSize int                    `json:"elasticPoolSize"`
-	ElasticSearch   string                 `json:"elasticSearch"`
-	RedisServers    string                 `json:"redisServers"`
-	MgoAddr         string                 `json:"mgoAddr"`
-	MgoSize         int                    `json:"mgoSize"`
-	TestQuery       map[string]interface{} `json:"testQuery"`
-	MaxMatchSize    int                    `json:"maxMatchSize"`
-	BulkSize        int                    `json:"bulkSize"`
-	BigBulkSize     int                    `json:"bigBulkSize"`
-	FilterReg       string                 `json:"filterReg"`
-	RetainReg       string                 `json:"retainReg"`
-	MatchPoolSize   int                    `json:"matchPoolSize"`
-	SavePoolSize    int                    `json:"savePoolSize"`
-	MatchDuration   int64                  `json:"matchDuration"`
-	NotMatchHour    []int                  `json:"notMatchHour"`
-	Mysql           struct {
-		DbName       string
-		Address      string
-		UserName     string
-		PassWord     string
-		MaxOpenConns int
-		MaxIdleConns int
-	} `json:"mysql"`
-}
-
-type taskConfig struct {
-	LastTime string `json:"lastTime"`
-	LastId   string `json:"lastId"`
-}
-
-var (
-	Config     *config
-	TaskConfig *taskConfig
-	FilterReg  *regexp.Regexp
-	RetainReg  *regexp.Regexp
-)
-
-func init() {
-	util.ReadConfig("./config.json", &Config)
-	util.ReadConfig("./task.json", &TaskConfig)
-	FilterReg = regexp.MustCompile(Config.FilterReg)
-	RetainReg = regexp.MustCompile(Config.RetainReg)
-}

+ 0 - 142
src/jfw/modules/pushentniche/src/match/dfa/interestanalysis.go

@@ -1,142 +0,0 @@
-/**
- *兴趣分析
- *
- */
-package dfa
-
-import (
-	"log"
-	"strings"
-)
-
-//DFA实现
-type DFA struct {
-	link        map[string]interface{} //存放or
-	linkAnd     map[string]int         //存放and
-	linkAndWord map[string]interface{} //存放and中的拆分词
-
-}
-
-//添加词组,用于初始化,该方法是可以调用多次的
-func (d *DFA) AddWord(words ...string) {
-	if d.link == nil {
-		d.link = make(map[string]interface{})
-		d.linkAnd = make(map[string]int)
-		d.linkAndWord = make(map[string]interface{})
-	}
-	var nowMap *map[string]interface{}
-	for _, key := range words {
-		keys := strings.Split(key, "+")
-		lenkeys := len(keys)
-		if lenkeys > 1 {
-			d.linkAnd[key] = lenkeys
-			for k := 0; k < lenkeys; k++ {
-				minKey := keys[k]
-				nowMap = &d.linkAndWord
-				for i := 0; i < len(minKey); i++ {
-					kc := minKey[i : i+1]
-					if v, ok := (*nowMap)[kc]; ok {
-						nowMap, _ = v.(*map[string]interface{})
-					} else {
-						newMap := map[string]interface{}{}
-						newMap["YN"] = "N"
-						(*nowMap)[kc] = &newMap
-						nowMap = &newMap
-					}
-					if i == len(minKey)-1 {
-						(*nowMap)["YN"] = "Y"
-						if (*nowMap)["key"] == nil {
-							(*nowMap)["key"] = make(map[string]int)
-						}
-						(*nowMap)["key"].(map[string]int)[key] = k
-					}
-				}
-			}
-		} else {
-			nowMap = &d.link
-			for i := 0; i < len(key); i++ {
-				kc := key[i : i+1]
-				if v, ok := (*nowMap)[kc]; ok {
-					nowMap, _ = v.(*map[string]interface{})
-				} else {
-					newMap := map[string]interface{}{}
-					newMap["YN"] = "N"
-					(*nowMap)[kc] = &newMap
-					nowMap = &newMap
-				}
-
-				if i == len(key)-1 {
-					(*nowMap)["YN"] = "Y"
-				}
-			}
-		}
-	}
-}
-func (d *DFA) Clear() {
-	d.link = nil
-}
-
-//从给定的内容中找出匹配上的关键词
-func (d *DFA) Analy(src string) []string {
-	if d.link == nil {
-		log.Println("请先添加词组")
-		return []string{}
-	}
-	keywords := []string{}
-	tempMap := make(map[string][]bool)
-	for i := 0; i < len(src); i++ {
-		nowMap := &d.link
-		length := 0 // 匹配标识数默认为0
-		//flag := false // 敏感词结束标识位:用于敏感词只有1位的情况
-		for j := i; j < len(src); j++ {
-			word := src[j : j+1]
-			nowMap, _ = (*nowMap)[word].(*map[string]interface{})
-			if nowMap != nil {
-				length = length + 1
-				tag, _ := (*nowMap)["YN"].(string)
-				if "Y" == tag {
-					//flag = true
-					keywords = append(keywords, src[i:i+length])
-				}
-			} else {
-				break
-			}
-		}
-		nowMap = &d.linkAndWord
-		length = 0
-		for j := i; j < len(src); j++ {
-			word := src[j : j+1]
-			nowMap, _ = (*nowMap)[word].(*map[string]interface{})
-			if nowMap != nil {
-				length = length + 1
-				tag, _ := (*nowMap)["YN"].(string)
-				if "Y" == tag {
-					mkeys := (*nowMap)["key"].(map[string]int)
-					for k, v := range mkeys {
-						tempBool := tempMap[k]
-						if tempBool == nil {
-							tempBool = make([]bool, d.linkAnd[k])
-							tempMap[k] = tempBool
-						}
-						tempBool[v] = true
-					}
-				}
-			} else {
-				break
-			}
-		}
-	}
-	for k, v := range tempMap {
-		ball := true
-		for _, m := range v {
-			if !m {
-				ball = false
-				break
-			}
-		}
-		if ball {
-			keywords = append(keywords, k)
-		}
-	}
-	return keywords
-}

+ 0 - 45
src/jfw/modules/pushentniche/src/match/dfa/interestanalysis_test.go

@@ -1,45 +0,0 @@
-package dfa
-
-import (
-	"log"
-	"strings"
-	"testing"
-	"time"
-)
-
-var d *DFA = &DFA{}
-
-func copyMap(m map[string]int) (m2 map[string]int) {
-	m2 = make(map[string]int)
-	for k, v := range m {
-		m2[k] = v
-	}
-	return m2
-}
-
-func TestAnaly(t *testing.T) {
-	d.AddWord("办公", "办+楼", "河+省", "完+你们8")
-	log.Println(strings.Split("河+南+", "+")[2])
-	t1 := time.Now()
-	log.Println(d.Analy("这胡省锦河涛写给江泽民的信我们你们于办公楼上你完就是啊。"), "=====")
-	log.Println(time.Now().Sub(t1).Seconds())
-	d.Clear()
-	//log.Println(d.Analy("这是胡锦涛写给江泽民的信啊。"))
-
-}
-
-func Test_Label(t *testing.T) {
-	log.Println("000----")
-
-	for _, v := range []int{1, 2, 3, 4, 5} {
-		log.Println(v)
-	L1:
-		for _, vv := range []string{"a", "b", "c", "d"} {
-			log.Println(vv)
-			if vv == "add" {
-				break L1
-			}
-		}
-	}
-	log.Println("111----")
-}

+ 0 - 19
src/jfw/modules/pushentniche/src/match/job/job.go

@@ -1,19 +0,0 @@
-package job
-
-import (
-	"sync"
-)
-
-type Job interface {
-	Execute()
-}
-
-type jobs struct {
-	Match Job
-}
-
-var Jobs = &jobs{
-	Match: &MatchJob{
-		allProject: &sync.Map{},
-	},
-}

+ 0 - 793
src/jfw/modules/pushentniche/src/match/job/matchjob.go

@@ -1,793 +0,0 @@
-package job
-
-import (
-	"encoding/json"
-	"fmt"
-	. "match/config"
-	. "match/matcher"
-	. "match/util"
-	. "public"
-	"qfw/util"
-	"qfw/util/elastic"
-	"qfw/util/mongodb"
-	"qfw/util/redis"
-	"sort"
-	"strings"
-	"sync"
-	"time"
-
-	"github.com/donnie4w/go-logger/logger"
-	"gopkg.in/mgo.v2/bson"
-)
-
-const (
-	DB           = "bidding"
-	MaxId        = `{"query":{"filtered":{"filter":{"bool":{"must":{"range":{"id":{"gt":"%s"}}}}}}},"_source":["_id","comeintime"],"sort":{"id":"desc"},"from":0,"size":1}`
-	ProjectQuery = `{"query":{"filtered":{"filter":{"term":{"list.infoid":"%s"}}}},"_source":["_id","list.infoid"],"sort":{"id":"desc"},"from":0,"size":1}`
-)
-
-type Project struct {
-	Id               string
-	List_last_infoid string
-}
-
-type MatchJob struct {
-	allProject *sync.Map
-}
-
-//定时任务,匹配数据,存库
-func (m *MatchJob) Execute() {
-	defer util.Catch()
-	logger.Info("开始匹配数据任务。。。", TaskConfig.LastId, TaskConfig.LastTime)
-	startId := util.ObjToString(TaskConfig.LastId)
-	//获取本次查询的最大id
-	idQuery := ""
-	if startId == "" {
-		idQuery = strings.Replace(fmt.Sprintf(MaxId, startId), `"gt"`, `"gte"`, -1)
-	} else {
-		idQuery = fmt.Sprintf(MaxId, startId)
-	}
-	resId := elastic.Get(DB, DB, idQuery)
-	endId := ""
-	var endTime interface{}
-	if resId != nil && *resId != nil && len(*resId) == 1 {
-		endId = util.ObjToString((*resId)[0]["_id"])
-		endTime = (*resId)[0]["endTime"]
-	} else {
-		logger.Info("获取本次查询的最大id的时候,未查找到数据!", idQuery)
-		return
-	}
-	st, _ := time.ParseInLocation(util.Date_Full_Layout, TaskConfig.LastTime, time.Local)
-	datas := m.LoadBidding(startId, endId, st.Unix())
-	if datas == nil || len(*datas) == 0 {
-		return
-	}
-	m.Start(datas)
-	m.allProject = &sync.Map{}
-	if endTime == nil {
-		endTime = time.Now().Unix()
-	}
-	TaskConfig.LastTime = util.FormatDateWithObj(&endTime, util.Date_Full_Layout)
-	TaskConfig.LastId = endId
-	logger.Info("匹配数据任务结束。。。", TaskConfig.LastId, TaskConfig.LastTime)
-	//
-}
-
-//加载数据到内存中
-func (m *MatchJob) LoadBidding(lastId, newId string, lastTime int64) *[]map[string]interface{} {
-	defer util.Catch()
-	c_query := map[string]interface{}{
-		"publishtime": map[string]interface{}{
-			"$gt": lastTime - 7*86400,
-		},
-		"extracttype": 1,
-	}
-	idQuery := map[string]interface{}{}
-	if lastId != "" {
-		idQuery["$gt"] = bson.ObjectIdHex(lastId)
-	}
-	if newId != "" {
-		idQuery["$lte"] = bson.ObjectIdHex(newId)
-	}
-	if len(idQuery) > 0 {
-		c_query["_id"] = idQuery
-	}
-	//c_query = map[string]interface{}{
-	//"_id": bson.ObjectIdHex("5da702bfa5cb26b9b773e4d7"),
-	//}
-	logger.Info("开始加载", Bidding, "数据", c_query)
-	var res []map[string]interface{}
-	sess := mongodb.GetMgoConn()
-	defer mongodb.DestoryMongoConn(sess)
-	it := sess.DB(DbName).C(Bidding).Find(c_query).Select(map[string]interface{}{
-		"title":           1,
-		"detail":          1,
-		"projectscope":    1,
-		"publishtime":     1,
-		"toptype":         1,
-		"subtype":         1,
-		"type":            1,
-		"area":            1,
-		"s_subscopeclass": 1,
-		"city":            1,
-		"buyerclass":      1,
-		"jsondata":        1,
-	}).Sort("_id").Iter()
-	index := 0
-	for temp := make(map[string]interface{}); it.Next(&temp); {
-		_id := util.BsonIdToSId(temp["_id"])
-		temp["_id"] = _id
-		if util.ObjToString(temp["area"]) == "A" {
-			temp["area"] = "全国"
-		}
-		res = append(res, temp)
-		//信息缓存3天
-		info := map[string]interface{}{}
-		for _, v := range InfoSaveFields {
-			if v == "_id" || temp[v] == nil {
-				continue
-			}
-			info[v] = temp[v]
-		}
-		redis.Put(Pushcache_1, "info_"+_id, info, 259200)
-		temp = make(map[string]interface{})
-		index++
-		if index%500 == 0 {
-			logger.Info("加载", Bidding, "数据:", index)
-		}
-	}
-	logger.Info(Bidding, "数据已经加载结束。。。", index)
-	return &res
-}
-
-func (m *MatchJob) InitEnt() {
-	//初始化企业
-	InitEnts(Mysql)
-	//初始化部门
-	InitEntDepts(Mysql)
-	InitEntDeptParents(Mysql)
-	//初始化人员
-	InitEntUsers(Mysql)
-	//初始化分发规则
-	m.InitEntDistribute()
-}
-func (m *MatchJob) ClearEnt() {
-	Ents = map[int]*Ent{}
-	EntDepts = map[int]*EntDept{}
-	EntParentDept = map[int][]*EntDeptParent{}
-	EntChildDept = map[int][]*EntDeptParent{}
-	EntUsers = map[int]*EntUser{}
-	EntDeptDis = map[int][]*EntDistribute{}
-}
-func (m *MatchJob) Start(datas *[]map[string]interface{}) {
-	defer util.Catch()
-	defer m.ClearEnt()
-	m.InitEnt()
-	subSet := m.LoadSubSet()
-	if subSet != nil && len(subSet.EntRules) > 0 {
-		m.ToMatch(subSet, datas)
-	}
-	m.allProject = &sync.Map{}
-}
-
-func (m *MatchJob) LoadSubSet() *EntSubSet {
-	defer util.Catch()
-	entSubSet := NewEntSubSet()
-	//标题匹配
-	title_key := make(map[string]*[]*EntRule)
-	title_notkey := make(map[string]*[]*EntRule)
-	//正文匹配
-	detail_key := make(map[string]*[]*EntRule)
-	detail_notkey := make(map[string]*[]*EntRule)
-	//
-	sess := mongodb.GetMgoConn()
-	defer mongodb.DestoryMongoConn(sess)
-	query := map[string]interface{}{}
-	if len(Config.TestQuery) > 0 {
-		for k, v := range Config.TestQuery {
-			query[k] = v
-		}
-	}
-	logger.Info("加载订阅设置", query)
-	it := sess.DB(DbName).C(Entniche_rule).Find(query).Select(map[string]interface{}{
-		"i_entid":    1,
-		"i_deptid":   1,
-		"i_userid":   1,
-		"o_entniche": 1,
-	}).Iter()
-	for _temp := make(map[string]interface{}); it.Next(&_temp); {
-		func(temp map[string]interface{}) {
-			entId := util.IntAll(temp["i_entid"])
-			deptId := util.IntAll(temp["i_deptid"])
-			userId := util.IntAll(temp["i_userid"])
-			if entId == 0 || (deptId == 0 && userId == 0) {
-				return
-			} else if Ents[entId] == nil {
-				logger.Info("没有找到该企业", entId)
-				return
-			}
-			entName := Ents[entId].Name
-			if deptId > 0 && EntDepts[deptId] == nil {
-				logger.Info("没有找到该部门", entName, entId, deptId)
-				return
-			}
-			deptName := ""
-			if EntDepts[deptId] != nil {
-				deptName = EntDepts[deptId].Name
-			}
-			subSet, _ := temp["o_entniche"].(map[string]interface{})
-			if subSet == nil || len(subSet) == 0 {
-				logger.Info("订阅设置为空,过滤掉", entName, entId, deptName, deptId, userId)
-				return
-			}
-			//
-			if deptId > 0 { //部门订阅
-				if Ents[entId].Model != 1 {
-					logger.Info("不是统一订阅模式,过滤掉", entName, entId, deptName, deptId)
-					return
-				} else if EntDepts[deptId] == nil {
-					logger.Info("没有找到该部门,过滤掉", entName, entId, deptName, deptId)
-					return
-				} else if EntDepts[deptId].Subdis == 0 {
-					logger.Info("该部门的订阅分发没有开启,过滤掉", entName, entId, deptName, deptId)
-					return
-				} else if EntDepts[deptId].Nodiff == 0 && EntDeptDis[deptId] == nil {
-					logger.Info("该部门开启了订阅分发,没有开启全员无差别接收,但是没有分发规则,过滤掉", entName, entId, deptName, deptId)
-					return
-				}
-				//如果我的上级部门打开了订阅分发,并且开启了全员无差别接收,本部门规则无效
-				for _, dept := range EntParentDept[deptId] {
-					if EntDepts[dept.Pid].Subdis == 1 && EntDepts[dept.Pid].Nodiff == 1 {
-						logger.Info("我的上级部门", dept.Pid, "开启了订阅分发和全员无差别,过滤掉", entName, entId, deptName, deptId)
-						return
-					}
-				}
-			} else if userId > 0 { //个人订阅
-				if Ents[entId].Model != 2 {
-					logger.Info("不是个人订阅模式,过滤掉", entName, entId, userId)
-					return
-				} else if EntUsers[userId] == nil {
-					logger.Info("没有找到该用户,过滤掉", entName, entId, userId)
-					return
-				} else if EntUsers[userId].Power == 0 {
-					logger.Info("该用户没有权限,过滤掉", entName, entId, userId)
-					return
-				}
-			}
-			rule := &EntRule{
-				EntId:     entId,
-				EntName:   entName,
-				DeptId:    deptId,
-				UserId:    userId,
-				AppPush:   util.IntAllDef(subSet["i_apppush"], 1),
-				MailPush:  util.IntAll(subSet["i_mailpush"]),
-				RateMode:  util.IntAllDef(subSet["i_ratemode"], 2),
-				MatchType: util.IntAllDef(subSet["i_matchway"], 1),
-			}
-			logger.Info("加载订阅设置", "entId", entId, "entName", entName, "deptId", deptId, "deptName", deptName, "userId", userId, "appPush", rule.AppPush, "mailPush", rule.MailPush, "rateMode", rule.RateMode, "matchType", rule.MatchType)
-			if (deptId > 0 && EntDepts[deptId].Nodiff == 1) || userId > 0 {
-				if m.InitSubSet(entSubSet, subSet, rule, &title_key, &title_notkey, &detail_key, &detail_notkey) {
-					entSubSet.EntRules[rule] = true
-				}
-			}
-			if deptId <= 0 {
-				return
-			}
-			//分发规则
-			if EntDepts[deptId].Nodiff == 1 {
-				logger.Info("该部门开启了全员无差别,分发规则无效", entName, entId, deptName, deptId)
-				return
-			} else if EntDeptDis[deptId] == nil {
-				logger.Info("该部门没有分发规则", entName, entId, deptName, deptId)
-				return
-			}
-			itemMap := map[string]interface{}{}
-			items, _ := subSet["a_items"].([]interface{})
-			for _, v := range items {
-				item, _ := v.(map[string]interface{})
-				if item == nil {
-					continue
-				}
-				item_name, _ := item["s_item"].(string)
-				if item_name == "" {
-					continue
-				}
-				itemMap[item_name] = item
-			}
-			for _, dis := range EntDeptDis[deptId] {
-				child_rule := &EntRule{
-					EntId:     rule.EntId,
-					EntName:   rule.EntName,
-					DeptId:    rule.DeptId,
-					AppPush:   rule.AppPush,
-					MailPush:  rule.MailPush,
-					RateMode:  rule.RateMode,
-					MatchType: rule.MatchType,
-					DisId:     dis.Id,
-				}
-				child_items := []interface{}{}
-				for _, item_name := range dis.Items {
-					if itemMap[item_name] == nil {
-						continue
-					}
-					child_items = append(child_items, itemMap[item_name])
-				}
-				child_subSet := map[string]interface{}{}
-				if len(dis.Buyerclass) > 0 {
-					child_subSet["a_buyerclass"] = dis.Buyerclass
-				}
-				if len(dis.Area) > 0 {
-					child_subSet["o_area"] = dis.Area
-				}
-				if len(child_items) > 0 {
-					child_subSet["a_items"] = child_items
-				}
-				if len(child_subSet) == 0 {
-					continue
-				}
-				if m.InitSubSet(entSubSet, child_subSet, child_rule, &title_key, &title_notkey, &detail_key, &detail_notkey) {
-					entSubSet.EntRules[child_rule] = true
-				}
-			}
-		}(_temp)
-		_temp = make(map[string]interface{})
-	}
-	//
-	title_pjob := &KeyDfa{
-		Key_entRule:    &title_key,
-		Notkey_entRule: &title_notkey,
-	}
-	title_pjob.CreateDaf()
-	detail_pjob := &KeyDfa{
-		Key_entRule:    &detail_key,
-		Notkey_entRule: &detail_notkey,
-	}
-	detail_pjob.CreateDaf()
-	entSubSet.Title_KeyDfa = title_pjob
-	entSubSet.Detail_KeyDfa = detail_pjob
-	return entSubSet
-}
-func (m *MatchJob) InitSubSet(entSubSet *EntSubSet, subSet map[string]interface{}, entRule *EntRule, title_key, title_notkey, detail_key, detail_notkey *map[string]*[]*EntRule) bool {
-	keys := []string{} //过滤后的关键词
-	notkeys := []string{}
-	var allKeySet []*KeySet
-	var err error
-	items, _ := subSet["a_items"].([]interface{})
-	for _, v := range items {
-		item, _ := v.(map[string]interface{})
-		var keySet []*KeySet
-		keySet, err = m.GetKeySet(item["a_key"])
-		if err != nil {
-			break
-		}
-		allKeySet = append(allKeySet, keySet...)
-	}
-	if err != nil {
-		logger.Error("订阅设置错误!", entRule.EntName, "entId", entRule.EntId, "deptId", entRule.DeptId, "userId", entRule.UserId, err)
-		return false
-	}
-	key_notkey := map[string]map[string]bool{} //关键词所对应的排除词
-	originalKeys := []string{}                 //原始关键词
-	////////////////
-	for _, vs := range allKeySet {
-		if vs == nil {
-			logger.Error("订阅设置异常", entRule.EntName, "entId", entRule.EntId, "deptId", entRule.DeptId, "userId", entRule.UserId)
-			continue
-		}
-		var vs_keys []string
-		for _, vs_v := range [][]string{vs.Keys, vs.AppendKeys} {
-			for _, vs_vv := range vs_v {
-				vs_vv = strings.TrimSpace(vs_vv)
-				if vs_vv == "" {
-					continue
-				}
-				vs_keys = append(vs_keys, vs_vv)
-			}
-		}
-		if len(vs_keys) == 0 {
-			continue
-		}
-		key := strings.Join(vs_keys, "+")
-		originalKeys = append(originalKeys, key)
-		if FilterReg.String() != "" && FilterReg.MatchString(key) {
-			continue
-		} else if RetainReg.String() != "" && !RetainReg.MatchString(key) {
-			continue
-		}
-		keys = append(keys, key)
-		notkeys = append(notkeys, vs.NotKeys...)
-		//转大写
-		upperKey := strings.ToUpper(key)
-		//建立与排除词的对应关系
-		for _, notkey := range vs.NotKeys {
-			upperNotkey := strings.ToUpper(notkey)
-			if key_notkey[upperKey] == nil {
-				key_notkey[upperKey] = map[string]bool{}
-			}
-			key_notkey[upperKey][upperNotkey] = true
-		}
-	}
-	buyerclass, _ := subSet["a_buyerclass"].([]interface{})
-	infotype, _ := subSet["a_infotype"].([]interface{})
-	area, _ := subSet["o_area"].(map[string]interface{})
-	if len(keys) == 0 && len(buyerclass) == 0 && len(infotype) == 0 && len(area) == 0 {
-		return false
-	}
-	entRule.Keys = originalKeys
-	entRule.Key_notkey = key_notkey
-	entRule.O_entniche = &O_entniche{
-		ProjectMatch: util.IntAllDef(subSet["i_projectmatch"], 1),
-	}
-	//采购单位行业
-	//如果有关键词 有采购单位行业,行业加上“其它”
-	if len(buyerclass) == 0 {
-		entSubSet.Add("", entRule, &entSubSet.Buyerclass)
-	} else {
-		if len(keys) > 0 {
-			buyerclass = append(buyerclass, "其它")
-		}
-		for _, v := range buyerclass {
-			s_v, _ := v.(string)
-			if s_v == "" {
-				continue
-			}
-			entSubSet.Add(s_v, entRule, &entSubSet.Buyerclass)
-		}
-	}
-	//区域
-	if len(area) == 0 {
-		entSubSet.Add("", entRule, &entSubSet.Area)
-	} else {
-		for k, v := range area {
-			if k == "" {
-				continue
-			}
-			vs, _ := v.([]interface{})
-			if len(vs) == 0 {
-				entSubSet.Add(k, entRule, &entSubSet.Area)
-			} else {
-				for _, vv := range vs {
-					s_vv, _ := vv.(string)
-					if s_vv == "" {
-						continue
-					}
-					entSubSet.Add(s_vv, entRule, &entSubSet.City)
-				}
-			}
-		}
-	}
-	//信息类型
-	if len(infotype) == 0 {
-		entSubSet.Add("", entRule, &entSubSet.InfoType)
-	} else {
-		for _, v := range infotype {
-			s_v, _ := v.(string)
-			if s_v == "" {
-				continue
-			}
-			entRule.O_entniche.SubTypes = append(entRule.O_entniche.SubTypes, s_v)
-			entSubSet.Add(s_v, entRule, &entSubSet.InfoType)
-		}
-	}
-	m.MakeKeyUser(keys, entRule, title_key)
-	m.MakeKeyUser(notkeys, entRule, title_notkey)
-	if entRule.MatchType == 2 {
-		m.MakeKeyUser(keys, entRule, detail_key)
-		m.MakeKeyUser(notkeys, entRule, detail_notkey)
-	}
-	return true
-}
-func (m *MatchJob) InitEntDistribute() {
-	sess := mongodb.GetMgoConn()
-	defer mongodb.DestoryMongoConn(sess)
-	it := sess.DB(DbName).C(Entniche_distribute).Find(map[string]interface{}{
-		"i_status": map[string]interface{}{"$ne": 1},
-	}).Select(map[string]interface{}{
-		"_id":          1,
-		"i_entid":      1,
-		"i_deptid":     1,
-		"a_items":      1,
-		"o_area":       1,
-		"a_buyerclass": 1,
-	}).Iter()
-	for temp := make(map[string]interface{}); it.Next(&temp); {
-		if temp["i_deptid"] == nil {
-			continue
-		}
-		deptId := util.IntAll(temp["i_deptid"])
-		a_items, _ := temp["a_items"].([]interface{})
-		o_area, _ := temp["o_area"].(map[string]interface{})
-		a_buyerclass, _ := temp["a_buyerclass"].([]interface{})
-		EntDeptDis[deptId] = append(EntDeptDis[deptId], &EntDistribute{
-			Id:         util.BsonIdToSId(temp["_id"]),
-			DeptId:     deptId,
-			Area:       o_area,
-			Buyerclass: a_buyerclass,
-			Items:      util.ObjArrToStringArr(a_items),
-		})
-		temp = make(map[string]interface{})
-	}
-}
-
-//把规则挂在词下面
-func (m *MatchJob) MakeKeyUser(keys []string, entRule *EntRule, key_entRule *map[string]*[]*EntRule) {
-	mp := map[string]bool{}
-	for _, key := range keys {
-		v := strings.ToUpper(key)
-		if v == "" || mp[v] {
-			continue
-		}
-		mp[v] = true
-		arr := (*key_entRule)[v]
-		if arr == nil {
-			arr = &[]*EntRule{}
-		}
-		*arr = append(*arr, entRule)
-		(*key_entRule)[v] = arr
-	}
-}
-
-//遍历数据并执行推送操作
-func (m *MatchJob) EachAllBidInfo(matcher Matcher, datas *[]map[string]interface{}) (*map[*EntRule]*SortList, *map[*EntRule]*[]string) {
-	defer util.Catch()
-	logger.Info("开始匹配数据。。。")
-	userMap := map[*EntRule]*SortList{}
-	projectUserMap := map[*EntRule]*[]string{}
-	lock := &sync.Mutex{}
-	var index int
-	matchPool := make(chan bool, Config.MatchPoolSize)
-	matchWaitGroup := &sync.WaitGroup{}
-	for _, temp := range *datas {
-		matchPool <- true
-		matchWaitGroup.Add(1)
-		go func(info map[string]interface{}) {
-			defer util.Catch()
-			defer func() {
-				matchWaitGroup.Done()
-				<-matchPool
-			}()
-			entRules, projectEntRules := matcher.Match(&info)
-			lock.Lock()
-			defer lock.Unlock()
-			if entRules != nil && len(*entRules) > 0 {
-				for k, v := range *entRules {
-					l := userMap[k]
-					if l == nil {
-						l = &SortList{}
-					}
-					*l = append(*l, &MatchInfo{
-						Info: &info,
-						Keys: v.Keys,
-					})
-					userMap[k] = l
-				}
-			}
-			if projectEntRules != nil && len(*projectEntRules) > 0 {
-				for _, v := range *projectEntRules {
-					l := projectUserMap[v]
-					if l == nil {
-						l = &[]string{}
-					}
-					*l = append(*l, util.ObjToString(info["_id"]))
-					projectUserMap[v] = l
-				}
-			}
-		}(temp)
-		index++
-		if index%500 == 0 {
-			logger.Info("匹配数据", index)
-		}
-	}
-	matchWaitGroup.Wait()
-	logger.Info("匹配数据结束。。。", index)
-	return &userMap, &projectUserMap
-}
-
-func (m *MatchJob) ToMatch(matcher Matcher, datas *[]map[string]interface{}) {
-	logger.Info("开始匹配商机管理订阅规则。。。")
-	entRuleMap, projectentRuleMap := m.EachAllBidInfo(matcher, datas)
-	logger.Info("开始匹配商机管理订阅规则。。。匹配结束。。。")
-	logger.Info("开始保存到", Pushspace_entniche_temp, "表。。。")
-	index := 0
-	var saveBatch []map[string]interface{}
-	myMatchId := map[string]map[string]bool{}
-	myFilterId := map[string]map[string]bool{}
-	//
-	savePool := make(chan bool, Config.SavePoolSize)
-	saveWaitGroup := &sync.WaitGroup{}
-	lock := &sync.Mutex{}
-	for k, v := range *entRuleMap {
-		savePool <- true
-		saveWaitGroup.Add(1)
-		go func(entRule *EntRule, infos *SortList) {
-			defer util.Catch()
-			defer func() {
-				<-savePool
-				saveWaitGroup.Done()
-			}()
-			//取最新50条
-			sort.Sort(infos)
-			var array []*MatchInfo
-			matchTitle := map[string]bool{}
-			matchId := map[string]bool{}
-			filterId := map[string]bool{}
-			size := 0
-			for _, v2 := range *infos {
-				title := util.ObjToString((*v2.Info)["title"])
-				_id := util.ObjToString((*v2.Info)["_id"])
-				if matchTitle[title] {
-					filterId[_id] = true
-					continue
-				}
-				matchTitle[title] = true
-				info := map[string]interface{}{}
-				for _, field := range InfoSaveFields {
-					if (*v2.Info)[field] == nil {
-						continue
-					}
-					info[field] = (*v2.Info)[field]
-				}
-				matchId[_id] = true
-				array = append(array, &MatchInfo{
-					Info: &info,
-					Keys: v2.Keys,
-				})
-				size++
-				if size >= Config.MaxMatchSize {
-					break
-				}
-			}
-			if size == 0 {
-				return
-			}
-			lock.Lock()
-			defer lock.Unlock()
-			unique := GetUnique(entRule.EntId, entRule.DeptId, entRule.UserId, entRule.DisId)
-			myMatchId[unique] = matchId
-			myFilterId[unique] = filterId
-			saveBatch = append(saveBatch, map[string]interface{}{
-				"entid":        entRule.EntId,
-				"entname":      entRule.EntName,
-				"deptid":       entRule.DeptId,
-				"userid":       entRule.UserId,
-				"distributeid": entRule.DisId,
-				"ratemode":     entRule.RateMode,
-				"apppush":      entRule.AppPush,
-				"mailpush":     entRule.MailPush,
-				"list":         array,
-				"size":         size,
-				"words":        entRule.Keys,
-				"timestamp":    time.Now().Unix(),
-			})
-			if len(saveBatch) == Config.BulkSize {
-				mongodb.SaveBulk(Pushspace_entniche_temp, saveBatch...)
-				saveBatch = []map[string]interface{}{}
-			}
-		}(k, v)
-		index++
-		if index%500 == 0 {
-			logger.Info("保存到", Pushspace_entniche_temp, "表:", index)
-		}
-	}
-	saveWaitGroup.Wait()
-	if len(saveBatch) > 0 {
-		mongodb.SaveBulk(Pushspace_entniche_temp, saveBatch...)
-		saveBatch = []map[string]interface{}{}
-	}
-	logger.Info("保存到", Pushspace_entniche_temp, "表结束。。。", index)
-	m.ToRelationProject(projectentRuleMap, &myMatchId, &myFilterId)
-}
-
-//关联项目
-func (m *MatchJob) ToRelationProject(projectEntRule *map[*EntRule]*[]string, myMatchId, myFilterId *map[string]map[string]bool) {
-	logger.Info("开始关联项目。。。")
-	index := 0
-	var updateproject [][]map[string]interface{}
-	//
-	savePool := make(chan bool, Config.SavePoolSize)
-	saveWaitGroup := &sync.WaitGroup{}
-	lock := &sync.Mutex{}
-	for k, v := range *projectEntRule {
-		savePool <- true
-		saveWaitGroup.Add(1)
-		go func(entRule *EntRule, _ids *[]string) {
-			defer util.Catch()
-			defer func() {
-				<-savePool
-				saveWaitGroup.Done()
-			}()
-			unique := GetUnique(entRule.EntId, entRule.DeptId, entRule.UserId, entRule.DisId)
-			needLength := 50 - len((*myMatchId)[unique])
-			for _, _id := range *_ids {
-				if (*myFilterId)[unique] != nil && (*myFilterId)[unique][_id] {
-					continue
-				}
-				//如果有信息类型,优先用订阅匹配上的信息,然后最多关联50条
-				if len(entRule.O_entniche.SubTypes) > 0 {
-					if (*myMatchId)[unique] == nil || !(*myMatchId)[unique][_id] {
-						if needLength > 0 {
-							needLength--
-						} else {
-							continue
-						}
-					}
-				} else { //如果没有信息类型,只关联订阅匹配上的信息
-					if (*myMatchId)[unique] == nil || !(*myMatchId)[unique][_id] {
-						continue
-					}
-				}
-				list_last_infoid := ""
-				projectId := ""
-				if value, ok := m.allProject.Load(_id); ok {
-					project, _ := value.(*Project)
-					projectId = project.Id
-					list_last_infoid = project.List_last_infoid
-				} else {
-					projects := elastic.Get(Projectset, Projectset, fmt.Sprintf(ProjectQuery, _id))
-					if projects == nil || len(*projects) == 0 {
-						continue
-					}
-					list := (*projects)[0]["list"].([]interface{})
-					if len(list) == 0 {
-						continue
-					}
-					list_last, _ := list[len(list)-1].(map[string]interface{})
-					list_last_infoid = util.ObjToString(list_last["infoid"])
-					projectId, _ = (*projects)[0]["_id"].(string)
-					m.allProject.Store(_id, &Project{
-						Id:               projectId,
-						List_last_infoid: list_last_infoid,
-					})
-				}
-				if projectId == "" || list_last_infoid == "" {
-					continue
-				}
-				lock.Lock()
-				updateproject = append(updateproject, []map[string]interface{}{
-					map[string]interface{}{
-						"projectid": projectId,
-						"unique":    unique,
-					},
-					map[string]interface{}{
-						"$set": map[string]interface{}{
-							"projectid":    projectId,
-							"infoid":       _id,
-							"unique":       unique,
-							"entid":        entRule.EntId,
-							"deptid":       entRule.DeptId,
-							"userid":       entRule.UserId,
-							"distributeid": entRule.DisId,
-							"maxid":        list_last_infoid,
-							"subtypes":     entRule.O_entniche.SubTypes,
-							"createtime":   time.Now().Unix(),
-						},
-					},
-				})
-				if len(updateproject) == Config.BigBulkSize {
-					mongodb.NewUpdateBulk(Pushspace_entniche_project, true, true, updateproject...)
-					updateproject = [][]map[string]interface{}{}
-				}
-				lock.Unlock()
-			}
-		}(k, v)
-		index++
-		if index%500 == 0 {
-			logger.Info("关联项目:", index)
-		}
-	}
-	saveWaitGroup.Wait()
-	if len(updateproject) > 0 {
-		mongodb.NewUpdateBulk(Pushspace_entniche_project, true, true, updateproject...)
-		updateproject = [][]map[string]interface{}{}
-	}
-	logger.Info("关联项目结束。。。", index)
-}
-
-func (m *MatchJob) GetKeySet(a_key interface{}) ([]*KeySet, error) {
-	var keySet []*KeySet
-	_bs, err := json.Marshal(a_key)
-	if err == nil {
-		err = json.Unmarshal(_bs, &keySet)
-	}
-	return keySet, err
-}

+ 0 - 47
src/jfw/modules/pushentniche/src/match/job/timetask.go

@@ -1,47 +0,0 @@
-package job
-
-import (
-	. "match/config"
-	"qfw/util"
-	"time"
-
-	"github.com/donnie4w/go-logger/logger"
-)
-
-type timeTask struct {
-	Match *MatchTimeTask //匹配数据
-}
-
-var Task = &timeTask{
-	Match: &MatchTimeTask{},
-}
-
-type MatchTimeTask struct {
-}
-
-func (m *MatchTimeTask) Execute(flag bool) {
-	hour := time.Now().Hour()
-	//23点到1点之间,不执行定时任务
-	//订阅付费有每天0点的定时任务删除pushspace_temp表的数据,会有冲突
-	isRun := true
-	if flag {
-		if hour == 0 {
-			isRun = false
-		}
-		for _, v := range Config.NotMatchHour {
-			if v == hour {
-				isRun = false
-				break
-			}
-		}
-	}
-	if isRun {
-		Jobs.Match.Execute()
-		util.WriteSysConfig("./task.json", &TaskConfig)
-	}
-	t := time.Duration(Config.MatchDuration) * time.Minute
-	logger.Info("start match job after", t)
-	time.AfterFunc(t, func() {
-		m.Execute(true)
-	})
-}

+ 0 - 26
src/jfw/modules/pushentniche/src/match/main.go

@@ -1,26 +0,0 @@
-//订阅推送-匹配数据服务
-package main
-
-import (
-	"flag"
-	"log"
-	"match/job"
-
-	"github.com/donnie4w/go-logger/logger"
-)
-
-func main() {
-	modle := flag.Int("m", 0, "默认:0;1 非定时任务匹配数据;")
-	flag.Parse()
-	logger.SetConsole(false)
-	logger.SetRollingDaily("./logs", "match.log")
-	log.Println("订阅推送-匹配数据程序启动。。。")
-	//job.Jobs.Match.Execute()
-	//return
-	if *modle == 1 {
-		job.Jobs.Match.Execute()
-	} else {
-		go job.Task.Match.Execute(false)
-		<-chan bool(nil)
-	}
-}

+ 0 - 139
src/jfw/modules/pushentniche/src/match/matcher/entmatch.go

@@ -1,139 +0,0 @@
-package matcher
-
-import (
-	. "match/util"
-	"strings"
-)
-
-//企业商机管理
-type EntSubSet struct {
-	EntRules      map[*EntRule]bool
-	Title_KeyDfa  *KeyDfa
-	Detail_KeyDfa *KeyDfa
-	Buyerclass    map[string]map[*EntRule]bool
-	Area          map[string]map[*EntRule]bool
-	City          map[string]map[*EntRule]bool
-	InfoType      map[string]map[*EntRule]bool
-}
-
-func (v *EntSubSet) Add(k string, u *EntRule, m *map[string]map[*EntRule]bool) {
-	mk := (*m)[k]
-	if mk == nil {
-		mk = map[*EntRule]bool{}
-	}
-	mk[u] = true
-	(*m)[k] = mk
-}
-func NewEntSubSet() *EntSubSet {
-	return &EntSubSet{
-		EntRules:   map[*EntRule]bool{},
-		Buyerclass: map[string]map[*EntRule]bool{},
-		Area:       map[string]map[*EntRule]bool{},
-		City:       map[string]map[*EntRule]bool{},
-		InfoType:   map[string]map[*EntRule]bool{},
-	}
-}
-
-func (e *EntSubSet) Match(info *map[string]interface{}) (*map[*EntRule]*MatchResult, *[]*EntRule) {
-	buyerclass, _ := (*info)["buyerclass"].(string)
-	area, _ := (*info)["area"].(string)
-	if area == "全国" {
-		area = ""
-	}
-	city, _ := (*info)["city"].(string)
-	subtype, _ := (*info)["subtype"].(string)
-	title := getTitle(info)
-	//订阅词
-	keys := e.Title_KeyDfa.Key.Analy(title)
-	//排除词
-	notkeys := e.Title_KeyDfa.NotKey.Analy(title)
-	title_entRules := e.GetFinalUser(keys, notkeys, e.Title_KeyDfa.Key_entRule)
-	//开启智能匹配的用户,匹配projectscope
-	detail_entRules := &map[*EntRule]*MatchResult{}
-	if e.Detail_KeyDfa != nil {
-		detail, _ := (*info)["projectscope"].(string)
-		if detail == "" {
-			detail, _ = (*info)["detail"].(string)
-		}
-		if detail != "" {
-			detail = strings.ToUpper(detail)
-			keys = e.Detail_KeyDfa.Key.Analy(detail)
-			notkeys = e.Detail_KeyDfa.NotKey.Analy(detail)
-			detail_entRules = e.GetFinalUser(keys, notkeys, e.Detail_KeyDfa.Key_entRule)
-			for d_k, d_u := range *detail_entRules {
-				if (*title_entRules)[d_k] != nil {
-					continue
-				}
-				(*title_entRules)[d_k] = d_u
-			}
-		}
-	}
-	entRules := map[*EntRule]*MatchResult{}
-	var projectUsers []*EntRule
-	for k, _ := range e.EntRules {
-		var matchEntRule *MatchResult
-		if len(k.Keys) > 0 {
-			matchEntRule = (*title_entRules)[k]
-			if matchEntRule == nil {
-				matchEntRule = (*detail_entRules)[k]
-			}
-			if matchEntRule == nil {
-				continue
-			}
-		} else {
-			matchEntRule = &MatchResult{}
-		}
-		if (!e.Buyerclass[""][k] && !e.Buyerclass[buyerclass][k]) ||
-			(!e.Area[""][k] && !e.Area[area][k] && !e.City[city][k]) {
-			continue
-		}
-		//关联项目不需要匹配信息类型
-		if k.O_entniche.ProjectMatch == 1 {
-			projectUsers = append(projectUsers, k)
-		}
-		if !e.InfoType[""][k] && !e.InfoType[subtype][k] {
-			continue
-		}
-		entRules[k] = matchEntRule
-	}
-	return &entRules, &projectUsers
-}
-
-//获取最终的用户,排除词、信息范围、信息类型之后的
-//返回匹配上的用户和没有匹配到的用户
-func (e *EntSubSet) GetFinalUser(keys, notkeys []string, key_user *map[string]*[]*EntRule) *map[*EntRule]*MatchResult {
-	keyMap := map[string]bool{}
-	for _, v := range keys {
-		keyMap[v] = true
-	}
-	entRules := map[*EntRule]*MatchResult{} //匹配到用户
-	//遍历所有用户
-	for k, us := range *key_user {
-		if !keyMap[k] { //该关键词没有匹配到的用户
-			continue
-		}
-		for _, u := range *us {
-			//获取该词下面所有的用户
-			//遍历我的排除词,如果存在的话,排除自己
-			isContinue := false
-			for _, notkey := range notkeys {
-				if u.Key_notkey[k][notkey] {
-					isContinue = true
-					break
-				}
-			}
-			if isContinue {
-				continue
-			}
-			matchEntRule := entRules[u]
-			if matchEntRule == nil {
-				matchEntRule = &MatchResult{
-					Keys: []string{},
-				}
-			}
-			matchEntRule.Keys = append(matchEntRule.Keys, k)
-			entRules[u] = matchEntRule
-		}
-	}
-	return &entRules
-}

+ 0 - 53
src/jfw/modules/pushentniche/src/match/matcher/matcher.go

@@ -1,53 +0,0 @@
-package matcher
-
-import (
-	"match/dfa"
-	. "match/util"
-	"strings"
-)
-
-type Matcher interface {
-	Match(info *map[string]interface{}) (*map[*EntRule]*MatchResult, *[]*EntRule)
-}
-type KeyDfa struct {
-	Key            *dfa.DFA
-	NotKey         *dfa.DFA
-	Key_entRule    *map[string]*[]*EntRule
-	Notkey_entRule *map[string]*[]*EntRule
-}
-
-//关键词和排除词
-func (p *KeyDfa) CreateDaf() {
-	//关键词
-	p.Key = &dfa.DFA{}
-	keys := make([]string, 0)
-	for k, _ := range *p.Key_entRule {
-		keys = append(keys, k)
-	}
-	p.Key.AddWord(keys...)
-	//排除关键词
-	p.NotKey = &dfa.DFA{}
-	notKeys := make([]string, 0)
-	for k, _ := range *p.Notkey_entRule {
-		notKeys = append(notKeys, k)
-	}
-	p.NotKey.AddWord(notKeys...)
-}
-
-type MatchResult struct {
-	Keys []string
-}
-type RelationProject struct {
-	TopTypes []string
-}
-
-func getTitle(info *map[string]interface{}) string {
-	title, _ := (*info)["title"].(string)
-	jsondata, _ := (*info)["jsondata"].(map[string]interface{})
-	if jsondata != nil {
-		goods, _ := jsondata["goods"].(string)
-		title += goods
-	}
-	title = strings.ToUpper(title)
-	return title
-}

+ 0 - 1
src/jfw/modules/pushentniche/src/match/task.json

@@ -1 +0,0 @@
-{"lastTime":"","lastId":""}

+ 0 - 34
src/jfw/modules/pushentniche/src/match/util/db.go

@@ -1,34 +0,0 @@
-package util
-
-import (
-	"log"
-	. "match/config"
-	"qfw/util/elastic"
-	"qfw/util/mongodb"
-	"qfw/util/mysql"
-	"qfw/util/redis"
-)
-
-var (
-	Mysql  *mysql.Mysql
-	DbName = "qfw"
-)
-
-func init() {
-	mongodb.InitMongodbPool(Config.MgoSize, Config.MgoAddr, DbName)
-	log.Println("mongodb初始化完成!")
-	redis.InitRedis(Config.RedisServers)
-	log.Println("redis初始化完成!")
-	elastic.InitElasticSize(Config.ElasticSearch, Config.ElasticPoolSize)
-	log.Println("elastic初始化完成!")
-	Mysql = &mysql.Mysql{
-		DBName:       Config.Mysql.DbName,
-		Address:      Config.Mysql.Address,
-		UserName:     Config.Mysql.UserName,
-		PassWord:     Config.Mysql.PassWord,
-		MaxOpenConns: Config.Mysql.MaxOpenConns,
-		MaxIdleConns: Config.Mysql.MaxIdleConns,
-	}
-	Mysql.Init()
-	log.Println("mysql初始化完成!")
-}

+ 0 - 29
src/jfw/modules/pushentniche/src/match/util/entity.go

@@ -1,29 +0,0 @@
-package util
-
-type EntRule struct {
-	EntId      int
-	EntName    string
-	DeptId     int
-	UserId     int
-	Key_notkey map[string]map[string]bool //关键词-排除词
-	Keys       []string                   //用户原始关键词
-	O_entniche *O_entniche
-	AppPush    int
-	MailPush   int
-	RateMode   int
-	MatchType  int
-	DisId      string
-}
-type O_entniche struct {
-	SubTypes     []string
-	ProjectMatch int
-}
-
-//关键词
-type KeySet struct {
-	Keys       []string `json:"key"`       //关键词
-	NotKeys    []string `json:"notkey"`    //排除词
-	InfoTypes  []string `json:"infotype"`  //信息类型
-	Areas      []string `json:"area"`      //地区
-	AppendKeys []string `json:"appendkey"` //附加词
-}

+ 0 - 202
src/jfw/modules/pushentniche/src/public/entity.go

@@ -1,202 +0,0 @@
-package public
-
-import (
-	"qfw/util"
-	"qfw/util/mysql"
-
-	"github.com/donnie4w/go-logger/logger"
-)
-
-type SortList []*MatchInfo
-
-func (s SortList) Len() int {
-	return len(s)
-}
-
-func (s SortList) Less(i, j int) bool {
-	return util.Int64All((*s[i].Info)["publishtime"]) > util.Int64All((*s[j].Info)["publishtime"])
-}
-
-func (s SortList) Swap(i, j int) {
-	s[i], s[j] = s[j], s[i]
-}
-
-type MatchInfo struct {
-	Info *map[string]interface{}
-	Keys []string
-}
-
-///////////////////////
-var Ents = map[int]*Ent{}
-
-type Ent struct {
-	Id         int
-	Model      int
-	Name       string
-	DeptParent map[int][]int
-}
-
-func InitEnts(Mysql *mysql.Mysql) {
-	list := Mysql.SelectBySql("select id,model,name from entniche_info where status=1 and model in (1,2)")
-	if list == nil {
-		return
-	}
-	for _, v := range *list {
-		id := util.IntAll(v["id"])
-		Ents[id] = &Ent{
-			Id:    id,
-			Model: util.IntAll(v["model"]),
-			Name:  util.ObjToString(v["name"]),
-		}
-	}
-	logger.Info("entniche_info加载完成!")
-}
-
-var EntUsers = map[int]*EntUser{}
-
-type EntUser struct {
-	Id    int
-	Name  string
-	Mail  string
-	Phone string
-	Power int
-}
-
-func InitEntUsers(Mysql *mysql.Mysql) {
-	list := Mysql.SelectBySql(`select id,name,mail,phone,power from entniche_user`)
-	if list == nil {
-		return
-	}
-	for _, v := range *list {
-		id := util.IntAll(v["id"])
-		EntUsers[id] = &EntUser{
-			Id:    id,
-			Name:  util.ObjToString(v["name"]),
-			Mail:  util.ObjToString(v["mail"]),
-			Phone: util.ObjToString(v["phone"]),
-			Power: util.IntAll(v["power"]),
-		}
-	}
-	logger.Info("entniche_user加载完成!")
-}
-
-var EntDepts = map[int]*EntDept{}
-
-type EntDept struct {
-	Id     int
-	Pid    int
-	Name   string
-	Nodiff int
-	Subdis int
-}
-
-func InitEntDepts(Mysql *mysql.Mysql) {
-	list := Mysql.SelectBySql(`select id,name,pid,subdis,nodiff from entniche_department`)
-	if list == nil {
-		return
-	}
-	for _, v := range *list {
-		id := util.IntAll(v["id"])
-		EntDepts[id] = &EntDept{
-			Id:     id,
-			Pid:    util.IntAll(v["pid"]),
-			Nodiff: util.IntAll(v["nodiff"]),
-			Subdis: util.IntAll(v["subdis"]),
-			Name:   util.ObjToString(v["name"]),
-		}
-	}
-	logger.Info("entniche_department加载完成!")
-}
-
-//我所有的父部门
-var EntParentDept = map[int][]*EntDeptParent{}
-
-//我所有的子部门
-var EntChildDept = map[int][]*EntDeptParent{}
-
-type EntDeptParent struct {
-	Id  int
-	Pid int
-}
-
-func InitEntDeptParents(Mysql *mysql.Mysql) {
-	list := Mysql.SelectBySql(`select id,pid from entniche_department_parent`)
-	if list == nil {
-		return
-	}
-	for _, v := range *list {
-		id := util.IntAll(v["id"])
-		pid := util.IntAll(v["pid"])
-		EntParentDept[id] = append(EntParentDept[id], &EntDeptParent{
-			Id:  id,
-			Pid: pid,
-		})
-		EntChildDept[pid] = append(EntChildDept[pid], &EntDeptParent{
-			Id:  id,
-			Pid: pid,
-		})
-	}
-	logger.Info("entniche_department_parent加载完成!")
-}
-
-var EntUserDept = map[int]*EntDeptUser{}
-var EntDeptUsers = map[int][]*EntDeptUser{}
-
-type EntDeptUser struct {
-	UserId int
-	DeptId int
-}
-
-func InitEntDeptUsers(Mysql *mysql.Mysql) {
-	list := Mysql.SelectBySql(`select dept_id,user_id from entniche_department_user`)
-	if list == nil {
-		return
-	}
-	for _, v := range *list {
-		user_id := util.IntAll(v["user_id"])
-		dept_id := util.IntAll(v["dept_id"])
-		entDeptUser := &EntDeptUser{
-			UserId: user_id,
-			DeptId: dept_id,
-		}
-		EntUserDept[user_id] = entDeptUser
-		EntDeptUsers[dept_id] = append(EntDeptUsers[dept_id], entDeptUser)
-	}
-	logger.Info("entniche_department_user加载完成!")
-}
-
-var EntRuleUsers = map[string][]*EntRuleUser{}
-var EntUserRules = map[int][]*EntRuleUser{}
-
-type EntRuleUser struct {
-	UserId int
-	RuleId string
-}
-
-func InitEntRuleUsers(Mysql *mysql.Mysql) {
-	list := Mysql.SelectBySql(`select user_id,rule_id from entniche_user_rule`)
-	if list == nil {
-		return
-	}
-	for _, v := range *list {
-		ruleId := util.ObjToString(v["rule_id"])
-		userId := util.IntAll(v["user_id"])
-		entRuleUser := &EntRuleUser{
-			UserId: userId,
-			RuleId: ruleId,
-		}
-		EntRuleUsers[ruleId] = append(EntRuleUsers[ruleId], entRuleUser)
-		EntUserRules[userId] = append(EntUserRules[userId], entRuleUser)
-	}
-	logger.Info("entniche_user_rule加载完成!")
-}
-
-var EntDeptDis = map[int][]*EntDistribute{}
-
-type EntDistribute struct {
-	Id         string
-	DeptId     int
-	Area       map[string]interface{}
-	Buyerclass []interface{}
-	Items      []string
-}

+ 0 - 30
src/jfw/modules/pushentniche/src/public/rpccall.go

@@ -1,30 +0,0 @@
-package public
-
-import (
-	"net/rpc"
-	"qfw/util"
-	"time"
-
-	"github.com/donnie4w/go-logger/logger"
-)
-
-//
-func PcHelperIsOnLine(address, phone string, sleep int) bool {
-	defer util.Catch()
-	if sleep > 0 {
-		time.Sleep(time.Duration(sleep) * time.Millisecond)
-	}
-	var repl string
-	client, err := rpc.DialHTTP("tcp", address)
-	if err != nil {
-		logger.Error(err.Error())
-		return false
-	}
-	defer client.Close()
-	err = client.Call("Service.IsOnLine", phone, &repl)
-	if err != nil {
-		logger.Error(err.Error())
-		return false
-	}
-	return repl == "y"
-}

+ 0 - 59
src/jfw/modules/pushentniche/src/public/util.go

@@ -1,59 +0,0 @@
-package public
-
-import (
-	"fmt"
-	"qfw/util"
-	"regexp"
-)
-
-const (
-	OneDaySecond               = 86400
-	SevenDay                   = 604800
-	User                       = "user"
-	Bidding                    = "bidding"
-	Projectset                 = "projectset"
-	Pushspace_entniche         = "pushspace_entniche"
-	Pushspace_entniche_temp    = "pushspace_entniche_temp"
-	Pushspace_entniche_project = "pushspace_entniche_project"
-	Pushspace_entniche_wait    = "pushspace_entniche_wait"
-	Pushcache_1                = "pushcache_1"
-	Pushcache_2_a              = "pushcache_2_a"
-	//企业商机管理
-	Entniche_rule       = "entniche_rule"
-	Entniche_distribute = "entniche_distribute"
-)
-
-var (
-	Se             = util.SimpleEncrypt{Key: "topnet"}
-	MailReg        = regexp.MustCompile("^.+@.+$")
-	InfoSaveFields = []string{"_id", "area", "city", "buyerclass", "publishtime", "s_subscopeclass", "subtype", "title", "toptype", "type"}
-	WeekNum        = map[string]int{
-		"Monday":    1,
-		"Tuesday":   2,
-		"Wednesday": 3,
-		"Thursday":  4,
-		"Friday":    5,
-		"Saturday":  6,
-		"Sunday":    7,
-	}
-)
-
-//一天的推送总数
-func DayCountKey(id int) string {
-	return fmt.Sprintf("entniche_daycount_%s_%d", util.NowFormat(util.Date_yyyyMMdd), id)
-}
-
-func PushInfoKey(userId int, infoId string) string {
-	return fmt.Sprintf("entniche_pushinfo_%d_%s", userId, infoId)
-}
-
-func GetUnique(entId, deptId, userId int, disId string) string {
-	if disId != "" {
-		return fmt.Sprintf("dis_%d_%s", entId, disId)
-	} else if deptId > 0 {
-		return fmt.Sprintf("dept_%d_%d", entId, deptId)
-	} else if userId > 0 {
-		return fmt.Sprintf("user_%d_%d", entId, userId)
-	}
-	return ""
-}

File diff suppressed because it is too large
+ 0 - 32
src/jfw/modules/pushentniche/src/push/config.json


+ 0 - 114
src/jfw/modules/pushentniche/src/push/config/config.go

@@ -1,114 +0,0 @@
-package config
-
-import (
-	"qfw/util"
-	"qfw/util/mail"
-	"strings"
-)
-
-type config struct {
-	JianyuDomain            string                 `json:"jianyuDomain"`
-	RedisServers            string                 `json:"redisServers"`
-	PushPoolSize            int                    `json:"pushPoolSize"`
-	ProjectPushPoolSize     int                    `json:"projectPushPoolSize"`
-	LoadProjectPoolSize     int                    `json:"loadProjectPoolSize"`
-	MergePoolSize           int                    `json:"mergePoolSize"`
-	MovePoolSize            int                    `json:"movePoolSize"`
-	Mail_content            string                 `json:"mail_content"`
-	Mail_html               string                 `json:"mail_html"`
-	Mail_title              string                 `json:"mail_title"`
-	Mail_according          string                 `json:"mail_according"`
-	Mails                   []*pushMail            `json:"mails"`
-	MaxPushSize             int                    `json:"maxPushSize"`
-	MaxRelationProject      int                    `json:"maxRelationProject"`
-	Mongodb                 *MongodbConfig         `json:"mongodb"`
-	ProjectMongodb          *MongodbConfig         `json:"projectMongodb"`
-	TestQuery               map[string]interface{} `json:"testQuery"`
-	AppPushServiceRpc       string                 `json:"appPushServiceRpc"`
-	PushBatch               int                    `json:"pushBatch"`
-	OncePushTime            string                 `json:"oncePushTime"`
-	OtherPushTimes          []string               `json:"otherPushTimes"`
-	ProjectPushTime         string                 `json:"projectPushTime"`
-	PushDay                 int                    `json:"pushDay"`
-	PushWeek                string                 `json:"pushWeek"`
-	AppPoolSize             int                    `json:"appPoolSize"`
-	MailSleep               int                    `json:"mailSleep"`
-	SaveSleep               int                    `json:"saveSleep"`
-	AppSleep                int                    `json:"appSleep"`
-	IsPushMail              bool                   `json:"isPushMail"`
-	SavePoolSize            int                    `json:"savePoolSize"`
-	MinutePushSize          int                    `json:"minutePushSize"`
-	FastigiumMinutePushSize int                    `json:"fastigiumMinutePushSize"`
-	FastigiumTime           string                 `json:"fastigiumTime"`
-	NinePushRedisTimeout    int                    `json:"ninePushRedisTimeout"`
-	MoveBatch               int                    `json:"moveBatch"`
-	MoveDuration            int                    `json:"moveDuration"`
-	BulkSize                int                    `json:"bulkSize"`
-	BigBulkSize             int                    `json:"bigBulkSize"`
-	ProjectPublishTimeLimit int64                  `json:"projectPublishTimeLimit"`
-	TimeoutWarn             string                 `json:"timeoutWarn"`
-	Mysql                   struct {
-		DbName       string
-		Address      string
-		UserName     string
-		PassWord     string
-		MaxOpenConns int
-		MaxIdleConns int
-	} `json:"mysql"`
-	SaveMysql struct {
-		DbName       string
-		Address      string
-		UserName     string
-		PassWord     string
-		MaxOpenConns int
-		MaxIdleConns int
-	} `json:"saveMysql"`
-}
-
-type MongodbConfig struct {
-	Alias    string `json:"alias"`
-	DbName   string `json:"dbName"`
-	CollName string `json:"collName"`
-	Address  string `json:"address"`
-	Size     int    `json:"size"`
-}
-type pushMail struct {
-	Addr         string `json:"addr"`
-	Port         int    `json:"port"`
-	Pwd          string `json:"pwd"`
-	User         string `json:"user"`
-	MailPoolSize int    `json:"mailPoolSize"`
-	MailReTry    int    `json:"mailReTry"`
-}
-type projectTask struct {
-	Pici int64 `json:"pici"`
-}
-
-var (
-	Gmails         []*mail.GmailAuth
-	Config         *config
-	ProjectTask    *projectTask
-	FastigiumStart int
-	FastigiumEnd   int
-)
-
-func init() {
-	util.ReadConfig("./config.json", &Config)
-	util.ReadConfig("./projecttask.json", &ProjectTask)
-	//
-	if fastigiumTimes := strings.Split(Config.FastigiumTime, "-"); len(fastigiumTimes) == 2 {
-		FastigiumStart = util.IntAll(fastigiumTimes[0])
-		FastigiumEnd = util.IntAll(fastigiumTimes[1])
-	}
-	Gmails = make([]*mail.GmailAuth, len(Config.Mails))
-	for k, v := range Config.Mails {
-		Gmails[k] = &mail.GmailAuth{
-			SmtpHost: v.Addr,
-			SmtpPort: v.Port,
-			User:     v.User,
-			Pwd:      v.Pwd,
-			PoolSize: v.MailPoolSize,
-			ReTry:    v.MailReTry,
-		}
-	}
-}

+ 0 - 42
src/jfw/modules/pushentniche/src/push/job/jobs.go

@@ -1,42 +0,0 @@
-package job
-
-import (
-	. "public"
-	. "push/util"
-	"sync"
-)
-
-var Jobs = struct {
-	Move        *MoveJob
-	Push        *PushJob
-	ProjectPush *ProjectPushJob
-}{
-	Move: &MoveJob{},
-	Push: &PushJob{
-		lock: &sync.Mutex{},
-	},
-	ProjectPush: &ProjectPushJob{},
-}
-
-func InitEnt() {
-	InitEnts(Mysql)
-	InitEntUsers(Mysql)
-	InitEntDeptUsers(Mysql)
-	InitEntRuleUsers(Mysql)
-	InitEntDepts(Mysql)
-	InitEntDeptParents(Mysql)
-	InitEntDistribute()
-}
-
-func ClearEnt() {
-	Ents = map[int]*Ent{}
-	EntUsers = map[int]*EntUser{}
-	EntUserDept = map[int]*EntDeptUser{}
-	EntDeptUsers = map[int][]*EntDeptUser{}
-	EntRuleUsers = map[string][]*EntRuleUser{}
-	EntUserRules = map[int][]*EntRuleUser{}
-	EntDepts = map[int]*EntDept{}
-	EntParentDept = map[int][]*EntDeptParent{}
-	EntChildDept = map[int][]*EntDeptParent{}
-	EntDeptDis = map[int][]*EntDistribute{}
-}

+ 0 - 317
src/jfw/modules/pushentniche/src/push/job/movejob.go

@@ -1,317 +0,0 @@
-//数据迁移
-package job
-
-import (
-	. "public"
-	. "push/config"
-	putil "push/util"
-	"qfw/util"
-	"qfw/util/mongodb"
-	"sort"
-	"strings"
-	"sync"
-	"time"
-
-	"github.com/donnie4w/go-logger/logger"
-	mgo "gopkg.in/mgo.v2"
-)
-
-var (
-	MoveFields = []string{"entid", "entname", "deptid", "words", "ratemode", "apppush", "mailpush", "timestamp"}
-)
-
-type MoveUser struct {
-	info map[string]interface{}
-	ids  []interface{}
-}
-
-type MoveJob struct {
-}
-
-func (m *MoveJob) Execute() {
-	defer util.Catch()
-	Jobs.Push.lock.Lock()
-	defer Jobs.Push.lock.Unlock()
-	logger.Info("开始迁移数据。。。")
-	nowUnix := time.Now().Unix()
-	sess := mongodb.GetMgoConn()
-	defer mongodb.DestoryMongoConn(sess)
-	query := map[string]interface{}{
-		"timestamp": map[string]interface{}{
-			"$lt": nowUnix,
-		},
-	}
-	if len(Config.TestQuery) > 0 {
-		for k, v := range Config.TestQuery {
-			query[k] = v
-		}
-	}
-	it := sess.DB(Config.Mongodb.DbName).C(Pushspace_entniche_temp).Find(query).Sort("entid", "deptid", "userid", "distributeid").Iter()
-	moveUsers := map[string]*MoveUser{}
-	index, number, length := 0, 0, 0
-	//
-	moveWait := &sync.WaitGroup{}
-	movePool := make(chan bool, Config.MovePoolSize)
-	moveLock := &sync.Mutex{}
-	for data := make(map[string]interface{}); it.Next(&data); {
-		movePool <- true
-		moveWait.Add(1)
-		index++
-		go func(temp map[string]interface{}) {
-			defer util.Catch()
-			defer func() {
-				<-movePool
-				moveWait.Done()
-			}()
-			entId := util.IntAll(temp["entid"])
-			deptId := util.IntAll(temp["deptid"])
-			userId := util.IntAll(temp["userid"])
-			disId := util.ObjToString(temp["distributeid"])
-			unique := GetUnique(entId, deptId, userId, disId)
-			maxPushSize := Config.MaxPushSize
-			moveLock.Lock()
-			defer moveLock.Unlock()
-			moveUser := moveUsers[unique]
-			if moveUser != nil {
-				list, _ := moveUser.info["list"].(*SortList)
-				idMap := map[string]bool{}
-				titleMap := map[string]bool{}
-				for _, v := range *list {
-					idMap[util.ObjToString((*v.Info)["_id"])] = true
-					titleMap[util.ObjToString((*v.Info)["title"])] = true
-				}
-				newList := putil.ToSortList(temp["list"])
-				for _, v := range *newList {
-					if idMap[util.ObjToString((*v.Info)["_id"])] {
-						continue
-					} else if titleMap[util.ObjToString((*v.Info)["title"])] {
-						continue
-					}
-					*list = append(*list, v)
-				}
-				sort.Sort(list)
-				if len(*list) > maxPushSize {
-					*list = (*list)[:maxPushSize]
-				}
-				temp["list"] = list
-				moveUser.info = temp
-				moveUser.ids = append(moveUser.ids, temp["_id"])
-			} else {
-				temp["list"] = putil.ToSortList(temp["list"])
-				moveUser = &MoveUser{
-					info: temp,
-					ids:  []interface{}{temp["_id"]},
-				}
-			}
-			moveUsers[unique] = moveUser
-			length++
-			if length == Config.MoveBatch {
-				m.merge(&number, nowUnix, moveUsers)
-				length = 0
-				moveUsers = map[string]*MoveUser{}
-			}
-		}(data)
-		data = make(map[string]interface{})
-		if index%500 == 0 {
-			logger.Info("迁移数据:", index)
-		}
-	}
-	moveWait.Wait()
-	if length > 0 {
-		m.merge(&number, nowUnix, moveUsers)
-		length = 0
-		moveUsers = map[string]*MoveUser{}
-	}
-	logger.Info("迁移数据结束。。。", index)
-}
-func (m *MoveJob) merge(number *int, nowUnix int64, moveUsers map[string]*MoveUser) {
-	*number++
-	logger.Info("第", *number, "次开始合并数据")
-	index := 0
-	saveArray := []map[string]interface{}{}
-	saveArray_delete := []interface{}{}
-	updateArray_query := []map[string]interface{}{}
-	updateArray_set := []map[string]interface{}{}
-	updateArray_delete := []interface{}{}
-	invalidArray_delete := []interface{}{}
-	//
-	mergeLock := &sync.Mutex{}
-	mergeWait := &sync.WaitGroup{}
-	mergePool := make(chan bool, Config.MergePoolSize)
-	for k, v := range moveUsers {
-		mergePool <- true
-		mergeWait.Add(1)
-		go func(unique string, moveUser *MoveUser) {
-			defer util.Catch()
-			defer func() {
-				<-mergePool
-				mergeWait.Done()
-			}()
-			sess := mongodb.GetMgoConn()
-			defer mongodb.DestoryMongoConn(sess)
-			var data map[string]interface{}
-			var query map[string]interface{}
-			uniques := strings.Split(unique, "_")
-			if len(uniques) != 3 {
-				return
-			}
-			if uniques[0] == "dis" {
-				query = map[string]interface{}{
-					"distributeid": util.ObjToString(uniques[2]),
-				}
-			} else if uniques[0] == "dept" {
-				query = map[string]interface{}{
-					"entid":  util.IntAll(uniques[1]),
-					"deptid": util.IntAll(uniques[2]),
-				}
-			} else if uniques[0] == "user" {
-				query = map[string]interface{}{
-					"entid":  util.IntAll(uniques[1]),
-					"userid": util.IntAll(uniques[2]),
-				}
-			} else {
-				return
-			}
-			sess.DB(Config.Mongodb.DbName).C(Pushspace_entniche).Find(query).Select(map[string]interface{}{"list": 1}).One(&data)
-			if data == nil { //批量新增
-				mergeLock.Lock()
-				saveArray = append(saveArray, moveUser.info)
-				saveArray_delete = append(saveArray_delete, moveUser.ids...)
-				if len(saveArray) == Config.BulkSize {
-					m.saveBulk(sess, &saveArray, &saveArray_delete)
-				}
-				mergeLock.Unlock()
-			} else { //批量更新
-				setMap := map[string]interface{}{}
-				for _, field := range MoveFields {
-					if moveUser.info[field] == nil {
-						continue
-					}
-					setMap[field] = moveUser.info[field]
-				}
-				//
-				oldList := putil.ToSortList(data["list"])
-				idMap := map[string]bool{}
-				for _, vv := range *oldList {
-					idMap[util.ObjToString((*vv.Info)["_id"])] = true
-				}
-				newList := make(SortList, 0)
-				newListOrig, _ := moveUser.info["list"].(*SortList)
-				//去重
-				for _, vv := range *newListOrig {
-					if idMap[util.ObjToString((*vv.Info)["_id"])] {
-						continue
-					}
-					newList = append(newList, vv)
-				}
-				upSet := map[string]interface{}{}
-				if pLength := len(newList); pLength > 0 {
-					rLength := len(*oldList)
-					maxPushSize := Config.MaxPushSize
-					if rLength+pLength > maxPushSize {
-						newList = append(newList, *oldList...)
-						sort.Sort(newList)
-						setMap["list"] = newList[:maxPushSize]
-						setMap["size"] = maxPushSize
-					} else { //追加
-						setMap["size"] = rLength + pLength
-						upSet["$push"] = map[string]interface{}{
-							"list": map[string]interface{}{
-								"$each": newList,
-							},
-						}
-					}
-				}
-				upSet["$set"] = setMap
-				mergeLock.Lock()
-				updateArray_delete = append(updateArray_delete, moveUser.ids...)
-				updateArray_query = append(updateArray_query, map[string]interface{}{"_id": data["_id"]})
-				updateArray_set = append(updateArray_set, upSet)
-				if len(updateArray_query) == Config.BulkSize {
-					m.updateBulk(sess, &updateArray_query, &updateArray_set, &updateArray_delete)
-				}
-				mergeLock.Unlock()
-			}
-		}(k, v)
-		index++
-		if index%500 == 0 {
-			logger.Info("第", *number, "次合并数据:", index)
-		}
-	}
-	mergeWait.Wait()
-	if len(saveArray) > 0 {
-		m.saveBulk(nil, &saveArray, &saveArray_delete)
-	}
-	if len(updateArray_query) > 0 {
-		m.updateBulk(nil, &updateArray_query, &updateArray_set, &updateArray_delete)
-	}
-	if len(invalidArray_delete) > 0 {
-		m.delBulk(nil, &invalidArray_delete)
-	}
-	logger.Info("第", *number, "次合并数据结束。。。", index)
-}
-func (m *MoveJob) saveBulk(sess *mgo.Session, saves *[]map[string]interface{}, deletes *[]interface{}) {
-	if sess == nil {
-		sess = mongodb.GetMgoConn()
-		defer mongodb.DestoryMongoConn(sess)
-	}
-	coll := sess.DB(Config.Mongodb.DbName).C(Pushspace_entniche)
-	bulk := coll.Bulk()
-	for _, v := range *saves {
-		bulk.Insert(v)
-	}
-	_, err := bulk.Run()
-	if nil != err {
-		logger.Info("BulkError", err)
-	} else {
-		m.delBulk(sess, deletes)
-	}
-	*saves = []map[string]interface{}{}
-}
-func (m *MoveJob) updateBulk(sess *mgo.Session, array_q, array_s *[]map[string]interface{}, array_d *[]interface{}) {
-	if sess == nil {
-		sess = mongodb.GetMgoConn()
-		defer mongodb.DestoryMongoConn(sess)
-	}
-	coll := sess.DB(Config.Mongodb.DbName).C(Pushspace_entniche)
-	bulk := coll.Bulk()
-	for k, v := range *array_q {
-		bulk.Update(v, (*array_s)[k])
-	}
-	_, err := bulk.Run()
-	if nil != err {
-		logger.Info("UpdateBulkError", err)
-	} else {
-		m.delBulk(sess, array_d)
-	}
-	*array_q = []map[string]interface{}{}
-	*array_s = []map[string]interface{}{}
-}
-func (m *MoveJob) delBulk(sess *mgo.Session, array *[]interface{}) {
-	if sess == nil {
-		sess = mongodb.GetMgoConn()
-		defer mongodb.DestoryMongoConn(sess)
-	}
-	coll := sess.DB(Config.Mongodb.DbName).C(Pushspace_entniche_temp)
-	count := 0
-	bulk := coll.Bulk()
-	for _, v := range *array {
-		count++
-		bulk.Remove(map[string]interface{}{"_id": v})
-		if count == Config.BigBulkSize {
-			_, err := bulk.Run()
-			if nil != err {
-				logger.Info("DelBulkError", err)
-			}
-			count = 0
-			bulk = coll.Bulk()
-		}
-	}
-	if count > 0 {
-		_, err := bulk.Run()
-		if nil != err {
-			logger.Info("DelBulkError", err)
-		}
-	}
-	*array = []interface{}{}
-}

+ 0 - 383
src/jfw/modules/pushentniche/src/push/job/projectjob.go

@@ -1,383 +0,0 @@
-//关联项目推送
-package job
-
-import (
-	. "public"
-	. "push/config"
-	. "push/util"
-	"qfw/util"
-	"qfw/util/mongodb"
-	"qfw/util/mongodbutil"
-	"qfw/util/redis"
-	"sort"
-	"strings"
-	"sync"
-	"time"
-
-	"github.com/donnie4w/go-logger/logger"
-	"gopkg.in/mgo.v2/bson"
-)
-
-type ProjectPushJob struct {
-}
-
-func (p *ProjectPushJob) Execute() {
-	Jobs.Push.lock.Lock()
-	defer func() {
-		ClearEnt()
-		Jobs.Push.lock.Unlock()
-	}()
-	logger.Info("开始关联项目推送任务。。。")
-	InitEnt()
-	unix := time.Now().Unix()
-	projects := p.loadProject()
-	startId := ""
-	batchIndex := 0
-	//
-	pushPool := make(chan bool, Config.ProjectPushPoolSize)
-	pushWait := &sync.WaitGroup{}
-	for {
-		batchIndex++
-		batchCount, datas := p.loadPushspace_project(batchIndex, &startId)
-		logger.Info("开始第", batchIndex, "次关联项目匹配。。。")
-		index := 0
-		for k, v := range *datas {
-			pushPool <- true
-			pushWait.Add(1)
-			go func(unique string, list []map[string]interface{}) {
-				defer util.Catch()
-				defer func() {
-					<-pushPool
-					pushWait.Done()
-				}()
-				uniques := strings.Split(unique, "_")
-				if len(uniques) != 3 {
-					return
-				}
-				ui := &UserInfo{}
-				ui.EntId = util.IntAll(uniques[1])
-				if Ents[ui.EntId] == nil {
-					logger.Error("没有找到该企业", ui.EntId)
-					p.Delete(unique)
-					return
-				}
-				if uniques[0] == "dis" {
-					ui.DisId = util.ObjToString(uniques[2])
-				} else if uniques[0] == "dept" {
-					ui.DeptId = util.IntAll(uniques[2])
-					if EntDepts[ui.DeptId] == nil {
-						logger.Error("没有找到该部门", ui.DeptId)
-						p.Delete(unique)
-						return
-					}
-					ui.DeptName = EntDepts[ui.DeptId].Name
-				} else if uniques[0] == "user" {
-					ui.Id = util.IntAll(uniques[2])
-					if EntUsers[ui.Id] == nil {
-						logger.Error("没有找到该人员", ui.EntId)
-						p.Delete(unique)
-						return
-					}
-				} else {
-					return
-				}
-				sess := mongodb.GetMgoConn()
-				defer mongodb.DestoryMongoConn(sess)
-				var u map[string]interface{}
-				var query map[string]interface{}
-				if ui.DeptId > 0 {
-					query = map[string]interface{}{
-						"i_entid":  ui.EntId,
-						"i_deptid": ui.DeptId,
-					}
-				} else if ui.Id > 0 {
-					query = map[string]interface{}{
-						"i_entid":  ui.EntId,
-						"i_userid": ui.Id,
-					}
-				} else {
-					return
-				}
-				sess.DB(Config.Mongodb.DbName).C(Entniche_rule).FindId(query).Select(map[string]interface{}{
-					"o_entniche.i_projectmatch": 1,
-				}).One(&u)
-				if u == nil || len(u) == 0 {
-					logger.Error(ui.EntName, ui.EntId, ui.DeptName, ui.DeptId, ui.Id, "没有找到相关信息")
-					p.Delete(unique)
-					return
-				}
-				o_entniche, _ := u["o_entniche"].(map[string]interface{})
-				if util.IntAll(o_entniche["i_projectmatch"]) == 0 {
-					logger.Info(ui.EntName, ui.EntId, ui.DeptName, ui.DeptId, ui.Id, "关联项目推送没有打开")
-					return
-				}
-				dayCountKey := DayCountKey(ui.Id)
-				dayCount, err := redis.GetNewInt(Pushcache_2_a, dayCountKey)
-				if err != nil {
-					logger.Error(ui.EntName, ui.EntId, ui.DeptName, ui.DeptId, ui.Id, "redis中获取当天推送总数出错", err)
-					return
-				} else if dayCount >= Config.MaxPushSize {
-					return
-				}
-				needCount := Config.MaxPushSize - dayCount
-				sortList := &SortList{}
-				length := 0
-				i := len(list)
-				for {
-					var updateProject [][]map[string]interface{}
-					for i > 0 {
-						i--
-						projectId, _ := list[i]["projectid"].(string)
-						pi, ok := projects.Load(projectId)
-						if !ok {
-							return
-						}
-						subtypes, _ := list[i]["subtypes"].([]interface{})
-						maxId, _ := list[i]["maxid"].(string)
-						userSubtype := map[string]bool{}
-						for _, t := range subtypes {
-							userSubtype[util.ObjToString(t)] = true
-						}
-						//
-						project, _ := pi.(map[string]interface{})
-						project_list, _ := project["list"].([]interface{})
-						infoId := ""
-						for _, pl := range project_list {
-							plm, _ := pl.(map[string]interface{})
-							infoId, _ = plm["infoid"].(string)
-							if bson.ObjectIdHex(infoId) <= bson.ObjectIdHex(maxId) {
-								continue
-							}
-							publishtime := util.Int64All(plm["publishtime"])
-							if unix-publishtime > Config.ProjectPublishTimeLimit { //发布时间7天之内
-								continue
-							}
-							subtype, _ := plm["subtype"].(string)
-							if len(userSubtype) > 0 && !userSubtype[subtype] {
-								continue
-							}
-							isExists, err := redis.Exists(Pushcache_2_a, PushInfoKey(ui.Id, infoId))
-							if err != nil {
-								logger.Error("推送信息判重出错", err)
-								continue
-							}
-							if isExists {
-								continue
-							}
-							length++
-							//满足条件,可以推送
-							info := map[string]interface{}{}
-							for _, field := range InfoSaveFields {
-								if field == "_id" || plm[field] == nil {
-									continue
-								}
-								info[field] = plm[field]
-							}
-							info["_id"] = infoId
-							*sortList = append(*sortList, &MatchInfo{Info: &info})
-						}
-						if infoId != maxId {
-							updateProject = append(updateProject, []map[string]interface{}{
-								map[string]interface{}{
-									"_id": list[i]["_id"],
-								},
-								map[string]interface{}{
-									"$set": map[string]interface{}{
-										"maxid": infoId,
-									},
-								},
-							})
-							if len(updateProject) == Config.BigBulkSize {
-								break
-							}
-						}
-					}
-					if len(updateProject) > 0 {
-						mongodb.NewUpdateBulk(Pushspace_entniche_project, true, true, updateProject...)
-					}
-					if len(updateProject) < Config.BigBulkSize {
-						break
-					}
-				}
-				if length == 0 {
-					return
-				}
-				sort.Sort(*sortList)
-				if length > needCount {
-					length = needCount
-				}
-				saveArray := make([]*MatchInfo, length)
-				for sk, sl := range *sortList {
-					saveArray[length-1-sk] = sl
-					if sk == length-1 {
-						break
-					}
-				}
-				var uIds map[int]bool
-				if ui.DeptId > 0 {
-					uIds = GetDeptUserIds(ui)
-					if uIds == nil {
-						logger.Info("该规则没有需要推送的员工", ui.EntName, ui.EntId, ui.DeptName, ui.DeptId, ui.DisId)
-						return
-					}
-				} else if ui.Id > 0 {
-					uIds = map[int]bool{ui.Id: true}
-				} else {
-					return
-				}
-				for uId, _ := range uIds {
-					newUi := &UserInfo{
-						Id:       uId,
-						EntId:    ui.EntId,
-						EntName:  ui.EntName,
-						DeptId:   ui.DeptId,
-						DeptName: ui.DeptName,
-					}
-					if pushDate := SaveToPushsubscribe(true, newUi, &saveArray); pushDate > 0 {
-						logger.Info(newUi.EntName, newUi.EntId, newUi.DeptName, newUi.DeptId, newUi.Id, "关联项目推送保存成功", pushDate, length)
-						redis.Put(Pushcache_2_a, dayCountKey, dayCount+length, OneDaySecond)
-						for _, v := range saveArray {
-							redis.Put(Pushcache_2_a, PushInfoKey(newUi.Id, util.ObjToString((*v.Info)["_id"])), 1, OneDaySecond)
-						}
-					} else {
-						logger.Info(newUi.EntName, newUi.EntId, newUi.DeptName, newUi.DeptId, newUi.Id, "关联项目推送保存出错", pushDate)
-					}
-				}
-			}(k, v)
-			index++
-			if index%500 == 0 {
-				logger.Info("第", batchIndex, "次关联项目匹配:", index)
-			}
-		}
-		pushWait.Wait()
-		logger.Info("第", batchIndex, "次关联项目匹配结束", index)
-		if batchCount < Config.PushBatch {
-			break
-		}
-	}
-	ProjectTask.Pici = unix
-	util.WriteSysConfig("./projecttask.json", &ProjectTask)
-	p.Clear()
-	logger.Info("关联项目推送任务结束。。。", unix)
-}
-
-//分批次加载pushspace_project表数据
-func (p *ProjectPushJob) loadPushspace_project(batchIndex int, startId *string) (int, *map[string][]map[string]interface{}) {
-	query := map[string]interface{}{}
-	if *startId != "" {
-		query["_id"] = map[string]interface{}{
-			"$lt": bson.ObjectIdHex(*startId),
-		}
-	}
-	if len(Config.TestQuery) > 0 {
-		for k, v := range Config.TestQuery {
-			query[k] = v
-		}
-	}
-	//query = map[string]interface{}{
-	//"_id": bson.ObjectIdHex("5dce558cc9122cb37872aa61"),
-	//}
-	logger.Info("开始加载第", batchIndex, "批关联项目", query)
-	index := 0
-	//一个用户最多加载最新的一万个关联项目
-	project_count := map[string]int{}
-	datas := map[string][]map[string]interface{}{}
-	prevUnique := ""
-	sess := mongodb.GetMgoConn()
-	defer mongodb.DestoryMongoConn(sess)
-	it := sess.DB(Config.Mongodb.DbName).C(Pushspace_entniche_project).Find(query).Select(map[string]interface{}{
-		"_id":       1,
-		"maxid":     1,
-		"subtypes":  1,
-		"entid":     1,
-		"deptid":    1,
-		"userid":    1,
-		"projectid": 1,
-		"unique":    1,
-	}).Sort("-_id", "unique").Iter()
-	for temp := make(map[string]interface{}); it.Next(&temp); {
-		*startId = util.BsonIdToSId(temp["_id"])
-		unique := util.ObjToString(temp["unique"])
-		if project_count[unique] >= Config.MaxRelationProject {
-			continue
-		}
-		project_count[unique] = project_count[unique] + 1
-		datas[unique] = append(datas[unique], temp)
-		temp = make(map[string]interface{})
-		index++
-		if index >= Config.PushBatch && unique != prevUnique {
-			break
-		}
-		prevUnique = unique
-	}
-	logger.Info("第", batchIndex, "批关联项目加载结束", index, *startId)
-	return index, &datas
-}
-
-//加载项目数据
-func (p *ProjectPushJob) loadProject() *sync.Map {
-	logger.Info("开始加载项目。。。")
-	sess := mongoutil.GetMgoConn(Config.ProjectMongodb.Alias)
-	defer mongoutil.DestoryMongoConn(Config.ProjectMongodb.Alias, sess)
-	query := map[string]interface{}{
-		"pici": map[string]interface{}{
-			"$gte": ProjectTask.Pici,
-		},
-	}
-	//query = map[string]interface{}{
-	//"_id": bson.ObjectIdHex("5da828a6e138234108b4c02e"),
-	//}
-	it := sess.DB(Config.ProjectMongodb.DbName).C(Config.ProjectMongodb.CollName).Find(query).Select(map[string]interface{}{
-		"_id":  1,
-		"list": 1,
-	}).Sort("_id").Iter()
-	projectMap := &sync.Map{}
-	index := 0
-	loadPool := make(chan bool, Config.LoadProjectPoolSize)
-	loadWait := &sync.WaitGroup{}
-	for m := make(map[string]interface{}); it.Next(&m); {
-		loadPool <- true
-		loadWait.Add(1)
-		go func(data map[string]interface{}) {
-			defer util.Catch()
-			defer func() {
-				<-loadPool
-				loadWait.Done()
-			}()
-			_id := util.BsonIdToSId(data["_id"])
-			projectMap.Store(_id, data)
-		}(m)
-		m = make(map[string]interface{})
-		index++
-		if index%500 == 0 {
-			logger.Info("加载项目:", index)
-		}
-	}
-	loadWait.Wait()
-	logger.Info("加载项目结束。。。", index)
-	return projectMap
-}
-
-//清理三个月前的数据
-func (p *ProjectPushJob) Clear() {
-	logger.Info("开始清理过期的关联项目数据。。。")
-	sess := mongodb.GetMgoConn()
-	defer mongodb.DestoryMongoConn(sess)
-	_, err := sess.DB(Config.Mongodb.DbName).C(Pushspace_entniche_project).RemoveAll(map[string]interface{}{
-		"createtime": map[string]interface{}{
-			"$lt": time.Now().AddDate(0, -3, 0).Unix(),
-		},
-	})
-	if err != nil {
-		logger.Error("清理过期的关联项目数据错误", err)
-	} else {
-		logger.Info("清理过期的关联项目数据结束。。。")
-	}
-}
-
-//删除
-func (p *ProjectPushJob) Delete(unique string) {
-	sess := mongodb.GetMgoConn()
-	defer mongodb.DestoryMongoConn(sess)
-	sess.DB(Config.Mongodb.DbName).C(Pushspace_entniche_project).Remove(map[string]interface{}{"unique": unique})
-}

+ 0 - 300
src/jfw/modules/pushentniche/src/push/job/pushjob.go

@@ -1,300 +0,0 @@
-//订阅推送
-package job
-
-import (
-	"fmt"
-	"net/http"
-	"os"
-	. "public"
-	. "push/config"
-	. "push/pusher"
-	. "push/util"
-	"qfw/util"
-	"qfw/util/mail"
-	"qfw/util/mongodb"
-	"strconv"
-	"sync"
-	"time"
-
-	"github.com/donnie4w/go-logger/logger"
-	"gopkg.in/mgo.v2/bson"
-)
-
-func init() {
-	if Config.MinutePushSize > 0 {
-		LimitMaxOneMinutePush(&Jobs.Push.minutePushPool, Config.MinutePushSize)
-	}
-	if Config.FastigiumMinutePushSize > 0 {
-		LimitMaxOneMinutePush(&Jobs.Push.fastigiumMinutePushPool, Config.FastigiumMinutePushSize)
-	}
-}
-
-type PushJob struct {
-	lock                    *sync.Mutex
-	minutePushPool          chan bool
-	fastigiumMinutePushPool chan bool
-}
-
-//taskType 1--一天三次推送 2--九点推送
-func (p *PushJob) Execute(taskType int) {
-	p.lock.Lock()
-	defer func() {
-		ClearEnt()
-		p.lock.Unlock()
-	}()
-	InitEnt()
-	p.beforePush(taskType)
-	//每天九点以后,推送每周每月的用户
-	if taskType == 2 {
-		for _, v := range ValieVipRateModes() {
-			p.beforePush(v)
-		}
-	}
-}
-
-//开始推送
-func (p *PushJob) beforePush(taskType int) {
-	var pusher Pusher
-	if taskType == 1 || taskType == 2 {
-		pusher = &NormalPush{}
-	} else if taskType == 3 || taskType == 4 || taskType == 5 {
-		pusher = &SpecialPush{}
-	} else {
-		return
-	}
-	p.StartPush(pusher, taskType)
-}
-
-//开始推送
-func (p *PushJob) StartPush(pusher Pusher, taskType int) {
-	defer util.Catch()
-	logger.Info("推送任务", taskType, "开始推送。。。")
-	batchIndex := 0
-	startId := ""
-	//
-	pushPool := make(chan bool, Config.PushPoolSize)
-	pushWait := &sync.WaitGroup{}
-	hasPushMap := map[string]bool{}
-	hasPushLock := &sync.Mutex{}
-	for {
-		batchIndex++
-		isBreak, users := pusher.OncePushBatch(taskType, batchIndex, &startId)
-		for _, temp := range *users {
-			isTake := true
-			select {
-			case <-time.After(5 * time.Minute):
-				isTake = false
-				logger.Error("推送任务", taskType, "推送放入通道超时,", temp["entid"], temp["entname"], temp["deptid"], temp["userid"], len(p.minutePushPool), len(p.fastigiumMinutePushPool))
-				go func() {
-					if Config.TimeoutWarn != "" {
-						if _, err := http.Get(Config.TimeoutWarn); err != nil {
-							logger.Error("发送告警邮件错误", err)
-						}
-					}
-				}()
-			case pushPool <- true:
-			}
-			pushWait.Add(1)
-			go func(v map[string]interface{}, take bool) {
-				defer util.Catch()
-				defer func() {
-					if take {
-						<-pushPool
-					}
-					pushWait.Done()
-				}()
-				ui := pusher.GetUserInfo(v)
-				if ui == nil {
-					pusher.AfterPush(nil, &UserInfo{}, v)
-					return
-				} else if Ents[ui.EntId] == nil {
-					logger.Info("没有找到该企业", ui.EntId)
-					pusher.AfterPush(nil, &UserInfo{}, v)
-					return
-				}
-				ui.EntName = Ents[ui.EntId].Name
-				//
-				var ids map[int]bool
-				if ui.DeptId > 0 && EntDepts[ui.DeptId] != nil {
-					ui.DeptName = EntDepts[ui.DeptId].Name
-					ids = GetDeptUserIds(ui)
-					if ids == nil {
-						logger.Info("该规则没有需要推送的员工", ui.EntName, ui.EntId, ui.DeptName, ui.DeptId, ui.DisId)
-						pusher.AfterPush(nil, &UserInfo{}, v)
-						return
-					}
-				} else if ui.Id > 0 && EntUsers[ui.Id] != nil {
-					ids = map[int]bool{ui.Id: true}
-				} else {
-					pusher.AfterPush(nil, &UserInfo{}, v)
-					return
-				}
-				var pushResult *PushResult
-				for id, _ := range ids {
-					if EntUsers[id] == nil {
-						logger.Error("mysql中没有找到该用户", ui.EntName, ui.EntId, ui.DeptName, ui.DeptId, id)
-						continue
-					} else if EntUsers[id].Power == 0 {
-						logger.Error("该用户没有权限", ui.EntName, ui.EntId, ui.DeptName, ui.DeptId, id)
-						continue
-					}
-					ui.Id = id
-					ui.Phone = EntUsers[id].Phone
-					ui.Email = EntUsers[id].Mail
-					u, pushWay := p.AppendGetUserInfo(ui)
-					if u == nil {
-						continue
-					}
-					logger.Info("推送任务", taskType, "开始推送用户", ui.EntName, ui.EntId, ui.DeptName, ui.DeptId, "id", u.Id, "MId", u.MId, "phone", u.Phone, "jpushid", u.Jpushid, "opushid", u.Opushid, "phoneType", u.AppPhoneType, "rateMode", u.RateMode)
-					if pushWay.AppPush || pushWay.MailPush {
-						//去重 -- start
-						hasPushLock.Lock()
-						exists_key := fmt.Sprintf("%d_%d", u.EntId, u.Id)
-						if hasPushMap[exists_key] {
-							logger.Info("推送任务", taskType, "过滤掉重复推送用户", ui.EntName, ui.EntId, ui.DeptName, ui.DeptId, "id", u.Id, "MId", u.MId, "phone", u.Phone)
-							hasPushLock.Unlock()
-							continue
-						}
-						hasPushMap[exists_key] = true
-						hasPushLock.Unlock()
-						//去重 -- end
-						pr := p.doPush(pusher, taskType, pushWay, u, ToSortList(v["list"]))
-						if pr != nil && pr.PushDate > 0 {
-							pushResult = pr
-						}
-					}
-				}
-				pusher.AfterPush(pushResult, &UserInfo{}, v)
-			}(temp, isTake)
-		}
-		if isBreak {
-			break
-		}
-	}
-	pushWait.Wait()
-	logger.Info("推送任务结束。。。", taskType)
-}
-
-func (p *PushJob) AppendGetUserInfo(u *UserInfo) (*UserInfo, *PushWay) {
-	user := mongodb.FindOneByField(User, map[string]interface{}{
-		"i_appid": 2,
-		"s_phone": u.Phone,
-	}, `{"_id":1,"s_jpushid":1,"s_opushid":1,"s_appponetype":1}`)
-	if user == nil || len(*user) == 0 {
-		logger.Error("mongodb中没有找到该用户", u.EntName, u.EntId, u.DeptName, u.DeptId, u.Id, u.Phone)
-		return nil, nil
-	}
-	u.MId = util.BsonIdToSId((*user)["_id"])
-	u.Jpushid = util.ObjToString((*user)["s_jpushid"])
-	u.Opushid = util.ObjToString((*user)["s_opushid"])
-	u.AppPhoneType = util.ObjToString((*user)["s_appponetype"])
-	logger.Info("mongodb中找到该用户", u.EntName, u.EntId, u.DeptName, u.DeptId, u.Id, u.Phone, u.MId, u.Jpushid, u.Opushid, u.AppPhoneType)
-	pushWay := NewPushWay(u)
-	return u, pushWay
-}
-
-//进入具体推送
-func (p *PushJob) doPush(pusher Pusher, taskType int, pushWay *PushWay, u *UserInfo, sl *SortList) (pushResult *PushResult) {
-	defer util.Catch()
-	now := time.Now()
-	//限制一分钟最大的推送数量
-	if p.fastigiumMinutePushPool != nil {
-		if hour := now.Hour(); hour >= FastigiumStart && hour <= FastigiumEnd {
-			<-p.fastigiumMinutePushPool //高峰期
-		}
-	} else if p.minutePushPool != nil {
-		<-p.minutePushPool //正常期
-	}
-	pushParam := pusher.GetPushParam(pushWay.MailPush, u, sl)
-	if pushParam == nil || pushParam.InfosLength == 0 {
-		logger.Info("推送任务", taskType, "没有要推送的数据!", u.EntName, u.EntId, u.DeptName, u.DeptId, u.Id, u.MId)
-		return
-	}
-	pushResult = &PushResult{
-		Infos:    pushParam.Infos,
-		PushDate: pushParam.PushDate,
-	}
-	if !pushParam.IsPush {
-		return
-	}
-	logger.Info("推送任务", taskType, "开始进行终端推送", u.EntName, u.EntId, u.DeptName, u.DeptId, u.Id, u.MId)
-	if pushWay.AppPush {
-		logger.Info("推送任务", taskType, "开始app推送", u.EntName, u.EntId, u.DeptName, u.DeptId, u.Id, u.MId)
-		descriptAppend := ""
-		if pushParam.InfosLength > 1 {
-			descriptAppend = fmt.Sprintf("\n...(共%d条)", pushParam.InfosLength)
-			pushParam.JpushTitle = fmt.Sprintf("1. %s", pushParam.JpushTitle)
-		}
-		go mongodb.Update(User, map[string]interface{}{
-			"_id": bson.ObjectIdHex(u.MId),
-		}, map[string]interface{}{
-			"$inc": map[string]interface{}{
-				"i_apppushunread": 1,
-			},
-		}, false, false)
-		isPushOk := SendApp(map[string]interface{}{
-			"phoneType":      u.AppPhoneType,
-			"descript":       pushParam.JpushTitle,
-			"descriptAppend": descriptAppend,
-			"type":           "bid",
-			"userId":         u.MId,
-			"url":            "/jyapp/free/sess/" + Se.EncodeString(u.MId+",_id,"+strconv.Itoa(int(now.Unix()))+",entnichehistorypush") + "__" + fmt.Sprint(pushParam.PushDate) + "__" + util.SE.Encode2HexByCheck(fmt.Sprintf("entniche_%d_%d", u.EntId, u.Id)) + "__" + util.SE.Encode2HexByCheck(u.EntName),
-			"otherPushId":    u.Opushid,
-			"jgPushId":       u.Jpushid, //极光-推送id
-		})
-		if isPushOk {
-			pushResult.AppStatus = 1
-		} else {
-			pushResult.AppStatus = -1
-		}
-		logger.Info("推送任务", taskType, "app推送结束", isPushOk, u.EntName, u.EntId, u.DeptName, u.DeptId, u.Id, u.MId)
-	}
-	//发送邮件
-	if pushWay.MailPush {
-		logger.Info("推送任务", taskType, "开始邮箱推送", u.EntName, u.EntId, u.DeptName, u.DeptId, u.Id, u.MId)
-		according := Config.Mail_according
-		html := fmt.Sprintf(Config.Mail_html, according, pushParam.MailContent)
-		isPushOk := p.sendMail(u.Email, Config.Mail_title, html, nil)
-		if isPushOk {
-			pushResult.MailStatus = 1
-		} else {
-			pushResult.MailStatus = -1
-		}
-		logger.Info("推送任务", taskType, "邮箱推送结束", isPushOk, u.EntName, u.EntId, u.DeptName, u.DeptId, u.Id, u.MId)
-	}
-	return
-}
-
-//推送邮件(含附件)
-func (p *PushJob) sendMail(email, subject, html string, fmdatas []map[string]interface{}) bool {
-	if !Config.IsPushMail || len(Gmails) == 0 {
-		return true
-	}
-	if Config.MailSleep > 0 {
-		time.Sleep(time.Duration(Config.MailSleep) * time.Millisecond)
-	}
-	defer util.Catch()
-	//生成附件
-	var fnamepath, rename string
-	// if len(fmdatas) > 0 { //开启导出
-	// 	fnamepath, rename = GetBidInfoXlsx(fmdatas)
-	// }
-	status := false
-	index := len(email) % 2
-	if index >= len(Gmails) {
-		index = 0
-	}
-	gmail := Gmails[index]
-	for i := 0; i < len(Gmails); i++ {
-		status = mail.GSendMail("剑鱼标讯", email, "", "", subject, html, fnamepath, rename, gmail)
-		if status {
-			break
-		} else {
-			gmail = Gmails[index^1]
-		}
-	}
-	if fnamepath != "" {
-		os.Remove(fnamepath)
-	}
-	return status
-}

+ 0 - 64
src/jfw/modules/pushentniche/src/push/job/timetask.go

@@ -1,64 +0,0 @@
-package job
-
-import (
-	"log"
-	. "push/config"
-	"qfw/util"
-	"strings"
-	"time"
-)
-
-type TimeTask struct{}
-
-func (t *TimeTask) Run() {
-	go t.push() //推送
-	go t.move() //迁移数据
-	go t.crontab("01:00", func() {
-		Jobs.ProjectPush.Clear()
-	})
-}
-func (t *TimeTask) push() {
-	for _, v := range Config.OtherPushTimes {
-		go t.crontab(v, func() {
-			Jobs.Push.Execute(1)
-		})
-	}
-	go t.crontab(Config.OncePushTime, func() {
-		Jobs.Push.Execute(2)
-	})
-	go t.crontab(Config.ProjectPushTime, func() {
-		Jobs.ProjectPush.Execute()
-	})
-}
-
-func (t *TimeTask) crontab(tm string, f func()) {
-	h_m := strings.Split(tm, ":")
-	if len(h_m) == 2 {
-		now := time.Now()
-		newDate := time.Date(now.Year(), now.Month(), now.Day(), util.IntAll(h_m[0]), util.IntAll(h_m[1]), 0, 0, time.Local)
-		if newDate.Before(now) {
-			newDate = newDate.AddDate(0, 0, 1)
-		}
-		sub := newDate.Sub(now)
-		log.Println("start", tm, "after", sub)
-		timer := time.NewTimer(sub)
-		for {
-			select {
-			case <-timer.C:
-				go f()
-				timer.Reset(time.Hour * 24)
-			}
-		}
-	} else {
-		log.Fatalln("crontab", tm)
-	}
-}
-
-func (t *TimeTask) move() {
-	d := time.Duration(Config.MoveDuration) * time.Minute
-	log.Println("start move after", d)
-	time.AfterFunc(d, func() {
-		Jobs.Move.Execute()
-		t.move()
-	})
-}

+ 0 - 39
src/jfw/modules/pushentniche/src/push/main.go

@@ -1,39 +0,0 @@
-//订阅推送-推送服务
-package main
-
-import (
-	"flag"
-	"log"
-	. "push/job"
-
-	"github.com/donnie4w/go-logger/logger"
-)
-
-func main() {
-	modle := flag.Int("m", 0, "0 定时任务模式推送;1 非定时任务模式推送;2 定时任务模式推送之前先执行-t的任务;3 补推;4 关联项目推送")
-	move := flag.Int("v", 0, "1 优先迁移数据")
-	taskType := flag.Int("t", 1, "1 一天三次推送;2 九点推送;3 每周;4 每月;5 每周+每月")
-	flag.Parse()
-	logger.SetConsole(false)
-	logger.SetRollingDaily("./logs", "push.log")
-	//
-	log.Println("订阅推送-推送程序启动。。。")
-	//Jobs.Move.Execute()
-	//Jobs.Push.Execute(2)
-	//Jobs.ProjectPush.Execute()
-	//return
-	if *move == 1 {
-		Jobs.Move.Execute()
-	}
-	if *modle == 1 {
-		Jobs.Push.Execute(*taskType)
-		return
-	} else if *modle == 2 {
-		Jobs.Push.Execute(*taskType)
-	} else if *modle == 4 {
-		Jobs.ProjectPush.Execute()
-		return
-	}
-	(&TimeTask{}).Run()
-	<-chan bool(nil)
-}

+ 0 - 1
src/jfw/modules/pushentniche/src/push/projecttask.json

@@ -1 +0,0 @@
-{"pici":1581871507}

+ 0 - 196
src/jfw/modules/pushentniche/src/push/pusher/normalpush.go

@@ -1,196 +0,0 @@
-package pusher
-
-import (
-	. "public"
-	. "push/config"
-	. "push/util"
-	"qfw/util"
-	"qfw/util/mongodb"
-	"qfw/util/redis"
-
-	"github.com/donnie4w/go-logger/logger"
-	"gopkg.in/mgo.v2/bson"
-)
-
-//正常推送,一天推送三次或者一天一次
-type NormalPush struct {
-}
-
-//获取需要推送的用户
-func (n *NormalPush) OncePushBatch(taskType, batchIndex int, startId *string) (bool, *[]map[string]interface{}) {
-	var query map[string]interface{}
-	//根据任务类型,查找ratemode
-	if taskType == 1 {
-		query = map[string]interface{}{
-			"ratemode": map[string]interface{}{
-				"$in": []int{1, 3, 4},
-			},
-		}
-	} else if taskType == 2 {
-		rateModes := ValieVipRateModes()
-		rateModes = append(rateModes, 2)
-		query = map[string]interface{}{
-			"ratemode": map[string]interface{}{
-				"$in": rateModes,
-			},
-		}
-	} else {
-		logger.Error("taskType error", taskType)
-		return true, nil
-	}
-	if len(Config.TestQuery) > 0 {
-		for k, v := range Config.TestQuery {
-			query[k] = v
-		}
-	}
-	if *startId != "" {
-		query["_id"] = map[string]interface{}{
-			"$gt": bson.ObjectIdHex(*startId),
-		}
-	}
-	return GetPushDatas(taskType, batchIndex, Pushspace_entniche, startId, query)
-}
-
-func (n *NormalPush) GetUserInfo(m map[string]interface{}) *UserInfo {
-	words, _ := m["words"].([]interface{})
-	keys := util.ObjArrToStringArr(words)
-	ui := &UserInfo{
-		Id:       util.IntAll(m["userid"]),
-		EntId:    util.IntAll(m["entid"]),
-		DeptId:   util.IntAll(m["deptid"]),
-		DisId:    util.ObjToString(m["distributeid"]),
-		Keys:     keys,
-		EntName:  util.ObjToString(m["entname"]),
-		Size:     util.IntAll(m["size"]),
-		AppPush:  util.IntAll(m["apppush"]),
-		MailPush: util.IntAll(m["mailpush"]),
-		RateMode: util.IntAllDef(m["ratemode"], 2),
-	}
-	return ui
-}
-
-//推送以后处理
-func (n *NormalPush) AfterPush(pushResult *PushResult, u *UserInfo, v map[string]interface{}) bool {
-	if pushResult != nil && pushResult.PushDate == 0 {
-		return false
-	}
-	//判断是否要删除数据
-	sess := mongodb.GetMgoConn()
-	defer mongodb.DestoryMongoConn(sess)
-	err := sess.DB(Config.Mongodb.DbName).C(Pushspace_entniche).RemoveId(v["_id"])
-	if err != nil {
-		logger.Error("推送任务", u.EntName, u.EntId, u.DeptName, u.DeptId, u.Id, u.DisId, "删除出错", err)
-		return false
-	}
-	return true
-}
-func (n *NormalPush) GetPushParam(mailPush bool, u *UserInfo, sl *SortList) *PushParam {
-	dayCountKey := DayCountKey(u.Id)
-	dayCount := redis.GetInt(Pushcache_2_a, dayCountKey)
-	if dayCount >= Config.MaxPushSize {
-		return nil
-	}
-	pushParam := NewPushParam(true, dayCount, mailPush, u, sl)
-	if pushParam.InfosLength == 0 {
-		return pushParam
-	}
-	//推送记录id
-	pushParam.PushDate = SaveToPushsubscribe(false, u, &pushParam.Infos)
-	if pushParam.PushDate > 0 {
-		redis.Put(Pushcache_2_a, dayCountKey, dayCount+pushParam.InfosLength, OneDaySecond)
-		for _, v := range pushParam.Infos {
-			redis.Put(Pushcache_2_a, PushInfoKey(u.Id, util.ObjToString((*v.Info)["_id"])), 1, OneDaySecond)
-		}
-	} else {
-		logger.Info(u.EntName, u.EntId, u.DeptName, u.DeptId, u.Id, u.MId, "订阅推送保存出错", pushParam.InfosLength)
-		return pushParam
-	}
-	logger.Info(u.EntName, u.EntId, u.DeptName, u.DeptId, u.Id, u.MId, "订阅推送保存成功", pushParam.PushDate, pushParam.InfosLength)
-	if u.RateMode == 3 || u.RateMode == 4 {
-		pushParam.IsPush = false
-		n.tempSave(u, pushParam)
-	} else {
-		pushParam.IsPush = true
-	}
-	return pushParam
-}
-
-//vip 每周 每月推送 暂时保存
-func (n *NormalPush) tempSave(u *UserInfo, pushParam *PushParam) {
-	pLength := len(pushParam.Infos)
-	logger.Info(u.EntName, u.EntId, u.DeptName, u.DeptId, u.Id, u.MId, "开始保存", pLength)
-	if pLength == 0 {
-		return
-	}
-	sess := mongodb.GetMgoConn()
-	defer mongodb.DestoryMongoConn(sess)
-	var data map[string]interface{}
-	coll := sess.DB(Config.Mongodb.DbName).C(Pushspace_entniche_wait)
-	unique := GetUnique(u.EntId, u.DeptId, u.Id, u.DisId)
-	coll.Find(map[string]interface{}{
-		"unique":   unique,
-		"status":   1,
-		"ratemode": u.RateMode,
-	}).Select(map[string]interface{}{
-		"size": 1,
-		"list": 1,
-		"date": 1,
-	}).One(&data)
-	nowymd := util.NowFormat(util.Date_yyyyMMdd)
-	maxLength := 50
-	if data == nil { //批量新增
-		if pLength > maxLength {
-			pushParam.Infos = pushParam.Infos[:maxLength]
-		}
-		err := coll.Insert(map[string]interface{}{
-			"unique":       unique,
-			"entname":      u.EntName,
-			"entid":        u.EntId,
-			"deptid":       u.DeptId,
-			"userid":       u.Id,
-			"distributeid": u.DisId,
-			"size":         pLength,
-			"list":         pushParam.Infos,
-			"date":         nowymd,
-			"createtime":   pushParam.PushDate,
-			"status":       1,
-			"ratemode":     u.RateMode,
-		})
-		if err != nil {
-			logger.Error(u.EntName, u.EntId, u.DeptName, u.DeptId, u.Id, "保存出错", err)
-			return
-		}
-	} else { //批量更新
-		upSet := map[string]interface{}{}
-		if nowymd != util.ObjToString(data["date"]) {
-			return
-		}
-		size := util.IntAll(data["size"])
-		set := map[string]interface{}{
-			"size": size + pLength,
-		}
-		oldList, _ := data["list"].([]interface{})
-		if size < maxLength {
-			count := maxLength - size
-			if pLength > count {
-				for i := 0; i < count; i++ {
-					oldList = append(oldList, pushParam.Infos[i])
-				}
-				set["list"] = oldList
-			} else { //追加
-				upSet["$push"] = map[string]interface{}{
-					"list": map[string]interface{}{
-						"$each": pushParam.Infos,
-					},
-				}
-			}
-		}
-		upSet["$set"] = set
-		err := coll.UpdateId(data["_id"], upSet)
-		if err != nil {
-			logger.Error(u.EntName, u.EntId, u.DeptName, u.DeptId, u.Id, "更新出错", err)
-			return
-		}
-	}
-	logger.Info(u.EntName, u.EntId, u.DeptName, u.DeptId, u.Id, "保存结束", pLength)
-}

+ 0 - 13
src/jfw/modules/pushentniche/src/push/pusher/pusher.go

@@ -1,13 +0,0 @@
-package pusher
-
-import (
-	. "public"
-	. "push/util"
-)
-
-type Pusher interface {
-	OncePushBatch(taskType, batchIndex int, startId *string) (bool, *[]map[string]interface{})
-	GetUserInfo(m map[string]interface{}) *UserInfo
-	GetPushParam(mailPush bool, k *UserInfo, sl *SortList) *PushParam
-	AfterPush(pushResult *PushResult, u *UserInfo, v map[string]interface{}) bool
-}

+ 0 - 123
src/jfw/modules/pushentniche/src/push/pusher/specialpush.go

@@ -1,123 +0,0 @@
-package pusher
-
-import (
-	. "public"
-	. "push/config"
-	. "push/util"
-	"qfw/util"
-	"qfw/util/mongodb"
-
-	"github.com/donnie4w/go-logger/logger"
-	"gopkg.in/mgo.v2/bson"
-)
-
-//vip用户每月或者没周推送
-type SpecialPush struct{}
-
-//获取需要推送的用户
-func (s *SpecialPush) OncePushBatch(taskType, batchIndex int, startId *string) (bool, *[]map[string]interface{}) {
-	query := map[string]interface{}{}
-	if taskType == 3 {
-		query["ratemode"] = 3
-	} else if taskType == 4 {
-		query["ratemode"] = 4
-	} else if taskType == 5 {
-		query["ratemode"] = map[string]interface{}{
-			"$in": []int{3, 4},
-		}
-	} else {
-		logger.Error("taskType error", taskType)
-		return true, nil
-	}
-	if len(Config.TestQuery) > 0 {
-		for k, v := range Config.TestQuery {
-			query[k] = v
-		}
-	}
-	if *startId != "" {
-		query["_id"] = map[string]interface{}{
-			"$gt": bson.ObjectIdHex(*startId),
-		}
-	}
-	return GetPushDatas(taskType, batchIndex, Pushspace_entniche_wait, startId, query)
-}
-
-func (s *SpecialPush) GetUserInfo(m map[string]interface{}) *UserInfo {
-	entName := util.ObjToString(m["entname"])
-	rateMode, _ := m["ratemode"].(int)
-	entId := util.IntAll(m["entid"])
-	deptId := util.IntAll(m["deptid"])
-	userId := util.IntAll(m["userid"])
-	var query map[string]interface{}
-	if deptId > 0 {
-		query = map[string]interface{}{
-			"i_entid":  entId,
-			"i_deptid": deptId,
-		}
-	} else if userId > 0 {
-		query = map[string]interface{}{
-			"i_entid":  entId,
-			"i_userid": userId,
-		}
-	} else {
-		s.deletePushspaceVip(m)
-		return nil
-	}
-	sess := mongodb.GetMgoConn()
-	defer mongodb.DestoryMongoConn(sess)
-	var u map[string]interface{}
-	sess.DB(Config.Mongodb.DbName).C(Entniche_rule).Find(query).Select(map[string]interface{}{
-		"o_entniche.i_ratemode": 1,
-		"o_entniche.i_apppush":  1,
-		"o_entniche.i_mailpush": 1,
-	}).One(&u)
-	if u == nil || len(u) == 0 {
-		logger.Error(query, "没有找到该信息")
-		s.deletePushspaceVip(m)
-		return nil
-	}
-	o_entniche, _ := u["o_entniche"].(map[string]interface{})
-	i_ratemode := util.IntAllDef(o_entniche["i_ratemode"], 2)
-	if rateMode != i_ratemode {
-		logger.Info(entName, entId, deptId, "部门规则的推送时间变了", rateMode, i_ratemode)
-		s.deletePushspaceVip(m)
-		return nil
-	}
-	return &UserInfo{
-		Id:         userId,
-		EntId:      entId,
-		EntName:    entName,
-		DeptId:     deptId,
-		RateMode:   rateMode,
-		AppPush:    util.IntAllDef(o_entniche["i_apppush"], 1),
-		MailPush:   util.IntAll(o_entniche["i_mailpush"]),
-		DisId:      util.ObjToString(m["distributeid"]),
-		Size:       util.IntAll(m["size"]),
-		CreateTime: util.Int64All(m["createtime"]),
-	}
-}
-
-func (s *SpecialPush) GetPushParam(mailPush bool, u *UserInfo, sl *SortList) *PushParam {
-	pushParam := NewPushParam(false, -1, mailPush, u, sl)
-	pushParam.IsPush = true
-	pushParam.InfosLength = u.Size
-	pushParam.PushDate = u.CreateTime
-	return pushParam
-}
-
-//推送以后处理
-func (s *SpecialPush) AfterPush(pushResult *PushResult, u *UserInfo, v map[string]interface{}) bool {
-	return s.deletePushspaceVip(v)
-}
-
-//删除临时表数据
-func (s *SpecialPush) deletePushspaceVip(u map[string]interface{}) bool {
-	sess := mongodb.GetMgoConn()
-	defer mongodb.DestoryMongoConn(sess)
-	err := sess.DB(Config.Mongodb.DbName).C(Pushspace_entniche_wait).RemoveId(u["_id"])
-	if err != nil {
-		logger.Error(u["_id"], u["entname"], u["entid"], u["deptid"], u["userid"], u["distributeid"], Pushspace_entniche_wait, "删除出错", err)
-		return false
-	}
-	return true
-}

+ 0 - 50
src/jfw/modules/pushentniche/src/push/util/db.go

@@ -1,50 +0,0 @@
-package util
-
-import (
-	"log"
-	. "push/config"
-	"qfw/util/jy"
-	"qfw/util/mongodb"
-	"qfw/util/mongodbutil"
-	"qfw/util/mysql"
-	"qfw/util/redis"
-)
-
-var Mysql *mysql.Mysql
-var SaveMysql *mysql.Mysql
-
-func init() {
-	mongodb.InitMongodbPool(Config.Mongodb.Size, Config.Mongodb.Address, Config.Mongodb.DbName)
-	project := mongoutil.PoolConfig{
-		Alias: Config.ProjectMongodb.Alias,
-		Addr:  Config.ProjectMongodb.Address,
-		DB:    Config.ProjectMongodb.DbName,
-		Size:  Config.ProjectMongodb.Size,
-	}
-	mongoutil.Config = append(mongoutil.Config, project)
-	mongoutil.InitMongodbPool()
-	log.Println("mongodb初始化完成!")
-	redis.InitRedis(Config.RedisServers)
-	log.Println("redis初始化完成!")
-	Mysql = &mysql.Mysql{
-		DBName:       Config.Mysql.DbName,
-		Address:      Config.Mysql.Address,
-		UserName:     Config.Mysql.UserName,
-		PassWord:     Config.Mysql.PassWord,
-		MaxOpenConns: Config.Mysql.MaxOpenConns,
-		MaxIdleConns: Config.Mysql.MaxIdleConns,
-	}
-	Mysql.Init()
-	//
-	SaveMysql = &mysql.Mysql{
-		DBName:       Config.SaveMysql.DbName,
-		Address:      Config.SaveMysql.Address,
-		UserName:     Config.SaveMysql.UserName,
-		PassWord:     Config.SaveMysql.PassWord,
-		MaxOpenConns: Config.SaveMysql.MaxOpenConns,
-		MaxIdleConns: Config.SaveMysql.MaxIdleConns,
-	}
-	SaveMysql.Init()
-	log.Println("mysql初始化完成!")
-	jy.PushMapping.Init(SaveMysql)
-}

+ 0 - 199
src/jfw/modules/pushentniche/src/push/util/entity.go

@@ -1,199 +0,0 @@
-package util
-
-import (
-	"fmt"
-	. "public"
-	. "push/config"
-	"qfw/util"
-	"qfw/util/mongodb"
-	"regexp"
-	"strings"
-
-	"github.com/donnie4w/go-logger/logger"
-)
-
-var Re = regexp.MustCompile("<[^>]+>([^<]+)?<[^>]+>")
-
-func InitEntDistribute() {
-	sess := mongodb.GetMgoConn()
-	defer mongodb.DestoryMongoConn(sess)
-	it := sess.DB(Config.Mongodb.DbName).C(Entniche_distribute).Find(map[string]interface{}{
-		"i_status": map[string]interface{}{"$ne": 1},
-	}).Select(map[string]interface{}{
-		"_id":      1,
-		"i_deptid": 1,
-	}).Iter()
-	for temp := make(map[string]interface{}); it.Next(&temp); {
-		if temp["i_deptid"] == nil {
-			continue
-		}
-		deptId := util.IntAll(temp["i_deptid"])
-		EntDeptDis[deptId] = append(EntDeptDis[deptId], &EntDistribute{
-			Id:     util.BsonIdToSId(temp["_id"]),
-			DeptId: deptId,
-		})
-		temp = make(map[string]interface{})
-	}
-	logger.Info(Entniche_distribute, "加载完成!")
-}
-
-type UserInfo struct {
-	Id           int    //mysql中user表的id
-	EntId        int    //企业id
-	EntName      string //企业名称
-	DeptId       int    //部门id
-	DeptName     string //部门名称
-	DisId        string
-	MId          string   //mongodb中user表的id
-	Keys         []string //用户原始关键词
-	Phone        string   //app手机号登录
-	Jpushid      string   //极光推送id
-	Opushid      string   //厂商推送id
-	AppPhoneType string   //手机型号
-	AppPush      int      //是否开启app推送
-	MailPush     int      //是否开启邮箱推送
-	RateMode     int      //推送时间
-	Email        string   //邮箱
-	Size         int      //模板消息中需要显示的数量,总条数
-	CreateTime   int64
-}
-
-//推送返回结果
-type PushResult struct {
-	IsVipTempSave bool
-	WxStatus      int
-	AppStatus     int
-	MailStatus    int
-	PushDate      int64
-	Infos         []*MatchInfo
-}
-type PushWay struct {
-	AppPush  bool
-	MailPush bool
-}
-
-//获取推送方式
-func NewPushWay(u *UserInfo) *PushWay {
-	appPush, mailPush := false, false
-	if u.AppPush == 1 {
-		appPush = true
-	}
-	if u.MailPush == 1 {
-		mailPush = true
-	}
-	if u.Jpushid == "" && u.Opushid == "" {
-		appPush = false
-	}
-	if u.Email == "" {
-		mailPush = false
-	}
-	pushWay := &PushWay{
-		AppPush:  appPush,
-		MailPush: mailPush,
-	}
-	logger.Info("用户接收方式", u.EntName, u.EntId, u.DeptName, u.DeptId, "id", u.Id, "Mid", u.MId, "appPush", pushWay.AppPush, "mailPush", pushWay.MailPush)
-	return pushWay
-}
-
-type PushParam struct {
-	JpushTitle   string
-	LastInfoDate int64
-	TitleArray   []string
-	Infos        []*MatchInfo
-	InfosLength  int
-	MailContent  string
-	PushDate     int64
-	IsPush       bool
-}
-
-func NewPushParam(isLimit bool, dayCount int, mailPush bool, u *UserInfo, sl *SortList) *PushParam {
-	mailContent := ""
-	jpushTitle := ""
-	lastInfoDate := int64(0)
-	titleArray := []string{}
-	infos := []*MatchInfo{}
-	infosLength := 0
-	for _, ks := range *sl {
-		infosLength++
-		dayCount++
-		k2 := *ks.Info
-		title := strings.Replace(k2["title"].(string), "\n", "", -1)
-		title = Re.ReplaceAllString(title, "$1")
-		area := util.ObjToString(k2["area"])
-		if area == "A" {
-			area = "全国"
-		}
-		newTitle := fmt.Sprintf("[%s]%s", area, title)
-		infos = append(infos, ks)
-		titleArray = append(titleArray, newTitle)
-		if infosLength == 1 {
-			jpushTitle = title
-			lastInfoDate = util.Int64All(k2["publishtime"])
-		}
-		//增加行业的处理
-		industryClassName := "buyerclass"
-		industry, _ := k2["buyerclass"].(string)
-		if mailPush && infosLength <= 50 { //关于邮件的处理
-			mailSid := util.CommonEncodeArticle("mailprivate", util.ObjToString(k2["_id"]))
-			url := fmt.Sprintf("%s/article/mailprivate/%s.html", Config.JianyuDomain, mailSid)
-			areaClassName := "area"
-			typeClassName := "type"
-			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)
-			//标题替换
-			otitle := title
-			for _, kw := range ks.Keys {
-				kws := strings.Split(kw, "+")
-				n := 0
-				otitle2 := otitle
-				for _, kwn := range kws {
-					ot := strings.Replace(otitle2, kwn, "<span class='keys'>"+kwn+"</span>", 1)
-					if ot != otitle {
-						n++
-						otitle2 = ot
-					} else {
-						break
-					}
-				}
-				if n == len(kws) {
-					otitle = otitle2
-					break
-				}
-			}
-			if industry == "" {
-				industryClassName = ""
-			}
-			if area == "" {
-				areaClassName = ""
-			}
-			if infotype == "" {
-				typeClassName = ""
-			}
-			mailContent += fmt.Sprintf(Config.Mail_content, infosLength, url, otitle, areaClassName, area, typeClassName, infotype, industryClassName, industry, dates)
-		}
-		if isLimit {
-			if dayCount >= Config.MaxPushSize {
-				break
-			}
-		}
-	}
-	return &PushParam{
-		JpushTitle:   jpushTitle,
-		LastInfoDate: lastInfoDate,
-		TitleArray:   titleArray,
-		Infos:        infos,
-		InfosLength:  infosLength,
-		MailContent:  mailContent,
-	}
-}

+ 0 - 91
src/jfw/modules/pushentniche/src/push/util/excel.go

@@ -1,91 +0,0 @@
-package util
-
-import (
-	"log"
-	"os"
-	qu "qfw/util"
-	"time"
-
-	"github.com/tealeg/xlsx"
-)
-
-var Sheets = map[int]xlsx.Sheet{}
-
-func init() {
-	fx, err := xlsx.OpenFile("./xlsx/temp.xlsx")
-	if err != nil {
-		log.Println(err.Error())
-		os.Exit(0)
-	}
-	for k, st := range fx.Sheets {
-		Sheets[k] = *st
-	}
-}
-func GetBidInfoXlsx(data []map[string]interface{}) (fnamepath, rename string) {
-	fx := xlsx.NewFile()
-	sheet := Sheets[0]
-	style := xlsx.NewStyle()
-	style.Alignment.WrapText = true
-	//信息
-	for _, v := range data {
-		row := sheet.AddRow()
-
-		projectname := qu.ObjToString(v["projectname"])
-		if projectname == "" {
-			projectname = qu.ObjToString(v["title"])
-		}
-		cell := row.AddCell()
-		cell.SetValue(projectname)
-		cell.SetStyle(style)
-
-		cell = row.AddCell()
-		cell.SetValue(v["subtype"])
-
-		budget := qu.Float64All(v["budget"]) / float64(10000)
-		cell = row.AddCell()
-		if budget != 0 {
-			cell.SetValue(budget)
-		} else {
-			cell.SetValue("")
-		}
-
-		cell = row.AddCell()
-		cell.SetValue(v["buyer"])
-		cell.SetStyle(style)
-
-		bpt := v["bidopentime"]
-		bidopentime := qu.FormatDateWithObj(&bpt, "2006-01-02 15:04")
-		cell = row.AddCell()
-		cell.SetValue(bidopentime)
-
-		cell = row.AddCell()
-		cell.SetValue(v["winner"])
-		cell.SetStyle(style)
-
-		bidamount := qu.Float64All(v["bidamount"]) / float64(10000)
-		cell = row.AddCell()
-		if bidamount != 0 {
-			cell.SetValue(bidamount)
-		} else {
-			cell.SetValue("")
-		}
-
-		pt := v["publishtime"]
-		publishtime := qu.FormatDateWithObj(&pt, qu.Date_Short_Layout)
-		cell = row.AddCell()
-		cell.SetValue(publishtime)
-	}
-	fx.AppendSheet(sheet, "剑鱼标讯")
-
-	t := time.Now()
-	rename = t.Format("2006-01-02") + ".xlsx"
-	fnamepath = "./xlsx/" + t.Format("20060102150405") + qu.GetRandom(4) + ".xlsx"
-
-	err := fx.Save(fnamepath)
-	//log.Println("err", err)
-	if err != nil {
-		return "", ""
-	} else {
-		return fnamepath, rename
-	}
-}

+ 0 - 22
src/jfw/modules/pushentniche/src/push/util/rpccall.go

@@ -1,22 +0,0 @@
-package util
-
-import (
-	. "push/config"
-	qrpc "qfw/util/rpc"
-	"time"
-)
-
-var (
-	appPushPool = make(chan bool, Config.AppPoolSize)
-)
-
-func SendApp(m map[string]interface{}) bool {
-	appPushPool <- true
-	defer func() {
-		<-appPushPool
-	}()
-	if Config.AppSleep > 0 {
-		time.Sleep(time.Duration(Config.AppSleep) * time.Millisecond)
-	}
-	return qrpc.AppPush(Config.AppPushServiceRpc, m)
-}

+ 0 - 311
src/jfw/modules/pushentniche/src/push/util/util.go

@@ -1,311 +0,0 @@
-package util
-
-import (
-	"encoding/json"
-	. "public"
-	. "push/config"
-	"qfw/util"
-	"qfw/util/jy"
-	"qfw/util/mongodb"
-	"sort"
-	"strings"
-	"time"
-
-	"github.com/donnie4w/go-logger/logger"
-)
-
-var SavePool chan bool
-
-func init() {
-	SavePool = make(chan bool, Config.SavePoolSize)
-}
-func ToSortList(list interface{}) *SortList {
-	sl := make(SortList, 0)
-	if list == nil {
-		return &sl
-	}
-	b, err := json.Marshal(list)
-	if err != nil {
-		return &sl
-	}
-	err = json.Unmarshal(b, &sl)
-	if err != nil {
-		return &sl
-	}
-	sort.Sort(sl)
-	return &sl
-}
-
-//控制一分钟最大推送数,均匀调度
-func LimitMaxOneMinutePush(pushPoll *chan bool, maxOneMinute int) {
-	max := int(maxOneMinute / 60)
-	*pushPoll = make(chan bool, max)
-	go func() {
-		for {
-			time.Sleep(time.Second)
-			for i := 0; i < max; i++ {
-				select {
-				case *pushPoll <- true:
-				default:
-					continue
-				}
-			}
-		}
-	}()
-}
-
-/*获取一批次推送的数据
- *batchIndex < 0 不走分批次加载
- */
-func GetPushDatas(taskType, batchIndex int, collection string, startId *string, query map[string]interface{}) (bool, *[]map[string]interface{}) {
-	logger.Info(taskType, collection, "开始加载第", batchIndex, "批用户", query)
-	users := []map[string]interface{}{}
-	i := 0
-	sess := mongodb.GetMgoConn()
-	defer mongodb.DestoryMongoConn(sess)
-	it := sess.DB(Config.Mongodb.DbName).C(collection).Find(query).Sort("_id").Iter()
-	for temp := make(map[string]interface{}); it.Next(&temp); {
-		i++
-		*startId = util.BsonIdToSId(temp["_id"])
-		users = append(users, temp)
-		temp = make(map[string]interface{})
-		if batchIndex > 0 && i == Config.PushBatch {
-			break
-		}
-	}
-	logger.Info(taskType, collection, "第", batchIndex, "批用户加载结束", *startId)
-	return batchIndex < 0 || i < Config.PushBatch, &users
-}
-
-//获取当前有效的vip推送模式
-func ValieVipRateModes() []int {
-	now := time.Now()
-	rateMode := []int{}
-	if strings.ToLower(now.Weekday().String()) == strings.ToLower(Config.PushWeek) {
-		rateMode = append(rateMode, 3)
-	}
-	if now.Day() == Config.PushDay {
-		rateMode = append(rateMode, 4)
-	}
-	return rateMode
-}
-
-//获取信息行业
-func GetSubScopeClass(subscopeclass interface{}) string {
-	industry := ""
-	if subscopeclass != nil {
-		k2sub := strings.Split(util.ObjToString(subscopeclass), ",")
-		if len(k2sub) > 0 {
-			industry = k2sub[0]
-			if industry != "" {
-				ss := strings.Split(industry, "_")
-				if len(ss) > 1 {
-					industry = ss[0]
-				}
-			}
-		}
-	}
-	return industry
-}
-
-//推送记录保存到mysql
-func SaveToPushsubscribe(isProjectInfo bool, u *UserInfo, matchInfos *[]*MatchInfo) int64 {
-	SavePool <- true
-	defer func() {
-		<-SavePool
-	}()
-	if Config.SaveSleep > 0 {
-		time.Sleep(time.Duration(Config.SaveSleep) * time.Millisecond)
-	}
-	unix := time.Now().Unix()
-	length := len(*matchInfos)
-	fields := []string{"entid", "deptid", "userid", "infoid", "date", "matchkeys", "area", "city", "buyerclass", "type", "toptype", "subtype"}
-	var saveCount int64
-	batchSize := 0
-	values := []interface{}{}
-	var subPush_datas = make([]*jy.SubPushList, length)
-	k := length - 1
-	for i := length - 1; i >= 0; i-- {
-		matchInfo := (*matchInfos)[i]
-		_id := util.ObjToString((*matchInfo.Info)["_id"])
-		//
-		pushCa := &jy.PushCa{
-			Date:   unix,
-			InfoId: _id,
-			Keys:   matchInfo.Keys,
-		}
-		pushCa.Isvip = 1
-		if isProjectInfo {
-			pushCa.Type = 1
-		}
-		subPush_datas[i] = jy.SubscribePush.InfoFormat(pushCa, &(*matchInfo.Info))
-		//
-		deptId := u.DeptId
-		if deptId == 0 {
-			deptId = EntUserDept[u.Id].DeptId
-		}
-		if EntDepts[deptId] != nil {
-			u.DeptName = EntDepts[deptId].Name
-		}
-		values = append(values, u.EntId, deptId, u.Id, _id, unix)
-		if len(matchInfo.Keys) > 0 {
-			values = append(values, strings.Join(matchInfo.Keys, " "))
-		} else {
-			values = append(values, nil)
-		}
-		if area := util.ObjToString((*matchInfo.Info)["area"]); area != "" {
-			if area == "全国" {
-				values = append(values, 0)
-			} else {
-				if area_mapping, ok := jy.PushMapping.Area[area]; ok {
-					values = append(values, area_mapping)
-				} else {
-					values = append(values, nil)
-				}
-			}
-		} else {
-			values = append(values, nil)
-		}
-		if city := util.ObjToString((*matchInfo.Info)["city"]); city != "" {
-			if city_mapping, ok := jy.PushMapping.City[city]; ok {
-				values = append(values, city_mapping)
-			} else {
-				values = append(values, nil)
-			}
-		} else {
-			values = append(values, nil)
-		}
-		if buyerclass := util.ObjToString((*matchInfo.Info)["buyerclass"]); buyerclass != "" {
-			if buyerclass_mapping, ok := jy.PushMapping.Buyerclass[buyerclass]; ok {
-				values = append(values, buyerclass_mapping)
-			} else {
-				values = append(values, nil)
-			}
-		} else {
-			values = append(values, nil)
-		}
-		if isProjectInfo {
-			values = append(values, 1)
-		} else {
-			values = append(values, nil)
-		}
-		if toptype := util.ObjToString((*matchInfo.Info)["toptype"]); toptype != "" {
-			if toptype_mapping, ok := jy.PushMapping.Toptype[toptype]; ok {
-				values = append(values, toptype_mapping)
-			} else {
-				values = append(values, nil)
-			}
-		} else {
-			values = append(values, nil)
-		}
-		if subtype := util.ObjToString((*matchInfo.Info)["subtype"]); subtype != "" {
-			if subtype_mapping, ok := jy.PushMapping.Subtype[subtype]; ok {
-				values = append(values, subtype_mapping)
-			} else {
-				values = append(values, nil)
-			}
-		} else {
-			values = append(values, nil)
-		}
-		batchSize++
-		if i == 0 || batchSize == Config.BigBulkSize {
-			count, lastId := Mysql.InsertBatch("pushentniche", fields, values)
-			saveCount += count
-			var this_k int64
-			for k >= 0 {
-				subPush_datas[k].Ca_index = lastId + this_k
-				k--
-				this_k++
-				if this_k == count {
-					break
-				}
-			}
-			batchSize = 0
-			values = []interface{}{}
-		}
-	}
-	if int(saveCount) != length {
-		logger.Error(u.EntName, u.EntId, u.DeptName, u.DeptId, u.Id, u.MId, "批量保存有问题", length, saveCount)
-	}
-	//更新redis
-	subPush, err := jy.EntnichePush.GetTodayCache(u.EntId, u.Id)
-	if err == nil && subPush != nil && len(subPush.Datas) > 0 {
-		if nowymd := util.NowFormat(util.Date_Short_Layout); subPush.Date != nowymd {
-			subPush = &jy.SubPush{
-				Date:  nowymd,
-				Datas: subPush_datas,
-			}
-		} else {
-			subPush.Datas = append(subPush_datas, subPush.Datas...)
-		}
-		jy.EntnichePush.PutTodayCache(u.EntId, u.Id, subPush)
-	}
-	//全部列表缓存
-	allCache, err := jy.EntnichePush.GetAllCache(u.EntId, u.Id)
-	if err == nil && allCache != nil && len(allCache) > 0 {
-		new_allCache := append(subPush_datas, allCache...)
-		if len(new_allCache) > jy.AllSubPushCacheSize {
-			new_allCache = new_allCache[:jy.AllSubPushCacheSize]
-		}
-		jy.EntnichePush.PutAllCache(u.EntId, u.Id, new_allCache)
-	}
-	//
-	if saveCount == 0 {
-		return 0
-	}
-	return unix
-}
-
-func GetDeptUserIds(ui *UserInfo) map[int]bool {
-	if EntDepts[ui.DeptId].Subdis == 0 {
-		logger.Info(ui.EntName, ui.EntId, ui.DeptName, ui.DeptId, "没有开启订阅分发,过滤掉")
-		return nil
-	} else if EntDepts[ui.DeptId].Nodiff == 0 && ui.DisId == "" {
-		logger.Info(ui.EntName, ui.EntId, ui.DeptName, ui.DeptId, "没有开启全员无差别接收,并且没有分发规则,过滤掉")
-		return nil
-	}
-	//对我的对着生效的用户
-	myIds := map[int]bool{}
-	//打开了全员无差别,下面所有员工都生效
-	if EntDepts[ui.DeptId].Nodiff == 1 {
-		for _, v := range EntDeptUsers[ui.DeptId] {
-			myIds[v.UserId] = true
-		}
-		for _, v := range EntChildDept[ui.DeptId] {
-			for _, vv := range EntDeptUsers[v.Id] {
-				myIds[vv.UserId] = true
-			}
-		}
-		logger.Info(ui.EntName, ui.EntId, ui.DeptName, ui.DeptId, "该部门打开了全员无差别", len(myIds), "人接收")
-	} else if ui.DisId != "" {
-		for _, v := range EntRuleUsers[ui.DisId] {
-			myIds[v.UserId] = true
-		}
-		logger.Info(ui.EntName, ui.EntId, ui.DeptName, ui.DeptId, "该规则开启了订阅分发", ui.DisId, "规则分发了", len(myIds), "人")
-	}
-	//我的上级部门,过滤掉本部门的人
-	for _, v := range EntParentDept[ui.DeptId] {
-		//看我的上级部门,有没有开启订阅分发
-		if EntDepts[v.Pid].Subdis == 0 {
-			continue
-		}
-		//看我的上级部门,有没有全员无差别接收
-		if EntDepts[v.Pid].Nodiff == 1 {
-			logger.Info(ui.EntName, ui.EntId, ui.DeptName, ui.DeptId, ui.DisId, "上级部门", v.Pid, "打开了全员无差别开关,过滤掉")
-			return nil
-		}
-		//看我的上级部门,有没有对我设置规则
-		for _, vv := range EntDeptDis[v.Pid] {
-			for _, vvv := range EntRuleUsers[vv.Id] {
-				_, ok := myIds[vvv.UserId]
-				if !ok {
-					continue
-				}
-				delete(myIds, vvv.UserId)
-				logger.Info(ui.EntName, ui.EntId, ui.DeptName, ui.DeptId, "上级部门", v.Pid, "对我设置的有", vvv.RuleId, "分发规则,此规则作废", vvv.UserId)
-			}
-		}
-	}
-	logger.Info(ui.EntName, ui.EntId, ui.DeptName, ui.DeptId, ui.DisId, "该规则匹配到", len(myIds), "人")
-	return myIds
-}

+ 0 - 1
src/jfw/modules/pushentniche/src/push/xlsx/readme.txt

@@ -1 +0,0 @@
-excel数据导出临时目录

BIN
src/jfw/modules/pushentniche/src/push/xlsx/temp.xlsx


+ 2 - 7
src/jfw/modules/pushproject/src/config.json

@@ -1,12 +1,7 @@
 {
-	"durationMinutes": "30",
-	"elasticPoolSize": 30,
-	"elasticsearch": "http://192.168.3.128:9800",
+	"durationMinutes": 30,
 	"lastid": "",
-	"mongodbName": "qfw",
-	"mongodbPoolSize": "20",
-	"mongodbServers": "192.168.3.128:27080",
-	"redisServers": "push=192.168.3.128:5002",
+	"startTime":"",
 	"rpcPort": "8759",
 	"viewDomain": "http://web-jydev-wcj.jianyu360.cn",
 	"weixinRpcServer": "127.0.0.1:8083",

+ 19 - 2
src/jfw/modules/pushproject/src/config/config.go

@@ -4,8 +4,25 @@ import (
 	"qfw/util"
 )
 
-var Sysconfig map[string]interface{}
+type config struct {
+	DurationMinutes   int
+	Lastid            string
+	StartTime         string
+	RpcPort           string
+	ViewDomain        string
+	WeixinRpcServer   string
+	Wxcolor           string
+	Wxcontent         string
+	Wxgroup           string
+	Wxtitle           string
+	Wxdetailcolor     string
+	AppPushServiceRpc string
+	Testids           []string
+	PushPool          int
+}
+
+var Config *config
 
 func init() {
-	util.ReadConfig(&Sysconfig)
+	util.ReadConfig(&Config)
 }

+ 26 - 0
src/jfw/modules/pushproject/src/db.json

@@ -0,0 +1,26 @@
+{
+	"mongodb": {
+		"main": {
+			"address": "192.168.3.128:27080",
+	 		"size": 5,
+	 		"dbName": "qfw"
+		},
+		"bidding": {
+			"address": "192.168.3.207:27092",
+	 		"size": 5,
+	 		"dbName": "qfw_data",
+			"collection": "bidding"
+		}
+	},
+	"elasticsearch": {
+		"main": {
+			"address": "http://192.168.3.128:9800",
+	    	"size": 5
+		}
+    },
+    "redis": {
+    	"main": {
+			"address": "push=192.168.3.128:5002"
+		}
+    }
+}

+ 67 - 10
src/jfw/modules/pushproject/src/db/db.go

@@ -1,22 +1,79 @@
 package db
 
 import (
-	. "config"
-	"qfw/mongodb"
+	"log"
+	m "mongodb"
 	"qfw/util"
 	"qfw/util/elastic"
 	"qfw/util/redis"
 )
 
-var MQFW mongodb.MongodbSim
+var (
+	DbConf      *dbConf
+	MQFW        m.MongodbSim
+	Mgo_Bidding m.MongodbSim
+)
+
+type dbConf struct {
+	Mongodb struct {
+		Main    *mgoConf
+		Bidding *mgoConf
+	}
+	Elasticsearch struct {
+		Main *esConf
+	}
+	Redis struct {
+		Main  *redisConf
+		Login *redisConf
+	}
+}
+type mgoConf struct {
+	Address    string
+	Size       int
+	DbName     string
+	UserName   string
+	Password   string
+	Collection string
+}
+
+type esConf struct {
+	Address string
+	Size    int
+}
+type redisConf struct {
+	Address string
+}
 
 func init() {
-	redis.InitRedisBySize(Sysconfig["redisServers"].(string), 200, 30, 300)
-	elastic.InitElasticSize(Sysconfig["elasticsearch"].(string), util.IntAllDef(Sysconfig["elasticPoolSize"], 30))
-	MQFW = mongodb.MongodbSim{
-		MongodbAddr: Sysconfig["mongodbServers"].(string),
-		Size:        util.IntAll(Sysconfig["mongodbPoolSize"]),
-		DbName:      Sysconfig["mongodbName"].(string),
+	util.ReadConfig("./db.json", &DbConf)
+	if DbConf != nil {
+		if DbConf.Elasticsearch.Main != nil {
+			elastic.InitElasticSize(DbConf.Elasticsearch.Main.Address, DbConf.Elasticsearch.Main.Size)
+			log.Println("初始化 elasticsearch")
+		}
+		//初始化redis
+		if DbConf.Redis.Main != nil {
+			log.Println("初始化 redis")
+			redis.InitRedisBySize(DbConf.Redis.Main.Address, 200, 30, 300)
+		}
+		//
+		if DbConf.Mongodb.Main != nil {
+			log.Println("初始化 mongodb main")
+			MQFW = m.MongodbSim{
+				MongodbAddr: DbConf.Mongodb.Main.Address,
+				Size:        DbConf.Mongodb.Main.Size,
+				DbName:      DbConf.Mongodb.Main.DbName,
+			}
+			MQFW.InitPool()
+		}
+		if DbConf.Mongodb.Bidding != nil {
+			log.Println("初始化 mongodb bidding")
+			Mgo_Bidding = m.MongodbSim{
+				MongodbAddr: DbConf.Mongodb.Bidding.Address,
+				Size:        DbConf.Mongodb.Bidding.Size,
+				DbName:      DbConf.Mongodb.Bidding.DbName,
+			}
+			Mgo_Bidding.InitPool()
+		}
 	}
-	MQFW.InitPool()
 }

+ 5 - 6
src/jfw/modules/pushproject/src/main.go

@@ -1,7 +1,7 @@
 package main
 
 import (
-	"config"
+	. "config"
 	"log"
 	"net"
 	"net/http"
@@ -24,12 +24,11 @@ func main() {
 	crpc := new(rpcpush.FollowPushRpc)
 	rpc.Register(crpc)
 	rpc.HandleHTTP()
-	port, _ := config.Sysconfig["rpcPort"].(string)
-	l, err := net.Listen("tcp", ":"+port)
+	l, err := net.Listen("tcp", ":"+Config.RpcPort)
 	if err != nil {
 		log.Fatalln("rpc启动错误", err)
 	}
-	log.Println("rpc端口:", port)
+	log.Println("rpc端口:", Config.RpcPort)
 	go http.Serve(l, nil)
 	log.Println("项目推送程序启动。。。")
 	<-chan bool(nil)
@@ -38,7 +37,7 @@ func main() {
 func runJob() {
 	util.Try(func() {
 		push.Job()
-		util.WriteSysConfig(config.Sysconfig)
+		util.WriteSysConfig(Config)
 	}, func(e interface{}) {})
-	time.AfterFunc(time.Duration(util.IntAll(config.Sysconfig["durationMinutes"]))*time.Minute, runJob)
+	time.AfterFunc(time.Duration(Config.DurationMinutes)*time.Minute, runJob)
 }

+ 36 - 47
src/jfw/modules/pushproject/src/push/push.go

@@ -4,7 +4,7 @@ import (
 	. "config"
 	"db"
 	"fmt"
-	. "qfw/mongodb"
+	. "mongodb"
 	"qfw/util"
 	"qfw/util/elastic"
 	"qfw/util/redis"
@@ -18,7 +18,7 @@ import (
 	"time"
 
 	"github.com/donnie4w/go-logger/logger"
-	"gopkg.in/mgo.v2/bson"
+	"go.mongodb.org/mongo-driver/bson/primitive"
 )
 
 var (
@@ -28,20 +28,14 @@ var (
 	SortQuery       = `{"publishtime":"desc"}`
 	ShowField       = `"_id","title","publishtime","area","type","toptype","subtype","projectname","projectcode","href","infoformat","s_subscopeclass"`
 	KEEPCOUNT       = 100
-	PushPool        = make(chan bool, util.IntAllDef(Sysconfig["pushPool"], 30))
+	PushPool        = make(chan bool, Config.PushPool)
 	findpool        = make(chan bool, 10)
 	pushWaitGroup   = &sync.WaitGroup{}
 	searchWaitGroup = &sync.WaitGroup{}
 	reg1            = regexp.MustCompile(`\\+"`)
 	reg2            = regexp.MustCompile(`\\+`)
 	se              = util.SimpleEncrypt{Key: "topnet"}
-	WxTitle         = util.ObjToString(Sysconfig["wxtitle"])
-	WxContent       = util.ObjToString(Sysconfig["wxcontent"])
-	WxGroup         = util.ObjToString(Sysconfig["wxgroup"])
-	WxColor         = util.ObjToString(Sysconfig["wxcolor"])
-	WxDetailColor   = util.ObjToString(Sysconfig["wxdetailcolor"])
-	ViewDomain      = util.ObjToString(Sysconfig["viewDomain"])
-	LastLen         = 200 - len([]rune(WxContent)) - len([]rune(WxGroup))
+	LastLen         = 200 - len([]rune(Config.Wxcontent)) - len([]rune(Config.Wxgroup))
 )
 
 const (
@@ -73,20 +67,17 @@ type PushUser struct {
 //开始推送
 func Job() bool {
 	defer util.Catch()
-	_id := util.ObjToString(Sysconfig["lastid"])
-	StartTime, _ := Sysconfig["StartTime"].(string)
-	logger.Info("开始推送。。。", "lastid", _id, "StartTime", StartTime)
-	st, _ := time.ParseInLocation(util.Date_Full_Layout, StartTime, time.Local)
+	logger.Info("开始推送。。。", "lastid", Config.Lastid, "StartTime", Config.StartTime)
+	st, _ := time.ParseInLocation(util.Date_Full_Layout, Config.StartTime, time.Local)
 	lastTime := st.Unix()
 	idQuery := ""
-	if _id == "" {
-		idQuery = strings.Replace(fmt.Sprintf(MaxId, _id), `"gt"`, `"gte"`, -1)
+	if Config.Lastid == "" {
+		idQuery = strings.Replace(fmt.Sprintf(MaxId, Config.Lastid), `"gt"`, `"gte"`, -1)
 	} else {
-		idQuery = fmt.Sprintf(MaxId, _id)
+		idQuery = fmt.Sprintf(MaxId, Config.Lastid)
 	}
 	resId := elastic.Get("bidding", "bidding", idQuery)
 	lastid := ""
-	logger.Info("push-lastid", _id, resId)
 	var comeintime interface{}
 	if resId != nil && *resId != nil && len(*resId) == 1 {
 		lastid = util.ObjToString((*resId)[0]["_id"])
@@ -98,14 +89,12 @@ func Job() bool {
 	sess := db.MQFW.GetMgoConn()
 	defer db.MQFW.DestoryMongoConn(sess)
 	q := map[string]interface{}{}
-	testids_i, _ := Sysconfig["testids"].([]interface{})
-	testids := util.ObjArrToStringArr(testids_i)
-	if len(testids) > 0 {
+	if len(Config.Testids) > 0 {
 		q["s_userid"] = map[string]interface{}{
-			"$in": testids,
+			"$in": Config.Testids,
 		}
 	}
-	logger.Info("testids", testids)
+	logger.Info("testids", Config.Testids)
 	cur := sess.DB(db.MQFW.DbName).C(FOLLOW_COLLECTION).Find(q).Select(map[string]interface{}{
 		"s_projectcode": 1,
 		"s_projectname": 1,
@@ -140,7 +129,7 @@ func Job() bool {
 		logger.Info("未查找到需要推送的用户...")
 		return false
 	}
-	pnMap, pcMap := InitBiddingCache(_id, lastid, lastTime)
+	pnMap, pcMap := InitBiddingCache(lastid, lastTime)
 	if len(pnMap) == 0 && len(pcMap) == 0 {
 		logger.Info("加载数据到内存中的时候,未查找到数据...")
 		return false
@@ -160,9 +149,9 @@ func Job() bool {
 		}(k, v)
 	}
 	pushWaitGroup.Wait()
-	Sysconfig["StartTime"] = util.FormatDateWithObj(&comeintime, util.Date_Full_Layout)
-	Sysconfig["lastid"] = lastid
-	logger.Info("推送结束。。。", "lastid", lastid, "StartTime", Sysconfig["StartTime"])
+	Config.StartTime = util.FormatDateWithObj(&comeintime, util.Date_Full_Layout)
+	Config.Lastid = lastid
+	logger.Info("推送结束。。。", "lastid", Config.Lastid, "StartTime", Config.StartTime)
 	return true
 }
 
@@ -201,7 +190,7 @@ func EachAllBidInfo(users *[]*PushUser, pnMap, pcMap map[string][]map[string]int
 }
 
 //加载数据到内存中
-func InitBiddingCache(_id, lastid string, lastTime int64) (map[string][]map[string]interface{}, map[string][]map[string]interface{}) {
+func InitBiddingCache(lastid string, lastTime int64) (map[string][]map[string]interface{}, map[string][]map[string]interface{}) {
 	defer util.Catch()
 	c_query := map[string]interface{}{
 		"publishtime": map[string]interface{}{
@@ -210,11 +199,11 @@ func InitBiddingCache(_id, lastid string, lastTime int64) (map[string][]map[stri
 		"extracttype": 1,
 	}
 	idQuery := map[string]interface{}{}
-	if _id != "" {
-		idQuery["$gt"] = bson.ObjectIdHex(_id)
+	if Config.Lastid != "" {
+		idQuery["$gt"], _ = primitive.ObjectIDFromHex(Config.Lastid)
 	}
 	if lastid != "" {
-		idQuery["$lte"] = bson.ObjectIdHex(lastid)
+		idQuery["$lte"], _ = primitive.ObjectIDFromHex(lastid)
 	}
 	if len(idQuery) > 0 {
 		c_query["_id"] = idQuery
@@ -222,9 +211,9 @@ func InitBiddingCache(_id, lastid string, lastTime int64) (map[string][]map[stri
 	logger.Info("mongodb query:", c_query)
 	pnMap := map[string][]map[string]interface{}{}
 	pcMap := map[string][]map[string]interface{}{}
-	sess := db.MQFW.GetMgoConn()
-	defer db.MQFW.DestoryMongoConn(sess)
-	it := sess.DB("qfw").C("bidding").Find(c_query).Select(map[string]interface{}{
+	sess := db.Mgo_Bidding.GetMgoConn()
+	defer db.Mgo_Bidding.DestoryMongoConn(sess)
+	it := sess.DB(db.DbConf.Mongodb.Bidding.DbName).C(db.DbConf.Mongodb.Bidding.Collection).Find(c_query).Select(map[string]interface{}{
 		"_id":             1,
 		"title":           1,
 		"publishtime":     1,
@@ -383,20 +372,20 @@ func push(fid interface{}, sname, scode, title, userId string, res *[]map[string
 			//项目公告保留包括本身在内的最新100条
 			updateFlag := false
 			if fid != nil {
-				followObject, fok := db.MQFW.FindOneByField(FOLLOW_COLLECTION, &bson.M{"_id": fid}, `{"l_publishtime":1,"a_relationinfo":1,"s_id":1}`)
+				followObject, fok := db.MQFW.FindOneByField(FOLLOW_COLLECTION, &map[string]interface{}{"_id": fid}, `{"l_publishtime":1,"a_relationinfo":1,"s_id":1}`)
 				if fok && followObject != nil && len(*followObject) > 0 {
 					relationinfo, _ := (*followObject)["a_relationinfo"].([]interface{})
 					s_id, _ := (*followObject)["s_id"].(string)
 					rLength := len(relationinfo)
 					pLength := pushArray.Len()
-					setMap := bson.M{"a_lastpushids": ids}
+					setMap := map[string]interface{}{"a_lastpushids": ids}
 					if bpush {
 						setMap["l_lastpushtime"] = (*((*pushArray)[0]))["l_publishtime"]
 						setMap["i_apppushunread"] = 1
 					} else {
 						setMap["l_lastpushtime"] = (*followObject)["l_publishtime"]
 					}
-					updateMap := &bson.M{"$set": setMap}
+					updateMap := &map[string]interface{}{"$set": setMap}
 					if rLength > 0 && rLength+pLength > KEEPCOUNT { //保留100条
 						start := rLength + pLength - KEEPCOUNT
 						firstInfo, _ := relationinfo[0].(map[string]interface{})
@@ -418,9 +407,9 @@ func push(fid interface{}, sname, scode, title, userId string, res *[]map[string
 						}
 						setMap["a_relationinfo"] = relationinfoTemp
 					} else { //追加
-						(*updateMap)["$push"] = bson.M{"a_relationinfo": bson.M{"$each": pushArray}}
+						(*updateMap)["$push"] = map[string]interface{}{"a_relationinfo": map[string]interface{}{"$each": pushArray}}
 					}
-					updateFlag = db.MQFW.Update(FOLLOW_COLLECTION, &bson.M{"_id": fid}, updateMap, false, false)
+					updateFlag = db.MQFW.Update(FOLLOW_COLLECTION, &map[string]interface{}{"_id": fid}, updateMap, false, false)
 				}
 			}
 			if updateFlag && bpush {
@@ -444,7 +433,7 @@ func push(fid interface{}, sname, scode, title, userId string, res *[]map[string
 				}
 				if tit != "" {
 					followid := BsonIdToSId(fid)
-					saveId := db.MQFW.Save("jy_pushproject", bson.M{
+					saveId := db.MQFW.Save("jy_pushproject", map[string]interface{}{
 						"s_userid":       userId,
 						"l_date":         time.Now().Unix(),
 						"a_relationinfo": pushArray,
@@ -461,7 +450,7 @@ func push(fid interface{}, sname, scode, title, userId string, res *[]map[string
 					//微信推送
 					if applystatus == 1 && isPushWx == 1 && s_m_openid != "" {
 						lastTime := util.Int64All((*(*pushArray)[0])["l_publishtime"])
-						pushtt := fmt.Sprintf(WxTitle, tit)
+						pushtt := fmt.Sprintf(Config.Wxtitle, tit)
 						Tip1 := ""
 						minute := time.Now().Unix() - lastTime
 						if minute > -1 && minute < 61 {
@@ -512,13 +501,13 @@ func push(fid interface{}, sname, scode, title, userId string, res *[]map[string
 						}
 						isPushOk := rpccall.SendWinXin(&qrpc.NotifyMsg{
 							Openid:      s_m_openid,
-							Title:       fmt.Sprintf(WxTitle, tit),
+							Title:       fmt.Sprintf(Config.Wxtitle, tit),
 							Remark:      Tip1 + Remark + LastTip,
-							Detail:      WxGroup,
+							Detail:      Config.Wxgroup,
 							Service:     lastcreatetime,
-							Color:       WxColor,
-							DetailColor: WxDetailColor,
-							Url:         ViewDomain + "/front/sess/" + se.EncodeString(s_m_openid+",uid,"+strconv.Itoa(int(time.Now().Unix()))+",wxpushfollowlist") + "__" + saveId + "__" + followid,
+							Color:       Config.Wxcolor,
+							DetailColor: Config.Wxdetailcolor,
+							Url:         Config.ViewDomain + "/front/sess/" + se.EncodeString(s_m_openid+",uid,"+strconv.Itoa(int(time.Now().Unix()))+",wxpushfollowlist") + "__" + saveId + "__" + followid,
 						}, userId)
 						logger.Info("微信推送", isPushOk, userId, s_m_openid, pushnum, tit)
 					}
@@ -529,7 +518,7 @@ func push(fid interface{}, sname, scode, title, userId string, res *[]map[string
 							descriptAppend = fmt.Sprintf("\n...(共%d条)", pushnum)
 							jpushtitle = fmt.Sprintf("1. %s", jpushtitle)
 						}
-						isPushOk := qrpc.AppPush(Sysconfig["appPushServiceRpc"].(string), map[string]interface{}{
+						isPushOk := qrpc.AppPush(Config.AppPushServiceRpc, map[string]interface{}{
 							"phoneType":      phoneType,
 							"otherPushId":    opushid,
 							"jgPushId":       jpushid,

+ 2 - 2
src/jfw/modules/pushproject/src/rpccall/weixinrpc.go

@@ -1,7 +1,7 @@
 package rpccall
 
 import (
-	"config"
+	. "config"
 	"db"
 	qrpc "qfw/util/rpc"
 	"strings"
@@ -11,7 +11,7 @@ import (
 //微信远程调用,实现模板发送消息
 func SendWinXin(p *qrpc.NotifyMsg, userId string) bool {
 	time.Sleep(10 * time.Millisecond)
-	ok, res := qrpc.WxPush(config.Sysconfig["weixinRpcServer"].(string), "WeiXinRpc.SendPushMsg", p)
+	ok, res := qrpc.WxPush(Config.WeixinRpcServer, "WeiXinRpc.SendPushMsg", p)
 	if !ok && (strings.Contains(res, "[46004]") || strings.Contains(res, "[65302]") || strings.Contains(res, "[43004]") || strings.Contains(res, "[40003]")) {
 		db.MQFW.UpdateById("user", userId, map[string]interface{}{
 			"$set": map[string]interface{}{

+ 2 - 2
src/jfw/modules/pushproject/src/rpcpush/findData.go

@@ -5,7 +5,7 @@ import (
 	"qfw/util/redis"
 
 	"github.com/donnie4w/go-logger/logger"
-	"gopkg.in/mgo.v2/bson"
+	"go.mongodb.org/mongo-driver/bson/primitive"
 )
 
 func RpcFindFollow(projectname, projectcode, followid, thisid, userid, jpushid string, flag int) *push.Arr {
@@ -13,7 +13,7 @@ func RpcFindFollow(projectname, projectcode, followid, thisid, userid, jpushid s
 	var ff interface{}
 	if len(followid) > 5 {
 		bsave = true
-		ff = bson.ObjectIdHex(followid)
+		ff, _ = primitive.ObjectIDFromHex(followid)
 	}
 	if thisid != "" && bsave {
 		logger.Info(userid, thisid, "--add follow")

+ 0 - 5
src/jfw/modules/pushsubscribe/src/match/config.json

@@ -1,11 +1,6 @@
 {
-	"elasticPoolSize":1,
-	"elasticSearch":"http://192.168.3.128:9800",
-	"redisServers": "pushcache_1=192.168.3.128:5000,pushcache_2_b=192.168.3.128:5002",
 	"maxPushSize":150,
 	"vipMaxPushSize":2000,
-	"mgoAddr":"192.168.3.128:27080",
-	"mgoSize":10,
 	"testIds":["5ed463f327573456002068d3"],
 	"filterReg":"^(项目|中标|公告)$",
 	"retainReg":"[\\p{Han}a-zA-Z0-9]",

+ 0 - 5
src/jfw/modules/pushsubscribe/src/match/config/config.go

@@ -6,13 +6,8 @@ import (
 )
 
 type config struct {
-	ElasticPoolSize  int               `json:"elasticPoolSize"`
-	ElasticSearch    string            `json:"elasticSearch"`
-	RedisServers     string            `json:"redisServers"`
 	MaxPushSize      int               `json:"maxPushSize"`
 	VipMaxPushSize   int               `json:"vipMaxPushSize"`
-	MgoAddr          string            `json:"mgoAddr"`
-	MgoSize          int               `json:"mgoSize"`
 	TestIds          []string          `json:"testIds"`
 	FilterReg        string            `json:"filterReg"`
 	RetainReg        string            `json:"retainReg"`

+ 26 - 0
src/jfw/modules/pushsubscribe/src/match/db.json

@@ -0,0 +1,26 @@
+{
+	"mongodb": {
+		"main": {
+			"address": "192.168.3.128:27080",
+	 		"size": 5,
+	 		"dbName": "qfw"
+		},
+		"bidding": {
+			"address": "192.168.3.207:27092",
+	 		"size": 5,
+	 		"dbName": "qfw_data",
+			"collection": "bidding"
+		}
+	},
+	"elasticsearch": {
+		"main": {
+			"address": "http://192.168.3.128:9800",
+	    	"size": 5
+		}
+    },
+    "redis": {
+    	"main": {
+			"address": "pushcache_1=192.168.3.128:5000,pushcache_2_b=192.168.3.128:5002"
+		}
+    }
+}

+ 79 - 0
src/jfw/modules/pushsubscribe/src/match/db/db.go

@@ -0,0 +1,79 @@
+package db
+
+import (
+	"log"
+	m "mongodb"
+	"qfw/util"
+	"qfw/util/elastic"
+	"qfw/util/redis"
+)
+
+var (
+	DbConf      *dbConf
+	Mgo         m.MongodbSim
+	Mgo_Bidding m.MongodbSim
+)
+
+type dbConf struct {
+	Mongodb struct {
+		Main    *mgoConf
+		Bidding *mgoConf
+	}
+	Elasticsearch struct {
+		Main *esConf
+	}
+	Redis struct {
+		Main  *redisConf
+		Login *redisConf
+	}
+}
+type mgoConf struct {
+	Address    string
+	Size       int
+	DbName     string
+	UserName   string
+	Password   string
+	Collection string
+}
+
+type esConf struct {
+	Address string
+	Size    int
+}
+type redisConf struct {
+	Address string
+}
+
+func init() {
+	util.ReadConfig("./db.json", &DbConf)
+	if DbConf != nil {
+		if DbConf.Elasticsearch.Main != nil {
+			elastic.InitElasticSize(DbConf.Elasticsearch.Main.Address, DbConf.Elasticsearch.Main.Size)
+			log.Println("初始化 elasticsearch")
+		}
+		//初始化redis
+		if DbConf.Redis.Main != nil {
+			log.Println("初始化 redis")
+			redis.InitRedis(DbConf.Redis.Main.Address)
+		}
+		//
+		if DbConf.Mongodb.Main != nil {
+			log.Println("初始化 mongodb main")
+			Mgo = m.MongodbSim{
+				MongodbAddr: DbConf.Mongodb.Main.Address,
+				Size:        DbConf.Mongodb.Main.Size,
+				DbName:      DbConf.Mongodb.Main.DbName,
+			}
+			Mgo.InitPool()
+		}
+		if DbConf.Mongodb.Bidding != nil {
+			log.Println("初始化 mongodb bidding")
+			Mgo_Bidding = m.MongodbSim{
+				MongodbAddr: DbConf.Mongodb.Bidding.Address,
+				Size:        DbConf.Mongodb.Bidding.Size,
+				DbName:      DbConf.Mongodb.Bidding.DbName,
+			}
+			Mgo_Bidding.InitPool()
+		}
+	}
+}

+ 17 - 18
src/jfw/modules/pushsubscribe/src/match/job/matchjob.go

@@ -4,10 +4,10 @@ import (
 	"encoding/json"
 	"fmt"
 	. "match/config"
+	. "match/db"
 	. "match/matcher"
-	. "match/util"
+	. "mongodb"
 	. "public"
-	. "qfw/mongodb"
 	"qfw/util"
 	"qfw/util/elastic"
 	"qfw/util/redis"
@@ -17,11 +17,10 @@ import (
 	"time"
 
 	"github.com/donnie4w/go-logger/logger"
-	"gopkg.in/mgo.v2/bson"
+	"go.mongodb.org/mongo-driver/bson/primitive"
 )
 
 const (
-	DB           = "bidding"
 	MaxId        = `{"query":{"filtered":{"filter":{"bool":{"must":{"range":{"id":{"gt":"%s"}}}}}}},"_source":["_id","comeintime"],"sort":{"id":"desc"},"from":0,"size":1}`
 	ProjectQuery = `{"query":{"filtered":{"filter":{"term":{"list.infoid":"%s"}}}},"_source":["_id","list.infoid"],"sort":{"id":"desc"},"from":0,"size":1}`
 )
@@ -47,7 +46,7 @@ func (m *MatchJob) Execute() {
 	} else {
 		idQuery = fmt.Sprintf(MaxId, startId)
 	}
-	resId := elastic.Get(DB, DB, idQuery)
+	resId := elastic.Get(Es_Bidding, Es_Bidding, idQuery)
 	endId := ""
 	var endTime interface{}
 	if resId != nil && *resId != nil && len(*resId) == 1 {
@@ -96,10 +95,10 @@ func (m *MatchJob) LoadBidding(lastId, newId string, lastTime int64) *[]map[stri
 	c_query := map[string]interface{}{}
 	idQuery := map[string]interface{}{}
 	if lastId != "" {
-		idQuery["$gt"] = bson.ObjectIdHex(lastId)
+		idQuery["$gt"], _ = primitive.ObjectIDFromHex(lastId)
 	}
 	if newId != "" {
-		idQuery["$lte"] = bson.ObjectIdHex(newId)
+		idQuery["$lte"], _ = primitive.ObjectIDFromHex(newId)
 	}
 	if len(idQuery) > 0 {
 		c_query["_id"] = idQuery
@@ -110,11 +109,11 @@ func (m *MatchJob) LoadBidding(lastId, newId string, lastTime int64) *[]map[stri
 	// c_query = map[string]interface{}{
 	// 	"_id": bson.ObjectIdHex("5e8432a950b5ea296eea7ec5"),
 	// }
-	logger.Info("开始加载", Bidding, "数据", c_query)
+	logger.Info("开始加载", DbConf.Mongodb.Bidding.Collection, "数据", c_query)
 	var res []map[string]interface{}
-	sess := Mgo.GetMgoConn()
-	defer Mgo.DestoryMongoConn(sess)
-	it := sess.DB(DbName).C(Bidding).Find(c_query).Select(map[string]interface{}{
+	sess := Mgo_Bidding.GetMgoConn()
+	defer Mgo_Bidding.DestoryMongoConn(sess)
+	it := sess.DB(DbConf.Mongodb.Bidding.DbName).C(DbConf.Mongodb.Bidding.Collection).Find(c_query).Select(map[string]interface{}{
 		"title":           1,
 		"detail":          1,
 		"projectscope":    1,
@@ -159,10 +158,10 @@ func (m *MatchJob) LoadBidding(lastId, newId string, lastTime int64) *[]map[stri
 		temp = make(map[string]interface{})
 		index++
 		if index%500 == 0 {
-			logger.Info("加载", Bidding, "数据:", index)
+			logger.Info("加载", DbConf.Mongodb.Bidding.Collection, "数据:", index)
 		}
 	}
-	logger.Info(Bidding, "数据已经加载结束。。。", index)
+	logger.Info(DbConf.Mongodb.Bidding.Collection, "数据已经加载结束。。。", index)
 	return &res
 }
 
@@ -178,7 +177,7 @@ func (m *MatchJob) OnceUserBatch(batchIndex int, lastUserId *string) (int, *VipU
 		_idq["$in"] = ToObjectIds(Config.TestIds)
 	}
 	if *lastUserId != "" {
-		_idq["$gt"] = bson.ObjectIdHex(*lastUserId)
+		_idq["$gt"], _ = primitive.ObjectIDFromHex(*lastUserId)
 	}
 	if len(_idq) > 0 {
 		q["_id"] = _idq
@@ -186,7 +185,7 @@ func (m *MatchJob) OnceUserBatch(batchIndex int, lastUserId *string) (int, *VipU
 	logger.Info("开始加载第", batchIndex, "批用户", q)
 	session := Mgo.GetMgoConn()
 	defer Mgo.DestoryMongoConn(session)
-	query := session.DB(DbName).C(User).Find(&q).Select(UserCollFields).Sort("_id").Iter()
+	query := session.DB(DbConf.Mongodb.Main.DbName).C(User).Find(&q).Select(UserCollFields).Sort("_id").Iter()
 	n := 0
 	freeUser := NewFreeUser() //免费所有用户
 	vipUser := NewVipUser()   //vip所有用户
@@ -661,7 +660,7 @@ func (m *MatchJob) ToRelationProject(projectUser *map[*UserInfo]*[]string, myMat
 					projectId = project.Id
 					list_last_infoid = project.List_last_infoid
 				} else {
-					projects := elastic.Get(Projectset, Projectset, fmt.Sprintf(ProjectQuery, _id))
+					projects := elastic.Get(Es_Projectset, Es_Projectset, fmt.Sprintf(ProjectQuery, _id))
 					if projects == nil || len(*projects) == 0 {
 						continue
 					}
@@ -698,7 +697,7 @@ func (m *MatchJob) ToRelationProject(projectUser *map[*UserInfo]*[]string, myMat
 					},
 				})
 				if len(updateproject) == BigBulkSize {
-					Mgo.NewUpdateBulk(Pushspace_project, true, true, updateproject...)
+					Mgo.UpSertMultiBulk(Pushspace_project, true, true, updateproject...)
 					updateproject = [][]map[string]interface{}{}
 				}
 				lock.Unlock()
@@ -711,7 +710,7 @@ func (m *MatchJob) ToRelationProject(projectUser *map[*UserInfo]*[]string, myMat
 	}
 	saveWaitGroup.Wait()
 	if len(updateproject) > 0 {
-		Mgo.NewUpdateBulk(Pushspace_project, true, true, updateproject...)
+		Mgo.UpSertMultiBulk(Pushspace_project, true, true, updateproject...)
 		updateproject = [][]map[string]interface{}{}
 	}
 	logger.Info("关联项目结束。。。", index)

+ 10 - 10
src/jfw/modules/pushsubscribe/src/match/job/movejob.go

@@ -3,7 +3,8 @@ package job
 
 import (
 	. "match/config"
-	. "match/util"
+	. "match/db"
+	mgo "mongodb"
 	. "public"
 	"qfw/util"
 	"sort"
@@ -11,7 +12,6 @@ import (
 	"time"
 
 	"github.com/donnie4w/go-logger/logger"
-	mgo "gopkg.in/mgo.v2"
 )
 
 var (
@@ -47,7 +47,7 @@ func (m *MoveJob) Execute() {
 			"$in": Config.TestIds,
 		}
 	}
-	it := sess.DB(DbName).C(Pushspace_temp).Find(query).Sort("userid").Iter()
+	it := sess.DB(DbConf.Mongodb.Main.DbName).C(Pushspace_temp).Find(query).Sort("userid").Iter()
 	moveUsers := map[string]*MoveUser{}
 	index, number, length := 0, 0, 0
 	//
@@ -153,7 +153,7 @@ func (m *MoveJob) merge(number *int, nowUnix int64, moveUsers map[string]*MoveUs
 			sess := Mgo.GetMgoConn()
 			defer Mgo.DestoryMongoConn(sess)
 			var data map[string]interface{}
-			sess.DB(DbName).C(Pushspace).Find(map[string]interface{}{"userid": userId}).Select(map[string]interface{}{"list": 1}).One(&data)
+			sess.DB(DbConf.Mongodb.Main.DbName).C(Pushspace).Find(map[string]interface{}{"userid": userId}).Select(map[string]interface{}{"list": 1}).One(&data)
 			if data == nil { //批量新增
 				mergeLock.Lock()
 				saveArray = append(saveArray, moveUser.info)
@@ -234,12 +234,12 @@ func (m *MoveJob) merge(number *int, nowUnix int64, moveUsers map[string]*MoveUs
 	}
 	logger.Info("第", *number, "次合并数据结束。。。", index)
 }
-func (m *MoveJob) saveBulk(sess *mgo.Session, saves *[]map[string]interface{}, deletes *[]interface{}) {
+func (m *MoveJob) saveBulk(sess *mgo.MgoSess, saves *[]map[string]interface{}, deletes *[]interface{}) {
 	if sess == nil {
 		sess = Mgo.GetMgoConn()
 		defer Mgo.DestoryMongoConn(sess)
 	}
-	coll := sess.DB(DbName).C(Pushspace)
+	coll := sess.DB(DbConf.Mongodb.Main.DbName).C(Pushspace)
 	bulk := coll.Bulk()
 	for _, v := range *saves {
 		bulk.Insert(v)
@@ -252,12 +252,12 @@ func (m *MoveJob) saveBulk(sess *mgo.Session, saves *[]map[string]interface{}, d
 	}
 	*saves = []map[string]interface{}{}
 }
-func (m *MoveJob) updateBulk(sess *mgo.Session, array_q, array_s *[]map[string]interface{}, array_d *[]interface{}) {
+func (m *MoveJob) updateBulk(sess *mgo.MgoSess, array_q, array_s *[]map[string]interface{}, array_d *[]interface{}) {
 	if sess == nil {
 		sess = Mgo.GetMgoConn()
 		defer Mgo.DestoryMongoConn(sess)
 	}
-	coll := sess.DB(DbName).C(Pushspace)
+	coll := sess.DB(DbConf.Mongodb.Main.DbName).C(Pushspace)
 	bulk := coll.Bulk()
 	for k, v := range *array_q {
 		bulk.Update(v, (*array_s)[k])
@@ -271,12 +271,12 @@ func (m *MoveJob) updateBulk(sess *mgo.Session, array_q, array_s *[]map[string]i
 	*array_q = []map[string]interface{}{}
 	*array_s = []map[string]interface{}{}
 }
-func (m *MoveJob) delBulk(sess *mgo.Session, array *[]interface{}) {
+func (m *MoveJob) delBulk(sess *mgo.MgoSess, array *[]interface{}) {
 	if sess == nil {
 		sess = Mgo.GetMgoConn()
 		defer Mgo.DestoryMongoConn(sess)
 	}
-	coll := sess.DB(DbName).C(Pushspace_temp)
+	coll := sess.DB(DbConf.Mongodb.Main.DbName).C(Pushspace_temp)
 	count := 0
 	bulk := coll.Bulk()
 	for _, v := range *array {

BIN
src/jfw/modules/pushentniche/src/match/match → src/jfw/modules/pushsubscribe/src/match/match


+ 0 - 30
src/jfw/modules/pushsubscribe/src/match/util/db.go

@@ -1,30 +0,0 @@
-package util
-
-import (
-	"log"
-	. "match/config"
-	"qfw/mongodb"
-	"qfw/util/elastic"
-	"qfw/util/mysql"
-	"qfw/util/redis"
-)
-
-var (
-	Mysql  *mysql.Mysql
-	DbName = "qfw"
-	Mgo    mongodb.MongodbSim
-)
-
-func init() {
-	Mgo = mongodb.MongodbSim{
-		MongodbAddr: Config.MgoAddr,
-		Size:        Config.MgoSize,
-		DbName:      DbName,
-	}
-	Mgo.InitPool()
-	log.Println("mongodb初始化完成!")
-	redis.InitRedis(Config.RedisServers)
-	log.Println("redis初始化完成!")
-	elastic.InitElasticSize(Config.ElasticSearch, Config.ElasticPoolSize)
-	log.Println("elastic初始化完成!")
-}

+ 8 - 7
src/jfw/modules/pushsubscribe/src/public/util.go

@@ -3,7 +3,7 @@ package public
 import (
 	"encoding/json"
 	"fmt"
-	. "qfw/mongodb"
+	. "mongodb"
 	"qfw/util"
 	"regexp"
 	"sort"
@@ -11,7 +11,7 @@ import (
 	"time"
 
 	"github.com/donnie4w/go-logger/logger"
-	"gopkg.in/mgo.v2/bson"
+	"go.mongodb.org/mongo-driver/bson/primitive"
 )
 
 const (
@@ -20,8 +20,8 @@ const (
 	OneDaySecond        = 86400
 	SevenDay            = 604800
 	User                = "user"
-	Bidding             = "bidding"
-	Projectset          = "projectset"
+	Es_Bidding          = "bidding"
+	Es_Projectset       = "projectset"
 	Pushspace_project   = "pushspace_project"
 	Pushspace_statistic = "pushspace_statistic"
 	Pushspace_temp      = "pushspace_temp"
@@ -258,10 +258,11 @@ func NewUserInfoByUserColl(address string, sleep int, temp map[string]interface{
 func PushInfoKey(userId, infoId string) string {
 	return fmt.Sprintf("pushinfo_%s_%s", userId, infoId)
 }
-func ToObjectIds(ids []string) []bson.ObjectId {
-	_ids := []bson.ObjectId{}
+func ToObjectIds(ids []string) []primitive.ObjectID {
+	_ids := []primitive.ObjectID{}
 	for _, v := range ids {
-		_ids = append(_ids, bson.ObjectIdHex(v))
+		_id, _ := primitive.ObjectIDFromHex(v)
+		_ids = append(_ids, _id)
 	}
 	return _ids
 }

File diff suppressed because it is too large
+ 0 - 18
src/jfw/modules/pushsubscribe/src/push/config.json


+ 21 - 41
src/jfw/modules/pushsubscribe/src/push/config/config.go

@@ -8,32 +8,26 @@ import (
 )
 
 type config struct {
-	JianyuDomain  string `json:"jianyuDomain"`
-	RedisServers  string `json:"redisServers"`
-	ElasticSearch struct {
-		Size    int    `json:"size"`
-		Address string `json:"address"`
-	} `json:"elasticSearch"`
-	PushPoolSize        int            `json:"pushPoolSize"`
-	ProjectPushPoolSize int            `json:"projectPushPoolSize"`
-	LoadProjectPoolSize int            `json:"loadProjectPoolSize"`
-	ProjectPagingSize   int            `json:"projectPagingSize"`
-	Mail_content        string         `json:"mail_content"`
-	Mail_html           string         `json:"mail_html"`
-	Mail_title          string         `json:"mail_title"`
-	Mail_according      string         `json:"mail_according"`
-	Vip_mail_according  string         `json:"vip_mail_according"`
-	Mails               []*pushMail    `json:"mails"`
-	MaxPushSize         int            `json:"maxPushSize"`
-	VipMaxPushSize      int            `json:"vipMaxPushSize"`
-	MaxRelationProject  int            `json:"maxRelationProject"`
-	Mongodb             *MongodbConfig `json:"mongodb"`
-	TestIds             []string       `json:"testIds"`
-	WeixinRpcServer     string         `json:"weixinRpcServer"`
-	AppPushServiceRpc   string         `json:"appPushServiceRpc"`
-	PcHelper            string         `json:"pcHelper"`
-	PushBatch           int            `json:"pushBatch"`
-	OncePushTime        string         `json:"oncePushTime"`
+	JianyuDomain        string      `json:"jianyuDomain"`
+	PushPoolSize        int         `json:"pushPoolSize"`
+	ProjectPushPoolSize int         `json:"projectPushPoolSize"`
+	LoadProjectPoolSize int         `json:"loadProjectPoolSize"`
+	ProjectPagingSize   int         `json:"projectPagingSize"`
+	Mail_content        string      `json:"mail_content"`
+	Mail_html           string      `json:"mail_html"`
+	Mail_title          string      `json:"mail_title"`
+	Mail_according      string      `json:"mail_according"`
+	Vip_mail_according  string      `json:"vip_mail_according"`
+	Mails               []*pushMail `json:"mails"`
+	MaxPushSize         int         `json:"maxPushSize"`
+	VipMaxPushSize      int         `json:"vipMaxPushSize"`
+	MaxRelationProject  int         `json:"maxRelationProject"`
+	TestIds             []string    `json:"testIds"`
+	WeixinRpcServer     string      `json:"weixinRpcServer"`
+	AppPushServiceRpc   string      `json:"appPushServiceRpc"`
+	PcHelper            string      `json:"pcHelper"`
+	PushBatch           int         `json:"pushBatch"`
+	OncePushTime        string      `json:"oncePushTime"`
 	// OtherPushTimes          []string       `json:"otherPushTimes"`
 	FreePushTime            string `json:"freePushTime"`
 	WxPushDuration          int    `json:"wxPushDuration"`  //wx间隔
@@ -59,15 +53,7 @@ type config struct {
 	RpcPort                 string `json:"rpcPort"`
 	ProjectPublishTimeLimit int64  `json:"projectPublishTimeLimit"`
 	TimeoutWarn             string `json:"timeoutWarn"`
-	Mysql                   struct {
-		DbName       string
-		Address      string
-		UserName     string
-		PassWord     string
-		MaxOpenConns int
-		MaxIdleConns int
-	} `json:"mysql"`
-	WxTplMsg struct {
+	WxTplMsg                struct {
 		Id           string
 		First        *qrpc.TmplItem
 		Vip_first    *qrpc.TmplItem
@@ -83,12 +69,6 @@ type config struct {
 	AppNothingDescriptAppend string `json:"appNothingDescriptAppend"`
 }
 
-type MongodbConfig struct {
-	DbName   string `json:"dbName"`
-	CollName string `json:"collName"`
-	Address  string `json:"address"`
-	Size     int    `json:"size"`
-}
 type pushMail struct {
 	Addr         string `json:"addr"`
 	Port         int    `json:"port"`

+ 30 - 0
src/jfw/modules/pushsubscribe/src/push/db.json

@@ -0,0 +1,30 @@
+{
+	"mongodb": {
+		"main": {
+			"address": "192.168.3.128:27080",
+	 		"size": 5,
+	 		"dbName": "qfw"
+		}
+	},
+	"elasticsearch": {
+		"main": {
+			"address": "http://192.168.3.128:9800",
+	    	"size": 5
+		}
+    },
+    "redis": {
+    	"main": {
+			"address": "pushcache_2_a=192.168.3.128:5001,pushcache_2_b=192.168.3.128:5002"
+		}
+    },
+    "mysql": {
+	    "push": {
+	        "dbName": "jianyu",
+	        "address": "192.168.3.11:3366",
+	        "userName": "root",
+	        "passWord": "Topnet123",
+			"maxOpenConns": 5,
+			"maxIdleConns": 5
+	    }
+    }
+}

+ 95 - 0
src/jfw/modules/pushsubscribe/src/push/db/db.go

@@ -0,0 +1,95 @@
+package public
+
+import (
+	"log"
+	m "mongodb"
+	"qfw/util"
+	"qfw/util/elastic"
+	"qfw/util/jy"
+	"qfw/util/mysql"
+	"qfw/util/redis"
+)
+
+type dbConf struct {
+	Mongodb struct {
+		Main *mgoConf
+	}
+	Elasticsearch struct {
+		Main *esConf
+	}
+	Redis struct {
+		Main *redisConf
+	}
+	Mysql struct {
+		Push *mysqlConf
+	}
+}
+type mgoConf struct {
+	Address    string
+	Size       int
+	DbName     string
+	UserName   string
+	Password   string
+	Collection string
+}
+
+type esConf struct {
+	Address string
+	Size    int
+}
+type redisConf struct {
+	Address string
+}
+type mysqlConf struct {
+	DbName       string
+	Address      string
+	UserName     string
+	PassWord     string
+	MaxOpenConns int
+	MaxIdleConns int
+}
+
+var (
+	DbConf *dbConf
+	Mysql  *mysql.Mysql
+	Mgo    m.MongodbSim
+)
+
+func init() {
+	util.ReadConfig("./db.json", &DbConf)
+	if DbConf != nil {
+		if DbConf.Elasticsearch.Main != nil {
+			elastic.InitElasticSize(DbConf.Elasticsearch.Main.Address, DbConf.Elasticsearch.Main.Size)
+			log.Println("初始化 elasticsearch")
+		}
+		//初始化redis
+		if DbConf.Redis.Main != nil {
+			log.Println("初始化 redis")
+			redis.InitRedisBySize(DbConf.Redis.Main.Address, 100, 30, 300)
+		}
+		//
+		if DbConf.Mongodb.Main != nil {
+			log.Println("初始化 mongodb main")
+			Mgo = m.MongodbSim{
+				MongodbAddr: DbConf.Mongodb.Main.Address,
+				Size:        DbConf.Mongodb.Main.Size,
+				DbName:      DbConf.Mongodb.Main.DbName,
+			}
+			Mgo.InitPool()
+		}
+		//
+		if DbConf.Mysql.Push != nil {
+			log.Println("初始化 pushMysql")
+			Mysql = &mysql.Mysql{
+				Address:      DbConf.Mysql.Push.Address,
+				UserName:     DbConf.Mysql.Push.UserName,
+				PassWord:     DbConf.Mysql.Push.PassWord,
+				DBName:       DbConf.Mysql.Push.DbName,
+				MaxOpenConns: DbConf.Mysql.Push.MaxOpenConns,
+				MaxIdleConns: DbConf.Mysql.Push.MaxIdleConns,
+			}
+			Mysql.Init()
+			jy.PushMapping.Init(Mysql)
+		}
+	}
+}

+ 16 - 19
src/jfw/modules/pushsubscribe/src/push/job/nothingjob.go

@@ -3,10 +3,11 @@ package job
 
 import (
 	"fmt"
+	. "mongodb"
 	"public"
 	. "push/config"
+	. "push/db"
 	putil "push/util"
-	. "qfw/mongodb"
 	"qfw/util"
 	"qfw/util/mail"
 	qrpc "qfw/util/rpc"
@@ -16,7 +17,7 @@ import (
 	"time"
 
 	"github.com/donnie4w/go-logger/logger"
-	"gopkg.in/mgo.v2/bson"
+	"go.mongodb.org/mongo-driver/bson/primitive"
 )
 
 type NothingJob struct{}
@@ -34,17 +35,17 @@ func (n *NothingJob) PushNothing(ratetype int) {
 		},
 	}
 	if len(Config.TestIds) > 0 {
-		_ids := []bson.ObjectId{}
+		_ids := []primitive.ObjectID{}
 		for _, v := range Config.TestIds {
-			_ids = append(_ids, bson.ObjectIdHex(v))
+			_ids = append(_ids, StringTOBsonId(v))
 		}
 		query["_id"] = map[string]interface{}{
 			"$in": _ids,
 		}
 	}
-	sess := putil.Mgo.GetMgoConn()
-	defer putil.Mgo.DestoryMongoConn(sess)
-	it := sess.DB(Config.Mongodb.DbName).C("user").Find(query).Select(map[string]interface{}{
+	sess := Mgo.GetMgoConn()
+	defer Mgo.DestoryMongoConn(sess)
+	it := sess.DB(DbConf.Mongodb.Main.DbName).C("user").Find(query).Select(map[string]interface{}{
 		"_id":           1,
 		"s_nickname":    1,
 		"o_vipjy":       1,
@@ -67,12 +68,11 @@ func (n *NothingJob) PushNothing(ratetype int) {
 				<-pushPool
 				pushWait.Done()
 			}()
-<<<<<<< HEAD
 			if v["o_vipjy"] == nil {
 				return
-=======
+			}
 			vipjy := v["o_vipjy"].(map[string]interface{})
-			userid := util.BsonIdToSId(v["_id"])
+			userid := BsonIdToSId(v["_id"])
 			i_ratemode := util.IntAll(v["o_vipjy"].(map[string]interface{})["i_ratemode"])
 			//APP推送
 			if util.IntAll(vipjy["i_apppush"]) == 1 && (v["s_opushid"] != nil || v["s_jpushid"] != nil) {
@@ -97,22 +97,19 @@ func (n *NothingJob) PushNothing(ratetype int) {
 				logger.Info("推送任务 未匹配到数据 开始微信推送", userid)
 				isPushOk := n.SendWeixin(util.ObjToString(v["s_m_openid"]), i_ratemode)
 				logger.Info("推送任务 未匹配到数据 微信推送结束", isPushOk, userid)
->>>>>>> release
 			}
-			ratemode := util.IntAll(v["o_vipjy"].(map[string]interface{})["i_ratemode"])
-			userid := BsonIdToSId(v["_id"])
-			day1, day2 := n.ComputTime(ratemode, t)
+			day1, day2 := n.ComputTime(i_ratemode, t)
 			if n.isNoInfo(userid, day1, day2) {
-				if ratetype == 1 && ratemode != 1 { //实时推送的过滤掉其他推送
+				if ratetype == 1 && i_ratemode != 1 { //实时推送的过滤掉其他推送
 					return
 				}
-				if ratetype == 0 && ratemode == 1 { //其他推送 过滤掉实时推送
+				if ratetype == 0 && i_ratemode == 1 { //其他推送 过滤掉实时推送
 					return
 				}
-				if ratemode == 3 && !(strings.ToLower(time.Now().Weekday().String()) == strings.ToLower(Config.VipPushWeek)) {
+				if i_ratemode == 3 && !(strings.ToLower(time.Now().Weekday().String()) == strings.ToLower(Config.VipPushWeek)) {
 					return
 				}
-				if ratemode == 4 && !(time.Now().Day() == Config.VipPushDay) {
+				if i_ratemode == 4 && !(time.Now().Day() == Config.VipPushDay) {
 					return
 				}
 				n.StartPush(v)
@@ -228,7 +225,7 @@ func (n *NothingJob) sendMail(email, subject, html string, fmdatas []map[string]
 
 //判断是否有消息
 func (n *NothingJob) isNoInfo(userid string, day1, day2 int64) bool {
-	return putil.Mysql.CountBySql(`select count(1) as count from pushsubscribe where userid=? and (date between ? and ? )`, userid, day2, day1) == 0
+	return Mysql.CountBySql(`select count(1) as count from pushsubscribe where userid=? and (date between ? and ? )`, userid, day2, day1) == 0
 }
 
 //时间计算

Some files were not shown because too many files changed in this diff