123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- package ownermonitor
- import (
- "fmt"
- "strings"
- "time"
- "app.yhyue.com/moapp/jybase/redis"
- util "app.yhyue.com/moapp/jybase/common"
- "app.yhyue.com/moapp/jybase/logger"
- . "app.yhyue.com/moapp/jybase/mongodb"
- . "app.yhyue.com/moapp/jybase/mysql"
- . "bp.jydev.jianyu360.cn/BaseService/pushpkg/p"
- . "bp.jydev.jianyu360.cn/BaseService/userCenter/identity"
- )
- const (
- Pushspace_temp = "pushspace_ownermonitor_temp"
- )
- type OwnerMonitorInfo struct {
- *UserInfo
- OwnerMonitors []*OwnerMonitor //关注
- }
- //
- type OwnerMonitor struct {
- Id string //关注id
- EntName string //企业名称
- CreateTime int64 //关注时间
- Infos CSortList //匹配上的信息
- }
- //加载业主监控
- func LoadOwnerMonitor(mgo *MongodbSim, userId string) map[string]*OwnerMonitor {
- result := map[string]*OwnerMonitor{}
- list, _ := mgo.Find("follow_customer", map[string]interface{}{"userId": userId}, nil, `{"_id":1,"name":1,"date":1}`, false, -1, -1)
- if list != nil {
- for _, v := range *list {
- name, _ := v["name"].(string)
- date := util.Int64All(v["date"])
- result[name] = &OwnerMonitor{
- Id: BsonIdToSId(v["_id"]),
- EntName: name,
- CreateTime: date,
- }
- }
- }
- return result
- }
- //匹配
- func Match(msl *Mysql, mgoMain, mgoLog *MongodbSim, ui *UserInfo, sl *SortList, isEnt bool, uiSons []*UserInfo) {
- if sl == nil {
- return
- }
- userId := ui.Id
- if isEnt {
- identity := IdentityByEntUserId(msl, mgoMain, int64(ui.Entniche.UserId))
- if identity == nil {
- logger.Error("没有找到用户身份", ui.Entniche.UserId)
- return
- }
- userId = fmt.Sprint(identity.PositionId)
- }
- oms := LoadOwnerMonitor(mgoMain, userId)
- result := map[string]*OwnerMonitor{}
- for _, v := range *sl {
- buyer, _ := v.Info["buyer"].(string)
- if oms[buyer] == nil {
- continue
- }
- _id, _ := v.Info["_id"].(string)
- key := fmt.Sprintf("ownermonitor_%s_%s_%s", userId, buyer, _id)
- if exists, _ := redis.Exists("pushcache_1", key); exists {
- continue
- }
- if result[buyer] == nil {
- result[buyer] = oms[buyer]
- }
- redis.Put("pushcache_1", key, 1, ThreeDay)
- result[buyer].Infos = append(result[buyer].Infos, v.Info)
- }
- omis := []*OwnerMonitor{}
- matchBuyers := []string{}
- for k, v := range result {
- matchBuyers = append(matchBuyers, k)
- omis = append(omis, v)
- }
- uis := []*UserInfo{ui}
- if uiSons != nil && len(uiSons) > 0 {
- uis = append(uis, uiSons...)
- }
- for k, v := range uis {
- saveUserId := userId
- if k > 0 {
- saveUserId = v.Id
- }
- OwnerMonitorSplit(omis, func(list interface{}) {
- mgoLog.Save(Pushspace_temp, map[string]interface{}{
- "s_m_openid": v.S_m_openid,
- "jpushid": v.Jpushid,
- "opushid": v.Opushid,
- "appphonetype": v.AppPhoneType,
- "userid": saveUserId,
- "wxpush": v.PushSet.OwnerMonitor.WxPush,
- "apppush": v.PushSet.OwnerMonitor.AppPush,
- "mailpush": v.PushSet.OwnerMonitor.MailPush,
- "email": v.PushSet.Email,
- "list": list,
- "timestamp": time.Now().Unix(),
- "times": v.PushSet.OwnerMonitor.Times,
- "ratemode": v.PushSet.OwnerMonitor.RateMode,
- "vipstatus": v.VipStatus,
- "memberstatus": v.MemberStatus,
- "nichestatus": v.NicheStatus,
- })
- })
- }
- logger.Info(userId, "业主监控匹配上", len(result), "个", strings.Join(matchBuyers, ","))
- }
- //
- func OwnerMonitorSplit(list []*OwnerMonitor, f func(v interface{})) {
- l := len(list)
- if l == 0 {
- return
- }
- i := Mgo_ListSize
- for {
- if l > i {
- arr := list[i-Mgo_ListSize : i]
- f(&arr)
- } else if l > i-Mgo_ListSize {
- arr := list[i-Mgo_ListSize:]
- f(&arr)
- break
- }
- i += Mgo_ListSize
- }
- }
|