This commit is contained in:
commit
85c20e32e1
|
@ -2,7 +2,7 @@ from docxtpl import DocxTemplate, InlineImage
|
|||
from docx.shared import Mm, Inches, Pt
|
||||
from openpyxl import Workbook, load_workbook
|
||||
from openpyxl.drawing.image import Image
|
||||
from .models import User,Trouble,Dickey,Partment,Dicclass,Train,Drill,TroubleAccess,Group,Yjyc,ExamPaper,ExamPaperDetail,Question,Operation,Operzyry,Operspxq,Fxcs,Suggest,Suggestflow,Trainuser,Miss
|
||||
from .models import Checkjob, User,Trouble,Dickey,Partment,Dicclass,Train,Drill,TroubleAccess,Group,Yjyc,ExamPaper,ExamPaperDetail,Question,Operation,Operzyry,Operspxq,Fxcs,Suggest,Suggestflow,Trainuser,Miss
|
||||
from datetime import datetime,date
|
||||
import base64
|
||||
import os
|
||||
|
@ -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,6 +743,57 @@ def exportxlsx(a,objs,pic=1):
|
|||
res['Content-Disposition'] = 'attachment;filename='+filename+'.xlsx'
|
||||
res.write(output.getvalue())
|
||||
return res
|
||||
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.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')
|
||||
filename = '安全检查整改记录'
|
||||
output = BytesIO()
|
||||
wb.save(output)
|
||||
output.seek(0)
|
||||
res = HttpResponse(content_type='application/vnd.ms-excel')
|
||||
res['Content-Disposition'] = 'attachment;filename='+filename+'.xlsx'
|
||||
res.write(output.getvalue())
|
||||
return res
|
||||
|
||||
|
||||
|
||||
def exportyjdoc(vl):
|
||||
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),
|
||||
),
|
||||
]
|
|
@ -1360,6 +1360,14 @@ class Checktable(models.Model):
|
|||
|
||||
#检查任务
|
||||
class Checktask(models.Model):
|
||||
tasktype_choice = (
|
||||
(1, '每天一次'),
|
||||
(2, '每周一次'),
|
||||
(3, '每月一次'),
|
||||
(4, '每季度一次'),
|
||||
(5, '每半年一次'),
|
||||
(6, '每年一次'),
|
||||
)
|
||||
id=models.AutoField(primary_key=True)#主键
|
||||
checktaskname=models.CharField(max_length=300)#任务名
|
||||
checktype=models.ForeignKey(Checktable,on_delete=models.CASCADE)#关联检查表
|
||||
|
@ -1370,12 +1378,18 @@ class Checktask(models.Model):
|
|||
createdate = models.DateTimeField(default = timezone.now)#创建时间
|
||||
usecomp = models.ForeignKey(Partment,related_name='taskscomp',on_delete=models.CASCADE,null=True,blank=True)#创建公司
|
||||
deletemark = models.IntegerField(default=1)#是否删除
|
||||
tasktype = models.IntegerField(default=0)#任务执行频率(1每天,2每周,3每月,4每季度,5每半年,6每年)
|
||||
tasktype = models.IntegerField(default=1, choices=tasktype_choice)#任务执行频率(1每天,2每周,3每月,4每季度,5每半年,6每年)
|
||||
userlist = models.TextField(default='')#检查人列表
|
||||
zxstate = models.IntegerField(default=1)#1同时执行,2一个执行就执行
|
||||
taskstate = models.IntegerField(default=1)#是否暂停,1运行,2暂停
|
||||
|
||||
class Checkjob(models.Model):
|
||||
taskstate_choice = (
|
||||
(1, '正在整改中'),
|
||||
(2, '已整改完成'),
|
||||
(3, '任务关闭'),
|
||||
(4, '待执行')
|
||||
)
|
||||
id=models.AutoField(primary_key=True)#主键
|
||||
checktask=models.ForeignKey(Checktask,on_delete=models.CASCADE)#关联任务表
|
||||
checkname=models.ForeignKey(User,related_name='jianchas',on_delete=models.CASCADE)#检查人员
|
||||
|
@ -1388,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过期
|
||||
|
|
|
@ -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,16 +138,15 @@
|
|||
editable: false,
|
||||
});
|
||||
function yhsearch() {
|
||||
var querydata = $('#searchyhff').serializeJSON();
|
||||
querydata['a'] = 'listsearch'
|
||||
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:'listall'
|
||||
a:'listall4'
|
||||
}
|
||||
$('#jobtab').datagrid('load');
|
||||
|
||||
|
@ -223,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>
|
|
@ -6,8 +6,9 @@
|
|||
<a id="yanshou" onclick="yanshou()" class="easyui-linkbutton" data-options="iconCls: 'fa-download'">验收</a>
|
||||
{{/if}}
|
||||
<a iconCls="fa-close" class="easyui-linkbutton" onclick="closeForm()">关闭</a>
|
||||
<a iconCls="fa-download" class="easyui-linkbutton" onclick="exportcheckjobword()" data-options="{ iconCls: 'fa-download'}">导出</a>
|
||||
</div>
|
||||
<div data-options="region:'center'" style="height:100%;padding:15px 15px;">
|
||||
<div data-options="region:'center'" style="height:100%;padding:15px 15px;" id="checkjobdiv">
|
||||
<div style="text-align:center;font-size: 24px;font-weight: bold;margin-bottom: 20px;">{{checktask__checktaskname}}</div>
|
||||
<table class='detailtable' style="text-align:center;">
|
||||
<tr>
|
||||
|
@ -211,4 +212,7 @@
|
|||
}
|
||||
});
|
||||
}
|
||||
function exportcheckjobword(e) {
|
||||
$("#checkjobdiv").wordExport('安全检查整改记录');
|
||||
}
|
||||
</script>
|
|
@ -36,9 +36,9 @@
|
|||
data-options="label:'初次检查',currentText:'今天',closeText:'关闭',showSeconds:false" required=true />
|
||||
</div>
|
||||
<div style="margin-bottom:5px">
|
||||
<input id="checktabtitle" class="easyui-textbox" name="checktabtitle" style=" width: 480px;
|
||||
<input id="checktabtitlex" class="easyui-textbox" name="checktabtitle" style=" width: 480px;
|
||||
height: 40px
|
||||
" data-options="label:'检查项目'" required=true />
|
||||
" data-options="label:'检查表'" required=true />
|
||||
</div>
|
||||
<div style="margin-top:10px;margin-bottom:5px">
|
||||
<input id="checkplace" class="easyui-textbox" name="checkplace" style=" width: 480px;
|
||||
|
@ -55,7 +55,7 @@
|
|||
|
||||
|
||||
$(function () {
|
||||
$("#checktabtitle").combobox({
|
||||
$("#checktabtitlex").combobox({
|
||||
url: 'api/checkproject?a=checktablist',
|
||||
valueField: 'value',
|
||||
textField: 'text',
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -8664,6 +8664,9 @@ def checkprojects(req):
|
|||
|
||||
return HttpResponse(transjson(total, a), content_type="application/json")
|
||||
elif a == 'listall3':
|
||||
"""
|
||||
任务分配列表
|
||||
"""
|
||||
startnum,endnum = fenye(req)
|
||||
a = Checktask.objects.filter(usecomp=Partment.objects.get(partid=companyid), deletemark=1).order_by('-createdate')
|
||||
total = a.count()
|
||||
|
@ -8673,8 +8676,27 @@ def checkprojects(req):
|
|||
|
||||
return HttpResponse(transjson(total, a), content_type="application/json")
|
||||
elif a == 'listall4':
|
||||
"""
|
||||
检查工作列表
|
||||
"""
|
||||
startnum,endnum = fenye(req)
|
||||
a = Checkjob.objects.filter(usecomp=Partment.objects.get(partid=companyid),checkname__userid=userid,deletemark=1).order_by('-starttime')
|
||||
a = Checkjob.objects.filter(usecomp=Partment.objects.get(
|
||||
partid=companyid)).exclude(deletemark=0)
|
||||
qssj = req.GET.get('qssj')#开始时间
|
||||
jssj = req.GET.get('jssj')#结束时间
|
||||
checktabtitle = req.GET.get('checktabtitle')#检查表名
|
||||
checktaskname = req.GET.get('checktaskname')#任务名称
|
||||
checkername = req.GET.get('checkername', None)
|
||||
if qssj:
|
||||
a = a.filter(starttime__gte=qssj)
|
||||
if jssj:
|
||||
a = a.filter(starttime__lte=jssj)
|
||||
if checktabtitle:
|
||||
a = a.filter(checktask__checktype__id=checktabtitle)
|
||||
if checktaskname:
|
||||
a = a.filter(checktask__id=checktaskname)
|
||||
if checkername:
|
||||
a = a.filter(checkname__name=checkername)
|
||||
total = a.count()
|
||||
startnum, endnum = fenye(req)
|
||||
|
||||
|
@ -9046,6 +9068,48 @@ def checkprojects(req):
|
|||
return HttpResponse(transjson(total, a), content_type="application/json")
|
||||
|
||||
|
||||
def apicheckjob(req):
|
||||
a = req.GET.get('a')
|
||||
userid = req.session['userid']
|
||||
companyid = getcompany(userid)
|
||||
if a == 'exportexcel':
|
||||
"""
|
||||
检查工作列表导出
|
||||
"""
|
||||
objs = Checkjob.objects.filter(usecomp=Partment.objects.get(
|
||||
partid=companyid)).exclude(deletemark=0)
|
||||
qssj = req.GET.get('qssj', None)#开始时间
|
||||
jssj = req.GET.get('jssj', None)#结束时间
|
||||
checktabtitle = req.GET.get('checktabtitle', None)#检查表名
|
||||
checktaskname = req.GET.get('checktaskname', None)#任务名称
|
||||
checkername = req.GET.get('checkername', None)
|
||||
if qssj:
|
||||
objs = objs.filter(starttime__gte=qssj)
|
||||
if jssj:
|
||||
objs = objs.filter(starttime__lte=jssj)
|
||||
if checktabtitle:
|
||||
objs = objs.filter(checktask__checktype__id=checktabtitle)
|
||||
if checktaskname:
|
||||
objs = objs.filter(checktask__id=checktaskname)
|
||||
if checkername:
|
||||
objs = objs.filter(checkname__name=checkername)
|
||||
total = objs.count()
|
||||
if total > 200:
|
||||
res = HttpResponse()
|
||||
res.write('数量超过200,请筛选后导出!')
|
||||
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
|
||||
|
||||
|
||||
|
||||
@apicheck_login
|
||||
def apioffence(req):
|
||||
|
|
Loading…
Reference in New Issue