29 lines
		
	
	
		
			912 B
		
	
	
	
		
			Python
		
	
	
	
			
		
		
	
	
			29 lines
		
	
	
		
			912 B
		
	
	
	
		
			Python
		
	
	
	
from apps.system.models import Dept
 | 
						|
from django.conf import settings
 | 
						|
from apps.third.tapis import dhapis
 | 
						|
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 = {
 | 
						|
            "id": dept.third_info['dh_id'],
 | 
						|
            "parentId": 1,
 | 
						|
            "name": dept.name
 | 
						|
        }
 | 
						|
        dhClient.request(**dhapis['dept_update'], json=data)
 | 
						|
    dhClient.face_bind()
 |