Commit 75f2203e authored by chenying's avatar chenying

6.15修改下载仓库数据接口

parent c3747a59
...@@ -20,20 +20,20 @@ public class WarehouseExcel { ...@@ -20,20 +20,20 @@ public class WarehouseExcel {
private Logger logger = LoggerFactory.getLogger(WarehouseExcel.class); private Logger logger = LoggerFactory.getLogger(WarehouseExcel.class);
//导出的文件名 //导出的文件名
private String fileName; // private String fileName;
private String userName; private String userName;
private HttpServletResponse response; private HttpServletResponse response;
private List<ResultWarehouseNoAndTDLSNAndTimeVo> resultWarehouseNoAndTDLSNAndTimeVo; private ResultWarehouseNoAndTDLSNAndTimeVo resultWarehouseNoAndTDLSNAndTimeVo;
// private List<DownloadWarehouseVo> downloadWarehouseVos; // private List<DownloadWarehouseVo> downloadWarehouseVos;
public WarehouseExcel(String fileName, List<ResultWarehouseNoAndTDLSNAndTimeVo> resultWarehouseNoAndTDLSNAndTimeVo , String userName, HttpServletResponse response) { public WarehouseExcel( ResultWarehouseNoAndTDLSNAndTimeVo resultWarehouseNoAndTDLSNAndTimeVo , String userName, HttpServletResponse response) {
this.userName = userName; this.userName = userName;
this.resultWarehouseNoAndTDLSNAndTimeVo=resultWarehouseNoAndTDLSNAndTimeVo; this.resultWarehouseNoAndTDLSNAndTimeVo=resultWarehouseNoAndTDLSNAndTimeVo;
this.fileName = fileName; // this.fileName = fileName;
this.response = response; this.response = response;
// this.downloadWarehouseVos=downloadWarehouseVos; // this.downloadWarehouseVos=downloadWarehouseVos;
} }
...@@ -45,7 +45,7 @@ public class WarehouseExcel { ...@@ -45,7 +45,7 @@ public class WarehouseExcel {
// 创建工作簿对象 // 创建工作簿对象
HSSFWorkbook workbook = new HSSFWorkbook(); HSSFWorkbook workbook = new HSSFWorkbook();
try { try {
HSSFSheet sheet = workbook.createSheet("仓库温湿度观测记录表"); // 创建工作表 HSSFSheet sheet = workbook.createSheet(resultWarehouseNoAndTDLSNAndTimeVo.getWarehouseNo()+"仓库温湿度观测记录表"); // 创建工作表
HSSFCellStyle style = getStyle(workbook); HSSFCellStyle style = getStyle(workbook);
/* /*
...@@ -61,7 +61,7 @@ public class WarehouseExcel { ...@@ -61,7 +61,7 @@ public class WarehouseExcel {
//设置列的格式 //设置列的格式
cell1.setCellStyle(rowStyle1); cell1.setCellStyle(rowStyle1);
//将标题添加到列中 //将标题添加到列中
cell1.setCellValue(new HSSFRichTextString("仓库温湿度观测记录表")); cell1.setCellValue(new HSSFRichTextString(resultWarehouseNoAndTDLSNAndTimeVo.getWarehouseNo()+"仓库温湿度观测记录表-"+resultWarehouseNoAndTDLSNAndTimeVo.getTDLSN()));
} }
//设置行高 //设置行高
row1.setHeight((short) (30 * 20)); row1.setHeight((short) (30 * 20));
...@@ -69,150 +69,146 @@ public class WarehouseExcel { ...@@ -69,150 +69,146 @@ public class WarehouseExcel {
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 6)); sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 6));
int rowCount=1; int rowCount=1;
for (int a=0;a<resultWarehouseNoAndTDLSNAndTimeVo.size();a++){ /*
/* * 创建第二行
* 创建第二行 * */
* */ HSSFRow row2 = sheet.createRow((short) rowCount);
HSSFRow row2 = sheet.createRow((short) rowCount); HSSFCell cell2 = null;
HSSFCell cell2 = null; HSSFCellStyle rowStyle2 = getStyle(workbook);
HSSFCellStyle rowStyle2 = getStyle(workbook); cell2 = row2.createCell(0);
cell2 = row2.createCell(0); cell2.setCellValue("年度");
cell2.setCellValue("年度"); cell2.setCellStyle(rowStyle2);
cell2.setCellStyle(rowStyle2); cell2 = row2.createCell(1);
cell2 = row2.createCell(1); cell2.setCellValue("");
cell2.setCellValue(""); cell2.setCellStyle(rowStyle2);
cell2.setCellStyle(rowStyle2); for (int n = 2; n < 6; n++) {
for (int n = 2; n < 6; n++) { cell2 = row2.createCell(n);
cell2 = row2.createCell(n); //设置列的格式
//设置列的格式
cell2.setCellStyle(rowStyle2);
//将标题添加到列中
cell2.setCellValue("库房适宜温度为"+resultWarehouseNoAndTDLSNAndTimeVo.get(a).getTemMin()+"℃-"+resultWarehouseNoAndTDLSNAndTimeVo.get(a).getTemMax()+"℃,湿度保持"+resultWarehouseNoAndTDLSNAndTimeVo.get(a).getHumidityMin()+"%-"+resultWarehouseNoAndTDLSNAndTimeVo.get(a).getHumidityMax()+"%,超标要做必要调节。");
sheet.addMergedRegion(new CellRangeAddress(rowCount, rowCount, 2, 5));
}
cell2 = row2.createCell(6);
cell2.setCellValue("记录人:"+userName);
cell2.setCellStyle(rowStyle2); cell2.setCellStyle(rowStyle2);
row2.setHeight((short) (26 * 20)); //将标题添加到列中
cell2.setCellValue("库房适宜温度为"+resultWarehouseNoAndTDLSNAndTimeVo.getTemMin()+"℃-"+resultWarehouseNoAndTDLSNAndTimeVo.getTemMax()+"℃,湿度保持"+resultWarehouseNoAndTDLSNAndTimeVo.getHumidityMin()+"%-"+resultWarehouseNoAndTDLSNAndTimeVo.getHumidityMax()+"%,超标要做必要调节。");
sheet.addMergedRegion(new CellRangeAddress(rowCount, rowCount, 2, 5));
}
cell2 = row2.createCell(6);
cell2.setCellValue("记录人:"+userName);
cell2.setCellStyle(rowStyle2);
row2.setHeight((short) (26 * 20));
/* /*
* 创建第三行 * 创建第三行
* */ * */
rowCount=rowCount+1; rowCount=rowCount+1;
HSSFRow row3 = sheet.createRow((short) rowCount); HSSFRow row3 = sheet.createRow((short) rowCount);
HSSFCell cell3 = null; HSSFCell cell3 = null;
HSSFCellStyle rowStyle3 = getStyle(workbook); HSSFCellStyle rowStyle3 = getStyle(workbook);
for (int n = 0; n < 3; n++) { for (int n = 0; n < 3; n++) {
cell3 = row3.createCell(n); cell3 = row3.createCell(n);
cell3.setCellStyle(rowStyle3);
//将标题添加到列中
cell3.setCellValue("采样时间");
sheet.addMergedRegion(new CellRangeAddress(rowCount, rowCount, 0, 2));
}
cell3 = row3.createCell(3);
cell3.setCellValue("天气");
cell3.setCellStyle(rowStyle3);
cell3 = row3.createCell(4);
cell3.setCellValue("温度");
cell3.setCellStyle(rowStyle3);
cell3 = row3.createCell(5);
cell3.setCellValue("湿度");
cell3.setCellStyle(rowStyle3);
cell3 = row3.createCell(6);
cell3.setCellValue("是否预警");
cell3.setCellStyle(rowStyle3); cell3.setCellStyle(rowStyle3);
row3.setHeight((short) (26 * 20)); //将标题添加到列中
cell3.setCellValue("采样时间");
sheet.addMergedRegion(new CellRangeAddress(rowCount, rowCount, 0, 2));
}
cell3 = row3.createCell(3);
cell3.setCellValue("天气");
cell3.setCellStyle(rowStyle3);
cell3 = row3.createCell(4);
cell3.setCellValue("温度");
cell3.setCellStyle(rowStyle3);
cell3 = row3.createCell(5);
cell3.setCellValue("湿度");
cell3.setCellStyle(rowStyle3);
cell3 = row3.createCell(6);
cell3.setCellValue("是否预警");
cell3.setCellStyle(rowStyle3);
row3.setHeight((short) (26 * 20));
/** 创建第四行 /** 创建第四行
* */ * */
rowCount=rowCount+1; rowCount=rowCount+1;
HSSFRow row4= sheet.createRow((short) rowCount); HSSFRow row4= sheet.createRow((short) rowCount);
HSSFCell cell4 = null; HSSFCell cell4 = null;
HSSFCellStyle rowStyle4 = getStyle(workbook); HSSFCellStyle rowStyle4 = getStyle(workbook);
cell4 = row4.createCell(0); cell4 = row4.createCell(0);
cell4.setCellValue("月"); cell4.setCellValue("月");
cell4.setCellStyle(rowStyle4); cell4.setCellStyle(rowStyle4);
cell4 = row4.createCell(1); cell4 = row4.createCell(1);
cell4.setCellValue("日"); cell4.setCellValue("日");
cell4.setCellStyle(rowStyle4); cell4.setCellStyle(rowStyle4);
cell4 = row4.createCell(2); cell4 = row4.createCell(2);
cell4.setCellValue("时分"); cell4.setCellValue("时分");
cell4.setCellStyle(rowStyle4); cell4.setCellStyle(rowStyle4);
cell4 = row4.createCell(3); cell4 = row4.createCell(3);
cell4.setCellValue("天气"); cell4.setCellValue("天气");
cell4.setCellStyle(rowStyle4); cell4.setCellStyle(rowStyle4);
cell4 = row4.createCell(4); cell4 = row4.createCell(4);
cell4.setCellValue("温度"); cell4.setCellValue("温度");
cell4.setCellStyle(rowStyle4); cell4.setCellStyle(rowStyle4);
cell4 = row4.createCell(5); cell4 = row4.createCell(5);
cell4.setCellValue("湿度"); cell4.setCellValue("湿度");
cell4.setCellStyle(rowStyle4); cell4.setCellStyle(rowStyle4);
cell4 = row4.createCell(6); cell4 = row4.createCell(6);
cell4.setCellValue("是否预警"); cell4.setCellValue("是否预警");
cell4.setCellStyle(rowStyle4); cell4.setCellStyle(rowStyle4);
sheet.addMergedRegion(new CellRangeAddress(rowCount-1, rowCount, 3, 3)); sheet.addMergedRegion(new CellRangeAddress(rowCount-1, rowCount, 3, 3));
sheet.addMergedRegion(new CellRangeAddress(rowCount-1, rowCount, 4, 4)); sheet.addMergedRegion(new CellRangeAddress(rowCount-1, rowCount, 4, 4));
sheet.addMergedRegion(new CellRangeAddress(rowCount-1, rowCount, 5, 5)); sheet.addMergedRegion(new CellRangeAddress(rowCount-1, rowCount, 5, 5));
sheet.addMergedRegion(new CellRangeAddress(rowCount-1, rowCount, 6, 6)); sheet.addMergedRegion(new CellRangeAddress(rowCount-1, rowCount, 6, 6));
row4.setHeight((short) (26 * 20)); row4.setHeight((short) (26 * 20));
/** 循环创建仓库数据行数 /** 循环创建仓库数据行数
* */ * */
rowCount=rowCount+1; rowCount=rowCount+1;
if (resultWarehouseNoAndTDLSNAndTimeVo.get(a).getDownloadWarehouseVos().size()==0){ if (resultWarehouseNoAndTDLSNAndTimeVo.getDownloadWarehouseVos().size()==0){
HSSFRow row = sheet.createRow((short) rowCount); HSSFRow row = sheet.createRow((short) rowCount);
HSSFCell cell = null;
HSSFCellStyle rowStyle = getStyle(workbook);
for (int n = 0; n < 7; n++) {
cell = row.createCell(n);
//设置列的格式
cell.setCellStyle(rowStyle);
//将标题添加到列中
cell.setCellValue(new HSSFRichTextString(resultWarehouseNoAndTDLSNAndTimeVo.getGatewaySN()+"该时间段没有数据"));
}
//设置行高
row.setHeight((short) (26 * 20));
//合并单元格(参数1:起始行,参数2:截至行,参数3:起始列,参数4:截至列)
sheet.addMergedRegion(new CellRangeAddress(rowCount, rowCount, 0, 6));
}else{
HSSFCellStyle rowStyle = getStyle(workbook);
for(int i = 0;i<resultWarehouseNoAndTDLSNAndTimeVo.getDownloadWarehouseVos().size();i++) {
HSSFRow row = sheet.createRow((short) rowCount + i);
HSSFCell cell = null; HSSFCell cell = null;
HSSFCellStyle rowStyle = getStyle(workbook); Long time=Long.valueOf(resultWarehouseNoAndTDLSNAndTimeVo.getDownloadWarehouseVos().get(i).getTime());
for (int n = 0; n < 7; n++) { SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
cell = row.createCell(n); Date date=new Date(time);
//设置列的格式 cell2 = row2.createCell(1);
cell.setCellStyle(rowStyle); cell2.setCellValue(date.getYear());
//将标题添加到列中 cell2.setCellStyle(rowStyle);
cell.setCellValue(new HSSFRichTextString(resultWarehouseNoAndTDLSNAndTimeVo.get(a).getGatewaySN()+"该时间段没有数据"));
}
//设置行高
row.setHeight((short) (26 * 20));
//合并单元格(参数1:起始行,参数2:截至行,参数3:起始列,参数4:截至列)
sheet.addMergedRegion(new CellRangeAddress(rowCount, rowCount, 0, 6));
rowCount=rowCount+1;
}else{
HSSFCellStyle rowStyle = getStyle(workbook);
for(int i = 0;i<resultWarehouseNoAndTDLSNAndTimeVo.get(a).getDownloadWarehouseVos().size();i++) {
HSSFRow row = sheet.createRow((short) rowCount + i);
HSSFCell cell = null;
Long time=Long.valueOf(resultWarehouseNoAndTDLSNAndTimeVo.get(a).getDownloadWarehouseVos().get(i).getTime());
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date=new Date(time);
cell2 = row2.createCell(1);
cell2.setCellValue(date.getYear());
cell2.setCellStyle(rowStyle);
cell = row.createCell(0); cell = row.createCell(0);
cell.setCellValue(date.getMonth()+1); cell.setCellValue(date.getMonth()+1);
cell.setCellStyle(rowStyle); cell.setCellStyle(rowStyle);
cell = row.createCell(1); cell = row.createCell(1);
cell.setCellValue(date.getDay()); cell.setCellValue(date.getDay());
cell.setCellStyle(rowStyle); cell.setCellStyle(rowStyle);
cell = row.createCell(2); cell = row.createCell(2);
cell.setCellValue(date.getHours()+":"+date.getMinutes()); cell.setCellValue(date.getHours()+":"+date.getMinutes());
cell.setCellStyle(rowStyle); cell.setCellStyle(rowStyle);
cell = row.createCell(3); cell = row.createCell(3);
cell.setCellValue("-"); cell.setCellValue("-");
cell.setCellStyle(rowStyle); cell.setCellStyle(rowStyle);
cell = row.createCell(4); cell = row.createCell(4);
cell.setCellValue(resultWarehouseNoAndTDLSNAndTimeVo.get(a).getDownloadWarehouseVos().get(i).getTemperature()); cell.setCellValue(resultWarehouseNoAndTDLSNAndTimeVo.getDownloadWarehouseVos().get(i).getTemperature());
cell.setCellStyle(rowStyle); cell.setCellStyle(rowStyle);
cell = row.createCell(5); cell = row.createCell(5);
cell.setCellValue(resultWarehouseNoAndTDLSNAndTimeVo.get(a).getDownloadWarehouseVos().get(i).getHumidity()); cell.setCellValue(resultWarehouseNoAndTDLSNAndTimeVo.getDownloadWarehouseVos().get(i).getHumidity());
cell.setCellStyle(rowStyle); cell.setCellStyle(rowStyle);
cell = row.createCell(6); cell = row.createCell(6);
cell.setCellValue(resultWarehouseNoAndTDLSNAndTimeVo.get(a).getDownloadWarehouseVos().get(i).getAlarm()); cell.setCellValue(resultWarehouseNoAndTDLSNAndTimeVo.getDownloadWarehouseVos().get(i).getAlarm());
cell.setCellStyle(rowStyle); cell.setCellStyle(rowStyle);
row.setHeight((short) (26 * 20)); row.setHeight((short) (26 * 20));
}
} }
rowCount=rowCount+resultWarehouseNoAndTDLSNAndTimeVo.get(a).getDownloadWarehouseVos().size();
} }
sheet.setColumnWidth(0, 10 * 256); sheet.setColumnWidth(0, 10 * 256);
sheet.setColumnWidth(1, 10 * 256); sheet.setColumnWidth(1, 10 * 256);
......
...@@ -21,28 +21,29 @@ public class ResultWarehouseNoAndTDLSNAndTimeVo { ...@@ -21,28 +21,29 @@ public class ResultWarehouseNoAndTDLSNAndTimeVo {
private Float humidityMin; private Float humidityMin;
private String createTime; private Long createTime;
private String endTime; private Long endTime;
public String getCreateTime() { private List<DownloadWarehouseVo> downloadWarehouseVos;
public Long getCreateTime() {
return createTime; return createTime;
} }
public void setCreateTime(String createTime) { public void setCreateTime(Long createTime) {
this.createTime = createTime; this.createTime = createTime;
} }
public String getEndTime() { public Long getEndTime() {
return endTime; return endTime;
} }
public void setEndTime(String endTime) { public void setEndTime(Long endTime) {
this.endTime = endTime; this.endTime = endTime;
} }
private List<DownloadWarehouseVo> downloadWarehouseVos;
public List<DownloadWarehouseVo> getDownloadWarehouseVos() { public List<DownloadWarehouseVo> getDownloadWarehouseVos() {
return downloadWarehouseVos; return downloadWarehouseVos;
} }
......
...@@ -27,6 +27,6 @@ public interface TDLLogMapper { ...@@ -27,6 +27,6 @@ public interface TDLLogMapper {
Long getTimeByWarehouseNo(@Param("warehouseNo")String warehouseNo,@Param("gatewaySN")String gatewaySN); Long getTimeByWarehouseNo(@Param("warehouseNo")String warehouseNo,@Param("gatewaySN")String gatewaySN);
List<ResultWarehouseNoAndTDLSNAndTimeVo> getByWarehouseNoAndTDLSNAndTime(DownloadForWarehouseVo downloadForWarehouseVo); List<ResultWarehouseNoAndTDLSNAndTimeVo> getByWarehouseNoAndTime(DownloadForWarehouseVo downloadForWarehouseVo);
} }
...@@ -51,7 +51,7 @@ public class TDLLogService { ...@@ -51,7 +51,7 @@ public class TDLLogService {
return tdlLogMapper.getTimeByWarehouseNo(warehouseNo,SN); return tdlLogMapper.getTimeByWarehouseNo(warehouseNo,SN);
} }
public List<ResultWarehouseNoAndTDLSNAndTimeVo> getByWarehouseNoAndTDLSNAndTime(DownloadForWarehouseVo downloadForWarehouseVo){ public List<ResultWarehouseNoAndTDLSNAndTimeVo> getByWarehouseNoAndTime(DownloadForWarehouseVo downloadForWarehouseVo){
return tdlLogMapper.getByWarehouseNoAndTDLSNAndTime(downloadForWarehouseVo); return tdlLogMapper.getByWarehouseNoAndTime(downloadForWarehouseVo);
} }
} }
package com.example.tdl.web; package com.example.tdl.web;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.aliyun.oss.OSSClient; import com.aliyun.oss.OSSClient;
import com.example.tdl.common.WarehouseExcel; import com.example.tdl.common.WarehouseExcel;
import com.example.tdl.domain.dto.CommFeedback; import com.example.tdl.domain.dto.CommFeedback;
...@@ -17,7 +15,6 @@ import io.swagger.annotations.ApiImplicitParams; ...@@ -17,7 +15,6 @@ import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.shiro.SecurityUtils;
import org.influxdb.dto.Query; import org.influxdb.dto.Query;
import org.influxdb.dto.QueryResult; import org.influxdb.dto.QueryResult;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -56,12 +53,6 @@ public class DownloadController { ...@@ -56,12 +53,6 @@ public class DownloadController {
@Autowired @Autowired
private InfluxDBTemplate influxDBTemplate; private InfluxDBTemplate influxDBTemplate;
@Autowired
private InfoRedisService infoRedisService;
@Autowired
private TDLDeviceService tdlDeviceService;
@Autowired @Autowired
private I18nController i18n; private I18nController i18n;
...@@ -99,78 +90,74 @@ public class DownloadController { ...@@ -99,78 +90,74 @@ public class DownloadController {
fb.setMessage(i18n.getMessage(request,"Nonexistent")); fb.setMessage(i18n.getMessage(request,"Nonexistent"));
return gson.toJson(fb); return gson.toJson(fb);
} }
List<ResultWarehouseNoAndTDLSNAndTimeVo> resultWarehouseNoAndTDLSNAndTimeVos=tdlLogService.getByWarehouseNoAndTDLSNAndTime(downloadForWarehouseVo); List<ResultWarehouseNoAndTDLSNAndTimeVo> resultWarehouseNoAndTDLSNAndTimeVos=tdlLogService.getByWarehouseNoAndTime(downloadForWarehouseVo);
if (resultWarehouseNoAndTDLSNAndTimeVos.size()==0){ if (resultWarehouseNoAndTDLSNAndTimeVos.size()==0){
fb.setCode(0); fb.setCode(0);
fb.setMessage("没有数据"); fb.setMessage("没有数据");
return gson.toJson(fb); return gson.toJson(fb);
} }
String sqls=""; String sqls="";
String fileName = downloadForWarehouseVo.getWarehouseNo() + "仓库温湿度观测记录表-" + System.currentTimeMillis(); String fileName ="";
File file = new File("E:" + File.separator + fileName); String name="仓库温湿度观测记录"+System.currentTimeMillis();
File file = new File("E:" + File.separator + name);
if (!file.exists()) { if (!file.exists()) {
file.mkdir(); file.mkdir();
} }
for (int a=0;a<resultWarehouseNoAndTDLSNAndTimeVos.size();a++) { for (int a=0;a<resultWarehouseNoAndTDLSNAndTimeVos.size();a++) {
ResultWarehouseNoAndTDLSNAndTimeVo resultWarehouseNoAndTDLSNAndTimeVo=new ResultWarehouseNoAndTDLSNAndTimeVo(); ResultWarehouseNoAndTDLSNAndTimeVo resultWarehouseNoAndTDLSNAndTimeVo;
List<DownloadWarehouseVo> downloadWarehouseVos = new ArrayList<>(); resultWarehouseNoAndTDLSNAndTimeVo=resultWarehouseNoAndTDLSNAndTimeVos.get(a);
if (resultWarehouseNoAndTDLSNAndTimeVos.get(a).getEndTime() == null) { fileName =downloadForWarehouseVo.getWarehouseNo() + "仓库温湿度观测记录表-"+resultWarehouseNoAndTDLSNAndTimeVo.getTDLSN()+"-"+ + System.currentTimeMillis();
sqls = "SELECT \"b\", \"T\", \"h\" FROM \"tdl_policy\".\"" + resultWarehouseNoAndTDLSNAndTimeVos.get(a).getGatewayType() + "_" + resultWarehouseNoAndTDLSNAndTimeVos.get(a).getGatewaySN() + "\" WHERE (\"tdl\" = 'TDL-" + resultWarehouseNoAndTDLSNAndTimeVos.get(a).getTDLSN() + "') and time >= '" + resultWarehouseNoAndTDLSNAndTimeVos.get(a).getCreateTime() + "' ORDER BY time "; List<DownloadWarehouseVo> downloadWarehouseVos = null;
if (resultWarehouseNoAndTDLSNAndTimeVo.getEndTime() == null) {
sqls = "SELECT \"b\", \"T\", \"h\" FROM \"tdl_policy\".\"" + resultWarehouseNoAndTDLSNAndTimeVo.getGatewayType() + "_" + resultWarehouseNoAndTDLSNAndTimeVo.getGatewaySN() + "\" WHERE (\"tdl\" = 'TDL-" + resultWarehouseNoAndTDLSNAndTimeVo.getTDLSN() + "') and time >= " + resultWarehouseNoAndTDLSNAndTimeVo.getCreateTime()*1000000 + " ORDER BY time ";
} else { } else {
sqls = "SELECT \"b\", \"T\", \"h\" FROM \"tdl_policy\".\"" + resultWarehouseNoAndTDLSNAndTimeVos.get(a).getGatewayType() + "_" + resultWarehouseNoAndTDLSNAndTimeVos.get(a).getGatewaySN() + "\" WHERE (\"tdl\" = 'TDL-" + resultWarehouseNoAndTDLSNAndTimeVos.get(a).getTDLSN() + "') and time >= '" + resultWarehouseNoAndTDLSNAndTimeVos.get(a).getCreateTime() + "' and time<= '" + resultWarehouseNoAndTDLSNAndTimeVos.get(a).getEndTime() + "' ORDER BY time "; sqls = "SELECT \"b\", \"T\", \"h\" FROM \"tdl_policy\".\"" + resultWarehouseNoAndTDLSNAndTimeVo.getGatewayType() + "_" + resultWarehouseNoAndTDLSNAndTimeVo.getGatewaySN() + "\" WHERE (\"tdl\" = 'TDL-" + resultWarehouseNoAndTDLSNAndTimeVo.getTDLSN() + "') and time >= " + resultWarehouseNoAndTDLSNAndTimeVo.getCreateTime()*1000000 + " and time<= " + resultWarehouseNoAndTDLSNAndTimeVo.getEndTime()*1000000 + " ORDER BY time ";
} }
QueryResult queryResults = influxDBTemplate.query(new Query(sqls, database)); QueryResult queryResults = influxDBTemplate.query(new Query(sqls, database));
downloadWarehouseVos = getWarehouseData(queryResults); downloadWarehouseVos = getWarehouseData(queryResults);
if (downloadWarehouseVos.size()>0){ for (int i = 0; i < downloadWarehouseVos.size(); i++) {
for (int i = 0; i < downloadWarehouseVos.size(); i++) { if (downloadWarehouseVos.get(i).getTemperature() > resultWarehouseNoAndTDLSNAndTimeVos.get(a).getTemMax() ||
if (downloadWarehouseVos.get(i).getTemperature() > resultWarehouseNoAndTDLSNAndTimeVos.get(a).getTemMax() || downloadWarehouseVos.get(i).getTemperature() < resultWarehouseNoAndTDLSNAndTimeVos.get(a).getTemMin() ||
downloadWarehouseVos.get(i).getTemperature() < resultWarehouseNoAndTDLSNAndTimeVos.get(a).getTemMin() || downloadWarehouseVos.get(i).getHumidity() > resultWarehouseNoAndTDLSNAndTimeVos.get(a).getHumidityMax() ||
downloadWarehouseVos.get(i).getHumidity() > resultWarehouseNoAndTDLSNAndTimeVos.get(a).getHumidityMax() || downloadWarehouseVos.get(i).getHumidity() < resultWarehouseNoAndTDLSNAndTimeVos.get(a).getHumidityMin()) {
downloadWarehouseVos.get(i).getHumidity() < resultWarehouseNoAndTDLSNAndTimeVos.get(a).getHumidityMin()) { downloadWarehouseVos.get(i).setAlarm("报警");
downloadWarehouseVos.get(i).setAlarm("报警"); } else {
} else { downloadWarehouseVos.get(i).setAlarm("正常");
downloadWarehouseVos.get(i).setAlarm("正常");
}
} }
resultWarehouseNoAndTDLSNAndTimeVos.get(a).setDownloadWarehouseVos(downloadWarehouseVos); }
try { resultWarehouseNoAndTDLSNAndTimeVo.setDownloadWarehouseVos(downloadWarehouseVos);
WarehouseExcel warehouseExcel = new WarehouseExcel(fileName, resultWarehouseNoAndTDLSNAndTimeVos, user.getUserName(), response); try {
HSSFWorkbook wb = warehouseExcel.downloadExcel(); WarehouseExcel warehouseExcel = new WarehouseExcel(resultWarehouseNoAndTDLSNAndTimeVo, user.getUserName(), response);
if (wb != null) { HSSFWorkbook wb = warehouseExcel.downloadExcel();
request.setCharacterEncoding("utf-8"); if (wb != null) {
response.setCharacterEncoding("utf-8"); request.setCharacterEncoding("utf-8");
response.setContentType("application/vnd.ms-excel"); response.setCharacterEncoding("utf-8");
response.setHeader("Content-Disposition", "attachment; filename=" + fileName); response.setContentType("application/vnd.ms-excel");
OutputStream os = new FileOutputStream(new File(file + ".xls")); response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
wb.write(os); OutputStream os = new FileOutputStream(new File(file+File.separator+fileName + ".xls"));
os.flush(); wb.write(os);
os.close(); os.flush();
} else { os.close();
fb.setCode(0); } else {
fb.setMessage("上传失败");
}
} catch (Exception e) {
e.printStackTrace();
logger.info(e.toString());
fb.setCode(0); fb.setCode(0);
fb.setMessage("上传失败"); fb.setMessage("上传失败");
} }
}else{ } catch (Exception e) {
e.printStackTrace();
logger.info(e.toString());
fb.setCode(0); fb.setCode(0);
fb.setMessage("没有数据"); fb.setMessage("上传失败");
return gson.toJson(fb);
} }
} }
try { try {
ZipCompressUtil zipCom = new ZipCompressUtil(file + ".zip", file + ".xls"); ZipCompressUtil zipCom = new ZipCompressUtil(file + ".zip", file+"");
zipCom.zip(); zipCom.zip();
// OSSClient ossClient = AliyunOSSClientUtil.getOSSClient(); OSSClient ossClient = AliyunOSSClientUtil.getOSSClient();
// AliyunOSSClientUtil.uploadObject2OSS(ossClient, new File(file +".zip")); AliyunOSSClientUtil.uploadObject2OSS(ossClient, new File(file +".zip"));
if (new File(file + ".xls").delete()) { if (deleteFile(file)) {
new File(file+".zip").delete(); new File(file+".zip").delete();
fb.setCode(1); fb.setCode(1);
fb.setMessage("https://tdlcloud.oss-cn-shanghai.aliyuncs.com/warehouse/" + fileName + ".zip"); fb.setMessage("https://tdlcloud.oss-cn-shanghai.aliyuncs.com/warehouse/" + name + ".zip");
return gson.toJson(fb); return gson.toJson(fb);
} else { } else {
fb.setCode(0); fb.setCode(0);
...@@ -185,6 +172,30 @@ public class DownloadController { ...@@ -185,6 +172,30 @@ public class DownloadController {
return gson.toJson(fb); return gson.toJson(fb);
} }
/**
* 先根遍历序递归删除文件夹
*
* @param dirFile 要被删除的文件或者目录
* @return 删除成功返回true, 否则返回false
*/
public static boolean deleteFile(File dirFile) {
// 如果dir对应的文件不存在,则退出
if (!dirFile.exists()) {
return false;
}
if (dirFile.isFile()) {
return dirFile.delete();
} else {
for (File file : dirFile.listFiles()) {
deleteFile(file);
}
}
return dirFile.delete();
}
public List<DownloadWarehouseVo> getWarehouseData(QueryResult queryResult){ public List<DownloadWarehouseVo> getWarehouseData(QueryResult queryResult){
List<List<Object>> values = getValues(queryResult); List<List<Object>> values = getValues(queryResult);
List<DownloadWarehouseVo> downloadWarehouseVos = new ArrayList<>(); List<DownloadWarehouseVo> downloadWarehouseVos = new ArrayList<>();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment