气象预警查询修改,历史气象预警统计修改

master
徐杰盟 2024-05-27 17:00:03 +08:00
parent 7b52312207
commit 618785d8fe
1 changed files with 61 additions and 75 deletions

View File

@ -24,6 +24,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -110,8 +111,8 @@ public class WarningController {
} }
apiDto.setFilter(filter); 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://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://127.0.0.1:20000/shzh/met/zyqxfw/api/warning/getGroupWarning", JSON.toJSONString(apiDto));
JSONObject json = JSON.parseObject(str); JSONObject json = JSON.parseObject(str);
if (json != null && json.getInteger("code") == HttpStatus.SC_OK) { if (json != null && json.getInteger("code") == HttpStatus.SC_OK) {
List<WarningData> data = json.getJSONArray("data").toJavaList(WarningData.class); List<WarningData> data = json.getJSONArray("data").toJavaList(WarningData.class);
@ -186,8 +187,8 @@ public class WarningController {
apiDto.setFilter(filter); 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://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://127.0.0.1:20000/shzh/met/zyqxfw/api/warning/getGroupWarning", JSON.toJSONString(apiDto));
JSONObject json = JSON.parseObject(str); JSONObject json = JSON.parseObject(str);
if (json != null && json.getInteger("code") == HttpStatus.SC_OK) { if (json != null && json.getInteger("code") == HttpStatus.SC_OK) {
List<WarningData> data = json.getJSONArray("data").toJavaList(WarningData.class); List<WarningData> data = json.getJSONArray("data").toJavaList(WarningData.class);
@ -207,14 +208,13 @@ public class WarningController {
List<WarningListVo> respList = Lists.newArrayList(); List<WarningListVo> respList = Lists.newArrayList();
for (WarningData datum : data) { for (WarningData datum : data) {
String effectArea = datum.getEffectArea();
for (WarningData.TypeList typeList : datum.getTypeList()) { for (WarningData.TypeList typeList : datum.getTypeList()) {
// 预警类型 // 预警类型
String type = typeList.getType(); String type = typeList.getType();
for (WarningData.Warning warning : typeList.getWarnList()) { for (WarningData.Warning warning : typeList.getWarnList()) {
WarningListVo vo = new WarningListVo(); WarningListVo vo = new WarningListVo();
String publishUnit = warning.getPublishUnit(); String publishUnit = warning.getPublishUnit();
vo.setTitle(effectArea + publishUnit + "发布" + type + "预警"); vo.setTitle(publishUnit + "发布" + type + "预警");
vo.setPublishTime(warning.getPublishTime()); vo.setPublishTime(warning.getPublishTime());
vo.setContent(warning.getContent()); vo.setContent(warning.getContent());
vo.setWarnSignalType(warning.getWarnSignalType()); vo.setWarnSignalType(warning.getWarnSignalType());
@ -236,82 +236,68 @@ public class WarningController {
*/ */
private List<WarningHistoryListVo> getCount(List<WarningData> data) { private List<WarningHistoryListVo> getCount(List<WarningData> data) {
List<WarningHistoryListVo> respList = Lists.newArrayList(); List<WarningData.Warning> warnList = Lists.newArrayList();
for (WarningData datum : data) { for (WarningData datum : data) {
WarningHistoryListVo vo = new WarningHistoryListVo(); WarningHistoryListVo vo = new WarningHistoryListVo();
vo.setWarnSignalType("全部"); vo.setWarnSignalType("全部");
vo.setEffectArea(datum.getEffectArea());
List<WarningHistoryListVo> child = Lists.newArrayList();
for (WarningData.TypeList typeList : datum.getTypeList()) { for (WarningData.TypeList typeList : datum.getTypeList()) {
// 预警类型 warnList.addAll(typeList.getWarnList());
}
}
List<WarningData.Warning> warnList = typeList.getWarnList(); Map<String, List<WarningData.Warning>> warnMap = warnList.stream()
.collect(Collectors
.groupingBy(WarningData.Warning::getPublishUnit, Collectors.toList()));
// 地区分组 List<WarningHistoryListVo> respList = Lists.newArrayList();
Map<String, List<WarningData.Warning>> area = warnList.stream()
.collect(Collectors.groupingBy(WarningData.Warning::getEffectArea, Collectors.toList()));
area.forEach((areaStr, areaV) -> { warnMap.forEach((k,v) ->{
List<WarningHistoryListVo> countyChild = Lists.newArrayList(); WarningHistoryListVo vo = new WarningHistoryListVo();
WarningHistoryListVo childVo = new WarningHistoryListVo(); vo.setEffectArea(k.split("气象")[0]);
childVo.setWarnSignalType("全部");
childVo.setEffectArea(areaStr); // 类型
Map<String, List<WarningData.Warning>> types = v.stream()
.collect(Collectors
.groupingBy(WarningData.Warning::getWarnSignalType, Collectors.toList()));
types.forEach((kt,vt) ->{
WarningHistoryListVo voType = new WarningHistoryListVo();
voType.setWarnSignalType(kt);
// 类型分组
Map<String, List<WarningData.Warning>> types = area.get(areaStr).stream()
.collect(Collectors.groupingBy(WarningData.Warning::getEffectArea, Collectors.toList()));
types.forEach((k, v) -> {
WarningHistoryListVo county = new WarningHistoryListVo();
// 等级分组 // 等级分组
Map<String, Long> levels = v.stream() Map<String, Long> levels = vt.stream()
.collect(Collectors.groupingBy(WarningData.Warning::getWarnSignalLevel, Collectors.counting())); .collect(Collectors.groupingBy(WarningData.Warning::getWarnSignalLevel, Collectors.counting()));
levels.forEach((k1, v1) -> { levels.forEach((k1, v1) -> {
switch (k1) { switch (k1) {
case "红色": case "红色":
county.setRedCount(v1.intValue()); voType.setRedCount(v1.intValue());
childVo.setRedCount(v1.intValue() + childVo.getRedCount());
vo.setRedCount(v1.intValue() + vo.getRedCount()); vo.setRedCount(v1.intValue() + vo.getRedCount());
break; break;
case "橙色": case "橙色":
county.setOraCount(v1.intValue()); voType.setOraCount(v1.intValue());
childVo.setOraCount(v1.intValue() + childVo.getOraCount());
vo.setOraCount(v1.intValue() + vo.getOraCount()); vo.setOraCount(v1.intValue() + vo.getOraCount());
break; break;
case "黄色": case "黄色":
county.setYelCount(v1.intValue()); voType.setYelCount(v1.intValue());
childVo.setYelCount(v1.intValue() + childVo.getYelCount());
vo.setYelCount(v1.intValue() + vo.getYelCount()); vo.setYelCount(v1.intValue() + vo.getYelCount());
break; break;
case "蓝色": case "蓝色":
county.setBluCount(v1.intValue()); voType.setBluCount(v1.intValue());
childVo.setBluCount(v1.intValue() + childVo.getBluCount());
vo.setBluCount(v1.intValue() + vo.getBluCount()); vo.setBluCount(v1.intValue() + vo.getBluCount());
break; break;
default: default:
throw new MyException("当前预警等级不存在: " + k1); throw new MyException("当前预警等级不存在: " + k1);
} }
}); });
county.setWarnSignalType(k);
county.setSumCount(levels.size());
countyChild.add(county);
}); });
vo.setSumCount(v.size());
childVo.setSumCount(areaV.size());
childVo.setChild(countyChild);
vo.setSumCount(vo.getSumCount() + areaV.size());
child.add(childVo);
});
}
vo.setSumCount(datum.getTypeList().size());
vo.setChild(child);
respList.add(vo); respList.add(vo);
});
return respList.stream().sorted(Comparator.comparing(WarningHistoryListVo::getSumCount).reversed()).collect(Collectors.toList());
} }
return respList;
}
} }