Ver código fonte

feat:增加匹配方式

wangchuanjin 1 ano atrás
pai
commit
fd0837dfbc
4 arquivos alterados com 101 adições e 29 exclusões
  1. 78 24
      matcher/paymatch.go
  2. 3 2
      p/constant.go
  3. 2 1
      p/public.go
  4. 18 2
      p/struct.go

+ 78 - 24
matcher/paymatch.go

@@ -3,6 +3,7 @@ package matcher
 import (
 	"strings"
 
+	util "app.yhyue.com/moapp/jybase/common"
 	. "bp.jydev.jianyu360.cn/BaseService/pushpkg/p"
 )
 
@@ -11,6 +12,8 @@ type PayUser struct {
 	Users           map[*UserInfo]bool
 	Title_KeyDfa    *KeyDfa
 	Detail_KeyDfa   *KeyDfa
+	Filetext_KeyDfa *KeyDfa
+	PnP_KeyDfa      *KeyDfa
 	BuyerclassUsers map[string]map[*UserInfo]bool
 	AreaUsers       map[string]map[*UserInfo]bool
 	CityUsers       map[string]map[*UserInfo]bool
@@ -45,30 +48,78 @@ func (p *PayUser) ToMatch(info map[string]interface{}) (*map[*UserInfo]*MatchUse
 	city, _ := info["city"].(string)
 	district, _ := info["district"].(string)
 	subtype, _ := info["subtype"].(string)
-	title := GetInfoTitle(info)
-	//订阅词
-	keys := p.Title_KeyDfa.Key.Analy(title)
-	//排除词
-	notkeys := p.Title_KeyDfa.NotKey.Analy(title)
+	var amount float64
+	if info["bidamount"] != nil {
+		amount = util.Float64All(info["bidamount"])
+	} else if info["budget"] != nil {
+		amount = util.Float64All(info["budget"])
+	}
 	notUsers := map[*UserInfo]bool{}
-	title_users := p.GetFinalUser(MatchWay_Title, keys, notkeys, p.Title_KeyDfa.Key_user, &notUsers)
-	//开启智能匹配的用户,匹配projectscope
-	detail_users := &map[*UserInfo]*MatchUser{}
+	yesUsers := &map[*UserInfo]*MatchUser{}
+	//匹配标题
+	if p.Title_KeyDfa != nil {
+		if title := GetInfoTitle(info); title != "" {
+			//订阅词
+			keys := p.Title_KeyDfa.Key.Analy(title)
+			//排除词
+			notkeys := p.Title_KeyDfa.NotKey.Analy(title)
+			yesUsers = p.GetFinalUser(MatchWay_Title, keys, notkeys, p.Title_KeyDfa.Key_user, &notUsers)
+		}
+	}
+	//匹配项目名称/标的物
+	if p.PnP_KeyDfa != nil {
+		if projectname, _ := info["projectname"].(string); projectname != "" {
+			projectname = strings.ToUpper(projectname)
+			keys := p.PnP_KeyDfa.Key.Analy(projectname)
+			notkeys := p.PnP_KeyDfa.NotKey.Analy(projectname)
+			projectname_users := p.GetFinalUser(MatchWay_Projectname, keys, notkeys, p.PnP_KeyDfa.Key_user, &notUsers)
+			for d_k, d_u := range *projectname_users {
+				if (*yesUsers)[d_k] != nil {
+					continue
+				}
+				(*yesUsers)[d_k] = d_u
+			}
+		}
+		if purchasing, _ := info["purchasing"].(string); purchasing != "" {
+			purchasing = strings.ToUpper(purchasing)
+			keys := p.PnP_KeyDfa.Key.Analy(purchasing)
+			notkeys := p.PnP_KeyDfa.NotKey.Analy(purchasing)
+			purchasing_users := p.GetFinalUser(MatchWay_Purchasing, keys, notkeys, p.PnP_KeyDfa.Key_user, &notUsers)
+			for d_k, d_u := range *purchasing_users {
+				if (*yesUsers)[d_k] != nil {
+					continue
+				}
+				(*yesUsers)[d_k] = d_u
+			}
+		}
+	}
+	//匹配附件
 	if p.Detail_KeyDfa != nil {
-		//detail, _ := (*info)["projectscope"].(string)
-		//if detail == "" {
-		detail, _ := info["detail"].(string)
-		//}
-		if detail != "" {
+		if filetext, _ := info["filetext"].(string); filetext != "" {
+			filetext = strings.ToUpper(filetext)
+			keys := p.Filetext_KeyDfa.Key.Analy(filetext)
+			notkeys := p.Filetext_KeyDfa.NotKey.Analy(filetext)
+			filetext_users := p.GetFinalUser(MatchWay_Filetext, keys, notkeys, p.Filetext_KeyDfa.Key_user, &notUsers)
+			for d_k, d_u := range *filetext_users {
+				if (*yesUsers)[d_k] != nil {
+					continue
+				}
+				(*yesUsers)[d_k] = d_u
+			}
+		}
+	}
+	//匹配正文
+	if p.Detail_KeyDfa != nil {
+		if detail, _ := info["detail"].(string); detail != "" {
 			detail = strings.ToUpper(detail)
-			keys = p.Detail_KeyDfa.Key.Analy(detail)
-			notkeys = p.Detail_KeyDfa.NotKey.Analy(detail)
-			detail_users = p.GetFinalUser(MatchWay_Detail, keys, notkeys, p.Detail_KeyDfa.Key_user, &notUsers)
+			keys := p.Detail_KeyDfa.Key.Analy(detail)
+			notkeys := p.Detail_KeyDfa.NotKey.Analy(detail)
+			detail_users := p.GetFinalUser(MatchWay_Detail, keys, notkeys, p.Detail_KeyDfa.Key_user, &notUsers)
 			for d_k, d_u := range *detail_users {
-				if (*title_users)[d_k] != nil {
+				if (*yesUsers)[d_k] != nil {
 					continue
 				}
-				(*title_users)[d_k] = d_u
+				(*yesUsers)[d_k] = d_u
 			}
 		}
 	}
@@ -77,8 +128,7 @@ func (p *PayUser) ToMatch(info map[string]interface{}) (*map[*UserInfo]*MatchUse
 	for k, _ := range p.Users {
 		if notUsers[k] {
 			continue
-		}
-		if (!p.BuyerclassUsers[""][k] && !p.BuyerclassUsers[buyerclass][k]) ||
+		} else if (!p.BuyerclassUsers[""][k] && !p.BuyerclassUsers[buyerclass][k]) ||
 			(!p.AreaUsers[""][k] && !p.AreaUsers[area][k] && !p.CityUsers[city][k] && (p.DistrictUsers[city] == nil || !p.DistrictUsers[city][district][k])) {
 			continue
 		}
@@ -89,12 +139,16 @@ func (p *PayUser) ToMatch(info map[string]interface{}) (*map[*UserInfo]*MatchUse
 		if !p.SubtypeUsers[""][k] && !p.SubtypeUsers[subtype][k] {
 			continue
 		}
+		if k.SubSet.StartAmount > 0 && k.SubSet.EndAmount > 0 && (amount < k.SubSet.StartAmount || amount > k.SubSet.EndAmount) {
+			continue
+		} else if k.SubSet.StartAmount > 0 && amount < k.SubSet.StartAmount {
+			continue
+		} else if k.SubSet.EndAmount > 0 && amount > k.SubSet.EndAmount {
+			continue
+		}
 		var matchUser *MatchUser
 		if len(k.SubSet.Keys) > 0 {
-			matchUser = (*title_users)[k]
-			if matchUser == nil {
-				matchUser = (*detail_users)[k]
-			}
+			matchUser = (*yesUsers)[k]
 			if matchUser == nil {
 				continue
 			}

+ 3 - 2
p/constant.go

@@ -32,8 +32,9 @@ const (
 	Ent_EmpowerMember                     = "大会员"
 	MatchWay_Title                        = "1"
 	MatchWay_Detail                       = "2"
-	MatchWay_Attachment                   = "3"
-	MatchWay_SubjectMatter                = "4"
+	MatchWay_Filetext                     = "3"
+	MatchWay_Projectname                  = "4"
+	MatchWay_Purchasing                   = "5"
 )
 
 var (

+ 2 - 1
p/public.go

@@ -296,7 +296,8 @@ func LoadBidding(mgo *MongodbSim, dbName, coll string, startTime int64, redisCac
 				}
 				info[v] = temp[v]
 			}
-			redis.Put(Pushcache_1, "info_"+_id, info, 259200)
+			info["detail"] = temp["detail"]
+			redis.Put(Pushcache_1, "info_"+_id, info, OneDaySecond)
 		}
 		temp = make(map[string]interface{})
 		index++

+ 18 - 2
p/struct.go

@@ -67,7 +67,6 @@ type KeySet struct {
 
 // 解析订阅词
 type SubSet struct {
-	MatchWay              int                        //匹配方式 1-标题 2-正文
 	Matchbuyerclass_other int                        //是否开启其他按钮
 	ProjectMatch          int                        //项目关联推送
 	Items                 []string                   //关键词分类
@@ -88,6 +87,10 @@ type SubSet struct {
 	IsUpgrade             bool                       //免费用户是否订阅升级
 	MaxPushSize           int                        //推送最大条数
 	MaxMailSize           int                        //邮件最大条数
+	Switch                int                        //开关
+	MatchMode             []string                   //匹配方式 title detail filetext projectname/purchasing
+	StartAmount           float64                    //开始金额
+	EndAmount             float64                    //结束金额
 }
 
 // 推送设置
@@ -460,11 +463,24 @@ func (u *UserInfo) GetSubSet(isFreeUser bool, userId string, obj map[string]inte
 		Areas:                 []string{},
 		Subtypes:              []string{},
 		Buyerclasss:           []string{},
-		MatchWay:              util.IntAllDef(obj["i_matchway"], 1),
 		Matchbuyerclass_other: util.IntAllDef(obj["i_matchbuyerclass_other"], 1),
 		ProjectMatch:          util.IntAll(obj["i_projectmatch"]),
 		MaxPushSize:           util.IntAll(obj["i_maxpushsize"]),
 		MaxMailSize:           util.IntAll(obj["i_maxmailsize"]),
+		Switch:                util.IntAllDef(obj["i_switch"], 1),
+		MatchMode:             []string{},
+	}
+	matchMode, _ := obj["i_matchmode"].([]interface{})
+	for _, v := range matchMode {
+		vs, _ := v.(string)
+		subSet.MatchMode = append(subSet.MatchMode, vs)
+	}
+	if len(subSet.MatchMode) == 0 {
+		subSet.MatchMode = append(subSet.MatchMode, "title")
+	}
+	if amount := strings.Split(util.ObjToString(obj["amount"]), "-"); len(amount) == 2 {
+		subSet.StartAmount = util.Float64All(amount[0])
+		subSet.EndAmount = util.Float64All(amount[1])
 	}
 	var keySets []*KeySet
 	if isFreeUser {