|
|
@@ -26,6 +26,8 @@ from apps.AppInfo.models import (
|
|
|
Video_data,GardenArea,Store_Manage,Areacrop,Sell_Manage,Person_Pick,QXZAutoswitch,Sightsee_Info,Pic_Info,
|
|
|
QXZ_Alarm_Log,Experts,Relations,QXZ_Alarm,QXZ_Conf,QXZ_Base_Info,QXZ_Default_Conf,QXZ_Info_Record)
|
|
|
from apps.Equipment.all_dict import qxz_dict
|
|
|
+import xlwt
|
|
|
+from io import BytesIO
|
|
|
|
|
|
|
|
|
# 地图
|
|
|
@@ -4382,4 +4384,94 @@ class Add_Qxz_Test(ListView):
|
|
|
print("<-----this qxz_base_info table re-create failed!----->")
|
|
|
|
|
|
|
|
|
- return HttpResponse("1")
|
|
|
+ return HttpResponse("1")
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+# 气象站数据导出接口
|
|
|
+class QXZ_Data_Export(ListView):
|
|
|
+ def get(self,request):
|
|
|
+ equip_id = request.GET.get('id')
|
|
|
+ print("请求数据的设备id:",equip_id)
|
|
|
+ f_tbegin = request.GET.get('begin')
|
|
|
+ f_tend = request.GET.get('end')
|
|
|
+ filename = request.GET.get('filename')
|
|
|
+ print("f_tbegin:", f_tbegin)
|
|
|
+ print("f_tend:", f_tend)
|
|
|
+ print("f_tbegin:", type(f_tbegin))
|
|
|
+ print("f_tend:", type(f_tend))
|
|
|
+ # 查询时间段
|
|
|
+ if f_tbegin:
|
|
|
+ begindate = re.findall(r"\d+\.?\d*", f_tbegin)
|
|
|
+ enddate = re.findall(r"\d+\.?\d*", f_tend)
|
|
|
+ start_date = datetime.date(int(begindate[0]), int(begindate[1]), int(begindate[2]))
|
|
|
+ end_date = datetime.date(int(enddate[0]), int(enddate[1]), int(enddate[2]))
|
|
|
+ print("start_date:", start_date)
|
|
|
+ print("end_date:", end_date)
|
|
|
+ sta1 = QXZdata.objects.filter(equip_id=equip_id, upl_time__range=(start_date, end_date))
|
|
|
+ print("sta1:", sta1)
|
|
|
+ sta2 = [{"equip_name": x.equip_id.equip_name,
|
|
|
+ "qxz_data": eval(x.qxz_data)["data"],
|
|
|
+ "upl_time": x.upl_time.strftime("%Y-%m-%d %H:%M:%S")} for x in sta1]
|
|
|
+ # 查询全部
|
|
|
+ else:
|
|
|
+ sta1 = QXZdata.objects.filter(equip_id=equip_id)
|
|
|
+ print("sta1:",sta1)
|
|
|
+ sta2 = [{"equip_name": x.equip_id.equip_name,
|
|
|
+ "qxz_data": eval(x.qxz_data)["data"],
|
|
|
+ "upl_time": x.upl_time.strftime("%Y-%m-%d %H:%M:%S")} for x in sta1]
|
|
|
+ # print(sta2)
|
|
|
+ try:
|
|
|
+ # 遍历标题
|
|
|
+ title = []
|
|
|
+ for aaa in sta2[0]['qxz_data']:
|
|
|
+ # print(qxz_dict[aaa['eNum']][1])
|
|
|
+ title.append(qxz_dict[aaa['eNum']][1]+aaa['eKey'])
|
|
|
+ title.append("上报时间")
|
|
|
+ print(title)
|
|
|
+ # print(sta2[0]['qxz_data'])
|
|
|
+ except:
|
|
|
+ book = xlwt.Workbook() # 创建一个excel对象
|
|
|
+ sheet = book.add_sheet('Sheet1',cell_overwrite_ok=True) # 添加一个sheet页
|
|
|
+ sheet.write(0,0,"错误的时间段") # 将title数组中的字段写入到0行i列中
|
|
|
+ # 写出到IO
|
|
|
+ output = BytesIO()
|
|
|
+ book.save(output)
|
|
|
+ # 重新定位到开始
|
|
|
+ output.seek(0)
|
|
|
+ response = HttpResponse(content_type='application/vnd.ms-excel')
|
|
|
+ response['Content-Disposition'] = 'attachment;filename=%s.xls'%filename
|
|
|
+ response.write(output.getvalue())
|
|
|
+ return response
|
|
|
+
|
|
|
+
|
|
|
+ book = xlwt.Workbook() # 创建一个excel对象
|
|
|
+ sheet = book.add_sheet('Sheet1',cell_overwrite_ok=True) # 添加一个sheet页
|
|
|
+ for i in range(len(title)): # 遍历列
|
|
|
+ sheet.write(0,i,title[i]) # 将title数组中的字段写入到0行i列中
|
|
|
+
|
|
|
+ for x in range(len(sta2)): # 遍历列表
|
|
|
+ # print("行",x)
|
|
|
+ for xx in range(len(title)):
|
|
|
+ print("行",x+1,"列",xx)
|
|
|
+ # print(sta2[x]["qxz_data"][xx-1])
|
|
|
+ if xx+1 == len(title):
|
|
|
+ # print(x+1,xx,sta2[x]["upl_time"])
|
|
|
+ sheet.write(x+1,xx,sta2[x]["upl_time"])
|
|
|
+ break
|
|
|
+ # print(x+1,xx,sta2[x]["qxz_data"][xx]["eValue"]+" "+qxz_dict[sta2[x]["qxz_data"][xx]["eNum"]][2])
|
|
|
+ sheet.write(x+1,xx,sta2[x]["qxz_data"][xx]["eValue"]+" "+qxz_dict[sta2[x]["qxz_data"][xx]["eNum"]][2])
|
|
|
+
|
|
|
+ # 写出到IO
|
|
|
+ output = BytesIO()
|
|
|
+ book.save(output)
|
|
|
+ # 重新定位到开始
|
|
|
+ output.seek(0)
|
|
|
+ response = HttpResponse(content_type='application/vnd.ms-excel')
|
|
|
+ response['Content-Disposition'] = 'attachment;filename=%s.xls'%filename
|
|
|
+ response.write(output.getvalue())
|
|
|
+ return response
|
|
|
+
|
|
|
+
|
|
|
+ def post(self,request):
|
|
|
+ pass
|