导出检查记录excel

This commit is contained in:
caoqianming 2021-09-05 17:40:02 +08:00
parent cd300971eb
commit d62c484c32
8 changed files with 102 additions and 21 deletions

View File

@ -256,6 +256,14 @@ def exportdoc(a,id):
import re
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):
if a =='yh':
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.write(output.getvalue())
return res
elif a == 'chekjob':
elif a == 'checkjob':
#查询数据
wb = load_workbook(dirname + 'safesite/exportemp/checkjob.xlsx')
sheet = wb.active
for i, x in enumerate(objs):
num = str(i+3)
sheet['a'+num] = x.num
sheet['b'+num] = x.name
if x.cate:
sheet['c'+num] = x.cate.dickeyname
sheet['d'+num] = x.type
if x.area:
sheet['e'+num] = x.area.name
sheet['f'+num] = '正常' if x.state==1 else '异常'
sheet['g'+num] = 'https://safeyun.ctcshe.com/miniprogram/equipment?id='+str(x.id)
sheet['a'+num] = x.checktask.checktype.checktitle
sheet['b'+num] = x.checktask.get_tasktype_display()
sheet['c'+num] = x.checktask.checkplace
sheet['d'+num] = x.checktask.checktype.checkcontent
sheet['e'+num] = x.starttime
sheet['f'+num] = x.endtime
sheet['g'+num] = x.checkname.name
sheet['h'+num] = x.checkquestion
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
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())
return res
def exportyjdoc(vl):
doc = DocxTemplate(dirname + "safesite/exportemp/fxbg.docx")
#整理数据

Binary file not shown.

View File

@ -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),
),
]

View File

@ -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),
),
]

View File

@ -1402,7 +1402,7 @@ class Checkjob(models.Model):
createdate = models.DateTimeField(default = timezone.now)#创建时间
usecomp = models.ForeignKey(Partment,related_name='taskcomps',on_delete=models.CASCADE,null=True,blank=True)#创建公司
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)#任务开始时间
endtime=models.DateTimeField(null=True, blank=True)#任务结束时间
jobstate = models.IntegerField(default=1)#检查任务状态1可执行2过期

View File

@ -22,6 +22,7 @@
{% if request|has_permission:'b_checkjob_del' %}
<a id="deljob" class="easyui-linkbutton" onclick="deljob()" data-options="iconCls: 'fa-trash',plain:true">删除</a>
{% 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">
<div class="easyui-layout" style="width:100%;height:100%;">
<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='jssj' id='jssjyh' style="width:300px"></div>
@ -53,7 +54,7 @@
<script>
$(function () {
var option = $('#main').attr('value')
$("#searchyhff").form('clear');
$("#searchcheckjobff").form('clear');
})
$('#jobtab').datagrid({
url: 'api/checkproject?a=listall4',
@ -137,13 +138,13 @@
editable: false,
});
function yhsearch() {
var querydata = $('#searchyhff').serializeJSON();
var querydata = $('#searchcheckjobff').serializeJSON();
$('#sdg_job').dialog('close')
$('#jobtab').datagrid('load', querydata);
}
function reset() {
$('#searchyhff').form('clear')
$('#searchcheckjobff').form('clear')
$('#jobtab').datagrid('options').queryParams = {
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>

View File

@ -232,6 +232,7 @@ urlpatterns = [
path('api/safeitem/', views.apisafeitem),
path('api/safefeedback/', views.apisafefeedback),
path('api/countsafe/', viewsn.apicountsafe), # 安全数据统计
path('api/checkjob/', views.apicheckjob),
path('api/examtestrate',views.apiexamtestrate),

View File

@ -9098,12 +9098,16 @@ def apicheckjob(req):
res = HttpResponse()
res.write('数量超过200,请筛选后导出!')
return res
objs = objs.order_by('-starttime').values('id','checktask__checktaskname','jobstate',
'starttime','endtime','yanshou','checkquestion','zguser__username','zgtime','yanshouren__name'
'checktask__checktype__checktitle','checkname__username','checkname__name',
'taskstate','checktask__checktime','createuser__username','createdate', 'taskstate__display', 'checktask__tasktype__display')
# res = exportxlsx('checkjob', objs)
# return res
objs = objs.order_by('-starttime')
# .values('id',
# 'checktask__checktaskname','jobstate',
# 'starttime','endtime','yanshou','checkquestion','zguser__name','zgtime','yanshouren__name',
# 'checktask__checktype__checktitle','checkname__username','checkname__name',
# 'taskstate','checktask__checktime','createuser__username','createdate', 'taskstate',
# 'checktask__tasktype', 'checktask__checkplace', 'checktask__checktype__checkcontent', 'yhtp', 'zghtp'
# )
res = exportxlsx('checkjob', objs)
return res