lizijie
2021-12-24 76cf225f819b84ac017a2cb3e3231ea880eacdd6
热力图接口,报警信息接口
1 files added
11 files modified
1116 ■■■■■ changed files
screen-api/src/main/java/com/moral/api/controller/AlarmInfoController.java 20 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/controller/ChartController.java 179 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/mapper/AlarmInfoMapper.java 2 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/service/AlarmInfoService.java 9 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/service/HistoryDailyService.java 18 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/service/HistoryHourlyService.java 18 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/service/HistoryMonthlyService.java 18 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/service/impl/AlarmInfoServiceImpl.java 87 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/service/impl/HistoryDailyServiceImpl.java 257 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/service/impl/HistoryHourlyServiceImpl.java 233 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/service/impl/HistoryMonthlyServiceImpl.java 257 ●●●●● patch | view | raw | blame | history
screen-api/src/main/resources/mapper/AlarmInfoMapper.xml 18 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/controller/AlarmInfoController.java
@@ -74,4 +74,24 @@
        return ResultMessage.ok(resultMap);
    }
    @RequestMapping(value = "getDataByConditionWithoutPage", method = RequestMethod.GET)
    @ResponseBody
    public ResultMessage getDataByConditionWithoutPage(HttpServletRequest request){
        Map<String, Object> parameters = WebUtils.getParametersStartingWith(request,null);
        Object orgid = parameters.get("organization_id");
        Object startTime = parameters.get("startTime");
        Object endTime = parameters.get("endTime");
        Object index = parameters.get("index");
        Object alarmType = parameters.get("alarmType");
        if (ObjectUtils.isEmpty(orgid) || ObjectUtils.isEmpty(startTime) || ObjectUtils.isEmpty(endTime) || ObjectUtils.isEmpty(index) || ObjectUtils.isEmpty(alarmType)){
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        Organization organization = organizationMapper.selectById(Integer.parseInt(orgid.toString()));
        if (ObjectUtils.isEmpty(organization)){
            return ResultMessage.fail(ResponseCodeEnum.ORGANIZATION_NOT_EXIST.getCode(), ResponseCodeEnum.ORGANIZATION_NOT_EXIST.getMsg());
        }
        Map<String, Object> resultMap = alarmInfoService.getDataByConditionWithoutPage(parameters);
        return ResultMessage.ok(resultMap);
    }
}
screen-api/src/main/java/com/moral/api/controller/ChartController.java
New file
@@ -0,0 +1,179 @@
package com.moral.api.controller;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.moral.api.entity.Organization;
import com.moral.api.mapper.OrganizationMapper;
import com.moral.api.service.HistoryDailyService;
import com.moral.api.service.HistoryHourlyService;
import com.moral.api.service.HistoryMonthlyService;
import com.moral.constant.ResponseCodeEnum;
import com.moral.constant.ResultMessage;
import com.moral.util.DateUtils;
import com.moral.util.WebUtils;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
/**
 * @program: screen
 * @description: 图表数据
 * @author: lizijie
 * @create: 2021-11-10 16:05
 **/
