package matcher import ( "strings" . "bp.jydev.jianyu360.cn/BaseService/pushpkg/p" ) //付费用户 type PayUser struct { Users map[*UserInfo]bool Title_KeyDfa *KeyDfa Detail_KeyDfa *KeyDfa BuyerclassUsers map[string]map[*UserInfo]bool AreaUsers map[string]map[*UserInfo]bool CityUsers map[string]map[*UserInfo]bool SubtypeUsers 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{}, SubtypeUsers: map[string]map[*UserInfo]bool{}, } } // func (p *PayUser) Match(info *map[string]interface{}) (*map[*UserInfo]*MatchUser, *[]*UserInfo) { buyerclass, _ := (*info)["buyerclass"].(string) area, _ := (*info)["area"].(string) if area == "全国" { area = "" } city, _ := (*info)["city"].(string) subtype, _ := (*info)["subtype"].(string) title := GetInfoTitle(info) //订阅词 keys := p.Title_KeyDfa.Key.Analy(title) //排除词 notkeys := p.Title_KeyDfa.NotKey.Analy(title) notUsers := map[*UserInfo]bool{} title_users := p.GetFinalUser(MatchWay_Title, keys, notkeys, p.Title_KeyDfa.Key_user, ¬Users) //开启智能匹配的用户,匹配projectscope detail_users := &map[*UserInfo]*MatchUser{} if p.Detail_KeyDfa != nil { //detail, _ := (*info)["projectscope"].(string) //if detail == "" { detail, _ := (*info)["detail"].(string) //} if 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, ¬Users) for d_k, d_u := range *detail_users { if (*title_users)[d_k] != nil { continue } (*title_users)[d_k] = d_u } } } users := map[*UserInfo]*MatchUser{} var projectUsers []*UserInfo for k, _ := range p.Users { if notUsers[k] { continue } if (!p.BuyerclassUsers[""][k] && !p.BuyerclassUsers[buyerclass][k]) || (!p.AreaUsers[""][k] && !p.AreaUsers[area][k] && !p.CityUsers[city][k]) { continue } //关联项目不需要匹配信息类型 if k.SubSet.ProjectMatch == 1 { projectUsers = append(projectUsers, k) } if !p.SubtypeUsers[""][k] && !p.SubtypeUsers[subtype][k] { continue } var matchUser *MatchUser if len(k.SubSet.Keys) > 0 { matchUser = (*title_users)[k] if matchUser == nil { matchUser = (*detail_users)[k] } if matchUser == nil { continue } } else { matchUser = &MatchUser{} } users[k] = matchUser } return &users, &projectUsers } //获取最终的用户,排除词、信息范围、信息类型之后的 //返回匹配上的用户和没有匹配到的用户 func (p *PayUser) GetFinalUser(matchWay string, keys, notkeys []string, key_user *map[string]*[]*UserInfo, notUsers *map[*UserInfo]bool) *map[*UserInfo]*MatchUser { keyMap := map[string]bool{} for _, v := range keys { keyMap[v] = true } users := map[*UserInfo]*MatchUser{} //匹配到用户 //遍历所有用户 for k, us := range *key_user { if !keyMap[k] { //该关键词没有匹配到的用户 continue } for _, u := range *us { //获取该词下面所有的用户 //遍历我的排除词,如果存在的话,排除自己 isContinue := false for _, notkey := range notkeys { if u.SubSet.Key_notkey[k][notkey] { isContinue = true break } } if isContinue { (*notUsers)[u] = true continue } matchUser := users[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 users[u] = matchUser } } return &users }