39 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Python
		
	
	
	
			
		
		
	
	
			39 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Python
		
	
	
	
| from __future__ import absolute_import, unicode_literals
 | |
| from threading import Thread
 | |
| 
 | |
| from celery import shared_task
 | |
| 
 | |
| from apps.am.models import Area
 | |
| from apps.third.clients import xxClient
 | |
| from apps.third.models import TDevice
 | |
| from apps.third.tapis import xxapis
 | |
| 
 | |
| 
 | |
| def update_count_people(i: Area):
 | |
|     if i.third_info.get('xx_rail', None):
 | |
|         railId = i.third_info['xx_rail']['id']
 | |
|         json = {"railId": railId, "type": ""}
 | |
|         _, res = xxClient.request(**xxapis['rail_ibeacon_list'], json=json)
 | |
|         blt_list = res['recordList']
 | |
|         macs = []
 | |
|         for i in blt_list:
 | |
|             macs.append(i['mac'])
 | |
|         i.count_people = TDevice.objects.filter(
 | |
|             type=TDevice.DEVICE_BLT, obj_cate='people', code__in=macs).exclude(employee=None).count()
 | |
|         i.save()
 | |
|         if i.count_people >= i.count_people_max:
 | |
|             # 触发超员事件
 | |
|             pass
 | |
|         elif i.count_people < i.count_people_min:
 | |
|             # 触发缺员事件
 | |
|             pass
 | |
| 
 | |
| 
 | |
| @shared_task
 | |
| def cal_area_count():
 | |
|     """
 | |
|     计算区域内人员数量
 | |
|     """
 | |
|     for i in Area.objects.filter(type=Area.AREA_TYPE_FIX):
 | |
|         Thread(target=update_count_people, args=(i,)).start()
 |