|
@@ -2,6 +2,7 @@ package com.jiayue.insu.incloud.service.impl;
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
|
+import cn.hutool.core.date.LocalDateTimeUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.http.HttpRequest;
|
|
import cn.hutool.http.HttpRequest;
|
|
import cn.hutool.http.HttpUtil;
|
|
import cn.hutool.http.HttpUtil;
|
|
@@ -167,7 +168,7 @@ public class ApiServiceImpl implements ApiService {
|
|
// 解析短期文件
|
|
// 解析短期文件
|
|
JSONObject fileResult = null;
|
|
JSONObject fileResult = null;
|
|
// 内蒙古马吉拉湖光伏电站 返回未来10天数据
|
|
// 内蒙古马吉拉湖光伏电站 返回未来10天数据
|
|
- if ("J00476".equals(station.getStationCode())) {
|
|
|
|
|
|
+ if ("J00476".equals(station.getStationCode()) || "T00002-A".equals(station.getStationCode()) || "J00971-A".equals(station.getStationCode())) {
|
|
fileResult = fileAnalysis(file, station, "dq", requestJson.getStr("beginDate"), requestJson.getStr("beginDate"));
|
|
fileResult = fileAnalysis(file, station, "dq", requestJson.getStr("beginDate"), requestJson.getStr("beginDate"));
|
|
} else {
|
|
} else {
|
|
fileResult = fileAnalysis(file, station, "dq", requestJson.getStr("beginDate"), requestJson.getStr("beginDate"));
|
|
fileResult = fileAnalysis(file, station, "dq", requestJson.getStr("beginDate"), requestJson.getStr("beginDate"));
|
|
@@ -233,6 +234,7 @@ public class ApiServiceImpl implements ApiService {
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
public JSONObject putShortWpfData(JSONObject requestJson) {
|
|
public JSONObject putShortWpfData(JSONObject requestJson) {
|
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
// 根据场站编号查询场站信息
|
|
// 根据场站编号查询场站信息
|
|
Station station = stationService.findByStationCode(requestJson.getStr("wfId"));
|
|
Station station = stationService.findByStationCode(requestJson.getStr("wfId"));
|
|
// 文件生成时间
|
|
// 文件生成时间
|
|
@@ -241,11 +243,52 @@ public class ApiServiceImpl implements ApiService {
|
|
JSONObject values = JSONUtil.parseObj(requestJson.getJSONArray("values").get(0));
|
|
JSONObject values = JSONUtil.parseObj(requestJson.getJSONArray("values").get(0));
|
|
// 明日修正后数据Arr
|
|
// 明日修正后数据Arr
|
|
JSONArray datas = values.getJSONArray("datas");
|
|
JSONArray datas = values.getJSONArray("datas");
|
|
- // 将json数据转化为ListMap
|
|
|
|
- List<Map<String, Object>> dqListMap = getDqListMap(station, datas, station.getName());
|
|
|
|
|
|
+ List<Map<String, Object>> dqListMap = new ArrayList<>();
|
|
|
|
+ // 山东莱芜单独判断(其中T00002-A为给对面提供的测试场站)
|
|
|
|
+ if ("T00002-A".equals(station.getStationCode()) || "J00971-A".equals(station.getStationCode())){
|
|
|
|
+ String stationName = station.getName();
|
|
|
|
+ List<ForecastData> forecastDataList = forecastDataService.findByInitTimeAndStationCode(LocalDateTimeUtil.beginOfDay(LocalDateTime.now()),station.getStationCode());
|
|
|
|
+ DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
|
|
|
|
+ DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
|
+ for (int i = 0; i < forecastDataList.size(); i++) {
|
|
|
|
+ Map<String, Object> entry = new HashMap<>();
|
|
|
|
+ boolean foundMatch = false;
|
|
|
|
+ String forecastTimeStr = sdf.format(new Date(forecastDataList.get(i).getForecastTime()));
|
|
|
|
+ for (int j = 0; j < datas.size(); j++) {
|
|
|
|
+ JSONObject data = datas.getJSONObject(j);
|
|
|
|
+ String timeStr = data.getStr("time");
|
|
|
|
+ String formattedTime = "";
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ LocalDateTime dateTime = LocalDateTime.parse(timeStr, inputFormatter);
|
|
|
|
+ formattedTime = dateTime.format(outputFormatter);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ formattedTime = timeStr + ":00";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (forecastTimeStr.equals(formattedTime)) {
|
|
|
|
+ entry.put("stationName", stationName);
|
|
|
|
+ entry.put("fpValue", new BigDecimal(String.valueOf(data.get("data"))).divide(new BigDecimal("1000"), 2, BigDecimal.ROUND_HALF_UP));
|
|
|
|
+ entry.put("forecastTime", formattedTime);
|
|
|
|
+ foundMatch = true;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (!foundMatch) {
|
|
|
|
+ entry.put("stationName", stationName);
|
|
|
|
+ entry.put("fpValue", forecastDataList.get(i).getFpValue());
|
|
|
|
+ entry.put("forecastTime", forecastTimeStr);
|
|
|
|
+ }
|
|
|
|
+ dqListMap.add(entry);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }else {
|
|
|
|
+ // 将json数据转化为ListMap
|
|
|
|
+ dqListMap = getDqListMap(station, datas, station.getName());
|
|
|
|
+ }
|
|
|
|
+
|
|
// 短期文件模板
|
|
// 短期文件模板
|
|
String vmsPath = SystermUtils.getResourceBasePath() + "/vms/DQ.vm";
|
|
String vmsPath = SystermUtils.getResourceBasePath() + "/vms/DQ.vm";
|
|
- // 生成dq文件
|
|
|
|
JSONObject result = genFile(station, dqListMap, vmsPath, "_CORR", "DQ");
|
|
JSONObject result = genFile(station, dqListMap, vmsPath, "_CORR", "DQ");
|
|
if (JsonResultUtil.Type.failure.value().equals(result.get(JsonResultUtil.CODE_TAG))) {
|
|
if (JsonResultUtil.Type.failure.value().equals(result.get(JsonResultUtil.CODE_TAG))) {
|
|
Record record = new Record(CommonStant.RECORD_TYPE_PUSH_CORRECT_TO_MIN_IO, "CSGS", requestJson.getStr("wfId"), null, LocalDateTime.now(), LocalDateTime.now(), JsonResultUtil.Type.failure.msg(), JsonResultUtil.Type.failure.value());
|
|
Record record = new Record(CommonStant.RECORD_TYPE_PUSH_CORRECT_TO_MIN_IO, "CSGS", requestJson.getStr("wfId"), null, LocalDateTime.now(), LocalDateTime.now(), JsonResultUtil.Type.failure.msg(), JsonResultUtil.Type.failure.value());
|
|
@@ -361,7 +404,7 @@ public class ApiServiceImpl implements ApiService {
|
|
// 如果是短期
|
|
// 如果是短期
|
|
if ("dq".equals(type)) {
|
|
if ("dq".equals(type)) {
|
|
// 内蒙古马吉拉光伏电站返回未来10天数据
|
|
// 内蒙古马吉拉光伏电站返回未来10天数据
|
|
- if ("J00476".equals(station.getStationCode())) {
|
|
|
|
|
|
+ if ("J00476".equals(station.getStationCode()) || "T00002-A".equals(station.getStationCode())|| "J00971-A".equals(station.getStationCode())) {
|
|
// 如果 当条日期>开始时间 || 当条日期<结束时间 跳过当次循环
|
|
// 如果 当条日期>开始时间 || 当条日期<结束时间 跳过当次循环
|
|
if (thisDate.compareTo(format.format(useStartTime)) <= 0 || thisDate.compareTo(format.format(useEndTime)) >= 0) {
|
|
if (thisDate.compareTo(format.format(useStartTime)) <= 0 || thisDate.compareTo(format.format(useEndTime)) >= 0) {
|
|
continue;
|
|
continue;
|
|
@@ -375,7 +418,7 @@ public class ApiServiceImpl implements ApiService {
|
|
|
|
|
|
}
|
|
}
|
|
// 如果当条的日期和上调日期不一致,新建dayInfoJson(日数据json)
|
|
// 如果当条的日期和上调日期不一致,新建dayInfoJson(日数据json)
|
|
- if (!"J00476".equals(station.getStationCode())) {
|
|
|
|
|
|
+ if (!"J00476".equals(station.getStationCode()) && !"T00002-A".equals(station.getStationCode()) && !"J00971-A".equals(station.getStationCode())) {
|
|
if (!thisDate.equals(compareDate)) {
|
|
if (!thisDate.equals(compareDate)) {
|
|
// 如果不是第一条,且和上一条日期不是同一天,则将上条日期的96条数据放入日json数据
|
|
// 如果不是第一条,且和上一条日期不是同一天,则将上条日期的96条数据放入日json数据
|
|
if (!"".equals(compareDate)) {
|
|
if (!"".equals(compareDate)) {
|
|
@@ -643,15 +686,20 @@ public class ApiServiceImpl implements ApiService {
|
|
String pushDate = DateUtil.format(now, "yyyyMMdd");
|
|
String pushDate = DateUtil.format(now, "yyyyMMdd");
|
|
if (minIoFileUrlArr.length > 1) {
|
|
if (minIoFileUrlArr.length > 1) {
|
|
for (String url : minIoFileUrlArr) {
|
|
for (String url : minIoFileUrlArr) {
|
|
- postFileCreateInfoToCloud(station.getStationCode(), file.getName(), url);
|
|
|
|
- pushCorr(station, file.getName(), pushDate, url);
|
|
|
|
|
|
+ if (url.contains(station.getStationCode())) {
|
|
|
|
+// postFileCreateInfoToCloud(station.getStationCode(), file.getName(), url);
|
|
|
|
+ pushCorr(station, file.getName(), pushDate, url);
|
|
|
|
+ } else {
|
|
|
|
+ station.setStationCode(station.getStationCode().replace("-A", "-B"));
|
|
|
|
+// postFileCreateInfoToCloud(station.getStationCode(), file.getName(), url);
|
|
|
|
+ pushCorr(station, file.getName(), pushDate, url);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
// 如果文件放成功,回传文件生成信息到云端
|
|
// 如果文件放成功,回传文件生成信息到云端
|
|
postFileCreateInfoToCloud(station.getStationCode(), file.getName(), pushMinIoResult.getStr(JsonResultUtil.DATA_TAG));
|
|
postFileCreateInfoToCloud(station.getStationCode(), file.getName(), pushMinIoResult.getStr(JsonResultUtil.DATA_TAG));
|
|
pushCorr(station, file.getName(), pushDate, minIoFileUrl);
|
|
pushCorr(station, file.getName(), pushDate, minIoFileUrl);
|
|
}
|
|
}
|
|
-
|
|
|
|
return JsonResultUtil.success();
|
|
return JsonResultUtil.success();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -665,6 +713,8 @@ public class ApiServiceImpl implements ApiService {
|
|
public JSONObject pushFileToMinIo(File file, String stationCode) {
|
|
public JSONObject pushFileToMinIo(File file, String stationCode) {
|
|
// 存放完文件后返回的文件路径
|
|
// 存放完文件后返回的文件路径
|
|
String minIoFileUrl;
|
|
String minIoFileUrl;
|
|
|
|
+ InputStream in = null;
|
|
|
|
+ InputStream inB = null;
|
|
try {
|
|
try {
|
|
// 查看桶名称是否存在
|
|
// 查看桶名称是否存在
|
|
boolean flag = minioUtilService.bucketExists(bucketName);
|
|
boolean flag = minioUtilService.bucketExists(bucketName);
|
|
@@ -672,17 +722,22 @@ public class ApiServiceImpl implements ApiService {
|
|
return JsonResultUtil.failure("MinIo桶不存在");
|
|
return JsonResultUtil.failure("MinIo桶不存在");
|
|
}
|
|
}
|
|
// 向minIo中放入文件
|
|
// 向minIo中放入文件
|
|
- InputStream in = new FileInputStream(file);
|
|
|
|
|
|
+ in = new FileInputStream(file);
|
|
String fileName = "/" + stationCode + "/" + file.getName();
|
|
String fileName = "/" + stationCode + "/" + file.getName();
|
|
minIoFileUrl = minioUtilService.putObject(bucketName, fileName, in);
|
|
minIoFileUrl = minioUtilService.putObject(bucketName, fileName, in);
|
|
// 如果是AB机,向B中也放入文件
|
|
// 如果是AB机,向B中也放入文件
|
|
if (stationCode.indexOf("-A") > 0) {
|
|
if (stationCode.indexOf("-A") > 0) {
|
|
|
|
+ // InputStream 在被读取后,指针已经移动到了流的末尾,第二次上传B时就已经没有数据了,故新建一个输入流
|
|
|
|
+ inB = new FileInputStream(file);
|
|
String fileNameB = "/" + stationCode.replace("-A", "-B") + "/" + file.getName();
|
|
String fileNameB = "/" + stationCode.replace("-A", "-B") + "/" + file.getName();
|
|
- minIoFileUrl = minIoFileUrl + ";" + minioUtilService.putObject(bucketName, fileNameB, in);
|
|
|
|
|
|
+ minIoFileUrl = minIoFileUrl + ";" + minioUtilService.putObject(bucketName, fileNameB, inB);
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
return JsonResultUtil.failure("推送MinIo失败");
|
|
return JsonResultUtil.failure("推送MinIo失败");
|
|
|
|
+ }finally {
|
|
|
|
+ close(in);
|
|
|
|
+ close(inB);
|
|
}
|
|
}
|
|
return JsonResultUtil.success(minIoFileUrl);
|
|
return JsonResultUtil.success(minIoFileUrl);
|
|
}
|
|
}
|
|
@@ -1216,4 +1271,14 @@ public class ApiServiceImpl implements ApiService {
|
|
return bigDecimal;
|
|
return bigDecimal;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // 封装一个安全的关闭方法
|
|
|
|
+ private static void close(InputStream inputStream) {
|
|
|
|
+ if (inputStream != null) {
|
|
|
|
+ try {
|
|
|
|
+ inputStream.close();
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace(); // 可选:日志记录
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|