feat: 继续完善定时报告

This commit is contained in:
fit2cloud-chenyw 2021-11-20 22:11:27 +08:00
parent 7666335e43
commit 527446de2e
5 changed files with 58 additions and 8 deletions

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>dataease-server</artifactId>
<groupId>io.dataease</groupId>
<version>1.4.0</version>
<version>1.5.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -1,18 +1,27 @@
package io.dataease.job.sechedule.strategy.impl;
import io.dataease.auth.entity.SysUserEntity;
import io.dataease.auth.entity.TokenInfo;
import io.dataease.auth.service.AuthUserService;
import io.dataease.auth.util.JWTUtils;
import io.dataease.commons.utils.CodingUtil;
import io.dataease.commons.utils.CommonBeanFactory;
import io.dataease.job.sechedule.strategy.TaskHandler;
import io.dataease.plugins.common.entity.GlobalTaskEntity;
import io.dataease.plugins.common.entity.GlobalTaskInstance;
import io.dataease.plugins.config.SpringContextUtil;
import io.dataease.plugins.xpack.email.dto.response.XpackEmailTemplateDTO;
import io.dataease.plugins.xpack.email.service.EmailXpackService;
import org.quartz.*;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import java.net.InetAddress;
import java.net.UnknownHostException;
@Service
public class EmailTaskHandler extends TaskHandler implements Job {
@ -21,12 +30,19 @@ public class EmailTaskHandler extends TaskHandler implements Job {
private static final Integer RUNING = 0;
private AuthUserService authUserService;
@Override
protected JobDataMap jobDataMap(GlobalTaskEntity taskEntity) {
JobDataMap jobDataMap = new JobDataMap();
jobDataMap.put("taskEntity", taskEntity);
EmailXpackService emailXpackService = SpringContextUtil.getBean(EmailXpackService.class);
XpackEmailTemplateDTO emailTemplateDTO = emailXpackService.emailTemplate(taskEntity.getTaskId());
jobDataMap.put("emailTemplate", emailTemplateDTO);
SysUserEntity creator = CommonBeanFactory.getBean(AuthUserService.class).getUserById(taskEntity.getCreator());
jobDataMap.put("creator", creator);
return jobDataMap;
}
@ -41,7 +57,15 @@ public class EmailTaskHandler extends TaskHandler implements Job {
GlobalTaskInstance taskInstance = buildInstance(taskEntity);
Long instanceId = saveInstance(taskInstance);
taskInstance.setInstanceId(instanceId);
proxy().printImage(taskEntity, taskInstance);
XpackEmailTemplateDTO emailTemplate = (XpackEmailTemplateDTO) jobDataMap.get("emailTemplate");
SysUserEntity creator = (SysUserEntity) jobDataMap.get("creator");
proxy().sendReport(taskEntity, taskInstance, emailTemplate, creator);
}
@ -62,13 +86,37 @@ public class EmailTaskHandler extends TaskHandler implements Job {
return taskInstance;
}
@Async
public void printImage(GlobalTaskEntity taskEntity, GlobalTaskInstance taskInstance) {
EmailXpackService emailXpackService = SpringContextUtil.getBean(EmailXpackService.class);
emailXpackService.executeJob(taskEntity, taskInstance);
@Async
public void sendReport(GlobalTaskEntity taskEntity, GlobalTaskInstance taskInstance, XpackEmailTemplateDTO emailTemplateDTO, SysUserEntity user) {
EmailXpackService emailXpackService = SpringContextUtil.getBean(EmailXpackService.class);
String fileId = emailXpackService.print(panelUrl(emailTemplateDTO.getPanelId()), tokenByUser(user));
// 下面继续执行发送邮件的略记
String recipients = emailTemplateDTO.getRecipients();
byte[] content = emailTemplateDTO.getContent();
}
private String tokenByUser(SysUserEntity user) {
TokenInfo tokenInfo = TokenInfo.builder().userId(user.getUserId()).username(user.getUsername()).build();
String token = JWTUtils.sign(tokenInfo, user.getPassword());
return token;
}
private String panelUrl(String panelId) {
InetAddress ip = null;
try {
ip = InetAddress.getLocalHost();
} catch (UnknownHostException e) {
e.printStackTrace();
}
Environment environment = SpringContextUtil.getBean(Environment.class);
Integer port = environment.getProperty("server.port", Integer.class);
String url = "http://" + ip + ":"+port + "/#/preview/" + panelId;
return url;
}
}

View File

@ -3,6 +3,7 @@ package io.dataease.plugins.server;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.dataease.commons.utils.AuthUtils;
import io.dataease.commons.utils.BeanUtils;
import io.dataease.commons.utils.PageUtils;
import io.dataease.commons.utils.Pager;
@ -42,6 +43,7 @@ public class XEmailTaskServer {
public void save(@RequestBody XpackEmailCreate param) throws Exception{
XpackEmailTaskRequest request = param.fillContent();
EmailXpackService emailXpackService = SpringContextUtil.getBean(EmailXpackService.class);
request.setCreator(AuthUtils.getUser().getUserId());
emailXpackService.save(request);
GlobalTaskEntity globalTask = BeanUtils.copyBean(new GlobalTaskEntity(), request);
scheduleService.addSchedule(globalTask);

View File

@ -6,7 +6,7 @@
<parent>
<artifactId>dataease-server</artifactId>
<groupId>io.dataease</groupId>
<version>1.4.0</version>
<version>1.5.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.dataease</groupId>
<artifactId>dataease-server</artifactId>
<version>1.4.0</version>
<version>1.5.0</version>
<packaging>pom</packaging>
<parent>