diff --git a/apps/system/services.py b/apps/system/services.py index 61ac3aaf..d013c970 100644 --- a/apps/system/services.py +++ b/apps/system/services.py @@ -7,22 +7,23 @@ from apps.third.dahua import dhClient def sync_dahua_dept(dept: Dept): # 同步大华部门信息 third_info = dept.third_info - if settings.DAHUA_ENABLED and not third_info.get('dh_id', False): - # 如果dh_id 不存在 - data = { - "parentId": 1, - "name": dept.name, - "service": "ehs" - } - _, res = dhClient.request(**dhapis['dept_create'], json=data) - third_info['dh_id'] = res['id'] - dept.third_info = third_info - dept.save() - elif settings.DAHUA_ENABLED and dept.third_info.get('dh_id', False): - data = { + if settings.DAHUA_ENABLED: + if third_info.get('dh_id', False): + data = { "id": dept.third_info['dh_id'], "parentId": 1, "name": dept.name - } - dhClient.request(**dhapis['dept_update'], json=data) - dhClient.face_bind() + } + dhClient.request(**dhapis['dept_update'], json=data) + else: + # 如果dh_id 不存在 + data = { + "parentId": 1, + "name": dept.name, + "service": "ehs" + } + _, res = dhClient.request(**dhapis['dept_create'], json=data) + third_info['dh_id'] = res['id'] + dept.third_info = third_info + dept.save() + dhClient.face_bind()