matcher_test.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. package matcher
  2. import (
  3. "fmt"
  4. "testing"
  5. util "app.yhyue.com/moapp/jybase/common"
  6. "app.yhyue.com/moapp/jybase/logger"
  7. . "app.yhyue.com/moapp/jybase/mongodb"
  8. . "bp.jydev.jianyu360.cn/BaseService/pushpkg/p"
  9. )
  10. func TestMatch(t *testing.T) {
  11. m := &matchJob{}
  12. m.mgo = &MongodbSim{
  13. MongodbAddr: "192.168.3.206:27080",
  14. Size: 2,
  15. DbName: "qfw",
  16. }
  17. m.mgo.InitPool()
  18. bidMgo := &MongodbSim{
  19. MongodbAddr: "192.168.3.206:27002",
  20. Size: 2,
  21. DbName: "qfw",
  22. UserName: "jyDevGroup",
  23. Password: "jy@DevGroup",
  24. }
  25. bidMgo.InitPool()
  26. query := map[string]interface{}{
  27. "_id": map[string]interface{}{
  28. "$in": ToObjectIds([]string{"665cc37666cf0db42a7f7981"}),
  29. },
  30. }
  31. datas, _ := LoadBidding(bidMgo, "qfw_data", "bidding", 0, false, query, nil)
  32. m.Start(datas)
  33. }
  34. type matchJob struct {
  35. mgo *MongodbSim
  36. }
  37. func (m *matchJob) Start(datas *[]map[string]interface{}) {
  38. defer util.Catch()
  39. allSubSet := NewPayUser()
  40. //标题匹配
  41. title_key := make(map[string]*[]*UserInfo)
  42. title_notkey := make(map[string]*[]*UserInfo)
  43. title_pjob := &KeyDfa{
  44. Key_user: &title_key,
  45. Notkey_user: &title_notkey,
  46. }
  47. //正文匹配
  48. detail_key := make(map[string]*[]*UserInfo)
  49. detail_notkey := make(map[string]*[]*UserInfo)
  50. detail_pjob := &KeyDfa{
  51. Key_user: &detail_key,
  52. Notkey_user: &detail_notkey,
  53. }
  54. //附件匹配
  55. filetext_key := make(map[string]*[]*UserInfo)
  56. filetext_notkey := make(map[string]*[]*UserInfo)
  57. filetext_pjob := &KeyDfa{
  58. Key_user: &filetext_key,
  59. Notkey_user: &filetext_notkey,
  60. }
  61. //项目名称/标的物匹配
  62. pnp_key := make(map[string]*[]*UserInfo)
  63. pnp_notkey := make(map[string]*[]*UserInfo)
  64. pnp_pjob := &KeyDfa{
  65. Key_user: &pnp_key,
  66. Notkey_user: &pnp_notkey,
  67. }
  68. m.LoadMySubSet(allSubSet, title_pjob, detail_pjob, filetext_pjob, pnp_pjob)
  69. //
  70. title_pjob.CreateDaf()
  71. detail_pjob.CreateDaf()
  72. filetext_pjob.CreateDaf()
  73. pnp_pjob.CreateDaf()
  74. allSubSet.Title_KeyDfa = title_pjob
  75. allSubSet.Detail_KeyDfa = detail_pjob
  76. allSubSet.Filetext_KeyDfa = filetext_pjob
  77. allSubSet.PnP_KeyDfa = pnp_pjob
  78. //
  79. allSubSet.Match(1, datas)
  80. }
  81. //我的订阅设置
  82. func (m *matchJob) LoadMySubSet(allSubSet *PayUser, title_pjob, detail_pjob, filetext_pjob, pnp_pjob *KeyDfa) {
  83. defer util.Catch()
  84. sess := m.mgo.GetMgoConn()
  85. defer m.mgo.DestoryMongoConn(sess)
  86. query := map[string]interface{}{
  87. "_id": StringTOBsonId("665a8ba6842ed1e25c138ac7"),
  88. }
  89. logger.Info("我的订阅设置", query)
  90. it := sess.DB("qfw").C("entniche_rule").Find(query).Select(map[string]interface{}{
  91. "i_entid": 1,
  92. "i_deptid": 1,
  93. "i_userid": 1,
  94. "o_entniche": 1,
  95. "i_type": 1,
  96. }).Iter()
  97. for temp := make(map[string]interface{}); it.Next(&temp); {
  98. entId := util.IntAll(temp["i_entid"])
  99. userId := util.IntAll(temp["i_userid"])
  100. user := &UserInfo{
  101. Entniche: &Entniche{
  102. UserId: userId,
  103. IsNew: 1,
  104. },
  105. }
  106. subSetType := util.IntAllDef(temp["i_type"], -1)
  107. subSet, _ := temp["o_entniche"].(map[string]interface{})
  108. user.GetSubSet(subSetType == 2, fmt.Sprint(userId), subSet)
  109. if user.SubSet.Switch == 0 {
  110. logger.Info("订阅开关没有开启,过滤掉", entId, userId)
  111. continue
  112. }
  113. if subSetType == 2 && len(user.SubSet.Keys) == 0 {
  114. logger.Info("过滤掉,没有关键词", entId, userId)
  115. continue
  116. } else if subSetType != 2 && len(user.SubSet.Keys) == 0 && user.SubSet.Subtype == nil && user.SubSet.Area == nil && user.SubSet.Buyerclass == nil {
  117. logger.Info("没有订阅,过滤掉", entId, userId)
  118. continue
  119. }
  120. if subSetType == 2 {
  121. user.PushSet.SubSet.RateMode = 0
  122. }
  123. m.InitSubSet(allSubSet, user, title_pjob, detail_pjob, filetext_pjob, pnp_pjob)
  124. allSubSet.Users[user] = true
  125. temp = make(map[string]interface{})
  126. }
  127. }
  128. func (m *matchJob) InitSubSet(allSubSet *PayUser, user *UserInfo, title_pjob, detail_pjob, filetext_pjob, pnp_pjob *KeyDfa) {
  129. user.AddBuyerclass(&allSubSet.BuyerclassUsers)
  130. user.AddAreaCityDistrict(&allSubSet.AreaUsers, &allSubSet.CityUsers, &allSubSet.DistrictUsers)
  131. user.AddSubtype(&allSubSet.SubtypeUsers)
  132. user.MakeKeyUserByMatchMode(title_pjob, detail_pjob, filetext_pjob, pnp_pjob)
  133. }