计算区域人员数量bug

This commit is contained in:
caoqianming 2022-11-03 15:45:13 +08:00
parent 1bf37aa239
commit 2448406e97
1 changed files with 13 additions and 9 deletions

View File

@ -18,7 +18,10 @@ from django.utils import timezone
import time import time
from django.core.cache import cache from django.core.cache import cache
from django.conf import settings from django.conf import settings
from apps.utils.tasks import CustomTask
@shared_task(base=CustomTask)
def store_img(code: str, duration: int): def store_img(code: str, duration: int):
while True: while True:
global_img = dhClient.snap(code) global_img = dhClient.snap(code)
@ -40,18 +43,19 @@ def update_count_people(i: Area):
_, res = xxClient.request(**xxapis['rail_ibeacon_list'], json=json) _, res = xxClient.request(**xxapis['rail_ibeacon_list'], json=json)
blt_list = res['recordList'] blt_list = res['recordList']
macs = [] macs = []
for i in blt_list: for m in blt_list:
macs.append(i['mac']) macs.append(m['userId'])
i.count_people = TDevice.objects.filter( count_people = TDevice.objects.filter(
type=TDevice.DEVICE_BLT, obj_cate='people', code__in=macs).exclude(employee=None).count() type=TDevice.DEVICE_BLT, obj_cate='people', code__in=macs).exclude(employee=None).count()
i.count_people = count_people
i.save() i.save()
if i.count_people >= i.count_people_max: if count_people >= i.count_people_max:
# 触发超员事件 # 触发超员事件
handle_xx_event_3('over_man', i) 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) 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): 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): areas = Area.objects.filter(type=Area.AREA_TYPE_FIX)
Thread(target=update_count_people, args=(i,), daemon=True).start() for i in areas:
time.sleep(1) update_count_people(i)
@shared_task @shared_task