dispatch xx event
This commit is contained in:
parent
72ee32062f
commit
71da2960a2
|
@ -0,0 +1,23 @@
|
|||
# Generated by Django 3.2.12 on 2022-06-25 00:19
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('am', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='area',
|
||||
name='count_people_max',
|
||||
field=models.PositiveIntegerField(default=1000, verbose_name='最大人员数'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='area',
|
||||
name='count_people_min',
|
||||
field=models.PositiveIntegerField(default=0, verbose_name='最小人员数'),
|
||||
),
|
||||
]
|
|
@ -32,6 +32,8 @@ class Area(CommonBModel):
|
|||
remployee_yes = models.BooleanField('准许相关方人员', default=False)
|
||||
employee_yes = models.BooleanField('准许全部员工', default=True)
|
||||
posts_access = models.ManyToManyField(Post, through='am.access')
|
||||
count_people_min = models.PositiveIntegerField('最小人员数', default=0)
|
||||
count_people_max = models.PositiveIntegerField('最大人员数', default=1000)
|
||||
third_info = models.JSONField('三方信息', default=dict,
|
||||
null=False, blank=True)
|
||||
|
||||
|
|
|
@ -1,24 +1,27 @@
|
|||
|
||||
|
||||
from apps.am.models import Area
|
||||
from apps.third.clients import xxClient
|
||||
from apps.third.tapis import xxapis
|
||||
|
||||
class EcmService:
|
||||
"""事件处理服务
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def dispatch_dahua_event(data:dict):
|
||||
@classmethod
|
||||
def dispatch_dahua_event(cls, data: dict):
|
||||
"""分发大华事件进行处理
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
@staticmethod
|
||||
def dispatch_xunxi_event(data:dict):
|
||||
@classmethod
|
||||
def dispatch_xunxi_event(cls, data: dict):
|
||||
"""分发寻息事件进行处理
|
||||
"""
|
||||
if data.type == 'rail':
|
||||
if data.data.type == 1:
|
||||
# 围栏进入
|
||||
pass
|
||||
cls.rail_in(data=data.data)
|
||||
elif data.data.type == 2:
|
||||
# 围栏离开
|
||||
pass
|
||||
|
@ -35,3 +38,23 @@ class EcmService:
|
|||
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_railId=data['railId']).first()
|
||||
if area:
|
||||
json = {"railId": data['railId'], "type": ""}
|
||||
_, res = xxClient.request(**xxapis['rail_ibeacon_list'], json=json)
|
||||
if res['totalCount'] >= area.count_people_max:
|
||||
# 触发超员事件
|
||||
pass
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from django.db import models
|
||||
from apps.am.models import Area
|
||||
|
||||
import uuid
|
||||
from apps.utils.models import BaseModel
|
||||
|
||||
# Create your models here.
|
||||
|
@ -40,3 +40,20 @@ class TDevice(BaseModel):
|
|||
is_clock = models.BooleanField('是否打卡设备', default=False)
|
||||
third_info = models.JSONField('三方信息', default=dict,
|
||||
null=False, blank=True)
|
||||
|
||||
|
||||
class Tlog(BaseModel):
|
||||
"""第三方请求与处理日志
|
||||
"""
|
||||
id = models.UUIDField(primary_key=True, default=uuid.uuid4)
|
||||
result_type = models.PositiveSmallIntegerField('结果类型',
|
||||
default=10,
|
||||
help_text='10成功20失败30错误')
|
||||
result = models.JSONField(null=True, blank=True)
|
||||
request_method = models.CharField(max_length=10)
|
||||
request_url = models.TextField(null=True, blank=True)
|
||||
request_params = models.JSONField(null=True, blank=True)
|
||||
request_json = models.JSONField(null=True, blank=True)
|
||||
bind_my_request = models.CharField('关联用户请求ID',
|
||||
max_length=50,
|
||||
null=True, blank=True)
|
||||
|
|
|
@ -97,11 +97,15 @@ xxapis = {
|
|||
"method": "post"
|
||||
},
|
||||
"rail_create": {
|
||||
"url": '/api/railsV2/add',
|
||||
"url": "/api/railsV2/add",
|
||||
"method": "post"
|
||||
},
|
||||
"rail_update": {
|
||||
"url": '/api/railsV2/edit',
|
||||
"url": "/api/railsV2/edit",
|
||||
"method": "post"
|
||||
},
|
||||
"rail_ibeacon_list": {
|
||||
"url": "/WebLocate/locateByRail",
|
||||
"method": "post"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -208,7 +208,7 @@ class DhCommonViewSet(CreateModelMixin, CustomGenericViewSet):
|
|||
|
||||
@action(methods=['post'], detail=False,
|
||||
authentication_classes=[], permission_classes=[],
|
||||
serializer_class=serializers.Serializer)
|
||||
serializer_class=serializers.Serializer, logging_methods=[]) # 不记录日志
|
||||
def mq(self, request, pk=None):
|
||||
"""大华事件处理
|
||||
|
||||
|
|
|
@ -77,8 +77,8 @@ class XxClient:
|
|||
else:
|
||||
r = getattr(requests, method)('{}{}'.format(settings.XX_BASE_URL, url),
|
||||
params=params, json=json, timeout=timeout, verify=False)
|
||||
if settings.DEBUG:
|
||||
print_roundtrip(r)
|
||||
# if settings.DEBUG:
|
||||
# print_roundtrip(r)
|
||||
ret = r.json()
|
||||
if ret.get('errorCode') == '1060000':
|
||||
self.get_token() # 重新获取token
|
||||
|
|
Loading…
Reference in New Issue