|
@@ -80,14 +80,16 @@ func (d *Department) GetAllUsers(ent_id, dept_id int) *[]*User {
|
|
|
//获取部门下所有子部门和部门下员工
|
|
|
func (d *Department) GetDeptAndUser(ent_id, dept_id int) *[]*Department {
|
|
|
r := Mysql.SelectBySql(`select a.id,a.name,b.user_count,c.dept_count from entniche_department a
|
|
|
- LEFT JOIN (select b.id,count(c.user_id) as user_count from entniche_department b
|
|
|
- INNER JOIN entniche_department_user c on (b.id=c.dept_id)
|
|
|
- where b.ent_id=? and b.pid=? GROUP BY b.id
|
|
|
+ LEFT JOIN (SELECT a.id,count(DISTINCT a.id,c.user_id) as user_count from entniche_department_parent a
|
|
|
+ LEFT JOIN entniche_department_parent b on (a.id=b.pid)
|
|
|
+ INNER JOIN entniche_department_user c on (b.id=c.dept_id or a.id=c.dept_id)
|
|
|
+ where a.pid=? GROUP BY a.id
|
|
|
) b on (a.id=b.id)
|
|
|
- LEFT JOIN (select b.id,count(c.id) as dept_count from entniche_department b
|
|
|
- INNER JOIN entniche_department c on (b.id=c.pid)
|
|
|
- where b.ent_id=? and b.pid=? GROUP BY b.id
|
|
|
- ) c on (a.id=c.id) where a.ent_id=? and a.pid=?`, ent_id, dept_id, ent_id, dept_id, ent_id, dept_id)
|
|
|
+ LEFT JOIN (select a.id,count(b.id) as dept_count from entniche_department a
|
|
|
+ INNER JOIN entniche_department b on (a.id=b.pid)
|
|
|
+ where a.pid=? GROUP BY a.id
|
|
|
+ ) c on (a.id=c.id)
|
|
|
+ where a.ent_id=? and a.pid=? ORDER BY a.id`, dept_id, dept_id, ent_id, dept_id)
|
|
|
departments, _ := JsonUnmarshal(r, &[]*Department{}).(*[]*Department)
|
|
|
if departments == nil {
|
|
|
return &[]*Department{}
|