Commit 75e0ac77 authored by zhengjinlei's avatar zhengjinlei

分页查询

parent 7abc3100
# coding: utf-8 # coding: utf-8
from django.shortcuts import render from django.shortcuts import render
from django.db.models import Count, Sum from django.db.models import Count, Sum, Avg
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
...@@ -460,7 +460,7 @@ class TasksApi(viewsets.ViewSet): ...@@ -460,7 +460,7 @@ class TasksApi(viewsets.ViewSet):
f_name = extra['filename'] if extra and 'filename' in extra.keys() else '' f_name = extra['filename'] if extra and 'filename' in extra.keys() else ''
detail = {'id': check['id'], 'sessionId': check['sessionId'], 'createdAt': check['createdAt'], detail = {'id': check['id'], 'sessionId': check['sessionId'], 'createdAt': check['createdAt'],
'area': t_name.split('_')[0], 'agentName': check['agentName'], 'filename': f_name, 'area': t_name.split('_')[0], 'agentName': check['agentName'], 'filename': f_name,
'remainTime': check['remainTime']} 'remainTime': check['remainTime'], 'sessionCollectionId': k, 'taskId': check['taskId']}
rule_detail = {'fwyy': 10, 'kcb': 10, 'jsy': 5, 'fwtd': 10, 'yssb': 5, 'jysb': 5, 'yycl': 10, rule_detail = {'fwyy': 10, 'kcb': 10, 'jsy': 5, 'fwtd': 10, 'yssb': 5, 'jysb': 5, 'yycl': 10,
'ywcc': 15, 'yyjlz': 15, 'fwjs': 5, 'wtgbj': 5, 'wzyhfljs': 5, 'wgzlf': 100, 'mgc': 100} 'ywcc': 15, 'yyjlz': 15, 'fwjs': 5, 'wtgbj': 5, 'wzyhfljs': 5, 'wgzlf': 100, 'mgc': 100}
if result: if result:
...@@ -494,40 +494,30 @@ class TasksApi(viewsets.ViewSet): ...@@ -494,40 +494,30 @@ class TasksApi(viewsets.ViewSet):
""" """
task_id = req.data.get('task', '') task_id = req.data.get('task', '')
agent_name = req.data.get('agentName', '') agent_name = req.data.get('agentName', '')
page = req.data.get('page', '1')
page_size = req.data.get('page_size', '10')
start_date = req.data.get('start_date', (datetime.now() + timedelta(days=-1)).strftime('%Y-%m-%d')) 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')) end_date = req.data.get('end_date', datetime.now().strftime('%Y-%m-%d'))
task_condition = {'hasCheck': 1, 'createdAt__gte': start_date, 'createdAt__lt': end_date + ' 23:59:59'} 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()
task_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 task_condition['task'] = task_id
tasks = Tasks.objects.filter(**task_condition).values('id', 'name', 'sessionCollectionId') if agent_name:
task_dict = {} task_condition['agentName'] = agent_name
task_name_dict = {}
for t in tasks: rules = RulesStat.objects.filter(**task_condition).extra(select={'area': "task", 'agentName': 'agentName'})\
task_name_dict[t['id']] = t['name'] .values('area', 'agentName').annotate(avg_score=Avg('score')).order_by('-avg_score')
if t['sessionCollectionId'] in task_dict.keys(): paginator = Paginator(rules, page_size)
task_dict[t['sessionCollectionId']].append(t['id']) total_count = paginator.count
else: try:
task_dict[t['sessionCollectionId']] = [t['id'], ] seats = paginator.page(page)
return_data = [] except PageNotAnInteger:
detail = {} seats = paginator.page(1)
for k, v in task_dict.items(): except EmptyPage:
table_name = TABLE_PRE + k seats = paginator.page(paginator.num_pages)
tn = CheckSession.set_table(table_name)
session_condition = {'taskId__in': v} return Response({'code': 0, 'msg': 'success', 'count': total_count, 'data': seats.object_list})
if agent_name:
session_condition['agentName'] = agent_name
checks = tn.objects.filter(**session_condition).values('id', 'agentName', 'taskId', 'sessionId', 'score')
for check in checks:
if check['agentName'] in detail.keys():
pre_score = detail[check['agentName']]['avg_score']
detail[check['agentName']]['avg_score'] = (pre_score + check['score']) / 2
else:
area_name = task_name_dict[check['taskId']].split('_')[0]
detail[check['agentName']] = {'area': area_name, 'avg_score': check['score']}
for k, v in detail.items():
v['agentName'] = k
return_data.append(v)
return Response({'code': 0, 'msg': 'success', 'data': return_data})
@action(['post'], detail=False) @action(['post'], detail=False)
def static_rule(self, req: Request): def static_rule(self, req: Request):
...@@ -658,13 +648,12 @@ class TasksApi(viewsets.ViewSet): ...@@ -658,13 +648,12 @@ class TasksApi(viewsets.ViewSet):
table_list = json.loads(tables) table_list = json.loads(tables)
else: else:
table_list = tables table_list = tables
total_count = 0
session_condition = {'create_date__gte': q_start_date, 'create_date__lt': q_end_date, 'rule': rule_name, session_condition = {'create_date__gte': q_start_date, 'create_date__lt': q_end_date, 'rule': rule_name,
'sessionCollectionId__in': table_list} 'sessionCollectionId__in': table_list}
checks = RulesStat.objects.filter(**session_condition).values('agentName', 'customName', 'remainTime', 'score', checks = RulesStat.objects.filter(**session_condition).values('agentName', 'customName', 'remainTime', 'score',
'sessionCollectionId', 'sessionId', 'taskId') 'sessionCollectionId', 'sessionId', 'taskId')
paginator = Paginator(checks, page_size) paginator = Paginator(checks, page_size)
total_count += paginator.count total_count = paginator.count
try: try:
seats = paginator.page(page) seats = paginator.page(page)
except PageNotAnInteger: except PageNotAnInteger:
......
...@@ -132,19 +132,19 @@ ...@@ -132,19 +132,19 @@
<el-table <el-table
:data="tableData.slice((currentPage-1)*pagesize,currentPage*pagesize)" :data="tableData"
id='mutiTable' id='mutiTable'
border border
style="width: 100%"> style="width: 100%">
<el-table-column <el-table-column
prop="area" prop="area"
label="地市" label="地市"
width="150"> width="250">
</el-table-column> </el-table-column>
<el-table-column <el-table-column
prop="agentName" prop="agentName"
label="工号" label="工号"
width="190"> width="250">
</el-table-column> </el-table-column>
<el-table-column <el-table-column
prop="avg_score" prop="avg_score"
......
...@@ -173,7 +173,7 @@ new Vue({ ...@@ -173,7 +173,7 @@ new Vue({
that.poprule = msg.data[0]; that.poprule = msg.data[0];
that.popcurrentPage = 1; that.popcurrentPage = 1;
that.poppage = 1; that.poppage = 1;
that.getDetail(that.taskvalue,that.start_date,that.end_date,that.poptables,that.poprule, that.poppage, that.poppagesize); that.getDetail(that.taskvalue,that.start_date,that.end_date,that.poptables,that.poprule, that.poppage, that.poppagesize,that.takevalue);
//that.tableData = msg.data[2]; //that.tableData = msg.data[2];
that.dialogTableVisible = true; that.dialogTableVisible = true;
}) })
...@@ -194,14 +194,14 @@ new Vue({ ...@@ -194,14 +194,14 @@ new Vue({
}, },
popCurrentChange(page){ popCurrentChange(page){
this.poppage = page; this.poppage = page;
this.getDetail(this.taskvalue,this.start_date,this.end_date,this.poptables,this.poprule, this.poppage, this.poppagesize); this.getDetail(this.taskvalue,this.start_date,this.end_date,this.poptables,this.poprule, this.poppage, this.poppagesize,this.takevalue);
}, },
getDetail(task,start_date,end_date, tables, rule, page, page_size){ getDetail(task,start_date,end_date, tables, rule, page, page_size,agentName){
//this.getRule(this.taskvalue,this.start_date,this.end_date,this.takevalue); // 获取统计数据 //this.getRule(this.taskvalue,this.start_date,this.end_date,this.takevalue); // 获取统计数据
let that = this; let that = this;
//this.$loading({text:'数据加载中...'}); //this.$loading({text:'数据加载中...'});
this.poploading = true; this.poploading = true;
RquestsPost('api/v1/tasks/rule_detail/',{task,end_date,start_date,tables,rule,page,page_size}).then(data => { RquestsPost('api/v1/tasks/rule_detail/',{task,end_date,start_date,tables,rule,page,page_size,agentName}).then(data => {
console.log(data.data); console.log(data.data);
if(data.code != 0){ if(data.code != 0){
that.$message(data.msg); that.$message(data.msg);
......
...@@ -16,6 +16,8 @@ new Vue({ ...@@ -16,6 +16,8 @@ new Vue({
loading: true, loading: true,
tableData: [], tableData: [],
currentPage:1, currentPage:1,
page: 1,
page_size: 10,
pagesize: 10, pagesize: 10,
total: 10, total: 10,
isHidePage: true, isHidePage: true,
...@@ -31,16 +33,19 @@ new Vue({ ...@@ -31,16 +33,19 @@ new Vue({
changeRange(dateRange){ changeRange(dateRange){
this.start_date = dateRange[0]; this.start_date = dateRange[0];
this.end_date = dateRange[1]; this.end_date = dateRange[1];
this.getRule(this.taskvalue,this.start_date,this.end_date,this.takevalue); // 获取统计数据 this.page = 1;
this.getRule(this.taskvalue,this.start_date,this.end_date,this.takevalue,this.page,this.page_size); // 获取统计数据
}, },
changeTask(msg){ changeTask(msg){
this.taskvalue = msg; this.taskvalue = msg;
this.getTake() this.getTake()
this.getRule(this.taskvalue,this.start_date,this.end_date,this.takevalue); // 获取统计数据 this.page = 1;
this.getRule(this.taskvalue,this.start_date,this.end_date,this.takevalue,this.page,this.page_size); // 获取统计数据
}, },
changeTake(msg){ changeTake(msg){
this.takevalue = msg; this.takevalue = msg;
this.getRule(this.taskvalue,this.start_date,this.end_date,this.takevalue); // 获取统计数据 this.page = 1;
this.getRule(this.taskvalue,this.start_date,this.end_date,this.takevalue,this.page,this.page_size); // 获取统计数据
}, },
getTask(){ getTask(){
let that = this; let that = this;
...@@ -66,16 +71,17 @@ new Vue({ ...@@ -66,16 +71,17 @@ new Vue({
{id:'安徽省营业部',name:'安徽省营业部'}, {id:'安徽省营业部',name:'安徽省营业部'},
]; ];
}, },
getRule(task,start_date,end_date,agentName){ getRule(task,start_date,end_date,agentName,page,page_size){
let that = this; let that = this;
this.$loading({text:'数据加载中...'}); this.$loading({text:'数据加载中...'});
RquestsPost('api/v1/tasks/seat_area/',{task,start_date,end_date,agentName}).then(data => { RquestsPost('api/v1/tasks/seat_area/',{task,start_date,end_date,agentName,page,page_size}).then(data => {
if(data.code != 0){ if(data.code != 0){
//that.takeList = [{agentName:'全部坐席'}] //that.takeList = [{agentName:'全部坐席'}]
}else{ }else{
that.tableData = data.data; that.tableData = data.data;
this.total = data.data.length; this.total = data.count;
this.isHidePage = !(data.data.length > 0); this.isHidePage = !(data.data.length > 0);
} }
that.$loading().close(); that.$loading().close();
...@@ -131,6 +137,8 @@ new Vue({ ...@@ -131,6 +137,8 @@ new Vue({
}, },
CurrentChange(page){ CurrentChange(page){
this.currentPage = page; this.currentPage = page;
this.page = page;
this.getRule(this.taskvalue,this.start_date,this.end_date,this.takevalue,this.page,this.page_size); // 获取统计数据
}, },
init(){ init(){
this.dateRange = [new Date(new Date()-24*60*60*1000), new Date()]; this.dateRange = [new Date(new Date()-24*60*60*1000), new Date()];
...@@ -138,7 +146,7 @@ new Vue({ ...@@ -138,7 +146,7 @@ new Vue({
this.end_date = this.dateFormat(new Date()); this.end_date = this.dateFormat(new Date());
this.getTask(); // 获取任务 this.getTask(); // 获取任务
this.getTake(); // 获取坐席 this.getTake(); // 获取坐席
this.getRule(this.taskvalue,this.start_date,this.end_date,this.takevalue); // 获取统计数据 this.getRule(this.taskvalue,this.start_date,this.end_date,this.takevalue,this.page,this.page_size); // 获取统计数据
} }
......
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