From 65b70cf13a2ec91013d876771be878c165cae3a4 Mon Sep 17 00:00:00 2001 From: cjl <909710561@qq.com> Date: Tue, 23 Apr 2024 15:32:45 +0800 Subject: [PATCH] fix:补充提交 --- screen-api/src/main/java/com/moral/api/service/impl/DataDisplayServiceImpl.java | 365 ++++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 298 insertions(+), 67 deletions(-) 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 31f5cb1..84c58c2 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,9 +1,7 @@ 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.jhlabs.composite.AverageComposite; import com.moral.api.entity.*; import com.moral.api.mapper.DeviceMapper; import com.moral.api.mapper.HistoryMonthlyMapper; @@ -13,8 +11,10 @@ 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 com.moral.api.pojo.vo.historyMonthly.HistoryResultVo; import com.moral.api.service.*; import com.moral.api.utils.GetCenterPointFromListOfCoordinates; +import com.moral.api.utils.StringUtils; import com.moral.constant.Constants; import com.moral.constant.SeparateTableType; import com.moral.pojo.AQI; @@ -23,7 +23,6 @@ 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; @@ -253,6 +252,21 @@ return dtos; } + public static void main(String[] args) { + List<String> sensors = new ArrayList<>(); + sensors.add("a34004"); + sensors.add("a34002"); + sensors.add("a21026"); + StringBuilder str = new StringBuilder(); + for(String s : sensors){ + str.append(" avg(JSON_EXTRACT( value, '$"+s+"' )) pm,"); + } + str.deleteCharAt(str.length() - 1); + System.out.println(str.toString()); + + } + + @Override public List<SensorComparisonDisplayDTO> getSensorComparisonDisplayDataV2(Map<String, Object> params) { //������ @@ -263,31 +277,60 @@ List<String> times = (List<String>) params.get("times"); String startTime = times.get(0); String endTime = times.get(1); - String mac = params.get("mac").toString(); + boolean type = subStr(params.get("mac").toString()); + String mac = type?params.get("mac").toString().substring(0, params.get("mac").toString().indexOf(",avg")):params.get("mac").toString(); + List<String> macList = new ArrayList<>(); + if(type){ + macList = deviceService.getMacMonitorPointId(Integer.parseInt(mac)); + }else { + macList.add(mac); + } + String reportType = params.get("reportType").toString(); Map<String, String> timeValueMap = new LinkedHashMap<>();//key���time���value������������json //��������������� if (reportType.equals(Constants.MONTHLY_REPORT)) { + //������������������ + List<SensorComparisonDisplayDTO> dtos = new ArrayList<>(); + Date startDate = DateUtils.getDate(startTime,DateUtils.yyyy_MM_EN); Date endDate = DateUtils.getDate(endTime,DateUtils.yyyy_MM_EN); - //List<HistoryHourly> hourlies = historyHourlyService.getValueByMacAndTime(mac, startDate, endDate); - QueryWrapper<HistoryMonthly> historyMonthlyQueryWrapper = new QueryWrapper<>(); - historyMonthlyQueryWrapper.eq("mac",mac); - historyMonthlyQueryWrapper.between("time",startTime.substring(0,7)+"-01 00:00:00",endTime.substring(0,7)+"-01 00:00:00"); - List<HistoryMonthly> monthlies = historyMonthlyMapper.selectList(historyMonthlyQueryWrapper); - for (HistoryMonthly historyMonthly : monthlies) { - Date time = historyMonthly.getTime(); - String dateStr = DateUtils.dateToDateString(time, "yyyy-MM"); - String value = historyMonthly.getValue(); - timeValueMap.put(dateStr, value); + for(String s : sensors){ + SensorComparisonDisplayDTO dto = new SensorComparisonDisplayDTO(); + if(s.equals("a00e12") || s.equals("a00e03")){ + dto.setCode("1"); + }else if (s.equals("a01006")){ + dto.setCode("2"); + }else if (s.equals("a99054") || s.equals("a21005")){ + dto.setCode("3"); + }else { + dto.setCode("0"); + } + List<Map<String, Object>> dtoTimeValueList = new ArrayList<>(); + String str = " ROUND(avg(JSON_EXTRACT( value, '$."+s+"' )),2) value "; + List<HistoryResultVo> monthlies = historyMonthlyMapper.listAll(str.toString(),macList,startTime.substring(0,7)+"-01 00:00:00",endTime.substring(0,7)+"-01 00:00:00"); + Map<String, List<HistoryResultVo>> prodMap= monthlies.stream().collect(Collectors.groupingBy(HistoryResultVo::getTime)); + //��������������������� + Date middleDate = startDate; + while (DateUtils.compareDateStr(DateUtils.dateToDateString(endDate,DateUtils.yyyy_MM_EN),DateUtils.dateToDateString(middleDate,DateUtils.yyyy_MM_EN),DateUtils.yyyy_MM_EN)<=0){ + Map<String, Object> resultMap = new LinkedHashMap<>(); + resultMap.put("time",DateUtils.dateToDateString(middleDate,DateUtils.yyyy_MM_EN)); + if (prodMap.get(DateUtils.dateToDateString(middleDate,DateUtils.yyyy_MM_EN)) == null){ + resultMap.put("value",null); + }else { + List<HistoryResultVo> resultList = prodMap.get(DateUtils.dateToDateString(middleDate,DateUtils.yyyy_MM_EN)); + resultMap.put("value", resultList.get(0).getValue()); + } + dtoTimeValueList.add(resultMap); + middleDate = DateUtils.addMonths(middleDate,1); + } + + dto.setTimeValueList(dtoTimeValueList); + dtos.add(dto); } - //��������������������� - Date middleDate = startDate; - while (DateUtils.compareDateStr(DateUtils.dateToDateString(endDate,DateUtils.yyyy_MM_EN),DateUtils.dateToDateString(middleDate,DateUtils.yyyy_MM_EN),DateUtils.yyyy_MM_EN)<=0){ - if (timeValueMap.get(DateUtils.dateToDateString(middleDate,DateUtils.yyyy_MM_EN)) == null) - timeValueMap.put(DateUtils.dateToDateString(middleDate,DateUtils.yyyy_MM_EN), null); - middleDate = DateUtils.addMonths(middleDate,1); - } + + return dtos; + } //������������������ else if (reportType.equals(Constants.HOURLY_REPORT)) { @@ -393,6 +436,99 @@ } return dtos; } + @Override + public List<SensorComparisonDisplayDTO> getSensorComparisonDisplayDataV3(Map<String, Object> params) { + //������ + List<String> sensors = (List<String>) params.get("sensorCodes"); + //������������ + List<String> times = (List<String>) params.get("times"); + String startTime = times.get(0); + String endTime = times.get(1); + boolean type = subStr(params.get("mac").toString()); + String mac = type?params.get("mac").toString().substring(0, params.get("mac").toString().indexOf(",avg")):params.get("mac").toString(); + List<String> macList = new ArrayList<>(); + if(type){ + macList = deviceService.getMacMonitorPointId(Integer.parseInt(mac)); + }else { + macList.add(mac); + } + String reportType = params.get("reportType").toString(); + List<SensorComparisonDisplayDTO> dtos = new ArrayList<>(); + Date startDate = null; + Date endDate = null; + if (reportType.equals(Constants.MONTHLY_REPORT)) { + startDate = DateUtils.getDate(startTime,DateUtils.yyyy_MM_EN); + endDate = DateUtils.getDate(endTime,DateUtils.yyyy_MM_EN); + } else if (reportType.equals(Constants.HOURLY_REPORT)) { + startDate = DateUtils.getDate(startTime,DateUtils.yyyy_MM_dd_HH_EN); + endDate = DateUtils.getDate(endTime,DateUtils.yyyy_MM_dd_HH_EN); + } else if (reportType.equals(Constants.DAILY_REPORT)) { + startDate = DateUtils.getDate(startTime,DateUtils.yyyy_MM_dd_EN); + endDate = DateUtils.getDate(endTime,DateUtils.yyyy_MM_dd_EN); + } + for(String s : sensors){ + SensorComparisonDisplayDTO dto = new SensorComparisonDisplayDTO(); + if(s.equals("a00e12") || s.equals("a00e03")){ + dto.setCode("1"); + }else if (s.equals("a01006")){ + dto.setCode("2"); + }else if (s.equals("a99054") || s.equals("a21005")){ + dto.setCode("3"); + }else { + dto.setCode("0"); + } + List<Map<String, Object>> dtoTimeValueList = new ArrayList<>(); + String str = " ROUND(avg(JSON_EXTRACT( value, '$."+s+"' )),2) value "; + List<HistoryResultVo> historyResultVos = new ArrayList<>(); + if (reportType.equals(Constants.MONTHLY_REPORT)) { + historyResultVos = historyMonthlyMapper.listAll(str,macList,startTime.substring(0,7)+"-01 00:00:00",endTime.substring(0,7)+"-01 00:00:00"); + } else if (reportType.equals(Constants.HOURLY_REPORT)) { + historyResultVos = historyHourlyService.getAvgValueByMacAndTime(macList,str, startDate, endDate); + } else if (reportType.equals(Constants.DAILY_REPORT)) { + historyResultVos = historyDailyService.listAvgResult(str,macList,DateUtils.dateToDateString(startDate,DateUtils.yyyy_MM_dd_EN) ,DateUtils.dateToDateString(endDate,DateUtils.yyyy_MM_dd_EN) ); + } + Map<String, List<HistoryResultVo>> prodMap= historyResultVos.stream().collect(Collectors.groupingBy(HistoryResultVo::getTime)); + Date middleDate = startDate; + while(DateUtils.isTimeBeforE(endDate,middleDate)){ + Map<String, Object> resultMap = new LinkedHashMap<>(); + if (reportType.equals(Constants.MONTHLY_REPORT)) { + resultMap.put("time",DateUtils.dateToDateString(middleDate,DateUtils.yyyy_MM_EN)); + if (prodMap.get(DateUtils.dateToDateString(middleDate,DateUtils.yyyy_MM_EN)) == null){ + resultMap.put("value",null); + }else { + List<HistoryResultVo> resultList = prodMap.get(DateUtils.dateToDateString(middleDate,DateUtils.yyyy_MM_EN)); + resultMap.put("value", resultList.get(0).getValue()); + } + dtoTimeValueList.add(resultMap); + middleDate = DateUtils.addMonths(middleDate,1); + }else if(reportType.equals(Constants.HOURLY_REPORT)) { + resultMap.put("time",DateUtils.dateToDateString(middleDate,DateUtils.yyyy_MM_dd_HH_EN)); + if (prodMap.get(DateUtils.dateToDateString(middleDate,DateUtils.yyyy_MM_dd_HH_EN)) == null){ + resultMap.put("value",null); + }else { + List<HistoryResultVo> resultList = prodMap.get(DateUtils.dateToDateString(middleDate,DateUtils.yyyy_MM_dd_HH_EN)); + resultMap.put("value", resultList.get(0).getValue()); + } + dtoTimeValueList.add(resultMap); + middleDate = DateUtils.addHours(middleDate,1); + }else if(reportType.equals(Constants.DAILY_REPORT)){ + resultMap.put("time",DateUtils.dateToDateString(middleDate,DateUtils.yyyy_MM_dd_EN)); + if (prodMap.get(DateUtils.dateToDateString(middleDate,DateUtils.yyyy_MM_dd_EN)) == null){ + resultMap.put("value",null); + }else { + List<HistoryResultVo> resultList = prodMap.get(DateUtils.dateToDateString(middleDate,DateUtils.yyyy_MM_dd_EN)); + resultMap.put("value", resultList.get(0).getValue()); + } + dtoTimeValueList.add(resultMap); + middleDate = DateUtils.addDays(middleDate,1); + } + } + dto.setSensorCode(s); + dto.setTimeValueList(dtoTimeValueList); + dtos.add(dto); + } + return dtos; + } /** * ��������������� @@ -407,26 +543,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); @@ -455,45 +575,53 @@ 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<>(); +/* ArrayList<String> list1 = new ArrayList<>(); + list1.add("���������������"); + list1.add("���������������"); + list1.add("���������������"); + list1.add("���������������"); + list1.add("������������������");*/ if (form.equals("hour")){ //������ -// log.info(""+startTime); +// String[] split = startTime.split("-"); +// String s = "_" + split[0] + split[1]; 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); + 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); @@ -501,15 +629,107 @@ if (ObjectUtils.isEmpty(collect1)){ return null; } - getHeatMap(heatMap); + 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); } - + if (id==71){ + 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); + } + } + if (id==73){ + //��������� + double lat =33.414538; + double lng =120.066616; + for (int i = 0; i <11 ; i++) { + for (int j = 0; j < 20; j++) { + HeatMapDTO heatMapDTO = new HeatMapDTO(); + heatMapDTO.setCount(0.0); + heatMapDTO.setLat(lat); + heatMapDTO.setLng(lng); + heatMapDTO.setName("1"); + heatMapDTO.setMac(i+"1"+j); + rsHeatMap.add(heatMapDTO); + lng=lng+0.01; + if (j==19){ + lng=120.066616; + } + } + lat =lat-0.01; + } + //��������� + double lat1 =33.214555; + double lng1 =120.416805; + for (int i = 0; i < 11 ; i++) { + for (int j = 0; j < 10; j++) { + HeatMapDTO heatMapDTO = new HeatMapDTO(); + heatMapDTO.setCount(0.0); + heatMapDTO.setLat(lat1); + heatMapDTO.setLng(lng1); + heatMapDTO.setName("2"); + heatMapDTO.setMac(i+"2"+j); + rsHeatMap.add(heatMapDTO); + lng1=lng1+0.004; + if (j==9){ + lng1=120.416805; + } + } + lat1 =lat1-0.0022; + } + } return distrinList(rsHeatMap); } //������������ - private void getHeatMap(List<HeatMapDTO> heatMap) { + 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)){ @@ -527,8 +747,12 @@ 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); + } - heatMapDTO.setCount(0.0); geoCoordinate.setLongitude(heatMapDTO.getLng()); geoCoordinate.setLatitude(heatMapDTO.getLat()); geoCoordinates.add(geoCoordinate); @@ -539,9 +763,11 @@ 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<=0.0?0.0:rsCode); +// heatMapDTO.setCount(rsCode); + heatMapDTO.setCount(rsCode); // heatMapDTO.setSum(asDouble); heatMapDTO.setLng(centerPoint.getLongitude()); heatMapDTO.setLat(centerPoint.getLatitude()); @@ -941,6 +1167,11 @@ dto.setComIndex(comIndex); }); } - + private boolean subStr(String mac){ + if(StringUtils.isNotEmpty(mac)&&mac.contains(",avg")){ + return true; + } + return false; + } } -- Gitblit v1.8.0