Commit 8e28ef98 authored by Kerwin_Cui's avatar Kerwin_Cui

预警统计导出

parent 12b0f9ab
......@@ -42,4 +42,6 @@ urlpatterns = [
url(r'^monitor_excel/$', monitor_excel),
url(r'^system_cmdb/$', system_cmdb),
url(r'^download_monitor/$', download_monitor),
url(r'^alarm_count_out/$', alarm_count_out),
url(r'^download_alarm_count/$', download_alarm_count),
]
......@@ -2790,6 +2790,65 @@ def system_cmdb(request):
)
def alarm_count_out(request):
try:
req = json.loads(request.body)
data_list = []
for i in req:
new_list = []
new_list.append(i.get(u'system'))
new_list.append(i.get(u'total'))
new_list.append(i.get(u'bad_work'))
new_list.append(i.get(u'main_work'))
new_list.append(i.get(u'normal_work'))
new_list.append(i.get(u'bad_weekend'))
new_list.append(i.get(u'main_weekend'))
new_list.append(i.get(u'normal_weekend'))
data_list.append(new_list)
workbook = xlwt.Workbook(encoding='utf-8')
data_sheet = workbook.add_sheet('demo')
row0 = ['系统', '有效故障预警数', '严重故障预警数(交易日)', '主要故障预警数(交易日)', '次要故障预警数(交易日)',
'严重故障预警数(非交易日)', '主要故障预警数(非交易日)', '次要故障预警数(非交易日)']
for i in range(len(row0)):
data_sheet.write(0, i, row0[i], set_style(u'宋体', 220, True))
a = 1
while True:
for i in range(len(row0)):
data_sheet.write(a, i, data_list[0][i], set_style(u'宋体', 220, False))
data_list.pop(0)
a += 1
if len(data_list) == 0:
break
workbook.save(u'预警统计.xls')
return render_json(
{
"result": True,
"code": 0,
"message": u"生成文件成功",
"data": 1
}
)
except Exception as e:
return render_json(
{
"result": False,
"code": 1,
"message": u"未知错误:%s" % e,
"data": {}
}
)
def download_alarm_count(request):
file_name = u'预警统计.xls'
file = open(file_name, 'rb')
response = FileResponse(file)
response['Content-Type'] = 'application/octet-stream'
response['Content-Disposition'] = 'attachment;filename="预警统计.xls"'
return response
# 同步事件
def sync(request):
now_time = int(time.time())
......
......@@ -22,6 +22,10 @@
@click="searchList()"
style="float: right;margin-right:12px">查询
</el-button>
<el-button size="medium" id="search" type="primary"
@click="listOut()"
style="float: right;margin-right:12px">导出
</el-button>
</div>
</div>
......@@ -103,6 +107,35 @@
this.total = res.data.count
})
},
async listOut(){
console.log(!this.AlarmCountData.length)
if (!this.AlarmCountData.length){
vm.$message(
{
type: 'error',
message: "当前搜索条件下无数据!"
}
)
}else {
await this.out_data();
vm.$message({
type: 'success',
message: '下载成功'
});
this.download_alarm_count();
}
},
out_data(){
return new Promise((resolve,reject)=>{
axios.post('${SITE_URL}alarm_count_out/', this.AlarmCountData).then(res => {
if (res.data == 1) {resolve('ok')}
})
})
},
download_alarm_count(){
window.location.href = "${SITE_URL}download_alarm_count";
},
getUserGroup() {
axios.get('${SITE_URL}search_user_group/').then(res => {
this.GroupOp = res.data['group_list'];
......
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