优化待办
This commit is contained in:
@@ -388,15 +388,63 @@ class UnregisteredUserList(APIView):
|
||||
except EmptyPage:
|
||||
users_page = paginator.page(paginator.num_pages)
|
||||
|
||||
# 批量获取所有用户的团队信息,优化查询性能
|
||||
from User.models import Team
|
||||
team_names = [user.team for user in users_page.object_list if user.team]
|
||||
teams_dict = {}
|
||||
if team_names:
|
||||
teams = Team.objects.prefetch_related('approvers').filter(
|
||||
name__in=team_names,
|
||||
is_deleted=False
|
||||
)
|
||||
for team in teams:
|
||||
teams_dict[team.name] = team
|
||||
|
||||
# 批量获取所有用户的待审核入职登记,优化查询性能
|
||||
user_ids = [user.id for user in users_page.object_list]
|
||||
pending_approvals_dict = {}
|
||||
if user_ids:
|
||||
pending_approvals = Approval.objects.filter(
|
||||
type="入职财务登记",
|
||||
user_id__in=[str(uid) for uid in user_ids],
|
||||
state="审核中",
|
||||
is_deleted=False
|
||||
)
|
||||
for approval in pending_approvals:
|
||||
try:
|
||||
user_id = int(approval.user_id)
|
||||
if user_id not in pending_approvals_dict:
|
||||
pending_approvals_dict[user_id] = approval
|
||||
except (ValueError, TypeError):
|
||||
continue
|
||||
|
||||
data = []
|
||||
for user in users_page.object_list:
|
||||
# 检查是否有待审核的入职登记(状态为"审核中")
|
||||
pending_approval = Approval.objects.filter(
|
||||
type="入职财务登记",
|
||||
user_id=str(user.id),
|
||||
state="审核中",
|
||||
is_deleted=False
|
||||
).first()
|
||||
pending_approval = pending_approvals_dict.get(user.id)
|
||||
|
||||
# 获取完整的团队信息
|
||||
team_info = None
|
||||
if user.team:
|
||||
team = teams_dict.get(user.team)
|
||||
if team:
|
||||
team_info = {
|
||||
'id': team.id,
|
||||
'name': team.name,
|
||||
'team_type': team.team_type,
|
||||
'team_type_display': team.get_team_type_display(), # 个人团队/团队
|
||||
'description': team.description,
|
||||
'approvers': list(team.approvers.filter(is_deleted=False).values('id', 'username'))
|
||||
}
|
||||
else:
|
||||
# 如果团队不存在,只返回团队名称
|
||||
team_info = {
|
||||
'name': user.team,
|
||||
'team_type': None,
|
||||
'team_type_display': None,
|
||||
'description': None,
|
||||
'approvers': []
|
||||
}
|
||||
|
||||
data.append({
|
||||
'id': user.id,
|
||||
@@ -407,7 +455,7 @@ class UnregisteredUserList(APIView):
|
||||
'mobilePhone': user.mobilePhone,
|
||||
'department': list(user.department.values('id', 'username')),
|
||||
'role': list(user.role.values('id', 'RoleName', 'permissionId')),
|
||||
'team': user.team,
|
||||
'team': team_info, # 返回完整的团队信息对象
|
||||
'Dateofjoining': user.Dateofjoining.strftime("%Y-%m-%d") if user.Dateofjoining else None,
|
||||
'state': user.state,
|
||||
'has_pending_approval': pending_approval is not None, # 是否有待审核的入职登记
|
||||
|
||||
Reference in New Issue
Block a user