Commit ff7bc26b authored by zhengjinlei's avatar zhengjinlei

查询资源

parent a88c4932
...@@ -42,33 +42,18 @@ class TasksApi(viewsets.ViewSet): ...@@ -42,33 +42,18 @@ class TasksApi(viewsets.ViewSet):
:return: :return:
""" """
task_id = req.GET.get('task', '') task_id = req.GET.get('task', '')
task_condition = {'hasCheck': 1} start_date = req.data.get('start_date', (datetime.now() + timedelta(days=-1)).strftime('%Y-%m-%d'))
session_condition = {} end_date = req.data.get('end_date', datetime.now().strftime('%Y-%m-%d'))
q_start_date = datetime.strptime(start_date, '%Y-%m-%d').date()
q_end_date = (datetime.strptime(end_date, '%Y-%m-%d') + + timedelta(days=1)).date()
session_condition = {'create_date__gte': q_start_date, 'create_date__lt': q_end_date}
if task_id: if task_id:
task_condition['name__startswith'] = task_id session_condition['task'] = task_id
tasks = Tasks.objects.filter(**task_condition).values('id', 'sessionCollectionId') seats = SeatStat.objects.filter(**session_condition).values('agentName')
task_dict = {}
for t in tasks:
if t['sessionCollectionId'] in task_dict.keys():
task_dict[t['sessionCollectionId']].append(t['id'])
else:
task_dict[t['sessionCollectionId']] = [t['id'], ]
return_data = [] return_data = []
for agent in seats:
for k, v in task_dict.items(): if agent not in return_data:
# session_collection = t['sessionCollectionId'] return_data.append(agent)
table_name = TABLE_PRE + k
tn = CheckSession.set_table(table_name)
session_condition['taskId__in'] = v
agents = tn.objects.filter(**session_condition).values('agentName')
# .annotate(Count=Count('agentName')).values('agentName')
# if agents:
# return_data.append(agents)
for agent in agents:
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