Commit 9ada3a7c authored by lvshibao's avatar lvshibao

group中的table添加市,县

parent 15bda856
......@@ -4,7 +4,8 @@ from rest_framework.decorators import action
from rest_framework.request import Request
from before_request import before_request
from inspect_report.dbhelper import db_static_score, db_seat_rule, db_seat_check, db_seat_area, db_static_rule
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
from datetime import datetime
from django.http import HttpResponse
import logging
......@@ -30,7 +31,10 @@ class DataApi(viewsets.ViewSet):
:return:
"""
rules = db_static_score(req)
scores = db_static_score(req)
scores = set_city_country_by_team_name(scores, 'area')
response = HttpResponse(content_type='text/csv')
file_name = '组长概览_' + datetime.now().strftime('%Y%m%d%H%M%S') + '.csv'
response['Content-Type'] = 'application/octet-stream'
......@@ -39,11 +43,11 @@ class DataApi(viewsets.ViewSet):
response.write(codecs.BOM_UTF8)
writer = csv.writer(response)
# 设置表头
header = ['地市', '全部会话数', '触发违规项次数', '服务类平均分', '业务类平均分', '总平均分(包含0分项)', '触发0分项次数']
header = ['地市', '县', '团队', '全部会话数', '触发违规项次数', '服务类平均分', '业务类平均分', '总平均分(包含0分项)', '触发0分项次数']
writer.writerow(header)
# 设置表数据
for r in rules:
row = [r['area'], r['total_session'], r['validate_num'], r['avg_score_svc'], r['avg_score_bus'],
for r in scores:
row = [r['city'], r['country'], r['area'], r['total_session'], r['validate_num'], r['avg_score_svc'], r['avg_score_bus'],
r['avg_score'], r['validate_zero']]
writer.writerow(row)
return response
......@@ -120,7 +124,7 @@ class DataApi(viewsets.ViewSet):
response.write(codecs.BOM_UTF8)
writer = csv.writer(response)
# 设置表头
header = ['地市', '坐席工号', '坐席名称', '全部会话数', '触发违规项次数', '服务类平均分', '业务类平均分', '平均分', '触发0分项次数']
header = ['团队', '坐席工号', '坐席名称', '全部会话数', '触发违规项次数', '服务类平均分', '业务类平均分', '平均分', '触发0分项次数']
writer.writerow(header)
# 设置表数据
for r in scores:
......
......@@ -8,7 +8,8 @@ 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
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
from inspect_report.models import RulesStat, SeatStat, ScoreStat, Round, Seat
import json
from django.views.decorators.clickjacking import xframe_options_exempt
......@@ -350,8 +351,10 @@ class TasksApi(viewsets.ViewSet):
total_count, scores = page_with_seat_name(all_scores, page, page_size)
scores = set_city_country_by_team_name(scores.object_list, 'area')
return Response(
{'code': 0, 'msg': 'success', 'count': total_count, 'data': scores.object_list})
{'code': 0, 'msg': 'success', 'count': total_count, 'data': scores})
@action(['post'], detail=False)
@before_request
......
......@@ -6,10 +6,38 @@ from pypinyin import pinyin, Style
from config.config import TABLE_PRE
from inspect_report.agency import get_team_names, get_agent_name
from inspect_report.cron import get_remain
from inspect_report.models import ScoreStat, Round, SeatStat, Seat, Country, Tasks, CheckSession, RulesStat
from inspect_report.models import ScoreStat, Round, SeatStat, Seat, Country, Tasks, CheckSession, RulesStat, Team
from inspect_report.pagehelper import page_with_seat_name
def set_city_country_by_team_name(objects, key):
team_country_dict = get_city_country_team()
for object_dict in objects:
object_dict['city'] = team_country_dict[object_dict[key]]['city']
object_dict['country'] = team_country_dict[object_dict[key]]['country']
return objects
def get_city_country_team():
teams = Team.objects.values('name', 'country_id')
countries = Country.objects.values('id', 'name', 'parent')
countries_dict = dict()
for country in countries:
countries_dict[country['id']] = {'name': country['name'], 'parent': country['parent']}
teams_dict = dict()
for team in teams:
teams_dict[team['name']] = dict()
country_dict = countries_dict[team['country_id']]
if country_dict['parent'] is not None and int(country_dict['parent']) != 153:
teams_dict[team['name']]['country'] = country_dict['name']
teams_dict[team['name']]['city'] = countries_dict[country_dict['parent']]['name']
else:
teams_dict[team['name']]['country'] = ''
teams_dict[team['name']]['city'] = country_dict['name']
return teams_dict
def db_static_score(req):
city_id = req.data.get('city', None)
country_id = req.data.get('country', None)
......
......@@ -199,6 +199,16 @@
border
@sort-change='sortChange'
style="width: 100%;margin-bottom:20px;">
<el-table-column
prop="city"
label="市"
>
</el-table-column>
<el-table-column
prop="country"
label="县"
>
</el-table-column>
<el-table-column
prop="area"
label="团队"
......
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