|
@@ -0,0 +1,105 @@
|
|
|
+package matcher
|
|
|
+
|
|
|
+import (
|
|
|
+ . "bp.jydev.jianyu360.cn/BaseService/pushpkg/p"
|
|
|
+)
|
|
|
+
|
|
|
+//免费用户
|
|
|
+type FreeUser struct {
|
|
|
+ Users map[*UserInfo]bool
|
|
|
+ Title_KeyDfa *KeyDfa
|
|
|
+ AreaUsers map[string]map[*UserInfo]bool
|
|
|
+ SubtypeUsers map[string]map[*UserInfo]bool
|
|
|
+}
|
|
|
+
|
|
|
+//
|
|
|
+func NewFreeUser() *FreeUser {
|
|
|
+ return &FreeUser{
|
|
|
+ Users: map[*UserInfo]bool{},
|
|
|
+ AreaUsers: map[string]map[*UserInfo]bool{},
|
|
|
+ SubtypeUsers: map[string]map[*UserInfo]bool{},
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+//
|
|
|
+func (f *FreeUser) Match(info map[string]interface{}) (*map[*UserInfo]*MatchUser, *[]*UserInfo) {
|
|
|
+ area, _ := info["area"].(string)
|
|
|
+ if area == "全国" {
|
|
|
+ area = ""
|
|
|
+ }
|
|
|
+ toptype, _ := info["toptype"].(string)
|
|
|
+ title := GetInfoTitle(info)
|
|
|
+ //订阅词
|
|
|
+ keys := f.Title_KeyDfa.Key.Analy(title)
|
|
|
+ //排除词
|
|
|
+ notkeys := f.Title_KeyDfa.NotKey.Analy(title)
|
|
|
+ title_users := f.GetFinalUser(keys, notkeys, f.Title_KeyDfa.Key_user, info)
|
|
|
+ users := map[*UserInfo]*MatchUser{}
|
|
|
+ for k, _ := range f.Users {
|
|
|
+ if k.SubSet.IsUpgrade && ((!f.AreaUsers[""][k] && !f.AreaUsers[area][k]) || (!f.SubtypeUsers[""][k] && !f.SubtypeUsers[toptype][k])) {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ var matchUser *MatchUser
|
|
|
+ if len(k.SubSet.Keys) > 0 {
|
|
|
+ matchUser = (*title_users)[k]
|
|
|
+ if matchUser == nil {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ matchUser = &MatchUser{}
|
|
|
+ }
|
|
|
+ users[k] = matchUser
|
|
|
+ }
|
|
|
+ return &users, nil
|
|
|
+}
|
|
|
+
|
|
|
+//获取最终的用户,排除词、信息范围、信息类型之后的
|
|
|
+//返回匹配上的用户和没有匹配到的用户
|
|
|
+func (f *FreeUser) GetFinalUser(keys, notkeys []string, key_user *map[string]*[]*UserInfo, info map[string]interface{}) *map[*UserInfo]*MatchUser {
|
|
|
+ area, _ := info["area"].(string)
|
|
|
+ toptype, _ := info["toptype"].(string)
|
|
|
+ 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 {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if !u.SubSet.IsUpgrade {
|
|
|
+ //遍历我的信息范围,看该信息是不是在我的信息范围中
|
|
|
+ if len(u.SubSet.Key_area[k]) > 0 && !u.SubSet.Key_area[k][area] {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ //遍历我的信息类型,看该信息是不是在我的信息类型中
|
|
|
+ if len(u.SubSet.Key_subtype[k]) > 0 && !u.SubSet.Key_subtype[k][toptype] {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ }
|
|
|
+ matchUser := users[u]
|
|
|
+ if matchUser == nil {
|
|
|
+ matchUser = &MatchUser{
|
|
|
+ Keys: []string{},
|
|
|
+ }
|
|
|
+ }
|
|
|
+ matchUser.Keys = append(matchUser.Keys, k)
|
|
|
+ users[u] = matchUser
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return &users
|
|
|
+}
|