Commit 5b1bca4d authored by lvshibao's avatar lvshibao

首页数据隔离

parent e2914e25
...@@ -6,7 +6,7 @@ from rest_framework.request import Request ...@@ -6,7 +6,7 @@ from rest_framework.request import Request
from inspect_report.models import Tasks, CheckSession, RulesStat, SeatStat, ScoreStat, Round from inspect_report.models import Tasks, CheckSession, RulesStat, SeatStat, ScoreStat, Round
import json import json
from datetime import datetime, timedelta from datetime import datetime, timedelta
from config.config import TABLE_PRE from config.config import TABLE_PRE, name_list
from django.http import HttpResponse from django.http import HttpResponse
import logging import logging
from pypinyin import Style, pinyin from pypinyin import Style, pinyin
...@@ -14,6 +14,7 @@ import csv ...@@ -14,6 +14,7 @@ import csv
import codecs import codecs
from django.utils.http import urlquote from django.utils.http import urlquote
from inspect_report.utils.account import get_account_info
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
...@@ -23,12 +24,14 @@ class DataApi(viewsets.ViewSet): ...@@ -23,12 +24,14 @@ class DataApi(viewsets.ViewSet):
permission_classes = () permission_classes = ()
@action(['get'], detail=False) @action(['get'], detail=False)
@get_account_info
def static_score_export(self, req: Request): def static_score_export(self, req: Request):
""" """
概览-地市得分统计-导出 概览-地市得分统计-导出
:param req: :param req:
:return: :return:
""" """
username = req.data.get('username', '')
task_id = req.GET.get('task', '') task_id = req.GET.get('task', '')
sort = req.GET.get('sort', '-avg_score') sort = req.GET.get('sort', '-avg_score')
start_date = req.GET.get('start_date', (datetime.now() + timedelta(days=-1)).strftime('%Y-%m-%d')) start_date = req.GET.get('start_date', (datetime.now() + timedelta(days=-1)).strftime('%Y-%m-%d'))
...@@ -38,6 +41,8 @@ class DataApi(viewsets.ViewSet): ...@@ -38,6 +41,8 @@ class DataApi(viewsets.ViewSet):
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['task'] = task_id task_condition['task'] = task_id
if username in name_list:
task_condition['task'] = username
rules = ScoreStat.objects.filter(**task_condition).extra(select={'area': "task"}) \ rules = ScoreStat.objects.filter(**task_condition).extra(select={'area': "task"}) \
.values('area').annotate(avg_score_svc=Round(Avg('service_score'), 2), .values('area').annotate(avg_score_svc=Round(Avg('service_score'), 2),
avg_score_bus=Round(Avg('business_score'), 2), avg_score_bus=Round(Avg('business_score'), 2),
......
...@@ -440,18 +440,22 @@ class TasksApi(viewsets.ViewSet): ...@@ -440,18 +440,22 @@ class TasksApi(viewsets.ViewSet):
return Response({'code': 0, 'msg': 'success', 'count': total_count, 'data': seats.object_list}) return Response({'code': 0, 'msg': 'success', 'count': total_count, 'data': seats.object_list})
@action(['post'], detail=False) @action(['post'], detail=False)
@get_account_info
def static_rule(self, req: Request): def static_rule(self, req: Request):
""" """
首页概述-违规项统计 首页概述-违规项统计
:param req: :param req:
:return: :return:
""" """
username = req.data.get('username', '')
task_id = req.data.get('task', '') task_id = req.data.get('task', '')
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'} task_condition = {'hasCheck': 1, 'createdAt__gte': start_date, 'createdAt__lt': end_date + ' 23:59:59'}
if task_id: if task_id:
task_condition['name__startswith'] = task_id task_condition['name__startswith'] = task_id
if username in name_list:
task_condition['name__startswith'] = username
tasks = Tasks.objects.filter(**task_condition).values('id', 'sessionCollectionId') tasks = Tasks.objects.filter(**task_condition).values('id', 'sessionCollectionId')
task_dict = {} task_dict = {}
for t in tasks: for t in tasks:
...@@ -493,7 +497,7 @@ class TasksApi(viewsets.ViewSet): ...@@ -493,7 +497,7 @@ class TasksApi(viewsets.ViewSet):
v['call_count'] = call_count v['call_count'] = call_count
data_sort.append(v) data_sort.append(v)
# data_sort = sorted(data_sort, key=lambda x: x['count'], reverse=True) # data_sort = sorted(data_sort, key=lambda x: x['count'], reverse=True)
return Response({'code': 0, 'msg': 'success', 'data': data_sort}) return Response({'code': 0, 'msg': 'success', 'data': data_sort, 'username': username})
@action(['post'], detail=False) @action(['post'], detail=False)
def rule_detail(self, req: Request): def rule_detail(self, req: Request):
......
...@@ -87,7 +87,7 @@ ...@@ -87,7 +87,7 @@
end-placeholder="结束日期" end-placeholder="结束日期"
:default-time="['00:00:00', '23:59:59']"> :default-time="['00:00:00', '23:59:59']">
</el-date-picker> </el-date-picker>
<el-select v-model="taskvalue" filterable placeholder="请选择" @change="changeTask"> <el-select v-if="sel_is_show == true" v-model="taskvalue" filterable placeholder="请选择" @change="changeTask">
<el-option <el-option
v-for="item in taskList" v-for="item in taskList"
:key="item.id" :key="item.id"
......
...@@ -38,7 +38,12 @@ def get_account_info(func): ...@@ -38,7 +38,12 @@ def get_account_info(func):
cookie_jar = transfer_cookie(req.COOKIES) cookie_jar = transfer_cookie(req.COOKIES)
info = requests.get(USER_INFO_URL, cookies=cookie_jar) info = requests.get(USER_INFO_URL, cookies=cookie_jar)
# logger.info('req中的query_params为: ', req.query_params) # logger.info('req中的query_params为: ', req.query_params)
if info.json()['code'] != 200: try:
if info.json()['code'] != 200:
logger.info('未能获取用户信息: ' + info.text)
return Response({'code': -1, 'msg': '未能获取用户信息'})
except Exception:
logger.info('未能获取用户信息: ' + info.text)
return Response({'code': -1, 'msg': '未能获取用户信息'}) return Response({'code': -1, 'msg': '未能获取用户信息'})
req.data['username'] = info.json()['data']['userInfo']['name'] req.data['username'] = info.json()['data']['userInfo']['name']
return func(obj, req, *args, **kw) return func(obj, req, *args, **kw)
......
...@@ -15,7 +15,7 @@ new Vue({ ...@@ -15,7 +15,7 @@ new Vue({
poppagesize: 10, poppagesize: 10,
poptotal: 10, poptotal: 10,
poprule: '', poprule: '',
poptables: '', poptables: '',
popcurrentPage: 1, popcurrentPage: 1,
isHidePage: true, isHidePage: true,
scrollTop: 0, scrollTop: 0,
...@@ -31,10 +31,11 @@ new Vue({ ...@@ -31,10 +31,11 @@ new Vue({
dateRange:[new Date(), new Date()], dateRange:[new Date(), new Date()],
takevalue: '', takevalue: '',
titleInfo: { titleInfo: {
"total_session": 0, "total_session": 0,
"validate_session": 0, "validate_session": 0,
"ratio": 0, "ratio": 0,
}, },
sel_is_show: true,
loading: true, loading: true,
poptableData: [], poptableData: [],
tableData: [] tableData: []
...@@ -135,7 +136,7 @@ new Vue({ ...@@ -135,7 +136,7 @@ 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);
}, },
getRule(task,start_date,end_date,agentName,page,page_size){ getRule(task,start_date,end_date,agentName,page,page_size){
let that = this; let that = this;
...@@ -183,6 +184,12 @@ new Vue({ ...@@ -183,6 +184,12 @@ new Vue({
return false; return false;
} }
that.titleInfo = data.data; that.titleInfo = data.data;
if (['合肥', '芜湖', '淮北', '安庆', '黄山', '滁州', '阜阳', '亳州', '宿州', '六安', '宣城', '巢湖', '池州', '淮南', '安徽省营业部', '蚌埠', '马鞍山', '铜陵'].indexOf(data.username) !== -1) {
that.sel_is_show = false;
that.taskvalue = data.username;
} else {
that.sel_is_show = true;
}
//this.$loading().close(); //this.$loading().close();
}) })
}, },
...@@ -191,7 +198,7 @@ new Vue({ ...@@ -191,7 +198,7 @@ new Vue({
}, },
rowDetail(index,tableData){ rowDetail(index,tableData){
let data = tableData; let data = tableData;
console.log(data); console.log(data);
//this.poptableData = tableData[index].details; //this.poptableData = tableData[index].details;
this.poptables = data.tables; this.poptables = data.tables;
...@@ -199,7 +206,7 @@ new Vue({ ...@@ -199,7 +206,7 @@ new Vue({
this.popcurrentPage = 1; this.popcurrentPage = 1;
this.poppage = 1; this.poppage = 1;
this.taskvalue = tableData.area; this.taskvalue = tableData.area;
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.dialogTableVisible = true; this.dialogTableVisible = true;
}, },
......
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