diff --git a/apps/ecm/tasks.py b/apps/ecm/tasks.py index 6cb32ee4..0a4b2ffe 100644 --- a/apps/ecm/tasks.py +++ b/apps/ecm/tasks.py @@ -18,7 +18,10 @@ from django.utils import timezone import time from django.core.cache import cache from django.conf import settings +from apps.utils.tasks import CustomTask + +@shared_task(base=CustomTask) def store_img(code: str, duration: int): while True: global_img = dhClient.snap(code) @@ -40,18 +43,19 @@ def update_count_people(i: Area): _, 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( + for m in blt_list: + macs.append(m['userId']) + count_people = TDevice.objects.filter( type=TDevice.DEVICE_BLT, obj_cate='people', code__in=macs).exclude(employee=None).count() + i.count_people = count_people i.save() - if i.count_people >= i.count_people_max: + if count_people >= i.count_people_max: # 触发超员事件 handle_xx_event_3('over_man', i) - elif i.count_people < i.count_people_min: + elif count_people < i.count_people_min: # 触发缺员事件 handle_xx_event_3('lack_man', i) - return {'count': i.count_people} + return {'count': count_people} def handle_xx_event_3(name: str, area: Area): @@ -75,9 +79,9 @@ 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() - time.sleep(1) + areas = Area.objects.filter(type=Area.AREA_TYPE_FIX) + for i in areas: + update_count_people(i) @shared_task