| | |
| | | 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;
|
| | |
|
| | | @RestController
|
| | | @RequestMapping(value = "report")
|
| | | @RequestMapping("report")
|
| | | @CrossOrigin(origins = "*", maxAge = 3600)
|
| | | public class ReportController {
|
| | |
|
| | |
| | | Object mac = parameters.get("mac");
|
| | | Object time = parameters.get("time");
|
| | | Object type = parameters.get("type");
|
| | | if (isEmpty(mac) || isEmpty(time) || isEmpty(type)) {
|
| | | result.put("msg", "参数不能为空!");
|
| | | 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 {
|
| | | 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();
|
| | | 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();
|