Search in sources :

Example 1 with Contact

use of com.topcom.cms.yuqing.domain.Contact 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();
            }
        }
    }
}
Also used : JobExecutionContext(org.quartz.JobExecutionContext) SenderFactory(com.topcom.cms.yuqing.task.sender.factory.SenderFactory) TemplateException(freemarker.template.TemplateException) Logger(org.jboss.logging.Logger) BusinessException(com.topcom.cms.exception.BusinessException) Autowired(org.springframework.beans.factory.annotation.Autowired) Set(java.util.Set) Job(org.quartz.Job) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) EmailSenderFactory(com.topcom.cms.yuqing.task.sender.factory.EmailSenderFactory) JobExecutionException(org.quartz.JobExecutionException) ExecutionException(java.util.concurrent.ExecutionException) BriefingEmail(com.topcom.cms.yuqing.vo.email.BriefingEmail) Component(org.springframework.stereotype.Component) List(java.util.List) BriefingTask(com.topcom.cms.yuqing.domain.BriefingTask) BriefingTaskManager(com.topcom.cms.yuqing.service.BriefingTaskManager) JSONObject(net.sf.json.JSONObject) Contact(com.topcom.cms.yuqing.domain.Contact) Sender(com.topcom.cms.yuqing.task.sender.Sender) TemplateException(freemarker.template.TemplateException) IOException(java.io.IOException) BriefingEmail(com.topcom.cms.yuqing.vo.email.BriefingEmail) TemplateException(freemarker.template.TemplateException) BusinessException(com.topcom.cms.exception.BusinessException) IOException(java.io.IOException) JobExecutionException(org.quartz.JobExecutionException) ExecutionException(java.util.concurrent.ExecutionException) Contact(com.topcom.cms.yuqing.domain.Contact) Sender(com.topcom.cms.yuqing.task.sender.Sender) BusinessException(com.topcom.cms.exception.BusinessException) EmailSenderFactory(com.topcom.cms.yuqing.task.sender.factory.EmailSenderFactory) JSONObject(net.sf.json.JSONObject) SenderFactory(com.topcom.cms.yuqing.task.sender.factory.SenderFactory) EmailSenderFactory(com.topcom.cms.yuqing.task.sender.factory.EmailSenderFactory) BriefingTask(com.topcom.cms.yuqing.domain.BriefingTask) JobExecutionException(org.quartz.JobExecutionException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

BusinessException (com.topcom.cms.exception.BusinessException)1 BriefingTask (com.topcom.cms.yuqing.domain.BriefingTask)1 Contact (com.topcom.cms.yuqing.domain.Contact)1 BriefingTaskManager (com.topcom.cms.yuqing.service.BriefingTaskManager)1 Sender (com.topcom.cms.yuqing.task.sender.Sender)1 EmailSenderFactory (com.topcom.cms.yuqing.task.sender.factory.EmailSenderFactory)1 SenderFactory (com.topcom.cms.yuqing.task.sender.factory.SenderFactory)1 BriefingEmail (com.topcom.cms.yuqing.vo.email.BriefingEmail)1 TemplateException (freemarker.template.TemplateException)1 IOException (java.io.IOException)1 List (java.util.List)1 Set (java.util.Set)1 ExecutionException (java.util.concurrent.ExecutionException)1 Collectors (java.util.stream.Collectors)1 JSONObject (net.sf.json.JSONObject)1 Logger (org.jboss.logging.Logger)1 Job (org.quartz.Job)1 JobExecutionContext (org.quartz.JobExecutionContext)1 JobExecutionException (org.quartz.JobExecutionException)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1