| | |
| | | return dtos; |
| | | } |
| | | |
| | | @Override |
| | | public List<SensorComparisonDisplayDTO> getSensorComparisonDisplayDataV2(Map<String, Object> params) { |
| | | //取参 |
| | | List<String> sensors = (List<String>) params.get("sensorCodes"); |
| | | /*Date startDate = form.getStartDate(); |
| | | Date endDate = form.getEndDate();*/ |
| | | //所选时间 |
| | | List<String> times = (List<String>) params.get("times"); |
| | | String startTime = times.get(0); |
| | | String endTime = times.get(1); |
| | | String mac = params.get("mac").toString(); |
| | | String reportType = params.get("reportType").toString(); |
| | | Map<String, String> timeValueMap = new LinkedHashMap<>();//key为time,value为数据的json |
| | | //处理小时数据 |
| | | if (reportType.equals(Constants.HOURLY_REPORT)) { |
| | | Date startDate = DateUtils.getDate(startTime,DateUtils.yyyy_MM_dd_HH_EN); |
| | | Date endDate = DateUtils.getDate(endTime,DateUtils.yyyy_MM_dd_HH_EN); |
| | | List<HistoryHourly> hourlies = historyHourlyService.getValueByMacAndTime(mac, startDate, endDate); |
| | | for (HistoryHourly historyHourly : hourlies) { |
| | | Date time = historyHourly.getTime(); |
| | | String dateStr = DateUtils.dateToDateString(time, "yyyy-MM-dd HH"); |
| | | String value = historyHourly.getValue(); |
| | | timeValueMap.put(dateStr, value); |
| | | } |
| | | //补上无数据时间 |
| | | Date middleDate = startDate; |
| | | while (DateUtils.compareDateStr(DateUtils.dateToDateString(endDate,DateUtils.yyyy_MM_dd_HH_EN),DateUtils.dateToDateString(middleDate,DateUtils.yyyy_MM_dd_HH_EN),DateUtils.yyyy_MM_dd_HH_EN)<=0){ |
| | | if (timeValueMap.get(DateUtils.dateToDateString(middleDate,DateUtils.yyyy_MM_dd_HH_EN)) == null) |
| | | timeValueMap.put(DateUtils.dateToDateString(middleDate,DateUtils.yyyy_MM_dd_HH_EN), null); |
| | | middleDate = DateUtils.addHours(middleDate,1); |
| | | } |
| | | } |
| | | //处理日数据 |
| | | else if (reportType.equals(Constants.DAILY_REPORT)) { |
| | | Date startDate = DateUtils.getDate(startTime,DateUtils.yyyy_MM_dd_EN); |
| | | Date endDate = DateUtils.getDate(endTime,DateUtils.yyyy_MM_dd_EN); |
| | | List<HistoryDaily> dailies = historyDailyService.getHistoryDailyByMacAndTimeSlot(mac, startDate, endDate); |
| | | for (HistoryDaily historyDaily : dailies) { |
| | | Date time = historyDaily.getTime(); |
| | | String dateStr = DateUtils.dateToDateString(time, "yyyy-MM-dd"); |
| | | String value = historyDaily.getValue(); |
| | | timeValueMap.put(String.valueOf(dateStr), value); |
| | | } |
| | | //补上无数据时间 |
| | | Date middleDate = startDate; |
| | | while (DateUtils.compareDateStr(DateUtils.dateToDateString(endDate,DateUtils.yyyy_MM_dd_EN),DateUtils.dateToDateString(middleDate,DateUtils.yyyy_MM_dd_EN),DateUtils.yyyy_MM_dd_EN)<=0){ |
| | | if (timeValueMap.get(DateUtils.dateToDateString(middleDate,DateUtils.yyyy_MM_dd_EN)) == null) |
| | | timeValueMap.put(DateUtils.dateToDateString(middleDate,DateUtils.yyyy_MM_dd_EN), null); |
| | | middleDate = DateUtils.addDays(middleDate,1); |
| | | } |
| | | } else |
| | | return null; |
| | | //时间排序 |
| | | //timeValueMap = sortMapByTime(timeValueMap, reportType); |
| | | //封装返回数据 |
| | | List<SensorComparisonDisplayDTO> dtos = new ArrayList<>(); |
| | | for (String sensor : sensors) { |
| | | SensorComparisonDisplayDTO dto = new SensorComparisonDisplayDTO(); |
| | | List<Map<String, Object>> dtoTimeValueList = new ArrayList<>(); |
| | | dto.setSensorCode(sensor); |
| | | timeValueMap.forEach((time, valueJson) -> { |
| | | Map<String, Object> listMap = new HashMap<>(); |
| | | //如果对应时间没有数据,则放入空 |
| | | if (valueJson == null) { |
| | | listMap.put("time", time); |
| | | listMap.put("value", ""); |
| | | dtoTimeValueList.add(listMap); |
| | | return; |
| | | } |
| | | Map<String, Object> valueMap = JSON.parseObject(valueJson, Map.class); |
| | | Object sensorValueObject = valueMap.get(sensor); |
| | | //如果数据中没有该因子,则放入空 |
| | | if (sensorValueObject == null) { |
| | | listMap.put("time", time); |
| | | listMap.put("value", ""); |
| | | dtoTimeValueList.add(listMap); |
| | | return; |
| | | } |
| | | //如果是小时数据需要判断标记位 |
| | | if (reportType.equals(Constants.HOURLY_REPORT)) { |
| | | //如果标记位不为N,则放入空 |
| | | if (!Constants.NORMAL_FLAG.equals(valueMap.get(sensor + "-Flag"))) { |
| | | listMap.put("time", time); |
| | | listMap.put("value", ""); |
| | | dtoTimeValueList.add(listMap); |
| | | return; |
| | | } |
| | | } |
| | | //取出数据 |
| | | Double sensorValue = Double.parseDouble(sensorValueObject.toString()); |
| | | //封装数据 |
| | | listMap.put("time", time); |
| | | listMap.put("value", sensorValue); |
| | | dtoTimeValueList.add(listMap); |
| | | }); |
| | | Collections.sort(dtoTimeValueList, new Comparator<Map<String, Object>>() { |
| | | public int compare(Map<String, Object> o1, Map<String, Object> o2) { |
| | | String id1 = (String) o1.get("time"); |
| | | String id2 = (String) o2.get("time"); |
| | | return id1.compareTo(id2); |
| | | } |
| | | |
| | | }); |
| | | dto.setTimeValueList(dtoTimeValueList); |
| | | dtos.add(dto); |
| | | } |
| | | return dtos; |
| | | } |
| | | |
| | | /** |
| | | * @Description: 根据时间进行排序 |
| | | * @Param: [timeValueMap, reportType] |