Commit 87844b19 authored by zhuangzhuang's avatar zhuangzhuang

8.24--修改仓库下载接口

parent 563d88ca
...@@ -20,32 +20,30 @@ public class WarehouseExcel { ...@@ -20,32 +20,30 @@ 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 ResultWarehouseNoAndTDLSNAndTimeVo resultWarehouseNoAndTDLSNAndTimeVo; private ResultWarehouseNoAndTDLSNAndTimeVo resultWarehouseNoAndTDLSNAndTimeVo;
// private List<DownloadWarehouseVo> downloadWarehouseVos; // private List<DownloadWarehouseVo> downloadWarehouseVos;
public WarehouseExcel( ResultWarehouseNoAndTDLSNAndTimeVo resultWarehouseNoAndTDLSNAndTimeVo , String userName, HttpServletResponse response) {
public WarehouseExcel(String fileName, String userName, ResultWarehouseNoAndTDLSNAndTimeVo resultWarehouseNoAndTDLSNAndTimeVo) {
this.fileName = fileName;
this.userName = userName; this.userName = userName;
this.resultWarehouseNoAndTDLSNAndTimeVo=resultWarehouseNoAndTDLSNAndTimeVo; this.resultWarehouseNoAndTDLSNAndTimeVo = resultWarehouseNoAndTDLSNAndTimeVo;
// this.fileName = fileName;
this.response = response;
// this.downloadWarehouseVos=downloadWarehouseVos;
} }
/* /*
* 导出数据 * 导出数据
* */ * */
public HSSFWorkbook downloadExcel() throws Exception { public HSSFWorkbook downloadExcel() throws Exception {
// 创建工作簿对象 // 创建工作簿对象
HSSFWorkbook workbook = new HSSFWorkbook(); HSSFWorkbook workbook = new HSSFWorkbook();
try { try {
HSSFSheet sheet = workbook.createSheet(resultWarehouseNoAndTDLSNAndTimeVo.getWarehouseNo()+"仓库温湿度观测记录表"); // 创建工作表 HSSFSheet sheet = workbook.createSheet(fileName); // 创建工作表
HSSFCellStyle style = getStyle(workbook); HSSFCellStyle style = getStyle(workbook);
/* /*
...@@ -76,19 +74,22 @@ public class WarehouseExcel { ...@@ -76,19 +74,22 @@ public class WarehouseExcel {
HSSFCell cell2 = null; HSSFCell cell2 = null;
HSSFCellStyle rowStyle2 = getStyle(workbook); HSSFCellStyle rowStyle2 = getStyle(workbook);
cell2 = row2.createCell(0); cell2 = row2.createCell(0);
cell2.setCellValue("年度"); for (int n = 0; n < 3; n++) {
cell2.setCellStyle(rowStyle2); cell2 = row2.createCell(n);
cell2 = row2.createCell(1); //设置列的格式
cell2.setCellValue(""); cell2.setCellStyle(rowStyle2);
cell2.setCellStyle(rowStyle2); //将标题添加到列中
for (int n = 2; n < 6; n++) { cell2.setCellValue("年度:2018年");
}
sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 2));
for (int n = 3; n < 6; n++) {
cell2 = row2.createCell(n); cell2 = row2.createCell(n);
//设置列的格式 //设置列的格式
cell2.setCellStyle(rowStyle2); cell2.setCellStyle(rowStyle2);
//将标题添加到列中 //将标题添加到列中
cell2.setCellValue("库房适宜温度为"+resultWarehouseNoAndTDLSNAndTimeVo.getTemMin()+"℃-"+resultWarehouseNoAndTDLSNAndTimeVo.getTemMax()+"℃,湿度保持"+resultWarehouseNoAndTDLSNAndTimeVo.getHumidityMin()+"%-"+resultWarehouseNoAndTDLSNAndTimeVo.getHumidityMax()+"%,超标要做必要调节。"); cell2.setCellValue("库房适宜温度为"+resultWarehouseNoAndTDLSNAndTimeVo.getTemMin()+"℃-"+resultWarehouseNoAndTDLSNAndTimeVo.getTemMax()+"℃,湿度保持"+resultWarehouseNoAndTDLSNAndTimeVo.getHumidityMin()+"%-"+resultWarehouseNoAndTDLSNAndTimeVo.getHumidityMax()+"%,超标要做必要调节。");
sheet.addMergedRegion(new CellRangeAddress(rowCount, rowCount, 2, 5));
} }
sheet.addMergedRegion(new CellRangeAddress(1, 1, 3, 5));
cell2 = row2.createCell(6); cell2 = row2.createCell(6);
cell2.setCellValue("记录人:"+userName); cell2.setCellValue("记录人:"+userName);
cell2.setCellStyle(rowStyle2); cell2.setCellStyle(rowStyle2);
...@@ -106,8 +107,8 @@ public class WarehouseExcel { ...@@ -106,8 +107,8 @@ public class WarehouseExcel {
cell3.setCellStyle(rowStyle3); cell3.setCellStyle(rowStyle3);
//将标题添加到列中 //将标题添加到列中
cell3.setCellValue("采样时间"); cell3.setCellValue("采样时间");
sheet.addMergedRegion(new CellRangeAddress(rowCount, rowCount, 0, 2));
} }
sheet.addMergedRegion(new CellRangeAddress(2, 2, 0, 2));
cell3 = row3.createCell(3); cell3 = row3.createCell(3);
cell3.setCellValue("天气"); cell3.setCellValue("天气");
cell3.setCellStyle(rowStyle3); cell3.setCellStyle(rowStyle3);
...@@ -142,18 +143,18 @@ public class WarehouseExcel { ...@@ -142,18 +143,18 @@ public class WarehouseExcel {
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("湿度(%RH)");
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(2, 3, 3, 3));
sheet.addMergedRegion(new CellRangeAddress(rowCount-1, rowCount, 4, 4)); sheet.addMergedRegion(new CellRangeAddress(2, 3, 4, 4));
sheet.addMergedRegion(new CellRangeAddress(rowCount-1, rowCount, 5, 5)); sheet.addMergedRegion(new CellRangeAddress(2, 3, 5, 5));
sheet.addMergedRegion(new CellRangeAddress(rowCount-1, rowCount, 6, 6)); sheet.addMergedRegion(new CellRangeAddress(2, 3, 6, 6));
row4.setHeight((short) (26 * 20)); row4.setHeight((short) (26 * 20));
/** 循环创建仓库数据行数 /** 循环创建仓库数据行数
...@@ -213,10 +214,10 @@ public class WarehouseExcel { ...@@ -213,10 +214,10 @@ public class WarehouseExcel {
sheet.setColumnWidth(0, 10 * 256); sheet.setColumnWidth(0, 10 * 256);
sheet.setColumnWidth(1, 10 * 256); sheet.setColumnWidth(1, 10 * 256);
sheet.setColumnWidth(2, 10 * 256); sheet.setColumnWidth(2, 10 * 256);
sheet.setColumnWidth(3, 27 * 256); sheet.setColumnWidth(3, 35 * 256);
sheet.setColumnWidth(4, 27 * 256); sheet.setColumnWidth(4, 35 * 256);
sheet.setColumnWidth(5, 27 * 256); sheet.setColumnWidth(5, 35 * 256);
sheet.setColumnWidth(6, 27 * 256); sheet.setColumnWidth(6, 25* 256);
return workbook; return workbook;
}catch (Exception e) { }catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
......
package com.example.tdl.domain.vo; package com.example.tdl.domain.vo;
public class DownloadForWarehouseVo { public class DownloadForWarehouseVo {
private String startTime; private Long startTime;
private String stopTime; private Long stopTime;
private String warehouseNo; private String warehouseNo;
public String getStartTime() { public Long getStartTime() {
return startTime; return startTime;
} }
public void setStartTime(String startTime) { public void setStartTime(Long startTime) {
this.startTime = startTime; this.startTime = startTime;
} }
public String getStopTime() { public Long getStopTime() {
return stopTime; return stopTime;
} }
public void setStopTime(String stopTime) { public void setStopTime(Long stopTime) {
this.stopTime = stopTime; this.stopTime = stopTime;
} }
......
...@@ -35,7 +35,7 @@ public class AlarmController { ...@@ -35,7 +35,7 @@ public class AlarmController {
Gson gson=new Gson(); Gson gson=new Gson();
@Autowired @Autowired
private AlarmService alarmService=new AlarmService(); private AlarmService alarmService;
@Autowired @Autowired
private TokenRedisService tokenRedisService; private TokenRedisService tokenRedisService;
......
...@@ -513,7 +513,7 @@ public class DataController { ...@@ -513,7 +513,7 @@ public class DataController {
try { try {
String sqls = ""; String sqls = "";
if (resultCircuitVo.getEndTime() != null && resultCircuitVo.getEndTime() != 0) { if (resultCircuitVo.getEndTime() != null && resultCircuitVo.getEndTime() != 0) {
sqls = "SELECT \"tdl\",\"p\",\"T\",\"h\",\"a0\",\"a1\",\"ta\",\"bdlng\",\"bdlat\", FROM \"tdl_policy\".\""+device+"\" WHERE time >=" +startTime +" and time <=" +resultCircuitVo.getEndTime() * 1000000l+" ORDER BY time "; sqls = "SELECT \"tdl\",\"p\",\"T\",\"h\",\"a0\",\"a1\",\"ta\",\"bdlng\",\"bdlat\" FROM \"tdl_policy\".\""+device+"\" WHERE time >=" +startTime +" and time <=" +resultCircuitVo.getEndTime() * 1000000l+" ORDER BY time ";
} else { } else {
sqls = "SELECT \"tdl\",\"p\",\"T\",\"h\",\"a0\",\"a1\",\"ta\",\"bdlng\",\"bdlat\" FROM \"tdl_policy\".\""+device+"\" WHERE time >=" +startTime +" and time <=" +System.currentTimeMillis() * 1000000l+" ORDER BY time "; sqls = "SELECT \"tdl\",\"p\",\"T\",\"h\",\"a0\",\"a1\",\"ta\",\"bdlng\",\"bdlat\" FROM \"tdl_policy\".\""+device+"\" WHERE time >=" +startTime +" and time <=" +System.currentTimeMillis() * 1000000l+" ORDER BY time ";
} }
...@@ -579,6 +579,9 @@ public class DataController { ...@@ -579,6 +579,9 @@ public class DataController {
return gson.toJson(fb); return gson.toJson(fb);
} }
//解析数据 //解析数据
public List<LocationDataVo> getLocation(QueryResult queryResult) { public List<LocationDataVo> getLocation(QueryResult queryResult) {
List<List<Object>> values = getValues(queryResult); List<List<Object>> values = getValues(queryResult);
......
...@@ -70,12 +70,12 @@ public class DownloadController { ...@@ -70,12 +70,12 @@ public class DownloadController {
String token = request.getHeader("Account_token"); String token = request.getHeader("Account_token");
String datum = tokenRedisService.get("TOKEN_" +token); String datum = tokenRedisService.get("TOKEN_" +token);
UserRedisVo user = gson.fromJson(datum,UserRedisVo.class); UserRedisVo user = gson.fromJson(datum,UserRedisVo.class);
if (StringUtils.isEmpty(downloadForWarehouseVo.getStartTime())){ if (downloadForWarehouseVo.getStartTime()==null){
fb.setCode(0); fb.setCode(0);
fb.setMessage(i18n.getMessage(request,"downloadStartTime")); fb.setMessage(i18n.getMessage(request,"downloadStartTime"));
return gson.toJson(fb); return gson.toJson(fb);
} }
if (StringUtils.isEmpty(downloadForWarehouseVo.getStopTime())){ if (downloadForWarehouseVo.getStopTime() ==null){
fb.setCode(0); fb.setCode(0);
fb.setMessage(i18n.getMessage(request,"downloadEndTime")); fb.setMessage(i18n.getMessage(request,"downloadEndTime"));
return gson.toJson(fb); return gson.toJson(fb);
...@@ -96,25 +96,24 @@ public class DownloadController { ...@@ -96,25 +96,24 @@ public class DownloadController {
fb.setMessage("没有数据"); fb.setMessage("没有数据");
return gson.toJson(fb); return gson.toJson(fb);
} }
String sqls=""; File zipFile = new File("./export/" +downloadForWarehouseVo.getWarehouseNo()+"仓库温湿度观测记录.zip");
String fileName =""; File[] srcFiles = new File[resultWarehouseNoAndTDLSNAndTimeVos.size()];
String name=downloadForWarehouseVo.getWarehouseNo()+"仓库温湿度观测记录-"+System.currentTimeMillis();
File file = new File("E:" + File.separator + name);
if (!file.exists()) {
file.mkdir();
}
for (int a=0;a<resultWarehouseNoAndTDLSNAndTimeVos.size();a++) { for (int a=0;a<resultWarehouseNoAndTDLSNAndTimeVos.size();a++) {
ResultWarehouseNoAndTDLSNAndTimeVo resultWarehouseNoAndTDLSNAndTimeVo; ResultWarehouseNoAndTDLSNAndTimeVo resultWarehouseNoAndTDLSNAndTimeVo=resultWarehouseNoAndTDLSNAndTimeVos.get(a);
resultWarehouseNoAndTDLSNAndTimeVo=resultWarehouseNoAndTDLSNAndTimeVos.get(a); String fileName =downloadForWarehouseVo.getWarehouseNo() + "仓库温湿度观测记录表-"+resultWarehouseNoAndTDLSNAndTimeVo.getTDLSN();
fileName =downloadForWarehouseVo.getWarehouseNo() + "仓库温湿度观测记录表-"+resultWarehouseNoAndTDLSNAndTimeVo.getTDLSN()+"-"+ + System.currentTimeMillis(); srcFiles[a] = new File("./export/"+fileName+".xls") ;
List<DownloadWarehouseVo> downloadWarehouseVos = null; Long startTime = 0l;
if (resultWarehouseNoAndTDLSNAndTimeVo.getEndTime() == null) { Long stopTime = 0l;
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 "; if(downloadForWarehouseVo.getStartTime() >=resultWarehouseNoAndTDLSNAndTimeVo.getCreateTime()){
} else { startTime = downloadForWarehouseVo.getStartTime()*1000000l;
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 "; }else{
startTime = resultWarehouseNoAndTDLSNAndTimeVo.getCreateTime()*1000000l;
} }
stopTime = downloadForWarehouseVo.getStopTime()*1000000l;
String sqls = "SELECT \"b\", \"T\", \"h\" FROM \"tdl_policy\".\"" + resultWarehouseNoAndTDLSNAndTimeVo.getGatewayType() + "_" + resultWarehouseNoAndTDLSNAndTimeVo.getGatewaySN() + "\" WHERE (\"tdl\" = 'TDL-" + resultWarehouseNoAndTDLSNAndTimeVo.getTDLSN() + "') and time >= " + startTime + " and time<= " + stopTime + " ORDER BY time ";
QueryResult queryResults = influxDBTemplate.query(new Query(sqls, database)); QueryResult queryResults = influxDBTemplate.query(new Query(sqls, database));
downloadWarehouseVos = getWarehouseData(queryResults); List<DownloadWarehouseVo> downloadWarehouseVos = getWarehouseData(queryResults);
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() ||
...@@ -127,13 +126,13 @@ public class DownloadController { ...@@ -127,13 +126,13 @@ public class DownloadController {
} }
resultWarehouseNoAndTDLSNAndTimeVo.setDownloadWarehouseVos(downloadWarehouseVos); resultWarehouseNoAndTDLSNAndTimeVo.setDownloadWarehouseVos(downloadWarehouseVos);
try { try {
WarehouseExcel warehouseExcel = new WarehouseExcel(resultWarehouseNoAndTDLSNAndTimeVo, user.getUserName(), response); WarehouseExcel warehouseExcel = new WarehouseExcel(fileName,user.getUserName(),resultWarehouseNoAndTDLSNAndTimeVo);
HSSFWorkbook wb = warehouseExcel.downloadExcel(); HSSFWorkbook wb = warehouseExcel.downloadExcel();
request.setCharacterEncoding("utf-8"); request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8");
response.setContentType("application/vnd.ms-excel"); response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment; filename=" + fileName); response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
OutputStream os = new FileOutputStream(new File(file+File.separator+fileName + ".xls")); OutputStream os = new FileOutputStream(new File("./export/"+fileName+".xls"));
wb.write(os); wb.write(os);
os.flush(); os.flush();
os.close(); os.close();
...@@ -146,18 +145,20 @@ public class DownloadController { ...@@ -146,18 +145,20 @@ public class DownloadController {
} }
} }
try { try {
ZipCompressUtil zipCom = new ZipCompressUtil(file + ".zip", file+""); ZipCompressUtil.zipFiles(srcFiles,zipFile);
zipCom.zip();
OSSClient ossClient = AliyunOSSClientUtil.getOSSClient(); OSSClient ossClient = AliyunOSSClientUtil.getOSSClient();
AliyunOSSClientUtil.uploadObject2OSS(ossClient, new File(file +".zip")); String md5Key = AliyunOSSClientUtil.uploadObject2OSS(ossClient, zipFile);
if (deleteFile(file)) { if (md5Key != null) {
new File(file+".zip").delete(); for(int a =0;a<srcFiles.length;a++){
srcFiles[a].delete();
}
zipFile.delete();
fb.setCode(1); fb.setCode(1);
fb.setMessage("https://tdlcloud.oss-cn-shanghai.aliyuncs.com/warehouse/" + name + ".zip"); fb.setMessage("https://tdlcloud.oss-cn-shanghai.aliyuncs.com/warehouse/"+zipFile.getName());
return gson.toJson(fb); return gson.toJson(fb);
} else { } else {
fb.setCode(0); fb.setCode(0);
fb.setMessage("下载失败"); fb.setMessage("上传失败");
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
......
spring.datasource.url=jdbc:mysql://192.168.1.16:3306/tdlcloud?useUnicode=true&characterEncoding=utf-8&useSSL=false spring.datasource.url=jdbc:mysql://47.97.184.225:3306/tdlcloud?useUnicode=true&characterEncoding=utf-8&useSSL=false
spring.datasource.username=root spring.datasource.username=root
spring.datasource.password=37774020 spring.datasource.password=37774020
spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.driver-class-name=com.mysql.jdbc.Driver
...@@ -37,7 +37,7 @@ logging.config=classpath:logback.xml ...@@ -37,7 +37,7 @@ logging.config=classpath:logback.xml
# Mqtt # Mqtt
tdl.mqtt.url = ssl://192.168.1.12 tdl.mqtt.url = ssl://192.168.1.11
tdl.mqtt.port = 8883 tdl.mqtt.port = 8883
tdl.mqtt.username = ugen tdl.mqtt.username = ugen
tdl.mqtt.password = ugen tdl.mqtt.password = ugen
...@@ -52,7 +52,7 @@ tdl.mqtt.clientcrt = witcd.crt ...@@ -52,7 +52,7 @@ tdl.mqtt.clientcrt = witcd.crt
# InfluxDB # InfluxDB
spring.influxdb.username=admin spring.influxdb.username=admin
spring.influxdb.password=37774020 spring.influxdb.password=37774020
spring.influxdb.url=http://192.168.1.16:8086 spring.influxdb.url=http://47.97.184.225:8086
spring.influxdb.database=original spring.influxdb.database=original
spring.influxdb.retentionPolicy = tdl_policy spring.influxdb.retentionPolicy = tdl_policy
spring.influxdb.connent-timeout=10 spring.influxdb.connent-timeout=10
......
...@@ -84,7 +84,6 @@ ...@@ -84,7 +84,6 @@
from tdl_gateway_log t INNER JOIN alarm a ON t.alarm_id=a.id from tdl_gateway_log t INNER JOIN alarm a ON t.alarm_id=a.id
where warehouseNo=#{warehouseNo,jdbcType=VARCHAR} where warehouseNo=#{warehouseNo,jdbcType=VARCHAR}
AND TDLSN IS NOT NULL AND TDLSN IS NOT NULL
AND createTime BETWEEN (UNIX_TIMESTAMP(#{startTime,jdbcType=VARCHAR})*1000) AND endTime is NULL
AND (UNIX_TIMESTAMP(#{stopTime,jdbcType=VARCHAR})*1000)
</select> </select>
</mapper> </mapper>
\ No newline at end of file
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