From 296d509996b9500c35be0b81860fa14c1d275048 Mon Sep 17 00:00:00 2001
From: kaiyu <404897439@qq.com>
Date: Tue, 01 Dec 2020 10:47:51 +0800
Subject: [PATCH] 更改五分钟数据接口,添加界面左侧站点设备信息接口
---
src/main/java/com/moral/controller/ReportController.java | 131 ++++++++++++++++++++++++++++++-------------
1 files changed, 90 insertions(+), 41 deletions(-)
diff --git a/src/main/java/com/moral/controller/ReportController.java b/src/main/java/com/moral/controller/ReportController.java
index 5d90395..29ccd68 100644
--- a/src/main/java/com/moral/controller/ReportController.java
+++ b/src/main/java/com/moral/controller/ReportController.java
@@ -1,20 +1,22 @@
package com.moral.controller;
import java.io.OutputStream;
+import java.text.ParseException;
import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.*;
import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import com.moral.service.*;
+import com.moral.util.DatesUtil;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang3.time.DateUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
@@ -31,11 +33,6 @@
import com.moral.entity.charts.LineChartCriteria;
import com.moral.security.auth.JwtAuthenticationToken;
import com.moral.security.model.UserContext;
-import com.moral.service.AlarmDailyService;
-import com.moral.service.HistoryDailyService;
-import com.moral.service.HistoryMinutelyService;
-import com.moral.service.MonitorPointService;
-import com.moral.service.SensorService;
import cn.hutool.core.io.IoUtil;
import cn.hutool.poi.excel.ExcelWriter;
@@ -61,6 +58,9 @@
@Resource
private SensorService sensorService;
+ @Resource
+ private HistoryService historyService;
+
@GetMapping("compare")
public ResultBean<Map<String, List>> getCompareReport(HttpServletRequest request) throws Exception {
Map<String, Object> parameters = getParametersStartingWith(request, null);
@@ -79,6 +79,7 @@
List<Map<String, Object>> list = historyMinutelyService.getMonitorPointOrDeviceAvgData(parameters);
List<String> sensors = (List<String>) parameters.get("sensors");
String[][] exportColumn = new String[sensors.size() + 1][];
+ System.out.println(list.toString());
exportColumn[0] = new String[]{"������", "20", "time"};
for (int index = 0; index < sensors.size(); index++) {
String[] split = sensors.get(index).split("-");
@@ -96,26 +97,38 @@
return new ResultBean<Boolean>(true);
}
+ //������������������������������������
+ @GetMapping("O3Excel")
+ public ResultBean<Boolean> getO3ExcelReport(HttpServletRequest request, HttpServletResponse response) throws Exception {
+ Map<String, Object> parameters = getParametersStartingWith(request, null);
+ List<Map<String,Object>> maxList=historyService.getO3AVG(parameters);
+ String[][] exportColumn = new String[2][];
+ exportColumn[0] = new String[]{"������", "20", "time"};
+ String name = "O3������";
+ String key = "e15";
+ String unit = "ug/m��";
+ if (!ObjectUtils.isEmpty(unit) && !"null".equals(unit)) {
+ name += "-" + unit;
+ }
+ exportColumn[1] = new String[]{name, "10", key};
+ OutputStream outputStream = exportData(response, "Excel������", maxList, exportColumn);
+ outputStream.flush();
+ outputStream.close();
+ return new ResultBean<Boolean>(true);
+ }
+
+
+
@GetMapping("newExcel")
public ResultBean<Boolean> getNExcelReport(HttpServletRequest request, HttpServletResponse response) throws Exception {
Map<String, Object> parameters = getParametersStartingWith(request, null);
- List<Map<String, Object>> list = historyMinutelyService.getMonitorPointOrDeviceAvgData(parameters);
- ArrayList<String> sensorKeys = (ArrayList<String>) parameters.get("sensorKeys");
- for (Map<String, Object> map : list) {
- for (String sensorKey : sensorKeys) {
- if (map.get(sensorKey) == null) {
- map.put(sensorKey, "");
- }
- }
- }
-
String type = parameters.get("type").toString();
String time = parameters.get("time").toString();
- String timeb = "";
+ String timeb;
if (parameters.get("timeb") == null) {
- timeb = parameters.get("time").toString();
- } else {
- timeb = parameters.get("timeb").toString();
+ timeb = time;
+ }else {
+ timeb=parameters.get("timeb").toString();
}
String[] endTimes = timeb.split("-");
@@ -123,21 +136,12 @@
String beginTime = "";
String endTime = "";
List<String> monthList1 = new ArrayList<>();
- monthList1.add("01");
- monthList1.add("03");
- monthList1.add("05");
- monthList1.add("07");
- monthList1.add("08");
- monthList1.add("10");
- monthList1.add("12");
+ Collections.addAll(monthList1,"01","03","05","07","08","10","12");
List<String> monthList2 = new ArrayList<>();
- monthList2.add("04");
- monthList2.add("06");
- monthList2.add("09");
- monthList2.add("11");
+ Collections.addAll(monthList2,"04","06","09","11");
+
Integer year = Integer.valueOf(endTimes[0]);
int i = 0;
-
if (type.equals("year")) {
dateFormat = "yyyy-MM";
beginTime = time + "-01";
@@ -163,11 +167,11 @@
beginTime = time + " 00";
endTime = timeb + " 23";
i = Calendar.HOUR_OF_DAY;
- } else if (type.equals("hour")) {
- dateFormat = "yyyy-MM-dd HH:mm";
- beginTime = time + ":00:00";
- endTime = timeb + ":59:00";
- i = Calendar.MINUTE;
+ }else if(type.equals("hour")){
+ dateFormat="yyyy-MM-dd HH:mm";
+ beginTime=time+":00:00";
+ endTime=timeb+":59:00";
+ i=Calendar.MINUTE;
}
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
@@ -180,6 +184,50 @@
Map<String, Object> map = new HashMap<>();
map.put("time", format);
resultList.add(map);
+ }
+
+ if(type.equals("year")){
+ SimpleDateFormat sd = new SimpleDateFormat("yyyy");
+ Date dt = sd.parse(timeb);
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTime(dt);
+ calendar.add(Calendar.YEAR, 1);
+ Date dt1 = calendar.getTime();
+ timeb = sd.format(dt1);
+ }else if(type.equals("month")){
+ SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM");
+ Date dt = sd.parse(timeb);
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTime(dt);
+ calendar.add(Calendar.MONTH, 1);
+ Date dt1 = calendar.getTime();
+ timeb = sd.format(dt1);
+ }else if(type.equals("day")){
+ SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd");
+ Date dt = sd.parse(timeb);
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTime(dt);
+ calendar.add(Calendar.DAY_OF_MONTH, 1);
+ Date dt1 = calendar.getTime();
+ timeb = sd.format(dt1);
+ }else if(type.equals("hour")){
+ SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH");
+ Date dt = sd.parse(timeb);
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTime(dt);
+ calendar.add(Calendar.HOUR_OF_DAY, 1);
+ Date dt1 = calendar.getTime();
+ timeb = sd.format(dt1);
+ }
+ parameters.put("timeb",timeb);
+ List<Map<String, Object>> list = historyMinutelyService.getMonitorPointOrDeviceAvgData(parameters);
+ ArrayList<String> sensorKeys = (ArrayList<String>)parameters.get("sensorKeys");
+ for (Map<String, Object> map : list) {
+ for (String sensorKey : sensorKeys) {
+ if(map.get(sensorKey)==null){
+ map.put(sensorKey,"");
+ }
+ }
}
for (Map<String, Object> map : resultList) {
@@ -263,6 +311,7 @@
@GetMapping("custom-made-excel")
public ResultBean<Boolean> getCustomMadeExcelReport(HttpServletRequest request, HttpServletResponse response) throws Exception {
Map<String, Object> parameters = getParametersStartingWith(request, null);
+ System.out.println(parameters.toString());
ParameterUtils.getTimeType4Time(parameters);
String sensorsInfo = parameters.get("sensors").toString();
String sensorsInfoNew = StringUtils.strip(sensorsInfo, "[]");
--
Gitblit v1.8.0