Browse Source

wip:分发查询修改

wangkaiyue 2 years ago
parent
commit
e64842f16e
1 changed files with 9 additions and 3 deletions
  1. 9 3
      jyBXSubscribe/rpc/model/staffSubscribe.go

+ 9 - 3
jyBXSubscribe/rpc/model/staffSubscribe.go

@@ -65,6 +65,11 @@ func GetStaffSubscribeList(entId, entUserId int, query string, eStatus, pStatus,
 	// 加载当前企业所有企业分发数据
 	ruleIds := getEntSubscirbeList(entId, userEnt.Dept.Id, userEnt.Role_admin_system)
 
+	allRule := ""
+	if len(ruleIds) > 0 {
+		allRule = " AND b.rule_id in ('" + strings.Join(ruleIds, "','") + "')"
+	}
+
 	var sql string = ` FROM (
 	SELECT
 		a.id,
@@ -98,7 +103,7 @@ func GetStaffSubscribeList(entId, entUserId int, query string, eStatus, pStatus,
 			INNER JOIN entniche_user u ON ( b.ent_user_id = u.id ) 
 			%s
 		) a
-		LEFT JOIN entniche_user_rule b ON ( a.id = b.user_id ) 
+		LEFT JOIN entniche_user_rule b ON ( a.id = b.user_id %s)
 	GROUP BY
 		a.id,
 		a.NAME,
@@ -107,14 +112,15 @@ func GetStaffSubscribeList(entId, entUserId int, query string, eStatus, pStatus,
 		a.createtime
 ) as AllData 
 WHERE`
+
 	queryArr, valueArr := []string{" 1=1 "}, []interface{}{}
 	nowStr := time.Now().Format(date.Date_Full_Layout)
 	if userEnt.Role_admin_system { //企业管理员
-		sql = fmt.Sprintf(sql, "", "")
+		sql = fmt.Sprintf(sql, "", "", allRule)
 		valueArr = append(valueArr, entId, entId, nowStr)
 	} else { //部门管理员
 		limit := fmt.Sprintf(" INNER JOIN entniche_department_user d ON ( d.user_id = u.id) WHERE d.dept_id =? ")
-		sql = fmt.Sprintf(sql, limit, limit)
+		sql = fmt.Sprintf(sql, limit, limit, allRule)
 		valueArr = append(valueArr, entId, userEnt.Dept.Id, entId, nowStr, userEnt.Dept.Id)
 	}