| | |
| | |
|
| | | 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.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.web.bind.annotation.CrossOrigin;
|
| | | import org.springframework.web.bind.annotation.GetMapping;
|
| | | import org.springframework.web.bind.annotation.RequestMapping;
|
| | | import org.springframework.web.bind.annotation.RestController;
|
| | | import com.alibaba.fastjson.JSON;
|
| | | import com.moral.entity.charts.LineChartCriteria;
|
| | | import com.moral.entity.charts.PairData;
|
| | | import org.springframework.web.bind.annotation.*;
|
| | |
|
| | | 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.service.HistoryMinutelyService;
|
| | |
|
| | | @RestController
|
| | | @RequestMapping("report")
|
| | |
| | | public class ReportController {
|
| | |
|
| | | @Resource
|
| | | private HistoryService historyService;
|
| | | private HistoryMinutelyService historyMinutelyService;
|
| | |
|
| | | @Resource
|
| | | private DeviceService deviceService;
|
| | |
|
| | | @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<PairData>>>> 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); |
| | | String[][] exportColumn = new String[2][];
|
| | | 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++;
|
| | | }
|
| | | } else {
|
| | | exportColumn[1] = new String[] { (String) parameters.get("sensorName"), "10", (String) parameters.get("sensorKey") };
|
| | | }
|
| | | exportColumn[0] = new String[] { "时间", "20", "time" };
|
| | | |
| | | OutputStream outputStream = exportData(response, "Excel数据", list, exportColumn);
|
| | | outputStream.flush();
|
| | | outputStream.close();
|
| | | return new ResultBean<Boolean>(true);
|
| | | }
|
| | | }
|