Commit e2914e25 authored by lvshibao's avatar lvshibao

首页数据隔离

parent 5faa05e1
...@@ -2,3 +2,8 @@ ...@@ -2,3 +2,8 @@
# 经常调整的配置文件参数 # 经常调整的配置文件参数
debug = True debug = True
name_list = ['合肥', '芜湖', '淮北', '安庆', '黄山', '滁州', '阜阳', '亳州', '宿州', '六安', '宣城', '巢湖', '池州', '淮南', '安徽省营业部', '蚌埠', '马鞍山',
'铜陵']
USER_INFO_URL = 'http://172.17.1.74:8248/getUserInfo'
...@@ -8,7 +8,7 @@ from rest_framework.response import Response ...@@ -8,7 +8,7 @@ from rest_framework.response import Response
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.views.decorators.clickjacking import xframe_options_exempt from django.views.decorators.clickjacking import xframe_options_exempt
import logging import logging
from pypinyin import Style, pinyin from pypinyin import Style, pinyin
...@@ -243,7 +243,7 @@ class TasksApi(viewsets.ViewSet): ...@@ -243,7 +243,7 @@ class TasksApi(viewsets.ViewSet):
:return: :return:
""" """
username = req.data.get('username', '') username = req.data.get('username', '')
logger.info('username获取: ' + username) # logger.info('username获取: ' + 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'))
...@@ -252,6 +252,8 @@ class TasksApi(viewsets.ViewSet): ...@@ -252,6 +252,8 @@ class TasksApi(viewsets.ViewSet):
session_condition = {'create_date__gte': q_start_date, 'create_date__lt': q_end_date} session_condition = {'create_date__gte': q_start_date, 'create_date__lt': q_end_date}
if task_id: if task_id:
session_condition['task'] = task_id session_condition['task'] = task_id
if username in name_list:
session_condition['task'] = username
seat_data = SeatStat.objects.filter(**session_condition).aggregate( seat_data = SeatStat.objects.filter(**session_condition).aggregate(
validate_session_sum=Sum('validate_session'), total_session_sum=Sum('total_session')) validate_session_sum=Sum('validate_session'), total_session_sum=Sum('total_session'))
avg_score = ScoreStat.objects.filter(**session_condition).aggregate(score_avg=Round(Avg('score'), 2)) avg_score = ScoreStat.objects.filter(**session_condition).aggregate(score_avg=Round(Avg('score'), 2))
...@@ -263,7 +265,7 @@ class TasksApi(viewsets.ViewSet): ...@@ -263,7 +265,7 @@ class TasksApi(viewsets.ViewSet):
else: else:
return_data['ratio'] = 0.0 return_data['ratio'] = 0.0
return_data['avg_score'] = 0.0 return_data['avg_score'] = 0.0
return Response({'code': 0, 'msg': 'success', 'data': return_data}) return Response({'code': 0, 'msg': 'success', 'data': return_data, 'username': username})
@action(['post'], detail=False) @action(['post'], detail=False)
def static_date(self, req: Request): def static_date(self, req: Request):
...@@ -527,12 +529,14 @@ class TasksApi(viewsets.ViewSet): ...@@ -527,12 +529,14 @@ 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_score(self, req: Request): def static_score(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', '')
page = req.data.get('page', '1') page = req.data.get('page', '1')
page_size = req.data.get('page_size', '10') page_size = req.data.get('page_size', '10')
...@@ -544,6 +548,8 @@ class TasksApi(viewsets.ViewSet): ...@@ -544,6 +548,8 @@ class TasksApi(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),
...@@ -559,7 +565,7 @@ class TasksApi(viewsets.ViewSet): ...@@ -559,7 +565,7 @@ class TasksApi(viewsets.ViewSet):
except EmptyPage: except EmptyPage:
seats = paginator.page(paginator.num_pages) seats = paginator.page(paginator.num_pages)
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, 'username': username})
@action(['post'], detail=False) @action(['post'], detail=False)
def score_detail(self, req: Request): def score_detail(self, req: Request):
......
...@@ -9,6 +9,8 @@ from functools import wraps ...@@ -9,6 +9,8 @@ from functools import wraps
from rest_framework.request import Request from rest_framework.request import Request
from rest_framework.response import Response from rest_framework.response import Response
from config.config import USER_INFO_URL
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
...@@ -32,9 +34,9 @@ def get_account_info(func): ...@@ -32,9 +34,9 @@ def get_account_info(func):
""" """
@wraps(func) @wraps(func)
def account_info(obj, req: Request, *args, **kw): def account_info(obj, req: Request, *args, **kw):
logger.info('req中的data为: ' + json.dumps(req.COOKIES)) # logger.info('req中的data为: ' + json.dumps(req.COOKIES))
cookie_jar = transfer_cookie(req.COOKIES) cookie_jar = transfer_cookie(req.COOKIES)
info = requests.get('http://172.17.1.74:8248/getUserInfo', 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: if info.json()['code'] != 200:
return Response({'code': -1, 'msg': '未能获取用户信息'}) return Response({'code': -1, 'msg': '未能获取用户信息'})
......
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