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.List; import java.util.Map; 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) public class ReportController { @Resource private HistoryMinutelyService historyMinutelyService; @Resource private AlarmDailyService alarmDailyService; @GetMapping("compare") public ResultBean> getCompareReport(HttpServletRequest request) throws Exception { Map parameters = getParametersStartingWith(request, null); Map demo = historyMinutelyService.getCompareReport(parameters); return new ResultBean>(demo); } @PostMapping("line-chart") public ResultBean>>> lineChart(@RequestBody LineChartCriteria lineChartCriteria) { return new ResultBean<>(historyMinutelyService.queryLineChartDateByCrieria(lineChartCriteria)); } @GetMapping("excel") public ResultBean getExcelReport(HttpServletRequest request, HttpServletResponse response) throws Exception { Map parameters = getParametersStartingWith(request, null); List> list = historyMinutelyService.getMonitorPointOrDeviceAvgData(parameters); List sensors = (List) 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(true); } @GetMapping("pie") public ResultBean> getPieData(HttpServletRequest request) throws Exception { Map parameters = getParametersStartingWith(request, null); Map pieData = alarmDailyService.getPieData(parameters); return new ResultBean>(pieData); } @GetMapping("alarm-year") public ResultBean> getAlarmDataByYear(HttpServletRequest request) throws Exception { Map parameters = getParametersStartingWith(request, null); List result = alarmDailyService.getAlarmDataByYear(parameters); return new ResultBean>(result); } @GetMapping("alarm-month") public ResultBean>> getAlarmDataByMonth(HttpServletRequest request) throws Exception { Map parameters = getParametersStartingWith(request, null); List> result = alarmDailyService.getAlarmDataByMonth(parameters); return new ResultBean>>(result); } @Resource private HistoryDailyService historyDailyService; @GetMapping("emissions") public ResultBean>> getemissionsData(HttpServletRequest request, JwtAuthenticationToken token) throws Exception { Map parameters = WebUtils.getParametersStartingWith(request, null); UserContext userContext = token.getPrincipal(); Integer orgId = userContext.getOrganizationId(); parameters.put("orgId", orgId); List> result = historyDailyService.getEmissionsData(parameters); return new ResultBean>>(result); } @GetMapping("overproof") public ResultBean getOverproofData(HttpServletRequest request, JwtAuthenticationToken token) throws Exception { Map parameters = WebUtils.getParametersStartingWith(request, null); UserContext userContext = token.getPrincipal(); Integer orgId = userContext.getOrganizationId(); parameters.put("orgId", orgId); //List> result = null; Map result = historyDailyService.getOverproofData(parameters); return new ResultBean(result); } }