jinpengyong
2023-12-20 8a9366f0ff6202144ef2cb1765b873d0f0c3c626
chore:热力图层级代码提交
3 files added
9 files modified
584 ■■■■ changed files
screen-api/src/main/java/com/moral/api/controller/HeatMapController.java 148 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/controller/OrganizationController.java 14 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/entity/DeviceMapHierarchy.java 57 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/mapper/DeviceMapHierarchyMapper.java 9 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/mapper/DeviceMapper.java 3 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/pojo/dto/dataDisplay/HeatMapDTO.java 2 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/service/DataDisplayService.java 9 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/service/OrganizationService.java 9 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/service/impl/DataDisplayServiceImpl.java 105 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/service/impl/OrganizationServiceImpl.java 30 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/utils/HeatMapTimeUtils.java 167 ●●●●● patch | view | raw | blame | history
screen-api/src/main/resources/mapper/DeviceMapper.xml 31 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/controller/HeatMapController.java
@@ -4,24 +4,18 @@
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.moral.api.pojo.dto.dataDisplay.HeatMapDTO;
import com.moral.api.service.DataDisplayService;
import com.moral.api.utils.HeatMapTimeUtils;
import com.moral.api.vo.HeatMapVo;
import com.moral.api.vo.TimeHourVo;
import com.moral.constant.ResultMessage;
import com.moral.util.DateUtils;
/**
 * Description //todo
@@ -43,11 +37,11 @@
     @GetMapping("query")
     @ApiOperation("热力图显示")
     public ResultMessage  getHeatMap(@RequestParam @ApiParam(value = "code",name = "区域码") String code,
     public ResultMessage  getHeatMap(@RequestParam @ApiParam(value = "organizationId",name = "组织id") Integer id,
                                      @RequestParam @ApiParam(value = "startTime",name = "开始时间") String startTime,
                                      @RequestParam @ApiParam(value = "type",name= "因子类型") String type,
                                      @RequestParam @ApiParam(value = "form",name= "时间类型") String form){
         List<HeatMapDTO> heatMapData = dataDisplayService.getHeatMapData(code, startTime, type, form);
         List<HeatMapDTO> heatMapData = dataDisplayService.getHeatMapDataV2(id, startTime, type, form);
         return ResultMessage.ok(ObjectUtils.isEmpty(heatMapData)?"0":heatMapData);
     }
    @GetMapping("queryTime")
@@ -55,141 +49,7 @@
    public ResultMessage  getHeatMap(@RequestParam @ApiParam(value = "startTime",name = "开始时间") String startTime,
                                     @RequestParam @ApiParam(value = "endTime",name= "结束类型") String endTime,
                                     @RequestParam @ApiParam(value = "type",name= "时间类型") String type){
        ArrayList<HeatMapVo> heatMapVos = new ArrayList<>();
        if (type.equals("day")){
            ArrayList<TimeHourVo> timeHourVos = new ArrayList<>();
            String[] splitStart = startTime.split("-");
            String[] splitEnd = endTime.split("-");
            LocalDate startDate = LocalDate.of(Integer.parseInt(splitStart[0]), Integer.parseInt(splitStart[1]), Integer.parseInt(splitStart[2]));
            LocalDate endDate = LocalDate.of(Integer.parseInt(splitEnd[0]), Integer.parseInt(splitEnd[1]), Integer.parseInt(splitEnd[2]));
            long daysBetween = ChronoUnit.DAYS.between(startDate, endDate);
            for (int i = 0; i <= daysBetween; i++) {
                HeatMapVo heatMapVo = new HeatMapVo();
                LocalDate date = startDate.plusDays(i);
                heatMapVo.setId(i);
                heatMapVo.setName(date.toString());
                heatMapVo.setHourListTime(timeHourVos);
                heatMapVos.add(heatMapVo);
            }
        }else if (type.equals("month")){
            ArrayList<TimeHourVo> timeHourVos = new ArrayList<>();
            String[] splitStart = startTime.split("-");
            String[] splitEnd = endTime.split("-");
            //结束时间月份的天数
            int monthDay = DateUtils.getMonthDay(DateUtils.getDate(endTime,DateUtils.yyyy_MM_EN));
            LocalDate startDate = LocalDate.of(Integer.parseInt(splitStart[0]), Integer.parseInt(splitStart[1]),1);
            LocalDate endDate = LocalDate.of(Integer.parseInt(splitEnd[0]), Integer.parseInt(splitEnd[1]),monthDay);
            long daysBetween = ChronoUnit.DAYS.between(startDate, endDate);
            for (int i = 0; i <= daysBetween; i++) {
                HeatMapVo heatMapVo = new HeatMapVo();
                LocalDate date = startDate.plusDays(i);
                heatMapVo.setId(i);
                heatMapVo.setName(date.toString());
                heatMapVo.setHourListTime(timeHourVos);
                heatMapVos.add(heatMapVo);
            }
        }else {
            int id = 0;
            int idHour = -1;
            Date ks = DateUtils.getDate(startTime,"yyyy-MM-dd HH");
            Date js = DateUtils.getDateAddHour(DateUtils.getDate(endTime,"yyyy-MM-dd HH"),1);
            String name =  DateUtils.dateToDateString(ks,DateUtils.yyyy_MM_dd_EN);
            List<TimeHourVo> hourListTime = new ArrayList<>();
            while (DateUtils.isTimeBefor(js,ks)){
                idHour++;
                HeatMapVo heatMapVo = new HeatMapVo();
                String nameEndTime =  DateUtils.dateToDateString(ks,DateUtils.yyyy_MM_dd_EN);
                String time =  DateUtils.dateToDateString(ks,"HH");
                String ksTime =  DateUtils.dateToDateString(ks,"yyyy-MM-dd HH");
                TimeHourVo hourVo = new TimeHourVo();
                heatMapVo.setName(name);
                heatMapVo.setId(id);
                if(name.equals(nameEndTime)){
                    heatMapVo.setId(id);
                    heatMapVo.setName(name);
                    hourVo.setName(time);
                    hourVo.setId(idHour);
                    hourListTime.add(hourVo);
                    if(ksTime.equals(endTime)){
                        heatMapVo.setHourListTime(hourListTime);
                        heatMapVos.add(heatMapVo);
                        idHour++;
                        break;
                    }
                }else {
                    id++;
                    if(ksTime.equals(endTime)){
                        heatMapVo.setHourListTime(hourListTime);
                        heatMapVos.add(heatMapVo);
                        hourListTime = new ArrayList<>();
                        hourVo = new TimeHourVo();
                        heatMapVo = new HeatMapVo();
                        hourVo.setName("00");
                        hourVo.setId(idHour++);
                        hourListTime.add(hourVo);
                        heatMapVo.setId(id);
                        heatMapVo.setName(nameEndTime);
                        heatMapVo.setHourListTime(hourListTime);
                        heatMapVos.add(heatMapVo);
                        break;
                    }else {
                        name = nameEndTime;
                        heatMapVo.setHourListTime(hourListTime);
                        heatMapVos.add(heatMapVo);
                        hourListTime = new ArrayList<>();
                        hourVo.setName(time);
                        hourVo.setId(idHour);
                        hourListTime.add(hourVo);
                    }
                }
                ks = DateUtils.getDateAddHour(ks,1);
            }
            if(CollectionUtils.isNotEmpty(heatMapVos)){
                heatMapVos.get(0).setIdLength(idHour);
            }
/*            String[] splitStart = startTime.split("-");
            String[] s1 = splitStart[2].split(" ");
            String[] splitEnd = endTime.split("-");
            String[] s2 = splitEnd[2].split(" ");
            //获取天时间
            LocalDate startDate = LocalDate.of(Integer.parseInt(splitStart[0]), Integer.parseInt(splitStart[1]),Integer.parseInt(s1[0]));
            LocalDate endDate = LocalDate.of(Integer.parseInt(splitEnd[0]), Integer.parseInt(splitEnd[1]),Integer.parseInt(s2[0]));
            long daysBetween = ChronoUnit.DAYS.between(startDate, endDate);
            //获取小时
            LocalDateTime startDateTime = LocalDateTime.of(Integer.parseInt(splitStart[0]), Integer.parseInt(splitStart[1]), Integer.parseInt(s1[0]), Integer.parseInt(s1[1]), 0);
            LocalDateTime endDateTime = LocalDateTime.of(Integer.parseInt(splitEnd[0]), Integer.parseInt(splitEnd[1]), Integer.parseInt(s2[0]), Integer.parseInt(s2[1]), 0);
            List<String> hourList = new ArrayList<>();
            LocalDateTime currentDateTime = startDateTime;
            while (currentDateTime.isBefore(endDateTime) || currentDateTime.equals(endDateTime)) {
                hourList.add(currentDateTime.toString());
                currentDateTime = currentDateTime.plusHours(1);
            }
            int length=0;
            for (int i = 0; i <= daysBetween; i++) {
                ArrayList<TimeHourVo> timeHourVos = new ArrayList<>();
                HeatMapVo heatMapVo = new HeatMapVo();
                LocalDate date = startDate.plusDays(i);
                heatMapVo.setId(i);
                heatMapVo.setName(date.toString());
                for (int i1 = 0; i1 < hourList.size(); i1++) {
                    if (hourList.get(i1).contains(date.toString())){
                        TimeHourVo hourVo = new TimeHourVo();
                        hourVo.setName(hourList.get(i1).substring(11,13));
                        hourVo.setId(length);
                        timeHourVos.add(hourVo);
                        hourList.remove(i1);
                        i1--;
                        length++;
                    }
                }
                heatMapVo.setHourListTime(timeHourVos);
                heatMapVos.add(heatMapVo);
            }
            heatMapVos.get(0).setIdLength(length);*/
        }
        List<HeatMapVo> heatMapVos = HeatMapTimeUtils.getTime(startTime, endTime, type);
        return ResultMessage.ok(ObjectUtils.isEmpty(heatMapVos)?"0":heatMapVos);
    }
