Commit c445d851 authored by zhengjinlei's avatar zhengjinlei

地市质检成绩汇总分析

parent ac9a025d
......@@ -21,6 +21,22 @@ def get_team_names(city_id, country_id, team_id=None):
return team_names
def get_team_names_by_city(city=None):
# 获取地市团队对应关系
city_team = dict()
if city is None or city.parent is None:
countries = Country.objects.filter(parent=city.id)
for country in countries:
country_id_list = Country.objects.filter(Q(parent=country.id) | Q(id=country.id)).values_list('id')
team_names = Team.objects.filter(country_id__in=country_id_list).values_list('name')
city_team[country.name] = team_names
else:
country_id_list = Country.objects.filter(Q(parent=city.id) | Q(id=city.id)).values_list('id')
team_names = Team.objects.filter(country_id__in=country_id_list).values_list('name')
city_team[city.name] = team_names
return city_team
def get_agent_name(city_id, country_id, team_id, agent_name):
if agent_name is not None and agent_name != '':
return [agent_name]
......
......@@ -10,7 +10,7 @@ from rest_framework.response import Response
from before_request import before_request
from inspect_report.agency import get_team_names
from inspect_report.dbhelper import db_static_score, db_seat_rule, db_seat_check, db_seat_area, db_static_rule, \
set_city_country_by_team_name
set_city_country_by_team_name, db_city_score
from inspect_report.models import RulesStat, SeatStat, ScoreStat, Round, Seat, Tasks
import json
from django.views.decorators.clickjacking import xframe_options_exempt
......@@ -376,6 +376,17 @@ class TasksApi(viewsets.ViewSet):
return Response(
{'code': 0, 'msg': 'success', 'count': total_count, 'data': scores})
@action(['post'], detail=False)
# @before_request
def city_score(self, req: Request):
"""
地市质检成绩汇总分析
:param req:
:return:
"""
city_score_list = db_city_score(req)
return Response({'code': 0, 'msg': 'success', 'data': city_score_list})
@action(['post'], detail=False)
@before_request
def score_detail(self, req: Request):
......@@ -429,3 +440,8 @@ def score(request):
@xframe_options_exempt
def check(request):
return render(request, 'inspect/seat_check.html')
@xframe_options_exempt
def city_score(request):
return render(request, 'inspect/city_score.html')
......@@ -3,8 +3,8 @@ import json
from django.db.models import Avg, Sum, Count
from pypinyin import pinyin, Style
from config.config import TABLE_PRE
from inspect_report.agency import get_team_names, get_agent_name
from config.config import TABLE_PRE, name_list
from inspect_report.agency import get_team_names, get_agent_name, get_team_names_by_city
from inspect_report.utils.report_utils import get_remain
from inspect_report.models import ScoreStat, Round, SeatStat, Seat, Country, Tasks, CheckSession, RulesStat, Team
from inspect_report.pagehelper import page_with_seat_name
......@@ -55,6 +55,28 @@ def db_static_score(req):
return all_scores
def db_city_score(req):
username = req.data.get('username', '')
# username = '合肥'
if username in name_list:
city = Country.objects.filter(name=username).first()
else:
city = Country.objects.filter(parent__isnull=True).first()
team_dict = get_team_names_by_city(city)
task_condition = req.data.get('date_condition', {})
# task_condition = {'create_date__gte': '2020-03-08', 'create_date__lt': '2020-03-10'}
city_score_list = []
for c, t in team_dict.items():
task_condition['task__in'] = t
all_scores = ScoreStat.objects.filter(**task_condition).aggregate(
avg_score_svc=Round(Avg('service_score'), 2), avg_score_bus=Round(Avg('business_score'), 2),
avg_score=Round(Avg('score'), 2), total_session=Sum('total_session'), validate_num=Sum('validate_num'),
validate_zero=Sum('validate_zero'))
all_scores['city'] = c
city_score_list.append(all_scores)
return city_score_list
def db_seat_rule(req, if_page=False):
city_id = req.data.get('city', None) if 'city' in req.data else req.GET.get('city', None)
country_id = req.data.get('country', None) if 'country' in req.data else req.GET.get('country', None)
......
<!DOCTYPE html>
{% load static %}
<html lang="en">
<head>
<meta charset='utf-8' />
<title>地市质检成绩汇总分析</title>
<!-- 引入样式 -->
<link rel="stylesheet" href="{% static "inspect/css/element.css" %}">
<!-- 引入组件库 -->
<link rel='stylesheet' type='text/css' href="{% static "inspect/css/all.css" %}">
<style>
#OneTime{
display: inline-block;
}
#OneTime .el-input__icon {
line-height: 32px;
}
#OneTime .el-input .el-input__inner {
padding-left: 30px;
}
.groutTitle span{
display:inline-block;
margin-right: 20px;
color:#565656;
font-size:15px;
}
.groutTitle{
display: flex;
flex-direction: row;
margin-bottom: 20px;
margin-top: 10px;
}
.groutTitle > div{
order: 1;
flex-grow: 1;
background-color:#fff;
}
.groutTitle > div:nth-child(2){
margin: 0 10px;
}
.groutTitle > div:last-child{
margin-left:10px;
}
.groutTitle .grid-content{
padding: 20px;
}
.groutTitle .grid-content .icon{
font-size: 30px;
margin-right:10px;
}
.groutTitle .grid-content div{
display: inline-block;
vertical-align: middle;
}
.groutTitle .grid-content .content-value{
font-size: 30px;
}
#main{
background-color: #fff;
}
.el-dialog{
width: 700px
}
.is-fullscreen{
//z-index: 2222 !important;
}
#dialogDetail .el-table{
//min-height: 500px ;
}
</style>
</head>
<body style='height:100%'>
<!--
<div class='child-title'>语音坐席</div>
-->
<div class='child-main' id='childApp' style='background-color:initial;padding:0;'>
<div style='text-align:right;' class='childTitle'>
<el-date-picker
v-model="dateRange"
@change='changeRange'
clearable='false'
type="daterange"
value-format='yyyy-MM-dd'
start-placeholder="开始日期"
end-placeholder="结束日期"
:default-time="['00:00:00', '23:59:59']">
</el-date-picker>
</div>
<div id='main' style='width:100%;padding-bottom:20px'>
<el-table
:data="tableData"
border
style="width: 100%;margin-bottom:20px;">
<el-table-column
prop="city"
label="市"
>
</el-table-column>
<el-table-column
prop="total_session"
label="全部会话数"
>
</el-table-column>
<el-table-column
prop="validate_num"
label="触发违规项次数">
</el-table-column>
<el-table-column
prop="avg_score_svc"
label="服务类平均分">
</el-table-column>
<el-table-column
prop="avg_score_bus"
label="业务类平均分">
</el-table-column>
<el-table-column
prop="avg_score"
label="总平均分(包含0分项)">
</el-table-column>
<el-table-column
prop="validate_zero"
label="触发0分项次数">
</el-table-column>
</el-table>
</div>
</div>
<script type="text/javascript">
window.onload = function(){
};
</script>
<script src="{% static "inspect/js/vue.min.js" %}"></script>
<script src="{% static "inspect/js/element.js" %}"></script>
<script src="{% static "inspect/js/http.js" %}"></script>
<script type="text/javascript" src="{% static "inspect/js/city_score.js" %}"></script>
</body>
</html>
......@@ -15,7 +15,7 @@ Including another URLconf
"""
from django.contrib import admin
from django.urls import path
from .api.tasksapi import rule, seat, group, score, check
from .api.tasksapi import rule, seat, group, score, check, city_score
from .views import stat_rules_every, stat_seats_every, stat_scores_every, stat_time_every
urlpatterns = [
......@@ -25,6 +25,7 @@ urlpatterns = [
path('inspect/group/', group),
path('inspect/score/', score),
path('inspect/check/', check),
path('inspect/city_score/', city_score),
path('inspect/stat/rule/', stat_rules_every),
path('inspect/stat/seat/', stat_seats_every),
path('inspect/stat/score/', stat_scores_every),
......
new Vue({
el: '#childApp',
data: function () {
return {
ss: 'sas',
dateTime: '',
start_date: '',
init_simple: false,
isscrollTop: false,
poprule: '',
poptables: '',
popcurrentPage: 1,
scrollTop: 0,
country_chow: false,
BASEURL: window_url,
end_date: '',
sortObj: {
name: '',
sort: 'avg_score_bus',
},
poploading: false,
dialogTableVisible: false,
takeList: [],
dateRange: [new Date(), new Date()],
takevalue: '',
sel_is_show: true,
loading: true,
poptableData: [],
tableData: []
}
},
mounted() {
window.addEventListener('scroll', this.scrollToTop)
},
destroyed() {
window.removeEventListener('scroll', this.scrollToTop)
},
methods: {
changeRange(dateRange) {
this.start_date = dateRange[0];
this.end_date = dateRange[1];
this.getRule(this.cityvalue, this.countryvalue, this.start_date, this.end_date, this.takevalue, this.currentPage, 10); // 获取统计数据
},
changeCity(msg) {
console.log(msg);
this.cityvalue = msg;
this.countryvalue = null;
this.getCountry();
this.getRule(this.cityvalue, this.countryvalue, this.start_date, this.end_date, this.takevalue, this.currentPage, 10); // 获取统计数据
},
CurrentChange(page) {
this.currentPage = page;
this.getRule(this.cityvalue, this.countryvalue, this.start_date, this.end_date, this.takevalue, this.currentPage, 10); // 获取统计数据
},
getRule(start_date, end_date) {
let that = this;
console.log(start_date, end_date);
let arr = [];
this.$loading({text: '数据加载中...'});
let sort = this.sortObj.sort;
RquestsPost('api/v1/tasks/city_score/', {
end_date,
start_date
}).then(data => {
console.log(data.data);
if (data.code != 0) {
that.$message(data.msg);
if (data.msg) {
that.$message(data.msg);
} else {
that.$message('服务器错误')
}
}
if (!data.data) {
this.$loading().close();
return false;
}
//for(let key in data.data){
// arr.unshift([data.data[key],key])
//}
this.tableData = data.data;
this.$loading().close();
})},
dateFormat(date) {
return date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
},
// 为了计算距离顶部的高度,当高度大于60显示回顶部图标,小于60则隐藏
scrollToTop() {
const that = this
let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
that.scrollTop = scrollTop
if (that.scrollTop > 60) {
that.isscrollTop = true
} else {
that.isscrollTop = false
}
},
init() {
this.dateRange = [new Date(new Date() - 24 * 60 * 60 * 1000), new Date()];
this.start_date = this.dateFormat(new Date(new Date() - 24 * 60 * 60 * 1000));
this.end_date = this.dateFormat(new Date());
this.getRule(this.start_date, this.end_date); // 获取统计数据
}
},
created() {
this.init()
},
})
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