| | |
| | | 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; |
| | |
| | | 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) { |
| | | //取参 |
| | |
| | | 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)) { |
| | |
| | | } |
| | | 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; |
| | | } |
| | | |
| | | /** |
| | | * 热力图显示 |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<HeatMapDTO> getHeatMapDataV2(Integer id, String startTime, String type, String form) { |
| | | public List<HeatMapDTO> getHeatMapDataV2(Integer id, String startTime, String type, String form,Integer monitorId) { |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | map.put("start",startTime); |
| | | map.put("type","$."+ type); |
| | | map.put("monitorId",monitorId); |
| | | ArrayList<Integer> list = new ArrayList<>(); |
| | | list.add(id); |
| | | ArrayList<HeatMapDTO> rsHeatMap = new ArrayList<>(); |
| | |
| | | rsHeatMap.add(heatMapDTO); |
| | | } |
| | | } |
| | | if (id==73){ |
| | | |
| | | if (!ObjectUtils.isEmpty(monitorId)){ |
| | | if (monitorId==117){ |
| | | double lat =33.35001; |
| | | double lng =120.142939; |
| | | for (int i = 0; i <24 ; 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+"10"+j); |
| | | rsHeatMap.add(heatMapDTO); |
| | | lng=lng+0.0021; |
| | | if (j==19){ |
| | | lng=120.142939; |
| | | } |
| | | } |
| | | lat =lat-0.0011; |
| | | } |
| | | } else if (monitorId==118){ |
| | | double lat =33.375618; |
| | | double lng =120.14271; |
| | | for (int i = 0; i <24 ; i++) { |
| | | for (int j = 0; j < 17; j++) { |
| | | HeatMapDTO heatMapDTO = new HeatMapDTO(); |
| | | heatMapDTO.setCount(0.0); |
| | | heatMapDTO.setLat(lat); |
| | | heatMapDTO.setLng(lng); |
| | | heatMapDTO.setName("1"); |
| | | heatMapDTO.setMac(i+"10"+j); |
| | | rsHeatMap.add(heatMapDTO); |
| | | lng=lng+0.0021; |
| | | if (j==16){ |
| | | lng=120.14271; |
| | | } |
| | | } |
| | | lat =lat-0.0011; |
| | | } |
| | | } else if (monitorId==120){ |
| | | double lat =33.410581; |
| | | double lng =120.108739; |
| | | for (int i = 0; i <21 ; i++) { |
| | | for (int j = 0; j < 15; j++) { |
| | | HeatMapDTO heatMapDTO = new HeatMapDTO(); |
| | | heatMapDTO.setCount(0.0); |
| | | heatMapDTO.setLat(lat); |
| | | heatMapDTO.setLng(lng); |
| | | heatMapDTO.setName("1"); |
| | | heatMapDTO.setMac(i+"10"+j); |
| | | rsHeatMap.add(heatMapDTO); |
| | | lng=lng+0.0021; |
| | | if (j==14){ |
| | | lng=120.108739; |
| | | } |
| | | } |
| | | lat =lat-0.001; |
| | | } |
| | | }else if (monitorId==121){ |
| | | double lat =33.398466; |
| | | double lng =120.153462; |
| | | for (int i = 0; i <13 ; i++) { |
| | | for (int j = 0; j < 16; j++) { |
| | | HeatMapDTO heatMapDTO = new HeatMapDTO(); |
| | | heatMapDTO.setCount(0.0); |
| | | heatMapDTO.setLat(lat); |
| | | heatMapDTO.setLng(lng); |
| | | heatMapDTO.setName("1"); |
| | | heatMapDTO.setMac(i+"10"+j); |
| | | rsHeatMap.add(heatMapDTO); |
| | | lng=lng+0.00085; |
| | | if (j==15){ |
| | | lng=120.153462; |
| | | } |
| | | } |
| | | lat =lat-0.001; |
| | | } |
| | | }else if (monitorId==122){ |
| | | double lat =33.210894; |
| | | double lng =120.424509; |
| | | for (int i = 0; i <15 ; i++) { |
| | | for (int j = 0; j < 9; j++) { |
| | | HeatMapDTO heatMapDTO = new HeatMapDTO(); |
| | | heatMapDTO.setCount(0.0); |
| | | heatMapDTO.setLat(lat); |
| | | heatMapDTO.setLng(lng); |
| | | heatMapDTO.setName("1"); |
| | | heatMapDTO.setMac(i+"10"+j); |
| | | rsHeatMap.add(heatMapDTO); |
| | | lng=lng+0.0021; |
| | | if (j==8){ |
| | | lng=120.424509; |
| | | } |
| | | } |
| | | lat =lat-0.001; |
| | | } |
| | | }else if (monitorId==119){ |
| | | double lat =33.384755; |
| | | double lng =120.20625; |
| | | for (int i = 0; i <14 ; i++) { |
| | | for (int j = 0; j < 12; j++) { |
| | | HeatMapDTO heatMapDTO = new HeatMapDTO(); |
| | | heatMapDTO.setCount(0.0); |
| | | heatMapDTO.setLat(lat); |
| | | heatMapDTO.setLng(lng); |
| | | heatMapDTO.setName("1"); |
| | | heatMapDTO.setMac(i+"10"+j); |
| | | rsHeatMap.add(heatMapDTO); |
| | | lng=lng+0.0021; |
| | | if (j==11){ |
| | | lng=120.20625; |
| | | } |
| | | } |
| | | lat =lat-0.001; |
| | | } |
| | | } |
| | | } |
| | | /* if (id==73){ |
| | | //亭湖区 |
| | | double lat =33.414538; |
| | | double lng =120.066616; |
| | |
| | | } |
| | | lat1 =lat1-0.0022; |
| | | } |
| | | } |
| | | }*/ |
| | | return distrinList(rsHeatMap); |
| | | } |
| | | |
| | |
| | | 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()); |
| | | if (heatMapDTOS.size()>1){ |
| | | 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); |
| | | } |
| | | if (type.equals("a21026")){ |
| | | heatMapDTO.setCount(1.0); |
| | | }else { |
| | | heatMapDTO.setCount(0.0); |
| | | } |
| | | |
| | | geoCoordinate.setLongitude(heatMapDTO.getLng()); |
| | | geoCoordinate.setLatitude(heatMapDTO.getLat()); |
| | | geoCoordinates.add(geoCoordinate); |
| | | geoCoordinate.setLongitude(heatMapDTO.getLng()); |
| | | geoCoordinate.setLatitude(heatMapDTO.getLat()); |
| | | geoCoordinates.add(geoCoordinate); |
| | | } |
| | | } |
| | | if (!ObjectUtils.isEmpty(doubleArrayList)){ |
| | | if (!ObjectUtils.isEmpty(doubleArrayList) &&doubleArrayList.size()>1){ |
| | | HeatMapDTO heatMapDTO = new HeatMapDTO(); |
| | | //计算均值集合 |
| | | double asDouble = doubleArrayList.stream().mapToDouble(Double::valueOf).max().getAsDouble(); |
| | |
| | | dto.setComIndex(comIndex); |
| | | }); |
| | | } |
| | | |
| | | private boolean subStr(String mac){ |
| | | if(StringUtils.isNotEmpty(mac)&&mac.contains(",avg")){ |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | } |
| | | |