30 lines
973 B
Python
30 lines
973 B
Python
from __future__ import absolute_import, unicode_literals
|
|
|
|
from celery import shared_task
|
|
|
|
from apps.am.models import Area
|
|
from apps.third.clients import xxClient
|
|
from apps.third.tapis import xxapis
|
|
|
|
|
|
@shared_task
|
|
def cal_area_count():
|
|
"""
|
|
计算区域内人员数量
|
|
"""
|
|
for i in Area.objects.filter(type=Area.AREA_TYPE_FIX):
|
|
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)
|
|
total_count = res['totalCount']
|
|
if total_count >= i.count_people_max:
|
|
# 触发超员事件
|
|
i.count_people = total_count
|
|
i.save()
|
|
pass
|
|
elif total_count < i.count_people_min:
|
|
# 触发缺员事件
|
|
i.count_people_min = total_count
|
|
i.save()
|
|
pass |