Browse Source

feat:分发人员区分

duxin 2 years ago
parent
commit
0c5062c971

+ 13 - 1
jyBXSubscribe/rpc/internal/logic/getdistributorlogic.go

@@ -30,9 +30,21 @@ func NewGetDistributorLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge
 func (l *GetDistributorLogic) GetDistributor(in *bxsubscribe.GetDistributorReq) (*bxsubscribe.DistributorResp, error) {
 	// todo: add your logic here and delete this line
 	da := new(bxsubscribe.DistributorResp)
-	users := model.Distributor(strings.Split(in.Region, ","), common.IntAll(in.EntId), common.IntAll(in.EntUserId))
+	var (
+		users []*model.User
+	)
+	//搜索分发人员
+	if in.SelectIds == "1" {
+		users = model.AllDistributor(common.IntAll(in.EntId), common.IntAll(in.EntUserId))
+	} else {
+		//手动分发人员
+		users = model.Distributor(strings.Split(in.Region, ","), common.IntAll(in.EntId), common.IntAll(in.EntUserId))
+	}
 	if len(users) > 0 {
 		for _, v := range users {
+			if v.Id == common.IntAll(in.EntUserId) {
+				continue
+			}
 			var data bxsubscribe.UserResp
 			data.Id = common.Int64All(v.Id)
 			data.Name = v.Name

+ 12 - 0
jyBXSubscribe/rpc/model/distributor.go

@@ -6,6 +6,18 @@ import (
 	"strings"
 )
 
+func AllDistributor(entId, entUserId int) []*User {
+	var (
+		users []*User
+	)
+	entInfo := EntInfo(entId, entUserId)
+	if entInfo.Role_admin_department {
+		users = *GetDisUsers(entId, entInfo.Dept.Id)
+	} else if entInfo.Role_admin_system {
+		users = *GetEntUsers(entId)
+	}
+	return users
+}
 func Distributor(region []string, entId, entUserId int) []*User {
 	var (
 		ss, users []*User

+ 7 - 8
jyBXSubscribe/rpc/model/push.go

@@ -378,15 +378,14 @@ func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, en
 			}
 			//判断是企业管理员还是部门管理员 部门管理员获取所有子部门
 			userEnt := EntInfo(common.IntAll(spqp.EntId), common.IntAll(spqp.EntUserId))
-			if userEnt.Role_admin_department { //部门管理员 获取所有子部门
-				var deptIds []string
-				r := IC.MainMysql.SelectBySql(`select DISTINCT b.* from entniche_department_parent a 
-	INNER JOIN entniche_department b on (b.ent_id=? and (b.id=? or (a.pid=? and a.id=b.id)))`, spqp.EntId, userEnt.Dept.Id, userEnt.Dept.Id)
-				if r != nil && len(*r) > 0 {
-					for _, v := range *r {
-						deptIds = append(deptIds, common.InterfaceToStr(v["id"]))
+			if userEnt.Role_admin_department { //部门管理员 获取所有部门和子部门员工
+				users := GetDisUsers(common.IntAll(spqp.EntId), userEnt.Dept.Id)
+				var userIds []string
+				if users != nil && len(*users) > 0 {
+					for _, v := range *users {
+						userIds = append(userIds, common.InterfaceToStr(v.Id))
 					}
-					userStr += fmt.Sprintf(" a.deptid in (%s)  ", strings.Join(deptIds, ","))
+					userStr += fmt.Sprintf(" a.userid in (%s)  ", strings.Join(userIds, ","))
 				}
 			}
 		} else {