增加是否超时字段

This commit is contained in:
曹前明 2022-07-02 10:26:57 +08:00
parent a08500ab8c
commit fc0ce469e3
9 changed files with 83 additions and 22 deletions

View File

@ -7,6 +7,7 @@ from rest_framework import serializers
from apps.third.clients import xxClient from apps.third.clients import xxClient
from apps.third.tapis import xxapis from apps.third.tapis import xxapis
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework.exceptions import ParseError
from rest_framework.mixins import ListModelMixin, CreateModelMixin, DestroyModelMixin from rest_framework.mixins import ListModelMixin, CreateModelMixin, DestroyModelMixin

View File

@ -60,3 +60,14 @@ xx = {'id': 1656652947266,
'infoArray': None, 'infoArray': None,
'protocol': None} 'protocol': None}
print(json.dumps(xx)) print(json.dumps(xx))
{'id': 1656727743278,
'category': 'alarm',
'method': 'alarm.msg',
'info':
{'orgName': '根节点',
'nodeCode': '1000038$1$0$0',
'deviceCode': '1000038',
'alarmCode': '37f2b363-71aa-49c4-b352-711f4e098f46',
'alarmPicture': '6ad010cf-ce45-11ec-9715-e4246c7d1635/20220622/1/dsf_453810dc-f202-11ec-bd2d-e4246c7d1635_60524172_60587111.jpg', 'nodeType': 2, 'alarmDate': '1656727743', 'alarmGrade': 2, 'isSave': True, 'extend': {'faceImageUrl': ['6ad010cf-ce45-11ec-9715-e4246c7d1635/20220622/1/dsf_453810dc-f202-11ec-bd2d-e4246c7d1635_60524172_60587111.jpg'], 'glass': 0, 'beard': 0, 'candidateInfo': [], 'sex': 0, 'occurrenceCount': 0, 'deviceCode': '1000038', 'globalScenePicUrl': '6ad010cf-ce45-11ec-9715-e4246c7d1635/20220622/1/dsf_453810dc-f202-11ec-bd2d-e4246c7d1635_60425203_60524172.jpg', 'eye': 0, 'alarmType': 1001000, 'perFlag': -1, 'mouth': 0, 'feature': [], 'isHit': True, 'channelSeq': 0, 'szSerialUUID': '', 'channelName': '测试摄像头1', 'beginTime': 1656727739, 'endTime': 1656727739, 'age': -1, 'mask': 0}, 'unitType': 1, 'alarmType': 1001000, 'channelSeq': 0, 'orgCode': '001', 'channelName': '测试摄像头1', 'alarmStat': 1, 'isEvent': True}, 'subsystem': 'evo-face', 'userIds': None, 'sid': None, 'domainId': None, 'infoArray': None, 'protocol': None}

View File

@ -0,0 +1,32 @@
# Generated by Django 3.2.12 on 2022-07-02 02:25
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('ecm', '0003_alter_algochannel_unique_together'),
]
operations = [
migrations.RemoveField(
model_name='event',
name='imgs',
),
migrations.AddField(
model_name='event',
name='face_img',
field=models.CharField(blank=True, max_length=1000, null=True, verbose_name='人脸照'),
),
migrations.AddField(
model_name='event',
name='global_img',
field=models.CharField(blank=True, max_length=1000, null=True, verbose_name='全景照'),
),
migrations.AddField(
model_name='event',
name='is_timeout',
field=models.BooleanField(default=False, verbose_name='是否超时'),
),
]

View File

