ownermonitor.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. package ownermonitor
  2. import (
  3. "fmt"
  4. "time"
  5. "app.yhyue.com/moapp/jybase/redis"
  6. util "app.yhyue.com/moapp/jybase/common"
  7. "app.yhyue.com/moapp/jybase/logger"
  8. . "app.yhyue.com/moapp/jybase/mongodb"
  9. . "app.yhyue.com/moapp/jybase/mysql"
  10. . "bp.jydev.jianyu360.cn/BaseService/pushpkg/p"
  11. . "bp.jydev.jianyu360.cn/BaseService/userCenter/identity"
  12. )
  13. const (
  14. Pushspace_temp = "pushspace_ownermonitor_temp"
  15. )
  16. type OwnerMonitorInfo struct {
  17. *UserInfo
  18. OwnerMonitors []*OwnerMonitor //关注
  19. }
  20. //
  21. type OwnerMonitor struct {
  22. Id string //关注id
  23. EntName string //企业名称
  24. CreateTime int64 //关注时间
  25. Infos CSortList //匹配上的信息
  26. }
  27. //加载业主监控
  28. func LoadOwnerMonitor(mgo *MongodbSim, userId string) map[string]*OwnerMonitor {
  29. result := map[string]*OwnerMonitor{}
  30. list, _ := mgo.Find("follow_customer", map[string]interface{}{"userId": userId}, nil, `{"_id":1,"name":1,"date":1}`, false, -1, -1)
  31. if list != nil {
  32. for _, v := range *list {
  33. name, _ := v["name"].(string)
  34. date := util.Int64All(v["date"])
  35. result[name] = &OwnerMonitor{
  36. Id: BsonIdToSId(v["_id"]),
  37. EntName: name,
  38. CreateTime: date,
  39. }
  40. }
  41. }
  42. return result
  43. }
  44. //匹配
  45. func Match(msl *Mysql, mgoMain, mgoLog *MongodbSim, ui *UserInfo, sl *SortList, isEnt bool, uiSons []*UserInfo) {
  46. if sl == nil {
  47. return
  48. }
  49. userId := ui.Id
  50. if isEnt {
  51. identity := IdentityByEntUserId(msl, int64(ui.Entniche.UserId))
  52. if identity == nil {
  53. logger.Error("没有找到用户身份", ui.Entniche.UserId)
  54. return
  55. }
  56. userId = fmt.Sprint(identity.PositionId)
  57. }
  58. oms := LoadOwnerMonitor(mgoMain, userId)
  59. result := map[string]*OwnerMonitor{}
  60. for _, v := range *sl {
  61. buyer, _ := v.Info["buyer"].(string)
  62. if oms[buyer] == nil {
  63. continue
  64. }
  65. if result[buyer] == nil {
  66. result[buyer] = oms[buyer]
  67. }
  68. _id, _ := v.Info["_id"].(string)
  69. key := fmt.Sprintf("ownermonitor_%s_%s_%s", userId, buyer, _id)
  70. if exists, _ := redis.Exists("pushcache_1", key); exists {
  71. continue
  72. }
  73. redis.Put("pushcache_1", key, 1, ThreeDay)
  74. result[buyer].Infos = append(result[buyer].Infos, v.Info)
  75. }
  76. omis := []*OwnerMonitor{}
  77. for _, v := range result {
  78. omis = append(omis, v)
  79. }
  80. uis := []*UserInfo{ui}
  81. if uiSons != nil && len(uiSons) > 0 {
  82. uis = append(uis, uiSons...)
  83. }
  84. for k, v := range uis {
  85. saveUserId := userId
  86. if k > 0 {
  87. saveUserId = v.Id
  88. }
  89. OwnerMonitorSplit(omis, func(list interface{}) {
  90. mgoLog.Save(Pushspace_temp, map[string]interface{}{
  91. "s_m_openid": v.S_m_openid,
  92. "jpushid": v.Jpushid,
  93. "opushid": v.Opushid,
  94. "appphonetype": v.AppPhoneType,
  95. "userid": saveUserId,
  96. "wxpush": v.PushSet.OwnerMonitor.WxPush,
  97. "apppush": v.PushSet.OwnerMonitor.AppPush,
  98. "mailpush": v.PushSet.OwnerMonitor.MailPush,
  99. "email": v.PushSet.Email,
  100. "list": list,
  101. "timestamp": time.Now().Unix(),
  102. "times": v.PushSet.OwnerMonitor.Times,
  103. "ratemode": v.PushSet.OwnerMonitor.RateMode,
  104. "vipstatus": v.VipStatus,
  105. "memberstatus": v.MemberStatus,
  106. "nichestatus": v.NicheStatus,
  107. })
  108. })
  109. }
  110. logger.Info(userId, "业主监控匹配上", len(result), "个")
  111. }
  112. //
  113. func OwnerMonitorSplit(list []*OwnerMonitor, f func(v interface{})) {
  114. l := len(list)
  115. if l == 0 {
  116. return
  117. }
  118. i := Mgo_ListSize
  119. for {
  120. if l > i {
  121. arr := list[i-Mgo_ListSize : i]
  122. f(&arr)
  123. } else if l > i-Mgo_ListSize {
  124. arr := list[i-Mgo_ListSize:]
  125. f(&arr)
  126. break
  127. }
  128. i += Mgo_ListSize
  129. }
  130. }