Commit 5b1bca4d authored by lvshibao's avatar lvshibao

首页数据隔离

parent e2914e25
......@@ -6,7 +6,7 @@ from rest_framework.request import Request
from inspect_report.models import Tasks, CheckSession, RulesStat, SeatStat, ScoreStat, Round
import json
from datetime import datetime, timedelta
from config.config import TABLE_PRE
from config.config import TABLE_PRE, name_list
from django.http import HttpResponse
import logging
from pypinyin import Style, pinyin
......@@ -14,6 +14,7 @@ import csv
import codecs
from django.utils.http import urlquote
from inspect_report.utils.account import get_account_info
logger = logging.getLogger(__name__)
......@@ -23,12 +24,14 @@ class DataApi(viewsets.ViewSet):
permission_classes = ()
@action(['get'], detail=False)
@get_account_info
def static_score_export(self, req: Request):
"""
概览-地市得分统计-导出
:param req:
:return:
"""
username = req.data.get('username', '')
task_id = req.GET.get('task', '')
sort = req.GET.get('sort', '-avg_score')
start_date = req.GET.get('start_date', (datetime.now() + timedelta(days=-1)).strftime('%Y-%m-%d'))
......@@ -38,6 +41,8 @@ class DataApi(viewsets.ViewSet):
task_condition = {'create_date__gte': q_start_date, 'create_date__lt': q_end_date}
if 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"}) \
.values('area').annotate(avg_score_svc=Round(Avg('service_score'), 2),
avg_score_bus=Round(Avg('business_score'), 2),
......
......@@ -440,18 +440,22 @@ class TasksApi(viewsets.ViewSet):
return Response({'code': 0, 'msg': 'success', 'count': total_count, 'data': seats.object_list})
@action(['post'], detail=False)
@get_account_info
def static_rule(self, req: Request):
"""
首页概述-违规项统计
:param req:
:return:
"""
username = req.data.get('username', '')
task_id = req.data.get('task', '')
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'))
task_condition = {'hasCheck': 1, 'createdAt__gte': start_date, 'createdAt__lt': end_date + ' 23:59:59'}
if 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')
task_dict = {}
for t in tasks:
......@@ -493,7 +497,7 @@ class TasksApi(viewsets.ViewSet):
v['call_count'] = call_count
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})
return Response({'code': 0, 'msg': 'success', 'data': data_sort, 'username': username})
@action(['post'], detail=False)
def rule_detail(self, req: Request):
......
......@@ -87,7 +87,7 @@
end-placeholder="结束日期"
:default-time="['00:00:00', '23:59:59']">
</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
v-for="item in taskList"
:key="item.id"
......
......@@ -38,7 +38,12 @@ def get_account_info(func):
cookie_jar = transfer_cookie(req.COOKIES)
info = requests.get(USER_INFO_URL, cookies=cookie_jar)
# logger.info('req中的query_params为: ', req.query_params)
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': '未能获取用户信息'})
req.data['username'] = info.json()['data']['userInfo']['name']
return func(obj, req, *args, **kw)
......
......@@ -35,6 +35,7 @@ new Vue({
"validate_session": 0,
"ratio": 0,
},
sel_is_show: true,
loading: true,
poptableData: [],
tableData: []
......@@ -183,6 +184,12 @@ new Vue({
return false;
}
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();
})
},
......
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