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{}) notUsers := map[*UserInfo]bool{} 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, ¬Users) } } //匹配项目名称/标的物 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, ¬Users) 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, ¬Users) for d_k, d_u := range *purchasing_users { if (*yesUsers)[d_k] != nil { continue } (*yesUsers)[d_k] = d_u } } } //匹配附件 if p.Filetext_KeyDfa != nil { 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, ¬Users) 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, ¬Users) for d_k, d_u := range *detail_users { if (*yesUsers)[d_k] != nil { continue } (*yesUsers)[d_k] = d_u } } } 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) 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 } // 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 }