Commit a4408b68 by huangfusuper

添加运行实例与邮箱组合操作

parent a9018211
package com.byit.service.mapservice;
import com.byit.model.RunRecording;
/**
* 邮箱和运行实例表的组合操作
* @author huangfu
*/
public interface RunRecordingAndEmailService {
/**
* 将已经告警的实例修改为已高兴并且将此实例放置到邮箱列表
* @param runRecording
*/
void saveEmailAndRunRecording(RunRecording runRecording);
}
package com.byit.service.mapservice.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import com.byit.filesystem.FileSystem;
import com.byit.model.EmailAlarm;
import com.byit.model.JobTaskRunLogWithBLOBs;
import com.byit.model.RunRecording;
import com.byit.service.EmailAlarmService;
import com.byit.service.JobTaskRunLogService;
import com.byit.service.RunRecordingService;
import com.byit.service.mapservice.RunRecordingAndEmailService;
import com.byit.util.TimeFormatUtil;
import lombok.extern.slf4j.Slf4j;
import org.csource.common.MyException;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;
/**
* @author huangfu
*/
@Component
@Slf4j
public class RunRecordingAndEmailServiceImpl implements RunRecordingAndEmailService {
public static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
/**
* 邮箱表操作
*/
private final EmailAlarmService emailAlarmService;
/**
* 日志表操作
*/
private final JobTaskRunLogService jobTaskRunLogService;
/**
* 文件系统
*/
private final FileSystem fileSystem;
/**
* 运行实例操作
*/
private final RunRecordingService runRecordingService;
public RunRecordingAndEmailServiceImpl(EmailAlarmService emailAlarmService, JobTaskRunLogService jobTaskRunLogService,
FileSystem fileSystem, RunRecordingService runRecordingService) {
this.emailAlarmService = emailAlarmService;
this.jobTaskRunLogService = jobTaskRunLogService;
this.fileSystem = fileSystem;
this.runRecordingService = runRecordingService;
}
@Override
public void saveEmailAndRunRecording(RunRecording runRecording) {
//这一步是根据flowId和RunId查询对应的节点信息
List<JobTaskRunLogWithBLOBs> jobTaskRunLogByFlowIdAndRunId = jobTaskRunLogService.findJobTaskRunLogWithBLOBsByFlowIdAndRunId(runRecording.getFlowId(), runRecording.getRunId());
String flowName = runRecording.getFlowName();
String senContentHtml = runMsgHtml(jobTaskRunLogByFlowIdAndRunId, flowName);
EmailAlarm emailAlarm = EmailAlarm.builder()
.flowId(runRecording.getFlowId())
.flowName(flowName)
.runId(runRecording.getRunId())
.versionName(runRecording.getFlowVersionName())
.alarmEmail(runRecording.getAlarmEmail())
.alarmContent(senContentHtml)
.alarmResult("0")
.flowRes(runRecording.getFlowRunResult())
.alarmTitle(flowName)
.build();
//保存邮箱
emailAlarmService.saveEmailAlarm(emailAlarm);
//修改为已告警
runRecording.setIsAlarm("0");
runRecordingService.updateRunRecordingById(runRecording);
}
/**
* 生成发送邮件的html信息
* @param jobTaskRunLogs 节点的运行信息
* @param title 邮件主题
* @return 邮件主题的html
*/
private String runMsgHtml(List<JobTaskRunLogWithBLOBs> jobTaskRunLogs, String title) {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("<table border='1' width='80%' align='center' cellspacing='0' cellpadding='6'>")
.append(String.format("<h2 style='text-align:center;color:red'>%s</h2>", title))
.append("<thead align='center' style='background: blue;color: #fff'>")
.append("<th width = '10%'>节点名称</th>")
.append("<th width = '10%'>开始时间</th>")
.append("<th width = '10%'>结束时间</th>")
.append("<th width = '10%'>耗费时间</th>")
.append("<th width = '10%'>运行结果</th>")
.append("<th width = '50%'>运行日志</th>")
.append("</thead>")
.append("<tbody>");
if (CollectionUtil.isNotEmpty(jobTaskRunLogs)) {
jobTaskRunLogs.forEach(jobTaskRunLog -> {
long timeConsuming = jobTaskRunLog.getEndTime().getTime() - jobTaskRunLog.getStartTime().getTime();
/*
* String iframeHtml = "<iframe src='%s'></iframe>";
* String logFilePath = FILE_SYSTEM_PRE+fileSystemIp+":"+fileSystemPort+"/"+jobTaskRunLog.getLogRemotelyPath();
* String logFileUrl = String.format(iframeHtml,logFilePath);
*/
String logStr = null;
try {
if(null != jobTaskRunLog.getLogRemotelyPath()){
logStr = new String(fileSystem.downloaderFile(jobTaskRunLog.getLogRemotelyPath()), StandardCharsets.UTF_8);
}
} catch (IOException | MyException e) {
e.printStackTrace();
}
stringBuilder.append("<tr align='center'>")
.append(String.format("<td>%s</td>", jobTaskRunLog.getNodeName()))
.append(String.format("<td>%s</td>", DateUtil.format(jobTaskRunLog.getStartTime(), DATE_FORMAT)))
.append(String.format("<td>%s</td>", DateUtil.format(jobTaskRunLog.getEndTime(), DATE_FORMAT)))
.append(String.format("<td>%s</td>", TimeFormatUtil.timeFormat(timeConsuming)))
.append(String.format("<td>%s</td>", "1".equals(jobTaskRunLog.getRunCode()) ? "成功"
: "3".equals(jobTaskRunLog.getRunCode()) ? "补批成功"
: "4".equals(jobTaskRunLog.getRunCode()) ? "补批失败" : "失败"))
.append("<td>")
.append("<div style='display:inline-block;width:100%;word-break:break-all;height: auto;overflow: auto;text-align: left;'>")
.append(String.format("%s", logStr==null?jobTaskRunLog.getRunMsg():logStr))
.append("</div>")
.append("</td></tr>");
});
}
stringBuilder.append("</tbody>")
.append("</table>");
return stringBuilder.toString();
}
}
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