@ -86,6 +86,7 @@ class Event(CommonBModel):
on_delete=models.CASCADE, null=True, blank=True) on_delete=models.CASCADE, null=True, blank=True)
msg = models.TextField('事件文本', null=True, blank=True) msg = models.TextField('事件文本', null=True, blank=True)
voice = models.TextField('语音地址', null=True, blank=True) voice = models.TextField('语音地址', null=True, blank=True)
is_timeout = models.BooleanField('是否超时', default=False)
mark = models.PositiveSmallIntegerField('事件标记', default=10, help_text='10(正常)/20(误报)') mark = models.PositiveSmallIntegerField('事件标记', default=10, help_text='10(正常)/20(误报)')
handle_time = models.DateTimeField('处理时间', null=True, blank=True) handle_time = models.DateTimeField('处理时间', null=True, blank=True)
handle_user = models.ForeignKey(User, verbose_name='处理人', handle_user = models.ForeignKey(User, verbose_name='处理人',

View File

@ -3,7 +3,7 @@
import requests import requests
from apps.am.models import Access, Area from apps.am.models import Access, Area
from apps.am.tasks import cache_areas_info from apps.am.tasks import cache_areas_info
from apps.ecm.models import EventCate from apps.ecm.models import Event, EventCate
from apps.hrm.models import Employee from apps.hrm.models import Employee
from apps.system.models import User from apps.system.models import User
from apps.third.clients import xxClient from apps.third.clients import xxClient
@ -14,6 +14,10 @@ from django.core.cache import cache
import time import time
import shapely.geometry import shapely.geometry
from apps.third.clients import dhClient from apps.third.clients import dhClient
from django.utils import timezone
from django.conf import settings
import os
requests.packages.urllib3.disable_warnings()
def get_area_info_from_cache(target: str, cache: list): def get_area_info_from_cache(target: str, cache: list):
@ -22,13 +26,21 @@ def get_area_info_from_cache(target: str, cache: list):
return i return i
return None return None
# def save_dahua_pic(pic:str):
# """保存大华报警图片到本地 def save_dahua_pic(pic: str):
# 返回本地路径 """保存大华报警图片到本地
# """ 返回本地路径
# full_url = dhClient.get_full_pic(pic) """
# res = requests.get(url=full_url) file_name = pic.split('/')[-1]
# file_path = idwo full_url = dhClient.get_full_pic(pic)
res = requests.get(url=full_url, verify=False)
path = '/media/' + timezone.now().strftime('%Y/%m/%d/')
full_path = settings.BASE_DIR + path
if not os.path.exists(full_path):
os.makedirs(full_path)
with open(full_path + file_name, 'wb') as f:
f.write(res.content)
return path + file_name
class EcmService: class EcmService:
@ -57,15 +69,23 @@ class EcmService:
vchannel_code = data['info']['nodeCode'] vchannel_code = data['info']['nodeCode']
alarm_type = data['info']['alarmType'] alarm_type = data['info']['alarmType']
vchannel = TDevice.objects.filter(code=vchannel_code).first() vchannel = TDevice.objects.filter(code=vchannel_code).first()
if alarm_type == 1001003 and vchannel: # 内部人员报警 print(data)
if alarm_type in [1001003, 1001000] and vchannel: # 内部人员报警
# 加载算法逻辑 # 加载算法逻辑
# 安全帽检测 # 安全帽检测
ec = EventCate.objects.filter(code='helmet').first() ec = EventCate.objects.filter(code='helmet').first() # 模拟发生安全帽事件
# 视频区域 # 视频区域
area = vchannel.area area = vchannel.area
if ec and area: if ec and area:
# 保存照片 # 保存照片
pass face_img = save_dahua_pic(data['info']['alarmPicture'])
global_img = save_dahua_pic(data['info']['extend']['globalScenePicUrl'])
event = Event()
event.face_img = face_img
event.global_img = global_img
event.area = area
event.obj_cate = 'people'
event.employee = None
@classmethod @classmethod
def dispatch_xunxi_event(cls, data: dict): def dispatch_xunxi_event(cls, data: dict):

View File

@ -25,7 +25,7 @@ class TDevice(BaseModel):
(DEVICE_IBEACON, '定位信标'), (DEVICE_IBEACON, '定位信标'),
(DEVICE_BLT, '定位标签'), (DEVICE_BLT, '定位标签'),
(DEVICE_AOA, 'aoa引擎'), (DEVICE_AOA, 'aoa引擎'),
(DEVICE_SPEAKER, '音响'), (DEVICE_SPEAKER, '喇叭'),
(DEVICE_VCHANNEL, '视频通道'), (DEVICE_VCHANNEL, '视频通道'),
(DEVICE_DCHANNEL, '闸机通道'), (DEVICE_DCHANNEL, '闸机通道'),
(DEVICE_PANEL, '面板机') (DEVICE_PANEL, '面板机')

View File

@ -246,7 +246,6 @@ class DhCommonViewSet(CreateModelMixin, CustomGenericViewSet):
method = data['method'] method = data['method']
category = data['category'] category = data['category']
subsystem = data.get('subsystem', None) subsystem = data.get('subsystem', None)
print(data)
# info = data.get('info', {}) # info = data.get('info', {})
if method == 'department.update': if method == 'department.update':
pass pass
@ -257,9 +256,9 @@ class DhCommonViewSet(CreateModelMixin, CustomGenericViewSet):
刷卡事件 刷卡事件
""" """
HrmService.swipe(data=data) HrmService.swipe(data=data)
elif category == 'alarm' and subsystem == 'admin': elif category == 'alarm':
""" """
视频报警 其他报警转到事件派发
""" """
EcmService.dispatch_dahua_event(data=data) EcmService.dispatch_dahua_event(data=data)
return Response() return Response()

View File

@ -115,15 +115,13 @@ class MyLoggingMixin(object):
response = super().finalize_response( response = super().finalize_response(
request, response, *args, **kwargs request, response, *args, **kwargs
) )
# Ensure backward compatibility for those using _should_log hook # Ensure backward compatibility for those using _should_log hook
should_log = ( should_log = (
self._should_log if hasattr(self, "_should_log") else self.should_log self._should_log if hasattr(self, "_should_log") else self.should_log
) )
if should_log(request, response): if should_log(request, response):
if (connection.settings_dict.get("ATOMIC_REQUESTS") and if (connection.settings_dict.get("ATOMIC_REQUESTS") and
getattr(response, "exception", None) and connection.in_atomic_block): getattr(response, "exception", None) and connection.in_atomic_block):
# response with exception (HTTP status like: 401, 404, etc) # response with exception (HTTP status like: 401, 404, etc)
# pointwise disable atomic block for handle log (TransactionManagementError) # pointwise disable atomic block for handle log (TransactionManagementError)
connection.set_rollback(True) connection.set_rollback(True)
@ -238,9 +236,8 @@ class MyLoggingMixin(object):
Method that should return a value that evaluated to True if the request should be logged. Method that should return a value that evaluated to True if the request should be logged.
By default, check if the request method is in logging_methods. By default, check if the request method is in logging_methods.
""" """
return ( return self.logging_methods == "__all__" or response.status_code > 404 or response.status_code == 400 \
self.logging_methods == "__all__" or request.method in self.logging_methods or (request.method in self.logging_methods and response.status_code not in [401, 403, 404])
) and (response.status_code not in [401, 403, 404])
def _clean_data(self, data): def _clean_data(self, data):
""" """

View File

@ -268,7 +268,7 @@ SWAGGER_SETTINGS = {
LOG_PATH = os.path.join(BASE_DIR, 'log') LOG_PATH = os.path.join(BASE_DIR, 'log')
# 如果地址不存在则自动创建log文件夹 # 如果地址不存在则自动创建log文件夹
if not os.path.exists(os.path.join(LOG_PATH)): if not os.path.exists(os.path.join(LOG_PATH)):
os.mkdir(LOG_PATH) os.makedirs(LOG_PATH)
LOGGING = { LOGGING = {
'version': 1, 'version': 1,