kaiyu
2020-12-01 dbc664b7b328809818bd070e152248249ff2f939
src/main/java/com/moral/controller/WebController.java
@@ -66,6 +66,7 @@
    MapPathService mapPathService;
    @GetMapping("test")
    public ResultBean<List<WebProvince>> add(HttpServletRequest request) {
        String token = request.getHeader("token");
@@ -203,6 +204,75 @@
     * @Author: 下雨听风
     * @Date: 2020/10/19
     */
    @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("regionCode")))
            return ResultBean.fail("参数为null");
        String sensorKey = (String) parameters.get("sensorKey");
        String regionCode = (String) parameters.get("regionCode");
        String token = request.getHeader("token");
        //根据orgId获取该站点下所有设备mac集合
        String accountId = WebTokenUtils.getIdBytoken(token);
        Account account = accountService.getAccountById(Integer.parseInt(accountId));
        parameters.put("organizationId",account.getOrganizationId());
        List<MonitorPoint> monitorPoints = monitorPointService.getMonitorPointsAndDevicesByRegion(parameters);
        if(ObjectUtils.isEmpty(monitorPoints))
            return ResultBean.fail("该账号对应地区无站点");
        List<Device> devices = new ArrayList<>();
        for (MonitorPoint monitorPoint : monitorPoints) {
             devices.addAll(monitorPoint.getDevices());
        }
        if (ObjectUtils.isEmpty(devices))
            return ResultBean.fail("该账号对应地区无设备");
        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<>();
        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) {
@@ -412,7 +482,7 @@
    @UserLoginToken
    @GetMapping("mapPath")
    public ResultBean<List<WebProvince>> mapPath(HttpServletRequest request) {
    public ResultBean<List<WebProvince>> getMapPath(HttpServletRequest request) {
        String token = request.getHeader("token");
        List<WebProvince> mapPath = mapPathService.getMapPath(token);
        if (ObjectUtils.isEmpty(mapPath))
@@ -420,11 +490,25 @@
        return new ResultBean<>(mapPath);
    }
    @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: 返回结果添加设备经纬度以及state
     * @Param: [datas, devices]
     * @return: java.util.List<java.util.Map                               <                               java.lang.String                               ,                               java.lang.Object>>
     * @Author: 下雨听风
     * @Date: 2020/10/19
     */