From 618785d8feacd1a2cf6aed833bced4708a66dad5 Mon Sep 17 00:00:00 2001 From: xjm Date: Mon, 27 May 2024 17:00:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B0=94=E8=B1=A1=E9=A2=84=E8=AD=A6=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E4=BF=AE=E6=94=B9,=E5=8E=86=E5=8F=B2=E6=B0=94?= =?UTF-8?q?=E8=B1=A1=E9=A2=84=E8=AD=A6=E7=BB=9F=E8=AE=A1=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../whdc/controller/WarningController.java | 136 ++++++++---------- 1 file changed, 61 insertions(+), 75 deletions(-) diff --git a/src/main/java/com/whdc/controller/WarningController.java b/src/main/java/com/whdc/controller/WarningController.java index 20d3e42..313c257 100644 --- a/src/main/java/com/whdc/controller/WarningController.java +++ b/src/main/java/com/whdc/controller/WarningController.java @@ -24,6 +24,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -110,8 +111,8 @@ public class WarningController { } apiDto.setFilter(filter); - String str = HttpUtil.sendPost("http://223.75.53.141:8000/shzh/met/zyqxfw/api/warning/getGroupWarning", JSON.toJSONString(apiDto)); -// String str = HttpUtil.sendPost("http://127.0.0.1:20000/shzh/met/zyqxfw/api/warning/getGroupWarning", JSON.toJSONString(apiDto)); +// String str = HttpUtil.sendPost("http://223.75.53.141:8000/shzh/met/zyqxfw/api/warning/getGroupWarning", JSON.toJSONString(apiDto)); + String str = HttpUtil.sendPost("http://127.0.0.1:20000/shzh/met/zyqxfw/api/warning/getGroupWarning", JSON.toJSONString(apiDto)); JSONObject json = JSON.parseObject(str); if (json != null && json.getInteger("code") == HttpStatus.SC_OK) { List data = json.getJSONArray("data").toJavaList(WarningData.class); @@ -186,8 +187,8 @@ public class WarningController { apiDto.setFilter(filter); - String str = HttpUtil.sendPost("http://223.75.53.141:8000/shzh/met/zyqxfw/api/warning/getGroupWarning", JSON.toJSONString(apiDto)); -// String str = HttpUtil.sendPost("http://127.0.0.1:20000/shzh/met/zyqxfw/api/warning/getGroupWarning", JSON.toJSONString(apiDto)); +// String str = HttpUtil.sendPost("http://223.75.53.141:8000/shzh/met/zyqxfw/api/warning/getGroupWarning", JSON.toJSONString(apiDto)); + String str = HttpUtil.sendPost("http://127.0.0.1:20000/shzh/met/zyqxfw/api/warning/getGroupWarning", JSON.toJSONString(apiDto)); JSONObject json = JSON.parseObject(str); if (json != null && json.getInteger("code") == HttpStatus.SC_OK) { List data = json.getJSONArray("data").toJavaList(WarningData.class); @@ -207,14 +208,13 @@ public class WarningController { List respList = Lists.newArrayList(); for (WarningData datum : data) { - String effectArea = datum.getEffectArea(); for (WarningData.TypeList typeList : datum.getTypeList()) { // 预警类型 String type = typeList.getType(); for (WarningData.Warning warning : typeList.getWarnList()) { WarningListVo vo = new WarningListVo(); String publishUnit = warning.getPublishUnit(); - vo.setTitle(effectArea + publishUnit + "发布" + type + "预警"); + vo.setTitle(publishUnit + "发布" + type + "预警"); vo.setPublishTime(warning.getPublishTime()); vo.setContent(warning.getContent()); vo.setWarnSignalType(warning.getWarnSignalType()); @@ -236,82 +236,68 @@ public class WarningController { */ private List getCount(List data) { - List respList = Lists.newArrayList(); + List warnList = Lists.newArrayList(); for (WarningData datum : data) { WarningHistoryListVo vo = new WarningHistoryListVo(); vo.setWarnSignalType("全部"); - vo.setEffectArea(datum.getEffectArea()); - List child = Lists.newArrayList(); for (WarningData.TypeList typeList : datum.getTypeList()) { - // 预警类型 - - List warnList = typeList.getWarnList(); - - // 地区分组 - Map> area = warnList.stream() - .collect(Collectors.groupingBy(WarningData.Warning::getEffectArea, Collectors.toList())); - - area.forEach((areaStr, areaV) -> { - List countyChild = Lists.newArrayList(); - WarningHistoryListVo childVo = new WarningHistoryListVo(); - childVo.setWarnSignalType("全部"); - childVo.setEffectArea(areaStr); - - // 类型分组 - Map> types = area.get(areaStr).stream() - .collect(Collectors.groupingBy(WarningData.Warning::getEffectArea, Collectors.toList())); - types.forEach((k, v) -> { - WarningHistoryListVo county = new WarningHistoryListVo(); - // 等级分组 - Map levels = v.stream() - .collect(Collectors.groupingBy(WarningData.Warning::getWarnSignalLevel, Collectors.counting())); - - levels.forEach((k1, v1) -> { - switch (k1) { - case "红色": - county.setRedCount(v1.intValue()); - childVo.setRedCount(v1.intValue() + childVo.getRedCount()); - vo.setRedCount(v1.intValue() + vo.getRedCount()); - break; - case "橙色": - county.setOraCount(v1.intValue()); - childVo.setOraCount(v1.intValue() + childVo.getOraCount()); - vo.setOraCount(v1.intValue() + vo.getOraCount()); - break; - case "黄色": - county.setYelCount(v1.intValue()); - childVo.setYelCount(v1.intValue() + childVo.getYelCount()); - vo.setYelCount(v1.intValue() + vo.getYelCount()); - break; - case "蓝色": - county.setBluCount(v1.intValue()); - childVo.setBluCount(v1.intValue() + childVo.getBluCount()); - vo.setBluCount(v1.intValue() + vo.getBluCount()); - break; - default: - throw new MyException("当前预警等级不存在: " + k1); - } - }); - county.setWarnSignalType(k); - county.setSumCount(levels.size()); - countyChild.add(county); - }); - - childVo.setSumCount(areaV.size()); - childVo.setChild(countyChild); - vo.setSumCount(vo.getSumCount() + areaV.size()); - - child.add(childVo); - }); - + warnList.addAll(typeList.getWarnList()); } - - vo.setSumCount(datum.getTypeList().size()); - vo.setChild(child); - respList.add(vo); } - return respList; + Map> warnMap = warnList.stream() + .collect(Collectors + .groupingBy(WarningData.Warning::getPublishUnit, Collectors.toList())); + + List respList = Lists.newArrayList(); + + warnMap.forEach((k,v) ->{ + WarningHistoryListVo vo = new WarningHistoryListVo(); + vo.setEffectArea(k.split("气象")[0]); + + // 类型 + Map> types = v.stream() + .collect(Collectors + .groupingBy(WarningData.Warning::getWarnSignalType, Collectors.toList())); + types.forEach((kt,vt) ->{ + WarningHistoryListVo voType = new WarningHistoryListVo(); + voType.setWarnSignalType(kt); + + // 等级分组 + Map levels = vt.stream() + .collect(Collectors.groupingBy(WarningData.Warning::getWarnSignalLevel, Collectors.counting())); + + levels.forEach((k1, v1) -> { + switch (k1) { + case "红色": + voType.setRedCount(v1.intValue()); + vo.setRedCount(v1.intValue() + vo.getRedCount()); + break; + case "橙色": + voType.setOraCount(v1.intValue()); + vo.setOraCount(v1.intValue() + vo.getOraCount()); + break; + case "黄色": + voType.setYelCount(v1.intValue()); + vo.setYelCount(v1.intValue() + vo.getYelCount()); + break; + case "蓝色": + voType.setBluCount(v1.intValue()); + vo.setBluCount(v1.intValue() + vo.getBluCount()); + break; + default: + throw new MyException("当前预警等级不存在: " + k1); + } + }); + + + }); + vo.setSumCount(v.size()); + respList.add(vo); + }); + + return respList.stream().sorted(Comparator.comparing(WarningHistoryListVo::getSumCount).reversed()).collect(Collectors.toList()); } + }