event serializer优化
This commit is contained in:
parent
a815e7524f
commit
a0f11e8af7
|
|
@ -86,7 +86,7 @@ class Event(CommonBDModel):
|
||||||
vchannel = models.ForeignKey(TDevice, verbose_name='抓拍设备', on_delete=models.SET_NULL, null=True, blank=True)
|
vchannel = models.ForeignKey(TDevice, verbose_name='抓拍设备', on_delete=models.SET_NULL, null=True, blank=True)
|
||||||
location = models.JSONField('事件点位坐标', default=dict, null=False, blank=True)
|
location = models.JSONField('事件点位坐标', default=dict, null=False, blank=True)
|
||||||
opl = models.ForeignKey(Opl, verbose_name='关联许可证', on_delete=models.SET_NULL, null=True, blank=True)
|
opl = models.ForeignKey(Opl, verbose_name='关联许可证', on_delete=models.SET_NULL, null=True, blank=True)
|
||||||
obj_cate = models.CharField('发生对象', max_length=20, help_text='people(人员)/...')
|
obj_cate = models.CharField('发生对象', max_length=20, help_text='people(人员)/opl(作业)/other(其他)...')
|
||||||
employee = models.ForeignKey(Employee, verbose_name='当事人',
|
employee = models.ForeignKey(Employee, verbose_name='当事人',
|
||||||
on_delete=models.SET_NULL, null=True, blank=True)
|
on_delete=models.SET_NULL, null=True, blank=True)
|
||||||
msg = models.TextField('事件文本', null=True, blank=True)
|
msg = models.TextField('事件文本', null=True, blank=True)
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ from rest_framework import serializers
|
||||||
from apps.system.serializers import UserSimpleSerializer
|
from apps.system.serializers import UserSimpleSerializer
|
||||||
from apps.utils.constants import EXCLUDE_FIELDS
|
from apps.utils.constants import EXCLUDE_FIELDS
|
||||||
from rest_framework.exceptions import ParseError
|
from rest_framework.exceptions import ParseError
|
||||||
from apps.hrm.serializers import EmployeeSerializer
|
from apps.hrm.serializers import EmployeeSerializer, EmployeeSimpleSerializer
|
||||||
|
|
||||||
|
|
||||||
class EventCateCreateUpdateSerializer(CustomModelSerializer):
|
class EventCateCreateUpdateSerializer(CustomModelSerializer):
|
||||||
|
|
@ -75,9 +75,26 @@ class NotifySettingsSerializer(CustomModelSerializer):
|
||||||
|
|
||||||
|
|
||||||
class EventSerializer(serializers.ModelSerializer):
|
class EventSerializer(serializers.ModelSerializer):
|
||||||
|
area_ = AreaSerializer(source='area', read_only=True)
|
||||||
|
cates_ = EventCateSimpleSerializer(source='cates', read_only=True, many=True)
|
||||||
|
employee_ = EmployeeSimpleSerializer(source='employee', read_only=True)
|
||||||
|
operation_name = serializers.CharField(source='opl.operation.name', read_only=True)
|
||||||
|
vchannel_ = TDeviceSimpleSerializer(source='vchannel', read_only=True)
|
||||||
|
handle_user_name = serializers.CharField(source='handle_user.name', read_only=True)
|
||||||
|
face_img_f = MyFilePathField(source='face_img', read_only=True)
|
||||||
|
global_img_f = MyFilePathField(source='global_img', read_only=True)
|
||||||
|
voice_f = MyFilePathField(source='voice', read_only=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Event
|
||||||
|
fields = '__all__'
|
||||||
|
|
||||||
|
|
||||||
|
class EventDetailSerializer(serializers.ModelSerializer):
|
||||||
area_ = AreaSerializer(source='area', read_only=True)
|
area_ = AreaSerializer(source='area', read_only=True)
|
||||||
cates_ = EventCateSimpleSerializer(source='cates', read_only=True, many=True)
|
cates_ = EventCateSimpleSerializer(source='cates', read_only=True, many=True)
|
||||||
employee_ = EmployeeSerializer(source='employee', read_only=True)
|
employee_ = EmployeeSerializer(source='employee', read_only=True)
|
||||||
|
operation_name = serializers.CharField(source='opl.operation.name', read_only=True)
|
||||||
vchannel_ = TDeviceSimpleSerializer(source='vchannel', read_only=True)
|
vchannel_ = TDeviceSimpleSerializer(source='vchannel', read_only=True)
|
||||||
handle_user_name = serializers.CharField(source='handle_user.name', read_only=True)
|
handle_user_name = serializers.CharField(source='handle_user.name', read_only=True)
|
||||||
face_img_f = MyFilePathField(source='face_img', read_only=True)
|
face_img_f = MyFilePathField(source='face_img', read_only=True)
|
||||||
|
|
|
||||||
|
|
@ -135,7 +135,7 @@ def save_voice_and_speak(event: Event):
|
||||||
for i in sps2:
|
for i in sps2:
|
||||||
if i not in sps:
|
if i not in sps:
|
||||||
sps.append(i)
|
sps.append(i)
|
||||||
myLogger.info('获取到喇叭:' + str(sps))
|
# myLogger.info('获取到喇叭:' + str(sps))
|
||||||
if sps:
|
if sps:
|
||||||
spClient.speak(event.voice, sps, v_num)
|
spClient.speak(event.voice, sps, v_num)
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ from apps.ecm.serializers import (AlgoChannelCreateSerializer,
|
||||||
AlgoChannelSerializer, EventAggSerializer,
|
AlgoChannelSerializer, EventAggSerializer,
|
||||||
EventCateCreateUpdateSerializer,
|
EventCateCreateUpdateSerializer,
|
||||||
EventCateListSerializer,
|
EventCateListSerializer,
|
||||||
EventHandleSerializer, EventSerializer,
|
EventHandleSerializer, EventSerializer, EventSimpleSerializer,
|
||||||
NotifySettingsSerializer, RemindSerializer)
|
NotifySettingsSerializer, RemindSerializer)
|
||||||
from apps.ecm.service import update_remind_read
|
from apps.ecm.service import update_remind_read
|
||||||
from apps.utils.viewsets import CustomGenericViewSet, CustomModelViewSet
|
from apps.utils.viewsets import CustomGenericViewSet, CustomModelViewSet
|
||||||
|
|
@ -75,7 +75,8 @@ class EventViewSet(ListModelMixin, RetrieveModelMixin, DestroyModelMixin, Custom
|
||||||
perms_map = {'get': '*'}
|
perms_map = {'get': '*'}
|
||||||
queryset = Event.objects.all()
|
queryset = Event.objects.all()
|
||||||
serializer_class = EventSerializer
|
serializer_class = EventSerializer
|
||||||
select_related_fields = ['area', 'employee', 'handle_user', 'vchannel']
|
retrieve_serializer_class = EventSimpleSerializer
|
||||||
|
select_related_fields = ['area', 'employee', 'handle_user', 'vchannel', 'opl']
|
||||||
prefetch_related_fields = ['cates']
|
prefetch_related_fields = ['cates']
|
||||||
filterset_class = EventFilterSet
|
filterset_class = EventFilterSet
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue