use of com.topcom.cms.yuqing.domain.BriefingTask in project topcom-cloud by 545314690.
the class BriefingTaskController method findByUserId.
/**
* 查询当前登录用户的自定义专题
*
* @return 分页数据
*/
@RequestMapping(value = "/findByType", method = RequestMethod.POST, produces = "application/json")
@ResponseBody
public BriefingTask findByUserId(@CurrentUser User user, @RequestParam Briefing.BriefingType briefingType) {
List<BriefingTask> briefingTasks = briefingTaskManager.findByUserIdAndBriefingType(user.getId(), briefingType);
if (briefingTasks.size() > 0) {
BriefingTask briefingTask = briefingTasks.get(0);
briefingTask.setCronExpression(CronExpression.formCronString(briefingTask.getCron()));
return briefingTask;
} else {
return briefingTaskManager.createDefault(briefingType);
}
}
use of com.topcom.cms.yuqing.domain.BriefingTask in project topcom-cloud by 545314690.
the class BriefingTaskController method testCreate.
/**
* testCreate
*/
@RequestMapping(value = "/testCreate", method = RequestMethod.POST, produces = "application/json")
@ResponseBody
public Object testCreate(@CurrentUser User user, @RequestParam Briefing.BriefingType briefingType, @RequestParam Integer month, @RequestParam(required = false) Integer week) throws Exception {
BriefingTask briefingTask = findByUserId(user, briefingType);
Future future = briefingCreator.create(briefingTask, month, week);
return future.get();
}
use of com.topcom.cms.yuqing.domain.BriefingTask in project topcom-cloud by 545314690.
the class BriefingTaskWatcher method doAroundUpdate.
@Around("updateBriefingTask()")
public Object doAroundUpdate(ProceedingJoinPoint joinPoint) throws BusinessException {
Object[] args = joinPoint.getArgs();
if (args.length == 1) {
try {
Object proceed = joinPoint.proceed(args);
final BriefingTask briefingTask = (BriefingTask) proceed;
if (briefingTask != null) {
if (briefingTask.isEnable() == true) {
// 如果是开启
scheduleJob(briefingTask);
LogUtil.logger.info("更新任务:" + briefingTask.getBriefingType() + "成功");
} else {
// 如果是关闭
deleteJob(String.valueOf(briefingTask.getId()));
}
}
return briefingTask;
} catch (Throwable throwable) {
throwable.printStackTrace();
throw new BusinessException("更新失败");
}
}
return null;
}
use of com.topcom.cms.yuqing.domain.BriefingTask 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