|
@@ -2,6 +2,7 @@ package com.znzn.project.dc.dtdata.service.impl;
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
+import com.enosiot.apim.poseidon.exception.PoseidonException;
|
|
|
import com.znzn.project.dc.dtdata.common.CommonData;
|
|
import com.znzn.project.dc.dtdata.common.CommonData;
|
|
|
import com.znzn.project.dc.dtdata.entity.ExecError;
|
|
import com.znzn.project.dc.dtdata.entity.ExecError;
|
|
|
import com.znzn.project.dc.dtdata.entity.FileStore;
|
|
import com.znzn.project.dc.dtdata.entity.FileStore;
|
|
@@ -59,14 +60,15 @@ public class DataCollectionService implements IDataCollectionService {
|
|
|
int coreCount = Runtime.getRuntime().availableProcessors();
|
|
int coreCount = Runtime.getRuntime().availableProcessors();
|
|
|
int threadPoolCount = Math.min(coreCount * 2, 6);
|
|
int threadPoolCount = Math.min(coreCount * 2, 6);
|
|
|
this.executorService = Executors.newFixedThreadPool(threadPoolCount);
|
|
this.executorService = Executors.newFixedThreadPool(threadPoolCount);
|
|
|
- log.info("初始化数据收集服务,线程池大小: {}", threadPoolCount);
|
|
|
|
|
|
|
+ log.info("初始化数据收集服务,线程池大小[{}]", threadPoolCount);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
@Async
|
|
@Async
|
|
|
public void collectData(CollectDataInData inData) {
|
|
public void collectData(CollectDataInData inData) {
|
|
|
|
|
|
|
|
- LocalDateTime end = inData.getEndTime();
|
|
|
|
|
|
|
+ LocalDateTime execBegin = LocalDateTime.now();
|
|
|
|
|
+ LocalDateTime end = LocalDateTime.now().toLocalDate().atStartOfDay();
|
|
|
FileStore fileStore = CommonData.FILE_STORE;
|
|
FileStore fileStore = CommonData.FILE_STORE;
|
|
|
Integer id = fileStore.getId();
|
|
Integer id = fileStore.getId();
|
|
|
|
|
|
|
@@ -75,13 +77,17 @@ public class DataCollectionService implements IDataCollectionService {
|
|
|
while (!date.isAfter(end) && !date.isEqual(end)) {
|
|
while (!date.isAfter(end) && !date.isEqual(end)) {
|
|
|
LocalDateTime queryEndDate = date.plusMinutes(inData.getMinute());
|
|
LocalDateTime queryEndDate = date.plusMinutes(inData.getMinute());
|
|
|
long begin = System.currentTimeMillis();
|
|
long begin = System.currentTimeMillis();
|
|
|
- log.info("{},开始时间{},结束时间{},时间跨度为{}分钟", fileStore.getName(), date, end, inData.getMinute());
|
|
|
|
|
|
|
+ log.info("[{}],开始时间[{}],结束时间[{}],时间跨度为[{}]分钟", fileStore.getName(), date, end, inData.getMinute());
|
|
|
processSingleData(date, queryEndDate, inData);
|
|
processSingleData(date, queryEndDate, inData);
|
|
|
- execDataDateService.finishAndAddNextTime(id, queryEndDate);
|
|
|
|
|
|
|
+ if (null == inData.getExecErrorId()) {
|
|
|
|
|
+ execDataDateService.finishAndAddNextTime(id, queryEndDate);
|
|
|
|
|
+ }
|
|
|
date = queryEndDate;
|
|
date = queryEndDate;
|
|
|
- log.info("{},开始时间{},结束时间{},时间跨度为{}分钟,耗时{}", fileStore.getName(), date, end, inData.getMinute(),
|
|
|
|
|
|
|
+ end = LocalDateTime.now().toLocalDate().atStartOfDay();
|
|
|
|
|
+ log.info("[{}],开始时间[{}],结束时间[{}],时间跨度为[{}]分钟,耗时[{}]", fileStore.getName(), date, end, inData.getMinute(),
|
|
|
(System.currentTimeMillis() - begin) / 1000);
|
|
(System.currentTimeMillis() - begin) / 1000);
|
|
|
}
|
|
}
|
|
|
|
|
+ log.info("历史数据补全结束,截止时间[{}],总耗时[{}]", date, DateUtils.formatDuration(LocalDateTime.now(), execBegin));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@SneakyThrows
|
|
@SneakyThrows
|
|
@@ -108,7 +114,7 @@ public class DataCollectionService implements IDataCollectionService {
|
|
|
*/
|
|
*/
|
|
|
private void processSingleData(LocalDateTime queryBeginDate, LocalDateTime queryEndDate, CollectDataInData inData) {
|
|
private void processSingleData(LocalDateTime queryBeginDate, LocalDateTime queryEndDate, CollectDataInData inData) {
|
|
|
long logBegin = System.currentTimeMillis();
|
|
long logBegin = System.currentTimeMillis();
|
|
|
- log.info("开始处理日期: {} 的数据", queryBeginDate);
|
|
|
|
|
|
|
+ log.info("开始处理日期[{}]的数据", queryBeginDate);
|
|
|
List<String> windTurbineIdList = inData.getWindTurbineIdList();
|
|
List<String> windTurbineIdList = inData.getWindTurbineIdList();
|
|
|
FileStore fileStore = CommonData.FILE_STORE;
|
|
FileStore fileStore = CommonData.FILE_STORE;
|
|
|
|
|
|
|
@@ -146,7 +152,8 @@ public class DataCollectionService implements IDataCollectionService {
|
|
|
log.error("[{}]没有配置测点", turbine);
|
|
log.error("[{}]没有配置测点", turbine);
|
|
|
}
|
|
}
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
- log.error("处理风机 {} 数据失败: {}", turbine.getId(), e.getMessage(), e);
|
|
|
|
|
|
|
+ log.error("处理风机[{}] 数据失败[{}]", turbine.getId(), e.getMessage());
|
|
|
|
|
+ e.fillInStackTrace();
|
|
|
}
|
|
}
|
|
|
}, executorService);
|
|
}, executorService);
|
|
|
futures.add(future);
|
|
futures.add(future);
|
|
@@ -156,7 +163,7 @@ public class DataCollectionService implements IDataCollectionService {
|
|
|
|
|
|
|
|
// 等待所有任务完成
|
|
// 等待所有任务完成
|
|
|
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
|
|
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
|
|
|
- log.info("日期: {} 的数据处理完成, 耗时:{} 秒", queryBeginDate, (System.currentTimeMillis() - logBegin) / 1000);
|
|
|
|
|
|
|
+ log.info("日期[{}] 的数据处理完成, 耗时[{}]秒", queryBeginDate, (System.currentTimeMillis() - logBegin) / 1000);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void saveExecError(WindTurbine turbine, LocalDateTime queryStartDate, LocalDateTime queryEndDate, Integer errorCode, String message, Integer execErrorId) {
|
|
private void saveExecError(WindTurbine turbine, LocalDateTime queryStartDate, LocalDateTime queryEndDate, Integer errorCode, String message, Integer execErrorId) {
|
|
@@ -183,14 +190,26 @@ public class DataCollectionService implements IDataCollectionService {
|
|
|
/**
|
|
/**
|
|
|
* 处理单个风机数据
|
|
* 处理单个风机数据
|
|
|
*/
|
|
*/
|
|
|
|
|
+
|
|
|
private void processTurbineData(WindTurbine turbine, LocalDateTime queryStartDate, LocalDateTime queryEndDate, HashSet<String>
|
|
private void processTurbineData(WindTurbine turbine, LocalDateTime queryStartDate, LocalDateTime queryEndDate, HashSet<String>
|
|
|
pointIdsWithLogic, Integer execErrorId) throws IOException {
|
|
pointIdsWithLogic, Integer execErrorId) throws IOException {
|
|
|
|
|
+ processTurbineData(turbine, queryStartDate, queryEndDate, pointIdsWithLogic, execErrorId, 1);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ private void processTurbineData(WindTurbine turbine, LocalDateTime queryStartDate, LocalDateTime queryEndDate, HashSet<String>
|
|
|
|
|
+ pointIdsWithLogic, Integer execErrorId, Integer retryTimes) throws IOException {
|
|
|
|
|
|
|
|
long begin = System.currentTimeMillis();
|
|
long begin = System.currentTimeMillis();
|
|
|
// 查询历史数据
|
|
// 查询历史数据
|
|
|
List<JSONObject> historicalData = null;
|
|
List<JSONObject> historicalData = null;
|
|
|
try {
|
|
try {
|
|
|
historicalData = EnosapiUtils.queryHistoricalMeasurementPoint(turbine.getId(), queryStartDate.format(DATE_FORMATTER), queryEndDate.format(DATE_FORMATTER), new ArrayList<>(pointIdsWithLogic), "1m", true);
|
|
historicalData = EnosapiUtils.queryHistoricalMeasurementPoint(turbine.getId(), queryStartDate.format(DATE_FORMATTER), queryEndDate.format(DATE_FORMATTER), new ArrayList<>(pointIdsWithLogic), "1m", true);
|
|
|
|
|
+ } catch (PoseidonException e) {
|
|
|
|
|
+ if (EnosapiUtils.containsException(e, java.net.ConnectException.class)) {
|
|
|
|
|
+ log.error("风机[{}]请求超时,第[{}]次", turbine.getId(), retryTimes);
|
|
|
|
|
+ processTurbineData(turbine, queryStartDate, queryEndDate, pointIdsWithLogic, execErrorId, retryTimes + 1);
|
|
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
String message = e.getMessage();
|
|
String message = e.getMessage();
|
|
|
saveExecError(turbine, queryStartDate, queryEndDate, 2, message, execErrorId);
|
|
saveExecError(turbine, queryStartDate, queryEndDate, 2, message, execErrorId);
|
|
@@ -199,7 +218,7 @@ public class DataCollectionService implements IDataCollectionService {
|
|
|
if (null != historicalData && historicalData.isEmpty()) {
|
|
if (null != historicalData && historicalData.isEmpty()) {
|
|
|
String message = "没有获取到数据";
|
|
String message = "没有获取到数据";
|
|
|
saveExecError(turbine, queryStartDate, queryEndDate, 1, message, execErrorId);
|
|
saveExecError(turbine, queryStartDate, queryEndDate, 1, message, execErrorId);
|
|
|
- log.warn("风机 {} 在日期 {} 没有数据", turbine.getId(), queryStartDate);
|
|
|
|
|
|
|
+ log.warn("风机[{}]在日期[{}]没有数据", turbine.getId(), queryStartDate);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (historicalData != null && !historicalData.isEmpty()) {
|
|
if (historicalData != null && !historicalData.isEmpty()) {
|
|
@@ -223,11 +242,9 @@ public class DataCollectionService implements IDataCollectionService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (null != execErrorId) {
|
|
if (null != execErrorId) {
|
|
|
-// saveExecError(turbine, queryStartDate, queryEndDate, 0, "", execErrorId);
|
|
|
|
|
- execErrorService.removeById(execErrorId);
|
|
|
|
|
|
|
+ saveExecError(turbine, queryStartDate, queryEndDate, 0, "", execErrorId);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
// 构建文件路径 保存为文件
|
|
// 构建文件路径 保存为文件
|
|
|
String filePath = buildFilePath(turbine, queryStartDate);
|
|
String filePath = buildFilePath(turbine, queryStartDate);
|
|
|
createDirectories(filePath);
|
|
createDirectories(filePath);
|
|
@@ -238,11 +255,9 @@ public class DataCollectionService implements IDataCollectionService {
|
|
|
}
|
|
}
|
|
|
ParquetUtils.saveAsParquet(jsonDatas, allStanderList, filePath);
|
|
ParquetUtils.saveAsParquet(jsonDatas, allStanderList, filePath);
|
|
|
|
|
|
|
|
-
|
|
|
|
|
updateWindTurbineDataInfoTable(turbine, queryStartDate, jsonDatas.size(), lastObject, filePath);
|
|
updateWindTurbineDataInfoTable(turbine, queryStartDate, jsonDatas.size(), lastObject, filePath);
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
- log.info("风场:{},风机:{},风机ID:{},开始时间:{},结束时间:{},耗时:{}", turbine.getName(), turbine.getCode(), turbine.getId(),
|
|
|
|
|
|
|
+ log.info("风场[{}],风机[{}],风机ID[{}],开始时间[{}],结束时间[{}],耗时[{}]", turbine.getName(), turbine.getCode(), turbine.getId(),
|
|
|
queryStartDate.format(DATE_FORMATTER), queryEndDate.format(DATE_FORMATTER), (System.currentTimeMillis() - begin) / 1000);
|
|
queryStartDate.format(DATE_FORMATTER), queryEndDate.format(DATE_FORMATTER), (System.currentTimeMillis() - begin) / 1000);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -329,9 +344,9 @@ public class DataCollectionService implements IDataCollectionService {
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
private String buildFilePath(WindTurbine turbine, LocalDateTime date) {
|
|
private String buildFilePath(WindTurbine turbine, LocalDateTime date) {
|
|
|
- String basePath = CommonData.FILE_STORE != null ? CommonData.FILE_STORE.getSavaDir() : "/data/wind-turbine";
|
|
|
|
|
- return String.format("%s/%s/%s/%s/%s.%s", basePath, turbine.getType(), turbine.getWindFarmId(),
|
|
|
|
|
- date.format(DATE_FORMATTER_WITH_NUMBER), turbine.getId(), "parquet");
|
|
|
|
|
|
|
+ String basePath = CommonData.FILE_STORE != null ? CommonData.FILE_STORE.getSavaDir() : "/data/wind-turbine/tmp";
|
|
|
|
|
+ return String.format("%s/%s/%s/%s/%s.%s", basePath, date.format(DATE_FORMATTER_WITH_NUMBER), turbine.getType(),
|
|
|
|
|
+ turbine.getWindFarmId(), turbine.getId(), "parquet");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -352,7 +367,7 @@ public class DataCollectionService implements IDataCollectionService {
|
|
|
Files.createDirectories(parentDir.toPath());
|
|
Files.createDirectories(parentDir.toPath());
|
|
|
}
|
|
}
|
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
|
- log.error("创建目录失败: {}, 次数: {}", filePath, retryTimes, e);
|
|
|
|
|
|
|
+ log.error("创建目录失败[{}], 次数[{}]", filePath, retryTimes, e);
|
|
|
if (retryTimes < 6) {
|
|
if (retryTimes < 6) {
|
|
|
createDirectories(filePath, retryTimes + 1);
|
|
createDirectories(filePath, retryTimes + 1);
|
|
|
return;
|
|
return;
|