feat(system): 添加获取用户递归部门名称功能
- 在 Department模型中添加了 _recursion 类方法,用于递归获取指定属性值 - 新增 get_region_name 类方法,用于获取用户的所有上级部门名称 - 该功能可以用于显示用户所在的完整部门路径
This commit is contained in:
@@ -122,6 +122,27 @@ class Dept(CoreModel):
|
|||||||
help_text="上级部门",
|
help_text="上级部门",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _recursion(cls, instance, parent, result):
|
||||||
|
new_instance = getattr(instance, parent, None)
|
||||||
|
res = []
|
||||||
|
data = getattr(instance, result, None)
|
||||||
|
if data:
|
||||||
|
res.append(data)
|
||||||
|
if new_instance:
|
||||||
|
array = cls._recursion(new_instance, parent, result)
|
||||||
|
res += array
|
||||||
|
return res
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_region_name(cls, obj):
|
||||||
|
"""
|
||||||
|
获取某个用户的递归所有部门名称
|
||||||
|
"""
|
||||||
|
dept_name_all = cls._recursion(obj, "parent", "name")
|
||||||
|
dept_name_all.reverse()
|
||||||
|
return "/".join(dept_name_all)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def recursion_all_dept(cls, dept_id: int, dept_all_list=None, dept_list=None):
|
def recursion_all_dept(cls, dept_id: int, dept_all_list=None, dept_list=None):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user