paymatch.go 3.9 KB

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