Commit 988beb22 authored by lvshibao's avatar lvshibao

rules页面修改

parent 56cee779
...@@ -16,3 +16,11 @@ def get_team_names(city_id, country_id): ...@@ -16,3 +16,11 @@ def get_team_names(city_id, country_id):
country_id_list = Country.objects.filter(Q(parent=city_id) | Q(id=city_id)).values_list('id') 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') team_names = Team.objects.filter(country_id__in=country_id_list).values_list('name')
return team_names return team_names
def get_country_names(city_id):
city = Country.objects.filter(id=city_id).first()
if city.parent is None:
return None
else:
return city.name
...@@ -67,42 +67,31 @@ class DataApi(viewsets.ViewSet): ...@@ -67,42 +67,31 @@ class DataApi(viewsets.ViewSet):
return response return response
@action(['get'], detail=False) @action(['get'], detail=False)
@before_request
def static_rule_export(self, req: Request): def static_rule_export(self, req: Request):
""" """
违规项统计-导出 违规项统计-导出
:param req: :param req:
:return: :return:
""" """
task_id = req.GET.get('task', '') city_id = req.data.get('city', None)
start_date = req.GET.get('start_date', (datetime.now() + timedelta(days=-1)).strftime('%Y-%m-%d')) country_id = req.data.get('country', None)
end_date = req.GET.get('end_date', datetime.now().strftime('%Y-%m-%d')) task_condition = req.data.get('date_condition', {})
task_condition = {'hasCheck': 1, 'createdAt__gte': start_date, 'createdAt__lt': end_date + ' 23:59:59'}
if task_id:
task_condition['name__startswith'] = task_id
tasks = Tasks.objects.filter(**task_condition).values('id', 'sessionCollectionId')
task_dict = {}
for t in tasks:
if t['sessionCollectionId'] in task_dict.keys():
task_dict[t['sessionCollectionId']].append(t['id'])
else:
task_dict[t['sessionCollectionId']] = [t['id'], ]
return_data = {}
call_count = 0
for k, v in task_dict.items():
table_name = TABLE_PRE + k
tn = CheckSession.set_table(table_name)
session_condition = {'taskId__in': v, 'violationRuleCount__gt': 0}
validate_all = tn.objects.filter(**session_condition).aggregate(Count("id"))
call_count += validate_all['id__count']
q_start_date = datetime.strptime(start_date, '%Y-%m-%d').date() team_names = get_team_names(city_id, country_id)
q_end_date = (datetime.strptime(end_date, '%Y-%m-%d') + + timedelta(days=1)).date()
task_condition = {'create_date__gte': q_start_date, 'create_date__lt': q_end_date} task_condition['task__in'] = team_names
if task_id:
task_condition['task'] = task_id call_count = SeatStat.objects.filter(**task_condition).aggregate(Sum("validate_session"))
task_condition = req.data.get('date_condition', {})
task_condition['task__in'] = team_names
# tasks = RulesStat.objects.filter(**task_condition).values('rule', 'sessionCollectionId', 'rule_num')
tasks = RulesStat.objects.all().filter(**task_condition) \ tasks = RulesStat.objects.all().filter(**task_condition) \
.extra(select={'rule': "rule", 'sessionCollectionId': 'sessionCollectionId'}) \ .extra(select={'rule': "rule", 'sessionCollectionId': 'sessionCollectionId'}) \
.values('rule', 'sessionCollectionId').annotate(rule_num=Count('id')).order_by('-rule_num') .values('rule', 'sessionCollectionId').annotate(rule_num=Count('id')).order_by('-rule_num')
return_data = {}
for t in tasks: for t in tasks:
name = t['rule'] name = t['rule']
if name in return_data.keys(): if name in return_data.keys():
......
...@@ -7,7 +7,7 @@ from rest_framework.request import Request ...@@ -7,7 +7,7 @@ from rest_framework.request import Request
from rest_framework.response import Response from rest_framework.response import Response
from before_request import before_request from before_request import before_request
from inspect_report.agency import get_team_names from inspect_report.agency import get_team_names, get_country_names
from inspect_report.models import Tasks, CheckSession, RulesStat, SeatStat, ScoreStat, Round, Team, Country from inspect_report.models import Tasks, CheckSession, RulesStat, SeatStat, ScoreStat, Round, Team, Country
import json import json
from datetime import datetime, timedelta from datetime import datetime, timedelta
...@@ -447,39 +447,25 @@ class TasksApi(viewsets.ViewSet): ...@@ -447,39 +447,25 @@ class TasksApi(viewsets.ViewSet):
:param req: :param req:
:return: :return:
""" """
username = req.data.get('username', '')
task_id = req.data.get('task', '')
task_condition = req.data.get('at_condition', {})
task_condition['hasCheck'] = 1
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:
if t['sessionCollectionId'] in task_dict.keys():
task_dict[t['sessionCollectionId']].append(t['id'])
else:
task_dict[t['sessionCollectionId']] = [t['id'], ]
return_data = {}
call_count = 0
for k, v in task_dict.items():
table_name = TABLE_PRE + k
tn = CheckSession.set_table(table_name)
session_condition = {'taskId__in': v, 'violationRuleCount__gt': 0}
validate_all = tn.objects.filter(**session_condition).aggregate(Count("id"))
call_count += validate_all['id__count']
city_id = req.data.get('city', None)
country_id = req.data.get('country', None)
task_condition = req.data.get('date_condition', {}) task_condition = req.data.get('date_condition', {})
if task_id:
task_condition['task'] = task_id team_names = get_team_names(city_id, country_id)
elif username:
task_condition['task'] = username task_condition['task__in'] = team_names
call_count = SeatStat.objects.filter(**task_condition).aggregate(Sum("validate_session"))
task_condition = req.data.get('date_condition', {})
task_condition['task__in'] = team_names
# tasks = RulesStat.objects.filter(**task_condition).values('rule', 'sessionCollectionId', 'rule_num') # tasks = RulesStat.objects.filter(**task_condition).values('rule', 'sessionCollectionId', 'rule_num')
tasks = RulesStat.objects.all().filter(**task_condition) \ tasks = RulesStat.objects.all().filter(**task_condition) \
.extra(select={'rule': "rule", 'sessionCollectionId': 'sessionCollectionId'}) \ .extra(select={'rule': "rule", 'sessionCollectionId': 'sessionCollectionId'}) \
.values('rule', 'sessionCollectionId').annotate(rule_num=Count('id')).order_by('-rule_num') .values('rule', 'sessionCollectionId').annotate(rule_num=Count('id')).order_by('-rule_num')
return_data = {}
for t in tasks: for t in tasks:
name = t['rule'] name = t['rule']
if name in return_data.keys(): if name in return_data.keys():
...@@ -496,7 +482,7 @@ class TasksApi(viewsets.ViewSet): ...@@ -496,7 +482,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, 'username': username}) return Response({'code': 0, 'msg': 'success', 'data': data_sort})
@action(['post'], detail=False) @action(['post'], detail=False)
@before_request @before_request
...@@ -506,7 +492,8 @@ class TasksApi(viewsets.ViewSet): ...@@ -506,7 +492,8 @@ class TasksApi(viewsets.ViewSet):
:param req: :param req:
:return: :return:
""" """
username = req.data.get('username', '') city_id = req.data.get('city', None)
country_id = req.data.get('country', None)
tables = req.data.get('tables', '') tables = req.data.get('tables', '')
rule_name = req.data.get('rule', '') rule_name = req.data.get('rule', '')
page = req.data.get('page', '1') page = req.data.get('page', '1')
...@@ -518,8 +505,7 @@ class TasksApi(viewsets.ViewSet): ...@@ -518,8 +505,7 @@ class TasksApi(viewsets.ViewSet):
session_condition = req.data.get('date_condition', {}) session_condition = req.data.get('date_condition', {})
session_condition['rule'] = rule_name session_condition['rule'] = rule_name
session_condition['sessionCollectionId__in'] = table_list session_condition['sessionCollectionId__in'] = table_list
if username in name_list: session_condition['task__in'] = get_team_names(city_id, country_id)
session_condition['agentName__contains'] = name_code_dict[username]
checks = RulesStat.objects.filter(**session_condition).values('agentName', 'customName', 'remainTime', 'score', checks = RulesStat.objects.filter(**session_condition).values('agentName', 'customName', 'remainTime', 'score',
'sessionCollectionId', 'sessionId', 'taskId') 'sessionCollectionId', 'sessionId', 'taskId')
paginator = Paginator(checks, page_size) paginator = Paginator(checks, page_size)
......
...@@ -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="cityvalue" filterable placeholder="请选择" @change="changeCity"> <el-select v-model="cityvalue" filterable placeholder="请选择" @change="changeCity">
<el-option <el-option
v-for="item in cityList" v-for="item in cityList"
:key="item.id" :key="item.id"
...@@ -95,7 +95,7 @@ ...@@ -95,7 +95,7 @@
:value="item.id"> :value="item.id">
</el-option> </el-option>
</el-select> </el-select>
<el-select v-model="countryvalue" filterable placeholder="请选择" @change="changeCountry"> <el-select v-model="countryvalue" filterable placeholder="请选择" @change="changeCountry">
<el-option <el-option
v-for="item in countryList" v-for="item in countryList"
:key="item.id" :key="item.id"
......
...@@ -87,9 +87,17 @@ ...@@ -87,9 +87,17 @@
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-if="sel_is_show == true" v-model="taskvalue" filterable placeholder="请选择" @change="changeTask"> <el-select v-model="cityvalue" filterable placeholder="请选择市" @change="changeCity">
<el-option <el-option
v-for="item in taskList" v-for="item in cityList"
:key="item.id"
:label="item.name"
:value="item.id">
</el-option>
</el-select>
<el-select v-model="countryvalue" filterable placeholder="请选择县" @change="changeCountry">
<el-option
v-for="item in countryList"
:key="item.id" :key="item.id"
:label="item.name" :label="item.name"
:value="item.id"> :value="item.id">
...@@ -101,7 +109,8 @@ ...@@ -101,7 +109,8 @@
<form ref="loadModal" :action="`${BASEURL}api/v1/data/static_rule_export/`" method="get"> <form ref="loadModal" :action="`${BASEURL}api/v1/data/static_rule_export/`" method="get">
<input type="hidden" name="start_date" :value="start_date"> <input type="hidden" name="start_date" :value="start_date">
<input type="hidden" name="end_date" :value="end_date"> <input type="hidden" name="end_date" :value="end_date">
<input type="hidden" name="task" :value="taskvalue"> <input type="hidden" name="city" :value="cityvalue">
<input type="hidden" name="country" :value="countryvalue">
</form> </form>
</div> </div>
<div id='main' style='width:100%;padding-bottom:20px'> <div id='main' style='width:100%;padding-bottom:20px'>
...@@ -193,7 +202,6 @@ ...@@ -193,7 +202,6 @@
<script src="{% static "inspect/js/vue.min.js" %}"></script> <script src="{% static "inspect/js/vue.min.js" %}"></script>
<script src="{% static "inspect/js/element.js" %}"></script> <script src="{% static "inspect/js/element.js" %}"></script>
<script src="{% static "inspect/js/http.js" %}"></script> <script src="{% static "inspect/js/http.js" %}"></script>
<script type="text/javascript" src="{% static "inspect/js/config.js" %}"></script>
<script type="text/javascript" src="{% static "inspect/js/rule.js" %}"></script> <script type="text/javascript" src="{% static "inspect/js/rule.js" %}"></script>
</body> </body>
</html> </html>
...@@ -4,8 +4,10 @@ new Vue({ ...@@ -4,8 +4,10 @@ new Vue({
return { return {
ss:'sas', ss:'sas',
dateTime: '', dateTime: '',
taskList:[], cityList:[],
taskvalue: '', countryList:[],
cityvalue: null,
countryvalue: null,
start_date: '', start_date: '',
isscrollTop: false, isscrollTop: false,
currentPage:1, currentPage:1,
...@@ -25,13 +27,11 @@ new Vue({ ...@@ -25,13 +27,11 @@ new Vue({
dialogTableVisible: false, dialogTableVisible: false,
takeList:[], takeList:[],
dateRange:[new Date(), new Date()], dateRange:[new Date(), new Date()],
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: []
...@@ -51,42 +51,55 @@ new Vue({ ...@@ -51,42 +51,55 @@ new Vue({
changeRange(dateRange){ changeRange(dateRange){
this.start_date = dateRange[0]; this.start_date = dateRange[0];
this.end_date = dateRange[1]; this.end_date = dateRange[1];
this.getRule(this.taskvalue,this.start_date,this.end_date,this.takevalue); // 获取统计数据 this.getRule(this.cityvalue,this.countryvalue,this.start_date,this.end_date,this.takevalue); // 获取统计数据
}, },
changeTask(msg){ changeCity(msg){
console.log(msg); console.log(msg);
this.taskvalue = msg; this.cityvalue = msg;
this.getTake() this.countryvalue = null;
this.getRule(this.taskvalue,this.start_date,this.end_date,this.takevalue); // 获取统计数据 this.getCountry(this.cityvalue);
this.getRule(this.cityvalue,this.countryvalue,this.start_date,this.end_date,this.takevalue); // 获取统计数据
}, },
changeTake(msg){ changeCountry(msg){
this.takevalue = msg;
this.getRule(this.taskvalue,this.start_date,this.end_date,this.takevalue); // 获取统计数据
console.log(msg); console.log(msg);
this.countryvalue = msg;
this.getRule(this.cityvalue,this.countryvalue,this.start_date,this.end_date,this.takevalue); // 获取统计数据
}, },
getTask(){ getCountry() {
let that = this;
RquestsGet('api/v1/agency/country/?city_id=' + this.cityvalue).then(data => {
//console.log(data);
if (data.code != 0) {
that.$message('服务器错误')
} else {
that.countryList = data.data.country_list;
}
})
},
getCity(){
let that = this; let that = this;
that.taskList = [ var request = new XMLHttpRequest();
{id:'',name:'全省'},
{id:'合肥',name:'合肥'}, let uri = window_url + 'api/v1/agency/city/';
{id:'芜湖',name:'芜湖'},
{id:'蚌埠',name:'蚌埠'}, request.open('GET', uri, false);
{id:'淮南',name:'淮南'}, request.send(null);
{id:'马鞍山',name:'马鞍山'}, if (request.status === 200) {
{id:'淮北',name:'淮北'}, data = JSON.parse(request.response);
{id:'铜陵',name:'铜陵'}, console.log(data.code);
{id:'安庆',name:'安庆'}, if(data.code != 0){
{id:'黄山',name:'黄山'}, that.$message('服务器错误');
{id:'滁州',name:'滁州'}, } else {
{id:'阜阳',name:'阜阳'}, that.cityList = data.data.city_list;
{id:'毫州',name:'毫州'}, that.countryList = data.data.country_list;
{id:'宿州',name:'宿州'}, that.cityvalue = data.data.city_id;
{id:'六安',name:'六安'}, console.log(that.cityvalue);
{id:'宣城',name:'宣城'}, that.init_simple = true;
{id:'巢湖',name:'巢湖'}, }
{id:'池州',name:'池州'}, } else {
{id:'安徽省营业部',name:'安徽省营业部'}, that.$message('服务器错误');
]; }
//RquestsGet('api/v1/tasks/obtain/').then(data => { //RquestsGet('api/v1/tasks/obtain/').then(data => {
// //console.log(data); // //console.log(data);
// if(data.code != 0){ // if(data.code != 0){
...@@ -97,32 +110,20 @@ new Vue({ ...@@ -97,32 +110,20 @@ new Vue({
// } // }
//}) //})
}, },
getTake(){
let that = this;
RquestsGet('api/v1/tasks/seat/?task=' + that.taskvalue).then(data => {
//console.log(data);
if(data.code != 0){
//that.takeList = [{agentName:'全部坐席'}]
}else{
that.takeList = data.data;
}
})
},
CurrentChange(page){ CurrentChange(page){
this.currentPage = page; this.currentPage = page;
}, },
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.cityvalue,this.countryvalue,this.end_date,this.poptables,this.poprule, this.poppage, this.poppagesize);
}, },
getRule(task,start_date,end_date,agentName){ getRule(city,country,start_date,end_date,agentName){
let that = this; let that = this;
console.log(start_date,end_date); console.log(start_date,end_date);
let arr = []; let arr = [];
this.$loading({text:'数据加载中...'}); this.$loading({text:'数据加载中...'});
RquestsPost('api/v1/tasks/static_rule/',{task,end_date,start_date,agentName}).then(data => { RquestsPost('api/v1/tasks/static_rule/',{city,country,end_date,start_date,agentName}).then(data => {
console.log(data.data); console.log(data.data);
if(data.code != 0){ if(data.code != 0){
that.$message(data.msg); that.$message(data.msg);
...@@ -145,7 +146,7 @@ new Vue({ ...@@ -145,7 +146,7 @@ new Vue({
this.isHidePage = !(data.data.length > 0); this.isHidePage = !(data.data.length > 0);
this.$loading().close(); this.$loading().close();
}) })
RquestsPost('api/v1/tasks/static/',{task,end_date,start_date,agentName}).then(data => { RquestsPost('api/v1/tasks/static/',{city,country,end_date,start_date,agentName}).then(data => {
console.log(data.data); console.log(data.data);
if(data.code != 0){ if(data.code != 0){
that.$message(data.msg); that.$message(data.msg);
...@@ -183,15 +184,15 @@ new Vue({ ...@@ -183,15 +184,15 @@ 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.cityvalue,this.countryvalue,this.start_date,this.end_date,this.poptables,this.poprule, this.poppage, this.poppagesize);
}, },
getDetail(task,start_date,end_date, tables, rule, page, page_size){ getDetail(city,country,start_date,end_date, tables, rule, page, page_size){
//this.getRule(this.taskvalue,this.start_date,this.end_date,this.takevalue); // 获取统计数据 //this.getRule(this.taskvalue,this.start_date,this.end_date,this.takevalue); // 获取统计数据
let that = this; let that = this;
this.$loading({text:'数据加载中...'}); this.$loading({text:'数据加载中...'});
this.poploading = true; this.poploading = true;
RquestsPost('api/v1/tasks/rule_detail/',{task,end_date,start_date,tables,rule,page,page_size}).then(data => { RquestsPost('api/v1/tasks/rule_detail/',{city,country,end_date,start_date,tables,rule,page,page_size}).then(data => {
console.log(data.data); console.log(data.data);
this.$loading().close(); this.$loading().close();
this.dialogTableVisible = true; this.dialogTableVisible = true;
...@@ -244,10 +245,10 @@ new Vue({ ...@@ -244,10 +245,10 @@ new Vue({
this.dateRange = [new Date(new Date()-24*60*60*1000), new Date()]; 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.start_date = this.dateFormat(new Date(new Date()-24*60*60*1000));
this.end_date = this.dateFormat(new Date()); this.end_date = this.dateFormat(new Date());
this.getTask(); // 获取任务 this.getCity(); // 获取任务
//this.getTake(); // 获取坐席 //this.getTake(); // 获取坐席
this.getRule(this.taskvalue,this.start_date,this.end_date,this.takevalue); // 获取统计数据 this.getRule(this.cityvalue,this.countryvalue,this.start_date,this.end_date,this.takevalue); // 获取统计数据
} }
}, },
......
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