|
@@ -15,6 +15,7 @@ from common.db import db_event_management, db_user, db_area, db_emergency_plan
|
|
|
from common.security import valid_access_token
|
|
|
import traceback
|
|
|
from utils import *
|
|
|
+from utils.ry_system_util import *
|
|
|
from datetime import datetime, timedelta
|
|
|
from common.db import db_dict
|
|
|
from urllib.parse import quote
|
|
@@ -30,7 +31,7 @@ router = APIRouter()
|
|
|
|
|
|
|
|
|
|
|
|
-def get_dept_tree(db: Session, dept_id: int, tag_ids: Optional[Set[int]] = None) -> Dict:
|
|
|
+def get_dept_tree(db: Session, dept_id: int=0, tag_ids: Optional[Set[int]] = None) -> Dict:
|
|
|
dept = db.query(SysDept).filter(SysDept.dept_id == dept_id).first()
|
|
|
if not dept:
|
|
|
return None
|
|
@@ -96,20 +97,63 @@ def get_dept_tree(db: Session, dept_id: int, tag_ids: Optional[Set[int]] = None)
|
|
|
|
|
|
return dept_info
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+def get_dept_tree2(db: Session, tag_id: int = None) -> Dict:
|
|
|
+ dept_tree = []
|
|
|
+ def get_user_tags(user_id):
|
|
|
+ user_tags_subquery = db.query(SysUserTag.tag_id).filter(SysUserTag.user_id == user_id).subquery()
|
|
|
+ tags = db.query(SysTag).filter(SysTag.tag_id.in_(user_tags_subquery)).all()
|
|
|
+ return [{"tag_id": tag.tag_id, "tag_name": tag.tag_name} for tag in tags]
|
|
|
+ def build_dept_tree(depts, parent_dept):
|
|
|
+
|
|
|
+ for dept_info in depts:
|
|
|
+ dept = {
|
|
|
+ "uuid":new_guid().replace('-',''),
|
|
|
+ "id": dept_info.dept_id,
|
|
|
+ "label": dept_info.dept_name,
|
|
|
+ "deptType": True
|
|
|
+ }
|
|
|
+ # print(dept_info.dept_id)
|
|
|
+ children = parent_id_get_dept_info(db, dept_info.dept_id)
|
|
|
+ if len(children) > 0:
|
|
|
+ children_depts = build_dept_tree(children, dept)
|
|
|
+ dept["children"] = children_depts
|
|
|
+ users = db.query(SysUser).filter(SysUser.dept_id == dept_info.dept_id).filter(SysUser.del_flag != '2').all()
|
|
|
+ for user_info in users:
|
|
|
+ user = {
|
|
|
+ "uuid": new_guid().replace('-', ''),
|
|
|
+ "id": user_info.user_id,
|
|
|
+ "label": user_info.user_name,
|
|
|
+ "deptType": False,
|
|
|
+ "userTag":get_user_tags(user_info.user_id),
|
|
|
+ "userDept":dept_info.dept_name,
|
|
|
+ "positon":'',
|
|
|
+ "avatar":user_info.avatar
|
|
|
+ }
|
|
|
+ if "children" in dept:
|
|
|
+ dept['children'].append(user)
|
|
|
+ else:
|
|
|
+ dept['children']=[user]
|
|
|
+ dept_tree.append(dept)
|
|
|
+ return dept_tree
|
|
|
+ if tag_id is None:
|
|
|
+ dept_ids = [0]
|
|
|
+ else:
|
|
|
+ dept_ids = db.query(SysDeptTag).filter(SysDeptTag.tag_id == tag_id).all()
|
|
|
+ for dept_id in dept_ids:
|
|
|
+ dept_tree.append( build_dept_tree(parent_id_get_dept_info(db, dept_id), None))
|
|
|
+ return dept_tree
|
|
|
@router.get("/alldepts", response_model=Dict)
|
|
|
-def read_all_depts(db: Session = Depends(get_db), tag_ids: List[int] = Query(None, title="Tag IDs")):
|
|
|
- tag_ids_set = set(tag_ids) if tag_ids else None
|
|
|
- top_level_depts = get_dept_tree(db, 3, tag_ids_set)
|
|
|
- if not top_level_depts:
|
|
|
- raise HTTPException(status_code=404, detail="Department not found")
|
|
|
+def read_all_depts(db: Session = Depends(get_db), tag_id: int= Query(None, title="Tag IDs")):
|
|
|
+ # tag_ids_set = tag_id
|
|
|
+ # top_level_depts = get_dept_tree(db, 3, tag_ids_set)
|
|
|
+ # if not top_level_depts:
|
|
|
+ # raise HTTPException(status_code=404, detail="Department not found")
|
|
|
# return [top_level_depts]
|
|
|
-
|
|
|
+ data = get_dept_tree2(db,tag_id)
|
|
|
return {
|
|
|
"code": 200,
|
|
|
"msg": "成功",
|
|
|
- "data": top_level_depts
|
|
|
+ "data": data
|
|
|
}
|
|
|
|
|
|
|