| | |
| | | |
| | | import cn.gistack.common.utils.CommonUtil; |
| | | import cn.gistack.common.utils.SpringContextUtil; |
| | | import cn.gistack.nky.resultpojo.HsybGetFuturePo; |
| | | import cn.gistack.nky.resultpojo.*; |
| | | import cn.gistack.nky.service.IHsybService; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springblade.core.tool.utils.DateUtil; |
| | | import org.springframework.http.HttpEntity; |
| | | import org.springframework.http.HttpHeaders; |
| | | import org.springframework.http.MediaType; |
| | | import org.springblade.core.tool.utils.StringUtil; |
| | | import org.springframework.http.*; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.client.RestTemplate; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | |
| | | |
| | | private static String ONLINE = "http://10.42.7.148:50001"; |
| | | private static String LOCAL = "https://sk.hubeishuiyi.cn"; |
| | | private static String GET_FUTURE = "/hsybApi/api/fh-admin/skkr/getFuture"; |
| | | private static String GET_FUTURE_ONLINE = "/api/fh-admin/skkr/getFuture"; |
| | | private static String GET_FUTURE = "/hsybApi/api/fh-admin/skkr/getFuture"; |
| | | private static String GET_NEW_FUTURE = "/hsybApi/api/fh-admin/skkr/getSkFutureSw"; |
| | | private static String GET_FUTURE_ONLINE = "/api/fh-admin/skkr/getFuture"; |
| | | private static String GET_NEW_FUTURE_ONLINE = "/api/fh-admin/skkr/getSkFutureSw"; |
| | | |
| | | private static String AUTHORIZATION = "Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX25hbWUiOiJBRE1JTiIsIlVzZXJJZCI6IjEiLCJzY29wZSI6WyJhbGwiXSwiVXNlclJlYWxOYW1lIjoi6LaF57qn566h55CG5ZGYIiwiVXNlclh6cWhkbSI6IjQyMDUiLCJleHAiOjI1MTk3NzIwMTAsImp0aSI6ImExNTcxYzk1LTBkNjMtNDkyYi1iOWEyLTE2ZTIzNTQ5ZTY1ZiIsImNsaWVudF9pZCI6InVzZXItc2VydmljZSJ9.ebNVZrw9LbhKaj2w6RR8b2wccQiDkhvBeq79SxxCK-yWiOlIFqBkotTN4TNJg8umcpyYvLILwvqXWRJhffEtgi25sX2y6MqLIWM4kMZ9d8ptdnSmTpBPhltSiQOM0KFa1kl5nSDCBwYOLn-pESJglam76cjpgZNoC88x3iNHacdiXDItY0rtY85HrQ26uyJu9UovKtmYmZRHsIbGMpDta5Q1p4vfaCIr-YUayDrCweZJiQDEEcOSpWJ7O7RMk3pRkX_4UmPHFzrOI2lMp1jQIhxnSTE7EVAz_4z8h8r46muSkpF54Ic4XSawHKqdSLHx8T05LB0MpvOzWMPS6c1uHA"; |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public List<NewSwFuturePo> getNewFuture(String resId) { |
| | | Map<String, Object> params = new HashMap<>(); |
| | | params.put("resId", resId); |
| | | HsybGetFuturePo get = apiRequest(GET_NEW_FUTURE, "GET", params); |
| | | |
| | | //程序转为hashmap,手动转换类型 |
| | | List<NewSwFuturePo> data =JSON.parseArray(JSON.toJSONString(get.getData()), NewSwFuturePo.class); |
| | | List<NewSwFuturePo> filterData = filterPredict(data); |
| | | |
| | | log.info(StringUtil.format("过滤后的预测水位数据:{}", JSON.toJSONString(filterData))); |
| | | return filterData; |
| | | } |
| | | |
| | | private HsybGetFuturePo apiRequest(String url, String type, Map<String, Object> params) { |
| | | // 获取环境 |
| | | String activeProfile = SpringContextUtil.getActiveProfile(); |
| | | if (activeProfile.equals("dev")) { |
| | | url = LOCAL + url; |
| | | } |
| | | if (activeProfile.equals("prod")) { |
| | | url = ONLINE + GET_NEW_FUTURE_ONLINE; |
| | | } |
| | | if (activeProfile.equals("test")) { |
| | | url = ONLINE + GET_NEW_FUTURE_ONLINE; |
| | | } |
| | | |
| | | HttpMethod method; |
| | | if (type.toLowerCase().equals("get".toLowerCase())) { |
| | | method = HttpMethod.GET; |
| | | } else { |
| | | method = HttpMethod.POST; |
| | | } |
| | | // 声明一个header变量 |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | url = url + "?resId=" + params.get("resId"); |
| | | HttpEntity<String> httpEntity = new HttpEntity(null, headers); |
| | | log.info("请求地址:" + url); |
| | | log.info("请求参数:" + params); |
| | | RestTemplate template = new RestTemplate(); |
| | | ResponseEntity<HsybGetFuturePo> response = template.exchange(url, method, httpEntity, HsybGetFuturePo.class); |
| | | |
| | | if (response.getStatusCodeValue() == 200) { |
| | | return response.getBody(); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public HsybGetFuturePo apiRequest(String url, String jsonparams) { |
| | | |
| | | // 获取环境 |
| | | String activeProfile = SpringContextUtil.getActiveProfile(); |
| | | if (activeProfile.equals("dev")) { |
| | | url = LOCAL+ url ; |
| | | url = LOCAL + url; |
| | | } |
| | | if (activeProfile.equals("prod")) { |
| | | url = ONLINE+ GET_FUTURE_ONLINE ; |
| | | url = ONLINE + GET_FUTURE_ONLINE; |
| | | } |
| | | if (activeProfile.equals("test")) { |
| | | url = ONLINE + GET_FUTURE_ONLINE; |
| | |
| | | //获取等于当前时间的水位数据 |
| | | List<List<String>> collect = data.stream().filter(infoList -> infoList.get(0).equals(nowTime)).collect(Collectors.toList()); |
| | | |
| | | collect.forEach(infoList->{ |
| | | collect.forEach(infoList -> { |
| | | //给第一项重新赋值,因为后面取的是第一项,且预测参数时间只要日期 |
| | | infoList.set(0,infoList.get(4).split(" ")[0]); |
| | | infoList.set(0, infoList.get(4).split(" ")[0]); |
| | | }); |
| | | return collect; |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | // |
| | |
| | | // return distinctList; |
| | | } |
| | | |
| | | public Integer findIndex(List<List<String>> list,String reg){ |
| | | public List<NewSwFuturePo> filterPredict(List<NewSwFuturePo> list){ |
| | | |
| | | /** |
| | | * { |
| | | * "sw": "88.72", |
| | | * "time": "2024-02-01 16:00:00", |
| | | * "resId": "42092250024" |
| | | * }, |
| | | * { |
| | | * "sw": "88.72", |
| | | * "time": "2024-02-01 17:00:00", |
| | | * "resId": "42092250024" |
| | | * }, |
| | | */ |
| | | if (list.size() == 0){ |
| | | return null; |
| | | } |
| | | |
| | | //先拿第一个数据,第一个数据就是当前时间的下一个整点的预测数据 |
| | | NewSwFuturePo newSwFuturePo = list.get(0); |
| | | |
| | | //获取预测数据中,和第一条时间部分相同的数据;再筛选掉水位为0的数据 |
| | | List<NewSwFuturePo> filterList = list.stream().filter(item -> item.getTime().indexOf(newSwFuturePo.getTime().split(" ")[1]) > -1).filter(item->!item.getSw().equals("0.0")).collect(Collectors.toList()); |
| | | |
| | | //给时间重新赋值,因为南科院hst预测只需要日期 |
| | | filterList.forEach(e->{ |
| | | e.setTime(e.getTime().split(" ")[0]); |
| | | }); |
| | | |
| | | return filterList; |
| | | } |
| | | |
| | | public Integer findIndex(List<List<String>> list, String reg) { |
| | | for (int i = 0; i < list.size(); i++) { |
| | | if (list.get(i).get(0).indexOf(reg)>-1){ |
| | | return i; |
| | | if (list.get(i).get(0).indexOf(reg) > -1) { |
| | | return i; |
| | | } |
| | | } |
| | | return -1; |