paymatch.go 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. package matcher
  2. import (
  3. "strings"
  4. util "app.yhyue.com/moapp/jybase/common"
  5. . "bp.jydev.jianyu360.cn/BaseService/pushpkg/p"
  6. )
  7. //付费用户
  8. type PayUser struct {
  9. Users map[*UserInfo]bool
  10. Title_KeyDfa *KeyDfa
  11. Detail_KeyDfa *KeyDfa
  12. Filetext_KeyDfa *KeyDfa
  13. PnP_KeyDfa *KeyDfa
  14. BuyerclassUsers map[string]map[*UserInfo]bool
  15. AreaUsers map[string]map[*UserInfo]bool
  16. CityUsers map[string]map[*UserInfo]bool
  17. DistrictUsers map[string]map[string]map[*UserInfo]bool
  18. SubtypeUsers map[string]map[*UserInfo]bool
  19. TopBusinessTypeUsers map[string]map[*UserInfo]bool
  20. SubBusinessTypeUsers map[string]map[*UserInfo]bool
  21. }
  22. //
  23. func NewPayUser() *PayUser {
  24. return &PayUser{
  25. Users: map[*UserInfo]bool{},
  26. BuyerclassUsers: map[string]map[*UserInfo]bool{},
  27. AreaUsers: map[string]map[*UserInfo]bool{},
  28. CityUsers: map[string]map[*UserInfo]bool{},
  29. DistrictUsers: map[string]map[string]map[*UserInfo]bool{},
  30. SubtypeUsers: map[string]map[*UserInfo]bool{},
  31. TopBusinessTypeUsers: map[string]map[*UserInfo]bool{},
  32. SubBusinessTypeUsers: map[string]map[*UserInfo]bool{},
  33. }
  34. }
  35. //
  36. func (p *PayUser) Match(poolSize int, datas *[]map[string]interface{}) (*map[*UserInfo]*SortList, *map[*UserInfo]*[]string) {
  37. return EachFoMatch(p, poolSize, datas)
  38. }
  39. //
  40. func (p *PayUser) ToMatch(info map[string]interface{}) (*map[*UserInfo]*MatchUser, *[]*UserInfo) {
  41. buyerclass, _ := info["buyerclass"].(string)
  42. area, _ := info["area"].(string)
  43. if area == "全国" {
  44. area = ""
  45. }
  46. city, _ := info["city"].(string)
  47. district, _ := info["district"].(string)
  48. subtype, _ := info["subtype"].(string)
  49. var amount float64
  50. if info["bidamount"] != nil {
  51. amount = util.Float64All(info["bidamount"])
  52. } else if info["budget"] != nil {
  53. amount = util.Float64All(info["budget"])
  54. }
  55. tag_topinformation, _ := info["tag_topinformation"].([]interface{})
  56. tag_subinformation, _ := info["tag_subinformation"].([]interface{})
  57. notUsers := map[*UserInfo]bool{}
  58. yesUsers := &map[*UserInfo]*MatchUser{}
  59. //匹配标题
  60. if p.Title_KeyDfa != nil {
  61. if title := GetInfoTitle(info); title != "" {
  62. //订阅词
  63. keys := p.Title_KeyDfa.Key.Analy(title)
  64. //排除词
  65. notkeys := p.Title_KeyDfa.NotKey.Analy(title)
  66. yesUsers = p.GetFinalUser(MatchWay_Title, keys, notkeys, p.Title_KeyDfa.Key_user, &notUsers)
  67. }
  68. }
  69. //匹配项目名称/标的物
  70. if p.PnP_KeyDfa != nil {
  71. if projectname, _ := info["projectname"].(string); projectname != "" {
  72. projectname = strings.ToUpper(projectname)
  73. keys := p.PnP_KeyDfa.Key.Analy(projectname)
  74. notkeys := p.PnP_KeyDfa.NotKey.Analy(projectname)
  75. projectname_users := p.GetFinalUser(MatchWay_Projectname, keys, notkeys, p.PnP_KeyDfa.Key_user, &notUsers)
  76. for d_k, d_u := range *projectname_users {
  77. if (*yesUsers)[d_k] != nil {
  78. continue
  79. }
  80. (*yesUsers)[d_k] = d_u
  81. }
  82. }
  83. if purchasing, _ := info["purchasing"].(string); purchasing != "" {
  84. purchasing = strings.ToUpper(purchasing)
  85. keys := p.PnP_KeyDfa.Key.Analy(purchasing)
  86. notkeys := p.PnP_KeyDfa.NotKey.Analy(purchasing)
  87. purchasing_users := p.GetFinalUser(MatchWay_Purchasing, keys, notkeys, p.PnP_KeyDfa.Key_user, &notUsers)
  88. for d_k, d_u := range *purchasing_users {
  89. if (*yesUsers)[d_k] != nil {
  90. continue
  91. }
  92. (*yesUsers)[d_k] = d_u
  93. }
  94. }
  95. }
  96. //匹配附件
  97. if p.Filetext_KeyDfa != nil {
  98. if filetext, _ := info["filetext"].(string); filetext != "" {
  99. filetext = strings.ToUpper(filetext)
  100. keys := p.Filetext_KeyDfa.Key.Analy(filetext)
  101. notkeys := p.Filetext_KeyDfa.NotKey.Analy(filetext)
  102. filetext_users := p.GetFinalUser(MatchWay_Filetext, keys, notkeys, p.Filetext_KeyDfa.Key_user, &notUsers)
  103. for d_k, d_u := range *filetext_users {
  104. if (*yesUsers)[d_k] != nil {
  105. continue
  106. }
  107. (*yesUsers)[d_k] = d_u
  108. }
  109. }
  110. }
  111. //匹配正文
  112. if p.Detail_KeyDfa != nil {
  113. if detail, _ := info["detail"].(string); detail != "" {
  114. detail = strings.ToUpper(detail)
  115. keys := p.Detail_KeyDfa.Key.Analy(detail)
  116. notkeys := p.Detail_KeyDfa.NotKey.Analy(detail)
  117. detail_users := p.GetFinalUser(MatchWay_Detail, keys, notkeys, p.Detail_KeyDfa.Key_user, &notUsers)
  118. for d_k, d_u := range *detail_users {
  119. if (*yesUsers)[d_k] != nil {
  120. continue
  121. }
  122. (*yesUsers)[d_k] = d_u
  123. }
  124. }
  125. }
  126. users := map[*UserInfo]*MatchUser{}
  127. var projectUsers []*UserInfo
  128. for k, _ := range p.Users {
  129. if notUsers[k] {
  130. continue
  131. } else if !p.MatchArray(tag_topinformation, k, p.TopBusinessTypeUsers) || !p.MatchArray(tag_subinformation, k, p.SubBusinessTypeUsers) ||
  132. (!p.BuyerclassUsers[""][k] && !p.BuyerclassUsers[buyerclass][k]) ||
  133. (!p.AreaUsers[""][k] && !p.AreaUsers[area][k] && !p.CityUsers[city][k] && (p.DistrictUsers[city] == nil || !p.DistrictUsers[city][district][k])) {
  134. continue
  135. }
  136. //关联项目不需要匹配信息类型
  137. if k.SubSet.ProjectMatch == 1 {
  138. projectUsers = append(projectUsers, k)
  139. }
  140. if !p.SubtypeUsers[""][k] && !p.SubtypeUsers[subtype][k] {
  141. continue
  142. }
  143. if k.SubSet.StartAmount > 0 && k.SubSet.EndAmount > 0 && (amount < k.SubSet.StartAmount || amount > k.SubSet.EndAmount) {
  144. continue
  145. } else if k.SubSet.StartAmount > 0 && amount < k.SubSet.StartAmount {
  146. continue
  147. } else if k.SubSet.EndAmount > 0 && amount > k.SubSet.EndAmount {
  148. continue
  149. }
  150. var matchUser *MatchUser
  151. if len(k.SubSet.Keys) > 0 {
  152. matchUser = (*yesUsers)[k]
  153. if matchUser == nil {
  154. continue
  155. }
  156. } else {
  157. matchUser = &MatchUser{}
  158. }
  159. users[k] = matchUser
  160. }
  161. return &users, &projectUsers
  162. }
  163. //获取最终的用户,排除词、信息范围、信息类型之后的
  164. //返回匹配上的用户和没有匹配到的用户
  165. func (p *PayUser) GetFinalUser(matchWay string, keys, notkeys []string, key_user *map[string]*[]*UserInfo, notUsers *map[*UserInfo]bool) *map[*UserInfo]*MatchUser {
  166. keyMap := map[string]bool{}
  167. for _, v := range keys {
  168. keyMap[v] = true
  169. }
  170. users := map[*UserInfo]*MatchUser{} //匹配到用户
  171. //遍历所有用户
  172. for k, us := range *key_user {
  173. if !keyMap[k] { //该关键词没有匹配到的用户
  174. continue
  175. }
  176. for _, u := range *us {
  177. //获取该词下面所有的用户
  178. //遍历我的排除词,如果存在的话,排除自己
  179. isContinue := false
  180. for _, notkey := range notkeys {
  181. if u.SubSet.Key_notkey[k][notkey] {
  182. isContinue = true
  183. break
  184. }
  185. }
  186. if isContinue {
  187. (*notUsers)[u] = true
  188. continue
  189. }
  190. matchUser := users[u]
  191. if matchUser == nil {
  192. matchUser = &MatchUser{
  193. Keys: []string{},
  194. Items: []string{},
  195. Item: map[string]bool{},
  196. MatchWays: []string{},
  197. MatchWay: map[string]bool{},
  198. }
  199. }
  200. matchUser.Keys = append(matchUser.Keys, k)
  201. item := u.SubSet.Key_item[k]
  202. if item != "" {
  203. if !matchUser.Item[item] {
  204. matchUser.Items = append(matchUser.Items, item)
  205. }
  206. matchUser.Item[item] = true
  207. }
  208. if !matchUser.MatchWay[matchWay] {
  209. matchUser.MatchWays = append(matchUser.MatchWays, matchWay)
  210. }
  211. matchUser.MatchWay[matchWay] = true
  212. users[u] = matchUser
  213. }
  214. }
  215. return &users
  216. }
  217. //
  218. func (p *PayUser) MatchArray(values []interface{}, u *UserInfo, all map[string]map[*UserInfo]bool) bool {
  219. if all[""][u] {
  220. return true
  221. }
  222. for _, v := range values {
  223. vs, _ := v.(string)
  224. if vs == "" {
  225. continue
  226. }
  227. if all[vs][u] {
  228. return true
  229. }
  230. }
  231. return false
  232. }