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 @transaction.atomic
def create(self, validated_data): def create(self, validated_data):
instance = super().create(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) HrmService.sync_dahua_employee(ep=instance)
return instance return instance
@ -83,7 +83,6 @@ class EmployeeCreateUpdateSerializer(CustomModelSerializer):
instance.user.is_active = False instance.user.is_active = False
instance.user.save() instance.user.save()
# 同时去除门禁授权 # 同时去除门禁授权
if settings.DAHUA_ENABLED and dhClient:
# 如果是正式员工或相关方且有门禁权限: # 如果是正式员工或相关方且有门禁权限:
now = timezone.now() now = timezone.now()
if instance.type in ['employee', 'remployee']: if instance.type in ['employee', 'remployee']:

View File

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