From 129e7dde5da351e111c53d34b7dfa0d4c1f896ef Mon Sep 17 00:00:00 2001 From: kaiyu <404897439@qq.com> Date: Tue, 08 Dec 2020 10:09:53 +0800 Subject: [PATCH] 添加网页版获取单台设备一个小时AQI接口以及获取单台设备的某一个传感器月平均值 --- src/main/java/com/moral/controller/WebController.java | 603 +++++++++++++++++++++++++++++++++++++++++------------- 1 files changed, 456 insertions(+), 147 deletions(-) diff --git a/src/main/java/com/moral/controller/WebController.java b/src/main/java/com/moral/controller/WebController.java index a6fe5fe..d008ceb 100644 --- a/src/main/java/com/moral/controller/WebController.java +++ b/src/main/java/com/moral/controller/WebController.java @@ -5,23 +5,18 @@ import com.moral.common.exception.WebAuthException; 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.entity.*; +import com.moral.mapper.MapPathMapper; 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.PostConstruct; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; import java.util.stream.Collectors; @@ -33,10 +28,23 @@ @CrossOrigin(origins = "*", maxAge = 3600) @SuppressWarnings({"rawtypes", "unchecked", "unused"}) public class WebController { + + private static Map<String, Sensor> sensors; + + @PostConstruct + public void init() { + sensors = new HashMap<>(); + List<Sensor> allSensors = sensorService.getAllSensors(); + for (Sensor sensor : allSensors) { + sensors.put(sensor.getSensorKey(), sensor); + } + } + @Resource AccountService accountService; @Resource DictionaryDataService dictionaryDataService; + @Resource OrganizationService organizationService; @Resource WebTokenService webTokenService; @@ -48,21 +56,34 @@ MonitorPointService monitorPointService; @Resource DeviceService deviceService; + @Resource + HistoryFiveMinutelyService historyFiveMinutelyService; + @Resource + SensorService sensorService; + @Resource + OrganizationSensorsService organizationSensorsService; + @Resource + MapPathService mapPathService; + @Resource + HistoryService historyService; - @UserLoginToken @GetMapping("test") - public String add() { - return "test success!"; + public ResultBean<List<WebProvince>> add(HttpServletRequest request) { + String token = request.getHeader("token"); + List<WebProvince> mapPath = mapPathService.getMapPath(token); + if (ObjectUtils.isEmpty(mapPath)) + return new ResultBean<>("������������������������", ResultBean.FAIL); + return new ResultBean<>(mapPath); } - /** - * @Description: ������������ - * @Param: [parameters] - * @return: java.util.Map<java.lang.String,java.lang.Object> - * @Author: ������������ - * @Date: 2020/10/19 - */ + /** + * @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>(); @@ -70,41 +91,38 @@ resultMap.put("msg", "������������������������������������"); resultMap.put("accountId", -1); } else { - resultMap = accountService.webLogin(parameters); + resultMap = accountService.bsWebLogin(parameters); String accountId = String.valueOf(resultMap.get("accountId")); if (!accountId.equals("-1")) { - redisHashUtil.deleteMapVal("webToken",accountId); + redisHashUtil.deleteMapVal("webToken", accountId); resultMap.put("token", webTokenService.getToken(accountId)); } } return resultMap; } - /** - * @Description: ������������ - * @Param: [request] - * @return: java.util.Map<java.lang.String,java.lang.Object> - * @Author: ������������ - * @Date: 2020/10/19 - */ + /** + * @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) { Map<String, Object> resultMap = new HashMap<>(); String token = request.getHeader("token"); - String id = WebTokenUtils.getIdBytoken(token); - redisHashUtil.addMapOne("webToken", String.valueOf(id),token); + String id = WebTokenUtils.getIdBytoken(token); + redisHashUtil.addMapOne("webToken", String.valueOf(id), token); resultMap.put("msg", "������������!"); return resultMap; } - /** - * @Description: - * @Param: [request] - * @return: java.util.Map<java.lang.String,java.lang.Object> - * @Author: ������������ - * @Date: 2020/10/19 - */ + public static void main(String[] args) { + + } + @UserLoginToken @GetMapping("getAccountInfo") public Map<String, Object> getAccountInfo(HttpServletRequest request) { @@ -116,59 +134,20 @@ throw new WebAuthException("401,token������"); } Map<String, Object> resultMap = accountService.getAccountInfoById(id); - 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)); - } + 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 - */ + /** + * @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 @GetMapping("report_avg_datas") public ResultBean<List<Map<String, Object>>> getMonitorPointOrDeviceAvgData(HttpServletRequest request) @@ -183,8 +162,8 @@ String time = map.get("time").toString(); time = time.substring(time.length() - 2); map.put("time", Integer.valueOf(time)); - if(parameters.get("type").equals("day")){ - map.put("time", Integer.valueOf(time)+1); + if (parameters.get("type").equals("day")) { + map.put("time", Integer.valueOf(time) + 1); } map.put("value", map.remove(sensorKey)); } @@ -192,12 +171,12 @@ } /** - * @Description: ������������������������������ - * @Param: [request] - * @return: com.moral.common.bean.ResultBean<java.util.List<com.moral.entity.MonitorPoint>> - * @Author: ������������ - * @Date: 2020/10/19 - */ + * @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) @@ -208,90 +187,402 @@ } /** - * @Description: ��������������������������������������� - * @Param: [request] - * @return: com.moral.common.bean.ResultBean<java.util.List<com.moral.entity.Device>> - * @Author: ������������ - * @Date: 2020/10/19 - */ - /* @UserLoginToken*/ + * @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){ + 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 - */ + * @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 + @UserLoginToken + @GetMapping("fiveMinuteAvgDataNew") + public ResultBean<Map<String, Object>> getSensorFiveMinuteAvgDataNew(HttpServletRequest request) { + //���������������������������regionCode Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null); - if((!parameters.containsKey("sensorKey"))||(!parameters.containsKey("monitorPointId"))) - return ResultBean.fail("���������null"); + if ((!parameters.containsKey("sensorKey")) || (!parameters.containsKey("regionCode"))) + return ResultBean.fail("���������null"); String sensorKey = (String) parameters.get("sensorKey"); - Integer monitorPointId = Integer.parseInt((String) parameters.get("monitorPointId")); + String regionCode = (String) parameters.get("regionCode"); + String token = request.getHeader("token"); - //������monitorpointId������������������������������mac������ - List<Device> devices = deviceService.getDevicesByMonitorPointId(monitorPointId); - if(ObjectUtils.isEmpty(devices)) - return ResultBean.fail("���������������������monitorPointId������"); + //������orgId������������������������������mac������ + String accountId = WebTokenUtils.getIdBytoken(token); + Account account = accountService.getAccountById(Integer.parseInt(accountId)); + parameters.put("organizationId", account.getOrganizationId()); + List<MonitorPoint> monitorPoints = monitorPointService.getMonitorPointsAndDevicesByRegionNew(parameters); + if (ObjectUtils.isEmpty(monitorPoints)) + return ResultBean.fail("������������������������������"); + + List<Device> devices = new ArrayList<>(); + for (MonitorPoint monitorPoint : monitorPoints) { + if (!ObjectUtils.isEmpty(monitorPoint.getDevices())) + devices.addAll(monitorPoint.getDevices()); + } + if (ObjectUtils.isEmpty(devices)) + return ResultBean.fail("������������������������������"); + List<String> macs = new ArrayList<>(); - devices.forEach(p->{ + devices.forEach(p -> { macs.add(p.getMac()); }); //���������������mac��������������������������������������������������������� Map<String, Object> timeAndYearMonth = getTimeAndYearMonthForFiveMinuteData(); - String time= (String) timeAndYearMonth.get("time"); + 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); - datas = insertDeviceInfo(datas,devices); - return new ResultBean<List<Map<String, Object>>>(datas); + parameters.put("time", time); + parameters.put("yearAndMonth", yearAndMonth); + parameters.put("macs", macs); + List<Map<String, Object>> datas = historyFiveMinutelyService.getFiveMinutesDataByMacsAndTime(parameters); + //������������������������������������������������������������������������������ + if (ObjectUtils.isEmpty(datas)) { + time = getFiveMinuteAgoTime(time); + parameters.put("time", time); + datas = historyFiveMinutelyService.getFiveMinutesDataByMacsAndTime(parameters); + } + datas = insertDeviceInfo(datas, devices); + + //������monitorPointId��������������������� + List<Map<String, Object>> coordinate = new ArrayList<>(); + Integer orgId = account.getOrganizationId(); + monitorPoints.forEach(value -> { + if ("���������".equals(value.getDescription())) { + List list = LatLngTransformation.Convert_BD09_To_GCJ02(value.getLatitude(), value.getLongitude()); + Map<String, Object> controlStation = new HashMap<>(); + controlStation.put("name", value.getName()); + controlStation.put("longitude", list.get(0)); + controlStation.put("latitude", list.get(1)); + coordinate.add(controlStation); + } + }); + + Map<String, Object> datasMap = new HashMap<>(); + datasMap.put("coordinate", coordinate); + datasMap.put("device", datas); + + return new ResultBean<Map<String, Object>>(datasMap); + } + + @GetMapping("fiveMinuteAvgData") + public ResultBean<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 = historyFiveMinutelyService.getFiveMinutesDataByMacsAndTime(parameters); + + //������������������������������������������������������������������������������ + if (ObjectUtils.isEmpty(datas)) { + time = getFiveMinuteAgoTime(time); + parameters.put("time", time); + datas = historyFiveMinutelyService.getFiveMinutesDataByMacsAndTime(parameters); + } + datas = insertDeviceInfo(datas, devices); + + //������monitorPointId��������������������� + List<Map<String, Object>> coordinate = new ArrayList<>(); + MonitorPoint monitorPoint = monitorPointService.queryMonitorPointById(monitorPointId); + Integer orgId = monitorPoint.getOrganizationId(); + List<MonitorPoint> monitorPoints = monitorPointService.getMonitorPointsByOrganizationId(orgId); + monitorPoints.forEach(value -> { + if ("���������".equals(value.getDescription())) { + List list = LatLngTransformation.Convert_BD09_To_GCJ02(value.getLatitude(), value.getLongitude()); + Map<String, Object> controlStation = new HashMap<>(); + controlStation.put("name", value.getName()); + controlStation.put("longitude", list.get(0)); + controlStation.put("latitude", list.get(1)); + coordinate.add(controlStation); + } + }); + + Map<String, Object> datasMap = new HashMap<>(); + datasMap.put("coordinate", coordinate); + datasMap.put("device", datas); + + return new ResultBean<Map<String, Object>>(datasMap); + } + + @GetMapping("cangzhouMIdGetAllDevice") + public ResultBean<Map<String, Object>> cangzhouMIdGetAllDevice(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")); + MonitorPoint mPoint = monitorPointService.queryMonitorPointById(monitorPointId); + Integer code = mPoint.getCityCode(); + List<Device> devices = null; + if (code == 130900) { + devices = deviceService.getDeviceByCode(); + } else { + devices = deviceService.getDevicesByMonitorPointId(monitorPointId); + } + //������monitorpointId������������������������������mac������ + 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 = historyFiveMinutelyService.getFiveMinutesDataByMacsAndTime(parameters); + + //������������������������������������������������������������������������������ + if (ObjectUtils.isEmpty(datas)) { + time = getFiveMinuteAgoTime(time); + parameters.put("time", time); + datas = historyFiveMinutelyService.getFiveMinutesDataByMacsAndTime(parameters); + } + datas = insertDeviceInfo(datas, devices); + + //������monitorPointId��������������������� + List<Map<String, Object>> coordinate = new ArrayList<>(); + MonitorPoint monitorPoint = monitorPointService.queryMonitorPointById(monitorPointId); + Integer orgId = monitorPoint.getOrganizationId(); + List<MonitorPoint> monitorPoints = monitorPointService.getMonitorPointsByOrganizationId(orgId); + monitorPoints.forEach(value -> { + if ("���������".equals(value.getDescription())) { + List list = LatLngTransformation.Convert_BD09_To_GCJ02(value.getLatitude(), value.getLongitude()); + Map<String, Object> controlStation = new HashMap<>(); + controlStation.put("name", value.getName()); + controlStation.put("longitude", list.get(0)); + controlStation.put("latitude", list.get(1)); + coordinate.add(controlStation); + } + }); + + Map<String, Object> datasMap = new HashMap<>(); + datasMap.put("coordinate", coordinate); + datasMap.put("device", datas); + + return new ResultBean<Map<String, Object>>(datasMap); } /** - * @Description: ���������������������������������������state + * @Description: ������mac��������������������������������������������������������������������������������� + * @Param: [request] + * @return: com.moral.common.bean.ResultBean<java.util.Map < java.lang.String , java.lang.Object>> + * @Author: ������������ + * @Date: 2020/10/22 + */ + @GetMapping("fiveMinuteAvgDataByMac") + public ResultBean<Map<String, Object>> fiveMinuteAvgDataByMac(HttpServletRequest request) { + //���������������mac��� + Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null); + if ((!parameters.containsKey("mac"))) + return ResultBean.fail("���������null"); + String mac = (String) parameters.get("mac"); + + //������mac������orgId + String orgId = monitorPointService.getOrgIdByMac(mac); + + //��������������������������������������������������������������������������������� + Map<String, Object> specialSensors = organizationSensorsService.getSensorsByOrgId(orgId); + + if (ObjectUtils.isEmpty(specialSensors)) { + List<String> sensorKeys = sensorService.getSensorKeys(); + parameters.put("sensorKeys", sensorKeys); + } else { + String sensorKeys = (String) specialSensors.get("sensors"); + sensorKeys.trim(); + sensorKeys = sensorKeys.substring(1, sensorKeys.length() - 1); + parameters.put("sensorKeys", Arrays.asList(sensorKeys.split(","))); + } + + //������������������ + 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("mac", mac); + + Map<String, Object> datas = historyFiveMinutelyService.getFiveMinutesDataByMac(parameters); + + //������������������������������������������������������������������������������ + if (ObjectUtils.isEmpty(datas)) { + time = getFiveMinuteAgoTime(time); + parameters.put("time", time); + datas = historyFiveMinutelyService.getFiveMinutesDataByMac(parameters); + } + + + //������������������ + datas.values().removeIf((value) -> { + return ObjectUtils.isEmpty(value) || value.equals("[0, 0, 0]"); + }); + + //������������������ + Map<String, Object> sortDatas = new LinkedHashMap<>();//��������������������������������������� + Device device = deviceService.getDeviceByMac(mac, true); + sortDatas.put("������", device.getName()); + + //������������������ + datas.forEach((key, value) -> { + Sensor sensor = sensors.get(key); + if (!ObjectUtils.isEmpty(sensor)) { + String unit = ObjectUtils.isEmpty(sensor.getUnit()) ? "" : (String) sensor.getUnit(); + String str = (String) value; + str.trim(); + str = str.substring(1, str.length() - 1); + sortDatas.put(sensor.getName(), Arrays.asList(str.split(",")).get(0) + unit); + } + }); + + sortDatas.put("������", time); + + return new ResultBean<Map<String, Object>>(sortDatas); + } + + /** + * @Description: ������token������������������ + * @Param: [request] + * @return: com.moral.common.bean.ResultBean<java.util.List < com.moral.entity.WebProvince>> + * @Author: ������������ + * @Date: 2020/11/27 + */ + + @UserLoginToken + @GetMapping("mapPath") + public ResultBean<List<WebProvince>> getMapPath(HttpServletRequest request) { + String token = request.getHeader("token"); + List<WebProvince> mapPath = mapPathService.getMapPath(token); + if (ObjectUtils.isEmpty(mapPath)) + return new ResultBean<>("������������������������", ResultBean.FAIL); + return new ResultBean<>(mapPath); + } + + /** + * @Description: ������������������������ + * @Param: [request] + * @return: com.moral.common.bean.ResultBean<java.util.List<com.moral.entity.MonitorPoint>> + * @Author: ������������ + * @Date: 2020/12/8 + */ + @UserLoginToken + @GetMapping("monitor-points") + public ResultBean<List<MonitorPoint>> getmMnitorPoints(HttpServletRequest request) { + String accountId = WebTokenUtils.getIdBytoken(request.getHeader("token")); + Account account = accountService.getAccountById(Integer.parseInt(accountId)); + String regionCode = request.getParameter("regionCode"); + Map<String, Object> paramMap = new HashMap<>(); + paramMap.put("organizationId", account.getOrganizationId()); + paramMap.put("regionCode", regionCode); + List<MonitorPoint> monitorPoints = monitorPointService.getMonitorPointsAndDevicesByRegion(paramMap); + if (ObjectUtils.isEmpty(monitorPoints)) + return new ResultBean<>("���������������������������", ResultBean.FAIL); + return new ResultBean<List<MonitorPoint>>(monitorPoints); + } + + + /** + * @Description: ��������������������������������������������������� * @Param: [datas, devices] * @return: java.util.List<java.util.Map<java.lang.String,java.lang.Object>> * @Author: ������������ - * @Date: 2020/10/19 + * @Date: 2020/12/8 */ - public List<Map<String, Object>> insertDeviceInfo(List<Map<String, Object>> datas,List<Device> devices ){ - Map<String,Device> map = new HashMap<>(); - devices.forEach(p->{ - map.put(p.getMac(),p); + @UserLoginToken + @GetMapping("sensor-monthAvg") + public ResultBean<Map<String, Object>> getSensorMonthAvgByMac(HttpServletRequest request){ + Map<String, Object> parameters = getParametersStartingWith(request, null); + if ((!parameters.containsKey("mac"))||(!parameters.containsKey("macKey"))) + return ResultBean.fail("���������null"); + Map<String, Object> result = historyMinutelyService.getAverageBySensor(parameters); + return new ResultBean<Map<String, Object>>(result); + } + + /** + * @Description: ���������������������������������AQI + * @Param: [request] + * @return: com.moral.common.bean.ResultBean<java.util.Map<java.lang.String,java.lang.Object>> + * @Author: ������������ + * @Date: 2020/12/8 + */ + @UserLoginToken + @GetMapping("hourly-aqi") + public ResultBean<Map<String, Object>> getHourlyAQI(HttpServletRequest request){ + Map<String, Object> parameters = getParametersStartingWith(request, null); + if (!parameters.containsKey("mac")) + return ResultBean.fail("���������null"); + Map<String, Object> result = historyService.gitHourlyAQIByMacAndTimeslot(parameters); + return new ResultBean<Map<String, Object>>(result); + } + + + /** + * @Description: ���������������������������������������state + * @Param: [datas, devices] + * @Author: ������������ + * @Date: 2020/10/19 + */ + private List<Map<String, Object>> insertDeviceInfo(List<Map<String, Object>> datas, List<Device> devices) { + Map<String, Device> map = new HashMap<>(); + devices.forEach(p -> { + map.put(p.getMac(), p); }); - datas.forEach(p->{ + datas.forEach(p -> { String mac = (String) p.get("mac"); Device device = map.get(mac); List list = LatLngTransformation.Convert_BD09_To_GCJ02(device.getLatitude(), device.getLongitude()); - p.put("longitude",list.get(0)); - p.put("latitude",list.get(1)); - p.put("state",device.getState()); + p.put("longitude", list.get(0)); + p.put("latitude", list.get(1)); + p.put("state", device.getState()); }); return datas; } /** - * @Description: ������������������������������������������������������������������������������ - * @Param: [] - * @return: java.lang.String - * @Author: ������������ - * @Date: 2020/10/19 - */ + * @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"); @@ -302,14 +593,13 @@ String yearAndMonth = ""; String startTime = ""; Integer endMinute = Integer.parseInt(String.valueOf(minute.charAt(minute.length() - 1))); - if (endMinute >= 6||endMinute==0) {//��������������������� 6 7 8 9 0 ������12:16,12:20��������� ���������12:10-12:15��������� + if (endMinute >= 6 || endMinute == 0) {//��������������������� 6 7 8 9 0 ������12:16,12:20��������� ���������12:10-12:15��������� date = DateUtil.rollMinute(date, -1); StringBuilder time = new StringBuilder(sdf.format(date)); - startTime = time.replace(15, 19, "0:00").toString(); - }else {// ���������������������1 2 3 4 5 ������������������������������ ������12:11������������ ���������12:05-12:10��������� - date = DateUtil.rollMinute(date, -9); - StringBuilder time = new StringBuilder(sdf.format(date)); startTime = time.replace(15, 19, "5:00").toString(); + } else {// ���������������������1 2 3 4 5 ������������������������������ ������12:11������������ ���������12:05-12:10��������� + StringBuilder time = new StringBuilder(sdf.format(date)); + startTime = time.replace(15, 19, "0:00").toString(); } year = DateUtil.getYear(date); @@ -321,5 +611,24 @@ } + /** + * @Description: ������������������������������������������������������������ + * @Param: [time] + * @return: java.lang.String + * @Author: ������������ + * @Date: 2020/10/20 + */ + private String getFiveMinuteAgoTime(String time) { + try { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Date date = sdf.parse(time); + date = DateUtil.rollMinute(date, -5); + time = sdf.format(date); + return time; + } catch (ParseException e) { + return null; + } + } + } -- Gitblit v1.8.0