8 files renamed
2 files deleted
4 files added
24 files modified
| | |
| | | <artifactId>fastjson</artifactId> |
| | | <version>1.2.39</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>net.sourceforge.jexcelapi</groupId> |
| | | <artifactId>jxl</artifactId> |
| | | <version>2.6.12</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>net.sf.json-lib</groupId> |
| | | <artifactId>json-lib</artifactId> |
| | | <version>2.4</version> |
| | | <classifier>jdk15</classifier> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.projectlombok</groupId> |
| | | <artifactId>lombok</artifactId> |
| | | <version>1.16.18</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.springframework.boot</groupId> |
| | | <artifactId>spring-boot-starter-aop</artifactId> |
| | | </dependency> |
| | | </dependencies> |
| | | |
| | | <build> |
New file |
| | |
| | | package com.moral.common.aop;
|
| | |
|
| | | import java.util.HashMap;
|
| | | import java.util.Map;
|
| | |
|
| | | import org.aspectj.lang.ProceedingJoinPoint;
|
| | | import org.aspectj.lang.annotation.Around;
|
| | | import org.aspectj.lang.annotation.Aspect;
|
| | | import org.springframework.stereotype.Component;
|
| | |
|
| | | import com.moral.common.exception.BusinessException;
|
| | |
|
| | | import lombok.extern.log4j.Log4j;
|
| | |
|
| | | @Log4j
|
| | | @Aspect
|
| | | @Component
|
| | | public class ControllerAOP {
|
| | | |
| | | @Around("execution(* com.moral.controller.*Controller.*(..))")
|
| | | public Object handlerControllerMethod(ProceedingJoinPoint pjp) {
|
| | | long startTime = System.currentTimeMillis();
|
| | | Map<String, Object> result;
|
| | | try {
|
| | | result = (Map<String, Object>) pjp.proceed();
|
| | | log.info(pjp.getSignature() + "use time:" + (System.currentTimeMillis() - startTime));
|
| | | } catch (Throwable e) {
|
| | | result = handlerException(pjp, e);
|
| | | }
|
| | |
|
| | | return result;
|
| | | }
|
| | |
|
| | | private Map<String, Object> handlerException(ProceedingJoinPoint pjp, Throwable e) {
|
| | | Map<String, Object> result = new HashMap<String, Object>();
|
| | |
|
| | | // 已知异常
|
| | | if (e instanceof BusinessException) {
|
| | | result.put("msg", e.getLocalizedMessage());
|
| | | } else {
|
| | | log.error(pjp.getSignature() + " error ", e);
|
| | | result.put("msg", e.toString());
|
| | | //TODO 未知的异常,应该格外注意,可以发送邮件通知等
|
| | | }
|
| | |
|
| | | return result;
|
| | | }
|
| | | }
|
File was renamed from src/main/java/com/moral/util/Constants.java |
| | |
| | | package com.moral.util; |
| | | package com.moral.common.bean; |
| | | |
| | | // TODO: Auto-generated Javadoc |
| | | /** |
| | | * 系统常量. |
| | | */ |
New file |
| | |
| | | package com.moral.common.bean;
|
| | |
|
| | | import java.io.Serializable;
|
| | |
|
| | | import lombok.Data;
|
| | |
|
| | | @Data
|
| | | public class ResultBean<T>implements Serializable {
|
| | |
|
| | | private static final long serialVersionUID = 1L;
|
| | | |
| | | public static final int FAIL = 0;
|
| | | public static final int SUCCESS = 1;
|
| | | public static final int NO_PERMISSION = 2;
|
| | | private String msg = "success";
|
| | | private int code = SUCCESS;
|
| | | private T data;
|
| | | public ResultBean() {
|
| | | super();
|
| | | }
|
| | | public ResultBean(T data) {
|
| | | super();
|
| | | this.data = data;
|
| | | }
|
| | | |
| | | public ResultBean(Throwable e) {
|
| | | super();
|
| | | this.msg = e.toString();
|
| | | this.code = FAIL;
|
| | | }
|
| | | public ResultBean(String msg, int code) {
|
| | | super();
|
| | | this.msg = msg;
|
| | | this.code = code;
|
| | | }
|
| | | public ResultBean(int code) {
|
| | | super();
|
| | | this.code = code;
|
| | | }
|
| | | }
|
File was renamed from src/main/java/com/moral/util/BusinessException.java |
| | |
| | | package com.moral.util;
|
| | | package com.moral.common.exception;
|
| | |
|
| | | public class BusinessException extends RuntimeException {
|
| | |
|
File was renamed from src/main/java/com/moral/mapper/BaseMapper.java |
| | |
| | | package com.moral.mapper;
|
| | | package com.moral.common.mapper;
|
| | |
|
| | | import java.io.Serializable;
|
| | | import java.util.List;
|
File was renamed from src/main/java/com/moral/util/CalculateUtils.java |
| | |
| | | package com.moral.util;
|
| | | package com.moral.common.util;
|
| | |
|
| | | public class CalculateUtils {
|
| | |
|
File was renamed from src/main/java/com/moral/util/Crypto.java |
| | |
| | | package com.moral.util; |
| | | package com.moral.common.util; |
| | | |
| | | import sun.misc.BASE64Encoder; |
| | | |
New file |
| | |
| | | package com.moral.common.util;
|
| | |
|
| | | import java.io.OutputStream;
|
| | | import java.io.UnsupportedEncodingException;
|
| | | import java.util.List;
|
| | |
|
| | | import javax.servlet.http.HttpServletResponse;
|
| | |
|
| | | import jxl.Workbook;
|
| | | import jxl.write.Label;
|
| | | import jxl.write.WritableCellFormat;
|
| | | import jxl.write.WritableFont;
|
| | | import jxl.write.WritableSheet;
|
| | | import jxl.write.WritableWorkbook;
|
| | | import jxl.write.WriteException;
|
| | | import jxl.write.biff.RowsExceededException;
|
| | | import net.sf.json.JSONObject;
|
| | |
|
| | | @SuppressWarnings("rawtypes")
|
| | | public class ExportExcelUtils {
|
| | |
|
| | | public static OutputStream exportData(HttpServletResponse response, String fileName, List list,String[][] exportColumn)
|
| | | throws Exception {
|
| | |
|
| | | // 文件名加后缀信
|
| | | String excelFileName = fileName + ".xls";
|
| | |
|
| | | OutputStream outputStream = response.getOutputStream();
|
| | | // 设定输出文件头
|
| | | response.setHeader("Content-Type", "application/force-download");
|
| | | // 把文件名转码使前台可以显示中文名
|
| | | response.setHeader("Content-Disposition", "attachment; filename=\""
|
| | | + new String(excelFileName.getBytes("gb2312"), "ISO8859-1")
|
| | | + "\"");
|
| | | // 生成excel表格
|
| | | exportExcel(outputStream,list, getColumn(exportColumn),getName(exportColumn), fileName);
|
| | |
|
| | | return outputStream;
|
| | | }
|
| | |
|
| | | public static void exportExcel(OutputStream os, List list, String[] colTitles, String[] fieldNames, String fileName) throws Exception {
|
| | | WritableWorkbook wwb = Workbook.createWorkbook(os);
|
| | |
|
| | | createSheet(wwb, fileName, 0, list, colTitles, fieldNames);
|
| | |
|
| | | wwb.write();
|
| | | wwb.close();
|
| | | }
|
| | |
|
| | | private static void createSheet(WritableWorkbook wwb, String sheetName, int index, List list, String[] colTitles,
|
| | | String[] fieldNames)
|
| | | throws RowsExceededException, WriteException, UnsupportedEncodingException {
|
| | |
|
| | | WritableSheet ws = wwb.createSheet(sheetName, index);
|
| | | // 标题定义样式
|
| | | WritableFont font = new WritableFont(WritableFont.createFont("宋体"), 10, WritableFont.BOLD);
|
| | | WritableCellFormat wcf = new WritableCellFormat(font);
|
| | | |
| | | for (int i = 0; i < colTitles.length; i++) {
|
| | | String title = colTitles[i];
|
| | | ws.addCell(new Label(i, 0, title.split(",")[0], wcf));
|
| | | ws.setColumnView(i, Integer.valueOf(title.split(",")[1]));
|
| | | }
|
| | | for (int i = 0; i < list.size(); i++) {
|
| | | JSONObject jsonObject = JSONObject.fromObject(list.get(i));
|
| | | for (int j = 0; j < colTitles.length; j++) {
|
| | | ws.addCell(new Label(j, i + 1, jsonObject.getString(fieldNames[j])));
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获得导出 列标题 和 列宽度
|
| | | * |
| | | * @return
|
| | | */
|
| | | public static String[] getColumn(String[][] exportColumn) {
|
| | | if (exportColumn != null) {
|
| | | String[] result = new String[exportColumn.length];
|
| | | for (int i = 0; i < exportColumn.length; i++) {
|
| | | result[i] = exportColumn[i][0] + "," + exportColumn[i][1];
|
| | | }
|
| | | return result;
|
| | | } else {
|
| | | return new String[0];
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获得 表针对字段
|
| | | * |
| | | * @return
|
| | | */
|
| | | public static String[] getName(String[][] exportColumn) {
|
| | | if (exportColumn != null) {
|
| | | String[] result = new String[exportColumn.length];
|
| | | for (int i = 0; i < exportColumn.length; i++) {
|
| | | result[i] = exportColumn[i][2];
|
| | | }
|
| | | return result;
|
| | | } else {
|
| | | return new String[0];
|
| | | }
|
| | | }
|
| | |
|
| | | }
|
File was renamed from src/main/java/com/moral/util/RedisUtil.java |
| | |
| | | package com.moral.util; |
| | | package com.moral.common.util; |
| | | |
| | | import java.util.Set; |
| | | import java.util.concurrent.TimeUnit; |
File was renamed from src/main/java/com/moral/util/ResourceUtil.java |
| | |
| | | package com.moral.util;
|
| | | package com.moral.common.util;
|
| | |
|
| | | import java.util.ResourceBundle;
|
| | |
|
File was renamed from src/main/java/com/moral/util/WebUtils.java |
| | |
| | | package com.moral.util;
|
| | | package com.moral.common.util;
|
| | |
|
| | | import java.util.Enumeration;
|
| | | import java.util.Map;
|
New file |
| | |
| | | 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.HashMap;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
|
| | | 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.service.DeviceService;
|
| | | import com.moral.service.HistoryService;
|
| | |
|
| | | @RestController
|
| | | @RequestMapping(value = "report")
|
| | | @CrossOrigin(origins = "*", maxAge = 3600)
|
| | | public class ReportController {
|
| | |
|
| | | @Autowired
|
| | | private HistoryService historyService;
|
| | | |
| | | @Autowired
|
| | | 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");
|
| | | if (isEmpty(mac) || isEmpty(time) || isEmpty(type)) {
|
| | | 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();
|
| | | }
|
| | | }
|
| | | } catch (BusinessException be) {
|
| | | be.printStackTrace();
|
| | | result.put("msg", be.getMessage());
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | result.put("msg", "系统错误,请联系管理员!原因如下:"+e.getMessage());
|
| | | }
|
| | | return result;
|
| | | }
|
| | |
|
| | | }
|
| | |
| | | package com.moral.controller;
|
| | |
|
| | | import static com.moral.common.util.RedisUtil.get;
|
| | | import static com.moral.common.util.RedisUtil.hasKey;
|
| | | import static com.moral.common.util.ResourceUtil.getValue;
|
| | | import static com.moral.common.util.WebUtils.getParametersStartingWith;
|
| | | import static org.springframework.util.ObjectUtils.isEmpty;
|
| | |
|
| | | import java.io.IOException;
|
| | | import java.io.InputStreamReader;
|
| | | import java.util.HashMap;
|
| | |
| | | import org.springframework.beans.factory.annotation.Value;
|
| | | import org.springframework.core.io.Resource;
|
| | | import org.springframework.data.redis.core.RedisTemplate;
|
| | | 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.RequestMapping;
|
| | | import org.springframework.web.bind.annotation.RequestMethod;
|
| | | import org.springframework.web.bind.annotation.RequestParam;
|
| | | import org.springframework.web.bind.annotation.RestController;
|
| | |
|
| | | import com.alibaba.fastjson.JSON;
|
| | | import com.alibaba.fastjson.JSONReader;
|
| | | import com.alibaba.fastjson.TypeReference;
|
| | | import com.moral.util.ResourceUtil;
|
| | | import com.moral.common.bean.ResultBean;
|
| | | import com.moral.common.exception.BusinessException;
|
| | | import com.moral.entity.Account;
|
| | | import com.moral.service.AccountService;
|
| | | import com.moral.service.DeviceService;
|
| | | import com.moral.service.HistoryService;
|
| | | import com.moral.util.BusinessException;
|
| | | import com.moral.util.RedisUtil;
|
| | | import com.moral.util.WebUtils;
|
| | |
|
| | | // TODO: Auto-generated Javadoc
|
| | | /**
|
| | | * The Class ScreenController.
|
| | | */
|
| | |
| | | * the request
|
| | | * @return the map
|
| | | */
|
| | | @RequestMapping(value = "login", method = RequestMethod.GET)
|
| | | @GetMapping("login")
|
| | | public Map<String, Object> screenLogin(HttpServletRequest request) {
|
| | | Map<String, Object> resultMap = new HashMap<String, Object>();
|
| | | try {
|
| | | Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
|
| | | Map<String, Object> parameters = getParametersStartingWith(request, null);
|
| | | if (!(parameters.containsKey("account") && parameters.containsKey("password"))) {
|
| | | resultMap.put("msg", "用户名及密码不允许为空!");
|
| | | resultMap.put("accountId", -1);
|
| | | } else {
|
| | | resultMap = accountService.screenLogin(parameters);
|
| | | }
|
| | | return resultMap;
|
| | | }
|
| | |
|
| | | @GetMapping("login1")
|
| | | public ResultBean<Account> screenLogin1(HttpServletRequest request) {
|
| | | ResultBean<Account> resultBean = new ResultBean<Account>(ResultBean.FAIL);
|
| | | try {
|
| | | Map<String, Object> parameters = getParametersStartingWith(request, null);
|
| | | if (!(parameters.containsKey("account") && parameters.containsKey("password"))) {
|
| | | resultBean.setMsg("用户名及密码不允许为空!");
|
| | | } else {
|
| | | resultBean = accountService.screenLogin1(parameters);
|
| | | }
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | resultMap.put("accountId", -1);
|
| | | resultMap.put("msg", "系统错误,请联系管理员!原因如下:" + e.getMessage());
|
| | | resultBean = new ResultBean<Account>(e);
|
| | | }
|
| | | return resultMap;
|
| | | return resultBean;
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | * the request
|
| | | * @return the equipment states
|
| | | */
|
| | | @RequestMapping(value = "equipment-state", method = RequestMethod.GET)
|
| | | public Map<String, Object> getDeviceStates(HttpServletRequest request) {
|
| | | @GetMapping("equipment-state")
|
| | | public Map<String, Object> getDeviceStatesByAccount(HttpServletRequest request) {
|
| | | Map<String, Object> result = new LinkedHashMap<String, Object>();
|
| | | try {
|
| | | Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
|
| | | Map<String, Object> parameters = getParametersStartingWith(request, null);
|
| | | if (!parameters.containsKey("accountId")) {
|
| | | result.put("msg", "参数不能为空!");
|
| | | } else {
|
| | | result = deviceService.getDeviceStates(parameters);
|
| | | }
|
| | | } catch (BusinessException be) {
|
| | | be.printStackTrace();
|
| | | result.put("msg", be.getMessage());
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | result.put("msg", "系统错误,请联系管理员!原因如下:" + e.getMessage());
|
| | | result = deviceService.getDeviceStatesByAccount(parameters);
|
| | | }
|
| | | return result;
|
| | | }
|
| | |
| | | * @return the alarm levels
|
| | | */
|
| | | @SuppressWarnings("resource")
|
| | | @RequestMapping(value = "alarm-levels", method = RequestMethod.GET)
|
| | | @GetMapping("alarm-levels")
|
| | | public Map<String, Object> getAlarmLevels(HttpServletRequest request) {
|
| | | Map<String, Object> result = new LinkedHashMap<String, Object>();
|
| | | try {
|
| | | if (RedisUtil.hasKey(redisTemplate, levelKey)) {
|
| | | String levelConfigStr = RedisUtil.get(redisTemplate, levelKey);
|
| | | if (hasKey(redisTemplate, levelKey)) {
|
| | | String levelConfigStr = get(redisTemplate, levelKey);
|
| | | result = JSON.parseObject(levelConfigStr, new TypeReference<Map<String, Object>>() {});
|
| | | } else {
|
| | | InputStreamReader reader = new InputStreamReader(resource.getInputStream());
|
| | |
| | | * the request
|
| | | * @return the standard by sensor
|
| | | */
|
| | | @RequestMapping(value = "sensor-standard", method = RequestMethod.GET)
|
| | | public Map<String, Object> getStandardBySensor(HttpServletRequest request) {
|
| | | @GetMapping("sensor-standard")
|
| | | public Map<String, Object> getStandardBySensor(@RequestParam("macKey") String macKey) {
|
| | | Map<String, Object> result = new HashMap<String, Object>();
|
| | | try {
|
| | | String macKey = request.getParameter("macKey");
|
| | | if (ObjectUtils.isEmpty(macKey)) {
|
| | | result.put("msg", "参数不能为空!");
|
| | | if (isEmpty(macKey)) {
|
| | | throw new BusinessException("参数不能为空!");
|
| | | } else {
|
| | | result.put("standard", ResourceUtil.getValue(macKey + "-standard"));
|
| | | }
|
| | | } catch (BusinessException be) {
|
| | | be.printStackTrace();
|
| | | result.put("msg", be.getMessage());
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | result.put("msg", "系统错误,请联系管理员!原因如下:" + e.getMessage());
|
| | | result.put("standard", getValue(macKey + "-standard"));
|
| | | }
|
| | | return result;
|
| | | }
|
| | |
| | | * the request
|
| | | * @return the day AQI by sensor
|
| | | */
|
| | | @RequestMapping(value = "day-aqi", method = RequestMethod.GET)
|
| | | @GetMapping("day-aqi")
|
| | | public Map<String, Object> getDayAQIByDevice(HttpServletRequest request) {
|
| | | Map<String, Object> result = new HashMap<String, Object>();
|
| | | try {
|
| | | Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
|
| | | Map<String, Object> parameters = getParametersStartingWith(request, null);
|
| | | if (!parameters.containsKey("mac")) {
|
| | | result.put("msg", "参数不能为空!");
|
| | | } else {
|
| | | result = historyService.getDayAQIByDevice(parameters);
|
| | | }
|
| | | } catch (BusinessException be) {
|
| | | be.printStackTrace();
|
| | | result.put("msg", be.getMessage());
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | result.put("msg", "系统错误,请联系管理员!原因如下:" + e.getMessage());
|
| | | }
|
| | | return result;
|
| | | }
|
| | |
| | | * the request
|
| | | * @return the average by all
|
| | | */
|
| | | @RequestMapping(value = "/all-average", method = RequestMethod.GET)
|
| | | public Map<String, Object> getAverageByAll(HttpServletRequest request) {
|
| | | @GetMapping("all-average")
|
| | | public Map<String, Object> getAllSensorAverageByDevice(HttpServletRequest request) {
|
| | | Map<String, Object> result = new LinkedHashMap<String, Object>();
|
| | | try {
|
| | | Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
|
| | | Map<String, Object> parameters = getParametersStartingWith(request, null);
|
| | | if (!(parameters.containsKey("areaCode") && parameters.containsKey("accountId"))) {
|
| | | result.put("msg", "参数不能为空!");
|
| | | } else {
|
| | | result = historyService.getAverageByAll(parameters);
|
| | | }
|
| | | } catch (BusinessException be) {
|
| | | be.printStackTrace();
|
| | | result.put("msg", be.getMessage());
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | result.put("msg", "系统错误,请联系管理员!原因如下:" + e.getMessage());
|
| | | result = historyService.getAllSensorAverageByDevice(parameters);
|
| | | }
|
| | | return result;
|
| | | }
|
| | |
| | | * the request
|
| | | * @return the average by sensor
|
| | | */
|
| | | @RequestMapping(value = "/sensor-average", method = RequestMethod.GET)
|
| | | public Map<String, Object> getAverageBySensor(HttpServletRequest request) {
|
| | | @GetMapping("sensor-average")
|
| | | public Map<String, Object> getDeviceRankingBySensorAverage(HttpServletRequest request) {
|
| | | Map<String, Object> result = new HashMap<String, Object>();
|
| | | try {
|
| | | Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
|
| | | Map<String, Object> parameters = getParametersStartingWith(request, null);
|
| | | if (!(parameters.containsKey("areaCode") && parameters.containsKey("accountId")
|
| | | && parameters.containsKey("macKey"))) {
|
| | | result.put("msg", "参数不能为空!");
|
| | | } else {
|
| | | result = historyService.getAverageBySensor(parameters);
|
| | | }
|
| | | } catch (BusinessException be) {
|
| | | be.printStackTrace();
|
| | | result.put("msg", be.getMessage());
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | result.put("msg", "系统错误,请联系管理员!原因如下:" + e.getMessage());
|
| | | result = historyService.getDeviceRankingBySensorAverage(parameters);
|
| | | }
|
| | | return result;
|
| | | }
|
| | |
| | | * the request
|
| | | * @return the month average by sensor
|
| | | */
|
| | | @RequestMapping(value = "month-sensor-average", method = RequestMethod.GET)
|
| | | @GetMapping("month-sensor-average")
|
| | | public Map<String, Object> getMonthAverageBySensor(HttpServletRequest request) {
|
| | | Map<String, Object> result = new HashMap<String, Object>();
|
| | | try {
|
| | | Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
|
| | | Map<String, Object> parameters = getParametersStartingWith(request, null);
|
| | | if (!(parameters.containsKey("mac") && parameters.containsKey("macKey"))) {
|
| | | result.put("msg", "参数不能为空!");
|
| | | } else {
|
| | | result = historyService.getMonthAverageBySensor(parameters);
|
| | | }
|
| | | } catch (BusinessException be) {
|
| | | be.printStackTrace();
|
| | | result.put("msg", be.getMessage());
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | result.put("msg", "系统错误,请联系管理员!原因如下:" + e.getMessage());
|
| | | }
|
| | | return result;
|
| | | }
|
| | |
| | |
|
| | | import java.util.Date;
|
| | |
|
| | | import lombok.Data;
|
| | |
|
| | | @Data
|
| | | public class Account {
|
| | | private Integer id;
|
| | |
|
| | |
| | | private Date createTime;
|
| | |
|
| | | private Date expireTime;
|
| | |
|
| | | public Integer getId() {
|
| | | return id;
|
| | | }
|
| | |
|
| | | public void setId(Integer id) {
|
| | | this.id = id;
|
| | | }
|
| | |
|
| | | public String getAccountName() {
|
| | | return accountName;
|
| | | }
|
| | |
|
| | | public void setAccountName(String accountName) {
|
| | | this.accountName = accountName;
|
| | | }
|
| | |
|
| | | public String getPassword() {
|
| | | return password;
|
| | | }
|
| | |
|
| | | public void setPassword(String password) {
|
| | | this.password = password;
|
| | | }
|
| | |
|
| | | public Integer getOrganizationId() {
|
| | | return organizationId;
|
| | | }
|
| | |
|
| | | public void setOrganizationId(Integer organizationId) {
|
| | | this.organizationId = organizationId;
|
| | | }
|
| | |
|
| | | public String getEmail() {
|
| | | return email;
|
| | | }
|
| | |
|
| | | public void setEmail(String email) {
|
| | | this.email = email;
|
| | | }
|
| | |
|
| | | public String getMobile() {
|
| | | return mobile;
|
| | | }
|
| | |
|
| | | public void setMobile(String mobile) {
|
| | | this.mobile = mobile;
|
| | | }
|
| | |
|
| | | public String getWeixin() {
|
| | | return weixin;
|
| | | }
|
| | |
|
| | | public void setWeixin(String weixin) {
|
| | | this.weixin = weixin;
|
| | | }
|
| | |
|
| | | public String getIsDelete() {
|
| | | return isDelete;
|
| | | }
|
| | |
|
| | | public void setIsDelete(String isDelete) {
|
| | | this.isDelete = isDelete;
|
| | | }
|
| | |
|
| | | public Date getCreateTime() {
|
| | | return createTime;
|
| | | }
|
| | |
|
| | | public void setCreateTime(Date createTime) {
|
| | | this.createTime = createTime;
|
| | | }
|
| | |
|
| | | public Date getExpireTime() {
|
| | | return expireTime;
|
| | | }
|
| | |
|
| | | public void setExpireTime(Date expireTime) {
|
| | | this.expireTime = expireTime;
|
| | | }
|
| | |
|
| | | } |
| | |
| | |
|
| | | import java.util.Date;
|
| | |
|
| | | public class Device {
|
| | | import lombok.Data;
|
| | |
|
| | | @Data
|
| | | public class Device {/**
|
| | | * This field was generated by MyBatis Generator. This field corresponds to the database column device.id
|
| | | * @mbggenerated Wed Nov 29 16:17:59 CST 2017
|
| | | */
|
| | | private Integer id;
|
| | |
|
| | | /**
|
| | | * This field was generated by MyBatis Generator. This field corresponds to the database column device.name
|
| | | * @mbggenerated Wed Nov 29 16:17:59 CST 2017
|
| | | */
|
| | | private String name;
|
| | |
|
| | | /**
|
| | | * This field was generated by MyBatis Generator. This field corresponds to the database column device.address
|
| | | * @mbggenerated Wed Nov 29 16:17:59 CST 2017
|
| | | */
|
| | | private String address;
|
| | |
|
| | | /**
|
| | | * This field was generated by MyBatis Generator. This field corresponds to the database column device.longitude
|
| | | * @mbggenerated Wed Nov 29 16:17:59 CST 2017
|
| | | */
|
| | | private Float longitude;
|
| | |
|
| | | /**
|
| | | * This field was generated by MyBatis Generator. This field corresponds to the database column device.latitude
|
| | | * @mbggenerated Wed Nov 29 16:17:59 CST 2017
|
| | | */
|
| | | private Float latitude;
|
| | |
|
| | | /**
|
| | | * This field was generated by MyBatis Generator. This field corresponds to the database column device.mac
|
| | | * @mbggenerated Wed Nov 29 16:17:59 CST 2017
|
| | | */
|
| | | private String mac;
|
| | |
|
| | | private String state;
|
| | |
|
| | | /**
|
| | | * This field was generated by MyBatis Generator. This field corresponds to the database column device.operate_user_id
|
| | | * @mbggenerated Wed Nov 29 16:17:59 CST 2017
|
| | | */
|
| | | private Integer operateUserId;
|
| | |
|
| | | /**
|
| | | * This field was generated by MyBatis Generator. This field corresponds to the database column device.state
|
| | | * @mbggenerated Wed Nov 29 16:17:59 CST 2017
|
| | | */
|
| | | private String state;
|
| | | /**
|
| | | * This field was generated by MyBatis Generator. This field corresponds to the database column device.create_time
|
| | | * @mbggenerated Wed Nov 29 16:17:59 CST 2017
|
| | | */
|
| | | private Date createTime;
|
| | |
|
| | | /**
|
| | | * This field was generated by MyBatis Generator. This field corresponds to the database column device.install_time
|
| | | * @mbggenerated Wed Nov 29 16:17:59 CST 2017
|
| | | */
|
| | | private Date installTime;
|
| | |
|
| | | /**
|
| | | * This field was generated by MyBatis Generator. This field corresponds to the database column device.monitor_point_id
|
| | | * @mbggenerated Wed Nov 29 16:17:59 CST 2017
|
| | | */
|
| | | private Integer monitorPointId;
|
| | |
|
| | | /**
|
| | | * This field was generated by MyBatis Generator. This field corresponds to the database column device.device_version_id
|
| | | * @mbggenerated Wed Nov 29 16:17:59 CST 2017
|
| | | */
|
| | | private Integer deviceVersionId;
|
| | |
|
| | | public Integer getId() {
|
| | | return id;
|
| | | }
|
| | |
|
| | | public void setId(Integer id) {
|
| | | this.id = id;
|
| | | }
|
| | |
|
| | | public String getName() {
|
| | | return name;
|
| | | }
|
| | |
|
| | | public void setName(String name) {
|
| | | this.name = name;
|
| | | }
|
| | |
|
| | | public String getAddress() {
|
| | | return address;
|
| | | }
|
| | |
|
| | | public void setAddress(String address) {
|
| | | this.address = address;
|
| | | }
|
| | |
|
| | | public Float getLongitude() {
|
| | | return longitude;
|
| | | }
|
| | |
|
| | | public void setLongitude(Float longitude) {
|
| | | this.longitude = longitude;
|
| | | }
|
| | |
|
| | | public Float getLatitude() {
|
| | | return latitude;
|
| | | }
|
| | |
|
| | | public void setLatitude(Float latitude) {
|
| | | this.latitude = latitude;
|
| | | }
|
| | |
|
| | | public String getMac() {
|
| | | return mac;
|
| | | }
|
| | |
|
| | | public void setMac(String mac) {
|
| | | this.mac = mac;
|
| | | }
|
| | |
|
| | | public String getState() {
|
| | | return state;
|
| | | }
|
| | |
|
| | | public void setState(String state) {
|
| | | this.state = state;
|
| | | }
|
| | |
|
| | | public Integer getOperateUserId() {
|
| | | return operateUserId;
|
| | | }
|
| | |
|
| | | public void setOperateUserId(Integer operateUserId) {
|
| | | this.operateUserId = operateUserId;
|
| | | }
|
| | |
|
| | | public Date getCreateTime() {
|
| | | return createTime;
|
| | | }
|
| | |
|
| | | public void setCreateTime(Date createTime) {
|
| | | this.createTime = createTime;
|
| | | }
|
| | |
|
| | | public Date getInstallTime() {
|
| | | return installTime;
|
| | | }
|
| | |
|
| | | public void setInstallTime(Date installTime) {
|
| | | this.installTime = installTime;
|
| | | }
|
| | |
|
| | | public Integer getMonitorPointId() {
|
| | | return monitorPointId;
|
| | | }
|
| | |
|
| | | public void setMonitorPointId(Integer monitorPointId) {
|
| | | this.monitorPointId = monitorPointId;
|
| | | }
|
| | |
|
| | | public Integer getDeviceVersionId() {
|
| | | return deviceVersionId;
|
| | | }
|
| | |
|
| | | public void setDeviceVersionId(Integer deviceVersionId) {
|
| | | this.deviceVersionId = deviceVersionId;
|
| | | }
|
| | | } |
| | |
| | | import java.util.List;
|
| | |
|
| | | public class DeviceExample {
|
| | | /**
|
| | | * This field was generated by MyBatis Generator. This field corresponds to the database table device
|
| | | * @mbggenerated Wed Nov 29 16:17:59 CST 2017
|
| | | */
|
| | | protected String orderByClause;
|
| | |
|
| | | /**
|
| | | * This field was generated by MyBatis Generator. This field corresponds to the database table device
|
| | | * @mbggenerated Wed Nov 29 16:17:59 CST 2017
|
| | | */
|
| | | protected boolean distinct;
|
| | |
|
| | | /**
|
| | | * This field was generated by MyBatis Generator. This field corresponds to the database table device
|
| | | * @mbggenerated Wed Nov 29 16:17:59 CST 2017
|
| | | */
|
| | | protected List<Criteria> oredCriteria;
|
| | |
|
| | | /**
|
| | | * This method was generated by MyBatis Generator. This method corresponds to the database table device
|
| | | * @mbggenerated Wed Nov 29 16:17:59 CST 2017
|
| | | */
|
| | | public DeviceExample() {
|
| | | oredCriteria = new ArrayList<Criteria>();
|
| | | }
|
| | |
|
| | | /**
|
| | | * This method was generated by MyBatis Generator. This method corresponds to the database table device
|
| | | * @mbggenerated Wed Nov 29 16:17:59 CST 2017
|
| | | */
|
| | | public void setOrderByClause(String orderByClause) {
|
| | | this.orderByClause = orderByClause;
|
| | | }
|
| | |
|
| | | /**
|
| | | * This method was generated by MyBatis Generator. This method corresponds to the database table device
|
| | | * @mbggenerated Wed Nov 29 16:17:59 CST 2017
|
| | | */
|
| | | public String getOrderByClause() {
|
| | | return orderByClause;
|
| | | }
|
| | |
|
| | | /**
|
| | | * This method was generated by MyBatis Generator. This method corresponds to the database table device
|
| | | * @mbggenerated Wed Nov 29 16:17:59 CST 2017
|
| | | */
|
| | | public void setDistinct(boolean distinct) {
|
| | | this.distinct = distinct;
|
| | | }
|
| | |
|
| | | /**
|
| | | * This method was generated by MyBatis Generator. This method corresponds to the database table device
|
| | | * @mbggenerated Wed Nov 29 16:17:59 CST 2017
|
| | | */
|
| | | public boolean isDistinct() {
|
| | | return distinct;
|
| | | }
|
| | |
|
| | | /**
|
| | | * This method was generated by MyBatis Generator. This method corresponds to the database table device
|
| | | * @mbggenerated Wed Nov 29 16:17:59 CST 2017
|
| | | */
|
| | | public List<Criteria> getOredCriteria() {
|
| | | return oredCriteria;
|
| | | }
|
| | |
|
| | | /**
|
| | | * This method was generated by MyBatis Generator. This method corresponds to the database table device
|
| | | * @mbggenerated Wed Nov 29 16:17:59 CST 2017
|
| | | */
|
| | | public void or(Criteria criteria) {
|
| | | oredCriteria.add(criteria);
|
| | | }
|
| | |
|
| | | /**
|
| | | * This method was generated by MyBatis Generator. This method corresponds to the database table device
|
| | | * @mbggenerated Wed Nov 29 16:17:59 CST 2017
|
| | | */
|
| | | public Criteria or() {
|
| | | Criteria criteria = createCriteriaInternal();
|
| | | oredCriteria.add(criteria);
|
| | | return criteria;
|
| | | }
|
| | |
|
| | | /**
|
| | | * This method was generated by MyBatis Generator. This method corresponds to the database table device
|
| | | * @mbggenerated Wed Nov 29 16:17:59 CST 2017
|
| | | */
|
| | | public Criteria createCriteria() {
|
| | | Criteria criteria = createCriteriaInternal();
|
| | | if (oredCriteria.size() == 0) {
|
| | |
| | | return criteria;
|
| | | }
|
| | |
|
| | | /**
|
| | | * This method was generated by MyBatis Generator. This method corresponds to the database table device
|
| | | * @mbggenerated Wed Nov 29 16:17:59 CST 2017
|
| | | */
|
| | | protected Criteria createCriteriaInternal() {
|
| | | Criteria criteria = new Criteria();
|
| | | return criteria;
|
| | | }
|
| | |
|
| | | /**
|
| | | * This method was generated by MyBatis Generator. This method corresponds to the database table device
|
| | | * @mbggenerated Wed Nov 29 16:17:59 CST 2017
|
| | | */
|
| | | public void clear() {
|
| | | oredCriteria.clear();
|
| | | orderByClause = null;
|
| | | distinct = false;
|
| | | }
|
| | |
|
| | | /**
|
| | | * This class was generated by MyBatis Generator. This class corresponds to the database table device
|
| | | * @mbggenerated Wed Nov 29 16:17:59 CST 2017
|
| | | */
|
| | | protected abstract static class GeneratedCriteria {
|
| | | protected List<Criterion> criteria;
|
| | |
|
| | |
| | | return (Criteria) this;
|
| | | }
|
| | |
|
| | | public Criteria andOperateUserIdIsNull() {
|
| | | addCriterion("operate_user_id is null");
|
| | | return (Criteria) this;
|
| | | }
|
| | |
|
| | | public Criteria andOperateUserIdIsNotNull() {
|
| | | addCriterion("operate_user_id is not null");
|
| | | return (Criteria) this;
|
| | | }
|
| | |
|
| | | public Criteria andOperateUserIdEqualTo(Integer value) {
|
| | | addCriterion("operate_user_id =", value, "operateUserId");
|
| | | return (Criteria) this;
|
| | | }
|
| | |
|
| | | public Criteria andOperateUserIdNotEqualTo(Integer value) {
|
| | | addCriterion("operate_user_id <>", value, "operateUserId");
|
| | | return (Criteria) this;
|
| | | }
|
| | |
|
| | | public Criteria andOperateUserIdGreaterThan(Integer value) {
|
| | | addCriterion("operate_user_id >", value, "operateUserId");
|
| | | return (Criteria) this;
|
| | | }
|
| | |
|
| | | public Criteria andOperateUserIdGreaterThanOrEqualTo(Integer value) {
|
| | | addCriterion("operate_user_id >=", value, "operateUserId");
|
| | | return (Criteria) this;
|
| | | }
|
| | |
|
| | | public Criteria andOperateUserIdLessThan(Integer value) {
|
| | | addCriterion("operate_user_id <", value, "operateUserId");
|
| | | return (Criteria) this;
|
| | | }
|
| | |
|
| | | public Criteria andOperateUserIdLessThanOrEqualTo(Integer value) {
|
| | | addCriterion("operate_user_id <=", value, "operateUserId");
|
| | | return (Criteria) this;
|
| | | }
|
| | |
|
| | | public Criteria andOperateUserIdIn(List<Integer> values) {
|
| | | addCriterion("operate_user_id in", values, "operateUserId");
|
| | | return (Criteria) this;
|
| | | }
|
| | |
|
| | | public Criteria andOperateUserIdNotIn(List<Integer> values) {
|
| | | addCriterion("operate_user_id not in", values, "operateUserId");
|
| | | return (Criteria) this;
|
| | | }
|
| | |
|
| | | public Criteria andOperateUserIdBetween(Integer value1, Integer value2) {
|
| | | addCriterion("operate_user_id between", value1, value2, "operateUserId");
|
| | | return (Criteria) this;
|
| | | }
|
| | |
|
| | | public Criteria andOperateUserIdNotBetween(Integer value1, Integer value2) {
|
| | | addCriterion("operate_user_id not between", value1, value2, "operateUserId");
|
| | | return (Criteria) this;
|
| | | }
|
| | |
|
| | | public Criteria andStateIsNull() {
|
| | | addCriterion("state is null");
|
| | | return (Criteria) this;
|
| | |
| | |
|
| | | public Criteria andStateNotBetween(String value1, String value2) {
|
| | | addCriterion("state not between", value1, value2, "state");
|
| | | return (Criteria) this;
|
| | | }
|
| | |
|
| | | public Criteria andOperateUserIdIsNull() {
|
| | | addCriterion("operate_user_id is null");
|
| | | return (Criteria) this;
|
| | | }
|
| | |
|
| | | public Criteria andOperateUserIdIsNotNull() {
|
| | | addCriterion("operate_user_id is not null");
|
| | | return (Criteria) this;
|
| | | }
|
| | |
|
| | | public Criteria andOperateUserIdEqualTo(Integer value) {
|
| | | addCriterion("operate_user_id =", value, "operateUserId");
|
| | | return (Criteria) this;
|
| | | }
|
| | |
|
| | | public Criteria andOperateUserIdNotEqualTo(Integer value) {
|
| | | addCriterion("operate_user_id <>", value, "operateUserId");
|
| | | return (Criteria) this;
|
| | | }
|
| | |
|
| | | public Criteria andOperateUserIdGreaterThan(Integer value) {
|
| | | addCriterion("operate_user_id >", value, "operateUserId");
|
| | | return (Criteria) this;
|
| | | }
|
| | |
|
| | | public Criteria andOperateUserIdGreaterThanOrEqualTo(Integer value) {
|
| | | addCriterion("operate_user_id >=", value, "operateUserId");
|
| | | return (Criteria) this;
|
| | | }
|
| | |
|
| | | public Criteria andOperateUserIdLessThan(Integer value) {
|
| | | addCriterion("operate_user_id <", value, "operateUserId");
|
| | | return (Criteria) this;
|
| | | }
|
| | |
|
| | | public Criteria andOperateUserIdLessThanOrEqualTo(Integer value) {
|
| | | addCriterion("operate_user_id <=", value, "operateUserId");
|
| | | return (Criteria) this;
|
| | | }
|
| | |
|
| | | public Criteria andOperateUserIdIn(List<Integer> values) {
|
| | | addCriterion("operate_user_id in", values, "operateUserId");
|
| | | return (Criteria) this;
|
| | | }
|
| | |
|
| | | public Criteria andOperateUserIdNotIn(List<Integer> values) {
|
| | | addCriterion("operate_user_id not in", values, "operateUserId");
|
| | | return (Criteria) this;
|
| | | }
|
| | |
|
| | | public Criteria andOperateUserIdBetween(Integer value1, Integer value2) {
|
| | | addCriterion("operate_user_id between", value1, value2, "operateUserId");
|
| | | return (Criteria) this;
|
| | | }
|
| | |
|
| | | public Criteria andOperateUserIdNotBetween(Integer value1, Integer value2) {
|
| | | addCriterion("operate_user_id not between", value1, value2, "operateUserId");
|
| | | return (Criteria) this;
|
| | | }
|
| | |
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | public static class Criteria extends GeneratedCriteria {
|
| | |
|
| | | protected Criteria() {
|
| | | super();
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * This class was generated by MyBatis Generator. This class corresponds to the database table device
|
| | | * @mbggenerated Wed Nov 29 16:17:59 CST 2017
|
| | | */
|
| | | public static class Criterion {
|
| | | private String condition;
|
| | |
|
| | | private Object value;
|
| | |
|
| | | private Object secondValue;
|
| | |
|
| | | private boolean noValue;
|
| | |
|
| | | private boolean singleValue;
|
| | |
|
| | | private boolean betweenValue;
|
| | |
|
| | | private boolean listValue;
|
| | |
|
| | | private String typeHandler;
|
| | |
|
| | | public String getCondition() {
|
| | |
| | | this(condition, value, secondValue, null);
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * This class was generated by MyBatis Generator. This class corresponds to the database table device
|
| | | * @mbggenerated do_not_delete_during_merge
|
| | | */
|
| | | public static class Criteria extends GeneratedCriteria {
|
| | | protected Criteria() {
|
| | | super();
|
| | | }
|
| | | }
|
| | |
|
| | | } |
| | |
| | |
|
| | | import java.util.Date;
|
| | |
|
| | | import lombok.Data;
|
| | |
|
| | | @Data
|
| | | public class OperateUser {
|
| | | private Integer id;
|
| | |
|
| | |
| | |
|
| | | private Date expireTime;
|
| | |
|
| | | public Integer getId() {
|
| | | return id;
|
| | | }
|
| | |
|
| | | public void setId(Integer id) {
|
| | | this.id = id;
|
| | | }
|
| | |
|
| | | public String getJobNumber() {
|
| | | return jobNumber;
|
| | | }
|
| | |
|
| | | public void setJobNumber(String jobNumber) {
|
| | | this.jobNumber = jobNumber;
|
| | | }
|
| | |
|
| | | public String getName() {
|
| | | return name;
|
| | | }
|
| | |
|
| | | public void setName(String name) {
|
| | | this.name = name;
|
| | | }
|
| | |
|
| | | public String getPassword() {
|
| | | return password;
|
| | | }
|
| | |
|
| | | public void setPassword(String password) {
|
| | | this.password = password;
|
| | | }
|
| | |
|
| | | public Integer getOrganizationId() {
|
| | | return organizationId;
|
| | | }
|
| | |
|
| | | public void setOrganizationId(Integer organizationId) {
|
| | | this.organizationId = organizationId;
|
| | | }
|
| | |
|
| | | public String getMobile() {
|
| | | return mobile;
|
| | | }
|
| | |
|
| | | public void setMobile(String mobile) {
|
| | | this.mobile = mobile;
|
| | | }
|
| | |
|
| | | public String getEmail() {
|
| | | return email;
|
| | | }
|
| | |
|
| | | public void setEmail(String email) {
|
| | | this.email = email;
|
| | | }
|
| | |
|
| | | public String getWeixin() {
|
| | | return weixin;
|
| | | }
|
| | |
|
| | | public void setWeixin(String weixin) {
|
| | | this.weixin = weixin;
|
| | | }
|
| | |
|
| | | public String getIsDelete() {
|
| | | return isDelete;
|
| | | }
|
| | |
|
| | | public void setIsDelete(String isDelete) {
|
| | | this.isDelete = isDelete;
|
| | | }
|
| | |
|
| | | public Date getCreateTime() {
|
| | | return createTime;
|
| | | }
|
| | |
|
| | | public void setCreateTime(Date createTime) {
|
| | | this.createTime = createTime;
|
| | | }
|
| | |
|
| | | public Date getExpireTime() {
|
| | | return expireTime;
|
| | | }
|
| | |
|
| | | public void setExpireTime(Date expireTime) {
|
| | | this.expireTime = expireTime;
|
| | | }
|
| | | } |
| | |
| | |
|
| | | import java.util.Date;
|
| | |
|
| | | import lombok.Data;
|
| | |
|
| | | @Data
|
| | | public class Organization {
|
| | | private Integer id;
|
| | |
|
| | |
| | |
|
| | | private String description;
|
| | |
|
| | | public Integer getId() {
|
| | | return id;
|
| | | }
|
| | |
|
| | | public void setId(Integer id) {
|
| | | this.id = id;
|
| | | }
|
| | |
|
| | | public String getName() {
|
| | | return name;
|
| | | }
|
| | |
|
| | | public void setName(String name) {
|
| | | this.name = name;
|
| | | }
|
| | |
|
| | | public Integer getRank() {
|
| | | return rank;
|
| | | }
|
| | |
|
| | | public void setRank(Integer rank) {
|
| | | this.rank = rank;
|
| | | }
|
| | |
|
| | | public Integer getProvinceCode() {
|
| | | return provinceCode;
|
| | | }
|
| | |
|
| | | public void setProvinceCode(Integer provinceCode) {
|
| | | this.provinceCode = provinceCode;
|
| | | }
|
| | |
|
| | | public Integer getCityCode() {
|
| | | return cityCode;
|
| | | }
|
| | |
|
| | | public void setCityCode(Integer cityCode) {
|
| | | this.cityCode = cityCode;
|
| | | }
|
| | |
|
| | | public Integer getAreaCode() {
|
| | | return areaCode;
|
| | | }
|
| | |
|
| | | public void setAreaCode(Integer areaCode) {
|
| | | this.areaCode = areaCode;
|
| | | }
|
| | |
|
| | | public String getAddress() {
|
| | | return address;
|
| | | }
|
| | |
|
| | | public void setAddress(String address) {
|
| | | this.address = address;
|
| | | }
|
| | |
|
| | | public String getTelephone() {
|
| | | return telephone;
|
| | | }
|
| | |
|
| | | public void setTelephone(String telephone) {
|
| | | this.telephone = telephone;
|
| | | }
|
| | |
|
| | | public String getEmail() {
|
| | | return email;
|
| | | }
|
| | |
|
| | | public void setEmail(String email) {
|
| | | this.email = email;
|
| | | }
|
| | |
|
| | | public String getIsDelete() {
|
| | | return isDelete;
|
| | | }
|
| | |
|
| | | public void setIsDelete(String isDelete) {
|
| | | this.isDelete = isDelete;
|
| | | }
|
| | |
|
| | | public Date getCreateTime() {
|
| | | return createTime;
|
| | | }
|
| | |
|
| | | public void setCreateTime(Date createTime) {
|
| | | this.createTime = createTime;
|
| | | }
|
| | |
|
| | | public Date getExpireTime() {
|
| | | return expireTime;
|
| | | }
|
| | |
|
| | | public void setExpireTime(Date expireTime) {
|
| | | this.expireTime = expireTime;
|
| | | }
|
| | |
|
| | | public String getDescription() {
|
| | | return description;
|
| | | }
|
| | |
|
| | | public void setDescription(String description) {
|
| | | this.description = description;
|
| | | }
|
| | | } |
| | |
| | | package com.moral.entity;
|
| | |
|
| | | import lombok.Data;
|
| | |
|
| | | @Data
|
| | | public class OrganizationRelation {
|
| | | private Integer id;
|
| | |
|
| | |
| | |
|
| | | private Integer childId;
|
| | |
|
| | | public Integer getId() {
|
| | | return id;
|
| | | }
|
| | |
|
| | | public void setId(Integer id) {
|
| | | this.id = id;
|
| | | }
|
| | |
|
| | | public Integer getParentId() {
|
| | | return parentId;
|
| | | }
|
| | |
|
| | | public void setParentId(Integer parentId) {
|
| | | this.parentId = parentId;
|
| | | }
|
| | |
|
| | | public Integer getChildId() {
|
| | | return childId;
|
| | | }
|
| | |
|
| | | public void setChildId(Integer childId) {
|
| | | this.childId = childId;
|
| | | }
|
| | | } |
| | |
| | |
|
| | | import org.apache.ibatis.annotations.Mapper;
|
| | |
|
| | | import com.moral.common.mapper.BaseMapper;
|
| | | import com.moral.entity.Account;
|
| | | import com.moral.entity.AccountExample;
|
| | |
|
| | |
| | | import java.util.Map;
|
| | |
|
| | | import org.apache.ibatis.annotations.Mapper;
|
| | | import org.apache.ibatis.annotations.Param;
|
| | |
|
| | | import com.moral.common.mapper.BaseMapper;
|
| | | import com.moral.entity.Device;
|
| | | import com.moral.entity.DeviceExample;
|
| | |
|
| | | @Mapper
|
| | | public interface DeviceMapper extends BaseMapper<Device, DeviceExample, Integer> {
|
| | | List<Map<String, Object>> getDeviceStates(Map<String, Object> parameters);
|
| | |
|
| | | List<Map<String, Object>> getDeviceStatesByAccount(Map<String, Object> parameters);
|
| | |
|
| | | List<Map<String, Object>> getSensorsByDevice(@Param("mac")String mac);
|
| | | } |
| | |
| | |
|
| | | import org.apache.ibatis.annotations.Mapper;
|
| | |
|
| | | import com.moral.entity.History;
|
| | | import com.moral.entity.HistoryExample;
|
| | | import org.apache.ibatis.annotations.Param;
|
| | |
|
| | | @Mapper
|
| | | public interface HistoryMapper extends BaseMapper<History, HistoryExample, Integer> {
|
| | |
|
| | | int countByExample(HistoryExample example);
|
| | |
|
| | | int deleteByExample(HistoryExample example);
|
| | |
|
| | | int insert(History record);
|
| | |
|
| | | int insertSelective(History record);
|
| | |
|
| | | List<History> selectByExample(HistoryExample example);
|
| | |
|
| | | int updateByExampleSelective(@Param("record") History record, @Param("example") HistoryExample example);
|
| | |
|
| | | int updateByExample(@Param("record") History record, @Param("example") HistoryExample example);
|
| | | public interface HistoryMapper{
|
| | |
|
| | | Map<String, Double> getDayAQIByDevice(Map<String, Object> parameters);
|
| | |
|
| | | List<Map<String, Object>> getAverageByAll(Map<String, Object> parameters);
|
| | | Map<String, Object> getAllSensorAverageByDevice(Map<String, Object> parameters);
|
| | |
|
| | | List<Map<String, Object>> getSensorsAverageByDevice4Report(Map<String, Object> parameters);
|
| | |
|
| | | List<Map<String, Object>> getAreaAllDataByAccount(Map<String, Object> parameters);
|
| | |
|
| | | } |
| | |
| | |
|
| | | import org.apache.ibatis.annotations.Mapper;
|
| | |
|
| | | import com.moral.common.mapper.BaseMapper;
|
| | | import com.moral.entity.OperateUser;
|
| | | import com.moral.entity.OperateUserExample;
|
| | |
|
| | |
| | |
|
| | | import org.apache.ibatis.annotations.Mapper;
|
| | |
|
| | | import com.moral.common.mapper.BaseMapper;
|
| | | import com.moral.entity.Organization;
|
| | | import com.moral.entity.OrganizationExample;
|
| | |
|
| | |
| | |
|
| | | import org.apache.ibatis.annotations.Mapper;
|
| | |
|
| | | import com.moral.common.mapper.BaseMapper;
|
| | | import com.moral.entity.OrganizationRelation;
|
| | | import com.moral.entity.OrganizationRelationExample;
|
| | |
|
| | |
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
|
| | | import com.moral.common.bean.ResultBean;
|
| | | import com.moral.entity.Account;
|
| | |
|
| | | public interface AccountService {
|
| | |
| | |
|
| | | void setOrgIdsByAccount(Map<String, Object> parameters);
|
| | |
|
| | | ResultBean<Account> screenLogin1(Map<String, Object> parameters);
|
| | |
|
| | |
|
| | | }
|
| | |
| | | package com.moral.service;
|
| | |
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
|
| | | public interface DeviceService {
|
| | |
|
| | | Map<String, Object> getDeviceStates(Map<String, Object> parameters);
|
| | | Map<String, Object> getDeviceStatesByAccount(Map<String, Object> parameters);
|
| | |
|
| | | List<Map<String, Object>> getSensorsByDevice(String mac);
|
| | | }
|
| | |
| | | package com.moral.service;
|
| | |
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
|
| | |
|
| | | public interface HistoryService {
|
| | |
|
| | | Map<String, Object> getAverageByAll(Map<String, Object> parameters);
|
| | | Map<String, Object> getAllSensorAverageByDevice(Map<String, Object> parameters);
|
| | |
|
| | | Map<String, Object> getAverageBySensor(Map<String, Object> parameters);
|
| | | Map<String, Object> getDeviceRankingBySensorAverage(Map<String, Object> parameters);
|
| | |
|
| | | Map<String, Object> getDayAQIByDevice(Map<String, Object> parameters);
|
| | |
|
| | | Map<String, Object> getMonthAverageBySensor(Map<String, Object> parameters);
|
| | |
|
| | | List<Map<String, Object>> getSensorsAverageByDevice4Report(Map<String, Object> parameters, List<Map<String, Object>> sensorKeys);
|
| | | }
|
| | |
| | | package com.moral.service.impl;
|
| | |
|
| | | 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.Crypto.md5;
|
| | | import static com.moral.common.util.ResourceUtil.getValue;
|
| | | import static org.apache.commons.lang3.StringUtils.isNumeric;
|
| | | import static org.springframework.util.ObjectUtils.isEmpty;
|
| | |
|
| | | import java.util.HashMap;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | | import java.util.Set;
|
| | |
|
| | | import org.apache.commons.lang3.StringUtils;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.util.ObjectUtils;
|
| | |
|
| | | import com.moral.common.bean.ResultBean;
|
| | | import com.moral.common.exception.BusinessException;
|
| | | import com.moral.common.util.Crypto;
|
| | | import com.moral.entity.Account;
|
| | | import com.moral.entity.AccountExample;
|
| | | import com.moral.mapper.AccountMapper;
|
| | | import com.moral.service.AccountService;
|
| | | import com.moral.service.OrganizationService;
|
| | | import com.moral.util.BusinessException;
|
| | | import com.moral.util.Crypto;
|
| | | import com.moral.util.ResourceUtil;
|
| | |
|
| | | @Service
|
| | | public class AccountServiceImpl implements AccountService {
|
| | |
| | | public Map<String, Object> screenLogin(Map<String, Object> parameters) {
|
| | | Map<String, Object> result = new HashMap<String, Object>();
|
| | | AccountExample example = new AccountExample();
|
| | | String password = Crypto.md5((String) parameters.get("account"));
|
| | | String password = md5((String) parameters.get("account"));
|
| | | example.or().andAccountNameEqualTo((String) parameters.get("account")).andPasswordEqualTo(password);
|
| | | List<Account> accounts = accountMapper.selectByExample(example);
|
| | | if (ObjectUtils.isEmpty(accounts) || accounts.size() != 1) {
|
| | | if (isEmpty(accounts) || accounts.size() != 1) {
|
| | | result.put("msg", "用户名及密码输入错误!");
|
| | | } else {
|
| | | Account account = accounts.get(0);
|
| | | if ("1".equals(account.getIsDelete())) {
|
| | | if (IS_DELETE_FALSE.equals(account.getIsDelete())) {
|
| | | result.put("msg", "登录成功!");
|
| | | result.put("accountId", account.getId());
|
| | | } else {
|
| | |
| | | }
|
| | | return result;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public ResultBean<Account> screenLogin1(Map<String, Object> parameters) {
|
| | | ResultBean<Account> resultBean = new ResultBean<Account>();
|
| | | AccountExample example = new AccountExample();
|
| | | String password = Crypto.md5((String) parameters.get("password"));
|
| | | example.or().andAccountNameEqualTo((String) parameters.get("account")).andPasswordEqualTo(password);
|
| | | List<Account> accounts = accountMapper.selectByExample(example);
|
| | | if (isEmpty(accounts) || accounts.size() != 1) {
|
| | | resultBean.setMsg("用户名及密码输入错误!");
|
| | | resultBean.setCode(ResultBean.FAIL);
|
| | | } else {
|
| | | Account account = accounts.get(0);
|
| | | if (IS_DELETE_FALSE.equals(account.getIsDelete())) {
|
| | | resultBean.setData(account);
|
| | | } else {
|
| | | resultBean.setCode(ResultBean.NO_PERMISSION);
|
| | | resultBean.setMsg("您的账号已禁用,请联系管理员!");
|
| | | }
|
| | | }
|
| | | return resultBean;
|
| | | }
|
| | |
|
| | |
|
| | | @Override
|
| | | public List<Account> getAccountLists(String accountName, String password) {
|
| | |
| | | public void setOrgIdsByAccount(Map<String, Object> parameters) {
|
| | | String accountId = (String) parameters.get("accountId");
|
| | | accountId = accountId.replaceFirst("-", "");
|
| | | if (!StringUtils.isNumeric((String) parameters.get("accountId"))) {
|
| | | if (!isNumeric((String) parameters.get("accountId"))) {
|
| | | throw new BusinessException("accountId 参数不合法!");
|
| | | }
|
| | |
|
| | | Account account = accountMapper.selectByPrimaryKey((Integer.valueOf(accountId)));
|
| | | if (ObjectUtils.isEmpty(account) || "1".equals(account.getIsDelete())) {
|
| | | throw new BusinessException(accountId + "该账号不存在!");
|
| | | if (isEmpty(account) || IS_DELETE_TRUE.equals(account.getIsDelete())) {
|
| | | throw new BusinessException(accountId + ":该账号不存在!");
|
| | | }
|
| | | Integer orgId = account.getOrganizationId();
|
| | | // 不是摩瑞尔账号的需要根据组织来获取数据权限
|
| | |
|
| | | if (!("-1".equals(orgId) || ResourceUtil.getValue("orgId").equals(orgId))) {
|
| | | if (!(-1 == orgId || getValue("orgId").equals(orgId))) {
|
| | | Set<Integer> orgIds = organizationService.getChildOrganizationIds(orgId);
|
| | | parameters.put("orgIds", orgIds);
|
| | | }
|
| | |
| | | private AccountService accountService;
|
| | |
|
| | | @Override
|
| | | public Map<String, Object> getDeviceStates(Map<String, Object> parameters) {
|
| | | public Map<String, Object> getDeviceStatesByAccount(Map<String, Object> parameters) {
|
| | | Map<String, Object> result = new HashMap<String, Object>();
|
| | | accountService.setOrgIdsByAccount(parameters);
|
| | | List<Map<String, Object>> list = deviceMapper.getDeviceStates(parameters);
|
| | | List<Map<String, Object>> list = deviceMapper.getDeviceStatesByAccount(parameters);
|
| | | Long all = 0L, normal = 0L, abnormal = 0L, stop = 0L;
|
| | | for (Map<String, Object> map : list) {
|
| | | Long count = (Long) map.get("count");
|
| | | all += count;
|
| | | switch ((Integer) map.get("state")) {
|
| | | switch (Integer.valueOf((String) map.get("state"))) {
|
| | | case 0:
|
| | | normal = count;
|
| | | break;
|
| | |
| | | result.put("stop", stop);
|
| | | return result;
|
| | | }
|
| | | |
| | | @Override
|
| | | public List<Map<String, Object>> getSensorsByDevice(String mac) {
|
| | | return deviceMapper.getSensorsByDevice(mac);
|
| | | }
|
| | |
|
| | | }
|
| | |
| | | package com.moral.service.impl;
|
| | |
|
| | | import static com.moral.common.bean.Constants.NULL_VALUE;
|
| | | import static org.apache.commons.lang3.time.DateUtils.addDays;
|
| | | import static org.apache.commons.lang3.time.DateUtils.addHours;
|
| | | import static org.apache.commons.lang3.time.DateUtils.addMinutes;
|
| | | import static org.apache.commons.lang3.time.DateUtils.addMonths;
|
| | | import static org.apache.commons.lang3.time.DateUtils.parseDate;
|
| | | import static org.apache.commons.lang3.time.DateUtils.truncate;
|
| | | import static org.springframework.util.ObjectUtils.isEmpty;
|
| | |
|
| | | import java.text.ParseException;
|
| | | import java.util.Calendar;
|
| | | import java.util.Collections;
|
| | | import java.util.Date;
|
| | |
| | | import java.util.Map;
|
| | | import java.util.Set;
|
| | |
|
| | | import org.apache.commons.lang3.time.DateUtils;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.data.mongodb.core.MongoTemplate;
|
| | | import org.springframework.data.mongodb.core.aggregation.Aggregation;
|
| | | import org.springframework.data.mongodb.core.aggregation.AggregationResults;
|
| | | import org.springframework.data.mongodb.core.query.Criteria;
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.util.ObjectUtils;
|
| | |
|
| | | import com.mongodb.BasicDBObject;
|
| | | import com.moral.common.exception.BusinessException;
|
| | | import com.moral.common.util.CalculateUtils;
|
| | | import com.moral.common.util.ResourceUtil;
|
| | | import com.moral.mapper.HistoryMapper;
|
| | | import com.moral.service.AccountService;
|
| | | import com.moral.service.HistoryService;
|
| | | import com.moral.util.CalculateUtils;
|
| | | import com.moral.util.Constants;
|
| | | import com.moral.util.ResourceUtil;
|
| | |
|
| | | @Service
|
| | | public class HistoryServiceImpl implements HistoryService {
|
| | |
| | | private MongoTemplate mongoTemplate;
|
| | |
|
| | | @Override
|
| | | public Map<String, Object> getAverageByAll(Map<String, Object> parameters) {
|
| | | Map<String, Object> result = new LinkedHashMap<String, Object>();
|
| | |
|
| | | public Map<String, Object> getAllSensorAverageByDevice(Map<String, Object> parameters) {
|
| | | accountService.setOrgIdsByAccount(parameters);
|
| | | parameters.put("macKey", "all");
|
| | | Date date = new Date();
|
| | | // 当前时间 -10分钟
|
| | | parameters.put("start", DateUtils.addMinutes(date, -10));
|
| | | parameters.put("start", addMinutes(date, -10));
|
| | | // 当前时间 -5分钟
|
| | | parameters.put("end", DateUtils.addMinutes(date, -5));
|
| | | List<Map<String, Object>> averageByAll = historyMapper.getAverageByAll(parameters);
|
| | |
|
| | | for (Map<String, Object> map : averageByAll) {
|
| | | result.put((String) map.get("mac_key"), map.get("avg"));
|
| | | parameters.put("end", addMinutes(date, -5));
|
| | | String queryColumns = "";
|
| | | for (int i = 1; i < 20; i++) {
|
| | | if (i == 1) {
|
| | | queryColumns += "AVG(value -> '$.e" + i + "') e" + i;
|
| | | } else {
|
| | | queryColumns += " , AVG(value -> '$.e" + i + "') e" + i;
|
| | | }
|
| | | return result;
|
| | | }
|
| | | parameters.put("queryColumns", queryColumns);
|
| | | parameters.put("macKey", "all");
|
| | | List<Map<String, Object>> list = historyMapper.getAreaAllDataByAccount(parameters);
|
| | |
|
| | | return list.get(0);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public Map<String, Object> getAverageBySensor(Map<String, Object> parameters) {
|
| | | public Map<String, Object> getDeviceRankingBySensorAverage(Map<String, Object> parameters) {
|
| | | Map<String, Object> result = new LinkedHashMap<String, Object>();
|
| | |
|
| | | accountService.setOrgIdsByAccount(parameters);
|
| | | Date date = new Date();
|
| | | // 当前时间 -1小时
|
| | | parameters.put("start", DateUtils.addHours(date, -1));
|
| | | parameters.put("start", addHours(date, -1));
|
| | | parameters.put("end", date);
|
| | | List<Map<String, Object>> averageByAll = historyMapper.getAverageByAll(parameters);
|
| | | parameters.put("macKey", "'$."+ parameters.get("macKey")+"'");
|
| | | List<Map<String, Object>> list = historyMapper.getAreaAllDataByAccount(parameters);
|
| | |
|
| | | for (Map<String, Object> map : averageByAll) {
|
| | | for (Map<String, Object> map : list) {
|
| | | result.put((String) map.get("name"), map.get("avg"));
|
| | | }
|
| | | return result;
|
| | |
| | | Map<String, Object> resultMap = new HashMap<String, Object>();
|
| | | Date date = new Date();
|
| | | // 昨日00:00:00
|
| | | parameters.put("start", DateUtils.truncate(DateUtils.addDays(date, -1), Calendar.DATE));
|
| | | parameters.put("start", truncate(addDays(date, -1), Calendar.DATE));
|
| | | // 今日00:00:00
|
| | | parameters.put("end", DateUtils.truncate(date, Calendar.DATE));
|
| | | parameters.put("end", truncate(date, Calendar.DATE));
|
| | | String[] IAQIValues = ResourceUtil.getArrValue("IAQI");
|
| | | Map<String, Double> average = historyMapper.getDayAQIByDevice(parameters);
|
| | | if (ObjectUtils.isEmpty(average)) {
|
| | | resultMap.put("AQI", Constants.NULL_VALUE);
|
| | | if (isEmpty(average)) {
|
| | | resultMap.put("AQI", NULL_VALUE);
|
| | | } else {
|
| | | Set<Double> IAQIs = new HashSet<Double>();
|
| | | for (Map.Entry<String, Double> entry : average.entrySet()) {
|
| | | double minMacKey = 0, maxMacKey = 0, minIAQI = 0, maxIAQI = 0;
|
| | | String[] macKeyValues = ResourceUtil.getArrValue(entry.getKey());
|
| | | Double avg = entry.getValue();
|
| | | if (ObjectUtils.isEmpty(avg)) {
|
| | | if (isEmpty(avg)) {
|
| | | IAQIs.add(null);
|
| | | } else {
|
| | | int index = -1;
|
| | |
| | | }
|
| | | }
|
| | | IAQIs.remove(null);
|
| | | if (ObjectUtils.isEmpty(IAQIs)) {
|
| | | resultMap.put("AQI", Constants.NULL_VALUE);
|
| | | if (isEmpty(IAQIs)) {
|
| | | resultMap.put("AQI", NULL_VALUE);
|
| | | } else {
|
| | | Double AQI = Collections.max(IAQIs);
|
| | | if (AQI == Double.MAX_VALUE) {
|
| | |
| | | public Map<String, Object> getMonthAverageBySensor(Map<String, Object> parameters) {
|
| | | Map<String, Object> result = new HashMap<String, Object>();
|
| | | Date date = new Date();
|
| | | Long end = DateUtils.truncate(date, Calendar.DATE).getTime(),start;
|
| | | Long end = truncate(date, Calendar.DATE).getTime(), start;
|
| | | // 每月一日的数据取上月的数据
|
| | | if (1 == Calendar.getInstance().get(Calendar.DAY_OF_MONTH)) {
|
| | | // 上个月1日00:00:00
|
| | | start = DateUtils.truncate(DateUtils.addMonths(date, -1), Calendar.MONTH).getTime();
|
| | | start = truncate(addMonths(date, -1), Calendar.MONTH).getTime();
|
| | | } else {
|
| | | // 这个月1日00:00:00
|
| | | start = DateUtils.truncate(date, Calendar.MONTH).getTime();
|
| | | start = truncate(date, Calendar.MONTH).getTime();
|
| | | }
|
| | | Aggregation aggregation = Aggregation.newAggregation(
|
| | | Aggregation.match(Criteria.where("mac").is(parameters.get("mac"))),
|
| | |
| | | );
|
| | | AggregationResults<BasicDBObject> results = mongoTemplate.aggregate(aggregation, "data", BasicDBObject.class);
|
| | | List<BasicDBObject> list = results.getMappedResults();
|
| | | if (ObjectUtils.isEmpty(list)) {
|
| | | result.put("average", Constants.NULL_VALUE);
|
| | | if (isEmpty(list)) {
|
| | | result.put("average", NULL_VALUE);
|
| | | } else {
|
| | | result = list.get(0);
|
| | | result.put("average", String.format("%.2f", result.get("average")));
|
| | |
| | | return result;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<Map<String, Object>> getSensorsAverageByDevice4Report(Map<String, Object> parameters,List<Map<String, Object>> sensors) {
|
| | | Object type = parameters.get("type");
|
| | | if ("hour".equals(type)) {
|
| | | parameters.put("type", "%Y-%m-%d %H:00");
|
| | | } else if ("minute".equals(type)) {
|
| | | parameters.put("type", "%Y-%m-%d %H:%i:00");
|
| | | } else {
|
| | | throw new BusinessException("type参数输入错误!");
|
| | | }
|
| | | |
| | | try {
|
| | | Date start = parseDate((String)parameters.get("time"), "yyyy-MM-dd");
|
| | | parameters.put("start", start);
|
| | | parameters.put("end", addDays(start, 1));
|
| | | } catch (ParseException e) {
|
| | | e.printStackTrace();
|
| | | throw new BusinessException("time参数输入错误!");
|
| | | }
|
| | | String queryColumns = "";
|
| | | for (int i = 0; i < sensors.size(); i++) {
|
| | | String sensorKey = (String) sensors.get(i).get("key");
|
| | | if (i == sensors.size() - 1) {
|
| | | queryColumns += "AVG(value -> '$." + sensorKey + "') " + sensorKey;
|
| | | } else {
|
| | | queryColumns += "AVG(value -> '$." + sensorKey + "') " + sensorKey +",";
|
| | | }
|
| | | }
|
| | | parameters.put("queryColumns", queryColumns);
|
| | | |
| | | return historyMapper.getSensorsAverageByDevice4Report(parameters);
|
| | | }
|
| | |
|
| | | }
|
| | |
| | | package com.moral.service.impl;
|
| | |
|
| | | import static com.moral.common.bean.Constants.IS_DELETE_FALSE;
|
| | |
|
| | | import java.util.HashSet;
|
| | | import java.util.List;
|
| | | import java.util.Set;
|
| | |
| | | import com.moral.mapper.OrganizationMapper;
|
| | | import com.moral.mapper.OrganizationRelationMapper;
|
| | | import com.moral.service.OrganizationService;
|
| | | import com.moral.util.Constants;
|
| | |
|
| | | @Service
|
| | | public class OrganizationServiceImpl implements OrganizationService {
|
| | |
| | | OrganizationRelationExample example = new OrganizationRelationExample();
|
| | | example.or().andParentIdEqualTo(orgId);
|
| | | Organization organization = organizationMapper.selectByPrimaryKey(orgId);
|
| | | if (Constants.IS_DELETE_FALSE.equals(organization.getIsDelete())) {
|
| | | if (IS_DELETE_FALSE.equals(organization.getIsDelete())) {
|
| | | List<OrganizationRelation> organizationRelations = organizationRelationMapper.selectByExample(example);
|
| | | for (OrganizationRelation organizationRelation : organizationRelations) {
|
| | | Set<Integer> organizationIds = getChildOrganizationIds(organizationRelation.getParentId());
|
| | |
| | | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
| | | <mapper namespace="com.moral.mapper.DeviceMapper" >
|
| | | <resultMap id="BaseResultMap" type="com.moral.entity.Device" >
|
| | | <id column="id" property="id" jdbcType="INTEGER" />
|
| | | <result column="name" property="name" jdbcType="VARCHAR" />
|
| | | <result column="address" property="address" jdbcType="VARCHAR" />
|
| | | <result column="longitude" property="longitude" jdbcType="REAL" />
|
| | | <result column="latitude" property="latitude" jdbcType="REAL" />
|
| | | <result column="mac" property="mac" jdbcType="VARCHAR" />
|
| | | <result column="state" property="state" jdbcType="CHAR" />
|
| | | <result column="operate_user_id" property="operateUserId" jdbcType="INTEGER" />
|
| | | <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
|
| | | <result column="install_time" property="installTime" jdbcType="TIMESTAMP" />
|
| | | <result column="monitor_point_id" property="monitorPointId" jdbcType="INTEGER" />
|
| | | <result column="device_version_id" property="deviceVersionId" jdbcType="INTEGER" />
|
| | | <!-- |
| | | WARNING - @mbggenerated |
| | | This element is automatically generated by MyBatis Generator, do not modify. |
| | | This element was generated on Wed Nov 29 16:17:59 CST 2017. |
| | | --> |
| | | <id column="id" jdbcType="INTEGER" property="id" /> |
| | | <result column="name" jdbcType="VARCHAR" property="name" /> |
| | | <result column="address" jdbcType="VARCHAR" property="address" /> |
| | | <result column="longitude" jdbcType="REAL" property="longitude" /> |
| | | <result column="latitude" jdbcType="REAL" property="latitude" /> |
| | | <result column="mac" jdbcType="VARCHAR" property="mac" /> |
| | | <result column="operate_user_id" jdbcType="INTEGER" property="operateUserId" /> |
| | | <result column="state" jdbcType="CHAR" property="state" /> |
| | | <result column="create_time" jdbcType="TIMESTAMP" property="createTime" /> |
| | | <result column="install_time" jdbcType="TIMESTAMP" property="installTime" /> |
| | | <result column="monitor_point_id" jdbcType="INTEGER" property="monitorPointId" /> |
| | | <result column="device_version_id" jdbcType="INTEGER" property="deviceVersionId" /> |
| | | </resultMap>
|
| | | <sql id="Example_Where_Clause" >
|
| | | <!-- |
| | | WARNING - @mbggenerated |
| | | This element is automatically generated by MyBatis Generator, do not modify. |
| | | This element was generated on Wed Nov 29 16:17:59 CST 2017. |
| | | --> |
| | | <where >
|
| | | <foreach collection="oredCriteria" item="criteria" separator="or" >
|
| | | <if test="criteria.valid" >
|
| | | <trim prefix="(" suffix=")" prefixOverrides="and" >
|
| | | <trim prefix="(" prefixOverrides="and" suffix=")"> |
| | | <foreach collection="criteria.criteria" item="criterion" >
|
| | | <choose >
|
| | | <when test="criterion.noValue" >
|
| | |
| | | </when>
|
| | | <when test="criterion.listValue" >
|
| | | and ${criterion.condition}
|
| | | <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
|
| | | <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=","> |
| | | #{listItem}
|
| | | </foreach>
|
| | | </when>
|
| | |
| | | </where>
|
| | | </sql>
|
| | | <sql id="Update_By_Example_Where_Clause" >
|
| | | <!-- |
| | | WARNING - @mbggenerated |
| | | This element is automatically generated by MyBatis Generator, do not modify. |
| | | This element was generated on Wed Nov 29 16:17:59 CST 2017. |
| | | --> |
| | | <where >
|
| | | <foreach collection="example.oredCriteria" item="criteria" separator="or" >
|
| | | <if test="criteria.valid" >
|
| | | <trim prefix="(" suffix=")" prefixOverrides="and" >
|
| | | <trim prefix="(" prefixOverrides="and" suffix=")"> |
| | | <foreach collection="criteria.criteria" item="criterion" >
|
| | | <choose >
|
| | | <when test="criterion.noValue" >
|
| | |
| | | </when>
|
| | | <when test="criterion.listValue" >
|
| | | and ${criterion.condition}
|
| | | <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
|
| | | <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=","> |
| | | #{listItem}
|
| | | </foreach>
|
| | | </when>
|
| | |
| | | </where>
|
| | | </sql>
|
| | | <sql id="Base_Column_List" >
|
| | | id, name, address, longitude, latitude, mac, state, operate_user_id, create_time, |
| | | <!-- |
| | | WARNING - @mbggenerated |
| | | This element is automatically generated by MyBatis Generator, do not modify. |
| | | This element was generated on Wed Nov 29 16:17:59 CST 2017. |
| | | --> |
| | | id, name, address, longitude, latitude, mac, operate_user_id, state, create_time, |
| | | install_time, monitor_point_id, device_version_id
|
| | | </sql>
|
| | | <select id="selectByExample" resultMap="BaseResultMap" parameterType="com.moral.entity.DeviceExample" >
|
| | | <select id="selectByExample" parameterType="com.moral.entity.DeviceExample" resultMap="BaseResultMap"> |
| | | <!-- |
| | | WARNING - @mbggenerated |
| | | This element is automatically generated by MyBatis Generator, do not modify. |
| | | This element was generated on Wed Nov 29 16:17:59 CST 2017. |
| | | --> |
| | | select
|
| | | <if test="distinct" >
|
| | | distinct
|
| | |
| | | order by ${orderByClause}
|
| | | </if>
|
| | | </select>
|
| | | <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
|
| | | <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap"> |
| | | <!-- |
| | | WARNING - @mbggenerated |
| | | This element is automatically generated by MyBatis Generator, do not modify. |
| | | This element was generated on Wed Nov 29 16:17:59 CST 2017. |
| | | --> |
| | | select
|
| | | <include refid="Base_Column_List" />
|
| | | from device
|
| | | where id = #{id,jdbcType=INTEGER}
|
| | | </select>
|
| | | <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
|
| | | <!-- |
| | | WARNING - @mbggenerated |
| | | This element is automatically generated by MyBatis Generator, do not modify. |
| | | This element was generated on Wed Nov 29 16:17:59 CST 2017. |
| | | --> |
| | | delete from device
|
| | | where id = #{id,jdbcType=INTEGER}
|
| | | </delete>
|
| | | <delete id="deleteByExample" parameterType="com.moral.entity.DeviceExample" >
|
| | | <!-- |
| | | WARNING - @mbggenerated |
| | | This element is automatically generated by MyBatis Generator, do not modify. |
| | | This element was generated on Wed Nov 29 16:17:59 CST 2017. |
| | | --> |
| | | delete from device
|
| | | <if test="_parameter != null" >
|
| | | <include refid="Example_Where_Clause" />
|
| | | </if>
|
| | | </delete>
|
| | | <insert id="insert" parameterType="com.moral.entity.Device" >
|
| | | <!-- |
| | | WARNING - @mbggenerated |
| | | This element is automatically generated by MyBatis Generator, do not modify. |
| | | This element was generated on Wed Nov 29 16:17:59 CST 2017. |
| | | --> |
| | | insert into device (id, name, address,
|
| | | longitude, latitude, mac,
|
| | | state, operate_user_id, create_time, |
| | | operate_user_id, state, create_time, |
| | | install_time, monitor_point_id, device_version_id
|
| | | )
|
| | | values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{address,jdbcType=VARCHAR},
|
| | | #{longitude,jdbcType=REAL}, #{latitude,jdbcType=REAL}, #{mac,jdbcType=VARCHAR},
|
| | | #{state,jdbcType=CHAR}, #{operateUserId,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, |
| | | #{operateUserId,jdbcType=INTEGER}, #{state,jdbcType=CHAR}, #{createTime,jdbcType=TIMESTAMP}, |
| | | #{installTime,jdbcType=TIMESTAMP}, #{monitorPointId,jdbcType=INTEGER}, #{deviceVersionId,jdbcType=INTEGER}
|
| | | )
|
| | | </insert>
|
| | | <insert id="insertSelective" parameterType="com.moral.entity.Device" >
|
| | | <!-- |
| | | WARNING - @mbggenerated |
| | | This element is automatically generated by MyBatis Generator, do not modify. |
| | | This element was generated on Wed Nov 29 16:17:59 CST 2017. |
| | | --> |
| | | insert into device
|
| | | <trim prefix="(" suffix=")" suffixOverrides="," >
|
| | | <if test="id != null" >
|
| | |
| | | <if test="mac != null" >
|
| | | mac,
|
| | | </if>
|
| | | <if test="state != null" >
|
| | | state,
|
| | | </if>
|
| | | <if test="operateUserId != null" >
|
| | | operate_user_id,
|
| | | </if> |
| | | <if test="state != null"> |
| | | state, |
| | | </if>
|
| | | <if test="createTime != null" >
|
| | | create_time,
|
| | |
| | | <if test="mac != null" >
|
| | | #{mac,jdbcType=VARCHAR},
|
| | | </if>
|
| | | <if test="state != null" >
|
| | | #{state,jdbcType=CHAR},
|
| | | </if>
|
| | | <if test="operateUserId != null" >
|
| | | #{operateUserId,jdbcType=INTEGER},
|
| | | </if> |
| | | <if test="state != null"> |
| | | #{state,jdbcType=CHAR}, |
| | | </if>
|
| | | <if test="createTime != null" >
|
| | | #{createTime,jdbcType=TIMESTAMP},
|
| | |
| | | </trim>
|
| | | </insert>
|
| | | <select id="countByExample" parameterType="com.moral.entity.DeviceExample" resultType="java.lang.Integer" >
|
| | | <!-- |
| | | WARNING - @mbggenerated |
| | | This element is automatically generated by MyBatis Generator, do not modify. |
| | | This element was generated on Wed Nov 29 16:17:59 CST 2017. |
| | | --> |
| | | select count(*) from device
|
| | | <if test="_parameter != null" >
|
| | | <include refid="Example_Where_Clause" />
|
| | | </if>
|
| | | </select>
|
| | | <update id="updateByExampleSelective" parameterType="map" >
|
| | | <!-- |
| | | WARNING - @mbggenerated |
| | | This element is automatically generated by MyBatis Generator, do not modify. |
| | | This element was generated on Wed Nov 29 16:17:59 CST 2017. |
| | | --> |
| | | update device
|
| | | <set >
|
| | | <if test="record.id != null" >
|
| | |
| | | <if test="record.mac != null" >
|
| | | mac = #{record.mac,jdbcType=VARCHAR},
|
| | | </if>
|
| | | <if test="record.state != null" >
|
| | | state = #{record.state,jdbcType=CHAR},
|
| | | </if>
|
| | | <if test="record.operateUserId != null" >
|
| | | operate_user_id = #{record.operateUserId,jdbcType=INTEGER},
|
| | | </if> |
| | | <if test="record.state != null"> |
| | | state = #{record.state,jdbcType=CHAR}, |
| | | </if>
|
| | | <if test="record.createTime != null" >
|
| | | create_time = #{record.createTime,jdbcType=TIMESTAMP},
|
| | |
| | | </if>
|
| | | </update>
|
| | | <update id="updateByExample" parameterType="map" >
|
| | | <!-- |
| | | WARNING - @mbggenerated |
| | | This element is automatically generated by MyBatis Generator, do not modify. |
| | | This element was generated on Wed Nov 29 16:17:59 CST 2017. |
| | | --> |
| | | update device
|
| | | set id = #{record.id,jdbcType=INTEGER},
|
| | | name = #{record.name,jdbcType=VARCHAR},
|
| | |
| | | longitude = #{record.longitude,jdbcType=REAL},
|
| | | latitude = #{record.latitude,jdbcType=REAL},
|
| | | mac = #{record.mac,jdbcType=VARCHAR},
|
| | | state = #{record.state,jdbcType=CHAR},
|
| | | operate_user_id = #{record.operateUserId,jdbcType=INTEGER},
|
| | | state = #{record.state,jdbcType=CHAR}, |
| | | create_time = #{record.createTime,jdbcType=TIMESTAMP},
|
| | | install_time = #{record.installTime,jdbcType=TIMESTAMP},
|
| | | monitor_point_id = #{record.monitorPointId,jdbcType=INTEGER},
|
| | |
| | | </if>
|
| | | </update>
|
| | | <update id="updateByPrimaryKeySelective" parameterType="com.moral.entity.Device" >
|
| | | <!-- |
| | | WARNING - @mbggenerated |
| | | This element is automatically generated by MyBatis Generator, do not modify. |
| | | This element was generated on Wed Nov 29 16:17:59 CST 2017. |
| | | --> |
| | | update device
|
| | | <set >
|
| | | <if test="name != null" >
|
| | |
| | | <if test="mac != null" >
|
| | | mac = #{mac,jdbcType=VARCHAR},
|
| | | </if>
|
| | | <if test="state != null" >
|
| | | state = #{state,jdbcType=CHAR},
|
| | | </if>
|
| | | <if test="operateUserId != null" >
|
| | | operate_user_id = #{operateUserId,jdbcType=INTEGER},
|
| | | </if> |
| | | <if test="state != null"> |
| | | state = #{state,jdbcType=CHAR}, |
| | | </if>
|
| | | <if test="createTime != null" >
|
| | | create_time = #{createTime,jdbcType=TIMESTAMP},
|
| | |
| | | where id = #{id,jdbcType=INTEGER}
|
| | | </update>
|
| | | <update id="updateByPrimaryKey" parameterType="com.moral.entity.Device" >
|
| | | <!-- |
| | | WARNING - @mbggenerated |
| | | This element is automatically generated by MyBatis Generator, do not modify. |
| | | This element was generated on Wed Nov 29 16:17:59 CST 2017. |
| | | --> |
| | | update device
|
| | | set name = #{name,jdbcType=VARCHAR},
|
| | | address = #{address,jdbcType=VARCHAR},
|
| | | longitude = #{longitude,jdbcType=REAL},
|
| | | latitude = #{latitude,jdbcType=REAL},
|
| | | mac = #{mac,jdbcType=VARCHAR},
|
| | | state = #{state,jdbcType=CHAR},
|
| | | operate_user_id = #{operateUserId,jdbcType=INTEGER},
|
| | | state = #{state,jdbcType=CHAR}, |
| | | create_time = #{createTime,jdbcType=TIMESTAMP},
|
| | | install_time = #{installTime,jdbcType=TIMESTAMP},
|
| | | monitor_point_id = #{monitorPointId,jdbcType=INTEGER},
|
| | | device_version_id = #{deviceVersionId,jdbcType=INTEGER}
|
| | | where id = #{id,jdbcType=INTEGER}
|
| | | </update>
|
| | | |
| | | <select id="getDeviceStates" resultType="map">
|
| | | <select id="getDeviceStatesByAccount" resultType="map"> |
| | | SELECT
|
| | | COUNT( d.state ) count,
|
| | | d.state
|
| | | FROM
|
| | | device d
|
| | | <if test="orgIds != null and orgIds.size > 0">
|
| | | ,monitor_point mp,
|
| | | monitor_point_organization mpo |
| | | <if test="orgIds != null and orgIds.size > 0"> |
| | | ,monitor_point mp |
| | | WHERE
|
| | | d.monitor_point_id = mp.id
|
| | | AND mp.id = mpo.monitor_point_id |
| | | AND mpo.organization_id IN
|
| | | <foreach collection="orgIds" item="listItem" open="(" separator="," close=")" >
|
| | | AND mp.organization_id IN |
| | | <foreach close=")" collection="orgIds" item="listItem" open="(" separator=","> |
| | | #{listItem}
|
| | | </foreach>
|
| | | </if>
|
| | | GROUP BY d.state
|
| | | </select>
|
| | | |
| | | <select id="getSensorsByDevice" resultType="map"> |
| | | SELECT |
| | | s.`key`, |
| | | s.`name` |
| | | FROM |
| | | sensor s, |
| | | device d, |
| | | device_version_sensor dvs |
| | | WHERE |
| | | d.mac = #{mac} |
| | | AND d.device_version_id = dvs.version_id |
| | | AND dvs.sensor_id = s.id |
| | | ORDER BY |
| | | s.id |
| | | </select> |
| | | </mapper> |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?>
|
| | | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
| | | <mapper namespace="com.moral.mapper.HistoryMapper"> |
| | | <resultMap id="BaseResultMap" type="com.moral.entity.History"> |
| | | <result column="mac" jdbcType="VARCHAR" property="mac" /> |
| | | <result column="value" jdbcType="OTHER" property="value" /> |
| | | <result column="time" jdbcType="TIMESTAMP" property="time" /> |
| | | <result column="version" jdbcType="INTEGER" property="version" /> |
| | | </resultMap> |
| | | <sql id="Example_Where_Clause"> |
| | | <where> |
| | | <foreach collection="oredCriteria" item="criteria" separator="or"> |
| | | <if test="criteria.valid"> |
| | | <trim prefix="(" prefixOverrides="and" suffix=")"> |
| | | <foreach collection="criteria.criteria" item="criterion"> |
| | | <choose> |
| | | <when test="criterion.noValue"> |
| | | and ${criterion.condition} |
| | | </when> |
| | | <when test="criterion.singleValue"> |
| | | and ${criterion.condition} #{criterion.value} |
| | | </when> |
| | | <when test="criterion.betweenValue"> |
| | | and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} |
| | | </when> |
| | | <when test="criterion.listValue"> |
| | | and ${criterion.condition} |
| | | <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=","> |
| | | #{listItem} |
| | | </foreach> |
| | | </when> |
| | | </choose> |
| | | </foreach> |
| | | </trim> |
| | | </if> |
| | | </foreach> |
| | | </where> |
| | | </sql> |
| | | <sql id="Update_By_Example_Where_Clause"> |
| | | <where> |
| | | <foreach collection="example.oredCriteria" item="criteria" separator="or"> |
| | | <if test="criteria.valid"> |
| | | <trim prefix="(" prefixOverrides="and" suffix=")"> |
| | | <foreach collection="criteria.criteria" item="criterion"> |
| | | <choose> |
| | | <when test="criterion.noValue"> |
| | | and ${criterion.condition} |
| | | </when> |
| | | <when test="criterion.singleValue"> |
| | | and ${criterion.condition} #{criterion.value} |
| | | </when> |
| | | <when test="criterion.betweenValue"> |
| | | and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} |
| | | </when> |
| | | <when test="criterion.listValue"> |
| | | and ${criterion.condition} |
| | | <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=","> |
| | | #{listItem} |
| | | </foreach> |
| | | </when> |
| | | </choose> |
| | | </foreach> |
| | | </trim> |
| | | </if> |
| | | </foreach> |
| | | </where> |
| | | </sql> |
| | | <sql id="Base_Column_List"> |
| | | mac, value, time, version |
| | | </sql> |
| | | <select id="selectByExample" parameterType="com.moral.entity.HistoryExample" resultMap="BaseResultMap"> |
| | | select |
| | | <if test="distinct"> |
| | | distinct |
| | | </if> |
| | | <include refid="Base_Column_List" /> |
| | | from history |
| | | <if test="_parameter != null"> |
| | | <include refid="Example_Where_Clause" /> |
| | | </if> |
| | | <if test="orderByClause != null"> |
| | | order by ${orderByClause} |
| | | </if> |
| | | </select> |
| | | <delete id="deleteByExample" parameterType="com.moral.entity.HistoryExample"> |
| | | delete from history |
| | | <if test="_parameter != null"> |
| | | <include refid="Example_Where_Clause" /> |
| | | </if> |
| | | </delete> |
| | | <insert id="insert" parameterType="com.moral.entity.History"> |
| | | insert into history (mac, value, time, |
| | | version) |
| | | values (#{mac,jdbcType=VARCHAR}, #{value,jdbcType=OTHER}, #{time,jdbcType=TIMESTAMP}, |
| | | #{version,jdbcType=INTEGER}) |
| | | </insert> |
| | | <insert id="insertSelective" parameterType="com.moral.entity.History"> |
| | | insert into history |
| | | <trim prefix="(" suffix=")" suffixOverrides=","> |
| | | <if test="mac != null"> |
| | | mac, |
| | | </if> |
| | | <if test="value != null"> |
| | | value, |
| | | </if> |
| | | <if test="time != null"> |
| | | time, |
| | | </if> |
| | | <if test="version != null"> |
| | | version, |
| | | </if> |
| | | </trim> |
| | | <trim prefix="values (" suffix=")" suffixOverrides=","> |
| | | <if test="mac != null"> |
| | | #{mac,jdbcType=VARCHAR}, |
| | | </if> |
| | | <if test="value != null"> |
| | | #{value,jdbcType=OTHER}, |
| | | </if> |
| | | <if test="time != null"> |
| | | #{time,jdbcType=TIMESTAMP}, |
| | | </if> |
| | | <if test="version != null"> |
| | | #{version,jdbcType=INTEGER}, |
| | | </if> |
| | | </trim> |
| | | </insert> |
| | | <select id="countByExample" parameterType="com.moral.entity.HistoryExample" resultType="java.lang.Integer"> |
| | | select count(*) from history |
| | | <if test="_parameter != null"> |
| | | <include refid="Example_Where_Clause" /> |
| | | </if> |
| | | </select> |
| | | <update id="updateByExampleSelective" parameterType="map"> |
| | | update history |
| | | <set> |
| | | <if test="record.mac != null"> |
| | | mac = #{record.mac,jdbcType=VARCHAR}, |
| | | </if> |
| | | <if test="record.value != null"> |
| | | value = #{record.value,jdbcType=OTHER}, |
| | | </if> |
| | | <if test="record.time != null"> |
| | | time = #{record.time,jdbcType=TIMESTAMP}, |
| | | </if> |
| | | <if test="record.version != null"> |
| | | version = #{record.version,jdbcType=INTEGER}, |
| | | </if> |
| | | </set> |
| | | <if test="_parameter != null"> |
| | | <include refid="Update_By_Example_Where_Clause" /> |
| | | </if> |
| | | </update> |
| | | <update id="updateByExample" parameterType="map"> |
| | | update history |
| | | set mac = #{record.mac,jdbcType=VARCHAR}, |
| | | value = #{record.value,jdbcType=OTHER}, |
| | | time = #{record.time,jdbcType=TIMESTAMP}, |
| | | version = #{record.version,jdbcType=INTEGER} |
| | | <if test="_parameter != null"> |
| | | <include refid="Update_By_Example_Where_Clause" /> |
| | | </if> |
| | | </update> |
| | | <resultMap id="BaseResultMap" type="com.moral.entity.History"> |
| | | <result column="device_mac" jdbcType="VARCHAR" property="deviceMac" /> |
| | | <result column="value" jdbcType="OTHER" property="value" /> |
| | | <result column="time" jdbcType="TIMESTAMP" property="time" /> |
| | | <result column="version" jdbcType="VARCHAR" property="version" /> |
| | | </resultMap> |
| | | <sql id="Example_Where_Clause"> |
| | | <where> |
| | | <foreach collection="oredCriteria" item="criteria" separator="or"> |
| | | <if test="criteria.valid"> |
| | | <trim prefix="(" prefixOverrides="and" suffix=")"> |
| | | <foreach collection="criteria.criteria" item="criterion"> |
| | | <choose> |
| | | <when test="criterion.noValue"> |
| | | and ${criterion.condition} |
| | | </when> |
| | | <when test="criterion.singleValue"> |
| | | and ${criterion.condition} #{criterion.value} |
| | | </when> |
| | | <when test="criterion.betweenValue"> |
| | | and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} |
| | | </when> |
| | | <when test="criterion.listValue"> |
| | | and ${criterion.condition} |
| | | <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=","> |
| | | #{listItem} |
| | | </foreach> |
| | | </when> |
| | | </choose> |
| | | </foreach> |
| | | </trim> |
| | | </if> |
| | | </foreach> |
| | | </where> |
| | | </sql> |
| | | <sql id="Update_By_Example_Where_Clause"> |
| | | <where> |
| | | <foreach collection="example.oredCriteria" item="criteria" separator="or"> |
| | | <if test="criteria.valid"> |
| | | <trim prefix="(" prefixOverrides="and" suffix=")"> |
| | | <foreach collection="criteria.criteria" item="criterion"> |
| | | <choose> |
| | | <when test="criterion.noValue"> |
| | | and ${criterion.condition} |
| | | </when> |
| | | <when test="criterion.singleValue"> |
| | | and ${criterion.condition} #{criterion.value} |
| | | </when> |
| | | <when test="criterion.betweenValue"> |
| | | and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} |
| | | </when> |
| | | <when test="criterion.listValue"> |
| | | and ${criterion.condition} |
| | | <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=","> |
| | | #{listItem} |
| | | </foreach> |
| | | </when> |
| | | </choose> |
| | | </foreach> |
| | | </trim> |
| | | </if> |
| | | </foreach> |
| | | </where> |
| | | </sql> |
| | | <sql id="Base_Column_List"> |
| | | device_mac, value, time, version |
| | | </sql> |
| | | <select id="selectByExample" parameterType="com.moral.entity.HistoryExample" resultMap="BaseResultMap"> |
| | | select |
| | | <if test="distinct"> |
| | | distinct |
| | | </if> |
| | | <include refid="Base_Column_List" /> |
| | | from history |
| | | <if test="_parameter != null"> |
| | | <include refid="Example_Where_Clause" /> |
| | | </if> |
| | | <if test="orderByClause != null"> |
| | | order by ${orderByClause} |
| | | </if> |
| | | </select> |
| | | <delete id="deleteByExample" parameterType="com.moral.entity.HistoryExample"> |
| | | delete from history |
| | | <if test="_parameter != null"> |
| | | <include refid="Example_Where_Clause" /> |
| | | </if> |
| | | </delete> |
| | | <insert id="insert" parameterType="com.moral.entity.History"> |
| | | insert into history (device_mac, value, time, |
| | | version) |
| | | values (#{deviceMac,jdbcType=VARCHAR}, #{value,jdbcType=OTHER}, #{time,jdbcType=TIMESTAMP}, |
| | | #{version,jdbcType=VARCHAR}) |
| | | </insert> |
| | | <insert id="insertSelective" parameterType="com.moral.entity.History"> |
| | | insert into history |
| | | <trim prefix="(" suffix=")" suffixOverrides=","> |
| | | <if test="deviceMac != null"> |
| | | device_mac, |
| | | </if> |
| | | <if test="value != null"> |
| | | value, |
| | | </if> |
| | | <if test="time != null"> |
| | | time, |
| | | </if> |
| | | <if test="version != null"> |
| | | version, |
| | | </if> |
| | | </trim> |
| | | <trim prefix="values (" suffix=")" suffixOverrides=","> |
| | | <if test="deviceMac != null"> |
| | | #{deviceMac,jdbcType=VARCHAR}, |
| | | </if> |
| | | <if test="value != null"> |
| | | #{value,jdbcType=OTHER}, |
| | | </if> |
| | | <if test="time != null"> |
| | | #{time,jdbcType=TIMESTAMP}, |
| | | </if> |
| | | <if test="version != null"> |
| | | #{version,jdbcType=VARCHAR}, |
| | | </if> |
| | | </trim> |
| | | </insert> |
| | | <select id="countByExample" parameterType="com.moral.entity.HistoryExample" resultType="java.lang.Integer"> |
| | | select count(*) from history |
| | | <if test="_parameter != null"> |
| | | <include refid="Example_Where_Clause" /> |
| | | </if> |
| | | </select> |
| | | <update id="updateByExampleSelective" parameterType="map"> |
| | | update history |
| | | <set> |
| | | <if test="record.deviceMac != null"> |
| | | device_mac = #{record.deviceMac,jdbcType=VARCHAR}, |
| | | </if> |
| | | <if test="record.value != null"> |
| | | value = #{record.value,jdbcType=OTHER}, |
| | | </if> |
| | | <if test="record.time != null"> |
| | | time = #{record.time,jdbcType=TIMESTAMP}, |
| | | </if> |
| | | <if test="record.version != null"> |
| | | version = #{record.version,jdbcType=VARCHAR}, |
| | | </if> |
| | | </set> |
| | | <if test="_parameter != null"> |
| | | <include refid="Update_By_Example_Where_Clause" /> |
| | | </if> |
| | | </update> |
| | | <update id="updateByExample" parameterType="map"> |
| | | update history |
| | | set device_mac = #{record.deviceMac,jdbcType=VARCHAR}, |
| | | value = #{record.value,jdbcType=OTHER}, |
| | | time = #{record.time,jdbcType=TIMESTAMP}, |
| | | version = #{record.version,jdbcType=VARCHAR} |
| | | <if test="_parameter != null"> |
| | | <include refid="Update_By_Example_Where_Clause" /> |
| | | </if> |
| | | </update> |
| | | |
| | | <select id="getDayAQIBySensor" resultType="map"> |
| | | <select id="getDayAQIByDevice" resultType="map"> |
| | | SELECT |
| | | AVG(value -> '$.e1') e1, |
| | | AVG(value -> '$.e2') e2, |
| | | AVG(value -> '$.e10') e10, |
| | | AVG(value -> '$.e11') e11, |
| | | AVG(value -> '$.e15') e15, |
| | | AVG(value -> '$.e16') e16 |
| | | AVG(value -> '$.e1') e1, |
| | | AVG(value -> '$.e2') e2, |
| | | AVG(value -> '$.e10') e10, |
| | | AVG(value -> '$.e11') e11, |
| | | AVG(value -> '$.e15') e15, |
| | | AVG(value -> '$.e16') e16 |
| | | FROM |
| | | history |
| | | WHERE |
| | | device_mac = #{mac} |
| | | mac = #{mac} |
| | | AND time > #{start} |
| | | AND time < #{end} |
| | | </select> |
| | | |
| | | <select id="getAverageByAll" resultType="map"> |
| | | <select id="getAllSensorAverageByDevice" resultType="java.util.LinkedHashMap"> |
| | | SELECT |
| | | <if test="macKey != null and macKey != 'all'"> |
| | | e.name, |
| | | </if> |
| | | <if test="macKey == 'all'"> |
| | | h.mac_key, |
| | | </if> |
| | | AVG(h.mac_value) avg |
| | | ${queryColumns}
|
| | | FROM |
| | | history h, |
| | | monitorpoint m, |
| | | equipment e |
| | | WHERE |
| | | m.areacode = #{areaCode} |
| | | AND m.id = epoint |
| | | AND e.mac = h.mac |
| | | AND h.time > #{start} |
| | | AND h.time < #{end} |
| | | device d,
|
| | | monitor_point mp
|
| | | <if test="orgIds != null and orgIds.size > 0"> |
| | | <!-- JOIN org_equ oe ON e.id = oe.equid --> |
| | | AND e.owner_id IN |
| | | LEFT JOIN monitor_point_organization mpo ON mpo.monitor_point_id = mp.id |
| | | AND mpo.organization_id IN
|
| | | <foreach close=")" collection="orgIds" item="listItem" open="(" separator=","> |
| | | #{listItem} |
| | | </foreach> |
| | | </if> |
| | | <if test="macKey != null and macKey != 'all'"> |
| | | AND h.mac_key = #{macKey} |
| | | GROUP BY e.id |
| | | ORDER BY avg |
| | | </if> |
| | | WHERE
|
| | | mp.area_code = #{areaCode} |
| | | AND h.time > #{start} |
| | | AND h.time < #{end}
|
| | | AND h.mac = d.mac |
| | | AND d.monitor_point_id = mp.id |
| | | </select>
|
| | | |
| | | <select id="getAreaAllDataByAccount" resultType="java.util.LinkedHashMap">
|
| | | SELECT
|
| | | <if test="macKey == 'all'"> |
| | | GROUP BY h.mac_key |
| | | ${queryColumns}
|
| | | </if> |
| | | <if test="macKey != 'all'">
|
| | | d.`name`,
|
| | | AVG( h.`value` -> ${macKey}) avg
|
| | | </if> |
| | | FROM
|
| | | history h,
|
| | | device d,
|
| | | monitor_point mp
|
| | | WHERE
|
| | | mp.area_code = #{areaCode} |
| | | AND h.time > #{start} |
| | | AND h.time < #{end}
|
| | | <if test="orgIds != null and orgIds.size > 0">
|
| | | AND mp.organization_id IN
|
| | | <foreach close=")" collection="orgIds" item="listItem" open="(" separator=",">
|
| | | #{listItem}
|
| | | </foreach>
|
| | | </if>
|
| | | AND h.mac = d.mac |
| | | AND d.monitor_point_id = mp.id |
| | | <if test="macKey != 'all'">
|
| | | GROUP BY d.id
|
| | | ORDER BY avg desc
|
| | | </if> |
| | | </select> |
| | | |
| | | <select id="getSensorsAverageByDevice4Report" resultType="map">
|
| | | SELECT
|
| | | DATE_FORMAT(time, #{type}) time,
|
| | | ${queryColumns}
|
| | | FROM
|
| | | history h
|
| | | WHERE
|
| | | h.mac = #{mac}
|
| | | AND h.time >= #{start}
|
| | | AND h.time < #{end}
|
| | | GROUP BY
|
| | | DATE_FORMAT(time, #{type})
|
| | | ORDER BY
|
| | | time
|
| | | </select>
|
| | | |
| | | </mapper> |
| | |
| | | "e1":{ |
| | | "level1":35, |
| | | "level2":115, |
| | | "level3":250 |
| | | "level3":250, |
| | | "enable":1 |
| | | }, |
| | | "e2":{ |
| | | "level1":50, |
| | | "level2":250, |
| | | "level3":420 |
| | | "level3":420, |
| | | "enable":1 |
| | | }, |
| | | "e3":{ |
| | | "level1":2000, |
| | | "level2":5000, |
| | | "level3":8000 |
| | | "level1":20000, |
| | | "level2":30000, |
| | | "level3":40000, |
| | | "enable":0 |
| | | }, |
| | | "e4":{ |
| | | "level1":10, |
| | | "level2":30, |
| | | "level3":60 |
| | | "level1":30, |
| | | "level2":75, |
| | | "level3":100, |
| | | "enable":0 |
| | | }, |
| | | "e5":{ |
| | | "level1":0.01, |
| | | "level2":0.02, |
| | | "level3":0.05 |
| | | "level3":0.05, |
| | | "enable":0 |
| | | }, |
| | | "e6":{ |
| | | "level1":60, |
| | | "level2":100, |
| | | "level3":160 |
| | | "level3":160, |
| | | "enable":0 |
| | | }, |
| | | "e7":{ |
| | | "level1":35, |
| | | "level2":30, |
| | | "level3":40 |
| | | "level3":40, |
| | | "enable":0 |
| | | }, |
| | | "e8":{ |
| | | "level1":30, |
| | | "level2":40, |
| | | "level3":50 |
| | | "level3":50, |
| | | "enable":0 |
| | | }, |
| | | "e9":{ |
| | | "level1":0.01, |
| | | "level2":0.02, |
| | | "level3":0.03 |
| | | "level3":0.03, |
| | | "enable":0 |
| | | }, |
| | | "e10":{ |
| | | "level1":2, |
| | | "level2":14, |
| | | "level3":36 |
| | | "level3":36, |
| | | "enable":1 |
| | | }, |
| | | "e11":{ |
| | | "level1":0.05, |
| | | "level2":0.475, |
| | | "level3":1.6 |
| | | "level1":50, |
| | | "level2":475, |
| | | "level3":1600, |
| | | "enable":1 |
| | | }, |
| | | "e12":{ |
| | | "level1":10000, |
| | | "level2":15000, |
| | | "level3":25000 |
| | | "level3":20000, |
| | | "enable":0 |
| | | }, |
| | | "e13":{ |
| | | "level1":30, |
| | | "level2":50, |
| | | "level3":90 |
| | | "level1":60, |
| | | "level2":90, |
| | | "level3":120, |
| | | "enable":0 |
| | | }, |
| | | "e14":{ |
| | | "level1":2, |
| | | "level2":4, |
| | | "level3":6 |
| | | "level1":100, |
| | | "level2":200, |
| | | "level3":300, |
| | | "enable":0 |
| | | }, |
| | | "e15":{ |
| | | "level1":0.16, |
| | | "level2":0.3, |
| | | "level3":0.8 |
| | | "level1":160, |
| | | "level2":300, |
| | | "level3":800, |
| | | "enable":1 |
| | | }, |
| | | "e16":{ |
| | | "level1":0.04, |
| | | "level2":0.18, |
| | | "level3":0.565 |
| | | "level1":40, |
| | | "level2":180, |
| | | "level3":565, |
| | | "enable":1 |
| | | }, |
| | | "e17":{ |
| | | "level1":1, |
| | | "level2":2, |
| | | "level3":5 |
| | | "level1":1.5, |
| | | "level2":3, |
| | | "level3":5, |
| | | "enable":0 |
| | | }, |
| | | "e18":{ |
| | | "level1":5, |
| | | "level2":6, |
| | | "level3":8 |
| | | "level3":8, |
| | | "enable":0 |
| | | }, |
| | | "e19":{ |
| | | "level1":480, |
| | | "level2":580, |
| | | "level3":680 |
| | | "level1":3000, |
| | | "level2":4000, |
| | | "level3":5000, |
| | | "enable":0 |
| | | } |
| | | } |