wcj 5 rokov pred
rodič
commit
66ea52dcfe

+ 9 - 7
src/jfw/modules/entniche/src/entity/department.go

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

+ 4 - 8
src/jfw/modules/entniche/src/service/department/department.go

@@ -51,18 +51,14 @@ func (a *Action) Add() {
 				"createtime": nowFormat,
 				"timestamp":  nowFormat,
 			})
-			var user_role_id int64
-			aid, _ := a.GetInteger("aid")
-			if aid > 0 {
-				user_role_id = Mysql.InsertByTx(tx, Entniche_user_role, map[string]interface{}{
-					"user_id": aid,
-					"role_id": Role_admin_department,
-				})
+			setAdminFlag := true
+			if aid, _ := a.GetInteger("aid"); aid > 0 {
+				setAdminFlag = VarDepartment.SetAdmin(tx, entId, int(dept_id), aid)
 			}
 			dept_parent_id_1 := Mysql.InsertBySqlByTx(tx, `INSERT INTO entniche_department_parent (id,pid)
 				SELECT ? as id,pid from entniche_department_parent where id=?`, dept_id, pid)
 			dept_parent_id_2 := Mysql.InsertBySqlByTx(tx, `INSERT INTO entniche_department_parent (id,pid) values(?,?)`, dept_id, pid)
-			return dept_id > 0 && user_role_id > -1 && dept_parent_id_1 > -1 && dept_parent_id_2 > -1
+			return dept_id > 0 && setAdminFlag && dept_parent_id_1 > -1 && dept_parent_id_2 > -1
 		}) {
 			status = 1
 		} else {