| | |
| | |
|
| | | 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 javax.annotation.Resource;
|
| | | import javax.servlet.http.HttpServletRequest;
|
| | | import javax.servlet.http.HttpServletResponse;
|
| | |
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import static org.springframework.util.ObjectUtils.*;
|
| | | 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.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 {
|
| | |
|
| | | @Autowired
|
| | | @Resource
|
| | | private HistoryService historyService;
|
| | |
|
| | | @Autowired
|
| | | @Resource
|
| | | private DeviceService deviceService;
|
| | |
|
| | | @GetMapping("sensors-average")
|
| | |
| | | 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();
|