|
@@ -4,6 +4,7 @@ import cn.hutool.core.date.LocalDateTimeUtil;
|
|
|
import cn.hutool.core.io.file.FileReader;
|
|
|
import cn.hutool.http.HttpRequest;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
+import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.jiayue.insu.incloud.compermisson.BJZYYJYSDComPermisson;
|
|
|
import com.jiayue.insu.incloud.constants.CommonStant;
|
|
@@ -17,6 +18,7 @@ import com.jiayue.insu.incloud.entity.Station;
|
|
|
import com.jiayue.insu.incloud.service.ForecastDataLxService;
|
|
|
import com.jiayue.insu.incloud.service.IntegrationCompanyService;
|
|
|
import com.jiayue.insu.incloud.service.RecordService;
|
|
|
+import lombok.Data;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
@@ -298,7 +300,174 @@ public class PushDataForLX implements IPushInitForecastData {
|
|
|
|
|
|
@Override
|
|
|
public Boolean pushNWPData(Station station) {
|
|
|
- return null;
|
|
|
+ IntegrationCompany integrationCompany = integrationCompanyService.findByCode(CompanyConstant.COMPANY_LX);
|
|
|
+ // 获取场站编号
|
|
|
+ String stationCode = station.getStationCode();
|
|
|
+ Record record = new Record(CommonStant.RECORD_TYPE_PUSH_INIT_NWP, CompanyConstant.COMPANY_LX, stationCode, null, LocalDateTimeUtil.beginOfDay(LocalDateTime.now()), LocalDateTime.now(), null, null);
|
|
|
+ record.setState(StatusEnum.SUCCESS.getSign());
|
|
|
+ // 如果场站编号为空,则返回
|
|
|
+ if (stationCode == null || "".equals(stationCode)) {
|
|
|
+ record.setState(StatusEnum.STATION_CODE_NULL.getSign());
|
|
|
+ record.setStateContent(StatusEnum.STATION_CODE_NULL.getMsg());
|
|
|
+ recordService.save(record);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ // 获取指定目录下的短期原始数据(/jiayue/insu/file/init/J00269/)
|
|
|
+ String filePath = lxFilePath + stationCode + File.separatorChar;
|
|
|
+ File files = new File(filePath);
|
|
|
+ String[] fileNames = files.list();
|
|
|
+ // 如果文件名列表为空
|
|
|
+ if (fileNames == null || fileNames.length == 0) {
|
|
|
+ log.info("指定目录下无文件");
|
|
|
+ record.setState(StatusEnum.FILE_NULL.getSign());
|
|
|
+ record.setStateContent(StatusEnum.FILE_NULL.getMsg());
|
|
|
+ recordService.save(record);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ // 获取当天日期
|
|
|
+ LocalDateTime today = LocalDateTime.now();
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
|
|
|
+ String todayStr = today.format(formatter);
|
|
|
+ // 转为list并根据日期筛选排序
|
|
|
+ List<String> fileList = Arrays.stream(fileNames).collect(Collectors.toList());
|
|
|
+ List<String> filterFileList = fileList.stream().filter(s -> s.contains(todayStr)).filter(s -> s.contains("NWP")).collect(Collectors.toList());
|
|
|
+ // 如果筛选后无文件
|
|
|
+ if (filterFileList.size() == 0) {
|
|
|
+ log.info("无当日文件");
|
|
|
+ record.setState(StatusEnum.FILE_NULL.getSign());
|
|
|
+ record.setStateContent(StatusEnum.FILE_NULL.getMsg());
|
|
|
+ recordService.save(record);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ filterFileList.sort(Collections.reverseOrder());
|
|
|
+ // 获取原始文件
|
|
|
+ File originalFile = new File(filterFileList.get(0));
|
|
|
+ // 读取文件
|
|
|
+ FileReader fileReader = new FileReader(filePath + originalFile);
|
|
|
+ List<String> originalContents = fileReader.readLines();
|
|
|
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+
|
|
|
+ String genDate = dateFormat.format(new Date());
|
|
|
+
|
|
|
+
|
|
|
+ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
|
|
+
|
|
|
+ BigDecimal nwpDirectRadiation = new BigDecimal("0.7"); //直接辐射
|
|
|
+ BigDecimal nwpDiffuseRadiation = new BigDecimal("0.3"); //散接辐射
|
|
|
+ List<WeatherDataDetail> details = new ArrayList<>();
|
|
|
+ int i = 0;
|
|
|
+ // 循环解析原始NWP文件
|
|
|
+ for (String originalContent : originalContents) {
|
|
|
+
|
|
|
+ // 从有#的数据开始获取 数据示例:#1 帽子山光伏电站 2023-06-22 00:00:00 0.0
|
|
|
+ if (originalContent.contains("#")) {
|
|
|
+
|
|
|
+ // 根据分隔符分割,取时间和功率
|
|
|
+ String[] originalContentArr = originalContent.split("\t");
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 刨除当天的数据
|
|
|
+ if (sdf.format(format.parse(originalContentArr[5])).contains(genDate)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ } catch (ParseException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ // 如果分割后的数组长度小于4,则数据格式不正确
|
|
|
+ if (originalContentArr.length < 35) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ if (i<960){
|
|
|
+ WeatherDataDetail detail = new WeatherDataDetail();
|
|
|
+ detail.setTime(sdf.format(format.parse(originalContentArr[5])));
|
|
|
+ detail.setT(new BigDecimal(originalContentArr[6]).subtract(new BigDecimal("273.15")).toString());//温度
|
|
|
+ detail.setSwr(new BigDecimal(originalContentArr[9]).setScale(2, RoundingMode.HALF_UP).toString());//短波辐射(相当于总辐射)
|
|
|
+ detail.setP(new BigDecimal(originalContentArr[8]).setScale(2, RoundingMode.HALF_UP).toString());//地表气压
|
|
|
+ detail.setRh(new BigDecimal(originalContentArr[7]).setScale(2, RoundingMode.HALF_UP).toString());//2m相对湿度
|
|
|
+ detail.setDiffuseRadiation(new BigDecimal(originalContentArr[9]).multiply(nwpDiffuseRadiation).setScale(2, RoundingMode.HALF_UP).toString());//散接辐射
|
|
|
+ detail.setDirectRadiation(new BigDecimal(originalContentArr[9]).multiply(nwpDirectRadiation).setScale(2, RoundingMode.HALF_UP).toString());//直接辐射
|
|
|
+
|
|
|
+ detail.setWs10(new BigDecimal(originalContentArr[19]).setScale(2, RoundingMode.HALF_UP).toString());
|
|
|
+ detail.setWs30(new BigDecimal(originalContentArr[20]).setScale(2, RoundingMode.HALF_UP).toString());
|
|
|
+ detail.setWs50(new BigDecimal(originalContentArr[21]).setScale(2, RoundingMode.HALF_UP).toString());
|
|
|
+ detail.setWs70(new BigDecimal(originalContentArr[22]).setScale(2, RoundingMode.HALF_UP).toString());
|
|
|
+ detail.setWs80(new BigDecimal(originalContentArr[23]).setScale(2, RoundingMode.HALF_UP).toString());
|
|
|
+ detail.setWs90(new BigDecimal(originalContentArr[24]).setScale(2, RoundingMode.HALF_UP).toString());
|
|
|
+ detail.setWs100(new BigDecimal(originalContentArr[25]).setScale(2, RoundingMode.HALF_UP).toString());
|
|
|
+ detail.setWs170(new BigDecimal(originalContentArr[26]).setScale(2, RoundingMode.HALF_UP).toString());
|
|
|
+ detail.setWd10(new BigDecimal(originalContentArr[27]).setScale(2, RoundingMode.HALF_UP).toString());
|
|
|
+ detail.setWd30(new BigDecimal(originalContentArr[28]).setScale(2, RoundingMode.HALF_UP).toString());
|
|
|
+ detail.setWd50(new BigDecimal(originalContentArr[29]).setScale(2, RoundingMode.HALF_UP).toString());
|
|
|
+ detail.setWd70(new BigDecimal(originalContentArr[30]).setScale(2, RoundingMode.HALF_UP).toString());
|
|
|
+ detail.setWd80(new BigDecimal(originalContentArr[31]).setScale(2, RoundingMode.HALF_UP).toString());
|
|
|
+ detail.setWd90(new BigDecimal(originalContentArr[32]).setScale(2, RoundingMode.HALF_UP).toString());
|
|
|
+ detail.setWd100(new BigDecimal(originalContentArr[33]).setScale(2, RoundingMode.HALF_UP).toString());
|
|
|
+ detail.setWd170(new BigDecimal(originalContentArr[34]).setScale(2, RoundingMode.HALF_UP).toString());
|
|
|
+ details.add(detail);
|
|
|
+ i++;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ WeatherDataValue value = new WeatherDataValue();
|
|
|
+ value.setDatas(details);
|
|
|
+ List<WeatherDataValue> values = new ArrayList<>();
|
|
|
+ values.add(value);
|
|
|
+ WeatherDataRequest request = new WeatherDataRequest();
|
|
|
+ request.setStationId(stationCode);
|
|
|
+ request.setDate(genDate);
|
|
|
+ request.setValues(values);
|
|
|
+
|
|
|
+
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ String json = null;
|
|
|
+ try {
|
|
|
+ json = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(request);
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ String response;
|
|
|
+ // 测试地址
|
|
|
+// HttpRequest httpRequest = HttpRequest.post("https://frp-end.com:54383/forecast/reportMeteorologyData")
|
|
|
+ // 正式地址
|
|
|
+ HttpRequest httpRequest = HttpRequest.post("http://112.2.27.84:4220/forecast/reportMeteorologyData")
|
|
|
+
|
|
|
+// HttpRequest httpRequest = HttpRequest.post("")
|
|
|
+// HttpRequest httpRequest = HttpRequest.post("http://112.2.27.4/forecast")
|
|
|
+ .header("Content-Type", "application/json");
|
|
|
+ httpRequest.setGlobalTimeout(20000);
|
|
|
+ response = httpRequest.body(json).execute().body();
|
|
|
+
|
|
|
+ ResponseLXVo responseLXVo = JSONUtil.toBean(response, ResponseLXVo.class);
|
|
|
+ if (responseLXVo.getCode().equals("200")) {
|
|
|
+ record.setState(StatusEnum.SUCCESS.getSign());
|
|
|
+ record.setStateContent(responseLXVo.getMessage());
|
|
|
+ log.info("=========={}:{} ==>上送NWP原始数据成功 {}条==========", integrationCompany.getName(), station.getStationCode(), details.size());
|
|
|
+// log.info("{} 原始数据:{}", stationCode, json);
|
|
|
+ recordService.save(record);
|
|
|
+
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ log.error("=========={}:{} ==>上送数据失败 失败标识:{} ,失败原因:{} ==========", integrationCompany.getName(), station.getStationCode(), responseLXVo.getCode(), responseLXVo.getMessage());
|
|
|
+ log.info("{} 原始数据:{}", stationCode, json);
|
|
|
+ record.setState(StatusEnum.FILE_NULL.getSign());
|
|
|
+ record.setStateContent(responseLXVo.getMessage());
|
|
|
+ recordService.save(record);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
public String addOneDay(String lastForecastDateStr) {
|
|
@@ -343,4 +512,43 @@ public class PushDataForLX implements IPushInitForecastData {
|
|
|
}
|
|
|
return randomNumber;
|
|
|
}
|
|
|
+
|
|
|
+ @Data
|
|
|
+ public class WeatherDataRequest {
|
|
|
+ private String stationId;
|
|
|
+ private String date;
|
|
|
+ private List<WeatherDataValue> values;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Data
|
|
|
+ class WeatherDataValue {
|
|
|
+ private List<WeatherDataDetail> datas;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Data
|
|
|
+ class WeatherDataDetail {
|
|
|
+ private String time;
|
|
|
+ private String swr; // 总辐射
|
|
|
+ private String directRadiation; // 直辐射
|
|
|
+ private String diffuseRadiation; // 散辐射
|
|
|
+ private String t; // 温度
|
|
|
+ private String p; // 气压
|
|
|
+ private String rh; // 湿度
|
|
|
+ private String ws10; // 10米风速
|
|
|
+ private String ws30; // 30米风速
|
|
|
+ private String ws50; // 50米风速
|
|
|
+ private String ws70; // 70米风速
|
|
|
+ private String ws80; // 80米风速
|
|
|
+ private String ws90; // 90米风速
|
|
|
+ private String ws100; // 100米风速
|
|
|
+ private String ws170; // 170米风速
|
|
|
+ private String wd10; // 10米风向
|
|
|
+ private String wd30; // 30米风向
|
|
|
+ private String wd50; // 50米风向
|
|
|
+ private String wd70; // 70米风向
|
|
|
+ private String wd80; // 80米风向
|
|
|
+ private String wd90; // 90米风向
|
|
|
+ private String wd100; // 100米风向
|
|
|
+ private String wd170; // 170米风向
|
|
|
+ }
|
|
|
}
|