@Slf4j
@Api(tags = {"设备小时数据"})
@RestController
@CrossOrigin(origins = "*", maxAge = 3600)
@RequestMapping("/chart")
public class ChartController {
    @Resource
    private OrganizationMapper organizationMapper;
    @Resource
    private HistoryHourlyService historyHourlyService;
    @Resource
    private HistoryDailyService historyDailyService;
    @Resource
    private HistoryMonthlyService historyMonthlyService;
    @RequestMapping(value = "getThermodynamicDiagramDataByCondition", method = RequestMethod.GET)
    @ResponseBody
    public ResultMessage getThermodynamicDiagramDataByCondition(HttpServletRequest request) throws ParseException {
        Map<String, Object> parameters = WebUtils.getParametersStartingWith(request,null);
        Object orgid = parameters.get("organization_id");
        Object sensorCode = parameters.get("sensor_code");
        Object type = parameters.get("type");
        if (ObjectUtils.isEmpty(orgid) || ObjectUtils.isEmpty(sensorCode) || ObjectUtils.isEmpty(type)){
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        Organization organization = organizationMapper.selectById(Integer.parseInt(orgid.toString()));
        if (ObjectUtils.isEmpty(organization)){
            return ResultMessage.fail(ResponseCodeEnum.ORGANIZATION_NOT_EXIST.getCode(), ResponseCodeEnum.ORGANIZATION_NOT_EXIST.getMsg());
        }
        Map<String, Object> resultMap = new HashMap<>();
        List<Map<String,Object>> resultList = new ArrayList<>();
        if (type.equals("hourly")){
            Object time = parameters.get("time");
            if (ObjectUtils.isEmpty(time)){
                return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
            }
            resultMap = historyHourlyService.getThermodynamicDiagramDataByOrgIdSensorCodeTime(parameters);
            return ResultMessage.ok(resultMap);
        }
        if (type.equals("daily")){
            Object time = parameters.get("time");
            if (ObjectUtils.isEmpty(time)){
                return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
            }
            resultMap = historyDailyService.getThermodynamicDiagramDataByOrgIdSensorCodeTime(parameters);
            return ResultMessage.ok(resultMap);
        }
        if (type.equals("monthly")){
            Object time = parameters.get("time");
            if (ObjectUtils.isEmpty(time)){
                return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
            }
            resultMap = historyMonthlyService.getThermodynamicDiagramDataByOrgIdSensorCodeTime(parameters);
            return ResultMessage.ok(resultMap);
        }
        if (type.equals("custom")){
            String startTime = parameters.get("startTime").toString();
            String endTime = parameters.get("endTime").toString();
            if (ObjectUtils.isEmpty(startTime) || ObjectUtils.isEmpty(endTime)){
                return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
            }
            if (startTime.length() == 13){
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//24小时制
                long newTime1 = simpleDateFormat.parse(startTime+":00:00").getTime();
                long newTime2 = simpleDateFormat.parse(endTime+":00:00").getTime();
                Long result = newTime2 - newTime1; //获取两时间相差的毫秒数
                long nd = 1000 * 24 * 60 * 60;
                long nh = 1000 * 60 * 60;
                long nm = 1000 * 60;
                long hour = result / nh; //获取相差的小时数
                if (hour+1>12){
                    return ResultMessage.fail(-1, "时间不能超过12小时");
                }
                if (hour<0){
                    return ResultMessage.fail(ResponseCodeEnum.TIME_FORMAT_INVALID.getCode(), ResponseCodeEnum.TIME_FORMAT_INVALID.getMsg());
                }
                parameters.put("hour",hour);
                resultList = historyHourlyService.getThermodynamicDiagramDataByOrgIdSensorCodeTimeslot(parameters);
                return ResultMessage.ok(resultList);
            }
            if (startTime.length() == 10){
                long days = DateUtils.getQuotByDays(startTime, endTime);
                if (days+1>12){
                    return ResultMessage.fail(-1, "时间不能超过12天");
                }
                parameters.put("days",days);
                resultList = historyDailyService.getThermodynamicDiagramDataByOrgIdSensorCodeTimeSlot(parameters);
                return ResultMessage.ok(resultList);
            }
            if (startTime.length() == 7){
                SimpleDateFormat df = new SimpleDateFormat("yyyy-MM");
                Date satrtTimeDate = df.parse(startTime);
                Date endTimeDate = df.parse(endTime);
                long months = DateUtils.getMonth(satrtTimeDate,endTimeDate); //获取相差的小时数
                if (months+1>12){
                    return ResultMessage.fail(-1, "时间不能超过12月");
                }
                parameters.put("months",months);
                resultList = historyMonthlyService.getThermodynamicDiagramDataByOrgIdSensorCodeTimeSlot(parameters);
                return ResultMessage.ok(resultList);
            }
        }
        return ResultMessage.ok(resultMap);
    }
    @RequestMapping(value = "returnDataTest", method = RequestMethod.GET)
    @ResponseBody
    public ResultMessage returnDataTest(HttpServletRequest request) throws ParseException {
        List bigList = new ArrayList();
        Map<String,Object> resultMap = new HashMap<>();
        List<Double> boundList = new ArrayList<>();
        boundList.add(120.70980239181193);
        boundList.add(31.329143000000002);
        boundList.add(120.74077860818807);
        boundList.add(31.356963);
        resultMap.put("bound",boundList);
        resultMap.put("time","2021-12-10 08:00:00");
        List<Double> centerPointList = new ArrayList<>();
        centerPointList.add(120.72529050000001);
        centerPointList.add(31.343053);
        resultMap.put("centerPoint",centerPointList);
        List<Double> list1 = new ArrayList<>();
        list1.add(120.711611);
        list1.add(31.355163);
        list1.add(1.0);
        List<Double> list2 = new ArrayList<>();
        list2.add(120.726821);
        list2.add(31.342079);
        list2.add(4.0);
        List<Double> list3 = new ArrayList<>();
        list3.add(120.735515);
        list3.add(31.353261);
        list3.add(2.0);
        List list123 = new ArrayList();
        list123.add(list1);
        list123.add(list3);
        list123.add(list2);
        resultMap.put("list",list123);
        for (int i=0;i<10;i++){
            resultMap.put("time","2021-12-10 0"+i+":00:00");
            bigList.add(resultMap);
        }
        return ResultMessage.ok(bigList);
    }
}
screen-api/src/main/java/com/moral/api/mapper/AlarmInfoMapper.java
@@ -19,6 +19,8 @@
    List<Map<String,Object>> selectDataByCondition(Map<String, Object> map);
    List<Map<String,Object>> selectDataByConditionWithoutPage(Map<String, Object> map);
    List<Map<String,Object>> selectNewestData(Map<String, Object> map);
}
screen-api/src/main/java/com/moral/api/service/AlarmInfoService.java
@@ -26,6 +26,15 @@
    Map<String,Object> getDataByCondition(Map<String, Object> parameters);
    
    /**
      *@Description: 通过条件查询报警信息,不分页
      *@Param: [parameters]
      *@return: java.util.Map<java.lang.String,java.lang.Object>
      *@Author: lizijie
      *@Date: 2021/12/24 13:24
     **/
    Map<String,Object> getDataByConditionWithoutPage(Map<String, Object> parameters);
    /**
      *@Description: 污染报警提醒
      *@Param: [parameters]
      *@return: java.util.List<java.util.Map<java.lang.String,java.lang.Object>> 
screen-api/src/main/java/com/moral/api/service/HistoryDailyService.java
@@ -47,4 +47,22 @@
            */
    List<HistoryDaily> getHistoryDailyByMacAndTimeSlot( String mac, Date startDate,Date endDate);
    /**
     *@Description: 通过组织id、因子编码和时间获取日数据
     *@Param: [map]
     *@return: java.util.Map<java.lang.String,java.lang.Object>
     *@Author: lizijie
     *@Date: 2021/12/15 15:16
     **/
    Map<String, Object> getThermodynamicDiagramDataByOrgIdSensorCodeTime(Map<String, Object> map);
    /**
     *@Description: 通过组织id、因子编码和时间段获取日数据
     *@Param: [map]
     *@return: java.util.Map<java.lang.String,java.lang.Object>
     *@Author: lizijie
     *@Date: 2021/12/16 15:16
     **/
    List<Map<String, Object>> getThermodynamicDiagramDataByOrgIdSensorCodeTimeSlot(Map<String, Object> map);
}
screen-api/src/main/java/com/moral/api/service/HistoryHourlyService.java
@@ -36,6 +36,24 @@
      *@Date: 2021/12/10 14:57
     **/
    Map<String, Object> getLastTwelveHourDataByOrgIdAndSensorCode(Map map);
    /**
      *@Description: 通过组织id、因子编码和时间获取小时数据
      *@Param: [map]
      *@return: java.util.Map<java.lang.String,java.lang.Object>
      *@Author: lizijie
      *@Date: 2021/12/15 15:16
     **/
    Map<String, Object> getThermodynamicDiagramDataByOrgIdSensorCodeTime(Map<String, Object> map);
    /**
     *@Description: 通过组织id、因子编码和时间段获取小时数据
     *@Param: [map]
     *@return: java.util.Map<java.lang.String,java.lang.Object>
     *@Author: lizijie
     *@Date: 2021/12/16 15:16
     **/
    List<Map<String, Object>> getThermodynamicDiagramDataByOrgIdSensorCodeTimeslot(Map<String, Object> map);
    /**
    * @Description: 根据mac和时间获取小时值
screen-api/src/main/java/com/moral/api/service/HistoryMonthlyService.java
@@ -34,4 +34,22 @@
            * @Date: 2021/9/30
            */
    Map<String,HistoryMonthly> getHistoryMonthlyByMacsAndDate(List<String> mac, Date date);
    /**
     *@Description: 通过组织id、因子编码和时间获取月数据
     *@Param: [map]
     *@return: java.util.Map<java.lang.String,java.lang.Object>
     *@Author: lizijie
     *@Date: 2021/12/15 15:16
     **/
    Map<String, Object> getThermodynamicDiagramDataByOrgIdSensorCodeTime(Map<String, Object> map);
    /**
     *@Description: 通过组织id、因子编码和时间段获取月数据
     *@Param: [map]
     *@return: java.util.Map<java.lang.String,java.lang.Object>
     *@Author: lizijie
     *@Date: 2021/12/16 15:16
     **/
    List<Map<String, Object>> getThermodynamicDiagramDataByOrgIdSensorCodeTimeSlot(Map<String, Object> map);
}
screen-api/src/main/java/com/moral/api/service/impl/AlarmInfoServiceImpl.java
@@ -143,6 +143,93 @@
    }
    @Override
    public Map<String, Object> getDataByConditionWithoutPage(Map<String, Object> parameters) {
        Map<String, Object> resultMap = new HashMap<>();
        int orgId = Integer.parseInt(parameters.get("organization_id").toString());
        //定义一个集合,存放所有id
        List<Integer> allOrgId = new ArrayList<>();
        allOrgId.add(orgId);
        //循环集合
        //所有子组织
        List<Organization> allChildrenOrganization = organizationService.getChildrenOrganizationsById(orgId);
        if (!ObjectUtils.isEmpty(allChildrenOrganization) || allChildrenOrganization.size() < 1){
            for (Organization organization:allChildrenOrganization) {
                allOrgId.add(organization.getId());
            }
        }
        //集合去重
        List<Integer> allOrgIdWithoutDuplicates = allOrgId.stream().distinct().collect(Collectors.toList());
        //声明一个list,存放设备id
        List<Integer> deviceIdList = new ArrayList<>();
        for (Integer orgIdWithoutDuplicates:allOrgIdWithoutDuplicates) {
            //根据id查询所属设备
            QueryWrapper<Device> wrapper_device = new QueryWrapper<>();
            wrapper_device.eq("is_delete",Constants.NOT_DELETE).eq("organization_id",orgIdWithoutDuplicates);
            List<Device> devices = new ArrayList<>();
            devices = deviceMapper.selectList(wrapper_device);
            if (devices.size()>0){
                for (Device device:devices) {
                    int deviceId = device.getId();
                    deviceIdList.add(deviceId);
                }
            }else {
                continue;
            }
        }
        if (deviceIdList.size()>0){
            Map<String, Object> map = new HashMap<>();
            QueryWrapper<AlarmInfo> alarmInfoQueryWrapper = new QueryWrapper<>();
            map.put("deviceIds",deviceIdList);
            alarmInfoQueryWrapper.in("device_id",deviceIdList);
            String startTime = parameters.get("startTime")+" 00:00:00";
            String endTime = parameters.get("endTime")+" 23:59:59";
            map.put("startTime",startTime);
            map.put("endTime",endTime);
            alarmInfoQueryWrapper.between("alarm_time", startTime, endTime);
            String index = parameters.get("index").toString();
            if (!index.equals("all")){
                map.put("index",index);
                alarmInfoQueryWrapper.eq("`index`", index);
            }
            String alarmType = parameters.get("alarmType").toString();
            switch (alarmType){
                case "overrun" : map.put("alarmType","超限");
                    alarmInfoQueryWrapper.eq("alarm_type","超限");
                    break;
                case "sudden" : map.put("alarmType","突然高");
                    alarmInfoQueryWrapper.eq("alarm_type","突然高");
                    break;
                case "state100" : map.put("alarmType","超过国控站点100%");
                    alarmInfoQueryWrapper.eq("alarm_type","超过国控站点100%");
                    break;
                case "state150" : map.put("alarmType","超过国控站点150%");
                    alarmInfoQueryWrapper.eq("alarm_type","超过国控站点150%");
                    break;
                case "state250" : map.put("alarmType","超过国控站点250%");
                    alarmInfoQueryWrapper.eq("alarm_type","超过国控站点250%");
                    break;
                case "city150" : map.put("alarmType","超过市区均值150%");
                    alarmInfoQueryWrapper.eq("alarm_type","超过市区均值150%");
                    break;
                case "city250" : map.put("alarmType","超过市区均值250%");
                    alarmInfoQueryWrapper.eq("alarm_type","超过市区均值250%");
                    break;
                default:break;
            }
            List<Map<String, Object>> resultList = alarmInfoMapper.selectDataByConditionWithoutPage(map);
            SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            for (Map<String, Object> alarmInfo:resultList) {
                String alarm_time = SDF.format(alarmInfo.get("alarm_time"));
                alarmInfo.put("alarm_time",alarm_time);
            }
            Integer totalNumber = alarmInfoMapper.selectCount(alarmInfoQueryWrapper);
            resultMap.put("alarmInfos", resultList);
            return resultMap;
        }
        return null;
    }
    @Override
    public Map<String, Object> alarmReminder(Map<String, Object> parameters) {
        Map<String,Object> resultMap = new HashMap<>();
        int orgId = Integer.parseInt(parameters.get("organization_id").toString());
screen-api/src/main/java/com/moral/api/service/impl/HistoryDailyServiceImpl.java
@@ -1,21 +1,29 @@
package com.moral.api.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.moral.api.entity.Device;
import com.moral.api.entity.GeoCoordinate;
import com.moral.api.entity.HistoryDaily;
import com.moral.api.entity.Organization;
import com.moral.api.mapper.DeviceMapper;
import com.moral.api.mapper.HistoryDailyMapper;
import com.moral.api.service.HistoryDailyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.moral.api.service.OrganizationService;
import com.moral.api.utils.GetCenterPointFromListOfCoordinates;
import com.moral.constant.Constants;
import com.moral.util.DateUtils;
import com.moral.util.PollutantUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
/**
 * <p>
@@ -30,6 +38,12 @@
    @Autowired
    private HistoryDailyMapper historyDailyMapper;
    @Autowired
    private DeviceMapper deviceMapper;
    @Autowired
    private OrganizationService organizationService;
    @Override
    public Map<String, Object> getMonthAvg(Map<String, Object> params) {
@@ -79,5 +93,240 @@
        return historyDailies;
    }
    @Override
    public Map<String, Object> getThermodynamicDiagramDataByOrgIdSensorCodeTime(Map<String, Object> parameters) {
        Map<String, Object> resultMap = new HashMap<>();
        int orgId = Integer.parseInt(parameters.get("organization_id").toString());
        //定义一个集合,存放所有id
        List<Integer> allOrgId = new ArrayList<>();
        allOrgId.add(orgId);
        //循环集合
        //所有子组织
        List<Organization> allChildrenOrganization = organizationService.getChildrenOrganizationsById(orgId);
        if (!ObjectUtils.isEmpty(allChildrenOrganization) || allChildrenOrganization.size() < 1){
            for (Organization organization:allChildrenOrganization) {
                allOrgId.add(organization.getId());
            }
        }
        //集合去重
        List<Integer> allOrgIdWithoutDuplicates = allOrgId.stream().distinct().collect(Collectors.toList());
        //声明一个list,存放设备mac
        List<String> deviceMacList = new ArrayList<>();
        //声明一个map,Mac作为key,device作为value
        Map<String,Device> deviceMap = new HashMap<>();
        List<Double> longitudeList = new ArrayList<>();
        List<Double> latitudeList = new ArrayList<>();
        for (Integer orgIdWithoutDuplicates:allOrgIdWithoutDuplicates) {
            //根据id查询所属设备
            QueryWrapper<Device> wrapper_device = new QueryWrapper<>();
            wrapper_device.eq("is_delete",Constants.NOT_DELETE).eq("organization_id",orgIdWithoutDuplicates);
            List<Device> devices = new ArrayList<>();
            devices = deviceMapper.selectList(wrapper_device);
            if (devices.size()>0){
                for (Device device:devices) {
                    String mac = device.getMac();
                    deviceMacList.add(mac);
                    deviceMap.put(mac,device);
                    double longitude = device.getLongitude();
                    double latitude = device.getLatitude();
                    longitudeList.add(longitude);
                    latitudeList.add(latitude);
                }
            }else {
                continue;
            }
        }
        //获取时间
        String time = parameters.get("time").toString().substring(0,10)+" 00:00:00";
        resultMap.put("time",time);
        QueryWrapper<HistoryDaily> historyDailyQueryWrapper = new QueryWrapper<>();
        historyDailyQueryWrapper.eq("time",time);
        historyDailyQueryWrapper.in("mac", deviceMacList);
        List<HistoryDaily> historyDailies = historyDailyMapper.selectList(historyDailyQueryWrapper);
        List<Object> list = new ArrayList<>();
        for (HistoryDaily historyDailyData:historyDailies) {
            List<Object> list1 = new ArrayList<>();
            String mac = historyDailyData.getMac();
            Device device = deviceMap.get(mac);
            double longitude = device.getLongitude();
            double latitude = device.getLatitude();
            JSONObject value = JSONObject.parseObject(historyDailyData.getValue());
            double num = Double.parseDouble(value.get(parameters.get("sensor_code")).toString());
            int level = PollutantUtils.pollutantLevel(num, (parameters.get("sensor_code")).toString());
            list1.add(longitude);
            list1.add(latitude);
            list1.add(level);
            list.add(list1);
        }
        resultMap.put("list",list);
        double latitudeMin = Collections.min(latitudeList)-0.0018;
        double latitudeMax = Collections.max(latitudeList)+0.0018;
        double longitudeMin = Collections.min(longitudeList)-0.2/(111*Math.cos(latitudeMin));
        double longitudeMax = Collections.max(longitudeList)+0.2/(111*Math.cos(latitudeMin));
        List<Double> bound = new ArrayList<>();
        bound.add(longitudeMin);
        bound.add(latitudeMin);
        bound.add(longitudeMax);
        bound.add(latitudeMax);
        resultMap.put("bound",bound);
        List<List> bound1 = new ArrayList<>();
        List<Double> left_up = new ArrayList<>();
        left_up.add(latitudeMax);
        left_up.add(longitudeMin);
        List<Double> right_up = new ArrayList<>();
        right_up.add(latitudeMax);
        right_up.add(longitudeMax);
        List<Double> left_down = new ArrayList<>();
        left_down.add(latitudeMin);
        left_down.add(longitudeMin);
        List<Double> right_down = new ArrayList<>();
        right_down.add(latitudeMin);
        right_down.add(longitudeMax);
        bound1.add(left_up);
        bound1.add(right_up);
        bound1.add(right_down);
        bound1.add(left_down);
        List<GeoCoordinate> geoCoordinates = new ArrayList<>();
        for (List bo:bound1) {
            GeoCoordinate g = new GeoCoordinate();
            g.setLatitude(Double.parseDouble(bo.get(0).toString()));
            g.setLongitude(Double.parseDouble(bo.get(1).toString()));
            geoCoordinates.add(g);
        }
        GeoCoordinate centerPoint400 = GetCenterPointFromListOfCoordinates.getCenterPoint400(geoCoordinates);
        List centerPoint = new ArrayList();
        centerPoint.add(centerPoint400.getLongitude());
        centerPoint.add(centerPoint400.getLatitude());
        resultMap.put("centerPoint",centerPoint);
        return resultMap;
    }
    @Override
    public List<Map<String, Object>> getThermodynamicDiagramDataByOrgIdSensorCodeTimeSlot(Map<String, Object> parameters) {
        int orgId = Integer.parseInt(parameters.get("organization_id").toString());
        //定义一个集合,存放所有id
        List<Integer> allOrgId = new ArrayList<>();
        allOrgId.add(orgId);
        //循环集合
        //所有子组织
        List<Organization> allChildrenOrganization = organizationService.getChildrenOrganizationsById(orgId);
        if (!ObjectUtils.isEmpty(allChildrenOrganization) || allChildrenOrganization.size() < 1){
            for (Organization organization:allChildrenOrganization) {
                allOrgId.add(organization.getId());
            }
        }
        //集合去重
        List<Integer> allOrgIdWithoutDuplicates = allOrgId.stream().distinct().collect(Collectors.toList());
        //声明一个list,存放设备mac
        List<String> deviceMacList = new ArrayList<>();
        //声明一个map,Mac作为key,device作为value
        Map<String,Device> deviceMap = new HashMap<>();
        List<Double> longitudeList = new ArrayList<>();
        List<Double> latitudeList = new ArrayList<>();
        for (Integer orgIdWithoutDuplicates:allOrgIdWithoutDuplicates) {
            //根据id查询所属设备
            QueryWrapper<Device> wrapper_device = new QueryWrapper<>();
            wrapper_device.eq("is_delete",Constants.NOT_DELETE).eq("organization_id",orgIdWithoutDuplicates);
            List<Device> devices = new ArrayList<>();
            devices = deviceMapper.selectList(wrapper_device);
            if (devices.size()>0){
                for (Device device:devices) {
                    String mac = device.getMac();
                    deviceMacList.add(mac);
                    deviceMap.put(mac,device);
                    double longitude = device.getLongitude();
                    double latitude = device.getLatitude();
                    longitudeList.add(longitude);
                    latitudeList.add(latitude);
                }
            }else {
                continue;
            }
        }
        double latitudeMin = Collections.min(latitudeList)-0.0018;
        double latitudeMax = Collections.max(latitudeList)+0.0018;
        double longitudeMin = Collections.min(longitudeList)-0.2/(111*Math.cos(latitudeMin));
        double longitudeMax = Collections.max(longitudeList)+0.2/(111*Math.cos(latitudeMin));
        List<Double> bound = new ArrayList<>();
        bound.add(longitudeMin);
        bound.add(latitudeMin);
        bound.add(longitudeMax);
        bound.add(latitudeMax);
        List<List> bound1 = new ArrayList<>();
        List<Double> left_up = new ArrayList<>();
        left_up.add(latitudeMax);
        left_up.add(longitudeMin);
        List<Double> right_up = new ArrayList<>();
        right_up.add(latitudeMax);
        right_up.add(longitudeMax);
        List<Double> left_down = new ArrayList<>();
        left_down.add(latitudeMin);
        left_down.add(longitudeMin);
        List<Double> right_down = new ArrayList<>();
        right_down.add(latitudeMin);
        right_down.add(longitudeMax);
        bound1.add(left_up);
        bound1.add(right_up);
        bound1.add(right_down);
        bound1.add(left_down);
        List<GeoCoordinate> geoCoordinates = new ArrayList<>();
        for (List bo:bound1) {
            GeoCoordinate g = new GeoCoordinate();
            g.setLatitude(Double.parseDouble(bo.get(0).toString()));
            g.setLongitude(Double.parseDouble(bo.get(1).toString()));
            geoCoordinates.add(g);
        }
        GeoCoordinate centerPoint400 = GetCenterPointFromListOfCoordinates.getCenterPoint400(geoCoordinates);
        List centerPoint = new ArrayList();
        centerPoint.add(centerPoint400.getLongitude());
        centerPoint.add(centerPoint400.getLatitude());
        List<Map<String, Object>> resultList = new ArrayList<>();
        //获取时间
        String endTime = parameters.get("endTime").toString().substring(0,10)+" 00:00:00";
        //获取时间
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        int days = Integer.parseInt(parameters.get("days").toString());
        Date newEndTime = new Date();
        for (int i=days;i>=0;i--){
            Map<String, Object> resultMap = new HashMap<>();
            //先存放中心点和边界点
            resultMap.put("centerPoint",centerPoint);
            resultMap.put("bound",bound);
            Calendar calendar = Calendar.getInstance();
            try {
                newEndTime = df.parse(endTime);
            } catch (ParseException e) {
                e.printStackTrace();
            }
            calendar.setTime(newEndTime);
            calendar.set(Calendar.DAY_OF_MONTH,calendar.get(Calendar.DAY_OF_MONTH)-i);
            String time = df.format(calendar.getTime())+" 00:00:00";
            //存放时间
            resultMap.put("time",time);
            QueryWrapper<HistoryDaily> historyDailyQueryWrapper = new QueryWrapper<>();
            historyDailyQueryWrapper.eq("time",time);
            historyDailyQueryWrapper.in("mac", deviceMacList);
            List<HistoryDaily> historyDailies = historyDailyMapper.selectList(historyDailyQueryWrapper);
            List<Object> list = new ArrayList<>();
            for (HistoryDaily historyDailyData:historyDailies) {
                List<Object> list1 = new ArrayList<>();
                String mac = historyDailyData.getMac();
                Device device = deviceMap.get(mac);
                double longitude = device.getLongitude();
                double latitude = device.getLatitude();
                JSONObject value = JSONObject.parseObject(historyDailyData.getValue());
                double num = Double.parseDouble(value.get(parameters.get("sensor_code")).toString());
                int level = PollutantUtils.pollutantLevel(num, (parameters.get("sensor_code")).toString());
                list1.add(longitude);
                list1.add(latitude);
                list1.add(level);
                list.add(list1);
            }
            resultMap.put("list",list);
            resultList.add(resultMap);
        }
        return resultList;
    }
}
screen-api/src/main/java/com/moral/api/service/impl/HistoryHourlyServiceImpl.java
@@ -21,6 +21,7 @@
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
@@ -294,6 +295,238 @@
        return resultMap;
    }
    @Override
    public Map<String, Object> getThermodynamicDiagramDataByOrgIdSensorCodeTime(Map<String, Object> parameters) {
        Map<String, Object> resultMap = new HashMap<>();
        int orgId = Integer.parseInt(parameters.get("organization_id").toString());
        //定义一个集合,存放所有id
        List<Integer> allOrgId = new ArrayList<>();
        allOrgId.add(orgId);
        //循环集合
        //所有子组织
        List<Organization> allChildrenOrganization = organizationService.getChildrenOrganizationsById(orgId);
        if (!ObjectUtils.isEmpty(allChildrenOrganization) || allChildrenOrganization.size() < 1){
            for (Organization organization:allChildrenOrganization) {
                allOrgId.add(organization.getId());
            }
        }
        //集合去重
        List<Integer> allOrgIdWithoutDuplicates = allOrgId.stream().distinct().collect(Collectors.toList());
        //声明一个list,存放设备mac
        List<String> deviceMacList = new ArrayList<>();
        //声明一个map,Mac作为key,device作为value
        Map<String,Device> deviceMap = new HashMap<>();
        List<Double> longitudeList = new ArrayList<>();
        List<Double> latitudeList = new ArrayList<>();
        for (Integer orgIdWithoutDuplicates:allOrgIdWithoutDuplicates) {
            //根据id查询所属设备
            QueryWrapper<Device> wrapper_device = new QueryWrapper<>();
            wrapper_device.eq("is_delete",Constants.NOT_DELETE).eq("organization_id",orgIdWithoutDuplicates);
            List<Device> devices = new ArrayList<>();
            devices = deviceMapper.selectList(wrapper_device);
            if (devices.size()>0){
                for (Device device:devices) {
                    String mac = device.getMac();
                    deviceMacList.add(mac);
                    deviceMap.put(mac,device);
                    double longitude = device.getLongitude();
                    double latitude = device.getLatitude();
                    longitudeList.add(longitude);
                    latitudeList.add(latitude);
                }
            }else {
                continue;
            }
        }
        //获取时间
        String time = parameters.get("time").toString().substring(0,13)+":00:00";
        resultMap.put("time",time);
        String timeUnits =  DateUtils.stringToDateString(time, DateUtils.yyyy_MM_dd_HH_mm_ss_EN, DateUtils.yyyyMM_EN);
        List<Map<String,Object>> historyHourlyDatas = new ArrayList<>();
        historyHourlyDatas = historyHourlyMapper.selectDataByMacsAndTime(timeUnits, deviceMacList, time);
        List<Object> list = new ArrayList<>();
        for (Map historyHourlyData:historyHourlyDatas) {
            List<Object> list1 = new ArrayList<>();
            String mac = historyHourlyData.get("mac").toString();
            Device device = deviceMap.get(mac);
            double longitude = device.getLongitude();
            double latitude = device.getLatitude();
            JSONObject value = JSONObject.parseObject(historyHourlyData.get("value").toString());
            double num = Double.parseDouble(value.get(parameters.get("sensor_code")).toString());
            int level = PollutantUtils.pollutantLevel(num, (parameters.get("sensor_code")).toString());
            list1.add(longitude);
            list1.add(latitude);
            list1.add(level);
            list.add(list1);
        }
        resultMap.put("list",list);
        double latitudeMin = Collections.min(latitudeList)-0.0018;
        double latitudeMax = Collections.max(latitudeList)+0.0018;
        double longitudeMin = Collections.min(longitudeList)-0.2/(111*Math.cos(latitudeMin));
        double longitudeMax = Collections.max(longitudeList)+0.2/(111*Math.cos(latitudeMin));
        List<Double> bound = new ArrayList<>();
        bound.add(longitudeMin);
        bound.add(latitudeMin);
        bound.add(longitudeMax);
        bound.add(latitudeMax);
        resultMap.put("bound",bound);
        List<List> bound1 = new ArrayList<>();
        List<Double> left_up = new ArrayList<>();
        left_up.add(latitudeMax);
        left_up.add(longitudeMin);
        List<Double> right_up = new ArrayList<>();
        right_up.add(latitudeMax);
        right_up.add(longitudeMax);
        List<Double> left_down = new ArrayList<>();
        left_down.add(latitudeMin);
        left_down.add(longitudeMin);
        List<Double> right_down = new ArrayList<>();
        right_down.add(latitudeMin);
        right_down.add(longitudeMax);
        bound1.add(left_up);
        bound1.add(right_up);
        bound1.add(right_down);
        bound1.add(left_down);
        List<GeoCoordinate> geoCoordinates = new ArrayList<>();
        for (List bo:bound1) {
            GeoCoordinate g = new GeoCoordinate();
            g.setLatitude(Double.parseDouble(bo.get(0).toString()));
            g.setLongitude(Double.parseDouble(bo.get(1).toString()));
            geoCoordinates.add(g);
        }
        GeoCoordinate centerPoint400 = GetCenterPointFromListOfCoordinates.getCenterPoint400(geoCoordinates);
        List centerPoint = new ArrayList();
        centerPoint.add(centerPoint400.getLongitude());
        centerPoint.add(centerPoint400.getLatitude());
        resultMap.put("centerPoint",centerPoint);
        return resultMap;
    }
    @Override
    public List<Map<String, Object>> getThermodynamicDiagramDataByOrgIdSensorCodeTimeslot(Map<String, Object> parameters) {
        int orgId = Integer.parseInt(parameters.get("organization_id").toString());
        //定义一个集合,存放所有id
        List<Integer> allOrgId = new ArrayList<>();
        allOrgId.add(orgId);
        //循环集合
        //所有子组织
        List<Organization> allChildrenOrganization = organizationService.getChildrenOrganizationsById(orgId);
        if (!ObjectUtils.isEmpty(allChildrenOrganization) || allChildrenOrganization.size() < 1){
            for (Organization organization:allChildrenOrganization) {
                allOrgId.add(organization.getId());
            }
        }
        //集合去重
        List<Integer> allOrgIdWithoutDuplicates = allOrgId.stream().distinct().collect(Collectors.toList());
        //声明一个list,存放设备mac
        List<String> deviceMacList = new ArrayList<>();
        //声明一个map,Mac作为key,device作为value
        Map<String,Device> deviceMap = new HashMap<>();
        List<Double> longitudeList = new ArrayList<>();
        List<Double> latitudeList = new ArrayList<>();
        for (Integer orgIdWithoutDuplicates:allOrgIdWithoutDuplicates) {
            //根据id查询所属设备
            QueryWrapper<Device> wrapper_device = new QueryWrapper<>();
            wrapper_device.eq("is_delete",Constants.NOT_DELETE).eq("organization_id",orgIdWithoutDuplicates);
            List<Device> devices = new ArrayList<>();
            devices = deviceMapper.selectList(wrapper_device);
            if (devices.size()>0){
                for (Device device:devices) {
                    String mac = device.getMac();
                    deviceMacList.add(mac);
                    deviceMap.put(mac,device);
                    double longitude = device.getLongitude();
                    double latitude = device.getLatitude();
                    longitudeList.add(longitude);
                    latitudeList.add(latitude);
                }
            }else {
                continue;
            }
        }
        double latitudeMin = Collections.min(latitudeList)-0.0018;
        double latitudeMax = Collections.max(latitudeList)+0.0018;
        double longitudeMin = Collections.min(longitudeList)-0.2/(111*Math.cos(latitudeMin));
        double longitudeMax = Collections.max(longitudeList)+0.2/(111*Math.cos(latitudeMin));
        List<Double> bound = new ArrayList<>();
        bound.add(longitudeMin);
        bound.add(latitudeMin);
        bound.add(longitudeMax);
        bound.add(latitudeMax);
        List<List> bound1 = new ArrayList<>();
        List<Double> left_up = new ArrayList<>();
        left_up.add(latitudeMax);
        left_up.add(longitudeMin);
        List<Double> right_up = new ArrayList<>();
        right_up.add(latitudeMax);
        right_up.add(longitudeMax);
        List<Double> left_down = new ArrayList<>();
        left_down.add(latitudeMin);
        left_down.add(longitudeMin);
        List<Double> right_down = new ArrayList<>();
        right_down.add(latitudeMin);
        right_down.add(longitudeMax);
        bound1.add(left_up);
        bound1.add(right_up);
        bound1.add(right_down);
        bound1.add(left_down);
        List<GeoCoordinate> geoCoordinates = new ArrayList<>();
        for (List bo:bound1) {
            GeoCoordinate g = new GeoCoordinate();
            g.setLatitude(Double.parseDouble(bo.get(0).toString()));
            g.setLongitude(Double.parseDouble(bo.get(1).toString()));
            geoCoordinates.add(g);
        }
        GeoCoordinate centerPoint400 = GetCenterPointFromListOfCoordinates.getCenterPoint400(geoCoordinates);
        List centerPoint = new ArrayList();
        centerPoint.add(centerPoint400.getLongitude());
        centerPoint.add(centerPoint400.getLatitude());
        List<Map<String, Object>> list = new ArrayList<>();
        //获取时间
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH");
        String endTime = parameters.get("endTime").toString();
        int hour = Integer.parseInt(parameters.get("hour").toString());
        Date newEndTime = new Date();
        for (int i=hour;i>=0;i--){
            Map<String, Object> resultMap = new HashMap<>();
            //先存放中心点和边界点
            resultMap.put("centerPoint",centerPoint);
            resultMap.put("bound",bound);
            Calendar calendar = Calendar.getInstance();
            try {
                newEndTime = df.parse(endTime);
            } catch (ParseException e) {
                e.printStackTrace();
            }
            calendar.setTime(newEndTime);
            calendar.set(Calendar.HOUR_OF_DAY,calendar.get(Calendar.HOUR_OF_DAY)-i);
            String time = df.format(calendar.getTime())+":00:00";
            //存放时间
            resultMap.put("time",time);
            String timeUnits =  DateUtils.dateToDateString(calendar.getTime(), DateUtils.yyyyMM_EN);
            List<Map<String,Object>> historyHourlyDatas = new ArrayList<>();
            historyHourlyDatas = historyHourlyMapper.selectDataByMacsAndTime(timeUnits, deviceMacList, time);
            List<Object> oneHourlyList = new ArrayList<>();
            for (Map historyHourlyData:historyHourlyDatas) {
                List<Object> list1 = new ArrayList<>();
                String mac = historyHourlyData.get("mac").toString();
                Device device = deviceMap.get(mac);
                double longitude = device.getLongitude();
                double latitude = device.getLatitude();
                JSONObject value = JSONObject.parseObject(historyHourlyData.get("value").toString());
                double num = Double.parseDouble(value.get(parameters.get("sensor_code")).toString());
                int level = PollutantUtils.pollutantLevel(num, (parameters.get("sensor_code")).toString());
                list1.add(longitude);
                list1.add(latitude);
                list1.add(level);
                oneHourlyList.add(list1);
            }
            resultMap.put("list",oneHourlyList);
            list.add(resultMap);
        }
        return list;
    }
    /**
    * @Description: 查询一段时间内某一mac的数据
            * @Param: [mac, startDate, endDate]
screen-api/src/main/java/com/moral/api/service/impl/HistoryMonthlyServiceImpl.java
@@ -1,18 +1,24 @@
package com.moral.api.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.moral.api.entity.HistoryMonthly;
import com.moral.api.entity.*;
import com.moral.api.mapper.DeviceMapper;
import com.moral.api.mapper.HistoryMonthlyMapper;
import com.moral.api.service.HistoryMonthlyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.moral.api.service.OrganizationService;
import com.moral.api.utils.GetCenterPointFromListOfCoordinates;
import com.moral.constant.Constants;
import com.moral.util.PollutantUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
/**
 * <p>
@@ -27,6 +33,12 @@
    @Autowired
    HistoryMonthlyMapper historyMonthlyMapper;
    @Autowired
    DeviceMapper deviceMapper;
    @Autowired
    private OrganizationService organizationService;
    @Override
    public HistoryMonthly getHistoryMonthlyByMacAndDate(String mac, Date date) {
@@ -51,4 +63,239 @@
        }
        return map;
    }
    @Override
    public Map<String, Object> getThermodynamicDiagramDataByOrgIdSensorCodeTime(Map<String, Object> parameters) {
        Map<String, Object> resultMap = new HashMap<>();
        int orgId = Integer.parseInt(parameters.get("organization_id").toString());
        //定义一个集合,存放所有id
        List<Integer> allOrgId = new ArrayList<>();
        allOrgId.add(orgId);
        //循环集合
        //所有子组织
        List<Organization> allChildrenOrganization = organizationService.getChildrenOrganizationsById(orgId);
        if (!ObjectUtils.isEmpty(allChildrenOrganization) || allChildrenOrganization.size() < 1){
            for (Organization organization:allChildrenOrganization) {
                allOrgId.add(organization.getId());
            }
        }
        //集合去重
        List<Integer> allOrgIdWithoutDuplicates = allOrgId.stream().distinct().collect(Collectors.toList());
        //声明一个list,存放设备mac
        List<String> deviceMacList = new ArrayList<>();
        //声明一个map,Mac作为key,device作为value
        Map<String,Device> deviceMap = new HashMap<>();
        List<Double> longitudeList = new ArrayList<>();
        List<Double> latitudeList = new ArrayList<>();
        for (Integer orgIdWithoutDuplicates:allOrgIdWithoutDuplicates) {
            //根据id查询所属设备
            QueryWrapper<Device> wrapper_device = new QueryWrapper<>();
            wrapper_device.eq("is_delete",Constants.NOT_DELETE).eq("organization_id",orgIdWithoutDuplicates);
            List<Device> devices = new ArrayList<>();
            devices = deviceMapper.selectList(wrapper_device);
            if (devices.size()>0){
                for (Device device:devices) {
                    String mac = device.getMac();
                    deviceMacList.add(mac);
                    deviceMap.put(mac,device);
                    double longitude = device.getLongitude();
                    double latitude = device.getLatitude();
                    longitudeList.add(longitude);
                    latitudeList.add(latitude);
                }
            }else {
                continue;
            }
        }
        //获取时间
        String time = parameters.get("time").toString().substring(0,7)+"-01 00:00:00";
        resultMap.put("time",time);
        QueryWrapper<HistoryMonthly> historyMonthlyQueryWrapper = new QueryWrapper<>();
        historyMonthlyQueryWrapper.eq("time",time);
        historyMonthlyQueryWrapper.in("mac", deviceMacList);
        List<HistoryMonthly> historyDailies = historyMonthlyMapper.selectList(historyMonthlyQueryWrapper);
        List<Object> list = new ArrayList<>();
        for (HistoryMonthly historyDailyData:historyDailies) {
            List<Object> list1 = new ArrayList<>();
            String mac = historyDailyData.getMac();
            Device device = deviceMap.get(mac);
            double longitude = device.getLongitude();
            double latitude = device.getLatitude();
            JSONObject value = JSONObject.parseObject(historyDailyData.getValue());
            double num = Double.parseDouble(value.get(parameters.get("sensor_code")).toString());
            int level = PollutantUtils.pollutantLevel(num, (parameters.get("sensor_code")).toString());
            list1.add(longitude);
            list1.add(latitude);
            list1.add(level);
            list.add(list1);
        }
        resultMap.put("list",list);
        double latitudeMin = Collections.min(latitudeList)-0.0018;
        double latitudeMax = Collections.max(latitudeList)+0.0018;
        double longitudeMin = Collections.min(longitudeList)-0.2/(111*Math.cos(latitudeMin));
        double longitudeMax = Collections.max(longitudeList)+0.2/(111*Math.cos(latitudeMin));
        List<Double> bound = new ArrayList<>();
        bound.add(longitudeMin);
        bound.add(latitudeMin);
        bound.add(longitudeMax);
        bound.add(latitudeMax);
        resultMap.put("bound",bound);
        List<List> bound1 = new ArrayList<>();
        List<Double> left_up = new ArrayList<>();
        left_up.add(latitudeMax);
        left_up.add(longitudeMin);
        List<Double> right_up = new ArrayList<>();
        right_up.add(latitudeMax);
        right_up.add(longitudeMax);
        List<Double> left_down = new ArrayList<>();
        left_down.add(latitudeMin);
        left_down.add(longitudeMin);
        List<Double> right_down = new ArrayList<>();
        right_down.add(latitudeMin);
        right_down.add(longitudeMax);
        bound1.add(left_up);
        bound1.add(right_up);
        bound1.add(right_down);
        bound1.add(left_down);
        List<GeoCoordinate> geoCoordinates = new ArrayList<>();
        for (List bo:bound1) {
            GeoCoordinate g = new GeoCoordinate();
            g.setLatitude(Double.parseDouble(bo.get(0).toString()));
            g.setLongitude(Double.parseDouble(bo.get(1).toString()));
            geoCoordinates.add(g);
        }
        GeoCoordinate centerPoint400 = GetCenterPointFromListOfCoordinates.getCenterPoint400(geoCoordinates);
        List centerPoint = new ArrayList();
        centerPoint.add(centerPoint400.getLongitude());
        centerPoint.add(centerPoint400.getLatitude());
        resultMap.put("centerPoint",centerPoint);
        return resultMap;
    }
    @Override
    public List<Map<String, Object>> getThermodynamicDiagramDataByOrgIdSensorCodeTimeSlot(Map<String, Object> parameters) {
        int orgId = Integer.parseInt(parameters.get("organization_id").toString());
        //定义一个集合,存放所有id
        List<Integer> allOrgId = new ArrayList<>();
        allOrgId.add(orgId);
        //循环集合
        //所有子组织
        List<Organization> allChildrenOrganization = organizationService.getChildrenOrganizationsById(orgId);
        if (!ObjectUtils.isEmpty(allChildrenOrganization) || allChildrenOrganization.size() < 1){
            for (Organization organization:allChildrenOrganization) {
                allOrgId.add(organization.getId());
            }
        }
        //集合去重
        List<Integer> allOrgIdWithoutDuplicates = allOrgId.stream().distinct().collect(Collectors.toList());
        //声明一个list,存放设备mac
        List<String> deviceMacList = new ArrayList<>();
        //声明一个map,Mac作为key,device作为value
        Map<String,Device> deviceMap = new HashMap<>();
        List<Double> longitudeList = new ArrayList<>();
        List<Double> latitudeList = new ArrayList<>();
        for (Integer orgIdWithoutDuplicates:allOrgIdWithoutDuplicates) {
            //根据id查询所属设备
            QueryWrapper<Device> wrapper_device = new QueryWrapper<>();
            wrapper_device.eq("is_delete",Constants.NOT_DELETE).eq("organization_id",orgIdWithoutDuplicates);
            List<Device> devices = new ArrayList<>();
            devices = deviceMapper.selectList(wrapper_device);
            if (devices.size()>0){
                for (Device device:devices) {
                    String mac = device.getMac();
                    deviceMacList.add(mac);
                    deviceMap.put(mac,device);
                    double longitude = device.getLongitude();
                    double latitude = device.getLatitude();
                    longitudeList.add(longitude);
                    latitudeList.add(latitude);
                }
            }else {
                continue;
            }
        }
        double latitudeMin = Collections.min(latitudeList)-0.0018;
        double latitudeMax = Collections.max(latitudeList)+0.0018;
        double longitudeMin = Collections.min(longitudeList)-0.2/(111*Math.cos(latitudeMin));
        double longitudeMax = Collections.max(longitudeList)+0.2/(111*Math.cos(latitudeMin));
        List<Double> bound = new ArrayList<>();
        bound.add(longitudeMin);
        bound.add(latitudeMin);
        bound.add(longitudeMax);
        bound.add(latitudeMax);
        List<List> bound1 = new ArrayList<>();
        List<Double> left_up = new ArrayList<>();
        left_up.add(latitudeMax);
        left_up.add(longitudeMin);
        List<Double> right_up = new ArrayList<>();
        right_up.add(latitudeMax);
        right_up.add(longitudeMax);
        List<Double> left_down = new ArrayList<>();
        left_down.add(latitudeMin);
        left_down.add(longitudeMin);
        List<Double> right_down = new ArrayList<>();
        right_down.add(latitudeMin);
        right_down.add(longitudeMax);
        bound1.add(left_up);
        bound1.add(right_up);
        bound1.add(right_down);
        bound1.add(left_down);
        List<GeoCoordinate> geoCoordinates = new ArrayList<>();
        for (List bo:bound1) {
            GeoCoordinate g = new GeoCoordinate();
            g.setLatitude(Double.parseDouble(bo.get(0).toString()));
            g.setLongitude(Double.parseDouble(bo.get(1).toString()));
            geoCoordinates.add(g);
        }
        GeoCoordinate centerPoint400 = GetCenterPointFromListOfCoordinates.getCenterPoint400(geoCoordinates);
        List centerPoint = new ArrayList();
        centerPoint.add(centerPoint400.getLongitude());
        centerPoint.add(centerPoint400.getLatitude());
        List<Map<String, Object>> resultList = new ArrayList<>();
        //获取时间
        String endTime = parameters.get("endTime").toString().substring(0,7)+"-01 00:00:00";
        //获取时间
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM");
        int months = Integer.parseInt(parameters.get("months").toString());
        Date newEndTime = new Date();
        for (int i=months;i>=0;i--){
            Map<String, Object> resultMap = new HashMap<>();
            //先存放中心点和边界点
            resultMap.put("centerPoint",centerPoint);
            resultMap.put("bound",bound);
            Calendar calendar = Calendar.getInstance();
            try {
                newEndTime = df.parse(endTime);
            } catch (ParseException e) {
                e.printStackTrace();
            }
            calendar.setTime(newEndTime);
            calendar.set(Calendar.MONTH,calendar.get(Calendar.MONDAY)-i);
            String time = df.format(calendar.getTime())+"-01 00:00:00";
            //存放时间
            resultMap.put("time",time);
            QueryWrapper<HistoryMonthly> historyMonthlyQueryWrapper = new QueryWrapper<>();
            historyMonthlyQueryWrapper.eq("time",time);
            historyMonthlyQueryWrapper.in("mac", deviceMacList);
            List<HistoryMonthly> historyDailies = historyMonthlyMapper.selectList(historyMonthlyQueryWrapper);
            List<Object> list = new ArrayList<>();
            for (HistoryMonthly historyMonthlyData:historyDailies) {
                List<Object> list1 = new ArrayList<>();
                String mac = historyMonthlyData.getMac();
                Device device = deviceMap.get(mac);
                double longitude = device.getLongitude();
                double latitude = device.getLatitude();
                JSONObject value = JSONObject.parseObject(historyMonthlyData.getValue());
                double num = Double.parseDouble(value.get(parameters.get("sensor_code")).toString());
                int level = PollutantUtils.pollutantLevel(num, (parameters.get("sensor_code")).toString());
                list1.add(longitude);
                list1.add(latitude);
                list1.add(level);
                list.add(list1);
            }
            resultMap.put("list",list);
            resultList.add(resultMap);
        }
        return resultList;
    }
}
screen-api/src/main/resources/mapper/AlarmInfoMapper.xml
@@ -32,6 +32,24 @@
        limit #{start},#{size}
    </select>
    <select id="selectDataByConditionWithoutPage" resultType="java.util.Map">
        select ai.id alarmInfoId,ai.alarm_time,ai.index,ai.alarm_type,ai.alarm_information,d.id deviceId,d.name deviceName,d.longitude,d.latitude
        from alarm_info ai, device d
        where ai.device_id in
        <foreach collection="deviceIds" item="deviceId" index="index" open="(" close=")" separator=",">
            #{deviceId}
        </foreach>
        and d.id = ai.device_id
        <if test="index != null">
            and ai.index = #{index}
        </if>
        <if test="alarmType != null">
            and ai.alarm_type = #{alarmType}
        </if>
        and alarm_time between #{startTime} and #{endTime}
        ORDER by ai.create_time DESC
    </select>
    <select id="selectNewestData" resultType="java.util.Map">
        select ai.id alarmInfoId,ai.alarm_time,ai.index,ai.alarm_type,ai.alarm_information,d.id deviceId,d.name deviceName,d.longitude,d.latitude
        from alarm_info ai, device d