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

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 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<WarningData> 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<WarningData> data = json.getJSONArray("data").toJavaList(WarningData.class);
@ -207,14 +208,13 @@ public class WarningController {
List<WarningListVo> 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<WarningHistoryListVo> getCount(List<WarningData> data) {
List<WarningHistoryListVo> respList = Lists.newArrayList();
List<WarningData.Warning> warnList = Lists.newArrayList();
for (WarningData datum : data) {
WarningHistoryListVo vo = new WarningHistoryListVo();
vo.setWarnSignalType("全部");
vo.setEffectArea(datum.getEffectArea());
List<WarningHistoryListVo> child = Lists.newArrayList();
for (WarningData.TypeList typeList : datum.getTypeList()) {
// 预警类型
List<WarningData.Warning> warnList = typeList.getWarnList();
// 地区分组
Map<String, List<WarningData.Warning>> area = warnList.stream()
.collect(Collectors.groupingBy(WarningData.Warning::getEffectArea, Collectors.toList()));
area.forEach((areaStr, areaV) -> {
List<WarningHistoryListVo> countyChild = Lists.newArrayList();
WarningHistoryListVo childVo = new WarningHistoryListVo();
childVo.setWarnSignalType("全部");
childVo.setEffectArea(areaStr);
// 类型分组
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()
.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<String, List<WarningData.Warning>> warnMap = warnList.stream()
.collect(Collectors
.groupingBy(WarningData.Warning::getPublishUnit, Collectors.toList()));
List<WarningHistoryListVo> respList = Lists.newArrayList();
warnMap.forEach((k,v) ->{
WarningHistoryListVo vo = new WarningHistoryListVo();
vo.setEffectArea(k.split("气象")[0]);
// 类型
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, Long> 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());
}
}