fengxiang
2018-02-05 259294a3a1f922188075ad6ddad502eca5886b07
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package com.moral.controller;
 
import static com.moral.common.util.ExportExcelUtils.exportData;
import static com.moral.common.util.WebUtils.getParametersStartingWith;
 
import java.io.OutputStream;
import java.util.List;
import java.util.Map;
import java.util.Set;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import com.moral.common.bean.ResultBean;
import com.moral.service.HistoryMinutelyService;
 
@RestController
@RequestMapping("report")
@CrossOrigin(origins = "*", maxAge = 3600)
public class ReportController {
 
    @Resource
    private HistoryMinutelyService historyMinutelyService;
    
    @GetMapping("compare")
    public ResultBean<Map<String, List<Object>>> getCompareReport(HttpServletRequest request) throws Exception {
        Map<String, Object> parameters = getParametersStartingWith(request, null);
        Map<String, List<Object>> demo = historyMinutelyService.getCompareReport(parameters); 
        return new ResultBean<Map<String,List<Object>>>(demo);
    }
 
    @GetMapping("excel")
    public ResultBean<Boolean> getExcelReport(HttpServletRequest request,HttpServletResponse response) throws Exception {
        Map<String, Object> parameters = getParametersStartingWith(request, null);
        List<Map<String, Object>> list = historyMinutelyService.getMonitorPointOrDeviceAvgData4Excel(parameters); 
        String[][] exportColumn =  new String[2][];
        exportColumn[0] = new String[] { "时间", "20", "time" };
        if (parameters.containsKey("sensors")) {
            Set<String> sensors = (Set<String>) parameters.get("sensors");
            exportColumn = new String[sensors.size() + 1][];
            exportColumn[0] = new String[] { "时间", "20", "time" };
            int index = 1;
            for (String sensorKey : sensors) {
                String[] split = sensorKey.split("-");
                String name = split[1];
                String key = split[0];
                exportColumn[index] = new String[] { name, "10", key };
                index++;
            }
        } else {
            exportColumn[1] = new String[] { (String) parameters.get("sensorName"), "10", (String) parameters.get("sensorKey") };
        }
        
        OutputStream outputStream = exportData(response, "Excel数据", list, exportColumn);
        outputStream.flush();
        outputStream.close();
        return new ResultBean<Boolean>(true);
    }
}