滞留和离岗代码优化

This commit is contained in:
曹前明 2022-09-21 20:10:17 +08:00
parent 82a3c3178a
commit 32f98cda16
1 changed files with 14 additions and 6 deletions

View File

@ -468,12 +468,20 @@ def loc_change(data):
# 判断停留时间是否合理
# 先通过自定义权限过滤(暂未做)
# 再经过通用设置过滤
code_name = ''
if 0 < stay_minute < area_fix['stay_minute_min']:
# 触发离岗事件
handle_xx_event_2('leave_area', ep=blts.employee, area=Area.objects.get(id=area_fix['id']))
elif area_fix['stay_minute_max'] < stay_minute:
code_name = 'leave_area'
elif area_fix['stay_minute_max'] > 0 and area_fix['stay_minute_max'] < stay_minute:
# 触发超时滞留事件
handle_xx_event_2('stand_area', ep=blts.employee, area=Area.objects.get(id=area_fix['id']))
code_name = 'stand_area'
if code_name: # 2分钟不再次触发
last_event = Event.objects.filter(cates__code=code_name, employee=blts.employee,
handle_user=None).order_by('-create_time').first()
if last_event and last_event.create_time + timedelta(minutes=2) > timezone.now():
pass
else:
handle_xx_event_2(code_name, ep=blts.employee, area=Area.objects.get(id=area_fix['id']))
else:
ep_loc_dict['time1'] = time2
ep_loc_dict['area_fix_id'] = area_fix['id'] if area_fix else None
@ -489,7 +497,7 @@ def handle_xx_event(name: str, data: dict):
# 触发事件
cate = EventCate.objects.filter(code=name).first()
# 找到最近未处理同一人发生的事件
if cate:
if cate: # 5分钟内不再次触发
last_event = Event.objects.filter(cates__code=name, employee=blts.employee,
handle_user=None).order_by('-create_time').first()
if last_event and last_event.create_time + timedelta(minutes=5) > timezone.now():
@ -505,7 +513,7 @@ def handle_xx_event(name: str, data: dict):
else:
area = Area.objects.get(id='1569585234968711168')
event.area = area
event.location = ep_loc_dict['xx_detail']
event.location = ep_loc_dict
event.obj_cate = 'people'
event.employee = blts.employee
event.happen_time = timezone.now()
@ -543,7 +551,7 @@ def handle_xx_event_2(name: str, ep: Employee, area: Area):
key_str = 'ep_{}'.format(ep.id)
ep_loc_dict = cache.get(key_str, None)
if ep_loc_dict:
event.location = ep_loc_dict['xx_detail']
event.location = ep_loc_dict
event.obj_cate = 'people'
event.employee = ep
event.happen_time = timezone.now()