screen-api/src/main/java/com/moral/api/controller/OrganizationController.java
@@ -6,6 +6,7 @@
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -16,7 +17,9 @@
import javax.servlet.http.HttpServletRequest;
import com.moral.api.entity.Organization;
import com.moral.api.service.DeviceService;
import com.moral.api.service.OrganizationService;
import com.moral.api.service.SysAreaService;
import com.moral.constant.ResponseCodeEnum;
import com.moral.constant.ResultMessage;
@@ -34,6 +37,9 @@
    @Autowired
    private DeviceService deviceService;
    @Autowired
    private OrganizationService organizationService;
    /**
     * @param request 请求信息
@@ -72,4 +78,12 @@
        List<Map<String, Object>> response = deviceService.getDevicesByOrganizationId(Integer.parseInt(params.get("organizationId").toString()));
        return ResultMessage.ok(response);
    }
    @GetMapping("getOrganizationId")
    @ApiOperation("根据账号查询组织")
    public  ResultMessage getOrganizationId(){
        List<Organization> organizations = organizationService.getOrganizationId();
        return ResultMessage.ok(ObjectUtils.isEmpty(organizations)?"0":organizations);
    }
}
screen-api/src/main/java/com/moral/api/entity/DeviceMapHierarchy.java
New file
@@ -0,0 +1,57 @@
package com.moral.api.entity;
import lombok.Data;
import java.util.Date;
/**
 * Description //todo
 *
 * @author swb
 * @ClassName DeviceMapHierarchy
 * @date 2023.12.19 11:24
 */
