From 4428fd50d5e8216d5d7bd63a7fc2e1bb8e239d9d Mon Sep 17 00:00:00 2001
From: ZhuDongming <773644075@qq.com>
Date: Wed, 13 May 2020 13:58:13 +0800
Subject: [PATCH] update大屏地图跳转定位问题
---
src/main/java/com/moral/controller/ReportController.java | 153 ++++++++++++++++++++++++--------------------------
1 files changed, 74 insertions(+), 79 deletions(-)
diff --git a/src/main/java/com/moral/controller/ReportController.java b/src/main/java/com/moral/controller/ReportController.java
index 4a5b678..d3c7e6c 100644
--- a/src/main/java/com/moral/controller/ReportController.java
+++ b/src/main/java/com/moral/controller/ReportController.java
@@ -2,7 +2,13 @@
import java.io.OutputStream;
import java.text.SimpleDateFormat;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
@@ -19,7 +25,6 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
-import com.alibaba.fastjson.JSONObject;
import com.moral.common.bean.ResultBean;
import com.moral.common.util.ParameterUtils;
import com.moral.common.util.WebUtils;
@@ -32,6 +37,7 @@
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;
@@ -53,6 +59,9 @@
@Resource
private MonitorPointService monitorPointService;
+
+ @Resource
+ private SensorService sensorService;
@GetMapping("compare")
public ResultBean<Map<String, List>> getCompareReport(HttpServletRequest request) throws Exception {
@@ -92,24 +101,13 @@
@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();
- System.out.println(parameters);
- 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("-");
@@ -117,21 +115,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";
@@ -157,6 +146,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;
}
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
@@ -169,6 +163,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) {
@@ -254,25 +292,10 @@
Map<String, Object> parameters = getParametersStartingWith(request, null);
ParameterUtils.getTimeType4Time(parameters);
String sensorsInfo = parameters.get("sensors").toString();
- String[] sensorsStr = sensorsInfo.split(",");
- List<String> sensorKeys = new ArrayList<>();
- List<String> sensorKeysNames = new ArrayList<>();
- List<String> sensorKeysUnits = new ArrayList<>();
- for (int index = 0; index < sensorsStr.length; index++) {
- String[] split = sensorsStr[index].split("-");
- String key;
- if (index == 0) {
- key = split[0].replace("\"", "").substring(1);
- } else {
- key = split[0].replace("\"", "");
- }
- String name = split[1].replace("\"", "");
- String Unit = split[2].replace("\"", "");
- sensorKeys.add(key);
- sensorKeysNames.add(name);
- sensorKeysUnits.add(Unit);
- }
- parameters.put("sensorKeys", sensorKeys);
+ String sensorsInfoNew = StringUtils.strip(sensorsInfo, "[]");
+ String[] sensorsStr = sensorsInfoNew.split(",");
+ List<List<String>> sensorInfos = sensorService.listSensorInfos(sensorsStr);
+ parameters.put("sensorKeys", sensorInfos.get(0));
List<String> macList = new ArrayList<>();
List<MonitorPoint> monitorPoints = monitorPointService.getMonitorPointsAndDevicesByRegion(parameters);
for (MonitorPoint m : monitorPoints) {
@@ -285,44 +308,16 @@
if (!CollectionUtils.isEmpty(macList)) {
list = historyMinutelyService.getDevicesSensorsAvgDataToExcel(parameters);
}
- List<List<Map<String, Object>>> sheets = new ArrayList<>();
- for (int i = 0; i < sensorKeys.size(); i++) {
- List<Map<String, Object>> sheet = new ArrayList<>();
- for (int j = 0; j < list.size(); j++) {
- Map<String, Object> data = new LinkedHashMap<>();
- for (Map.Entry<String, Object> kv : list.get(j).entrySet()) {
- if ("monitorPointName".equals(kv.getKey())) {
- data.put("������������(������:" + sensorKeysUnits.get(i) + ")", kv.getValue());
- } else if ("name".equals(kv.getKey())) {
- data.put("������������", kv.getValue());
- } else {
- String sensorsValue = kv.getValue().toString();
- JSONObject jsonObject = JSONObject.parseObject(sensorsValue);
- if (jsonObject != null) {
- List<Object> sensorsValueList = (List<Object>) jsonObject.get(sensorKeys.get(i));
- if (sensorsValueList != null) {
- data.put(kv.getKey(), sensorsValueList.get(0));
- } else {
- data.put(kv.getKey(), "");
- }
- } else {
- data.put(kv.getKey(), "");
- }
- }
- }
- sheet.add(data);
- }
- sheets.add(sheet);
- }
+ List<List<Map<String, Object>>> sheets = sensorService.listExcelDatas(sensorInfos, list);
if (!CollectionUtils.isEmpty(sheets)) {
- ExcelWriter writer = new ExcelWriter(false, sensorKeysNames.get(0));
+ ExcelWriter writer = new ExcelWriter(false, sensorInfos.get(1).get(0));
writer.write(sheets.get(0), true);
writer.autoSizeColumnAll();
writer.setColumnWidth(0, 25);
writer.setColumnWidth(1, 25);
if (sheets.size() >= 2) {
for (int i = 1; i < sheets.size(); i++) {
- writer.setSheet(sensorKeysNames.get(i));
+ writer.setSheet(sensorInfos.get(1).get(i));
writer.write(sheets.get(i), true);
writer.autoSizeColumnAll();
writer.setColumnWidth(0, 25);
--
Gitblit v1.8.0