29 lines
		
	
	
		
			918 B
		
	
	
	
		
			Python
		
	
	
	
			
		
		
	
	
			29 lines
		
	
	
		
			918 B
		
	
	
	
		
			Python
		
	
	
	
| from apps.system.models import Dept
 | |
| from django.conf import settings
 | |
| from apps.third.tapis import dhapis
 | |
| 
 | |
| 
 | |
| def sync_dahua_dept(dept: Dept):
 | |
|     # 同步大华部门信息
 | |
|     from apps.third.clients import dhClient
 | |
|     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 = {
 | |
|             "id": dept.third_info['dh_id'],
 | |
|             "parentId": 1,
 | |
|             "name": dept.name
 | |
|         }
 | |
|         dhClient.request(**dhapis['dept_update'], json=data)
 | |
|     dhClient.face_bind()
 |