diff --git a/mysite/settings.py b/mysite/settings.py index 01ffba4e..aa157605 100644 --- a/mysite/settings.py +++ b/mysite/settings.py @@ -85,7 +85,7 @@ DATABASES = { 'ENGINE': 'django.db.backends.postgresql', 'NAME': 'safedb', 'USER':'postgres', - 'PASSWORD':'0000', + 'PASSWORD':'cTc1111Qa', 'HOST':'114.115.210.98', 'PORT':'5432', 'CONN_MAX_AGE': 600, @@ -224,4 +224,4 @@ LOGGING = { 'propagate': True }, } -} \ No newline at end of file +} diff --git a/safesite/export.py b/safesite/export.py index 078dc144..9cd9e0d6 100644 --- a/safesite/export.py +++ b/safesite/export.py @@ -609,7 +609,7 @@ def exportxlsx(a,objs): res['Content-Disposition'] = 'attachment;filename='+filename+'.xlsx' res.write(output.getvalue()) return res - elif a == 'xj': + elif a == 'xj':#巡检记录 #查询数据 xjlist = objs.values('id','state','content','creattime','equipment__num','equipment__name','equipment__area__name','user__name','user__ubelongpart__partname','trouble__yhzt','trouble__yhnum','trouble__yhms') wb = load_workbook(dirname + 'safesite/exportemp/xj.xlsx') @@ -637,6 +637,28 @@ def exportxlsx(a,objs): res['Content-Disposition'] = 'attachment;filename='+filename+'.xlsx' res.write(output.getvalue()) return res + elif a == 'equipment':#设备 + #查询数据 + wb = load_workbook(dirname + 'safesite/exportemp/equipment.xlsx') + sheet = wb.active + for i, x in enumerate(objs): + num = str(i+3) + sheet['a'+num] = x.name + sheet['b'+num] = x.catename + sheet['c'+num] = x.type + sheet['d'+num] = x.area.name + sheet['e'+num] = '正常' if x.state==1 else '异常' + sheet['f'+num] = 'https://safeyun.ctcshe.com/miniprogram/equipment?id='+str(x.id) + nowtime = datetime.now().strftime('%Y%m%d%H%M%S') + sheet['b1'] = nowtime + filename = 'SBS' + nowtime + 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") diff --git a/safesite/exportemp/equipment.xlsx b/safesite/exportemp/equipment.xlsx new file mode 100644 index 00000000..04eab477 Binary files /dev/null and b/safesite/exportemp/equipment.xlsx differ diff --git a/safesite/exportemp/~$equipment.xlsx b/safesite/exportemp/~$equipment.xlsx new file mode 100644 index 00000000..e69de29b diff --git a/safesite/static/safesite/muban/安全生产管理系统-国检集团.docx b/safesite/static/safesite/muban/安全生产管理系统-国检集团.docx new file mode 100644 index 00000000..4db07147 Binary files /dev/null and b/safesite/static/safesite/muban/安全生产管理系统-国检集团.docx differ diff --git a/safesite/templates/equipment.html b/safesite/templates/equipment.html index bdf61857..95ef4534 100644 --- a/safesite/templates/equipment.html +++ b/safesite/templates/equipment.html @@ -29,6 +29,7 @@ 查询 + 导出Excel @@ -254,9 +255,6 @@ else { $.messager.alert('提示', '未选择数据!'); } - } - function exportsbexcel(){ - } function sbsearch(){ var querydata = $('#searchsbff').serializeJSON(); @@ -264,6 +262,11 @@ $('#sbtable').datagrid('load',querydata); //$('
').appendTo('body').submit().remove(); } + function exportsbexcel() { + var querydata = $('#searchsbff').serializeJSON(); + let url = 'api/equipment?a=listall&b=exportexcel&'+parseParams(querydata) + $('').appendTo('body').submit().remove(); + } function addsb(){ $('#sbff').form('clear') $('#sbtable').datagrid('clearSelections'); diff --git a/safesite/views.py b/safesite/views.py index 57d89dc8..228654dc 100644 --- a/safesite/views.py +++ b/safesite/views.py @@ -5371,19 +5371,22 @@ def apiequipment(req): userid = req.session['userid'] companyid = getcompany(userid) if a=='listall': - a = Equipment.objects.filter(deletemark=1,usecomp__partid=companyid) + objs = Equipment.objects.filter(deletemark=1,usecomp__partid=companyid) if req.GET.get('area',False): - a = a.filter(area__id=req.GET.get('area')) + objs = objs.filter(area__id=req.GET.get('area')) if req.GET.get('cate'): - a = a.filter(cate__dickeyid=req.GET.get('cate')) + objs = objs.filter(cate__dickeyid=req.GET.get('cate')) if req.GET.get('state'): - a = a.filter(state=req.GET.get('state')) + objs = objs.filter(state=req.GET.get('state')) if req.GET.get('name'): - a = a.filter(name__contains=req.GET.get('name')) - total = a.count() + objs = objs.filter(name__contains=req.GET.get('name')) + if req.GET.get('b',None) == 'exportexcel': + res = exportxlsx('equipment',objs)#导出设备列表 + return res + total = objs.count() startnum,endnum=fenye(req) - a = a.order_by('num')[startnum:endnum].values('id','num','name','type','oem','udate','place','istz','iskey','state','cate__dickeyname','area__name') - return HttpResponse(transjson(total,a),content_type="application/json") + objs = objs.order_by('num')[startnum:endnum].values('id','num','name','type','oem','udate','place','istz','iskey','state','cate__dickeyname','area__name') + return HttpResponse(transjson(total,objs),content_type="application/json") elif a == 'update': data = json.loads(req.body.decode('utf-8')) id = data['id']