Selaa lähdekoodia

feat:业主监控

wangchuanjin 1 vuosi sitten
vanhempi
commit
8f6d405036
3 muutettua tiedostoa jossa 146 lisäystä ja 31 poistoa
  1. 126 0
      ownermonitor/ownermonitor.go
  2. 20 18
      p/public.go
  3. 0 13
      p/struct.go

+ 126 - 0
ownermonitor/ownermonitor.go

@@ -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
+	}
+}

+ 20 - 18
p/public.go

@@ -440,6 +440,26 @@ func SortListSplit(list *SortList, f func(v interface{})) {
 	}
 	}
 }
 }
 
 
+//
+func CSortListSplit(list *CSortList, 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
+	}
+}
+
 //获取企业授权超级订阅/大会员的用户
 //获取企业授权超级订阅/大会员的用户
 func LoadEntProductUsers(msl *Mysql, testUserIds []int) (map[string]*UserInfo, map[int]*UserInfo, map[int]*UserInfo, []*UserInfo) {
 func LoadEntProductUsers(msl *Mysql, testUserIds []int) (map[string]*UserInfo, map[int]*UserInfo, map[int]*UserInfo, []*UserInfo) {
 	logger.Info("开始加载企业授权用户。。。")
 	logger.Info("开始加载企业授权用户。。。")
@@ -775,21 +795,3 @@ func ResourceCenterPowers(msl *Mysql, positionId int64) map[string]bool {
 	}
 	}
 	return powers
 	return powers
 }
 }
-
-//加载业主监控
-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
-}

+ 0 - 13
p/struct.go

@@ -904,16 +904,3 @@ type BiddingInfo struct {
 	Toptype         string
 	Toptype         string
 	Infotype        string
 	Infotype        string
 }
 }
-
-type OwnerMonitorInfo struct {
-	*UserInfo
-	OwnerMonitor []*OwnerMonitor //关注
-}
-
-//
-type OwnerMonitor struct {
-	Id         string    //关注id
-	EntName    string    //企业名称
-	CreateTime int64     //关注时间
-	Infos      CSortList //匹配上的信息
-}