From 69fe5c709ecf9093b1640356eff7c1991a6dd7d3 Mon Sep 17 00:00:00 2001 From: ZhuDongming <773644075@qq.com> Date: Thu, 23 Apr 2020 11:53:54 +0800 Subject: [PATCH] add定制导报表接口 --- src/main/java/com/moral/service/impl/AccountServiceImpl.java | 16 ++- src/main/resources/mapper/HistoryMinutelyMapper.xml | 4 src/main/java/com/moral/controller/ReportController.java | 222 +++++++++++++++++++++++++++----------------- 3 files changed, 149 insertions(+), 93 deletions(-) diff --git a/src/main/java/com/moral/controller/ReportController.java b/src/main/java/com/moral/controller/ReportController.java index d191744..c86ffbb 100644 --- a/src/main/java/com/moral/controller/ReportController.java +++ b/src/main/java/com/moral/controller/ReportController.java @@ -1,9 +1,9 @@ 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.ArrayList; +import java.util.Arrays; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -11,6 +11,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.apache.commons.collections.CollectionUtils; import org.springframework.util.ObjectUtils; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.GetMapping; @@ -20,107 +21,158 @@ import org.springframework.web.bind.annotation.RestController; import com.moral.common.bean.ResultBean; +import com.moral.common.util.ParameterUtils; import com.moral.common.util.WebUtils; +import com.moral.entity.Device; +import com.moral.entity.MonitorPoint; 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; +import com.moral.service.MonitorPointService; -@SuppressWarnings({ "unchecked", "rawtypes" }) +import static com.moral.common.util.ExportExcelUtils.exportData; +import static com.moral.common.util.WebUtils.getParametersStartingWith; + +@SuppressWarnings({"unchecked", "rawtypes"}) @RestController @RequestMapping("report") @CrossOrigin(origins = "*", maxAge = 3600) public class ReportController { - @Resource - private HistoryMinutelyService historyMinutelyService; + @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); - } + @Resource + private AlarmDailyService alarmDailyService; - @PostMapping("line-chart") - public ResultBean<Map<String, List<List<Double>>>> lineChart(@RequestBody LineChartCriteria lineChartCriteria) { - return new ResultBean<>(historyMinutelyService.queryLineChartDateByCrieria(lineChartCriteria)); - } + @Resource + private MonitorPointService monitorPointService; - @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("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); + } - @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); - } + @PostMapping("line-chart") + public ResultBean<Map<String, List<List<Double>>>> lineChart(@RequestBody LineChartCriteria lineChartCriteria) { + return new ResultBean<>(historyMinutelyService.queryLineChartDateByCrieria(lineChartCriteria)); + } - @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); - } + @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); + } - @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("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); - } + @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); + } + + @GetMapping("custom-made-excel") + public ResultBean<Boolean> getCustomMadeExcelReport(HttpServletRequest request, HttpServletResponse response) throws Exception { + Map<String, Object> parameters = getParametersStartingWith(request, null); + ParameterUtils.getTimeType4Time(parameters); + Object sensorKey = parameters.get("sensorKey"); + String sensorInfo = parameters.get("sensorInfo").toString(); + parameters.put("sensorKeys", Arrays.asList(sensorKey)); + List<String> macList = new ArrayList<>(); + List<MonitorPoint> monitorPoints = monitorPointService.getMonitorPointsAndDevicesByRegion(parameters); + for (MonitorPoint m : monitorPoints) { + for (Device d : m.getDevices()) { + macList.add(d.getMac()); + } + } + parameters.put("macs", macList); + List<Map<String, Object>> list = new ArrayList<>(); + if (!CollectionUtils.isEmpty(macList)) { + list = historyMinutelyService.getDevicesAvgDataToExcel(parameters); + } + Map<String, Object> map = list.get(0); + Map<Integer, String> mapNew = new LinkedHashMap<>(); + int i = 0; + for (String key : map.keySet()) { + if (!("monitorPointName".equals(key) || "name".equals(key))) { + mapNew.put(i, key); + i++; + } + } + String[][] exportColumn = new String[map.size()][]; + exportColumn[0] = new String[]{"������������-" + sensorInfo, "30", "monitorPointName"}; + exportColumn[1] = new String[]{"������������", "20", "name"}; + for (int index = 0; index < map.size() - 2; index++) { + exportColumn[index + 2] = new String[]{mapNew.get(index), "20", mapNew.get(index)}; + } + OutputStream outputStream = exportData(response, "Excel������", list, exportColumn); + outputStream.flush(); + outputStream.close(); + return new ResultBean<Boolean>(true); + } + } diff --git a/src/main/java/com/moral/service/impl/AccountServiceImpl.java b/src/main/java/com/moral/service/impl/AccountServiceImpl.java index a865fa9..fe05269 100644 --- a/src/main/java/com/moral/service/impl/AccountServiceImpl.java +++ b/src/main/java/com/moral/service/impl/AccountServiceImpl.java @@ -10,12 +10,6 @@ import java.util.Optional; import java.util.Set; -import static com.moral.common.bean.Constants.IS_DELETE_FALSE; -import static com.moral.common.bean.Constants.IS_DELETE_TRUE; -import static com.moral.common.util.ResourceUtil.getValue; -import static org.apache.commons.lang3.StringUtils.isNumeric; -import static org.springframework.util.ObjectUtils.isEmpty; - import javax.annotation.Resource; import org.apache.commons.lang3.StringUtils; @@ -42,6 +36,12 @@ import tk.mybatis.mapper.entity.Example; import tk.mybatis.mapper.entity.Example.Criteria; + +import static com.moral.common.bean.Constants.IS_DELETE_FALSE; +import static com.moral.common.bean.Constants.IS_DELETE_TRUE; +import static com.moral.common.util.ResourceUtil.getValue; +import static org.apache.commons.lang3.StringUtils.isNumeric; +import static org.springframework.util.ObjectUtils.isEmpty; @Service public class AccountServiceImpl implements AccountService { @@ -260,12 +260,16 @@ @Override public Map<String, Object> getMenuListsByAccountName(String accountName) { List<Menu> menuList = accountMapper.getParentMenuListsByAccountName(accountName); + Integer organizationId = accountMapper.getByAccountName(accountName).getOrganizationId(); + Map<String, Object> organizationMap = new LinkedHashMap<>(); + organizationMap.put("organizationId",organizationId); String email = accountMapper.getEmailByAccountName(accountName); Map<String, Object> mapList = new LinkedHashMap<>(); Map<String, Object> appMap = new LinkedHashMap<>(); appMap.put("name", "������������������������"); appMap.put("description", "������������������������������������������"); mapList.put("app", appMap); + mapList.put("organization", organizationMap); Map<String, Object> userMap = new LinkedHashMap<>(); userMap.put("name", accountName); userMap.put("avatar", "./assets/img/zorro.svg"); diff --git a/src/main/resources/mapper/HistoryMinutelyMapper.xml b/src/main/resources/mapper/HistoryMinutelyMapper.xml index 7af50a1..26ef457 100644 --- a/src/main/resources/mapper/HistoryMinutelyMapper.xml +++ b/src/main/resources/mapper/HistoryMinutelyMapper.xml @@ -183,7 +183,7 @@ select rs.monitorPointName,rs.name, <foreach collection="timeList" separator="," item="time"> - max(case time when #{time} then rs.${sensorKey} else null end) as #{time} + max(case time when #{time} then rs.${sensorKey} else "" end) as #{time} </foreach> from (SELECT @@ -210,7 +210,7 @@ ORDER BY h.mac) rs GROUP BY rs.monitorPointName,rs.name - order by rs.name + order by rs.monitorPointName </select> </mapper> \ No newline at end of file -- Gitblit v1.8.0