|
@@ -0,0 +1,126 @@
|
|
|
|
+package ownermonitor
|
|
|
|
+
|
|
|
|
+import (
|
|
|
|
+ "fmt"
|
|
|
|
+ "time"
|
|
|
|
+
|
|
|
|
+ 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
|
|
|
|
+ OwnerMonitor []*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, 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
|
|
|
|
+ }
|
|
|
|
+ result[buyer] = oms[buyer]
|
|
|
|
+ result[buyer].Infos = append(result[buyer].Infos, v.Info)
|
|
|
|
+ }
|
|
|
|
+ omis := []*OwnerMonitor{}
|
|
|
|
+ for _, v := range result {
|
|
|
|
+ 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,
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ logger.Info(userId, "业主监控匹配上", len(result), "个")
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+//
|
|
|
|
+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
|
|
|
|
+ }
|
|
|
|
+}
|