统计绑定人员数

This commit is contained in:
曹前明 2022-07-05 08:41:18 +08:00
parent 8704ca7fae
commit 09c175d038
4 changed files with 27 additions and 5 deletions

View File

@ -40,12 +40,16 @@ class TDevice(BaseModel):
areas = models.ManyToManyField(Area, verbose_name='覆盖区',
related_name='tareas')
obj_cate = models.CharField('绑定对象', max_length=20, help_text='people/...', null=True, blank=True)
employee = models.ForeignKey(Employee, verbose_name='绑定人员', on_delete=models.CASCADE, null=True, blank=True)
employee = models.ForeignKey(Employee, verbose_name='当前绑定人员', on_delete=models.CASCADE, null=True, blank=True)
is_clock = models.BooleanField('是否打卡设备', default=False)
third_info = models.JSONField('三方信息', default=dict,
null=False, blank=True)
class BltRecord(BaseModel):
pass
class Tlog(BaseModel):
"""第三方请求与处理日志
"""

View File

@ -59,3 +59,10 @@ class TlogSerializer(CustomModelSerializer):
class Meta:
model = Tlog
fields = '__all__'
class BltQuerySerializer(serializers.Serializer):
"""标签复杂查询
"""
areas = serializers.ListField(child=serializers.CharField(), label='区域ID列表')

View File

@ -12,7 +12,7 @@ router.register('xunxi', XxCommonViewSet, basename='api_xunxi')
router.register('dahua', DhCommonViewSet, basename='api_dahua')
router.register('tdevice', TDeviceViewSet, basename='tdevice')
router.register('tlog', TlogViewSet, basename='tlog')
router.register('tdevice/blt', BltViewSet, basename='blt')
router.register('blt', BltViewSet, basename='blt')
urlpatterns = [
path(API_BASE_URL, include(router.urls)),
path(API_BASE_URL + 'dahua/test/', DahuaTestView.as_view()),

View File

@ -11,15 +11,26 @@ from apps.am.models import Area
from rest_framework.views import APIView
class BltViewSet(CreateModelMixin, CustomGenericViewSet):
class BltViewSet(CustomGenericViewSet):
"""定位标签列表
定位标签列表
"""
queryset = TDevice.objects.filter(type=TDevice.DEVICE_BLT)
serializer_class = TDeviceSerializer
select_related_fields = ['employee']
ordering = ['-create_time']
@action(methods=['get'], detail=False, perms_map={'get': '*'})
def count_people_bind(self, request):
"""统计绑定人员数
统计绑定人员数
"""
qs = self.queryset.exclude(employee=None)
ret = {}
ret['count_employee'] = qs.filter(employee__type='employee').count()
ret['count_remployee'] = qs.filter(employee__type='remployee').count()
ret['count_visitor'] = qs.filter(employee__type='visitor').count()
return Response(ret)
class TDeviceViewSet(ListModelMixin, CustomGenericViewSet):