|
@@ -289,6 +289,94 @@ async def deptTree(request: Request,db: Session = Depends(get_db), user_id: int
|
|
|
"data": result
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+@router.get('/avcon/deptTree')
|
|
|
+async def deptTree(request: Request,label: str = Query(None, description='部门名称'),db: Session = Depends(get_db), user_id: int = Depends(valid_access_token)):
|
|
|
+ def build_dept_tree(depts, parent_dept):
|
|
|
+ dept_tree = []
|
|
|
+ for dept_info in depts:
|
|
|
+ dept = {
|
|
|
+ "id": dept_info.dept_id,
|
|
|
+ "label": dept_info.dept_name,
|
|
|
+ # "parentId": dept_info.parent_id,
|
|
|
+ # "weight": dept_info.order_num
|
|
|
+ }
|
|
|
+ # 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
|
|
|
+ else:
|
|
|
+ dept['isLeaf']=True
|
|
|
+ dept_tree.append(dept)
|
|
|
+ return dept_tree
|
|
|
+
|
|
|
+ # result = []
|
|
|
+ if label:
|
|
|
+ query = db.query(SysDept)
|
|
|
+ query = query.filter(SysDept.del_flag != '2')
|
|
|
+ query = query.filter(SysDept.dept_name.like(f'%{label}%'))
|
|
|
+ # for dept_info in :
|
|
|
+ result=build_dept_tree(query.all(), None)
|
|
|
+ else:
|
|
|
+ result=build_dept_tree(parent_id_get_dept_info(db, 0),None)
|
|
|
+ return {
|
|
|
+ "code": 200,
|
|
|
+ "msg": "操作成功",
|
|
|
+ "data": result
|
|
|
+ }
|
|
|
+
|
|
|
+@router.get('/avcon/list/dept/{dept_id}')
|
|
|
+async def get_dept_user_list(
|
|
|
+ # request: Request,
|
|
|
+ dept_id: int,
|
|
|
+ name: str = Query(None, description='昵称'),
|
|
|
+ db: Session = Depends(get_db),
|
|
|
+ body = Depends(remove_xss_json),
|
|
|
+ user_id = Depends(valid_access_token)
|
|
|
+):
|
|
|
+ query = db.query(SysUser)
|
|
|
+ query = query.filter(SysUser.del_flag != '2')
|
|
|
+
|
|
|
+ def get_dept_chli(dept_list: list, parent_id: int):
|
|
|
+
|
|
|
+ depts = parent_id_get_dept_info(db, parent_id)
|
|
|
+ if depts:
|
|
|
+ for dept in depts:
|
|
|
+ dept_list.append(dept.dept_id)
|
|
|
+ get_dept_chli(dept_list, dept.dept_id)
|
|
|
+ return dept_list
|
|
|
+
|
|
|
+ if dept_id:
|
|
|
+ query = query.filter(SysUser.dept_id.in_(get_dept_chli([], dept_id)))
|
|
|
+
|
|
|
+ if name:
|
|
|
+ query = query.filter(SysUser.nick_name.like(f'%{name}%'))
|
|
|
+
|
|
|
+ user_list = query.all()
|
|
|
+ user_list_dict = []
|
|
|
+ # 将模型实例转换为字典
|
|
|
+ for user in user_list:
|
|
|
+ dept = dept_id_get_ancestors_names(db,dept_id_get_dept_info(db,user.dept_id))
|
|
|
+ roleIds = user_id_get_user_roleIds(db, user_id)
|
|
|
+ user_roles = role_id_list_get_user_role(db,roleIds)
|
|
|
+ dev_id = user_id_get_avcon_dev_id(db, user.user_id)
|
|
|
+ user_list_dict.append({
|
|
|
+ "id": user.user_id,
|
|
|
+ "dept": dept,
|
|
|
+ "name": user.nick_name,
|
|
|
+ "mobile": dev_id,
|
|
|
+ "duty": '/'.join([i["roleName"] for i in user_roles])
|
|
|
+ } )
|
|
|
+
|
|
|
+
|
|
|
+ return {
|
|
|
+ "code": 200,
|
|
|
+ "data": user_list_dict,
|
|
|
+
|
|
|
+ "msg": "操作成功"
|
|
|
+ }
|
|
|
+
|
|
|
# def get_query_params(params: dict):
|
|
|
# return params
|
|
|
# def get_time_params(params: dict = Depends(get_query_params)):
|