From 2ab4d484c09bf29d5f63dafb0fec3eda23bc4b4e Mon Sep 17 00:00:00 2001 From: cjl <276999030@qq.com> Date: Mon, 25 Dec 2023 14:17:36 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/dev' into cjl --- screen-api/src/main/java/com/moral/api/utils/HeatMapTimeUtils.java | 167 +++++++++++++ screen-api/src/main/java/com/moral/api/service/impl/DataDisplayServiceImpl.java | 189 ++++++++++++++- 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 | 21 + 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 | 33 ++ 12 files changed, 513 insertions(+), 176 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..830e6ac 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,14 +43,19 @@ private String name; - public Double getCount(){ - Double count = this.count; - if (ObjectUtils.isEmpty(count)){ - count= 0.0; - return count; - } - return count; - } + private Integer groupId; + + +// private Double sum; + +// public Double getCount(){ +// Double count = this.count; +// if (ObjectUtils.isEmpty(count)){ +// count= 0.0; +// return count; +// } +// return 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..e560813 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 @@ -1,7 +1,6 @@ package com.moral.api.service.impl; import com.alibaba.fastjson.JSON; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.moral.api.entity.*; import com.moral.api.mapper.DeviceMapper; @@ -13,6 +12,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; @@ -404,26 +404,10 @@ 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<>(); - if (organizationId==24){ - LambdaQueryWrapper<Organization> wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(Organization::getIsDelete,Constants.NOT_DELETE); - wrapper.eq(Organization::getCityCode,code); - List<Organization> organizations = organizationMapper.selectList(wrapper); - List<Integer> collect = organizations.stream().map(organization -> organization.getId()).collect(Collectors.toList()); - list.addAll(collect); - }else { - list.add(organizationId); - } // ArrayList<Map<String, Object>> rsHeatMap = new ArrayList<>(); ArrayList<HeatMapDTO> rsHeatMap = new ArrayList<>(); - if (form.equals("hour")){ //������ Date date1 = DateUtils.getDate(startTime, DateUtils.yyyy_MM_dd_HH_EN); List<String> tableNames = MybatisPLUSUtils.getTableNamesByWrapper(date1, date1, SeparateTableType.MONTH); @@ -446,6 +430,175 @@ 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); + ArrayList<Integer> list = new ArrayList<>(); + list.add(id); + ArrayList<HeatMapDTO> rsHeatMap = new ArrayList<>(); + ArrayList<String> list1 = new ArrayList<>(); + list1.add("���������������"); + list1.add("���������������"); + list1.add("���������������"); + list1.add("���������������"); + list1.add("������������������"); + + if (form.equals("hour")){ //������ +// String[] split = startTime.split("-"); +// String s = "_" + split[0] + split[1]; + String dateString = DateUtils.stringToDateString(startTime, DateUtils.yyyy_MM_dd_HH_EN, DateUtils.yyyyMM_EN); + map.put("organizationIds",list); + map.put("tableName","_"+dateString); + + 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; + } + for (HeatMapDTO heatMapDTO : heatMap) { +// if (list1.contains(heatMapDTO.getName())){ + if (type.equals("a34002") || type.equals("a21026")){ + heatMapDTO.setCount(ObjectUtils.isEmpty(heatMapDTO.getCount())?49.0:heatMapDTO.getCount()); + }else if (type.equals("a34004")){ + heatMapDTO.setCount(ObjectUtils.isEmpty(heatMapDTO.getCount())?20.0:heatMapDTO.getCount()); + }else if (type.equals("a21004")){ + heatMapDTO.setCount(ObjectUtils.isEmpty(heatMapDTO.getCount())?20.0:heatMapDTO.getCount()); + }else if (type.equals("a21005")){ + heatMapDTO.setCount(ObjectUtils.isEmpty(heatMapDTO.getCount())?1.0:heatMapDTO.getCount()); + }else if (type.equals("a05024")){ + heatMapDTO.setCount(ObjectUtils.isEmpty(heatMapDTO.getCount())?138.0:heatMapDTO.getCount()); + }else { + heatMapDTO.setCount(ObjectUtils.isEmpty(heatMapDTO.getCount())?0.2:heatMapDTO.getCount()); + } +// }else { +// if (ObjectUtils.isEmpty(heatMapDTO.getCount())){ +// heatMapDTO.setCount(0.0); +// } +// } + } + + getHeatMap(heatMap,type); + 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; + } + for (HeatMapDTO heatMapDTO : heatMap) { + if (type.equals("a34002") || type.equals("a21026")){ + heatMapDTO.setCount(ObjectUtils.isEmpty(heatMapDTO.getCount())?49.0:heatMapDTO.getCount()); + }else if (type.equals("a34004")){ + heatMapDTO.setCount(ObjectUtils.isEmpty(heatMapDTO.getCount())?34.0:heatMapDTO.getCount()); + }else if (type.equals("a21004")){ + heatMapDTO.setCount(ObjectUtils.isEmpty(heatMapDTO.getCount())?39.0:heatMapDTO.getCount()); + }else if (type.equals("a21005")){ + heatMapDTO.setCount(ObjectUtils.isEmpty(heatMapDTO.getCount())?1.9:heatMapDTO.getCount()); + }else if (type.equals("a05024")){ + heatMapDTO.setCount(ObjectUtils.isEmpty(heatMapDTO.getCount())?100.0:heatMapDTO.getCount()); + }else { + heatMapDTO.setCount(ObjectUtils.isEmpty(heatMapDTO.getCount())?0.4:heatMapDTO.getCount()); + } + } + getHeatMap(heatMap,type); + rsHeatMap.addAll(heatMap); + } + for (int i = 0; i <6; i++) { + HeatMapDTO heatMapDTO = new HeatMapDTO(); + heatMapDTO.setCount(0.0); + if (i==0){ + heatMapDTO.setLat(40.590436); + heatMapDTO.setLng(122.861935); + heatMapDTO.setMac("1111"); + heatMapDTO.setName("1111"); + }else if (i==1){ + heatMapDTO.setLat(40.636617); + heatMapDTO.setLng(123.101544); + heatMapDTO.setMac("2222"); + heatMapDTO.setName("2222"); + }else if (i==2){ + heatMapDTO.setLat(40.890881); + heatMapDTO.setLng(122.910687); + heatMapDTO.setMac("3333"); + heatMapDTO.setName("3333"); + }else if (i==3){ + heatMapDTO.setLat(40.682129); + heatMapDTO.setLng(123.105836); + heatMapDTO.setMac("4444"); + heatMapDTO.setName("4444"); + }else if (i==4){ + heatMapDTO.setLat(40.890037); + heatMapDTO.setLng(123.021151); + heatMapDTO.setMac("5555"); + heatMapDTO.setName("5555"); + }else { + heatMapDTO.setLat(41.051333); + heatMapDTO.setLng(122.505864); + heatMapDTO.setMac("6666"); + heatMapDTO.setName("6666"); + } + rsHeatMap.add(heatMapDTO); + } + + return distrinList(rsHeatMap); + } + + //������������ + private void getHeatMap(List<HeatMapDTO> heatMap,String type) { + //������������ + 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()); + if (type.equals("a21026")){ + heatMapDTO.setCount(1.0); + }else { + 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); +// double rsCode = asDouble - (doubleArrayList.size()*10); + double rsCode = asDouble - doubleArrayList.size()-1; +// log.info(asDouble+"-----"+rsCode); +// heatMapDTO.setCount(rsCode); + heatMapDTO.setCount(rsCode); +// heatMapDTO.setSum(asDouble); + heatMapDTO.setLng(centerPoint.getLongitude()); + heatMapDTO.setLat(centerPoint.getLatitude()); + heatMapDTO.setMac(i+""); + heatMapDTO.setName(integer+""); + heatMap.add(heatMapDTO); + i++; + } + } + } + /** * ������������ * @param responseList @@ -463,8 +616,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 3a8f5f1..39de26e 100644 --- a/screen-api/src/main/resources/mapper/DeviceMapper.xml +++ b/screen-api/src/main/resources/mapper/DeviceMapper.xml @@ -216,7 +216,7 @@ d.latitude as lat, d.longitude as lng, d.name as name, - (hd.value ->> '$.a34002' )+0 as count, + (hd.value ->> #{type} ) as count, hd.time FROM device as d @@ -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