Explorar o código

feat:首次默认订阅数据

wangshan %!s(int64=3) %!d(string=hai) anos
pai
achega
f1de14fb24

+ 7 - 8
jyBXSubscribe/rpc/internal/logic/getsublistlogic.go

@@ -2,12 +2,11 @@ package logic
 
 import (
 	"context"
+	"github.com/zeromicro/go-zero/core/logx"
 	IC "jyBXSubscribe/rpc/init"
 	"jyBXSubscribe/rpc/internal/svc"
+	"jyBXSubscribe/rpc/model"
 	"jyBXSubscribe/rpc/type/bxsubscribe"
-	"jyBXSubscribe/rpc/util"
-
-	"github.com/zeromicro/go-zero/core/logx"
 )
 
 type GetSubListLogic struct {
@@ -32,9 +31,9 @@ func (l *GetSubListLogic) GetSubList(in *bxsubscribe.SubscribeInfosReq) (*bxsubs
 	//商机管理 i_entniche_apppushunread=0
 
 	if in.PageNum == 1 {
-		go util.UpdateUserPushUnread(in.UserId, in.UserType)
+		go model.UpdateUserPushUnread(in.UserId, in.UserType)
 	}
-	spqp := &util.SubPushQueryParam{
+	spqp := &model.SubPushQueryParam{
 		Mgo_bidding:   IC.MgoBidding,                      //mongo
 		Bidding:       IC.DB.Mongo.Bidding.Collection,     //招标信息 表
 		Bidding_back:  IC.DB.Mongo.Bidding.CollectionBack, //招标信息备份数据 表名
@@ -62,17 +61,17 @@ func (l *GetSubListLogic) GetSubList(in *bxsubscribe.SubscribeInfosReq) (*bxsubs
 	} else {
 		spqp.PushMysql = IC.PushMysql
 	}
-	hasNextPage, total, list := util.NewSubscribePush(in.UserType).Datas(spqp)
+	hasNextPage, total, list := model.NewSubscribePush(in.UserType).Datas(spqp)
 	/*
 	 *无推送记录生成推送记录
 	 *免费用户默认推送50条
 	 *大会员、新版商机管理、超级订阅用户 默认推送1000条记录
 	 */
 	if in.PageNum == 1 && spqp.IsEmpty() && len(list) == 0 {
-		hasNextPage, total, list = util.NewSubscribePush(in.UserType).DefaultDatas(spqp)
+		hasNextPage, total, list = model.NewSubscribePush(in.UserType).DefaultDatas(spqp)
 	}
 	//查询是否收藏
-	util.NewSubscribePush(in.UserType).MakeCollection(in.UserId, list)
+	model.NewSubscribePush(in.UserType).MakeCollection(in.UserId, list)
 	return &bxsubscribe.SubscribeInfosResp{
 		Data: &bxsubscribe.SubscribeData{
 			List:        list,

+ 3 - 3
jyBXSubscribe/rpc/internal/logic/getsubsomeinfologic.go

@@ -5,7 +5,7 @@ import (
 	"app.yhyue.com/moapp/jybase/redis"
 	"context"
 	IC "jyBXSubscribe/rpc/init"
-	"jyBXSubscribe/rpc/util"
+	"jyBXSubscribe/rpc/model"
 	"time"
 
 	"jyBXSubscribe/rpc/internal/svc"
@@ -33,8 +33,8 @@ func (l *GetSubSomeInfoLogic) GetSubSomeInfo(in *bxsubscribe.SomeInfoReq) (*bxsu
 	resp := &bxsubscribe.SomeInfoResp{
 		Data: &bxsubscribe.SomeInfo{},
 	}
-	user, _ := util.NewSubscribePush(in.UserType).UserInfo(in.UserId)
-	resp.Data.HasKey, resp.Data.Industry = util.GetKeySet(in.UserType, user, []string{})
+	user, _ := model.NewSubscribePush(in.UserType).UserInfo(in.UserId)
+	resp.Data.HasKey, resp.Data.Industry = model.GetKeySet(in.UserType, user, []string{})
 	todayNum := time.Unix(time.Now().Unix(), 1).Format("20060102")
 	if user != nil {
 		//超级订阅

+ 50 - 42
jyBXSubscribe/rpc/util/push.go → jyBXSubscribe/rpc/model/push.go

@@ -1,4 +1,4 @@
-package util
+package model
 
 import (
 	"app.yhyue.com/moapp/jybase/common"
@@ -13,6 +13,7 @@ import (
 	"github.com/zeromicro/go-zero/core/logx"
 	"go.mongodb.org/mongo-driver/bson/primitive"
 	IC "jyBXSubscribe/rpc/init"
+	ms "jyBXSubscribe/rpc/model/service"
 	"jyBXSubscribe/rpc/type/bxsubscribe"
 	"log"
 	"strconv"
@@ -728,6 +729,8 @@ func (s *subscribePush) DefaultDatas(spqp *SubPushQueryParam) (hasNextPage bool,
 	log.Println("userId:", spqp.UserId)
 	//用户信息
 	scd := s.getUserInfo(spqp)
+	logx.Info("获取用户信息耗时:", time.Since(t1))
+	t2 := time.Now()
 	if len(scd.Keyword) > 0 {
 		logx.Info(time.Since(t1), "--scd:", scd)
 		//获取查询语句
@@ -738,9 +741,6 @@ func (s *subscribePush) DefaultDatas(spqp *SubPushQueryParam) (hasNextPage bool,
 			now := time.Now()
 			for _, v := range *list {
 				redisKey := fmt.Sprintf("pushinfo_%s_%s", spqp.UserId, common.ObjToString(v["_id"]))
-				//if isExists, _ := redis.Exists("pushcache_2_a", redisKey); isExists {
-				//	continue
-				//}
 				title := strings.Replace(common.ObjToString(v["title"]), "\n", "", -1)
 				var myInsert = make(map[string]interface{})
 				myInsert["userid"] = spqp.UserId
@@ -806,7 +806,7 @@ func (s *subscribePush) DefaultDatas(spqp *SubPushQueryParam) (hasNextPage bool,
 			}
 		}
 	}
-	logx.Info("请求耗时:", time.Since(t1))
+	logx.Info("请求耗时:", time.Since(t2))
 	hasNextPage = len(result) > pageSize
 	total = int64(len(result))
 	return
@@ -972,12 +972,7 @@ type ViewCondition struct {
 
 //获取用户信息
 func (s *subscribePush) getUserInfo(spqp *SubPushQueryParam) (vc *ViewCondition) {
-	//优先级 由测试确认  大会员 》 商机管理 》 VIP 》 普通用户
-	userMap, ok := IC.Mgo.FindById("user", spqp.UserId, `{"o_jy":1,"o_vipjy":1,"i_vip_status":1,"o_member_jy":1,"i_member_status":1,"s_m_phone":1,"s_phone":1}`)
-	if !ok || userMap == nil || len(*userMap) == 0 {
-		return &ViewCondition{}
-	}
-	var isPayBool = true
+	var isPayBool = false
 	var tmpInfo = struct {
 		Items      []interface{}
 		BuyerClass []interface{}
@@ -985,38 +980,51 @@ func (s *subscribePush) getUserInfo(spqp *SubPushQueryParam) (vc *ViewCondition)
 		Area       map[string]interface{}
 		SelectType string
 	}{}
-	//大会员
-	if common.IntAll((*userMap)["i_member_status"]) > 0 && s.ModuleFlag == "mType" {
-		o_member_jy, _ := (*userMap)["o_member_jy"].(map[string]interface{})
-		tmpInfo.Items, _ = o_member_jy["a_items"].([]interface{})
-		tmpInfo.BuyerClass, _ = o_member_jy["a_buyerclass"].([]interface{})
-		tmpInfo.SubType, _ = o_member_jy["a_infotype"].([]interface{})
-		tmpInfo.Area, _ = o_member_jy["o_area"].(map[string]interface{})
-	} else if phone := common.If((*userMap)["s_phone"] != nil, common.ObjToString((*userMap)["s_phone"]), common.ObjToString((*userMap)["s_m_phone"])).(string); phone != "" && spqp.EntUserId != "" && s.ModuleFlag == "eType" {
-		//新商机管理用户
-		if count := IC.MainMysql.CountBySql(`SELECT count(1) FROM entniche_user u LEFT JOIN entniche_info i ON u.ent_id=i.id WHERE u.phone=? and u.power=1 and i.status=1 and i.isNew=1`, phone); count > 0 {
-			//查询商机管理用户的订阅信息
-			entId, _ := strconv.Atoi(spqp.EntId)
-			entMap, ok := IC.Mgo.FindOneByField("entniche_rule", map[string]interface{}{
-				"i_entid":  entId,
-				"s_userid": spqp.UserId,
-			}, `{"o_entniche":1}`)
-			if ok && entMap != nil && len(*entMap) > 0 {
-				o_entniche, _ := (*entMap)["o_entniche"].(map[string]interface{})
-				tmpInfo.Items, _ = o_entniche["a_items"].([]interface{})
-				tmpInfo.BuyerClass, _ = o_entniche["a_buyerclass"].([]interface{})
-				tmpInfo.SubType, _ = o_entniche["a_infotype"].([]interface{})
-				tmpInfo.Area, _ = o_entniche["o_area"].(map[string]interface{})
-			}
+	switch s.ModuleFlag {
+	case "mType":
+		userMap, ok := IC.Mgo.FindById("user", spqp.UserId, `{"o_member_jy":1,"i_member_status":1}`)
+		if !ok || userMap == nil || len(*userMap) == 0 {
+			return &ViewCondition{}
+		}
+		//大会员
+		if common.IntAll((*userMap)["i_member_status"]) > 0 {
+			isPayBool = true
+			o_member_jy, _ := (*userMap)["o_member_jy"].(map[string]interface{})
+			tmpInfo.Items, _ = o_member_jy["a_items"].([]interface{})
+			tmpInfo.BuyerClass, _ = o_member_jy["a_buyerclass"].([]interface{})
+			tmpInfo.SubType, _ = o_member_jy["a_infotype"].([]interface{})
+			tmpInfo.Area, _ = o_member_jy["o_area"].(map[string]interface{})
+		}
+	case "vType":
+		userMap, ok := IC.Mgo.FindById("user", spqp.UserId, `{"o_vipjy":1,"i_vip_status":1}`)
+		if !ok || userMap == nil || len(*userMap) == 0 {
+			return &ViewCondition{}
+		}
+		if common.IntAll((*userMap)["i_vip_status"]) > 0 {
+			isPayBool = true
+			o_vipjy, _ := (*userMap)["o_vipjy"].(map[string]interface{})
+			tmpInfo.Items, _ = o_vipjy["a_items"].([]interface{})
+			tmpInfo.BuyerClass, _ = o_vipjy["a_buyerclass"].([]interface{})
+			tmpInfo.SubType, _ = o_vipjy["a_infotype"].([]interface{})
+			tmpInfo.Area, _ = o_vipjy["o_area"].(map[string]interface{})
+		}
+	case "eType":
+		//商机管理
+		entUserId, _ := strconv.Atoi(spqp.EntUserId)
+		entId, _ := strconv.Atoi(spqp.EntId)
+		entInfo := (&ms.MatchJob{}).Start(entId, entUserId)
+		if entInfo != nil && len(entInfo) > 0 {
+			isPayBool = true
+			tmpInfo.Items, _ = entInfo["a_items"].([]interface{})
+			tmpInfo.BuyerClass, _ = entInfo["a_buyerclass"].([]interface{})
+			tmpInfo.SubType, _ = entInfo["a_infotype"].([]interface{})
+			tmpInfo.Area, _ = entInfo["o_area"].(map[string]interface{})
+		}
+	default:
+		userMap, ok := IC.Mgo.FindById("user", spqp.UserId, `{"o_jy":1}`)
+		if !ok || userMap == nil || len(*userMap) == 0 {
+			return &ViewCondition{}
 		}
-	} else if common.IntAll((*userMap)["i_vip_status"]) > 0 && s.ModuleFlag == "vType" {
-		o_vipjy, _ := (*userMap)["o_vipjy"].(map[string]interface{})
-		tmpInfo.Items, _ = o_vipjy["a_items"].([]interface{})
-		tmpInfo.BuyerClass, _ = o_vipjy["a_buyerclass"].([]interface{})
-		tmpInfo.SubType, _ = o_vipjy["a_infotype"].([]interface{})
-		tmpInfo.Area, _ = o_vipjy["o_area"].(map[string]interface{})
-	} else {
-		isPayBool = false
 		o_jy, _ := (*userMap)["o_jy"].(map[string]interface{})
 		if o_jy["a_key"] != nil {
 			tmpInfo.Items, _ = o_jy["a_key"].([]interface{})

+ 241 - 0
jyBXSubscribe/rpc/model/service/entity.go

@@ -0,0 +1,241 @@
+package service
+
+import (
+	util "app.yhyue.com/moapp/jybase/common"
+	. "app.yhyue.com/moapp/jybase/mongodb"
+	"app.yhyue.com/moapp/jybase/mysql"
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+func ClearEnt() {
+	Ents = map[int]*Ent{}
+	EntUsers = map[int]*EntUser{}
+	EntUserDept = map[int]*EntDeptUser{}
+	EntDeptUsers = map[int][]*EntDeptUser{}
+	EntRuleUsers = map[string][]*EntRuleUser{}
+	EntUserRules = map[int][]*EntRuleUser{}
+	EntDepts = map[int]*EntDept{}
+	EntParentDept = map[int][]*EntDeptParent{}
+	EntChildDept = map[int][]*EntDeptParent{}
+	EntDeptDis = map[int][]*EntDistribute{}
+}
+
+//
+func InitEnt(mysql *mysql.Mysql, mgo *MongodbSim, dbName string, entId, entUserId int) {
+	InitEnts(mysql, entId)
+	InitEntUsers(mysql, entUserId)
+	InitEntDeptUsers(mysql, entUserId)
+	InitEntRuleUsers(mysql, entUserId)
+	InitEntDepts(mysql, entId)
+	InitEntDeptParents(mysql, entId)
+	InitEntDistribute(mgo, dbName, entId)
+}
+
+///////////////////////
+var Ents = map[int]*Ent{}
+
+type Ent struct {
+	Id         int
+	Model      int
+	Name       string
+	DeptParent map[int][]int
+	IsNew      int
+}
+
+func InitEnts(Mysql *mysql.Mysql, entId int) {
+	list := Mysql.SelectBySql("select id,model,name from entniche_info where id=? and isNew=1 and status=1 and model in (1,2)", entId)
+	if list == nil {
+		return
+	}
+	for _, v := range *list {
+		id := util.IntAll(v["id"])
+		Ents[id] = &Ent{
+			Id:    id,
+			Model: util.IntAll(v["model"]),
+			Name:  util.ObjToString(v["name"]),
+		}
+	}
+	logx.Info("entniche_info加载完成!")
+}
+
+var EntDepts = map[int]*EntDept{}
+
+type EntDept struct {
+	Id     int
+	Pid    int
+	Name   string
+	Nodiff int
+	Subdis int
+}
+
+func InitEntDepts(Mysql *mysql.Mysql, entId int) {
+	list := Mysql.SelectBySql(`select id,name,pid,subdis,nodiff from entniche_department where ent_id=?`, entId)
+	if list == nil {
+		return
+	}
+	for _, v := range *list {
+		id := util.IntAll(v["id"])
+		EntDepts[id] = &EntDept{
+			Id:     id,
+			Pid:    util.IntAll(v["pid"]),
+			Nodiff: util.IntAll(v["nodiff"]),
+			Subdis: util.IntAll(v["subdis"]),
+			Name:   util.ObjToString(v["name"]),
+		}
+	}
+	logx.Info("entniche_department加载完成!")
+}
+
+var EntUsers = map[int]*EntUser{}
+
+type EntUser struct {
+	Id    int
+	Name  string
+	Mail  string
+	Phone string
+	Power int
+}
+
+func InitEntUsers(Mysql *mysql.Mysql, entUserId int) {
+	list := Mysql.SelectBySql(`select id,name,mail,phone,power from entniche_user where id=?`, entUserId)
+	if list == nil {
+		return
+	}
+	for _, v := range *list {
+		id := util.IntAll(v["id"])
+		EntUsers[id] = &EntUser{
+			Id:    id,
+			Name:  util.ObjToString(v["name"]),
+			Mail:  util.ObjToString(v["mail"]),
+			Phone: util.ObjToString(v["phone"]),
+			Power: util.IntAll(v["power"]),
+		}
+	}
+	logx.Info("entniche_user加载完成!")
+}
+
+//我所有的父部门
+var EntParentDept = map[int][]*EntDeptParent{}
+
+//我所有的子部门
+var EntChildDept = map[int][]*EntDeptParent{}
+
+type EntDeptParent struct {
+	Id  int
+	Pid int
+}
+
+func InitEntDeptParents(Mysql *mysql.Mysql, entId int) {
+	list := Mysql.SelectBySql(`select a.id,a.pid from entniche_department_parent a inner join entniche_department b on (a.id=b.id and b.ent_id=?)`, entId)
+	if list == nil {
+		return
+	}
+	for _, v := range *list {
+		id := util.IntAll(v["id"])
+		pid := util.IntAll(v["pid"])
+		EntParentDept[id] = append(EntParentDept[id], &EntDeptParent{
+			Id:  id,
+			Pid: pid,
+		})
+		EntChildDept[pid] = append(EntChildDept[pid], &EntDeptParent{
+			Id:  id,
+			Pid: pid,
+		})
+	}
+	logx.Info("entniche_department_parent加载完成!")
+}
+
+var EntUserDept = map[int]*EntDeptUser{}
+var EntDeptUsers = map[int][]*EntDeptUser{}
+
+type EntDeptUser struct {
+	UserId int
+	DeptId int
+}
+
+func InitEntDeptUsers(Mysql *mysql.Mysql, entUserId int) {
+	list := Mysql.SelectBySql(`select dept_id,user_id from entniche_department_user where user_id=?`, entUserId)
+	if list == nil {
+		return
+	}
+	for _, v := range *list {
+		user_id := util.IntAll(v["user_id"])
+		dept_id := util.IntAll(v["dept_id"])
+		entDeptUser := &EntDeptUser{
+			UserId: user_id,
+			DeptId: dept_id,
+		}
+		EntUserDept[user_id] = entDeptUser
+		EntDeptUsers[dept_id] = append(EntDeptUsers[dept_id], entDeptUser)
+	}
+	logx.Info("entniche_department_user加载完成!")
+}
+
+var EntRuleUsers = map[string][]*EntRuleUser{}
+var EntUserRules = map[int][]*EntRuleUser{}
+
+type EntRuleUser struct {
+	UserId int
+	RuleId string
+}
+
+func InitEntRuleUsers(Mysql *mysql.Mysql, entUserId int) {
+	list := Mysql.SelectBySql(`select user_id,rule_id from entniche_user_rule where user_id=?`, entUserId)
+	if list == nil {
+		return
+	}
+	for _, v := range *list {
+		ruleId := util.ObjToString(v["rule_id"])
+		userId := util.IntAll(v["user_id"])
+		entRuleUser := &EntRuleUser{
+			UserId: userId,
+			RuleId: ruleId,
+		}
+		EntRuleUsers[ruleId] = append(EntRuleUsers[ruleId], entRuleUser)
+		EntUserRules[userId] = append(EntUserRules[userId], entRuleUser)
+	}
+	logx.Info("entniche_user_rule加载完成!")
+}
+
+var EntDeptDis = map[int][]*EntDistribute{}
+
+type EntDistribute struct {
+	Id         string
+	DeptId     int
+	Area       map[string]interface{}
+	Buyerclass []interface{}
+	Items      []string
+}
+
+func InitEntDistribute(mgo *MongodbSim, dbName string, entId int) {
+	sess := mgo.GetMgoConn()
+	defer mgo.DestoryMongoConn(sess)
+	it := sess.DB(dbName).C("entniche_distribute").Find(map[string]interface{}{
+		"i_status": map[string]interface{}{"$ne": 1},
+		"i_entid":  entId,
+	}).Select(map[string]interface{}{
+		"_id":          1,
+		"i_entid":      1,
+		"i_deptid":     1,
+		"a_items":      1,
+		"o_area":       1,
+		"a_buyerclass": 1,
+	}).Iter()
+	for temp := make(map[string]interface{}); it.Next(&temp); {
+		if temp["i_deptid"] == nil {
+			continue
+		}
+		deptId := util.IntAll(temp["i_deptid"])
+		a_items, _ := temp["a_items"].([]interface{})
+		o_area, _ := temp["o_area"].(map[string]interface{})
+		a_buyerclass, _ := temp["a_buyerclass"].([]interface{})
+		EntDeptDis[deptId] = append(EntDeptDis[deptId], &EntDistribute{
+			Id:         BsonIdToSId(temp["_id"]),
+			DeptId:     deptId,
+			Area:       o_area,
+			Buyerclass: a_buyerclass,
+			Items:      util.ObjArrToStringArr(a_items),
+		})
+		temp = make(map[string]interface{})
+	}
+}

+ 265 - 0
jyBXSubscribe/rpc/model/service/matchjob.go

@@ -0,0 +1,265 @@
+package service
+
+import (
+	util "app.yhyue.com/moapp/jybase/common"
+	. "app.yhyue.com/moapp/jybase/mongodb"
+	"app.yhyue.com/moapp/jybase/mysql"
+	"github.com/zeromicro/go-zero/core/logx"
+	IC "jyBXSubscribe/rpc/init"
+)
+
+var Mysql *mysql.Mysql
+var Mgo *MongodbSim
+
+//用户基本信息
+type UserInfo struct {
+	Entniche *Entniche
+	SubSet   map[string]interface{}
+}
+
+//
+type Entniche struct {
+	EntId    int    //企业id
+	EntName  string //企业名称
+	DeptId   int    //部门id
+	DeptName string //部门名称
+	DisId    string //分发id
+	UserId   int
+}
+type MatchJob struct {
+}
+
+func (m *MatchJob) Start(entId, entUserId int) map[string]interface{} {
+	defer util.Catch()
+	defer ClearEnt()
+	InitEnt(IC.MainMysql, &IC.Mgo, "qfw", entId, entUserId)
+	users := m.LoadSubSet(entId)
+	return FinalSub(entUserId, users)
+}
+
+func (m *MatchJob) LoadSubSet(entId int) map[*UserInfo]bool {
+	defer util.Catch()
+	Users := map[*UserInfo]bool{}
+	sess := Mgo.GetMgoConn()
+	defer Mgo.DestoryMongoConn(sess)
+	it := sess.DB("qfw").C("entniche_rule").Find(map[string]interface{}{
+		"i_entid": entId,
+	}).Select(map[string]interface{}{
+		"i_entid":    1,
+		"i_deptid":   1,
+		"i_userid":   1,
+		"o_entniche": 1,
+	}).Iter()
+	for _temp := make(map[string]interface{}); it.Next(&_temp); {
+		func(temp map[string]interface{}) {
+			entId := util.IntAll(temp["i_entid"])
+			deptId := util.IntAll(temp["i_deptid"])
+			userId := util.IntAll(temp["i_userid"])
+			if entId == 0 || (deptId == 0 && userId == 0) {
+				return
+			} else if Ents[entId] == nil {
+				logx.Info("没有找到该企业", entId)
+				return
+			}
+			entName := Ents[entId].Name
+			if deptId > 0 && EntDepts[deptId] == nil {
+				logx.Info("没有找到该部门", entName, entId, deptId)
+				return
+			}
+			deptName := ""
+			if EntDepts[deptId] != nil {
+				deptName = EntDepts[deptId].Name
+			}
+			subSet, _ := temp["o_entniche"].(map[string]interface{})
+			if subSet == nil || len(subSet) == 0 {
+				logx.Info("订阅设置为空,过滤掉", entName, entId, deptName, deptId, userId)
+				return
+			}
+			//
+			if deptId > 0 { //部门订阅
+				if Ents[entId].Model != 1 {
+					logx.Info("不是统一订阅模式,过滤掉", entName, entId, deptName, deptId)
+					return
+				} else if EntDepts[deptId] == nil {
+					logx.Info("没有找到该部门,过滤掉", entName, entId, deptName, deptId)
+					return
+				} else if EntDepts[deptId].Subdis == 0 {
+					logx.Info("该部门的订阅分发没有开启,过滤掉", entName, entId, deptName, deptId)
+					return
+				} else if EntDepts[deptId].Nodiff == 0 && EntDeptDis[deptId] == nil {
+					logx.Info("该部门开启了订阅分发,没有开启全员无差别接收,但是没有分发规则,过滤掉", entName, entId, deptName, deptId)
+					return
+				}
+				//如果我的上级部门打开了订阅分发,并且开启了全员无差别接收,本部门规则无效
+				for _, dept := range EntParentDept[deptId] {
+					if EntDepts[dept.Pid].Subdis == 1 && EntDepts[dept.Pid].Nodiff == 1 {
+						logx.Info("我的上级部门", dept.Pid, "开启了订阅分发和全员无差别,过滤掉", entName, entId, deptName, deptId)
+						return
+					}
+				}
+			} else if userId > 0 { //个人订阅
+				if Ents[entId].Model != 2 {
+					logx.Info("不是个人订阅模式,过滤掉", entName, entId, userId)
+					return
+				} else if EntUsers[userId] == nil {
+					logx.Info("没有找到该用户,过滤掉", entName, entId, userId)
+					return
+				} else if EntUsers[userId].Power == 0 {
+					logx.Info("该用户没有权限,过滤掉", entName, entId, userId)
+					return
+				}
+			}
+			user := &UserInfo{
+				Entniche: &Entniche{
+					EntId:    entId,
+					EntName:  entName,
+					DeptId:   deptId,
+					DeptName: deptName,
+					UserId:   userId,
+				},
+				SubSet: subSet,
+			}
+			logx.Info("加载订阅设置", "entId", entId, "entName", entName, "deptId", deptId, "deptName", deptName, "userId", userId)
+			Users[user] = true
+			if deptId <= 0 {
+				return
+			}
+			//分发规则
+			if EntDepts[deptId].Nodiff == 1 {
+				logx.Info("该部门开启了全员无差别,分发规则无效", entName, entId, deptName, deptId)
+				return
+			} else if EntDeptDis[deptId] == nil {
+				logx.Info("该部门没有分发规则", entName, entId, deptName, deptId)
+				return
+			}
+			itemMap := map[string]interface{}{}
+			items, _ := subSet["a_items"].([]interface{})
+			for _, v := range items {
+				item, _ := v.(map[string]interface{})
+				if item == nil {
+					continue
+				}
+				item_name, _ := item["s_item"].(string)
+				if item_name == "" {
+					continue
+				}
+				itemMap[item_name] = item
+			}
+			for _, dis := range EntDeptDis[deptId] {
+				child_items := []interface{}{}
+				for _, item_name := range dis.Items {
+					if itemMap[item_name] == nil {
+						continue
+					}
+					child_items = append(child_items, itemMap[item_name])
+				}
+				child_subSet := map[string]interface{}{}
+				if len(dis.Buyerclass) > 0 {
+					child_subSet["a_buyerclass"] = dis.Buyerclass
+				}
+				if len(dis.Area) > 0 {
+					child_subSet["o_area"] = dis.Area
+				}
+				if len(child_items) > 0 {
+					child_subSet["a_items"] = child_items
+				}
+				if len(child_subSet) == 0 {
+					continue
+				}
+				child_user := &UserInfo{
+					Entniche: &Entniche{
+						EntId:    user.Entniche.EntId,
+						EntName:  user.Entniche.EntName,
+						DeptId:   user.Entniche.DeptId,
+						DeptName: user.Entniche.DeptName,
+						DisId:    dis.Id,
+					},
+					SubSet: child_subSet,
+				}
+				Users[child_user] = true
+			}
+		}(_temp)
+		_temp = make(map[string]interface{})
+	}
+	return Users
+}
+func FinalSub(entUserId int, users map[*UserInfo]bool) map[string]interface{} {
+	for k, _ := range users {
+		if k.Entniche.DeptId > 0 {
+			k.Entniche.DeptName = EntDepts[k.Entniche.DeptId].Name
+			staffIds := GetDeptUserIds(&UserInfo{
+				Entniche: &Entniche{
+					EntId:    k.Entniche.EntId,
+					EntName:  k.Entniche.EntName,
+					DeptId:   k.Entniche.DeptId,
+					DeptName: k.Entniche.DeptName,
+					DisId:    k.Entniche.DisId,
+				},
+			})
+			if staffIds == nil {
+				continue
+			}
+			if staffIds[entUserId] {
+				return k.SubSet
+			}
+		} else if k.Entniche.UserId > 0 {
+			return k.SubSet
+		} else {
+			continue
+		}
+	}
+	return nil
+}
+func GetDeptUserIds(ui *UserInfo) map[int]bool {
+	if EntDepts[ui.Entniche.DeptId].Subdis == 0 {
+		logx.Info(ui.Entniche.EntName, ui.Entniche.EntId, ui.Entniche.DeptName, ui.Entniche.DeptId, "没有开启订阅分发,过滤掉")
+		return nil
+	} else if EntDepts[ui.Entniche.DeptId].Nodiff == 0 && ui.Entniche.DisId == "" {
+		logx.Info(ui.Entniche.EntName, ui.Entniche.EntId, ui.Entniche.DeptName, ui.Entniche.DeptId, "没有开启全员无差别接收,并且没有分发规则,过滤掉")
+		return nil
+	}
+	//对我的对着生效的用户
+	myIds := map[int]bool{}
+	//打开了全员无差别,下面所有员工都生效
+	if EntDepts[ui.Entniche.DeptId].Nodiff == 1 {
+		for _, v := range EntDeptUsers[ui.Entniche.DeptId] {
+			myIds[v.UserId] = true
+		}
+		for _, v := range EntChildDept[ui.Entniche.DeptId] {
+			for _, vv := range EntDeptUsers[v.Id] {
+				myIds[vv.UserId] = true
+			}
+		}
+		logx.Info(ui.Entniche.EntName, ui.Entniche.EntId, ui.Entniche.DeptName, ui.Entniche.DeptId, "该部门打开了全员无差别", len(myIds), "人接收")
+	} else if ui.Entniche.DisId != "" {
+		for _, v := range EntRuleUsers[ui.Entniche.DisId] {
+			myIds[v.UserId] = true
+		}
+		logx.Info(ui.Entniche.EntName, ui.Entniche.EntId, ui.Entniche.DeptName, ui.Entniche.DeptId, "该规则开启了订阅分发", ui.Entniche.DisId, "规则分发了", len(myIds), "人")
+	}
+	//我的上级部门,过滤掉本部门的人
+	for _, v := range EntParentDept[ui.Entniche.DeptId] {
+		//看我的上级部门,有没有开启订阅分发
+		if EntDepts[v.Pid].Subdis == 0 {
+			continue
+		}
+		//看我的上级部门,有没有全员无差别接收
+		if EntDepts[v.Pid].Nodiff == 1 {
+			logx.Info(ui.Entniche.EntName, ui.Entniche.EntId, ui.Entniche.DeptName, ui.Entniche.DeptId, ui.Entniche.DisId, "上级部门", v.Pid, "打开了全员无差别开关,过滤掉")
+			return nil
+		}
+		//看我的上级部门,有没有对我设置规则
+		for _, vv := range EntDeptDis[v.Pid] {
+			for _, vvv := range EntRuleUsers[vv.Id] {
+				_, ok := myIds[vvv.UserId]
+				if !ok {
+					continue
+				}
+				delete(myIds, vvv.UserId)
+				logx.Info(ui.Entniche.EntName, ui.Entniche.EntId, ui.Entniche.DeptName, ui.Entniche.DeptId, "上级部门", v.Pid, "对我设置的有", vvv.RuleId, "分发规则,此规则作废", vvv.UserId)
+			}
+		}
+	}
+	logx.Info(ui.Entniche.EntName, ui.Entniche.EntId, ui.Entniche.DeptName, ui.Entniche.DeptId, ui.Entniche.DisId, "该规则匹配到", len(myIds), "人")
+	return myIds
+}