Commit d0f5cbe5 authored by Tong Li's avatar Tong Li

MP

parent 0fd5e9c9
......@@ -191,16 +191,16 @@ public class ResultWriter {
}
FlatParquetUtil parquetUtil = new FlatParquetUtil();
String periodTaskPath = getOptimizationPeriodTask(sceneId);
writeLog("writePeriodTasks"+result.getPeriodTasks().size());
writeLog("writePeriodTasks" + result.getPeriodTasks().size());
parquetUtil.write(result.getPeriodTasks(), periodTaskPath, PeriodTaskResult.class);
writeLog("writePeriodTasks");
writeLog("writePeriodOutputTasks"+result.getPeriodTaskOutputs().size());
writeLog("writePeriodOutputTasks" + result.getPeriodTaskOutputs().size());
String periodTaskOutputPath = getOptimizationPeriodTaskOutput(sceneId);
parquetUtil.write(result.getPeriodTaskOutputs(), periodTaskOutputPath, PeriodTaskResult.OutputInfo.class);
writeLog("writePeriodOutputTasks");
writeLog("writePispips:"+result.getPispips().size());
writeLog("writePispips:" + result.getPispips().size());
String pispiPath = getOptimizationPispip(sceneId);
parquetUtil.write(result.getPispips(), pispiPath, PispipResult.class);
......@@ -212,7 +212,7 @@ public class ResultWriter {
writeLog("writesalesDemand");
String salesDemandPath = getOptimizationSalesDemand(sceneId);
parquetUtil.write(result.getSalesDemands(), salesDemandPath, SalesDemandResult.class);
// List<PispipResult> pispips = parquetUtil.readAll(pispiPath, PispipResult.class);
// List<PispipResult> pispips = parquetUtil.readAll(pispiPath, PispipResult.class);
String salesDemandSummariePath = getOptimizationSalesDemandSummarie(sceneId);
parquetUtil.write(result.getSaleSummarieDemands(), salesDemandSummariePath, SalesDemandResult.class);
......@@ -235,58 +235,59 @@ public class ResultWriter {
List<OperationDemandResult> opDemands = buildOperationDemandResults();
parquetUtil.write(opDemands, getOptimizationOperationDemand(sceneId), OperationDemandResult.class);
try {
File file = getOptimizationFile(sceneId);
File tempFile = new File(file.getParentFile(), file.getName() + ".tmp");
if (useCompression) {
try (FileOutputStream fos = new FileOutputStream(tempFile);
GZIPOutputStream gzos = new GZIPOutputStream(fos)) {
objectMapper.writeValue(gzos, result);
}
} else {
objectMapper.writeValue(tempFile, result);
}
if (tempFile.length() == 0) {
logger.error("写入的临时文件为空: {}", tempFile.getAbsolutePath());
Files.deleteIfExists(tempFile.toPath());
return false;
}
if (useCompression) {
try (FileInputStream fis = new FileInputStream(tempFile);
GZIPInputStream gzis = new GZIPInputStream(fis)) {
OptimizationResult verifyChromosome = objectMapper.readValue(gzis, OptimizationResult.class);
if (verifyChromosome == null) {
throw new IOException("验证读取失败");
}
}
} else {
try {
OptimizationResult verifyChromosome = objectMapper.readValue(tempFile, OptimizationResult.class);
if (verifyChromosome == null) {
throw new IOException("验证读取失败");
}
} catch (Exception e) {
logger.error("验证染色体文件内容失败,文件: {}", tempFile.getAbsolutePath(), e);
Files.deleteIfExists(tempFile.toPath());
return false;
}
}
if (file.exists()) {
Files.deleteIfExists(file.toPath());
}
Files.move(tempFile.toPath(), file.toPath());
logger.info("保存成功,场景ID: {}, 文件: {}", sceneId, file.getAbsolutePath());
return true;
} catch (Exception e) {
logger.error("保存文件失败,场景ID: " + sceneId, e);
return false;
}
// try {
//
// File file = getOptimizationFile(sceneId);
// File tempFile = new File(file.getParentFile(), file.getName() + ".tmp");
//
// if (useCompression) {
// try (FileOutputStream fos = new FileOutputStream(tempFile);
// GZIPOutputStream gzos = new GZIPOutputStream(fos)) {
// objectMapper.writeValue(gzos, result);
// }
// } else {
// objectMapper.writeValue(tempFile, result);
// }
//
// if (tempFile.length() == 0) {
// logger.error("写入的临时文件为空: {}", tempFile.getAbsolutePath());
// Files.deleteIfExists(tempFile.toPath());
// return false;
// }
//
// if (useCompression) {
// try (FileInputStream fis = new FileInputStream(tempFile);
// GZIPInputStream gzis = new GZIPInputStream(fis)) {
// OptimizationResult verifyChromosome = objectMapper.readValue(gzis, OptimizationResult.class);
// if (verifyChromosome == null) {
// throw new IOException("验证读取失败");
// }
// }
// } else {
// try {
// OptimizationResult verifyChromosome = objectMapper.readValue(tempFile, OptimizationResult.class);
// if (verifyChromosome == null) {
// throw new IOException("验证读取失败");
// }
// } catch (Exception e) {
// logger.error("验证染色体文件内容失败,文件: {}", tempFile.getAbsolutePath(), e);
// Files.deleteIfExists(tempFile.toPath());
// return false;
// }
// }
//
// if (file.exists()) {
// Files.deleteIfExists(file.toPath());
// }
// Files.move(tempFile.toPath(), file.toPath());
//
// logger.info("保存成功,场景ID: {}, 文件: {}", sceneId, file.getAbsolutePath());
// return true;
// } catch (Exception e) {
// logger.error("保存文件失败,场景ID: " + sceneId, e);
// return false;
// }
} catch (IOException ex) {
logger.error("保存文件失败,场景ID: " + sceneId, ex);
return false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment