优化大版本

This commit is contained in:
27942
2026-01-12 14:58:43 +08:00
parent e787d13f77
commit 4c5cc672f5

View File

@@ -69,6 +69,7 @@ class UserRegister(APIView):
# 从人事管理同步其他数据(如果入职登记未提供)
# 如果提供了card或position则使用提供的值否则使用人事管理中的值
# 团队信息始终从人事管理中获取,不在财务登记中修改
update_fields = []
# 更新必填字段
@@ -94,9 +95,23 @@ class UserRegister(APIView):
# 保存用户信息
user.save(update_fields=update_fields)
# 从人事管理中获取团队信息(团队信息不在财务登记中修改)
team_name = user.team # 用户的团队名称(从人事管理中获取)
team = None
team_type_display = None
if team_name:
try:
from User.models import Team
team = Team.objects.get(name=team_name, is_deleted=False)
team_type_display = team.get_team_type_display()
except Team.DoesNotExist:
# 如果团队不存在,默认按团队类型处理(需要审批)
pass
# 构建审批内容(使用实际的值,包括从人事管理同步的)
actual_card = card if card else (user.card if user.card else '未填写')
actual_position = position if position else (user.position if user.position else '未填写')
actual_team = team_name if team_name else '未分配团队'
today = datetime.datetime.now()
formatted_date = today.strftime("%Y-%m-%d")
@@ -105,17 +120,6 @@ class UserRegister(APIView):
# 规则:
# - 个人团队personal不触发审批
# - 团队team需要审批直接选择某个人来审批
from User.models import Team
# 获取用户的团队信息
team_name = user.team # 用户的团队名称CharField
team = None
if team_name:
try:
team = Team.objects.get(name=team_name, is_deleted=False)
except Team.DoesNotExist:
# 如果团队不存在,默认按团队类型处理(需要审批)
pass
# 判断是否需要审批
if team and team.team_type == 'personal':
@@ -152,9 +156,20 @@ class UserRegister(APIView):
}, status=status.HTTP_404_NOT_FOUND)
# 创建审批记录(直接使用审批人用户名)
# 审批内容包含从人事管理同步的团队信息
content_parts = [
f"{username}{Dateofjoining}办理入职",
f"身份证:{actual_card}",
f"岗位:{actual_position}",
f"团队:{actual_team}"
]
if team_type_display:
content_parts.append(f"团队类型:{team_type_display}")
content_parts.append(f"薪资:{salary}")
Approval.objects.create(
title=username + "入职财务登记",
content=f"{username}{Dateofjoining}办理入职,身份证:{actual_card},岗位:{actual_position},薪资:{salary}",
content="".join(content_parts),
times=formatted_date,
personincharge=personincharge, # 直接使用审批人用户名
state='审核中',
@@ -162,12 +177,14 @@ class UserRegister(APIView):
user_id=str(user.id)
)
# 记录操作日志
# 记录操作日志(包含从人事管理获取的团队信息)
new_data = {
'user_id': user.id,
'username': user.username,
'card': user.card,
'position': user.position,
'team': team_name, # 从人事管理中获取的团队名称
'team_type': team_type_display if team else None, # 团队类型显示名称
'salary': user.salary,
'Dateofjoining': Dateofjoining,
'state': user.state
@@ -181,7 +198,7 @@ class UserRegister(APIView):
target_id=user.id,
target_name=user.username,
new_data=new_data,
remark=f'新增入职财务登记:{user.username},入职时间 {Dateofjoining},薪资 {salary}'
remark=f'新增入职财务登记:{user.username},入职时间 {Dateofjoining},薪资 {salary},团队 {team_name if team_name else "未分配"}'
)
return Response({
@@ -191,8 +208,10 @@ class UserRegister(APIView):
'username': user.username,
'Dateofjoining': Dateofjoining,
'salary': salary,
'card': user.card, # 返回实际使用的身份证(可能来自人事管理)
'position': user.position, # 返回实际使用的岗位(可能来自人事管理)
'card': user.card, # 返回实际使用的身份证(人事管理同步
'position': user.position, # 返回实际使用的岗位(人事管理同步
'team': team_name, # 返回团队名称(从人事管理中获取)
'team_type': team_type_display if team else None, # 返回团队类型(从人事管理中获取)
}
}, status=status.HTTP_200_OK)