use of com.webank.wedatasphere.qualitis.excel.ExcelResult in project Qualitis by WeBankFinTech.
the class ApplicationServiceImpl method joinAlarmConfig.
private void joinAlarmConfig(List<ExcelResult> results, TaskRuleSimple taskRuleSimple, ExcelResult excelResult, UploadResultRequest request, StringBuffer checkTemplateStr, StringBuffer resultStr) {
for (TaskRuleAlarmConfig taskRuleAlarmConfig : taskRuleSimple.getTaskRuleAlarmConfigList()) {
Integer checkTemplate = taskRuleAlarmConfig.getCheckTemplate();
String checkTemplateName = CheckTemplateEnum.getCheckTemplateName(checkTemplate);
String outputName = taskRuleAlarmConfig.getOutputName();
String compare = CompareTypeEnum.getCompareTypeName(taskRuleAlarmConfig.getCompareType());
Double threshold = taskRuleAlarmConfig.getThreshold();
Integer statusCode = taskRuleAlarmConfig.getStatus();
String status = AlarmConfigStatusEnum.getMessage(statusCode);
RuleMetric ruleMetric = taskRuleAlarmConfig.getRuleMetric();
TaskResult taskResult = taskResultDao.find(taskRuleSimple.getApplicationId(), taskRuleSimple.getRuleId(), ruleMetric != null ? ruleMetric.getId() : -1);
String resultValue = "";
Long runDate = null;
if (taskResult != null) {
resultValue = StringUtils.isNotBlank(taskResult.getValue()) ? taskResult.getValue() : "0";
runDate = taskResult.getRunDate();
}
if (request.getStatus().contains(statusCode)) {
checkTemplateStr.append(checkTemplateName).append(StringUtils.isNotBlank(compare) ? compare : "").append(" ").append(threshold).append(" ").append(status);
ExcelResult excelAlarmConfig = new ExcelResult();
BeanUtils.copyProperties(excelResult, excelAlarmConfig);
excelAlarmConfig.setRuleCheckTemplates(checkTemplateStr.toString());
resultStr.append(outputName).append(": ").append(resultValue);
excelAlarmConfig.setHistoryResult(resultStr.toString());
excelAlarmConfig.setCreateTime(runDate != null ? runDate.toString() : "");
excelAlarmConfig.setExecutionUser(taskRuleSimple.getExecuteUser());
results.add(excelAlarmConfig);
checkTemplateStr.delete(0, checkTemplateStr.length());
resultStr.delete(0, checkTemplateStr.length());
}
}
}
use of com.webank.wedatasphere.qualitis.excel.ExcelResult in project Qualitis by WeBankFinTech.
the class ApplicationServiceImpl method writeExcelFile.
private void writeExcelFile(File tmpFile, List<String> tables, UploadResultRequest request) throws UnExpectedRequestException {
int sheetNo = 1;
OutputStream tmpOutputStream = null;
try {
Path parentPath = Paths.get(tmpFile.getParent());
if (Files.notExists(parentPath)) {
tmpFile.getParentFile().mkdirs();
}
if (!tmpFile.exists()) {
LOGGER.info("Start to create local file.");
tmpFile.createNewFile();
}
tmpOutputStream = new FileOutputStream(tmpFile);
ExcelWriter writer = new ExcelWriter(tmpOutputStream, ExcelTypeEnum.XLSX, true);
// Find task with the start time and end time.
for (String tableName : tables) {
List<Task> tasks = taskDao.findWithSubmitTimeAndDatasource(request.getStartTime(), request.getEndTime(), request.getClusterName(), request.getDatabaseName(), tableName);
List<TaskRuleSimple> taskRuleSimples = tasks.stream().map(Task::getTaskRuleSimples).flatMap(taskRuleSimpleSet -> taskRuleSimpleSet.stream()).distinct().collect(Collectors.toList());
// Generate analysis result excel
List<ExcelResult> results = new ArrayList<>(taskRuleSimples.size());
for (TaskRuleSimple taskRuleSimple : taskRuleSimples) {
ExcelResult excelResult = new ExcelResult();
excelResult.setRuleName(taskRuleSimple.getRuleName());
excelResult.setClusterName(request.getClusterName());
excelResult.setDatabaseName(request.getDatabaseName());
excelResult.setTableName(tableName);
excelResult.setBeginTime(taskRuleSimple.getTask().getBeginTime());
excelResult.setEndTime(taskRuleSimple.getTask().getEndTime());
StringBuffer checkTemplateStr = new StringBuffer();
StringBuffer resultStr = new StringBuffer();
joinAlarmConfig(results, taskRuleSimple, excelResult, request, checkTemplateStr, resultStr);
results.add(excelResult);
}
Sheet templateSheet = new Sheet(sheetNo++, 0, ExcelResult.class);
templateSheet.setSheetName(tableName + "-" + ExcelSheetName.ANALYSIS_NAME);
writer.write(results, templateSheet);
}
writer.finish();
} catch (FileNotFoundException e) {
LOGGER.error(e.getMessage(), e);
throw new UnExpectedRequestException("{&FAILED_TO_CREATE_LOCAL_FILE}");
} catch (IOException e) {
LOGGER.error(e.getMessage(), e);
throw new UnExpectedRequestException("{&FAILED_TO_CREATE_LOCAL_FILE}");
} finally {
try {
tmpOutputStream.close();
} catch (IOException e) {
LOGGER.error(e.getMessage(), e);
}
}
}
Aggregations