Commit 8519e533 authored by zhengjinlei's avatar zhengjinlei

列表展示

parent 57f36d03
...@@ -75,6 +75,70 @@ class TasksApi(viewsets.ViewSet): ...@@ -75,6 +75,70 @@ class TasksApi(viewsets.ViewSet):
@action(['post'], detail=False) @action(['post'], detail=False)
def rule(self, req: Request): def rule(self, req: Request):
"""
获取违规项分析
:param req:
:return:
"""
task_id = req.data.get('task', '')
agent_name = req.data.get('agentName', '')
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'))
data_sort = []
return_data = {}
if agent_name:
task_condition = {'hasCheck': 1, 'createdAt__gte': start_date, 'createdAt__lt': end_date + ' 23:59:59'}
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'], ]
for k, v in task_dict.items():
table_name = TABLE_PRE + k
tn = CheckSession.set_table(table_name)
session_condition = {'taskId__in': v, 'agentName': agent_name}
checks = tn.objects.filter(**session_condition).values('id', 'checkResult')
for check in checks:
result = check['checkResult']
if result:
data = json.loads(result)
for d in data:
if 'isViolation' in d.keys() and d['isViolation'] and 'rule' in d.keys() and 'name' in d['rule'].keys():
name = d['rule']['name']
if name in return_data.keys():
return_data[name]['count'] += 1
else:
return_data[name] = {'count': 1, 'tables': []}
if k not in return_data[name]['tables']:
return_data[name]['tables'].append(k)
else:
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:
task_condition['area'] = task_id
tasks = RulesStat.objects.filter(**task_condition).values('rule_name', 'from_table', 'rule_num')
for t in tasks:
name = t['rule_name']
if name in return_data.keys():
return_data[name]['count'] += int(t['rule_num'])
else:
return_data[name] = {'count': int(t['rule_num']), 'tables': []}
if t['from_table'] not in return_data[name]['tables']:
return_data[name]['tables'].append(t['from_table'])
for k, v in return_data.items():
v['rule'] = k
data_sort.append(v)
data_sort = sorted(data_sort, key=lambda x: x['count'], reverse=True)
return Response({'code': 0, 'msg': 'success', 'data': data_sort})
@action(['post'], detail=False)
def rule_bak(self, req: Request):
""" """
获取违规项分析 获取违规项分析
:param req: :param req:
...@@ -524,14 +588,14 @@ class TasksApi(viewsets.ViewSet): ...@@ -524,14 +588,14 @@ class TasksApi(viewsets.ViewSet):
q_end_date = (datetime.strptime(end_date, '%Y-%m-%d') + + timedelta(days=1)).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} task_condition = {'create_date__gte': q_start_date, 'create_date__lt': q_end_date}
if task_id: if task_id:
task_condition['rule_name'] = task_id task_condition['area'] = task_id
tasks = RulesStat.objects.filter(**task_condition).values('rule_name', 'from_table', 'rule_num') tasks = RulesStat.objects.filter(**task_condition).values('rule_name', 'from_table', 'rule_num')
for t in tasks: for t in tasks:
name = t['rule_name'] name = t['rule_name']
if name in return_data.keys(): if name in return_data.keys():
return_data[name]['count'] += int(t['rule_num']) return_data[name]['count'] += int(t['rule_num'])
else: else:
return_data[name] = {'count': 1, 'tables': []} return_data[name] = {'count': int(t['rule_num']), 'tables': []}
if t['from_table'] not in return_data[name]['tables']: if t['from_table'] not in return_data[name]['tables']:
return_data[name]['tables'].append(t['from_table']) return_data[name]['tables'].append(t['from_table'])
data_sort = [] data_sort = []
...@@ -622,8 +686,8 @@ class TasksApi(viewsets.ViewSet): ...@@ -622,8 +686,8 @@ class TasksApi(viewsets.ViewSet):
tn = CheckSession.set_table(table_name) tn = CheckSession.set_table(table_name)
session_condition = {'checkResult__contains': rule_name, 'createdAt__gte': start_date, session_condition = {'checkResult__contains': rule_name, 'createdAt__gte': start_date,
'createdAt__lt': end_date + ' 23:59:59'} 'createdAt__lt': end_date + ' 23:59:59', 'violationRuleCount__gt': 0}
checks = tn.objects.filter(**session_condition).values('id', 'agentName', 'customName', checks = tn.objects.filter(**session_condition).values('id', 'agentName', 'customName', 'checkResult',
'remainTime', 'score', 'sessionId', 'taskId') 'remainTime', 'score', 'sessionId', 'taskId')
paginator = Paginator(checks, page_size) paginator = Paginator(checks, page_size)
total_count += paginator.count total_count += paginator.count
...@@ -635,9 +699,16 @@ class TasksApi(viewsets.ViewSet): ...@@ -635,9 +699,16 @@ class TasksApi(viewsets.ViewSet):
seats = paginator.page(paginator.num_pages) seats = paginator.page(paginator.num_pages)
for check in seats: for check in seats:
result = check['checkResult']
if result:
data = json.loads(result)
for d in data:
if 'isViolation' in d.keys() and d['isViolation'] and 'rule' in d.keys() \
and 'name' in d['rule'].keys() and d['rule']['name'] == rule_name:
detail = {'agentName': check['agentName'], 'customName': check['customName'], detail = {'agentName': check['agentName'], 'customName': check['customName'],
'remainTime': check['remainTime'], 'score': check['score'], 'sessionId': check['sessionId'], 'remainTime': check['remainTime'], 'score': check['score'],
'sessionCollectionId': k, 'taskId': check['taskId']} 'sessionId': check['sessionId'], 'sessionCollectionId': k,
'taskId': check['taskId']}
return_data.append(detail) return_data.append(detail)
return Response({'code': 0, 'msg': 'success', 'count': total_count, 'data': return_data}) return Response({'code': 0, 'msg': 'success', 'count': total_count, 'data': return_data})
......
...@@ -50,14 +50,14 @@ ...@@ -50,14 +50,14 @@
</el-select> </el-select>
</div> </div>
<div id='main' style='width:80%;height:600px' v-loading='true'></div> <div id='main' style='width:80%;height:600px' v-loading='true'></div>
<el-dialog title="详情" :visible.sync="dialogTableVisible"> <el-dialog title="详情" v-loading='poploading' width='700px' :visible.sync="dialogTableVisible">
<el-table style='margin-top:-20px' :data="tableData" max-height='500'> <el-table style='margin-top:-20px' :data="tableData" height='400'>
<el-table-column prop="agentName" label="坐席id"></el-table-column> <el-table-column prop="agentName" label="坐席id" width='190'></el-table-column>
<el-table-column prop="customName" label="客户" ></el-table-column> <el-table-column prop="customName" label="客户" width='190'></el-table-column>
<el-table-column prop="remainTime" label="通话时间(秒)"> <el-table-column prop="remainTime" label="通话时间(秒)">
{# <template slot-scope='scope'>#} {# <template slot-scope='scope'>#}
{# <span>{{scope.row.remainTime}}秒</span>#} {# <span>{{formatSeconds(scope.row.remainTime)}}</span>#}
{# </template>#} {# </template>#}
</el-table-column> </el-table-column>
<el-table-column prop="score" label="分数"></el-table-column> <el-table-column prop="score" label="分数"></el-table-column>
...@@ -67,6 +67,15 @@ ...@@ -67,6 +67,15 @@
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
<el-pagination
@current-change='popCurrentChange'
style='margin: 0 auto;text-align:center;margin-bottom:20px;'
layout="prev, pager, next"
:current-page.sync='popcurrentPage'
background
:page-size="poppagesize"
:total="poptotal">
</el-pagination>
</el-dialog> </el-dialog>
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
......
...@@ -13,6 +13,13 @@ new Vue({ ...@@ -13,6 +13,13 @@ new Vue({
takevalue: '', takevalue: '',
loading: true, loading: true,
tableData: [], tableData: [],
poppage: 1,
poppagesize: 10,
poptotal: 10,
poprule: '',
poptables: '',
poploading: false,
popcurrentPage: 1,
} }
}, },
methods: { methods: {
...@@ -80,10 +87,10 @@ new Vue({ ...@@ -80,10 +87,10 @@ new Vue({
let msgArr = []; let msgArr = [];
let that = this; let that = this;
for(let key in msg){ for(let key in msg){
msgArr.unshift([msg[key].rule, msg[key].count , msg[key].details]) msgArr.unshift([msg[key].rule, msg[key].count , msg[key].tables])
} }
let sourceArr = [ let sourceArr = [
[ 'product', 'amount', 'detail'], [ 'product', 'amount', 'tables'],
].concat(msgArr); ].concat(msgArr);
var option = { var option = {
dataZoom : [ dataZoom : [
...@@ -162,7 +169,12 @@ new Vue({ ...@@ -162,7 +169,12 @@ new Vue({
var myChart = echarts.init(document.getElementById('main')); var myChart = echarts.init(document.getElementById('main'));
myChart.setOption(option); myChart.setOption(option);
myChart.on('click',function(msg){ myChart.on('click',function(msg){
that.tableData = msg.data[2]; that.poptables = msg.data[2];
that.poprule = msg.data[0];
that.popcurrentPage = 1;
that.poppage = 1;
that.getDetail(that.taskvalue,that.start_date,that.end_date,that.poptables,that.poprule, that.poppage, that.poppagesize);
//that.tableData = msg.data[2];
that.dialogTableVisible = true; that.dialogTableVisible = true;
}) })
if(msg.length == 0){ if(msg.length == 0){
...@@ -179,8 +191,33 @@ new Vue({ ...@@ -179,8 +191,33 @@ new Vue({
window.onresize = function(){ window.onresize = function(){
myChart.resize(); myChart.resize();
} }
},
popCurrentChange(page){
this.poppage = page;
this.getDetail(this.taskvalue,this.start_date,this.end_date,this.poptables,this.poprule, this.poppage, this.poppagesize);
},
getDetail(task,start_date,end_date, tables, rule, page, page_size){
//this.getRule(this.taskvalue,this.start_date,this.end_date,this.takevalue); // 获取统计数据
let that = this;
//this.$loading({text:'数据加载中...'});
this.poploading = true;
RquestsPost('api/v1/tasks/rule_detail/',{task,end_date,start_date,tables,rule,page,page_size}).then(data => {
console.log(data.data);
if(data.code != 0){
that.$message(data.msg);
if(data.msg){
that.$message(data.msg);
}else{
that.$message('服务器错误')
}
}
//that.titleInfo = data.data;
that.poptotal = data.count;
that.poptableData = data.data;
//this.$loading().close();
that.tableData = data.data;
this.poploading = false;
})
}, },
getRule(task,start_date,end_date,agentName){ getRule(task,start_date,end_date,agentName){
let that = this; let that = this;
......
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