ZhuDongming
2019-08-09 def4359b55046dfb32d806f3778cf5a813310e7a
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
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 javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import com.moral.common.bean.ResultBean;
import com.moral.common.util.WebUtils;
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;
 
@SuppressWarnings({ "unchecked", "rawtypes" })
@RestController
@RequestMapping("report")
@CrossOrigin(origins = "*", maxAge = 3600)
public class ReportController {
 
    @Resource
    private HistoryMinutelyService historyMinutelyService;
 
    @Resource
    private AlarmDailyService alarmDailyService;
    
    @GetMapping("compare")
    public ResultBean<Map<String, List>> getCompareReport(HttpServletRequest request) throws Exception {
        Map<String, Object> parameters = getParametersStartingWith(request, null);
        Map<String, List> demo = historyMinutelyService.getCompareReport(parameters);
        return new ResultBean<Map<String, List>>(demo);
    }
 
    @PostMapping("line-chart")
    public ResultBean<Map<String, List<List<Double>>>> lineChart(@RequestBody LineChartCriteria lineChartCriteria) {
        return new ResultBean<>(historyMinutelyService.queryLineChartDateByCrieria(lineChartCriteria));
    }
 
    @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.getMonitorPointOrDeviceAvgData(parameters);
        List<String> sensors = (List<String>) parameters.get("sensors");
        String[][] exportColumn = new String[sensors.size() + 1][];
        exportColumn[0] = new String[] { "时间", "20", "time" };
        for (int index = 0; index < sensors.size(); index++) {
            String[] split = sensors.get(index).split("-");
            String name = split[1];
            String key = split[0];
            String unit = split[2];
            if (!ObjectUtils.isEmpty(unit) && !"null".equals(unit)) {
                name += "-" + unit;
            }
            exportColumn[index + 1] = new String[] { name, "10", key };
        }
        OutputStream outputStream = exportData(response, "Excel数据", list, exportColumn);
        outputStream.flush();
        outputStream.close();
        return new ResultBean<Boolean>(true);
    }
    
    @GetMapping("pie")
    public ResultBean<Map<String, Object>> getPieData(HttpServletRequest request) throws Exception {
        Map<String, Object> parameters = getParametersStartingWith(request, null);
        Map pieData = alarmDailyService.getPieData(parameters);
        
        return new ResultBean<Map<String, Object>>(pieData);
    }
 
    @GetMapping("alarm-year")
    public ResultBean<List<Integer>> getAlarmDataByYear(HttpServletRequest request) throws Exception {
        Map<String, Object> parameters = getParametersStartingWith(request, null);
        List<Integer> result = alarmDailyService.getAlarmDataByYear(parameters);
        
        return new ResultBean<List<Integer>>(result);
    }
 
    @GetMapping("alarm-month")
    public ResultBean<List<Map<String, Object>>> getAlarmDataByMonth(HttpServletRequest request) throws Exception {
        Map<String, Object> parameters = getParametersStartingWith(request, null);
        List<Map<String, Object>> result = alarmDailyService.getAlarmDataByMonth(parameters);
        
        return new ResultBean<List<Map<String, Object>>>(result);
    }
 
    @Resource
    private HistoryDailyService historyDailyService;
    
    @GetMapping("emissions")
    public ResultBean<List<Map<String, Object>>> getemissionsData(HttpServletRequest request, JwtAuthenticationToken token) throws Exception {
        Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
        UserContext userContext = token.getPrincipal();
        Integer orgId = userContext.getOrganizationId();
        parameters.put("orgId", orgId);
        List<Map<String, Object>> result = historyDailyService.getEmissionsData(parameters);
        return new ResultBean<List<Map<String, Object>>>(result);
    }
 
 
    @GetMapping("overproof")
    public ResultBean<Map> getOverproofData(HttpServletRequest request, JwtAuthenticationToken token) throws Exception {
        Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
        UserContext userContext = token.getPrincipal();
        Integer orgId = userContext.getOrganizationId();
        parameters.put("orgId", orgId);
        //List<Map<String, Object>> result = null;
        Map result = historyDailyService.getOverproofData(parameters);
        return new ResultBean<Map>(result);
    }
}