55 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Python
		
	
	
	
			
		
		
	
	
			55 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Python
		
	
	
	
| from __future__ import absolute_import, unicode_literals
 | |
| from multiprocessing import Event
 | |
| 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
 | |
| from django.utils import timezone
 | |
| 
 | |
| 
 | |
| @shared_task
 | |
| 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,), daemon=True).start()
 | |
| 
 | |
| 
 | |
| @shared_task
 | |
| def check_event_timeout():
 | |
|     """判断事件处理是否超期
 | |
|     """
 | |
|     for i in Event.objects.filter(handle_user=None, is_timeout=False):
 | |
|         cate = i.cates.all().order_by('priority', 'create_time').first()
 | |
|         if cate.hanle_minute > 0 and (timezone.now()-i.create_time).seconds > cate.hanle_minute * 60:
 | |
|             i.is_timeout = True
 | |
|             i.save()
 | |
| 
 | |
| 
 |