From 6f08c72b1056c9e4b2bdf79bafbc49fcc3cdcaa1 Mon Sep 17 00:00:00 2001 From: xufenglei <xufenglei> Date: Sun, 08 Apr 2018 11:24:56 +0800 Subject: [PATCH] 报表优化 --- src/main/java/com/moral/controller/ReportController.java | 88 +++++++++++++++++++++----------------------- 1 files changed, 42 insertions(+), 46 deletions(-) diff --git a/src/main/java/com/moral/controller/ReportController.java b/src/main/java/com/moral/controller/ReportController.java index d866077..ed398a7 100644 --- a/src/main/java/com/moral/controller/ReportController.java +++ b/src/main/java/com/moral/controller/ReportController.java @@ -2,74 +2,70 @@ import static com.moral.common.util.ExportExcelUtils.exportData; import static com.moral.common.util.WebUtils.getParametersStartingWith; -import static org.springframework.util.ObjectUtils.isEmpty; import java.io.OutputStream; -import java.util.HashMap; +import java.util.ArrayList; 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.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.exception.BusinessException; -import com.moral.common.util.ValidateUtil; -import com.moral.service.DeviceService; -import com.moral.service.HistoryService; +import com.moral.common.bean.ResultBean; +import com.moral.entity.charts.LineChartCriteria; +import com.moral.service.HistoryMinutelyService; +@SuppressWarnings("unchecked") @RestController @RequestMapping("report") @CrossOrigin(origins = "*", maxAge = 3600) public class ReportController { @Resource - private HistoryService historyService; - - @Resource - private DeviceService deviceService; + private HistoryMinutelyService historyMinutelyService; - @GetMapping("sensors-average") - public Map<String, Object> getSensorsAverageByDevice(HttpServletRequest request,HttpServletResponse response) { - Map<String, Object> result = new HashMap<String, Object>(); - try { - Map<String, Object> parameters = getParametersStartingWith(request, null); - Object mac = parameters.get("mac"); - Object time = parameters.get("time"); - Object type = parameters.get("type"); - ValidateUtil.notNull(mac, "param.is.null"); - ValidateUtil.notNull(time, "param.is.null"); - ValidateUtil.notNull(type, "param.is.null"); - List<Map<String, Object>> sensors = deviceService.getSensorsByDevice(mac.toString()); - List<Map<String, Object>> sensorsAverage = historyService.getSensorsAverageByDevice4Report(parameters,sensors); - if (isEmpty(sensorsAverage)) { - result.put("msg", "���������������"); - } else { - String[][] exportColumn = new String[sensors.size() + 1][]; - exportColumn[0] = new String[] { "������", "20", "time" }; - for (int i = 0; i < sensors.size(); i++) { - String name = (String) sensors.get(i).get("name"); - String key = (String) sensors.get(i).get("key"); - exportColumn[i + 1] = new String[] { name, "10", key }; - } - - OutputStream outputStream = 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; + @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); } + @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); + } } -- Gitblit v1.8.0