导出检查记录excel
This commit is contained in:
parent
cd300971eb
commit
d62c484c32
|
@ -256,6 +256,14 @@ def exportdoc(a,id):
|
||||||
|
|
||||||
import re
|
import re
|
||||||
ILLEGAL_CHARACTERS_RE = re.compile(r'[\000-\010]|[\013-\014]|[\016-\037]')
|
ILLEGAL_CHARACTERS_RE = re.compile(r'[\000-\010]|[\013-\014]|[\016-\037]')
|
||||||
|
def placeImg(sheet, imgp, place):
|
||||||
|
try:
|
||||||
|
img = Image(dirname + imgp)
|
||||||
|
if img.format!='mpo':
|
||||||
|
img.width, img.height = (90, 90) #这两个属性分别是对应添加图片的宽高
|
||||||
|
sheet.add_image(img, place)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
def exportxlsx(a,objs,pic=1):
|
def exportxlsx(a,objs,pic=1):
|
||||||
if a =='yh':
|
if a =='yh':
|
||||||
wb = load_workbook(dirname + 'safesite/exportemp/yhdc.xlsx')
|
wb = load_workbook(dirname + 'safesite/exportemp/yhdc.xlsx')
|
||||||
|
@ -735,21 +743,44 @@ def exportxlsx(a,objs,pic=1):
|
||||||
res['Content-Disposition'] = 'attachment;filename='+filename+'.xlsx'
|
res['Content-Disposition'] = 'attachment;filename='+filename+'.xlsx'
|
||||||
res.write(output.getvalue())
|
res.write(output.getvalue())
|
||||||
return res
|
return res
|
||||||
elif a == 'chekjob':
|
elif a == 'checkjob':
|
||||||
#查询数据
|
#查询数据
|
||||||
wb = load_workbook(dirname + 'safesite/exportemp/checkjob.xlsx')
|
wb = load_workbook(dirname + 'safesite/exportemp/checkjob.xlsx')
|
||||||
sheet = wb.active
|
sheet = wb.active
|
||||||
for i, x in enumerate(objs):
|
for i, x in enumerate(objs):
|
||||||
num = str(i+3)
|
num = str(i+3)
|
||||||
sheet['a'+num] = x.num
|
sheet['a'+num] = x.checktask.checktype.checktitle
|
||||||
sheet['b'+num] = x.name
|
sheet['b'+num] = x.checktask.get_tasktype_display()
|
||||||
if x.cate:
|
sheet['c'+num] = x.checktask.checkplace
|
||||||
sheet['c'+num] = x.cate.dickeyname
|
sheet['d'+num] = x.checktask.checktype.checkcontent
|
||||||
sheet['d'+num] = x.type
|
sheet['e'+num] = x.starttime
|
||||||
if x.area:
|
sheet['f'+num] = x.endtime
|
||||||
sheet['e'+num] = x.area.name
|
sheet['g'+num] = x.checkname.name
|
||||||
sheet['f'+num] = '正常' if x.state==1 else '异常'
|
sheet['h'+num] = x.checkquestion
|
||||||
sheet['g'+num] = 'https://safeyun.ctcshe.com/miniprogram/equipment?id='+str(x.id)
|
sheet['i'+num] = x.get_taskstate_display()
|
||||||
|
sheet['j'+num] = x.zguser.name if x.zguser else None
|
||||||
|
sheet['k'+num] = x.zgyq
|
||||||
|
sheet['l'+num] = x.zgjg
|
||||||
|
sheet['m'+num] = x.yanshouren.name if x.yanshouren else None
|
||||||
|
sheet['n'+num] = x.yanshou
|
||||||
|
if x.yhtp:
|
||||||
|
x1 = x.yhtp.split('?')
|
||||||
|
lenx1 = len(x1)
|
||||||
|
if lenx1>=1:
|
||||||
|
placeImg(sheet, x1[0], 'o'+num)
|
||||||
|
if lenx1>=2:
|
||||||
|
placeImg(sheet, x1[1], 'p'+num)
|
||||||
|
if lenx1>=3:
|
||||||
|
placeImg(sheet, x1[2], 'q'+num)
|
||||||
|
if x.zghtp:
|
||||||
|
x1 = x.zghtp.split('?')
|
||||||
|
lenx1 = len(x1)
|
||||||
|
if lenx1>=1:
|
||||||
|
placeImg(sheet, x1[0], 'r'+num)
|
||||||
|
if lenx1>=2:
|
||||||
|
placeImg(sheet, x1[1], 's'+num)
|
||||||
|
if lenx1>=3:
|
||||||
|
placeImg(sheet, x1[2], 't'+num)
|
||||||
|
|
||||||
#开始生成excel
|
#开始生成excel
|
||||||
sheet['b1'] = datetime.now().strftime('%Y%m%d%H%M%S')
|
sheet['b1'] = datetime.now().strftime('%Y%m%d%H%M%S')
|
||||||
|
@ -762,6 +793,8 @@ def exportxlsx(a,objs,pic=1):
|
||||||
res.write(output.getvalue())
|
res.write(output.getvalue())
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def exportyjdoc(vl):
|
def exportyjdoc(vl):
|
||||||
doc = DocxTemplate(dirname + "safesite/exportemp/fxbg.docx")
|
doc = DocxTemplate(dirname + "safesite/exportemp/fxbg.docx")
|
||||||
#整理数据
|
#整理数据
|
||||||
|
|
Binary file not shown.
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 2.2.8 on 2021-09-05 16:11
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('safesite', '0387_auto_20210826_2028'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='checktask',
|
||||||
|
name='tasktype',
|
||||||
|
field=models.IntegerField(choices=[(1, '每天一次'), (2, '每周一次'), (3, '每月一次'), (4, '每季度一次'), (5, '每半年一次'), (6, '每年一次')], default=1),
|
||||||
|
),
|
||||||
|
]
|
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 2.2.8 on 2021-09-05 16:12
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('safesite', '0388_auto_20210905_1611'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='checkjob',
|
||||||
|
name='taskstate',
|
||||||
|
field=models.IntegerField(choices=[(1, '正在整改中'), (2, '已整改完成'), (3, '任务关闭'), (4, '待执行')], default=1),
|
||||||
|
),
|
||||||
|
]
|
|
@ -1402,7 +1402,7 @@ class Checkjob(models.Model):
|
||||||
createdate = models.DateTimeField(default = timezone.now)#创建时间
|
createdate = models.DateTimeField(default = timezone.now)#创建时间
|
||||||
usecomp = models.ForeignKey(Partment,related_name='taskcomps',on_delete=models.CASCADE,null=True,blank=True)#创建公司
|
usecomp = models.ForeignKey(Partment,related_name='taskcomps',on_delete=models.CASCADE,null=True,blank=True)#创建公司
|
||||||
deletemark = models.IntegerField(default=1)#是否删除
|
deletemark = models.IntegerField(default=1)#是否删除
|
||||||
taskstate = models.IntegerField(default=1)#执行状态,1正在检查,2检查完毕,3,已关闭,4,未执行
|
taskstate = models.IntegerField(default=1, choices=taskstate_choice)#执行状态,1正在检查,2检查完毕,3,已关闭,4,未执行
|
||||||
starttime=models.DateTimeField(null=True, blank=True)#任务开始时间
|
starttime=models.DateTimeField(null=True, blank=True)#任务开始时间
|
||||||
endtime=models.DateTimeField(null=True, blank=True)#任务结束时间
|
endtime=models.DateTimeField(null=True, blank=True)#任务结束时间
|
||||||
jobstate = models.IntegerField(default=1)#检查任务状态,1可执行,2过期
|
jobstate = models.IntegerField(default=1)#检查任务状态,1可执行,2过期
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
{% if request|has_permission:'b_checkjob_del' %}
|
{% if request|has_permission:'b_checkjob_del' %}
|
||||||
<a id="deljob" class="easyui-linkbutton" onclick="deljob()" data-options="iconCls: 'fa-trash',plain:true">删除</a>
|
<a id="deljob" class="easyui-linkbutton" onclick="deljob()" data-options="iconCls: 'fa-trash',plain:true">删除</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
<a id="exportcheckjobexcel" onclick="exportcheckjobexcel()" class="easyui-linkbutton" data-options="iconCls: 'fa-download',plain:true">导出Excel</a>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -32,7 +33,7 @@
|
||||||
data-options="iconCls:'fa-search',resizable:true,modal:true,closed:true,border:false">
|
data-options="iconCls:'fa-search',resizable:true,modal:true,closed:true,border:false">
|
||||||
<div class="easyui-layout" style="width:100%;height:100%;">
|
<div class="easyui-layout" style="width:100%;height:100%;">
|
||||||
<div data-options="region:'center'" style="height:100%;text-align:right;">
|
<div data-options="region:'center'" style="height:100%;text-align:right;">
|
||||||
<form id='searchyhff' style="margin-right: 10px">
|
<form id='searchcheckjobff' style="margin-right: 10px">
|
||||||
<div style="margin-top:4px"><label>起始时间:</label><input name='qssj' id='qssjyh' style="width:300px"></div>
|
<div style="margin-top:4px"><label>起始时间:</label><input name='qssj' id='qssjyh' style="width:300px"></div>
|
||||||
<div style="margin-top:4px"><label>结束时间:</label><input name='jssj' id='jssjyh' style="width:300px"></div>
|
<div style="margin-top:4px"><label>结束时间:</label><input name='jssj' id='jssjyh' style="width:300px"></div>
|
||||||
|
|
||||||
|
@ -53,7 +54,7 @@
|
||||||
<script>
|
<script>
|
||||||
$(function () {
|
$(function () {
|
||||||
var option = $('#main').attr('value')
|
var option = $('#main').attr('value')
|
||||||
$("#searchyhff").form('clear');
|
$("#searchcheckjobff").form('clear');
|
||||||
})
|
})
|
||||||
$('#jobtab').datagrid({
|
$('#jobtab').datagrid({
|
||||||
url: 'api/checkproject?a=listall4',
|
url: 'api/checkproject?a=listall4',
|
||||||
|
@ -137,13 +138,13 @@
|
||||||
editable: false,
|
editable: false,
|
||||||
});
|
});
|
||||||
function yhsearch() {
|
function yhsearch() {
|
||||||
var querydata = $('#searchyhff').serializeJSON();
|
var querydata = $('#searchcheckjobff').serializeJSON();
|
||||||
$('#sdg_job').dialog('close')
|
$('#sdg_job').dialog('close')
|
||||||
$('#jobtab').datagrid('load', querydata);
|
$('#jobtab').datagrid('load', querydata);
|
||||||
|
|
||||||
}
|
}
|
||||||
function reset() {
|
function reset() {
|
||||||
$('#searchyhff').form('clear')
|
$('#searchcheckjobff').form('clear')
|
||||||
$('#jobtab').datagrid('options').queryParams = {
|
$('#jobtab').datagrid('options').queryParams = {
|
||||||
a:'listall4'
|
a:'listall4'
|
||||||
}
|
}
|
||||||
|
@ -222,5 +223,11 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function exportcheckjobexcel() {
|
||||||
|
var querydata = $('#searchcheckjobff').serializeJSON();
|
||||||
|
let url = 'api/checkjob?a=exportexcel&' + parseParams(querydata)
|
||||||
|
window.open(url);
|
||||||
|
// $('<form method="post" action="' + url + '"></form>').appendTo('body').submit().remove();
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
|
@ -232,6 +232,7 @@ urlpatterns = [
|
||||||
path('api/safeitem/', views.apisafeitem),
|
path('api/safeitem/', views.apisafeitem),
|
||||||
path('api/safefeedback/', views.apisafefeedback),
|
path('api/safefeedback/', views.apisafefeedback),
|
||||||
path('api/countsafe/', viewsn.apicountsafe), # 安全数据统计
|
path('api/countsafe/', viewsn.apicountsafe), # 安全数据统计
|
||||||
|
path('api/checkjob/', views.apicheckjob),
|
||||||
|
|
||||||
|
|
||||||
path('api/examtestrate',views.apiexamtestrate),
|
path('api/examtestrate',views.apiexamtestrate),
|
||||||
|
|
|
@ -9098,12 +9098,16 @@ def apicheckjob(req):
|
||||||
res = HttpResponse()
|
res = HttpResponse()
|
||||||
res.write('数量超过200,请筛选后导出!')
|
res.write('数量超过200,请筛选后导出!')
|
||||||
return res
|
return res
|
||||||
objs = objs.order_by('-starttime').values('id','checktask__checktaskname','jobstate',
|
objs = objs.order_by('-starttime')
|
||||||
'starttime','endtime','yanshou','checkquestion','zguser__username','zgtime','yanshouren__name'
|
# .values('id',
|
||||||
'checktask__checktype__checktitle','checkname__username','checkname__name',
|
# 'checktask__checktaskname','jobstate',
|
||||||
'taskstate','checktask__checktime','createuser__username','createdate', 'taskstate__display', 'checktask__tasktype__display')
|
# 'starttime','endtime','yanshou','checkquestion','zguser__name','zgtime','yanshouren__name',
|
||||||
# res = exportxlsx('checkjob', objs)
|
# 'checktask__checktype__checktitle','checkname__username','checkname__name',
|
||||||
# return res
|
# 'taskstate','checktask__checktime','createuser__username','createdate', 'taskstate',
|
||||||
|
# 'checktask__tasktype', 'checktask__checkplace', 'checktask__checktype__checkcontent', 'yhtp', 'zghtp'
|
||||||
|
# )
|
||||||
|
res = exportxlsx('checkjob', objs)
|
||||||
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue