From ffb6ac27209c89713b1677cf61719096382a39bc Mon Sep 17 00:00:00 2001 From: caoqianming Date: Fri, 24 Mar 2023 10:04:57 +0800 Subject: [PATCH] =?UTF-8?q?refector:=20hrm=20sync=20=E5=8A=A0=E5=85=A5dh?= =?UTF-8?q?=20enabled=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/hrm/serializers.py | 35 +++++++++++++++++------------------ apps/hrm/services.py | 3 +++ 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/apps/hrm/serializers.py b/apps/hrm/serializers.py index 43e0b3e9..b03ea3b2 100755 --- a/apps/hrm/serializers.py +++ b/apps/hrm/serializers.py @@ -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 diff --git a/apps/hrm/services.py b/apps/hrm/services.py index 2b981e6f..5a7127f3 100755 --- a/apps/hrm/services.py +++ b/apps/hrm/services.py @@ -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)