wangchuanjin 3 miesięcy temu
rodzic
commit
4d8a719ba6
4 zmienionych plików z 145 dodań i 6 usunięć
  1. 1 0
      matcher/freematch.go
  2. 140 0
      matcher/matcher_test.go
  3. 1 0
      matcher/paymatch.go
  4. 3 6
      p/struct.go

+ 1 - 0
matcher/freematch.go

@@ -97,6 +97,7 @@ func (f *FreeUser) GetFinalUser(keys, notkeys []string, keyUser *map[string]*[]*
 			if matchUser == nil {
 				matchUser = &MatchUser{
 					Keys: []string{},
+					Key:  map[string]bool{},
 				}
 			}
 			if !matchUser.Key[k] {

+ 140 - 0
matcher/matcher_test.go

@@ -0,0 +1,140 @@
+package matcher
+
+import (
+	"fmt"
+	"testing"
+
+	util "app.yhyue.com/moapp/jybase/common"
+	"app.yhyue.com/moapp/jybase/logger"
+	. "app.yhyue.com/moapp/jybase/mongodb"
+	. "bp.jydev.jianyu360.cn/BaseService/pushpkg/p"
+)
+
+func TestMatch(t *testing.T) {
+	m := &matchJob{}
+	m.mgo = &MongodbSim{
+		MongodbAddr: "192.168.3.206:27080",
+		Size:        2,
+		DbName:      "qfw",
+	}
+	m.mgo.InitPool()
+	bidMgo := &MongodbSim{
+		MongodbAddr: "192.168.3.206:27002",
+		Size:        2,
+		DbName:      "qfw",
+		UserName:    "jyDevGroup",
+		Password:    "jy@DevGroup",
+	}
+	bidMgo.InitPool()
+	query := map[string]interface{}{
+		"_id": map[string]interface{}{
+			"$in": ToObjectIds([]string{"665cc37666cf0db42a7f7981"}),
+		},
+	}
+	datas, _ := LoadBidding(bidMgo, "qfw_data", "bidding", 0, false, query, nil)
+	m.Start(datas)
+}
+
+type matchJob struct {
+	mgo *MongodbSim
+}
+
+func (m *matchJob) Start(datas *[]map[string]interface{}) {
+	defer util.Catch()
+	allSubSet := NewPayUser()
+	//标题匹配
+	title_key := make(map[string]*[]*UserInfo)
+	title_notkey := make(map[string]*[]*UserInfo)
+	title_pjob := &KeyDfa{
+		Key_user:    &title_key,
+		Notkey_user: &title_notkey,
+	}
+	//正文匹配
+	detail_key := make(map[string]*[]*UserInfo)
+	detail_notkey := make(map[string]*[]*UserInfo)
+	detail_pjob := &KeyDfa{
+		Key_user:    &detail_key,
+		Notkey_user: &detail_notkey,
+	}
+	//附件匹配
+	filetext_key := make(map[string]*[]*UserInfo)
+	filetext_notkey := make(map[string]*[]*UserInfo)
+	filetext_pjob := &KeyDfa{
+		Key_user:    &filetext_key,
+		Notkey_user: &filetext_notkey,
+	}
+	//项目名称/标的物匹配
+	pnp_key := make(map[string]*[]*UserInfo)
+	pnp_notkey := make(map[string]*[]*UserInfo)
+	pnp_pjob := &KeyDfa{
+		Key_user:    &pnp_key,
+		Notkey_user: &pnp_notkey,
+	}
+	m.LoadMySubSet(allSubSet, title_pjob, detail_pjob, filetext_pjob, pnp_pjob)
+	//
+	title_pjob.CreateDaf()
+	detail_pjob.CreateDaf()
+	filetext_pjob.CreateDaf()
+	pnp_pjob.CreateDaf()
+	allSubSet.Title_KeyDfa = title_pjob
+	allSubSet.Detail_KeyDfa = detail_pjob
+	allSubSet.Filetext_KeyDfa = filetext_pjob
+	allSubSet.PnP_KeyDfa = pnp_pjob
+	//
+	allSubSet.Match(1, datas)
+}
+
+//我的订阅设置
+func (m *matchJob) LoadMySubSet(allSubSet *PayUser, title_pjob, detail_pjob, filetext_pjob, pnp_pjob *KeyDfa) {
+	defer util.Catch()
+	sess := m.mgo.GetMgoConn()
+	defer m.mgo.DestoryMongoConn(sess)
+	query := map[string]interface{}{
+		"_id": StringTOBsonId("665a8ba6842ed1e25c138ac7"),
+	}
+	logger.Info("我的订阅设置", query)
+	it := sess.DB("qfw").C("entniche_rule").Find(query).Select(map[string]interface{}{
+		"i_entid":    1,
+		"i_deptid":   1,
+		"i_userid":   1,
+		"o_entniche": 1,
+		"i_type":     1,
+	}).Iter()
+	for temp := make(map[string]interface{}); it.Next(&temp); {
+		entId := util.IntAll(temp["i_entid"])
+		userId := util.IntAll(temp["i_userid"])
+		user := &UserInfo{
+			Entniche: &Entniche{
+				UserId: userId,
+				IsNew:  1,
+			},
+		}
+		subSetType := util.IntAllDef(temp["i_type"], -1)
+		subSet, _ := temp["o_entniche"].(map[string]interface{})
+		user.GetSubSet(subSetType == 2, fmt.Sprint(userId), subSet)
+		if user.SubSet.Switch == 0 {
+			logger.Info("订阅开关没有开启,过滤掉", entId, userId)
+			continue
+		}
+		if subSetType == 2 && len(user.SubSet.Keys) == 0 {
+			logger.Info("过滤掉,没有关键词", entId, userId)
+			continue
+		} else if subSetType != 2 && len(user.SubSet.Keys) == 0 && user.SubSet.Subtype == nil && user.SubSet.Area == nil && user.SubSet.Buyerclass == nil {
+			logger.Info("没有订阅,过滤掉", entId, userId)
+			continue
+		}
+		if subSetType == 2 {
+			user.PushSet.SubSet.RateMode = 0
+		}
+		m.InitSubSet(allSubSet, user, title_pjob, detail_pjob, filetext_pjob, pnp_pjob)
+		allSubSet.Users[user] = true
+		temp = make(map[string]interface{})
+	}
+}
+
+func (m *matchJob) InitSubSet(allSubSet *PayUser, user *UserInfo, title_pjob, detail_pjob, filetext_pjob, pnp_pjob *KeyDfa) {
+	user.AddBuyerclass(&allSubSet.BuyerclassUsers)
+	user.AddAreaCityDistrict(&allSubSet.AreaUsers, &allSubSet.CityUsers, &allSubSet.DistrictUsers)
+	user.AddSubtype(&allSubSet.SubtypeUsers)
+	user.MakeKeyUserByMatchMode(title_pjob, detail_pjob, filetext_pjob, pnp_pjob)
+}

+ 1 - 0
matcher/paymatch.go

@@ -168,6 +168,7 @@ func (p *PayUser) GetKeyUser(matchWay string, keys []string, keyUser *map[string
 			if matchUser == nil {
 				matchUser = &MatchUser{
 					Keys:      []string{},
+					Key:       map[string]bool{},
 					Items:     []string{},
 					Item:      map[string]bool{},
 					MatchWays: []string{},

+ 3 - 6
p/struct.go

@@ -266,7 +266,6 @@ func NewUserInfo(temp map[string]interface{}, tp int) *UserInfo {
 	return ui
 }
 
-//
 func NewMyUserInfo(Mgo *MongodbSim, msl *Mysql, userId string) *UserInfo {
 	var user *map[string]interface{}
 	if IsObjectIdHex(userId) {
@@ -283,7 +282,6 @@ func NewMyUserInfo(Mgo *MongodbSim, msl *Mysql, userId string) *UserInfo {
 	return ui
 }
 
-//
 func NewMyUserInfoByEntUserId(Mgo *MongodbSim, Mysql *Mysql, userId string) (*UserInfo, map[string]interface{}) {
 	var user *map[string]interface{}
 	if IsObjectIdHex(userId) {
@@ -738,7 +736,6 @@ func (u *UserInfo) AddTopBusinessType(m *map[string]map[*UserInfo]bool) {
 	}
 }
 
-//
 func (u *UserInfo) AddSubBusinessType(m *map[string]map[*UserInfo]bool) {
 	if len(u.SubSet.SubBusinessTypes) == 0 {
 		u.Add("", m)
@@ -786,7 +783,7 @@ func (u *UserInfo) AddArea(m *map[string]map[*UserInfo]bool) {
 	}
 }
 
-//添加省市映射关系
+// 添加省市映射关系
 func (u *UserInfo) AddAreaCity(area, city *map[string]map[*UserInfo]bool) {
 	if len(u.SubSet.Area) == 0 {
 		u.Add("", area)
@@ -811,7 +808,7 @@ func (u *UserInfo) AddAreaCity(area, city *map[string]map[*UserInfo]bool) {
 	}
 }
 
-//添加省市县映射关系
+// 添加省市县映射关系
 func (u *UserInfo) AddAreaCityDistrict(area, city *map[string]map[*UserInfo]bool, district *map[string]map[string]map[*UserInfo]bool) {
 	if len(u.SubSet.Area) == 0 {
 		u.Add("", area)
@@ -852,7 +849,6 @@ func (u *UserInfo) AddAreaCityDistrict(area, city *map[string]map[*UserInfo]bool
 	}
 }
 
-//
 func (u *UserInfo) MakeKeyUserByMatchMode(title_pjob, detail_pjob, filetext_pjob, pnp_pjob *KeyDfa) {
 	for _, v := range u.SubSet.MatchMode {
 		if v == "title" {
@@ -960,6 +956,7 @@ func (p *KeyDfa) CreateDaf() {
 
 type MatchUser struct {
 	Keys      []string
+	Key       map[string]bool
 	Items     []string
 	Item      map[string]bool
 	MatchWays []string