export sbs

This commit is contained in:
caoqianming 2019-11-14 11:23:53 +08:00
parent cc3ff02701
commit 282090a8fc
7 changed files with 42 additions and 14 deletions

View File

@ -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
},
}
}
}

View File

@ -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")

Binary file not shown.

View File

View File

@ -29,6 +29,7 @@
<label>设备名称</label><input name='name' id='sname'
class="easyui-textbox" >
<a id="sbsearch" onclick="sbsearch()" class="easyui-linkbutton" data-options="iconCls: 'fa-search',plain:true">查询</a>
<a id="exportsbexcel" onclick="exportsbexcel()" class="easyui-linkbutton" data-options="iconCls: 'fa-download',plain:true">导出Excel</a>
</form>
</div>
@ -254,9 +255,6 @@
else {
$.messager.alert('提示', '未选择数据!');
}
}
function exportsbexcel(){
}
function sbsearch(){
var querydata = $('#searchsbff').serializeJSON();
@ -264,6 +262,11 @@
$('#sbtable').datagrid('load',querydata);
//$('<form method="post" action="' + url + '"></form>').appendTo('body').submit().remove();
}
function exportsbexcel() {
var querydata = $('#searchsbff').serializeJSON();
let url = 'api/equipment?a=listall&b=exportexcel&'+parseParams(querydata)
$('<form method="post" action="' + url + '"></form>').appendTo('body').submit().remove();
}
function addsb(){
$('#sbff').form('clear')
$('#sbtable').datagrid('clearSelections');

View File

@ -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']