From a0d0ad8de7ac244aa29d1ca84d13b90e74729e33 Mon Sep 17 00:00:00 2001
From: kaiyu <404897439@qq.com>
Date: Mon, 19 Oct 2020 13:16:04 +0800
Subject: [PATCH] 增加获取六参五分钟平均值接口
---
src/main/java/com/moral/controller/WebController.java | 220 ++++++++++++++++++++++++++++++++++++++-----------------
1 files changed, 152 insertions(+), 68 deletions(-)
diff --git a/src/main/java/com/moral/controller/WebController.java b/src/main/java/com/moral/controller/WebController.java
index 1450043..7b66415 100644
--- a/src/main/java/com/moral/controller/WebController.java
+++ b/src/main/java/com/moral/controller/WebController.java
@@ -3,25 +3,27 @@
import com.auth0.jwt.exceptions.JWTDecodeException;
import com.moral.common.bean.ResultBean;
import com.moral.common.exception.WebAuthException;
-import com.moral.common.util.BeanUtils;
-import com.moral.common.util.ParameterUtils;
-import com.moral.common.util.RedisHashUtil;
-import com.moral.common.util.WebTokenUtils;
+import com.moral.common.util.*;
import com.moral.common.webAnno.UserLoginToken;
import com.moral.entity.AreaNames;
+import com.moral.entity.Device;
+import com.moral.entity.MonitorPoint;
import com.moral.entity.Organization;
import com.moral.service.*;
+import com.moral.util.DateUtil;
import com.moral.util.LatLngTransformation;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
import jdk.nashorn.internal.runtime.logging.Logger;
+import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.text.SimpleDateFormat;
+import java.util.*;
import java.util.stream.Collectors;
import static com.moral.common.util.WebUtils.getParametersStartingWith;
@@ -42,6 +44,11 @@
RedisHashUtil redisHashUtil;
@Resource
HistoryMinutelyService historyMinutelyService;
+ @Resource
+ MonitorPointService monitorPointService;
+ @Resource
+ DeviceService deviceService;
+
@UserLoginToken
@GetMapping("test")
@@ -49,6 +56,13 @@
return "test success!";
}
+ /**
+ * @Description: ������������
+ * @Param: [parameters]
+ * @return: java.util.Map<java.lang.String,java.lang.Object>
+ * @Author: ������������
+ * @Date: 2020/10/19
+ */
@PostMapping("login")
public Map<String, Object> login(@RequestBody Map<String, Object> parameters) {
Map<String, Object> resultMap = new HashMap<String, Object>();
@@ -66,6 +80,13 @@
return resultMap;
}
+ /**
+ * @Description: ������������
+ * @Param: [request]
+ * @return: java.util.Map<java.lang.String,java.lang.Object>
+ * @Author: ������������
+ * @Date: 2020/10/19
+ */
@UserLoginToken
@PostMapping("logout")
public Map<String, Object> logout(HttpServletRequest request) {
@@ -77,6 +98,13 @@
return resultMap;
}
+ /**
+ * @Description:
+ * @Param: [request]
+ * @return: java.util.Map<java.lang.String,java.lang.Object>
+ * @Author: ������������
+ * @Date: 2020/10/19
+ */
@UserLoginToken
@GetMapping("getAccountInfo")
public Map<String, Object> getAccountInfo(HttpServletRequest request) {
@@ -133,69 +161,19 @@
return resultMap;
}
- //������
- @UserLoginToken
- @RequestMapping("getAccountInfoTest")
- public Map<String, Object> getAccountInfoTest(@RequestBody Map<String, Object> parameters) {
- Map<String, Object> resultMap = new HashMap<String, Object>();
- System.out.println(parameters);
- if (!(parameters.containsKey("account") && parameters.containsKey("password"))) {
- resultMap.put("msg", "������������������������������������");
- resultMap.put("accountId", -1);
- } else {
- resultMap = accountService.screenLoginNew(parameters);
- // ������������������������������������������
- Object orgId = resultMap.get("orgId");
- if (resultMap.get("orgId") != null && resultMap.get("orgId") instanceof Integer) {
- StringBuilder areaNamesBuilder = new StringBuilder("������");
- //���������������������������������
- if (!((Integer) orgId).equals(dictionaryDataService.querySupperOrgId())) {
- //���������������������������������������������������
- Organization organization = organizationService.getOrganizationById((Integer) orgId);
- if (organization.getAreaNames() != null) {
- Map<String, String> areaNameMap = BeanUtils.beanToMap(organization.getAreaNames());
- List<String> names = areaNameMap.entrySet().stream().filter(item -> {
- return item.getValue() != null;
- }).map(item -> {
- return item.getValue();
- }).collect(Collectors.toList());
- AreaNames areaNames = organization.getAreaNames();
- areaNamesBuilder.append("/");
- areaNamesBuilder.append(String.join("/", names));
- }
- // ������������
- if (organization.getRank() != null && organization.getRank() == 0) {
- resultMap.put("type", "enterprise");
- } else {
- resultMap.put("type", "government");
- }
- Number mapAreaCode = null;
- if (organization.getVillageCode() != null) {
- mapAreaCode = organization.getVillageCode();
- } else if (organization.getTownCode() != null) {
- mapAreaCode = organization.getTownCode();
- } else if (organization.getAreaCode() != null) {
- mapAreaCode = organization.getAreaCode();
- } else if (organization.getCityCode() != null) {
- mapAreaCode = organization.getCityCode();
- } else if (organization.getProvinceCode() != null) {
- mapAreaCode = organization.getProvinceCode();
- }
- resultMap.put("mapAreaCode", mapAreaCode.toString());
- }
- resultMap.put("mapPath", areaNamesBuilder.toString());
- String accountId = String.valueOf(resultMap.get("accountId"));
- resultMap.put("token", webTokenService.getToken(accountId));
- }
- }
- return resultMap;
- }
-
+ /**
+ * @Description: ������������������������
+ * @Param: [request]
+ * @return: com.moral.common.bean.ResultBean<java.util.List<java.util.Map<java.lang.String,java.lang.Object>>>
+ * @Author: ������������
+ * @Date: 2020/10/19
+ */
@UserLoginToken
- @PostMapping("report_avg_datas")
- public ResultBean<List<Map<String, Object>>> getMonitorPointOrDeviceAvgData(HttpServletRequest request,@RequestBody Map<String, Object> parameters)
+ @GetMapping("report_avg_datas")
+ public ResultBean<List<Map<String, Object>>> getMonitorPointOrDeviceAvgData(HttpServletRequest request)
throws Exception {
+ Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
//������������������������������������������������
ParameterUtils.getTimeType4Time(parameters);
Object sensorKey = parameters.remove("sensorKey");
@@ -212,4 +190,110 @@
}
return new ResultBean<List<Map<String, Object>>>(list);
}
+
+ /**
+ * @Description: ������������������������������
+ * @Param: [request]
+ * @return: com.moral.common.bean.ResultBean<java.util.List<com.moral.entity.MonitorPoint>>
+ * @Author: ������������
+ * @Date: 2020/10/19
+ */
+ @UserLoginToken
+ @GetMapping("monitorpoints-devices")
+ public ResultBean<List<MonitorPoint>> getMonitorPointsAndDevicesByRegion(HttpServletRequest request)
+ throws Exception {
+ Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
+ List<MonitorPoint> monitorPoints = monitorPointService.getMonitorPointsAndDevicesByRegion(parameters);
+ return new ResultBean<List<MonitorPoint>>(monitorPoints);
+ }
+
+ /**
+ * @Description: ���������������������������������������
+ * @Param: [request]
+ * @return: com.moral.common.bean.ResultBean<java.util.List<com.moral.entity.Device>>
+ * @Author: ������������
+ * @Date: 2020/10/19
+ */
+ /* @UserLoginToken*/
+ @GetMapping("coordinates")
+ public ResultBean<List<Device>> getDeviceCoordinatesAndState(HttpServletRequest request){
+ Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
+ ParameterUtils.getRegionType4RegionCode(parameters);
+ return new ResultBean<List<Device>>(deviceService.queryDevice(parameters));
+ }
+
+ /**
+ * @Description: ������monitorId���������������������������������������������������������������������
+ * @Param: []
+ * @return: com.moral.common.bean.ResultBean<java.util.Map<java.lang.String,java.lang.Object>>
+ * @Author: ������������
+ * @Date: 2020/10/19
+ */
+
+ @GetMapping("fiveMinuteAvgData")
+ public ResultBean<List<Map<String, Object>>> getSensorFiveMinuteAvgData(HttpServletRequest request){
+ //���������������������������monitorpointId
+ Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
+ if((!parameters.containsKey("sensorKey"))||(!parameters.containsKey("monitorPointId")))
+ return ResultBean.fail("���������null");
+ String sensorKey = (String) parameters.get("sensorKey");
+ Integer monitorPointId = Integer.parseInt((String) parameters.get("monitorPointId"));
+
+ //������monitorpointId������������������������������mac������
+ List<Device> devices = deviceService.getDevicesByMonitorPointId(monitorPointId);
+ if(ObjectUtils.isEmpty(devices))
+ return ResultBean.fail("���������������������monitorPointId������");
+ List<String> macs = new ArrayList<>();
+ devices.forEach(p->{
+ macs.add(p.getMac());
+ });
+
+ //���������������mac���������������������������������������������������������
+ Map<String, Object> timeAndYearMonth = getTimeAndYearMonthForFiveMinuteData();
+ String time= (String) timeAndYearMonth.get("time");
+ String yearAndMonth = (String) timeAndYearMonth.get("yearAndMonth");
+ parameters.put("time",time);
+ parameters.put("yearAndMonth",yearAndMonth);
+ parameters.put("macs",macs);
+ List<Map<String, Object>> datas = historyMinutelyService.getFiveMinutesDataByMacsAndTime(parameters);
+ return new ResultBean<List<Map<String, Object>>>(datas);
+
+ }
+
+ /**
+ * @Description: ������������������������������������������������������������������������������
+ * @Param: []
+ * @return: java.lang.String
+ * @Author: ������������
+ * @Date: 2020/10/19
+ */
+ private Map<String, Object> getTimeAndYearMonthForFiveMinuteData() {
+ Map<String, Object> map = new HashMap<>();
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ Date date = new Date();
+ String minute = DateUtil.getMinute(date);
+ String year = "";
+ String month = "";
+ String yearAndMonth = "";
+ String startTime = "";
+ Integer endMinute = Integer.parseInt(String.valueOf(minute.charAt(minute.length() - 1)));
+ if (endMinute >= 5) {
+ StringBuilder time = new StringBuilder(sdf.format(date));
+ startTime = time.replace(15, 19, "0:00").toString();
+ } else {
+ date = DateUtil.rollMinute(date, -5);
+ StringBuilder time = new StringBuilder(sdf.format(date));
+ startTime = time.replace(15, 19, "5:00").toString();
+ }
+
+ year = DateUtil.getYear(date);
+ month = DateUtil.getMonth(date);
+ yearAndMonth = year + month;
+ map.put("time", startTime);
+ map.put("yearAndMonth", yearAndMonth);
+ return map;
+ }
+
+
+
}
--
Gitblit v1.8.0