Commit 863a5fd1 authored by zhengjinlei's avatar zhengjinlei

获取坐席列表

parent 2b6cdac5
# coding: utf-8 # coding: utf-8
from django.shortcuts import render from django.shortcuts import render
from django.db.models import Count
from rest_framework import viewsets from rest_framework import viewsets
from rest_framework.decorators import action from rest_framework.decorators import action
from rest_framework.request import Request from rest_framework.request import Request
...@@ -11,6 +12,8 @@ from config.config import TABLE_PRE ...@@ -11,6 +12,8 @@ from config.config import TABLE_PRE
from django.views.decorators.clickjacking import xframe_options_exempt from django.views.decorators.clickjacking import xframe_options_exempt
from inspect_report import permissions from inspect_report import permissions
import logging import logging
from functools import reduce
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
...@@ -40,18 +43,24 @@ class TasksApi(viewsets.ViewSet): ...@@ -40,18 +43,24 @@ class TasksApi(viewsets.ViewSet):
""" """
task_id = req.GET.get('task', '') task_id = req.GET.get('task', '')
task_condition = {} task_condition = {}
session_condition = {}
if task_id: if task_id:
task_condition['pk'] = task_id task_condition['pk'] = task_id
tasks = Tasks.objects.filter(**task_condition) session_condition['taskId'] = task_id
tasks = Tasks.objects.filter(**task_condition).values('sessionCollectionId').annotate(Count=Count('sessionCollectionId'))
return_data = [] return_data = []
for t in tasks: for t in tasks:
session_collection = t.sessionCollectionId session_collection = t['sessionCollectionId']
table_name = TABLE_PRE + session_collection table_name = TABLE_PRE + session_collection
tn = CheckSession.set_table(table_name) tn = CheckSession.set_table(table_name)
agents = tn.objects.filter(taskId=t.id).values('agentName') agents = tn.objects.filter(**session_condition).values('agentName').annotate(Count=Count('agentName')).values('agentName')
for agent in agents: return_data.append(agents)
if agent not in return_data: # for agent in agents:
return_data.append(agent) # if agent not in return_data:
# return_data.append(agent)
data_reduce = lambda x, y: x if y in x else x + [y]
return_data = reduce(data_reduce, [[], ] + return_data)
return Response({'code': 0, 'msg': 'success', 'data': return_data}) return Response({'code': 0, 'msg': 'success', 'data': return_data})
@action(['post'], detail=False) @action(['post'], detail=False)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment