refector: hrm sync 加入dh enabled判断

This commit is contained in:
caoqianming 2023-03-24 10:04:57 +08:00
parent 7c08b2374f
commit ffb6ac2720
2 changed files with 20 additions and 18 deletions

View File

@ -56,7 +56,7 @@ class EmployeeCreateUpdateSerializer(CustomModelSerializer):
@transaction.atomic
def create(self, validated_data):
instance = super().create(validated_data)
if settings.DAHUA_ENABLED and dhClient and instance.type == 'employee':
if instance.type == 'employee':
# 如果是内部员工
HrmService.sync_dahua_employee(ep=instance)
return instance
@ -83,23 +83,22 @@ class EmployeeCreateUpdateSerializer(CustomModelSerializer):
instance.user.is_active = False
instance.user.save()
# 同时去除门禁授权
if settings.DAHUA_ENABLED and dhClient:
# 如果是正式员工或相关方且有门禁权限:
now = timezone.now()
if instance.type in ['employee', 'remployee']:
start_time = None
end_time = None
if instance.third_info.get('dh_face_card', None) is None and instance.type == 'employee': # 如果是正式员工,给长时间期限
start_time = now
end_time = now + timedelta(days=7300)
if instance.job_state in [20, 30] and old_job_state == 10: # 离职或退休
start_time = now
end_time = now + timedelta(hours=8)
elif instance.job_state == 10 and old_job_state in [20, 30] and instance.type == 'employee': # 正式员工重新在职
start_time = now
end_time = now + timedelta(days=7300)
HrmService.sync_dahua_employee(ep=instance, old_photo=old_photo,
start_time=start_time, end_time=end_time)
# 如果是正式员工或相关方且有门禁权限:
now = timezone.now()
if instance.type in ['employee', 'remployee']:
start_time = None
end_time = None
if instance.third_info.get('dh_face_card', None) is None and instance.type == 'employee': # 如果是正式员工,给长时间期限
start_time = now
end_time = now + timedelta(days=7300)
if instance.job_state in [20, 30] and old_job_state == 10: # 离职或退休
start_time = now
end_time = now + timedelta(hours=8)
elif instance.job_state == 10 and old_job_state in [20, 30] and instance.type == 'employee': # 正式员工重新在职
start_time = now
end_time = now + timedelta(days=7300)
HrmService.sync_dahua_employee(ep=instance, old_photo=old_photo,
start_time=start_time, end_time=end_time)
return instance

View File

@ -11,6 +11,7 @@ from datetime import datetime, timedelta
from django.utils import timezone
from dateutil import tz
from threading import Thread
from django.conf import settings
myLogger = logging.getLogger('log')
@ -28,6 +29,8 @@ class HrmService:
Returns:
_type_: _description_
"""
if not settings.DAHUA_ENABLED: # 如果大华没启用, 直接返回
return
dh_id = ep.third_info.get('dh_id', None)
dh_photo = ep.third_info.get('dh_photo', None)
dh_face_card = ep.third_info.get('dh_face_card', None)