@Data
public class DeviceMapHierarchy {
    /**
     * 主键
     */
    private  Integer id;
    /**
     * 设备id
     */
    private  Integer deviceId;
    /**
     * 组织id
     *
     */
    private  Integer organizationId;
    /**
     * 缩放级别
     */
    private  Integer zoomLevel;
    /**
     * 分组id
     *
     */
    private  Integer groupId;
    /**
     * 热力范围
     */
    private  Integer hierarchyRange;
    /**
     * 是否删除
     */
    private  Integer isDel;
    private  Integer createId;
    private  String createName;
    private  Date createTime;
    private  Integer updateId;
    private  String updateName;
    private Date updateTime;
}
screen-api/src/main/java/com/moral/api/mapper/DeviceMapHierarchyMapper.java
New file
@@ -0,0 +1,9 @@
package com.moral.api.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
public interface DeviceMapHierarchyMapper extends BaseMapper<DeviceMapper> {
}
screen-api/src/main/java/com/moral/api/mapper/DeviceMapper.java
@@ -42,4 +42,7 @@
    List<HeatMapDTO> getHeatMap(HashMap<String,Object> params);
    List<HeatMapDTO> getHeatMapV1(HashMap<String,Object> params);
}
screen-api/src/main/java/com/moral/api/pojo/dto/dataDisplay/HeatMapDTO.java
@@ -43,6 +43,8 @@
    private  String name;
    private  Integer groupId;
    public Double getCount(){
        Double count = this.count;
        if (ObjectUtils.isEmpty(count)){
screen-api/src/main/java/com/moral/api/service/DataDisplayService.java
@@ -5,10 +5,6 @@
import com.moral.api.pojo.dto.dataDisplay.SensorComparisonDisplayDTO;
import com.moral.api.pojo.form.dataDisplay.MonitorPointDataDisplayForm;
import com.moral.api.pojo.form.dataDisplay.SensorComparisonDisplayForm;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -50,4 +46,9 @@
    List<HeatMapDTO> getHeatMapData(String code, String startTime, String type, String form);
    List<HeatMapDTO> getHeatMapDataV2(Integer id, String startTime, String type, String form);
}
screen-api/src/main/java/com/moral/api/service/OrganizationService.java
@@ -42,4 +42,13 @@
     */
    List<Integer> orgIdList( Integer organizationId);
    /**
     * 根据账号获取组织信息
     * @param
     * @return
     */
    List<Organization> getOrganizationId();
}
screen-api/src/main/java/com/moral/api/service/impl/DataDisplayServiceImpl.java
@@ -3,6 +3,7 @@
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jhlabs.composite.AverageComposite;
import com.moral.api.entity.*;
import com.moral.api.mapper.DeviceMapper;
import com.moral.api.mapper.HistoryMonthlyMapper;
@@ -13,6 +14,7 @@
import com.moral.api.pojo.form.dataDisplay.MonitorPointDataDisplayForm;
import com.moral.api.pojo.form.dataDisplay.SensorComparisonDisplayForm;
import com.moral.api.service.*;
import com.moral.api.utils.GetCenterPointFromListOfCoordinates;
import com.moral.constant.Constants;
import com.moral.constant.SeparateTableType;
import com.moral.pojo.AQI;
@@ -21,6 +23,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import reactor.core.publisher.Flux;
import java.util.*;
import java.util.stream.Collectors;
@@ -446,6 +449,106 @@
        return distrinList(rsHeatMap);
    }
    @Override
    public List<HeatMapDTO> getHeatMapDataV2(Integer id, String startTime, String type, String form) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("start",startTime);
        map.put("type","$."+ type);
        //获取用户信息
