use of com.topcom.cms.yuqing.task.sender.Sender in project topcom-cloud by 545314690.
the class WarningJob method sendEmail.
private void sendEmail(Page page, CustomSubject subject, Long wangningLogId) {
WarningTask warningTask = subject.getWarning();
// logger.info("开始推送Email消息:" + subject.getName());
List<Contact> contacts = warningTask.getContacts();
/**
* 获取所有联系人
*/
Set<String> emailSet = contacts.stream().filter(contact -> Contact.Type.EMAIL.equals(contact.getType())).map(contact -> contact.getAccount()).collect(Collectors.toSet());
logger.info("开始推送Email消息:" + subject.getName() + emailSet.toString());
if (emailSet.size() > 0) {
/**
*先保存预警日志,否则下面warningLog.getId()取到的日志Id总为0,保存日志的时候,不要调用save
*/
// 发送邮件
SenderFactory emailSenderFactory = new EmailSenderFactory();
Sender emailSender = emailSenderFactory.create();
String[] emails = {};
emails = emailSet.toArray(emails);
try {
WarningEmailBody warningEmailBody = new WarningEmailBody();
warningEmailBody.setContent(page.getContent());
warningEmailBody.setSpecialNumber(String.valueOf(page.getTotalElements()));
warningEmailBody.setSpecialName(subject.getName());
User user = userManager.findById(subject.getUserId());
warningEmailBody.setUser(user.getFullName() == null ? user.getUsername() : user.getFullName());
// warningEmailBody.setSubject("");
warningEmailBody.setSpecialUrl(warningEmailSetting.getSubjectUrl() + subject.getId());
warningEmailBody.setWarningLogUrl(warningEmailSetting.getLogUrl() + wangningLogId);
WarningEmail warningEmail = new WarningEmail().create(emails, warningEmailBody);
emailSender.send(warningEmail);
// 更新上次预警时间
warningTask.setLastWarningDate(new Date());
warningManager.save(warningTask);
} catch (IOException | TemplateException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}
use of com.topcom.cms.yuqing.task.sender.Sender in project topcom-cloud by 545314690.
the class BriefingJob method execute.
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
Long briefingTaskId = (Long) context.getMergedJobDataMap().get("briefingTaskId");
BriefingTask briefingTask = briefingTaskManager.findById(briefingTaskId);
logger.info("任务运行:" + briefingTask.getBriefingType() + ":" + briefingTaskId);
/**
* 生成月报
*/
JSONObject briefing = null;
try {
briefing = (JSONObject) briefingCreator.create(briefingTask).get();
logger.info("任务运行:生成报告成功");
} catch (BusinessException | InterruptedException | ExecutionException e) {
e.printStackTrace();
logger.info("任务运行:生成报告失败");
}
List<Contact> contacts = briefingTask.getContacts();
// 过滤出email联系人
Set<String> emailSet = contacts.stream().filter(contact -> Contact.Type.EMAIL.equals(contact.getType())).map(contact -> contact.getAccount()).collect(Collectors.toSet());
if (emailSet.size() > 0) {
SenderFactory emailSenderFactory = new EmailSenderFactory();
Sender emailSender = emailSenderFactory.create();
String[] emails = {};
emails = emailSet.toArray(emails);
if (briefing != null) {
try {
BriefingEmail briefingEmail = new BriefingEmail().create(emails, briefing);
briefingEmail.setSubject(SUBJECT);
emailSender.send(briefingEmail);
} catch (IOException | TemplateException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
Aggregations