paymatch.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. package matcher
  2. import (
  3. "strings"
  4. . "bp.jydev.jianyu360.cn/BaseService/pushpkg/p"
  5. )
  6. //付费用户
  7. type PayUser struct {
  8. Users map[*UserInfo]bool
  9. Title_KeyDfa *KeyDfa
  10. Detail_KeyDfa *KeyDfa
  11. BuyerclassUsers map[string]map[*UserInfo]bool
  12. AreaUsers map[string]map[*UserInfo]bool
  13. CityUsers map[string]map[*UserInfo]bool
  14. DistrictUsers map[string]map[string]map[*UserInfo]bool
  15. SubtypeUsers map[string]map[*UserInfo]bool
  16. }
  17. //
  18. func NewPayUser() *PayUser {
  19. return &PayUser{
  20. Users: map[*UserInfo]bool{},
  21. BuyerclassUsers: map[string]map[*UserInfo]bool{},
  22. AreaUsers: map[string]map[*UserInfo]bool{},
  23. CityUsers: map[string]map[*UserInfo]bool{},
  24. DistrictUsers: map[string]map[string]map[*UserInfo]bool{},
  25. SubtypeUsers: map[string]map[*UserInfo]bool{},
  26. }
  27. }
  28. //
  29. func (p *PayUser) Match(poolSize int, datas *[]map[string]interface{}) (*map[*UserInfo]*SortList, *map[*UserInfo]*[]string) {
  30. return EachFoMatch(p, poolSize, datas)
  31. }
  32. //
  33. func (p *PayUser) ToMatch(info map[string]interface{}) (*map[*UserInfo]*MatchUser, *[]*UserInfo) {
  34. buyerclass, _ := info["buyerclass"].(string)
  35. area, _ := info["area"].(string)
  36. if area == "全国" {
  37. area = ""
  38. }
  39. city, _ := info["city"].(string)
  40. district, _ := info["district"].(string)
  41. subtype, _ := info["subtype"].(string)
  42. title := GetInfoTitle(info)
  43. //订阅词
  44. keys := p.Title_KeyDfa.Key.Analy(title)
  45. //排除词
  46. notkeys := p.Title_KeyDfa.NotKey.Analy(title)
  47. notUsers := map[*UserInfo]bool{}
  48. title_users := p.GetFinalUser(MatchWay_Title, keys, notkeys, p.Title_KeyDfa.Key_user, &notUsers)
  49. //开启智能匹配的用户,匹配projectscope
  50. detail_users := &map[*UserInfo]*MatchUser{}
  51. if p.Detail_KeyDfa != nil {
  52. //detail, _ := (*info)["projectscope"].(string)
  53. //if detail == "" {
  54. detail, _ := info["detail"].(string)
  55. //}
  56. if detail != "" {
  57. detail = strings.ToUpper(detail)
  58. keys = p.Detail_KeyDfa.Key.Analy(detail)
  59. notkeys = p.Detail_KeyDfa.NotKey.Analy(detail)
  60. detail_users = p.GetFinalUser(MatchWay_Detail, keys, notkeys, p.Detail_KeyDfa.Key_user, &notUsers)
  61. for d_k, d_u := range *detail_users {
  62. if (*title_users)[d_k] != nil {
  63. continue
  64. }
  65. (*title_users)[d_k] = d_u
  66. }
  67. }
  68. }
  69. users := map[*UserInfo]*MatchUser{}
  70. var projectUsers []*UserInfo
  71. for k, _ := range p.Users {
  72. if notUsers[k] {
  73. continue
  74. }
  75. if (!p.BuyerclassUsers[""][k] && !p.BuyerclassUsers[buyerclass][k]) ||
  76. (!p.AreaUsers[""][k] && !p.AreaUsers[area][k] && !p.CityUsers[city][k] && (p.DistrictUsers[city] == nil || !p.DistrictUsers[city][district][k])) {
  77. continue
  78. }
  79. //关联项目不需要匹配信息类型
  80. if k.SubSet.ProjectMatch == 1 {
  81. projectUsers = append(projectUsers, k)
  82. }
  83. if !p.SubtypeUsers[""][k] && !p.SubtypeUsers[subtype][k] {
  84. continue
  85. }
  86. var matchUser *MatchUser
  87. if len(k.SubSet.Keys) > 0 {
  88. matchUser = (*title_users)[k]
  89. if matchUser == nil {
  90. matchUser = (*detail_users)[k]
  91. }
  92. if matchUser == nil {
  93. continue
  94. }
  95. } else {
  96. matchUser = &MatchUser{}
  97. }
  98. users[k] = matchUser
  99. }
  100. return &users, &projectUsers
  101. }
  102. //获取最终的用户,排除词、信息范围、信息类型之后的
  103. //返回匹配上的用户和没有匹配到的用户
  104. func (p *PayUser) GetFinalUser(matchWay string, keys, notkeys []string, key_user *map[string]*[]*UserInfo, notUsers *map[*UserInfo]bool) *map[*UserInfo]*MatchUser {
  105. keyMap := map[string]bool{}
  106. for _, v := range keys {
  107. keyMap[v] = true
  108. }
  109. users := map[*UserInfo]*MatchUser{} //匹配到用户
  110. //遍历所有用户
  111. for k, us := range *key_user {
  112. if !keyMap[k] { //该关键词没有匹配到的用户
  113. continue
  114. }
  115. for _, u := range *us {
  116. //获取该词下面所有的用户
  117. //遍历我的排除词,如果存在的话,排除自己
  118. isContinue := false
  119. for _, notkey := range notkeys {
  120. if u.SubSet.Key_notkey[k][notkey] {
  121. isContinue = true
  122. break
  123. }
  124. }
  125. if isContinue {
  126. (*notUsers)[u] = true
  127. continue
  128. }
  129. matchUser := users[u]
  130. if matchUser == nil {
  131. matchUser = &MatchUser{
  132. Keys: []string{},
  133. Items: []string{},
  134. Item: map[string]bool{},
  135. MatchWays: []string{},
  136. MatchWay: map[string]bool{},
  137. }
  138. }
  139. matchUser.Keys = append(matchUser.Keys, k)
  140. item := u.SubSet.Key_item[k]
  141. if item != "" {
  142. if !matchUser.Item[item] {
  143. matchUser.Items = append(matchUser.Items, item)
  144. }
  145. matchUser.Item[item] = true
  146. }
  147. if !matchUser.MatchWay[matchWay] {
  148. matchUser.MatchWays = append(matchUser.MatchWays, matchWay)
  149. }
  150. matchUser.MatchWay[matchWay] = true
  151. users[u] = matchUser
  152. }
  153. }
  154. return &users
  155. }