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;
|
}
|
|
}
|