//        Map<String, Object> userInfo = (Map<String, Object>) TokenUtils.getUserInfo();
//        Map<String, Object> orgInfo = (Map<String, Object>) userInfo.get("organization");
//        Integer organizationId = (Integer) orgInfo.get("id");
        //大账号
        ArrayList<Integer> list = new ArrayList<>();
        list.add(id);
//        if (organizationId==24){
////            LambdaQueryWrapper<Organization> wrapper = new LambdaQueryWrapper<>();
////            wrapper.eq(Organization::getIsDelete,Constants.NOT_DELETE);
////            wrapper.eq(Organization::getId,id);
////            List<Organization> organizations = organizationMapper.selectList(wrapper);
////            List<Integer> collect = organizations.stream().map(organization -> organization.getId()).collect(Collectors.toList());
////            list.addAll(collect);
//            list.add(id);
//        }else {
//            list.add(id);
//        }
        ArrayList<HeatMapDTO> rsHeatMap = new ArrayList<>();
        if (form.equals("hour")){ //小时
            log.info(""+startTime);
            String dateString = DateUtils.stringToDateString(startTime, DateUtils.yyyy_MM_dd_HH_EN, DateUtils.yyyyMM_EN);
//            Date date1 = DateUtils.getDate(startTime, DateUtils.yyyy_MM_dd_HH_EN);
            log.info(""+dateString);
            map.put("organizationIds",list);
            map.put("tableName","_"+dateString);
            List<HeatMapDTO> heatMap = deviceMapper.getHeatMapV1(map);
            log.info(heatMap.size()+"");
            List<HeatMapDTO> collect1 = heatMap.stream().filter(d -> d.getTime() != null).collect(Collectors.toList());
            if (ObjectUtils.isEmpty(collect1)){
                return null;
            }
            getHeatMap(heatMap);
            rsHeatMap.addAll(heatMap);
        }else { //天
            map.put("organizationIds",list);
            List<HeatMapDTO> heatMap = deviceMapper.getHeatMapV1(map);
            List<HeatMapDTO> collect1 = heatMap.stream().filter(d -> d.getTime() != null).collect(Collectors.toList());
            if (ObjectUtils.isEmpty(collect1)){
                return null;
            }
            getHeatMap(heatMap);
            rsHeatMap.addAll(heatMap);
        }
        return distrinList(rsHeatMap);
    }
    //数据处理
    private void getHeatMap(List<HeatMapDTO> heatMap) {
        //数据过滤
        List<HeatMapDTO> collect1 = heatMap.stream().filter(d -> d.getGroupId() != null).collect(Collectors.toList());
        if (ObjectUtils.isEmpty(collect1)){
            return;
        }
        //数据分类
        Map<Integer, List<HeatMapDTO>> collect = collect1.parallelStream().collect(Collectors.groupingBy(o ->o.getGroupId()));
        Set<Integer> integers = collect.keySet();
        int i = 0 ;
        for (Integer integer : integers) {
            ArrayList<Double> doubleArrayList = new ArrayList<>();
            ArrayList<GeoCoordinate> geoCoordinates = new ArrayList<>();
            List<HeatMapDTO> heatMapDTOS = collect.get(integer);
            for (HeatMapDTO heatMapDTO : heatMapDTOS) {
                GeoCoordinate geoCoordinate = new GeoCoordinate();
                doubleArrayList.add(heatMapDTO.getCount());
//                heatMapDTO.setCount(heatMapDTO.getCount());
                heatMapDTO.setCount(0.0);
                geoCoordinate.setLongitude(heatMapDTO.getLng());
                geoCoordinate.setLatitude(heatMapDTO.getLat());
                geoCoordinates.add(geoCoordinate);
            }
            if (!ObjectUtils.isEmpty(doubleArrayList)){
                HeatMapDTO heatMapDTO = new HeatMapDTO();
                //计算均值集合
                double asDouble = doubleArrayList.stream().mapToDouble(Double::valueOf).max().getAsDouble();
                //获取中心点
                GeoCoordinate centerPoint = GetCenterPointFromListOfCoordinates.getCenterPoint(geoCoordinates);
                heatMapDTO.setCount(asDouble);
                heatMapDTO.setLng(centerPoint.getLongitude());
                heatMapDTO.setLat(centerPoint.getLatitude());
                heatMapDTO.setMac(i+"");
                heatMap.add(heatMapDTO);
                i++;
            }
        }
    }
    /**
     * 字段去重
     * @param responseList
@@ -463,8 +566,6 @@
                rsMap.add(heatMapDTO);
            }
        }
        log.info(responseList.size()+"");
        log.info(rsMap.size()+"");
        return rsMap;
screen-api/src/main/java/com/moral/api/service/impl/OrganizationServiceImpl.java
@@ -1,5 +1,6 @@
package com.moral.api.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.moral.api.config.Interceptor.UserHelper;
import com.moral.api.entity.MonitorPoint;
@@ -12,12 +13,15 @@
import com.moral.api.service.OrganizationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.moral.constant.Constants;
import com.moral.util.TokenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
 * <p>
@@ -76,4 +80,30 @@
    public List<Integer> orgIdList(Integer organizationId) {
        return this.baseMapper.orgIdList(organizationId);
    }
    /**
     * 根据id获取组织信息
     *
     * @param
     * @return
     */
    @Override
    public List<Organization> getOrganizationId() {
        //获取用户信息
        Map<String, Object> userInfo = (Map<String, Object>) TokenUtils.getUserInfo();
        Map<String, Object> orgInfo = (Map<String, Object>) userInfo.get("organization");
        Integer organizationId = (Integer) orgInfo.get("id");
         ArrayList<Organization> rsList = new ArrayList<>();
        if (organizationId==24){
            LambdaQueryWrapper<Organization> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(Organization::getParentId,organizationId);
            wrapper.eq(Organization::getIsDelete,Constants.NOT_DELETE);
            List<Organization> organizations = organizationMapper.selectList(wrapper);
            rsList.addAll(organizations);
        }else {
            Organization organizationById = this.getOrganizationById(organizationId);
            rsList.add(organizationById);
        }
        return rsList;
    }
}
screen-api/src/main/java/com/moral/api/utils/HeatMapTimeUtils.java
New file
@@ -0,0 +1,167 @@
package com.moral.api.utils;
import org.apache.commons.collections4.CollectionUtils;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.moral.api.vo.HeatMapVo;
import com.moral.api.vo.TimeHourVo;
import com.moral.util.DateUtils;
/**
 * Description //todo
 *
 * @author swb
 * @ClassName HeatMapTimeUtils
 * @date 2023.12.18 13:42
 */
