From 8a9366f0ff6202144ef2cb1765b873d0f0c3c626 Mon Sep 17 00:00:00 2001 From: jinpengyong <jpy123456> Date: Wed, 20 Dec 2023 15:57:17 +0800 Subject: [PATCH] chore:热力图层级代码提交 --- screen-api/src/main/java/com/moral/api/utils/HeatMapTimeUtils.java | 167 ++++++++++++++++ screen-api/src/main/java/com/moral/api/service/impl/DataDisplayServiceImpl.java | 105 ++++++++++ screen-api/src/main/java/com/moral/api/service/OrganizationService.java | 9 screen-api/src/main/java/com/moral/api/service/DataDisplayService.java | 9 screen-api/src/main/java/com/moral/api/service/impl/OrganizationServiceImpl.java | 30 +++ screen-api/src/main/java/com/moral/api/entity/DeviceMapHierarchy.java | 57 +++++ screen-api/src/main/java/com/moral/api/controller/HeatMapController.java | 148 -------------- screen-api/src/main/java/com/moral/api/pojo/dto/dataDisplay/HeatMapDTO.java | 2 screen-api/src/main/java/com/moral/api/mapper/DeviceMapHierarchyMapper.java | 9 screen-api/src/main/java/com/moral/api/mapper/DeviceMapper.java | 3 screen-api/src/main/java/com/moral/api/controller/OrganizationController.java | 14 + screen-api/src/main/resources/mapper/DeviceMapper.xml | 31 +++ 12 files changed, 434 insertions(+), 150 deletions(-) diff --git a/screen-api/src/main/java/com/moral/api/controller/HeatMapController.java b/screen-api/src/main/java/com/moral/api/controller/HeatMapController.java index 2b149c1..7ca6485 100644 --- a/screen-api/src/main/java/com/moral/api/controller/HeatMapController.java +++ b/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); } diff --git a/screen-api/src/main/java/com/moral/api/controller/OrganizationController.java b/screen-api/src/main/java/com/moral/api/controller/OrganizationController.java index 6101bfc..58fdf2c 100644 --- a/screen-api/src/main/java/com/moral/api/controller/OrganizationController.java +++ b/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); + } } diff --git a/screen-api/src/main/java/com/moral/api/entity/DeviceMapHierarchy.java b/screen-api/src/main/java/com/moral/api/entity/DeviceMapHierarchy.java new file mode 100644 index 0000000..9e530f0 --- /dev/null +++ b/screen-api/src/main/java/com/moral/api/entity/DeviceMapHierarchy.java @@ -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; + + + +} diff --git a/screen-api/src/main/java/com/moral/api/mapper/DeviceMapHierarchyMapper.java b/screen-api/src/main/java/com/moral/api/mapper/DeviceMapHierarchyMapper.java new file mode 100644 index 0000000..7cfd122 --- /dev/null +++ b/screen-api/src/main/java/com/moral/api/mapper/DeviceMapHierarchyMapper.java @@ -0,0 +1,9 @@ +package com.moral.api.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + + + + +public interface DeviceMapHierarchyMapper extends BaseMapper<DeviceMapper> { +} diff --git a/screen-api/src/main/java/com/moral/api/mapper/DeviceMapper.java b/screen-api/src/main/java/com/moral/api/mapper/DeviceMapper.java index 2108f67..7492170 100644 --- a/screen-api/src/main/java/com/moral/api/mapper/DeviceMapper.java +++ b/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); + } diff --git a/screen-api/src/main/java/com/moral/api/pojo/dto/dataDisplay/HeatMapDTO.java b/screen-api/src/main/java/com/moral/api/pojo/dto/dataDisplay/HeatMapDTO.java index 632f91f..bf57b16 100644 --- a/screen-api/src/main/java/com/moral/api/pojo/dto/dataDisplay/HeatMapDTO.java +++ b/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)){ diff --git a/screen-api/src/main/java/com/moral/api/service/DataDisplayService.java b/screen-api/src/main/java/com/moral/api/service/DataDisplayService.java index 3f0c7db..20443b0 100644 --- a/screen-api/src/main/java/com/moral/api/service/DataDisplayService.java +++ b/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); } diff --git a/screen-api/src/main/java/com/moral/api/service/OrganizationService.java b/screen-api/src/main/java/com/moral/api/service/OrganizationService.java index 2c3972c..559b4e5 100644 --- a/screen-api/src/main/java/com/moral/api/service/OrganizationService.java +++ b/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(); + + } diff --git a/screen-api/src/main/java/com/moral/api/service/impl/DataDisplayServiceImpl.java b/screen-api/src/main/java/com/moral/api/service/impl/DataDisplayServiceImpl.java index 08b56c9..280c7fd 100644 --- a/screen-api/src/main/java/com/moral/api/service/impl/DataDisplayServiceImpl.java +++ b/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; diff --git a/screen-api/src/main/java/com/moral/api/service/impl/OrganizationServiceImpl.java b/screen-api/src/main/java/com/moral/api/service/impl/OrganizationServiceImpl.java index 9b03888..3616d86 100644 --- a/screen-api/src/main/java/com/moral/api/service/impl/OrganizationServiceImpl.java +++ b/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; + } } diff --git a/screen-api/src/main/java/com/moral/api/utils/HeatMapTimeUtils.java b/screen-api/src/main/java/com/moral/api/utils/HeatMapTimeUtils.java new file mode 100644 index 0000000..112ec28 --- /dev/null +++ b/screen-api/src/main/java/com/moral/api/utils/HeatMapTimeUtils.java @@ -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; + } + +} diff --git a/screen-api/src/main/resources/mapper/DeviceMapper.xml b/screen-api/src/main/resources/mapper/DeviceMapper.xml index 94613fe..39de26e 100644 --- a/screen-api/src/main/resources/mapper/DeviceMapper.xml +++ b/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> \ No newline at end of file -- Gitblit v1.8.0