paymatch.go 4.6 KB

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