123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- package matcher
- import (
- "strings"
- util "app.yhyue.com/moapp/jybase/common"
- . "bp.jydev.jianyu360.cn/BaseService/pushpkg/p"
- )
- //付费用户
- 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
- DistrictUsers map[string]map[string]map[*UserInfo]bool
- SubtypeUsers map[string]map[*UserInfo]bool
- TopBusinessTypeUsers map[string]map[*UserInfo]bool
- SubBusinessTypeUsers map[string]map[*UserInfo]bool
- }
- //
- func NewPayUser() *PayUser {
- return &PayUser{
- Users: map[*UserInfo]bool{},
- BuyerclassUsers: map[string]map[*UserInfo]bool{},
- AreaUsers: map[string]map[*UserInfo]bool{},
- CityUsers: map[string]map[*UserInfo]bool{},
- DistrictUsers: map[string]map[string]map[*UserInfo]bool{},
- SubtypeUsers: map[string]map[*UserInfo]bool{},
- TopBusinessTypeUsers: map[string]map[*UserInfo]bool{},
- SubBusinessTypeUsers: map[string]map[*UserInfo]bool{},
- }
- }
- //
- func (p *PayUser) Match(poolSize int, datas *[]map[string]interface{}) (*map[*UserInfo]*SortList, *map[*UserInfo]*[]string) {
- return EachFoMatch(p, poolSize, datas)
- }
- //
- func (p *PayUser) ToMatch(info map[string]interface{}) (*map[*UserInfo]*MatchUser, *[]*UserInfo) {
- buyerclass, _ := info["buyerclass"].(string)
- area, _ := info["area"].(string)
- if area == "全国" {
- area = ""
- }
- city, _ := info["city"].(string)
- district, _ := info["district"].(string)
- subtype, _ := info["subtype"].(string)
- var amount float64
- if info["bidamount"] != nil {
- amount = util.Float64All(info["bidamount"])
- } else if info["budget"] != nil {
- amount = util.Float64All(info["budget"])
- }
- tag_topinformation, _ := info["tag_topinformation"].([]interface{})
- tag_subinformation, _ := info["tag_subinformation"].([]interface{})
- yesUsers := map[*UserInfo]*MatchUser{}
- allKeys, notkeys := []string{}, []string{}
- //匹配标题
- if p.Title_KeyDfa != nil {
- if title := GetInfoTitle(info); title != "" {
- //订阅词
- keys := p.Title_KeyDfa.Key.Analy(title)
- allKeys = append(allKeys, keys...)
- //排除词
- notkeys = append(notkeys, p.Title_KeyDfa.NotKey.Analy(title)...)
- p.GetKeyUser(MatchWay_Title, keys, p.Title_KeyDfa.Key_user, yesUsers)
- }
- }
- //匹配项目名称/标的物
- if p.PnP_KeyDfa != nil {
- if projectname, _ := info["projectname"].(string); projectname != "" {
- projectname = strings.ToUpper(projectname)
- keys := p.PnP_KeyDfa.Key.Analy(projectname)
- allKeys = append(allKeys, keys...)
- notkeys = append(notkeys, p.PnP_KeyDfa.NotKey.Analy(projectname)...)
- p.GetKeyUser(MatchWay_Projectname, keys, p.PnP_KeyDfa.Key_user, yesUsers)
- }
- if purchasing, _ := info["purchasing"].(string); purchasing != "" {
- purchasing = strings.ToUpper(purchasing)
- keys := p.PnP_KeyDfa.Key.Analy(purchasing)
- allKeys = append(allKeys, keys...)
- notkeys = append(notkeys, p.PnP_KeyDfa.NotKey.Analy(purchasing)...)
- p.GetKeyUser(MatchWay_Purchasing, keys, p.PnP_KeyDfa.Key_user, yesUsers)
- }
- }
- //匹配附件
- if p.Filetext_KeyDfa != nil {
- if filetext, _ := info["filetext"].(string); filetext != "" {
- filetext = strings.ToUpper(filetext)
- keys := p.Filetext_KeyDfa.Key.Analy(filetext)
- allKeys = append(allKeys, keys...)
- notkeys = append(notkeys, p.Filetext_KeyDfa.NotKey.Analy(filetext)...)
- p.GetKeyUser(MatchWay_Filetext, keys, p.Filetext_KeyDfa.Key_user, yesUsers)
- }
- }
- //匹配正文
- if p.Detail_KeyDfa != nil {
- if detail, _ := info["detail"].(string); detail != "" {
- detail = strings.ToUpper(detail)
- keys := p.Detail_KeyDfa.Key.Analy(detail)
- allKeys = append(allKeys, keys...)
- notkeys = append(notkeys, p.Detail_KeyDfa.NotKey.Analy(detail)...)
- p.GetKeyUser(MatchWay_Detail, keys, p.Detail_KeyDfa.Key_user, yesUsers)
- }
- }
- notUsers := p.GetFinalUser(allKeys, notkeys, p.Title_KeyDfa, p.PnP_KeyDfa, p.Filetext_KeyDfa, p.Detail_KeyDfa)
- users := map[*UserInfo]*MatchUser{}
- var projectUsers []*UserInfo
- for k, _ := range p.Users {
- if notUsers[k] {
- continue
- } 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
- }
- //小程序
- if k.Extend != nil && k.Extend.Object != nil {
- if isMiniProgram, _ := k.Extend.Object["isMiniProgram"].(bool); isMiniProgram && (!p.MatchArray(tag_topinformation, k, p.TopBusinessTypeUsers) || !p.MatchArray(tag_subinformation, k, p.SubBusinessTypeUsers)) {
- continue
- }
- }
- //关联项目不需要匹配信息类型
- if k.SubSet.ProjectMatch == 1 {
- projectUsers = append(projectUsers, k)
- }
- 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 = yesUsers[k]
- if matchUser == nil {
- continue
- }
- } else {
- matchUser = &MatchUser{}
- }
- users[k] = matchUser
- }
- return &users, &projectUsers
- }
- //返回匹配上的用户
- func (p *PayUser) GetKeyUser(matchWay string, keys []string, keyUser *map[string]*[]*UserInfo, yesUsers map[*UserInfo]*MatchUser) {
- keyMap := map[string]bool{}
- for _, v := range keys {
- keyMap[v] = true
- }
- //遍历所有用户
- for k, us := range *keyUser {
- if !keyMap[k] { //该关键词没有匹配到的用户
- continue
- }
- for _, u := range *us {
- //获取该词下面所有的用户
- matchUser := yesUsers[u]
- if matchUser == nil {
- matchUser = &MatchUser{
- Keys: []string{},
- Items: []string{},
- Item: map[string]bool{},
- MatchWays: []string{},
- MatchWay: map[string]bool{},
- }
- }
- matchUser.Keys = append(matchUser.Keys, k)
- item := u.SubSet.Key_item[k]
- if item != "" {
- if !matchUser.Item[item] {
- matchUser.Items = append(matchUser.Items, item)
- }
- matchUser.Item[item] = true
- }
- if !matchUser.MatchWay[matchWay] {
- matchUser.MatchWays = append(matchUser.MatchWays, matchWay)
- }
- matchUser.MatchWay[matchWay] = true
- yesUsers[u] = matchUser
- }
- }
- }
- //获取最终的用户,排除词、信息范围、信息类型之后的
- //返回匹配上的用户和没有匹配到的用户
- func (p *PayUser) GetFinalUser(keys, notkeys []string, keyUsers ...*KeyDfa) map[*UserInfo]bool {
- notUsers := map[*UserInfo]bool{}
- keyMap := map[string]bool{}
- for _, v := range keys {
- keyMap[v] = true
- }
- //遍历所有用户
- for _, keyUser := range keyUsers {
- if keyUser == nil {
- continue
- }
- for k, us := range *keyUser.Key_user {
- if !keyMap[k] { //该关键词没有匹配到的用户
- continue
- }
- L:
- for _, u := range *us {
- //获取该词下面所有的用户
- //遍历我的排除词,如果存在的话,排除自己
- for _, notkey := range notkeys {
- if u.SubSet.Key_notkey[k][notkey] {
- notUsers[u] = true
- continue L
- }
- }
- }
- }
- }
- return notUsers
- }
- //
- func (p *PayUser) MatchArray(values []interface{}, u *UserInfo, all map[string]map[*UserInfo]bool) bool {
- if all[""][u] {
- return true
- }
- for _, v := range values {
- vs, _ := v.(string)
- if vs == "" {
- continue
- }
- if all[vs][u] {
- return true
- }
- }
- return false
- }
|