kaiyu
2020-12-15 3a46aae0a8e9e4bd3cb8dcd1185a69a74668995b
src/main/java/com/moral/controller/WebController.java
@@ -44,6 +44,7 @@
    AccountService accountService;
    @Resource
    DictionaryDataService dictionaryDataService;
    @Resource
    OrganizationService organizationService;
    @Resource
    WebTokenService webTokenService;
@@ -63,21 +64,23 @@
    OrganizationSensorsService organizationSensorsService;
    @Resource
    MapPathService mapPathService;
    @Resource
    HistoryService historyService;
    @GetMapping("test")
    public ResultBean<List<WebProvince>> add(HttpServletRequest request) {
        String token =  request.getHeader("token");
        String token = request.getHeader("token");
        List<WebProvince> mapPath = mapPathService.getMapPath(token);
        if(ObjectUtils.isEmpty(mapPath))
            return new ResultBean<>("获取地图信息失败",ResultBean.FAIL);
        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>
     * @return: java.util.Map<java.lang.String                                                               ,                                                               java.lang.Object>
     * @Author: 下雨听风
     * @Date: 2020/10/19
     */
@@ -101,7 +104,7 @@
    /**
     * @Description: 退出接口
     * @Param: [request]
     * @return: java.util.Map<java.lang.String               ,               java.lang.Object>
     * @return: java.util.Map<java.lang.String                                                               ,                                                               java.lang.Object>
     * @Author: 下雨听风
     * @Date: 2020/10/19
     */
@@ -116,13 +119,10 @@
        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) {
@@ -134,48 +134,9 @@
            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;
    }
@@ -183,7 +144,7 @@
    /**
     * @Description: 获取传感器平均值
     * @Param: [request]
     * @return: com.moral.common.bean.ResultBean<java.util.List               <               java.util.Map               <               java.lang.String               ,               java.lang.Object>>>
     * @return: com.moral.common.bean.ResultBean<java.util.List                                                               <                                                               java.util.Map                                                               <                                                               java.lang.String                                                               ,                                                               java.lang.Object>>>
     * @Author: 下雨听风
     * @Date: 2020/10/19
     */
@@ -212,7 +173,7 @@
    /**
     * @Description: 获取某个站点设备信息
     * @Param: [request]
     * @return: com.moral.common.bean.ResultBean<java.util.List               <               com.moral.entity.MonitorPoint>>
     * @return: com.moral.common.bean.ResultBean<java.util.List                                                               <                                                               com.moral.entity.MonitorPoint>>
     * @Author: 下雨听风
     * @Date: 2020/10/19
     */
@@ -228,7 +189,7 @@
    /**
     * @Description: 获取坐标接口,前端用于建点
     * @Param: [request]
     * @return: com.moral.common.bean.ResultBean<java.util.List               <               com.moral.entity.Device>>
     * @return: com.moral.common.bean.ResultBean<java.util.List                                                               <                                                               com.moral.entity.Device>>
     * @Author: 下雨听风
     * @Date: 2020/10/19
     */
@@ -243,13 +204,83 @@
    /**
     * @Description: 根据monitorId获取该站点下每一台设备具体传感器的五分钟平均值
     * @Param: []
     * @return: com.moral.common.bean.ResultBean<java.util.Map               <               java.lang.String               ,               java.lang.Object>>
     * @return: com.moral.common.bean.ResultBean<java.util.Map                                                               <                                                               java.lang.String                                                               ,                                                               java.lang.Object>>
     * @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.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 -> {
            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) {
    public ResultBean<Map<String, Object>> getSensorFiveMinuteAvgData(HttpServletRequest request) {
        //获取参数,传感器和monitorpointId
        Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
        if ((!parameters.containsKey("sensorKey")) || (!parameters.containsKey("monitorPointId")))
@@ -284,30 +315,30 @@
        datas = insertDeviceInfo(datas, devices);
        //根据monitorPointId获取国控站坐标
        List<Map<String,Object>> coordinate = new ArrayList<>();
        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())) {
        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());
                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);
        Map<String, Object> datasMap = new HashMap<>();
        datasMap.put("coordinate", coordinate);
        datasMap.put("device", datas);
        return new ResultBean<Map<String,Object>>(datasMap);
        return new ResultBean<Map<String, Object>>(datasMap);
    }
    @GetMapping("cangzhouMIdGetAllDevice")
    public ResultBean<Map<String,Object>> cangzhouMIdGetAllDevice(HttpServletRequest request) {
    public ResultBean<Map<String, Object>> cangzhouMIdGetAllDevice(HttpServletRequest request) {
        //获取参数,传感器和monitorpointId
        Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
        if ((!parameters.containsKey("sensorKey")) || (!parameters.containsKey("monitorPointId")))
@@ -317,10 +348,10 @@
        MonitorPoint mPoint = monitorPointService.queryMonitorPointById(monitorPointId);
        Integer code = mPoint.getCityCode();
        List<Device> devices = null;
        if (code == 130900){
             devices = deviceService.getDeviceByCode();
        }else {
             devices = deviceService.getDevicesByMonitorPointId(monitorPointId);
        if (code == 130900) {
            devices = deviceService.getDeviceByCode();
        } else {
            devices = deviceService.getDevicesByMonitorPointId(monitorPointId);
        }
        //根据monitorpointId获取该站点下所有设备mac集合
        if (ObjectUtils.isEmpty(devices))
@@ -348,35 +379,35 @@
        datas = insertDeviceInfo(datas, devices);
        //根据monitorPointId获取国控站坐标
        List<Map<String,Object>> coordinate = new ArrayList<>();
        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())) {
        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());
                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);
        Map<String, Object> datasMap = new HashMap<>();
        datasMap.put("coordinate", coordinate);
        datasMap.put("device", datas);
        return new ResultBean<Map<String,Object>>(datasMap);
        return new ResultBean<Map<String, Object>>(datasMap);
    }
    /**
    * @Description: 根据mac号获取单台设备信息,特殊客户只显示客户需要的传感器信息
            * @Param: [request]
            * @return: com.moral.common.bean.ResultBean<java.util.Map<java.lang.String,java.lang.Object>>
            * @Author: 下雨听风
            * @Date: 2020/10/22
            */
    /**
     * @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号
@@ -446,22 +477,85 @@
        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>> mapPath(HttpServletRequest request) {
        String token =  request.getHeader("token");
    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);
        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/12/8
            */
    @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]
     * @return: java.util.List<java.util.Map               <               java.lang.String               ,               java.lang.Object>>
     * @Author: 下雨听风
     * @Date: 2020/10/19
     */