101 lines
3.4 KiB
Python
101 lines
3.4 KiB
Python
|
|
|
|
from apps.am.models import Access, Area
|
|
from apps.hrm.models import Employee
|
|
from apps.system.models import User
|
|
from apps.third.clients import xxClient
|
|
from apps.third.models import TDevice
|
|
from apps.third.tapis import xxapis
|
|
|
|
|
|
class EcmService:
|
|
"""事件处理服务
|
|
"""
|
|
|
|
def create_remind_and_speak(cls):
|
|
"""
|
|
创建事件提醒并发送短信/微信/音响
|
|
"""
|
|
pass
|
|
|
|
@classmethod
|
|
def dispatch_dahua_event(cls, data: dict):
|
|
"""分发大华事件进行处理
|
|
"""
|
|
pass
|
|
|
|
@classmethod
|
|
def dispatch_xunxi_event(cls, data: dict):
|
|
"""分发寻息事件进行处理
|
|
"""
|
|
if data.type == 'rail':
|
|
if data.data.type == 1:
|
|
# 围栏进入
|
|
cls.rail_in(data=data.data)
|
|
elif data.data.type == 2:
|
|
# 围栏离开
|
|
pass
|
|
elif data.type == 'onKeyAlarm':
|
|
# 一键呼救
|
|
pass
|
|
elif data.type == 'onOffLine':
|
|
if data.data.online:
|
|
# 标签定位在线
|
|
pass
|
|
else:
|
|
# 标签定位离线
|
|
pass
|
|
elif data.type == 'lowpower':
|
|
# 低电量
|
|
pass
|
|
elif data.type == 'bltOnOffLineV2':
|
|
if data.data.online:
|
|
# 标签通信在线
|
|
pass
|
|
else:
|
|
# 标签通信离线
|
|
pass
|
|
|
|
@classmethod
|
|
def rail_in(cls, data):
|
|
"""围栏进入事件
|
|
"""
|
|
# 判断区域是否超员
|
|
area = Area.objects.filter(third_info__xx_rail__id=data['railId']).first()
|
|
# 判断进入对象
|
|
blts = TDevice.objects.filter(code=data['userId']).first()
|
|
if blts and blts.obj_cate == 'employee': # 如果是人
|
|
if area and area.type == Area.AREA_TYPE_FIX: # 如果是固定区域
|
|
json = {"railId": data['railId'], "type": ""}
|
|
_, res = xxClient.request(**xxapis['rail_ibeacon_list'], json=json)
|
|
total_count = res['totalCount']
|
|
if total_count >= area.count_people_max:
|
|
# 触发超员事件
|
|
area.count_people = total_count
|
|
area.save()
|
|
pass
|
|
elif total_count < area.count_people_min:
|
|
# 触发缺员事件
|
|
area.count_people_min = total_count
|
|
area.save()
|
|
pass
|
|
ep_blts = Employee.objects.filter(id=blts.obj).first() # 标签绑定人员
|
|
if ep_blts:
|
|
# 判断有无进入权限 进行匹配
|
|
if ep_blts.type == 'employee' and area.employee_yes:
|
|
return
|
|
elif ep_blts.type == 'remployee' and area.remployee_yes:
|
|
return
|
|
elif ep_blts.type == 'visitor' and area.visitor_yes:
|
|
return
|
|
for i in Access.objects.filter(area=area).order_by('sort'):
|
|
if i.obj_cate == 'employee':
|
|
ep_acess = Employee.objects.filter(id=i.obj).first()
|
|
if ep_blts == ep_acess and i.type == 10:
|
|
return
|
|
elif ep_blts == ep_acess and i.type == 20:
|
|
# 触发非法进入事件
|
|
pass
|
|
else:
|
|
# 触发未知标签进入事件
|
|
pass |