| | |
| | | import com.moral.api.entity.*; |
| | | import com.moral.api.mapper.DeviceMapper; |
| | | import com.moral.api.mapper.HistoryMonthlyMapper; |
| | | import com.moral.api.mapper.OrganizationMapper; |
| | | import com.moral.api.pojo.dto.dataDisplay.HeatMapDTO; |
| | | import com.moral.api.pojo.dto.dataDisplay.MonitorPointDataDisplayDTO; |
| | | 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; |
| | | import com.moral.util.*; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.ObjectUtils; |
| | | |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static com.moral.util.DateUtils.dateToDateString; |
| | | |
| | | /** |
| | | * @ClassName DataDisplayServiceImpl |
| | |
| | | * @Version TODO |
| | | **/ |
| | | @Service |
| | | @Slf4j |
| | | public class DataDisplayServiceImpl implements DataDisplayService { |
| | | |
| | | @Autowired |
| | |
| | | HistoryWeeklyService historyWeeklyService; |
| | | @Autowired |
| | | HistoryMonthlyService historyMonthlyService; |
| | | @Autowired |
| | | OrganizationMapper organizationMapper; |
| | | |
| | | @Autowired |
| | | DeviceMapper deviceMapper; |
| | |
| | | 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)) { |
| | |
| | | dtos.add(dto); |
| | | } |
| | | 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; |
| | | } |
| | | |
| | | /** |
| | | * 热力图显示 |
| | | * @param code |
| | | * @param startTime |
| | | * @param type |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<HeatMapDTO> getHeatMapData(String code, 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<>(); |
| | | |
| | | // 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); |
| | | // for (Integer integer : list) { |
| | | map.put("organizationIds",list); |
| | | map.put("tableName",tableNames.get(0)); |
| | | // List<Map<String, Object>> heatMap = deviceMapper.getHeatMap(map); |
| | | List<HeatMapDTO> heatMap = deviceMapper.getHeatMap(map); |
| | | rsHeatMap.addAll(heatMap); |
| | | // } |
| | | |
| | | }else { //天 |
| | | // for (Integer integer : list) { |
| | | map.put("organizationIds",list); |
| | | // List<Map<String, Object>> heatMap = deviceMapper.getHeatMap(map); |
| | | List<HeatMapDTO> heatMap = deviceMapper.getHeatMap(map); |
| | | rsHeatMap.addAll(heatMap); |
| | | // } |
| | | } |
| | | |
| | | return distrinList(rsHeatMap); |
| | | } |
| | | |
| | | @Override |
| | | 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<>(); |
| | | /* 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); |
| | | } |
| | | 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 (!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; |
| | | 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,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); |
| | | 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); |
| | | } |
| | | |
| | | geoCoordinate.setLongitude(heatMapDTO.getLng()); |
| | | geoCoordinate.setLatitude(heatMapDTO.getLat()); |
| | | geoCoordinates.add(geoCoordinate); |
| | | } |
| | | } |
| | | if (!ObjectUtils.isEmpty(doubleArrayList) &&doubleArrayList.size()>1){ |
| | | 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 |
| | | * @return |
| | | */ |
| | | private List<HeatMapDTO> distrinList(List<HeatMapDTO> responseList){ |
| | | List<HeatMapDTO> rsMap = new ArrayList<>(); |
| | | Set<String> keysSet = new HashSet<String>(); |
| | | for (HeatMapDTO heatMapDTO : responseList) { |
| | | String keys = String.valueOf(heatMapDTO.getMac()); |
| | | int beforeSize = keysSet.size(); |
| | | keysSet.add(keys); |
| | | int afterSize = keysSet.size(); |
| | | if(afterSize == beforeSize + 1){ |
| | | rsMap.add(heatMapDTO); |
| | | } |
| | | } |
| | | return rsMap; |
| | | |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | dto.setComIndex(comIndex); |
| | | }); |
| | | } |
| | | |
| | | private boolean subStr(String mac){ |
| | | if(StringUtils.isNotEmpty(mac)&&mac.contains(",avg")){ |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | } |
| | | |