From bc6a7cf68da9eaf2ba53d23d83d4d73ec76a7b86 Mon Sep 17 00:00:00 2001 From: ZhuDongming <773644075@qq.com> Date: Mon, 09 Dec 2019 11:28:48 +0800 Subject: [PATCH] 因子单位显示null修改 --- src/main/java/com/moral/controller/ReportController.java | 103 +++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 82 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/moral/controller/ReportController.java b/src/main/java/com/moral/controller/ReportController.java index 1726d19..d191744 100644 --- a/src/main/java/com/moral/controller/ReportController.java +++ b/src/main/java/com/moral/controller/ReportController.java @@ -6,20 +6,29 @@ 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.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) @@ -27,39 +36,91 @@ @Resource private HistoryMinutelyService historyMinutelyService; + + @Resource + private AlarmDailyService alarmDailyService; @GetMapping("compare") - public ResultBean<Map<String, List<Object>>> getCompareReport(HttpServletRequest request) throws Exception { + public ResultBean<Map<String, List>> 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); + 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 { + 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][]; + 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" }; - 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++; + 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; } - } else { - exportColumn[1] = new String[] { (String) parameters.get("sensorName"), "10", (String) parameters.get("sensorKey") }; + 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); + } } -- Gitblit v1.8.0