Commit ff7bc26b authored by zhengjinlei's avatar zhengjinlei

查询资源

parent a88c4932
......@@ -42,33 +42,18 @@ class TasksApi(viewsets.ViewSet):
:return:
"""
task_id = req.GET.get('task', '')
task_condition = {'hasCheck': 1}
session_condition = {}
start_date = req.data.get('start_date', (datetime.now() + timedelta(days=-1)).strftime('%Y-%m-%d'))
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:
task_condition['name__startswith'] = task_id
tasks = Tasks.objects.filter(**task_condition).values('id', 'sessionCollectionId')
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'], ]
session_condition['task'] = task_id
seats = SeatStat.objects.filter(**session_condition).values('agentName')
return_data = []
for k, v in task_dict.items():
# session_collection = t['sessionCollectionId']
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)
for agent in seats:
if agent not in return_data:
return_data.append(agent)
return Response({'code': 0, 'msg': 'success', 'data': return_data})
@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