public class HeatMapTimeUtils {
    /**
     *获取某段时间的每天天数,和小时数
     */
    public static List<HeatMapVo> getTime(String startTime, String endTime, String type){
        ArrayList<HeatMapVo> heatMapVos = new ArrayList<>();
        if (type.equals("day")){
            ArrayList<TimeHourVo> timeHourVos = new ArrayList<>();
            String[] splitStart = startTime.split("-");
            String[] splitEnd = endTime.split("-");
            LocalDate startDate = LocalDate.of(Integer.parseInt(splitStart[0]), Integer.parseInt(splitStart[1]), Integer.parseInt(splitStart[2]));
            LocalDate endDate = LocalDate.of(Integer.parseInt(splitEnd[0]), Integer.parseInt(splitEnd[1]), Integer.parseInt(splitEnd[2]));
            long daysBetween = ChronoUnit.DAYS.between(startDate, endDate);
            for (int i = 0; i <= daysBetween; i++) {
                HeatMapVo heatMapVo = new HeatMapVo();
                LocalDate date = startDate.plusDays(i);
                heatMapVo.setId(i);
                heatMapVo.setName(date.toString());
                heatMapVo.setHourListTime(timeHourVos);
                heatMapVos.add(heatMapVo);
            }
        }else if (type.equals("month")){
            ArrayList<TimeHourVo> timeHourVos = new ArrayList<>();
            String[] splitStart = startTime.split("-");
            String[] splitEnd = endTime.split("-");
            //结束时间月份的天数
            int monthDay = DateUtils.getMonthDay(DateUtils.getDate(endTime,DateUtils.yyyy_MM_EN));
            LocalDate startDate = LocalDate.of(Integer.parseInt(splitStart[0]), Integer.parseInt(splitStart[1]),1);
            LocalDate endDate = LocalDate.of(Integer.parseInt(splitEnd[0]), Integer.parseInt(splitEnd[1]),monthDay);
            long daysBetween = ChronoUnit.DAYS.between(startDate, endDate);
            for (int i = 0; i <= daysBetween; i++) {
                HeatMapVo heatMapVo = new HeatMapVo();
                LocalDate date = startDate.plusDays(i);
                heatMapVo.setId(i);
                heatMapVo.setName(date.toString());
                heatMapVo.setHourListTime(timeHourVos);
                heatMapVos.add(heatMapVo);
            }
        }else {
            int id = 0;
            int idHour = -1;
            Date ks = DateUtils.getDate(startTime,"yyyy-MM-dd HH");
            Date js = DateUtils.getDateAddHour(DateUtils.getDate(endTime,"yyyy-MM-dd HH"),1);
            String name =  DateUtils.dateToDateString(ks,DateUtils.yyyy_MM_dd_EN);
            List<TimeHourVo> hourListTime = new ArrayList<>();
            while (DateUtils.isTimeBefor(js,ks)){
                idHour++;
                HeatMapVo heatMapVo = new HeatMapVo();
                String nameEndTime =  DateUtils.dateToDateString(ks,DateUtils.yyyy_MM_dd_EN);
                String time =  DateUtils.dateToDateString(ks,"HH");
                String ksTime =  DateUtils.dateToDateString(ks,"yyyy-MM-dd HH");
                TimeHourVo hourVo = new TimeHourVo();
                heatMapVo.setName(name);
                heatMapVo.setId(id);
                if(name.equals(nameEndTime)){
                    heatMapVo.setId(id);
                    heatMapVo.setName(name);
                    hourVo.setName(time);
                    hourVo.setId(idHour);
                    hourListTime.add(hourVo);
                    if(ksTime.equals(endTime)){
                        heatMapVo.setHourListTime(hourListTime);
                        heatMapVos.add(heatMapVo);
                        idHour++;
                        break;
                    }
                }else {
                    id++;
                    if(ksTime.equals(endTime)){
                        heatMapVo.setHourListTime(hourListTime);
                        heatMapVos.add(heatMapVo);
                        hourListTime = new ArrayList<>();
                        hourVo = new TimeHourVo();
                        heatMapVo = new HeatMapVo();
                        hourVo.setName("00");
                        hourVo.setId(idHour++);
                        hourListTime.add(hourVo);
                        heatMapVo.setId(id);
                        heatMapVo.setName(nameEndTime);
                        heatMapVo.setHourListTime(hourListTime);
                        heatMapVos.add(heatMapVo);
                        break;
                    }else {
                        name = nameEndTime;
                        heatMapVo.setHourListTime(hourListTime);
                        heatMapVos.add(heatMapVo);
                        hourListTime = new ArrayList<>();
                        hourVo.setName(time);
                        hourVo.setId(idHour);
                        hourListTime.add(hourVo);
                    }
                }
                ks = DateUtils.getDateAddHour(ks,1);
            }
            if(CollectionUtils.isNotEmpty(heatMapVos)){
                heatMapVos.get(0).setIdLength(idHour);
            }
/*            String[] splitStart = startTime.split("-");
            String[] s1 = splitStart[2].split(" ");
            String[] splitEnd = endTime.split("-");
            String[] s2 = splitEnd[2].split(" ");
            //获取天时间
            LocalDate startDate = LocalDate.of(Integer.parseInt(splitStart[0]), Integer.parseInt(splitStart[1]),Integer.parseInt(s1[0]));
            LocalDate endDate = LocalDate.of(Integer.parseInt(splitEnd[0]), Integer.parseInt(splitEnd[1]),Integer.parseInt(s2[0]));
            long daysBetween = ChronoUnit.DAYS.between(startDate, endDate);
            //获取小时
            LocalDateTime startDateTime = LocalDateTime.of(Integer.parseInt(splitStart[0]), Integer.parseInt(splitStart[1]), Integer.parseInt(s1[0]), Integer.parseInt(s1[1]), 0);
            LocalDateTime endDateTime = LocalDateTime.of(Integer.parseInt(splitEnd[0]), Integer.parseInt(splitEnd[1]), Integer.parseInt(s2[0]), Integer.parseInt(s2[1]), 0);
            List<String> hourList = new ArrayList<>();
            LocalDateTime currentDateTime = startDateTime;
            while (currentDateTime.isBefore(endDateTime) || currentDateTime.equals(endDateTime)) {
                hourList.add(currentDateTime.toString());
                currentDateTime = currentDateTime.plusHours(1);
            }
            int length=0;
            for (int i = 0; i <= daysBetween; i++) {
                ArrayList<TimeHourVo> timeHourVos = new ArrayList<>();
                HeatMapVo heatMapVo = new HeatMapVo();
                LocalDate date = startDate.plusDays(i);
                heatMapVo.setId(i);
                heatMapVo.setName(date.toString());
                for (int i1 = 0; i1 < hourList.size(); i1++) {
                    if (hourList.get(i1).contains(date.toString())){
                        TimeHourVo hourVo = new TimeHourVo();
                        hourVo.setName(hourList.get(i1).substring(11,13));
                        hourVo.setId(length);
                        timeHourVos.add(hourVo);
                        hourList.remove(i1);
                        i1--;
                        length++;
                    }
                }
                heatMapVo.setHourListTime(timeHourVos);
                heatMapVos.add(heatMapVo);
            }
            heatMapVos.get(0).setIdLength(length);*/
        }
        return heatMapVos;
    }
}
screen-api/src/main/resources/mapper/DeviceMapper.xml
@@ -237,4 +237,35 @@
         d.is_delete = 0
        order by d.mac
    </select>
    <select id="getHeatMapV1" resultType="com.moral.api.pojo.dto.dataDisplay.HeatMapDTO">
        SELECT
        d.mac as mac,
        d.latitude as lat,
        d.longitude as lng,
        d.name as name,
        (hd.value ->> #{type} ) as count,
        hd.time,
        dm.group_id AS groupId
        FROM
        device as d
        inner JOIN organization o on o.id = d.organization_id and o.is_delete = 0
        <if test="organizationIds != null and organizationIds.size !=0">
            and organization_id in
            <foreach collection="organizationIds" item="id" index="index" open="(" close=")" separator=",">
                #{id}
            </foreach>
        </if>
        inner JOIN device_map_hierarchy as dm on d.id = dm.device_id
        <if test="tableName !=null">
            left join history_hourly${tableName} hd on hd.time = #{start}  and d.mac = hd.mac
        </if>
        <if test="tableName ==null ">
            left join history_daily hd on hd.time = #{start}   and d.mac = hd.mac
        </if>
        WHERE
        d.is_delete = 0
        order by d.mac
    </select>
</mapper>