diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/response/WarnMonthAlarmsResponseInfo.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/response/WarnMonthAlarmsResponseInfo.java index 1a5ad1c..e1ed4b9 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/response/WarnMonthAlarmsResponseInfo.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/response/WarnMonthAlarmsResponseInfo.java @@ -17,7 +17,7 @@ * 统计告警月份相关信息 */ @ApiModelProperty(value = "告警月份") - private String warnMonth; + private Integer warnMonth; /** * 统计告警站点 diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/response/WarnMonthAlarmsResponseInfo.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/response/WarnMonthAlarmsResponseInfo.java index 1a5ad1c..e1ed4b9 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/response/WarnMonthAlarmsResponseInfo.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/response/WarnMonthAlarmsResponseInfo.java @@ -17,7 +17,7 @@ * 统计告警月份相关信息 */ @ApiModelProperty(value = "告警月份") - private String warnMonth; + private Integer warnMonth; /** * 统计告警站点 diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/StatisticsServiceImpl.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/StatisticsServiceImpl.java index 42cc14b..81d206c 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/StatisticsServiceImpl.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/StatisticsServiceImpl.java @@ -226,15 +226,15 @@ .map(WarnMonthAlarmsResponseInfo::getWarnNumber) .collect(Collectors.toList())); warnMonthAlarmsResponse.setProjectCode(request.getProjectCode()); - Map monthCounts = new TreeMap<>(); + Map monthCounts = new TreeMap<>(); long totalSnCount = 0; for (WarnMonthAlarmsResponseInfo info : warnMonthAlarmsResponseInfoList) { // String key = info.getWarnYear() + "-" + info.getWarnMonth(); - String key = info.getWarnMonth(); + Integer key = info.getWarnMonth(); monthCounts.merge(key, info.getWarnNumber(), Long::sum); totalSnCount += info.getWarnNumber(); } - List> sortedEntries = new ArrayList<>(monthCounts.entrySet()); + List> sortedEntries = new ArrayList<>(monthCounts.entrySet()); sortedEntries.sort(Map.Entry.comparingByValue(Comparator.reverseOrder())); if (sortedEntries.size() >= 2) { long sumOfTopTwo = sortedEntries.get(0).getValue() + sortedEntries.get(1).getValue(); @@ -249,13 +249,20 @@ warnMonthAlarmsResponse.setDeviceCountProportion(percentage.doubleValue()); } warnMonthAlarmsResponse.setWarnDeviceCount(sumOfTopTwo); - warnMonthAlarmsResponse.setEndMonth(sortedEntries.get(1).getKey()); - warnMonthAlarmsResponse.setMaxStartMonth(sortedEntries.get(0).getKey()); + //对排序后的告警月份做判断,小的月份在前 + if(sortedEntries.get(0).getKey() monthCounts = new TreeMap<>(); + Map monthCounts = new TreeMap<>(); long totalSnCount = 0; for (WarnMonthAlarmsResponseInfo info : warnMonthAlarmsResponseInfoList) { // String key = info.getWarnYear() + "-" + info.getWarnMonth(); - String key = info.getWarnMonth(); + Integer key = info.getWarnMonth(); monthCounts.merge(key, info.getWarnNumber(), Long::sum); totalSnCount += info.getWarnNumber(); } - List> sortedEntries = new ArrayList<>(monthCounts.entrySet()); + List> sortedEntries = new ArrayList<>(monthCounts.entrySet()); sortedEntries.sort(Map.Entry.comparingByValue(Comparator.reverseOrder())); if (sortedEntries.size() >= 2) { long sumOfTopTwo = sortedEntries.get(0).getValue() + sortedEntries.get(1).getValue(); @@ -249,13 +249,20 @@ warnMonthAlarmsResponse.setDeviceCountProportion(percentage.doubleValue()); } warnMonthAlarmsResponse.setWarnDeviceCount(sumOfTopTwo); - warnMonthAlarmsResponse.setEndMonth(sortedEntries.get(1).getKey()); - warnMonthAlarmsResponse.setMaxStartMonth(sortedEntries.get(0).getKey()); + //对排序后的告警月份做判断,小的月份在前 + if(sortedEntries.get(0).getKey() SELECT - di.sn, - di.location, - DATE_FORMAT(MIN(di.first_warn_datetime), '%Y-%m-%d') AS dailyFirstWarnDatetime, + di_min.sn, + di_min.location, + di_min.dailyFirstWarnDatetime, COUNT(DISTINCT DATE(dm.date)) AS countDays FROM - ter_device_info di - INNER JOIN - ter_monitoring_warn_record dm ON di.sn = dm.sn - WHERE - di.project_code = #{projectCode} + (SELECT + sn, + location, + MIN(first_warn_datetime) AS dailyFirstWarnDatetime + FROM + ter_device_info + WHERE + project_code = #{projectCode} + GROUP BY + sn, + location + ) AS di_min + INNER JOIN + ter_monitoring_warn_record dm ON di_min.sn = dm.sn AND dm.date >= di_min.dailyFirstWarnDatetime GROUP BY - di.sn, - di.first_warn_datetime + di_min.sn, + di_min.location, + di_min.dailyFirstWarnDatetime ORDER BY - countDays DESC, - di.sn; + countDays DESC, + di_min.sn; diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/response/WarnMonthAlarmsResponseInfo.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/response/WarnMonthAlarmsResponseInfo.java index 1a5ad1c..e1ed4b9 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/response/WarnMonthAlarmsResponseInfo.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/response/WarnMonthAlarmsResponseInfo.java @@ -17,7 +17,7 @@ * 统计告警月份相关信息 */ @ApiModelProperty(value = "告警月份") - private String warnMonth; + private Integer warnMonth; /** * 统计告警站点 diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/StatisticsServiceImpl.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/StatisticsServiceImpl.java index 42cc14b..81d206c 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/StatisticsServiceImpl.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/StatisticsServiceImpl.java @@ -226,15 +226,15 @@ .map(WarnMonthAlarmsResponseInfo::getWarnNumber) .collect(Collectors.toList())); warnMonthAlarmsResponse.setProjectCode(request.getProjectCode()); - Map monthCounts = new TreeMap<>(); + Map monthCounts = new TreeMap<>(); long totalSnCount = 0; for (WarnMonthAlarmsResponseInfo info : warnMonthAlarmsResponseInfoList) { // String key = info.getWarnYear() + "-" + info.getWarnMonth(); - String key = info.getWarnMonth(); + Integer key = info.getWarnMonth(); monthCounts.merge(key, info.getWarnNumber(), Long::sum); totalSnCount += info.getWarnNumber(); } - List> sortedEntries = new ArrayList<>(monthCounts.entrySet()); + List> sortedEntries = new ArrayList<>(monthCounts.entrySet()); sortedEntries.sort(Map.Entry.comparingByValue(Comparator.reverseOrder())); if (sortedEntries.size() >= 2) { long sumOfTopTwo = sortedEntries.get(0).getValue() + sortedEntries.get(1).getValue(); @@ -249,13 +249,20 @@ warnMonthAlarmsResponse.setDeviceCountProportion(percentage.doubleValue()); } warnMonthAlarmsResponse.setWarnDeviceCount(sumOfTopTwo); - warnMonthAlarmsResponse.setEndMonth(sortedEntries.get(1).getKey()); - warnMonthAlarmsResponse.setMaxStartMonth(sortedEntries.get(0).getKey()); + //对排序后的告警月份做判断,小的月份在前 + if(sortedEntries.get(0).getKey() SELECT - di.sn, - di.location, - DATE_FORMAT(MIN(di.first_warn_datetime), '%Y-%m-%d') AS dailyFirstWarnDatetime, + di_min.sn, + di_min.location, + di_min.dailyFirstWarnDatetime, COUNT(DISTINCT DATE(dm.date)) AS countDays FROM - ter_device_info di - INNER JOIN - ter_monitoring_warn_record dm ON di.sn = dm.sn - WHERE - di.project_code = #{projectCode} + (SELECT + sn, + location, + MIN(first_warn_datetime) AS dailyFirstWarnDatetime + FROM + ter_device_info + WHERE + project_code = #{projectCode} + GROUP BY + sn, + location + ) AS di_min + INNER JOIN + ter_monitoring_warn_record dm ON di_min.sn = dm.sn AND dm.date >= di_min.dailyFirstWarnDatetime GROUP BY - di.sn, - di.first_warn_datetime + di_min.sn, + di_min.location, + di_min.dailyFirstWarnDatetime ORDER BY - countDays DESC, - di.sn; + countDays DESC, + di_min.sn; diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/resources/mapper/termite/MonitoringWarnRecordMapper.xml b/newfiber-termites/newfiber-termites-dataup/src/main/resources/mapper/termite/MonitoringWarnRecordMapper.xml index 3cdc137..fc813d9 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/resources/mapper/termite/MonitoringWarnRecordMapper.xml +++ b/newfiber-termites/newfiber-termites-dataup/src/main/resources/mapper/termite/MonitoringWarnRecordMapper.xml @@ -113,7 +113,7 @@ di.project_code AS projectCode, YEAR(t.date) AS warnYear, MONTH(t.date) AS warnMonth, - COUNT(*) AS warnNumber + COUNT(DISTINCT t.sn) AS warnNumber FROM ter_monitoring_warn_record t INNER JOIN