工业级运维app手机api
沈斌
2017-11-20 44bfab8ff28cbeb54686f9398699615324ca879b
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
package com.moral.monitor.controller;
 
import java.io.OutputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
 
import com.moral.monitor.service.ReportService;
import com.moral.monitor.util.BusinessException;
import com.moral.monitor.util.ExportExcelUtils;
import com.moral.monitor.util.WebUtils;
 
@RestController
@RequestMapping(value = "report")
@CrossOrigin(origins = "*", maxAge = 3600)
public class ReportController {
 
    @Autowired
    ReportService reportService;
    
    @RequestMapping(value = "/sensors-average", method = RequestMethod.GET)
    public Map<String, Object> getSensorsAverageByEquipment(HttpServletRequest request,HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
            Object mac = parameters.get("mac");
            Object time = parameters.get("time");
            Object type = parameters.get("type");
            if (ObjectUtils.isEmpty(mac) || ObjectUtils.isEmpty(time) || ObjectUtils.isEmpty(type)) {
                result.put("msg", "参数不能为空!");
            } else {
                List<Map<String, Object>> sensorsAverage = reportService.getSensorsAverageByEquipment(parameters);
                if (ObjectUtils.isEmpty(sensorsAverage)) {
                    result.put("msg", "无有效数据");
                } else {
                    String[][] exportColumn = new String[][] { 
                            new String[] { "时间", "20", "time" },
                            new String[] { "Pm2.5", "10", "e1" }, 
                            new String[] { "Pm10", "20", "e2" },
                            new String[] { "0.1升0.3um量", "30", "e3" }, 
                            new String[] { "0.1升2.5um量", "10", "e4" },
                            new String[] { "甲醛", "10", "e5" },
                            new String[] { "湿度", "10", "e6" },
                            new String[] { "温度", "10", "e7" },
                            new String[] { "氧气(O2)", "10", "e8" },
                            new String[] { "氯气(CL2)", "10", "e9" },
                            new String[] { "一氧化碳(CO)", "10", "e10" },
                            new String[] { "二氧化硫(SO2)", "10", "e11" },
                            new String[] { "光照", "10", "e12" },
                            new String[] { "噪音", "10", "e13" },
                            new String[] { "氨气(NH3)", "10", "e14" },
                            new String[] { "臭氧(O3)", "10", "e15" },
                            new String[] { "二氧化氮(NO2)", "10", "e16" },
                            new String[] { "挥发性有机气体", "10", "e17" },
                            new String[] { "风速", "10", "e18" },
                            new String[] { "二氧化碳(CO2)", "10", "e19" }
                    };
                    OutputStream outputStream = ExportExcelUtils.exportData(response, time + "日" + "设备:" + mac + type + "数据", sensorsAverage, exportColumn);
                    outputStream.flush();
                    outputStream.close();
                }
            }
        } catch (BusinessException be) {
            be.printStackTrace();
            result.put("msg", be.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            result.put("msg", "系统错误,请联系管理员!原因如下:"+e.getMessage());
        }
        return result;
    }
 
}