yuzixiang
2020-05-22 5c3994e0166baff540d323a779573299a56feec6
src/main/java/com/moral/controller/ReportController.java
@@ -1,22 +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.Collections;
import java.util.Date;
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;
@@ -33,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;
@@ -63,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);
@@ -81,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("-");
@@ -97,6 +96,28 @@
        outputStream.close();
        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 {
@@ -290,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, "[]");