diff --git a/src/main/java/com/whdc/controller/WarningController.java b/src/main/java/com/whdc/controller/WarningController.java index 313c257..a01e294 100644 --- a/src/main/java/com/whdc/controller/WarningController.java +++ b/src/main/java/com/whdc/controller/WarningController.java @@ -2,18 +2,22 @@ package com.whdc.controller; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import com.google.common.collect.Sets; import com.whdc.exception.MyException; import com.whdc.model.dto.ApiDto; import com.whdc.model.dto.GroupWarningDto; +import com.whdc.model.vo.AdcdTree; import com.whdc.model.vo.WarningData; import com.whdc.model.vo.WarningHistoryListVo; import com.whdc.model.vo.WarningListVo; import com.whdc.service.IAddressBookService; +import com.whdc.service.IAdinfoService; import com.whdc.utils.HttpUtil; import com.whdc.utils.ResultJson; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.compress.utils.Lists; import org.apache.commons.lang3.StringUtils; import org.apache.http.HttpStatus; @@ -23,10 +27,7 @@ import org.springframework.web.bind.annotation.RequestBody; 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.*; import java.util.stream.Collectors; /** @@ -46,6 +47,9 @@ public class WarningController { @Autowired private IAddressBookService addressBookService; + @Autowired + private IAdinfoService adinfoService; + /** * 气象预警 * @@ -187,8 +191,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); @@ -250,20 +254,27 @@ public class WarningController { .collect(Collectors .groupingBy(WarningData.Warning::getPublishUnit, Collectors.toList())); - List respList = Lists.newArrayList(); + List voList = Lists.newArrayList(); - warnMap.forEach((k,v) ->{ + warnMap.forEach((k, v) -> { WarningHistoryListVo vo = new WarningHistoryListVo(); vo.setEffectArea(k.split("气象")[0]); + vo.setWarnSignalType("全部"); + + + List typeList = Lists.newArrayList(); // 类型 Map> types = v.stream() .collect(Collectors .groupingBy(WarningData.Warning::getWarnSignalType, Collectors.toList())); - types.forEach((kt,vt) ->{ + + Set warnSignalType = Sets.newHashSet("雷电", "暴雨", "大风", "冰雹", "雷雨大风"); + types.forEach((kt, vt) -> { + WarningHistoryListVo voType = new WarningHistoryListVo(); voType.setWarnSignalType(kt); - + warnSignalType.remove(kt); // 等级分组 Map levels = vt.stream() .collect(Collectors.groupingBy(WarningData.Warning::getWarnSignalLevel, Collectors.counting())); @@ -290,14 +301,70 @@ public class WarningController { throw new MyException("当前预警等级不存在: " + k1); } }); - + voType.setSumCount(vt.size()); + typeList.add(voType); }); + + // 保证完整数据 + warnSignalType.forEach(kt ->{ + WarningHistoryListVo voType = new WarningHistoryListVo(); + voType.setWarnSignalType(kt); + typeList.add(voType); + }); + + vo.setChild(typeList); vo.setSumCount(v.size()); - respList.add(vo); + voList.add(vo); }); - return respList.stream().sorted(Comparator.comparing(WarningHistoryListVo::getSumCount).reversed()).collect(Collectors.toList()); + + // 进行行政区划匹配 + if (CollectionUtils.isNotEmpty(voList)) { + List tree = adinfoService.tree(null, null); + Map> areaMap = voList.stream() + .collect(Collectors + .groupingBy(WarningHistoryListVo::getEffectArea, Collectors.toList())); + + return getAdcdByWhlVo(tree, areaMap); + } + + return voList; } + private List getAdcdByWhlVo(List tree, Map> areaMap) { + List respList = Lists.newArrayList(); + + for (AdcdTree adcdTree : tree) { + String adnm = adcdTree.getAdnm(); + List children = adcdTree.getChildren(); + + List vos = areaMap.get(adnm); + if (CollectionUtils.isNotEmpty(vos)) { + WarningHistoryListVo vo = vos.get(0); + List childList = Lists.newArrayList(); + + childList.addAll(vo.getChild()); + + + if (CollectionUtils.isNotEmpty(children)) { + // 第一个是市级单位 + for (int i = 1; i < children.size(); i++) { + AdcdTree t = children.get(i); + String adnm1 = t.getAdnm(); + List vos1 = areaMap.get(adnm1); + if (CollectionUtils.isNotEmpty(vos1)) { + childList.addAll(vos1); + } + } + } + + + vo.setChild(childList); + respList.add(vo); + } + + } + return respList; + } }