| New file |
| | |
| | | package cn.gistack.alerts.alarmRule.service.impl; |
| | | |
| | | import cn.gistack.alerts.alarmRule.DTO.WaterQueryDTO; |
| | | import cn.gistack.alerts.alarmRule.entity.FsRAtmtnFrcstInf; |
| | | import cn.gistack.alerts.alarmRule.mapper.FsRAtmtnFrcstInfMapper; |
| | | import cn.gistack.alerts.alarmRule.service.FsRAtmtnFrcstService; |
| | | import cn.gistack.alerts.alarmRule.vo.*; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
| | | import com.fasterxml.jackson.core.JsonProcessingException; |
| | | import com.fasterxml.jackson.databind.JsonNode; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.StopWatch; |
| | | |
| | | import java.io.InputStream; |
| | | import java.net.URI; |
| | | import java.net.http.HttpClient; |
| | | import java.net.http.HttpRequest; |
| | | import java.net.http.HttpResponse; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.Duration; |
| | | import java.time.Instant; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | | @Slf4j |
| | | public class FsRAtmtnFrcstServiceImpl implements FsRAtmtnFrcstService { |
| | | @Autowired |
| | | private FsRAtmtnFrcstInfMapper fsRAtmtnFrcstInfMapper; |
| | | |
| | | private static final ObjectMapper objectMapper = new ObjectMapper(); |
| | | |
| | | private static final String apikey = "F1DBECD719108635189480CF60E6553ADB3109616426BD537F25A430DFC613B491A025C4A51E77FD08C6E5B7CBE05917A461286E7B6D69F1AB1B14F946149D2065B0C675F8FEDF4B9B05C1496881BC5A"; |
| | | private static final String cookie = "userobj=%7B%22_id%22%3A%225adfd17ddd000ba4188c53e0%22%2C%22name%22%3A%22%E9%98%B2%E6%B1%9B%E5%80%BC%E7%8F%AD%22%2C%22phone%22%3A%2213612345678%22%2C%22utype%22%3A0%2C%22dept%22%3A%22%E7%9C%81%E6%B0%B4%E5%88%A9%E5%8E%85%22%2C%22tm%22%3A%222018-04-25T00%3A53%3A17.147Z%22%2C%22token%22%3A%224e30701b3ac0996c60569e7f4c65ca5d%22%2C%22chkc%22%3Afalse%2C%22ywjk%22%3Afalse%2C%22yywh%22%3Afalse%7D"; |
| | | |
| | | private static final HttpClient client = HttpClient.newHttpClient(); |
| | | @Override |
| | | public Object getAtmtnInfo(String STCM, Integer type) { |
| | | StopWatch stopWatch = new StopWatch(); |
| | | stopWatch.start("查询预报信息"); |
| | | List<String> stcds = new ArrayList<>(); |
| | | if (StringUtils.isNotBlank(STCM)){ |
| | | stcds = fsRAtmtnFrcstInfMapper.getStcdS(STCM); |
| | | } |
| | | List<FsRAtmtnFrcstInfVO> atmtnInfo = new ArrayList<>(); |
| | | List<FsRAtmtnFrcstInfVO> result = new ArrayList<>(); |
| | | if (type==1){ |
| | | atmtnInfo = fsRAtmtnFrcstInfMapper.getAtmtnInfo(type,stcds); |
| | | }else if (type==2){ |
| | | atmtnInfo = fsRAtmtnFrcstInfMapper.getAtmtnInfo1(type,stcds); |
| | | } |
| | | Map<String, List<FsRAtmtnFrcstInfVO>> map = atmtnInfo.stream().filter(s->s.getSTCD()!=null).collect(Collectors.groupingBy(FsRAtmtnFrcstInf::getSTCD)); |
| | | if (!map.isEmpty()){ |
| | | for (Map.Entry<String, List<FsRAtmtnFrcstInfVO>> entry : map.entrySet()) { |
| | | List<FsRAtmtnFrcstInfVO> value = entry.getValue(); |
| | | List<FsRAtmtnFrcstDtVO> dtVOList = value.stream().map(s -> FsRAtmtnFrcstDtVO.builder().TM(s.getTM()).TZ(s.getTZ()).TQ(s.getTQ()).build()).collect(Collectors.toList()); |
| | | FsRAtmtnFrcstInfVO fsRAtmtnFrcstInfVO = value.get(0); |
| | | fsRAtmtnFrcstInfVO.setFrcstDtVOS(dtVOList); |
| | | result.add(fsRAtmtnFrcstInfVO); |
| | | } |
| | | } |
| | | stopWatch.stop(); |
| | | stopWatch.start("查询站点信息"); |
| | | List<String> STCDs = result.stream().map(FsRAtmtnFrcstInf::getSTCD).collect(Collectors.toList()); |
| | | List<StStbprpBVO> stationInfos = fsRAtmtnFrcstInfMapper.getStationInfo(STCDs); |
| | | stopWatch.stop(); |
| | | stopWatch.start("封装数据"); |
| | | Map<String, StStbprpBVO> stationMap = stationInfos.stream().collect(Collectors.toMap(StStbprpBVO::getSTCD, bvo -> bvo, (oldValue, newValue) -> oldValue)); // 合并函数:如果键冲突,选择保留哪个值(这里保留旧值) |
| | | if (CollectionUtils.isNotEmpty(result)){ |
| | | for (FsRAtmtnFrcstInfVO infVO : result) { |
| | | StStbprpBVO bvo = stationMap.get(infVO.getSTCD()); |
| | | if (Objects.nonNull(bvo)){ |
| | | infVO.setGRZ(bvo.getGRZ()); |
| | | infVO.setRVNM(bvo.getRVNM()==null?null: bvo.getRVNM().replaceAll(" ","")); |
| | | infVO.setSTNM(bvo.getSTNM()==null?null:bvo.getSTNM().replaceAll(" ","")); |
| | | infVO.setWRZ(bvo.getWRZ()); |
| | | infVO.setFSLTDZ(bvo.getFSLTDZ()); |
| | | infVO.setSFLZ(bvo.getSFLZ()); |
| | | } |
| | | for (FsRAtmtnFrcstDtVO dtVO : infVO.getFrcstDtVOS()) { |
| | | List<FsRAtmtnFrcstDtDeatilVO> list = new ArrayList<>(); |
| | | list.add(new FsRAtmtnFrcstDtDeatilVO("水位", dtVO.getTZ()==0?null:dtVO.getTZ().toString())); |
| | | list.add(new FsRAtmtnFrcstDtDeatilVO("流量", dtVO.getTQ()==0?null:dtVO.getTQ().toString())); |
| | | dtVO.setList(list); |
| | | } |
| | | } |
| | | } |
| | | stopWatch.stop(); |
| | | log.info(stopWatch.prettyPrint()); |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public List<WarningTypeVO> warningStatistics() { |
| | | List<WarningTypeVO> result = new ArrayList<>(); |
| | | StopWatch stopWatch = new StopWatch(); |
| | | stopWatch.start("水库统计"); |
| | | //水库统计 |
| | | Map<String,String> map = new HashMap<>(); |
| | | map.put("name","apikey"); |
| | | map.put("value",apikey); |
| | | JsonNode jsonNode = doRequest("GET", "https://sk.hubeishuiyi.cn/services/1234567890ABCDEFGHIJKLMN/res_over_flpr_des_rain/api", map, null); |
| | | JsonNode shuikuNode = jsonNode.get("data").get("data"); |
| | | List<WarningTypeVO> shuikuChild = new ArrayList<>(); |
| | | for (JsonNode node : shuikuNode) { |
| | | String overType = String.valueOf(node.get("over_type")); |
| | | shuikuChild.add(WarningTypeVO.builder().warningType(overType.substring(1, overType.length() - 1)).warningNum(String.valueOf(node.get("over_number"))).build()); |
| | | } |
| | | WarningTypeVO shuiku = WarningTypeVO.builder().warningType("水库").childList(shuikuChild).warningNum(String.valueOf(shuikuChild.stream().mapToInt(s -> Integer.parseInt(s.getWarningNum())).sum())).build(); |
| | | for (WarningTypeVO vo : shuikuChild) { |
| | | if (vo.getWarningType().equals("超设计洪水位")||vo.getWarningType().equals("超防洪高水位")){ |
| | | shuiku.setColor("红色"); |
| | | }else if (vo.getWarningType().equals("暴雨")){ |
| | | shuiku.setColor("黄色"); |
| | | } |
| | | } |
| | | result.add(shuiku); |
| | | stopWatch.stop(); |
| | | |
| | | stopWatch.start("水文统计"); |
| | | //水文统计 |
| | | List<WarningTypeVO> shuiziyuanChild = new ArrayList<>(); |
| | | JsonNode jsonNode1 = doRequest("GET", "https://hfc.mwr.cn/warn-release-api/api/warninfo.custom/4MTAOTM1MzEyQHFxLmNvbQ==", new HashMap<>(), null); |
| | | JsonNode data = jsonNode1.get("Data"); |
| | | List<WarningColorVO> hsChild = new ArrayList<>(); |
| | | List<WarningColorVO> ghChild = new ArrayList<>(); |
| | | for (JsonNode datum : data) { |
| | | String wrType = datum.get("WRType").toString(); |
| | | wrType = wrType.substring(1,wrType.length()-1); |
| | | String WRLevel = datum.get("WRLevel").toString(); |
| | | WRLevel = WRLevel.substring(1,WRLevel.length()-1); |
| | | if (wrType.equals("洪水")){ |
| | | hsChild.add(WarningColorVO.builder().colorName(WRLevel).build()); |
| | | }else { |
| | | ghChild.add(WarningColorVO.builder().colorName(WRLevel).build()); |
| | | } |
| | | } |
| | | WarningTypeVO hs = WarningTypeVO.builder().warningType("洪水预警").warningNum(String.valueOf(hsChild.size())).build(); |
| | | List<WarningColorVO> totals = hsChild.stream() |
| | | .collect(Collectors.groupingBy(WarningColorVO::getColorName, Collectors.counting())) |
| | | .entrySet().stream() |
| | | .map(entry -> new WarningColorVO(entry.getKey(), Math.toIntExact(entry.getValue()))) |
| | | .collect(Collectors.toList()); |
| | | hs.setColorVOList(totals); |
| | | |
| | | WarningTypeVO gh = WarningTypeVO.builder().warningType("干旱预警").warningNum(String.valueOf(ghChild.size())).build(); |
| | | List<WarningColorVO> totals1 = ghChild.stream() |
| | | .collect(Collectors.groupingBy(WarningColorVO::getColorName, Collectors.counting())) |
| | | .entrySet().stream() |
| | | .map(entry -> new WarningColorVO(entry.getKey(), Math.toIntExact(entry.getValue()))) |
| | | .collect(Collectors.toList()); |
| | | gh.setColorVOList(totals1); |
| | | shuiziyuanChild.add(hs); |
| | | shuiziyuanChild.add(gh); |
| | | WarningTypeVO shuiwen = WarningTypeVO.builder().warningType("水文").childList(shuiziyuanChild).warningNum(String.valueOf(shuiziyuanChild.stream().mapToInt(s -> Integer.parseInt(s.getWarningNum())).sum())).build(); |
| | | totals.addAll(totals1); |
| | | if (CollectionUtils.isNotEmpty(totals)){ |
| | | for (WarningColorVO vo : totals) { |
| | | String colorName = vo.getColorName(); |
| | | if (colorName.equals("红色")){ |
| | | shuiwen.setColor("红色"); |
| | | }else if (colorName.equals("橙色")){ |
| | | shuiwen.setColor("橙色"); |
| | | }else if (colorName.equals("黄色")){ |
| | | shuiwen.setColor("黄色"); |
| | | }else if (colorName.equals("蓝色")){ |
| | | shuiwen.setColor("蓝色"); |
| | | } |
| | | } |
| | | } |
| | | result.add(shuiwen); |
| | | stopWatch.stop(); |
| | | |
| | | stopWatch.start("山洪"); |
| | | //山洪 |
| | | List<WarningTypeVO> shList = new ArrayList<>(); |
| | | Map<String,String> map1 = new HashMap<>(); |
| | | map1.put("name","cookie"); |
| | | map1.put("value",cookie); |
| | | Date date = new Date(); |
| | | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH"); |
| | | String time = format.format(date); |
| | | String type = "sh"; |
| | | JsonNode jsonNode2 = doRequest("GET", "https://sk.hubeishuiyi.cn/contourcale/hour6?tm="+time+"&type="+type, map1, null); |
| | | JsonNode results = jsonNode2.get("results"); |
| | | int cnt = 0,wb = 0,nb = 0; |
| | | for (JsonNode node : results) { |
| | | JsonNode warnmap = node.get("warnmap"); |
| | | if (warnmap!=null){ |
| | | Iterator<JsonNode> elements = warnmap.elements(); |
| | | JsonNode jsonNode3 = elements.next(); |
| | | String cnt1 = jsonNode3.get("cnt").toString(); |
| | | cnt += Integer.parseInt(cnt1); |
| | | |
| | | String nbcnt1 = jsonNode3.get("nbcnt").toString(); |
| | | nb += Integer.parseInt(nbcnt1); |
| | | |
| | | String wbcnt1 = jsonNode3.get("wbcnt").toString(); |
| | | wb += Integer.parseInt(wbcnt1); |
| | | } |
| | | } |
| | | shList.add(WarningTypeVO.builder().warningType("总数").warningNum(String.valueOf(cnt)).build()); |
| | | shList.add(WarningTypeVO.builder().warningType("内部预警").warningNum(String.valueOf(nb)).build()); |
| | | shList.add(WarningTypeVO.builder().warningType("外部预警").warningNum(String.valueOf(wb)).build()); |
| | | WarningTypeVO shanhong = WarningTypeVO.builder().warningType("山洪").childList(shList).warningNum(String.valueOf(cnt)).build(); |
| | | if (wb>0){ |
| | | shanhong.setColor("红色"); |
| | | }else if (nb>0){ |
| | | shanhong.setColor("黄色"); |
| | | } |
| | | result.add(shanhong); |
| | | stopWatch.stop(); |
| | | |
| | | stopWatch.start("生态激流"); |
| | | //水资源 |
| | | //生态激流 |
| | | SimpleDateFormat dateFormat1 = new SimpleDateFormat("yyyy"); |
| | | String format1 = format.format(date); |
| | | String format2 = dateFormat1.format(date); |
| | | List<WarningTypeVO> szyList = new ArrayList<>(); |
| | | String dtBgTm = format2+"-01-01 00:00:00"; |
| | | String dtEdTm = format1+" 23:59:59"; |
| | | JsonNode jsonNode3 = doRequest("GET", "http://113.57.190.43:31700/api-szy-0.0.1/api/szy/v0.1/stjl/statis/b/queryBaseFlowList?addvcd=42", new HashMap<>(), null); |
| | | JsonNode result1 = jsonNode3.get("result"); |
| | | int red = 0 , blue = 0; |
| | | for (JsonNode node : result1) { |
| | | if (node.get("Q")!=null){ |
| | | String s = node.get("Q").toString(); |
| | | if (!s.equals("null")){ |
| | | String base_flow = node.get("BASE_FLOW").toString(); |
| | | String blue_alert = node.get("WATER_LEVEL_BLUE_ALERT").toString(); |
| | | double q = Double.parseDouble(s); |
| | | double flow = Double.parseDouble(base_flow.equals("null")?"0":base_flow.substring(1,base_flow.length()-1)); |
| | | double alert = Double.parseDouble(blue_alert.equals("null")?"0":blue_alert.substring(1,blue_alert.length()-1)); |
| | | if (q<flow){ |
| | | red++; |
| | | }else if (q<alert){ |
| | | blue++; |
| | | } |
| | | } |
| | | }else { |
| | | String z = node.get("Z").toString(); |
| | | if (!z.equals("null")){ |
| | | String water_level = node.get("WATER_LEVEL").toString(); |
| | | String blueAlert = node.get("WATER_LEVEL_BLUE_ALERT").toString(); |
| | | double Z = Double.parseDouble(z.substring(1,z.length()-1)); |
| | | double level = Double.parseDouble(water_level.equals("null")?"0": water_level.substring(1,water_level.length()-1)); |
| | | double alert = Double.parseDouble(blueAlert.equals("null")?"0": blueAlert.substring(1,blueAlert.length()-1)); |
| | | if (Z>0){ |
| | | if (Z>level){ |
| | | red++; |
| | | }else if (Z>alert){ |
| | | blue++; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | List<WarningColorVO> stjl = new ArrayList<>(); |
| | | stjl.add(WarningColorVO.builder().colorName("红色").colorWarningNum(red).build()); |
| | | stjl.add(WarningColorVO.builder().colorName("蓝色").colorWarningNum(blue).build()); |
| | | szyList.add(WarningTypeVO.builder().warningNum(String.valueOf(red+blue)).colorVOList(stjl).warningType("河湖断面生态流量").build()); |
| | | stopWatch.stop(); |
| | | |
| | | stopWatch.start("水量"); |
| | | //水量 |
| | | WaterQueryDTO queryDTO = WaterQueryDTO.builder().wiustTp("1").adlCd("42").tsBgTm(format2+"-01-01 00:00:00").tsEdTm(format1+" 00:00:00").build(); |
| | | int red1 = 0 , or = 0,blue1 = 0; |
| | | try { |
| | | String s = objectMapper.writeValueAsString(queryDTO); |
| | | JsonNode jsonNode4 = doRequest("POST", "http://113.57.190.43:31700/api-szy-0.0.1/api/szy/v0.1/wr/wiu/b/list", new HashMap<>(), s); |
| | | JsonNode result2 = jsonNode4.get("result"); |
| | | for (JsonNode node : result2) { |
| | | String ratio = node.get("RATIO").toString(); |
| | | double r = Double.parseDouble(ratio.equals("null") ? "0" : ratio); |
| | | if (r>1){ |
| | | red1++; |
| | | }else if (r>0.9&& r<=1){ |
| | | or++; |
| | | }else if (r>0.8&& r<=0.9){ |
| | | blue1++; |
| | | } |
| | | } |
| | | } catch (JsonProcessingException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | List<WarningColorVO> sl = new ArrayList<>(); |
| | | sl.add(WarningColorVO.builder().colorName("红色").colorWarningNum(red1).build()); |
| | | sl.add(WarningColorVO.builder().colorName("橙色").colorWarningNum(or).build()); |
| | | sl.add(WarningColorVO.builder().colorName("蓝色").colorWarningNum(blue1).build()); |
| | | szyList.add(WarningTypeVO.builder().warningNum(String.valueOf(red1+or+blue1)).colorVOList(sl).warningType("水量").build()); |
| | | stopWatch.stop(); |
| | | System.out.println(stopWatch.prettyPrint()); |
| | | WarningTypeVO shuiziyuan = WarningTypeVO.builder().warningType("水资源").childList(szyList).warningNum(String.valueOf(cnt)).build(); |
| | | result.add(shuiziyuan); |
| | | if (red1>0||red>0){ |
| | | shuiziyuan.setColor("红色"); |
| | | }else if (or>0){ |
| | | shuiziyuan.setColor("橙色"); |
| | | }else if (blue1>0||blue>0){ |
| | | shuiziyuan.setColor("蓝色"); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public WarningTypeVO warningStatisticsSK() { |
| | | StopWatch stopWatch = new StopWatch(); |
| | | //水库统计 |
| | | Map<String,String> map = new HashMap<>(); |
| | | map.put("name","apikey"); |
| | | map.put("value",apikey); |
| | | stopWatch.start("调用水库远程接口"); |
| | | JsonNode jsonNode = doRequest("GET", "https://sk.hubeishuiyi.cn/services/1234567890ABCDEFGHIJKLMN/res_over_flpr_des_rain/api", map, null); |
| | | stopWatch.stop(); |
| | | stopWatch.start("封装水库统计数据"); |
| | | JsonNode shuikuNode = jsonNode.get("data").get("data"); |
| | | List<WarningTypeVO> shuikuChild = new ArrayList<>(); |
| | | int typeNum = 0; |
| | | for (JsonNode node : shuikuNode) { |
| | | String overType = String.valueOf(node.get("over_type")); |
| | | JsonNode overNumber = node.get("over_number"); |
| | | if (overNumber!=null){ |
| | | if (Integer.parseInt(overNumber.toString())>0){ |
| | | typeNum++; |
| | | }; |
| | | } |
| | | shuikuChild.add(WarningTypeVO.builder().warningType(overType.substring(1, overType.length() - 1)).warningNum(String.valueOf(node.get("over_number"))).build()); |
| | | } |
| | | WarningTypeVO shuiku = WarningTypeVO.builder().warningType("水库").childList(shuikuChild).warningNum(String.valueOf(shuikuChild.stream().mapToInt(s -> Integer.parseInt(s.getWarningNum())).sum())).build(); |
| | | for (WarningTypeVO vo : shuikuChild) { |
| | | if (vo.getWarningType().equals("超设计洪水位")||vo.getWarningType().equals("超防洪高水位")){ |
| | | shuiku.setColor("红色"); |
| | | }else if (vo.getWarningType().equals("暴雨")){ |
| | | shuiku.setColor("黄色"); |
| | | } |
| | | } |
| | | shuiku.setTypeNum(String.valueOf(typeNum) ); |
| | | stopWatch.stop(); |
| | | log.info(stopWatch.prettyPrint()); |
| | | return shuiku; |
| | | } |
| | | |
| | | @Override |
| | | public WarningTypeVO warningStatisticsSW() { |
| | | //水文统计 |
| | | List<WarningTypeVO> shuiziyuanChild = new ArrayList<>(); |
| | | JsonNode jsonNode1 = doRequest("GET", "https://hfc.mwr.cn/warn-release-api/api/warninfo.custom/4MTAOTM1MzEyQHFxLmNvbQ==", new HashMap<>(), null); |
| | | JsonNode data = jsonNode1.get("Data"); |
| | | List<WarningColorVO> hsChild = new ArrayList<>(); |
| | | List<WarningColorVO> ghChild = new ArrayList<>(); |
| | | for (JsonNode datum : data) { |
| | | String wrType = datum.get("WRType").toString(); |
| | | wrType = wrType.substring(1,wrType.length()-1); |
| | | String WRLevel = datum.get("WRLevel").toString(); |
| | | WRLevel = WRLevel.substring(1,WRLevel.length()-1); |
| | | if (wrType.equals("洪水")){ |
| | | hsChild.add(WarningColorVO.builder().colorName(WRLevel).build()); |
| | | }else { |
| | | ghChild.add(WarningColorVO.builder().colorName(WRLevel).build()); |
| | | } |
| | | } |
| | | WarningTypeVO hs = WarningTypeVO.builder().warningType("洪水预警").warningNum(String.valueOf(hsChild.size())).build(); |
| | | List<WarningColorVO> totals = hsChild.stream() |
| | | .collect(Collectors.groupingBy(WarningColorVO::getColorName, Collectors.counting())) |
| | | .entrySet().stream() |
| | | .map(entry -> new WarningColorVO(entry.getKey(), Math.toIntExact(entry.getValue()))) |
| | | .collect(Collectors.toList()); |
| | | hs.setColorVOList(totals); |
| | | |
| | | WarningTypeVO gh = WarningTypeVO.builder().warningType("干旱预警").warningNum(String.valueOf(ghChild.size())).build(); |
| | | List<WarningColorVO> totals1 = ghChild.stream() |
| | | .collect(Collectors.groupingBy(WarningColorVO::getColorName, Collectors.counting())) |
| | | .entrySet().stream() |
| | | .map(entry -> new WarningColorVO(entry.getKey(), Math.toIntExact(entry.getValue()))) |
| | | .collect(Collectors.toList()); |
| | | gh.setColorVOList(totals1); |
| | | shuiziyuanChild.add(hs); |
| | | shuiziyuanChild.add(gh); |
| | | WarningTypeVO shuiwen = WarningTypeVO.builder().warningType("水文").childList(shuiziyuanChild).warningNum(String.valueOf(shuiziyuanChild.stream().mapToInt(s -> Integer.parseInt(s.getWarningNum())).sum())).build(); |
| | | totals.addAll(totals1); |
| | | if (CollectionUtils.isNotEmpty(totals)){ |
| | | for (WarningColorVO vo : totals) { |
| | | String colorName = vo.getColorName(); |
| | | if (colorName.equals("红色")){ |
| | | shuiwen.setColor("红色"); |
| | | }else if (colorName.equals("橙色")){ |
| | | shuiwen.setColor("橙色"); |
| | | }else if (colorName.equals("黄色")){ |
| | | shuiwen.setColor("黄色"); |
| | | }else if (colorName.equals("蓝色")){ |
| | | shuiwen.setColor("蓝色"); |
| | | } |
| | | } |
| | | } |
| | | shuiwen.setTypeNum(shuiwen.getWarningNum()); |
| | | return shuiwen; |
| | | } |
| | | |
| | | @Override |
| | | public WarningTypeVO warningStatisticsSH() { |
| | | List<WarningTypeVO> shList = new ArrayList<>(); |
| | | Map<String,String> map1 = new HashMap<>(); |
| | | map1.put("name","cookie"); |
| | | map1.put("value",cookie); |
| | | Date date = new Date(); |
| | | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH"); |
| | | String time = format.format(date); |
| | | String type = "sh"; |
| | | JsonNode jsonNode2 = doRequest("GET", "https://sk.hubeishuiyi.cn/contourcale/hour6?tm="+time+"&type="+type, map1, null); |
| | | JsonNode results = jsonNode2.get("results"); |
| | | int cnt = 0,wb = 0,nb = 0; |
| | | for (JsonNode node : results) { |
| | | JsonNode warnmap = node.get("warnmap"); |
| | | if (warnmap!=null){ |
| | | Iterator<JsonNode> elements = warnmap.elements(); |
| | | JsonNode jsonNode3 = elements.next(); |
| | | String cnt1 = jsonNode3.get("cnt").toString(); |
| | | cnt += Integer.parseInt(cnt1); |
| | | |
| | | String nbcnt1 = jsonNode3.get("nbcnt").toString(); |
| | | nb += Integer.parseInt(nbcnt1); |
| | | |
| | | String wbcnt1 = jsonNode3.get("wbcnt").toString(); |
| | | wb += Integer.parseInt(wbcnt1); |
| | | } |
| | | } |
| | | shList.add(WarningTypeVO.builder().warningType("总数").warningNum(String.valueOf(cnt)).build()); |
| | | shList.add(WarningTypeVO.builder().warningType("内部预警").warningNum(String.valueOf(nb)).build()); |
| | | shList.add(WarningTypeVO.builder().warningType("外部预警").warningNum(String.valueOf(wb)).build()); |
| | | WarningTypeVO shanhong = WarningTypeVO.builder().warningType("山洪").childList(shList).warningNum(String.valueOf(cnt)).build(); |
| | | if (wb>0){ |
| | | shanhong.setColor("红色"); |
| | | }else if (nb>0){ |
| | | shanhong.setColor("黄色"); |
| | | } |
| | | shanhong.setTypeNum(shanhong.getWarningNum()); |
| | | return shanhong; |
| | | } |
| | | |
| | | @Override |
| | | public WarningTypeVO warningStatisticsSZY() { |
| | | StopWatch stopWatch = new StopWatch(); |
| | | //水资源 |
| | | //生态激流 |
| | | Date date = new Date(); |
| | | SimpleDateFormat dateFormat1 = new SimpleDateFormat("yyyy"); |
| | | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); |
| | | String format1 = format.format(date); |
| | | String format2 = dateFormat1.format(date); |
| | | List<WarningTypeVO> szyList = new ArrayList<>(); |
| | | String dtBgTm = format2+"-01-01 00:00:00"; |
| | | String dtEdTm = format1+" 23:59:59"; |
| | | stopWatch.start("调用生态激流接口"); |
| | | JsonNode jsonNode3 = doRequest("GET", "http://113.57.190.43:31700/api-szy-0.0.1/api/szy/v0.1/stjl/statis/b/queryBaseFlowList?addvcd=42", new HashMap<>(), null); |
| | | stopWatch.stop(); |
| | | stopWatch.start("封装生态激流数据"); |
| | | JsonNode result1 = jsonNode3.get("result"); |
| | | int red = 0 , blue = 0; |
| | | for (JsonNode node : result1) { |
| | | if (node.get("Q")!=null){ |
| | | String s = node.get("Q").toString(); |
| | | if (!s.equals("null")){ |
| | | String base_flow = node.get("BASE_FLOW").toString(); |
| | | String blue_alert = node.get("WATER_LEVEL_BLUE_ALERT").toString(); |
| | | float q = Float.parseFloat(s); |
| | | float flow = Float.parseFloat(base_flow.equals("null")?"0":base_flow.substring(1,base_flow.length()-1)); |
| | | float alert = Float.parseFloat(blue_alert.equals("null")?"0":blue_alert.substring(1,blue_alert.length()-1)); |
| | | if (q>=0&&q<flow){ |
| | | red++; |
| | | }else if (q<alert){ |
| | | blue++; |
| | | } |
| | | } |
| | | }else { |
| | | String z = node.get("Z").toString(); |
| | | if (!z.equals("null")){ |
| | | String water_level = node.get("WATER_LEVEL").toString(); |
| | | String blueAlert = node.get("WATER_LEVEL_BLUE_ALERT").toString(); |
| | | float Z = Float.parseFloat(z.substring(1,z.length()-1)); |
| | | float level = Float.parseFloat(water_level.equals("null")?"0": water_level.substring(1,water_level.length()-1)); |
| | | float alert = Float.parseFloat(blueAlert.equals("null")?"0": blueAlert.substring(1,blueAlert.length()-1)); |
| | | if (Z>=0){ |
| | | if (Z>level){ |
| | | red++; |
| | | }else if (Z>alert){ |
| | | blue++; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | List<WarningColorVO> stjl = new ArrayList<>(); |
| | | stjl.add(WarningColorVO.builder().colorName("红色").colorWarningNum(red).build()); |
| | | stjl.add(WarningColorVO.builder().colorName("蓝色").colorWarningNum(blue).build()); |
| | | szyList.add(WarningTypeVO.builder().warningNum(String.valueOf(red+blue)).colorVOList(stjl).warningType("河湖断面生态流量").build()); |
| | | int typeNum = 0; |
| | | if (red>0||blue>0){ |
| | | typeNum += 1; |
| | | } |
| | | stopWatch.stop(); |
| | | //水量 |
| | | WaterQueryDTO queryDTO = WaterQueryDTO.builder().wiustTp("1").adlCd("42").tsBgTm(format2+"-01-01 00:00:00").tsEdTm(format1+" 00:00:00").build(); |
| | | int red1 = 0 , or = 0,blue1 = 0; |
| | | try { |
| | | String s = objectMapper.writeValueAsString(queryDTO); |
| | | stopWatch.start("调用水量接口"); |
| | | JsonNode jsonNode4 = doRequest("POST", "http://113.57.190.43:31700/api-szy-0.0.1/api/szy/v0.1/wr/wiu/b/list", new HashMap<>(), s); |
| | | stopWatch.stop(); |
| | | stopWatch.start("封装水量数据"); |
| | | JsonNode result2 = jsonNode4.get("result"); |
| | | for (JsonNode node : result2) { |
| | | String ratio = node.get("RATIO").toString(); |
| | | double r = Double.parseDouble(ratio.equals("null") ? "0" : ratio); |
| | | if (r>1){ |
| | | red1++; |
| | | }else if (r>0.9&& r<=1){ |
| | | or++; |
| | | }else if (r>0.8&& r<=0.9){ |
| | | blue1++; |
| | | } |
| | | } |
| | | } catch (JsonProcessingException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | List<WarningColorVO> sl = new ArrayList<>(); |
| | | sl.add(WarningColorVO.builder().colorName("红色").colorWarningNum(red1).build()); |
| | | sl.add(WarningColorVO.builder().colorName("橙色").colorWarningNum(or).build()); |
| | | sl.add(WarningColorVO.builder().colorName("蓝色").colorWarningNum(blue1).build()); |
| | | szyList.add(WarningTypeVO.builder().warningNum(String.valueOf(red1+or+blue1)).colorVOList(sl).warningType("水量").build()); |
| | | WarningTypeVO shuiziyuan = WarningTypeVO.builder().warningType("水资源").childList(szyList).warningNum(String.valueOf(red1+or+blue1+red+blue)).build(); |
| | | if (red1>0||blue1>0||or>0){ |
| | | typeNum += 1; |
| | | } |
| | | if (red1>0||red>0){ |
| | | shuiziyuan.setColor("红色"); |
| | | }else if (or>0){ |
| | | shuiziyuan.setColor("橙色"); |
| | | }else if (blue1>0||blue>0){ |
| | | shuiziyuan.setColor("蓝色"); |
| | | } |
| | | shuiziyuan.setTypeNum(String.valueOf(typeNum)); |
| | | stopWatch.stop(); |
| | | log.info(stopWatch.prettyPrint()); |
| | | return shuiziyuan; |
| | | } |
| | | |
| | | @Override |
| | | public Object countAtmtnInfo() { |
| | | Map<String,String> map = new HashMap<>(); |
| | | List<FsRAtmtnFrcstInfVO> atmtnInfo = fsRAtmtnFrcstInfMapper.getAtmtnInfo1(null, null); |
| | | // atmtnInfo.addAll(fsRAtmtnFrcstInfMapper.getAtmtnInfo1(null,null)); |
| | | List<String> STCDs = atmtnInfo.stream().map(FsRAtmtnFrcstInf::getSTCD).collect(Collectors.toList()); |
| | | List<StStbprpBVO> stationInfos = fsRAtmtnFrcstInfMapper.getStationInfo(STCDs); |
| | | Map<String, StStbprpBVO> stationMap = stationInfos.stream().collect(Collectors.toMap(StStbprpBVO::getSTCD, bvo -> bvo, (oldValue, newValue) -> oldValue)); |
| | | Integer num = 0; |
| | | if (CollectionUtils.isNotEmpty(atmtnInfo)){ |
| | | for (FsRAtmtnFrcstInfVO vo : atmtnInfo) { |
| | | StStbprpBVO stbprpBVO = stationMap.get(vo.getSTCD()); |
| | | if (vo.getTQ()> Float.parseFloat(stbprpBVO.getWRZ()) ){ |
| | | num++; |
| | | } |
| | | } |
| | | } |
| | | map.put("warningNum",String.valueOf(num)); |
| | | if (num>0){ |
| | | map.put("color","红色"); |
| | | }else { |
| | | map.put("color",""); |
| | | } |
| | | return map; |
| | | } |
| | | |
| | | /** |
| | | *处理远程请求 |
| | | */ |
| | | private static JsonNode doRequest(String method,String url,Map<String,String> headerParam,String param) { |
| | | HttpRequest.Builder builder = HttpRequest.newBuilder(); |
| | | if (method.equals("GET")){ |
| | | builder.GET(); |
| | | }else { |
| | | builder.POST(HttpRequest.BodyPublishers.ofString(param)); |
| | | } |
| | | builder.uri(URI.create(url)) |
| | | .header("Accept", "application/json").header("Content-Type","application/json"); |
| | | if (!headerParam.isEmpty()){ |
| | | builder.header(headerParam.get("name"),headerParam.get("value")); |
| | | } |
| | | try { |
| | | Instant requestS = Instant.now(); |
| | | HttpResponse<InputStream> response = client.send(builder.build(), HttpResponse.BodyHandlers.ofInputStream()); |
| | | Instant requestE= Instant.now(); |
| | | long requestTime = Duration.between(requestS, requestE).toMillis(); |
| | | log.info("请求时长为: " + requestTime + " milliseconds"); |
| | | Instant writeDataS = Instant.now(); |
| | | JsonNode jsonNode = objectMapper.readTree(response.body()); |
| | | Instant writeDataE = Instant.now(); |
| | | long writeDataTime = Duration.between(writeDataS, writeDataE).toMillis(); |
| | | log.info("接受数据时长: " + writeDataTime + " milliseconds"); |
| | | return jsonNode; |
| | | } catch (Exception e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | } |