forked from github/dataease
feat: 继续完善定时报告
This commit is contained in:
parent
7666335e43
commit
527446de2e
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>dataease-server</artifactId>
|
<artifactId>dataease-server</artifactId>
|
||||||
<groupId>io.dataease</groupId>
|
<groupId>io.dataease</groupId>
|
||||||
<version>1.4.0</version>
|
<version>1.5.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
@ -1,18 +1,27 @@
|
|||||||
package io.dataease.job.sechedule.strategy.impl;
|
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.service.AuthUserService;
|
||||||
|
import io.dataease.auth.util.JWTUtils;
|
||||||
|
import io.dataease.commons.utils.CodingUtil;
|
||||||
import io.dataease.commons.utils.CommonBeanFactory;
|
import io.dataease.commons.utils.CommonBeanFactory;
|
||||||
import io.dataease.job.sechedule.strategy.TaskHandler;
|
import io.dataease.job.sechedule.strategy.TaskHandler;
|
||||||
|
|
||||||
import io.dataease.plugins.common.entity.GlobalTaskEntity;
|
import io.dataease.plugins.common.entity.GlobalTaskEntity;
|
||||||
import io.dataease.plugins.common.entity.GlobalTaskInstance;
|
import io.dataease.plugins.common.entity.GlobalTaskInstance;
|
||||||
import io.dataease.plugins.config.SpringContextUtil;
|
import io.dataease.plugins.config.SpringContextUtil;
|
||||||
|
import io.dataease.plugins.xpack.email.dto.response.XpackEmailTemplateDTO;
|
||||||
import io.dataease.plugins.xpack.email.service.EmailXpackService;
|
import io.dataease.plugins.xpack.email.service.EmailXpackService;
|
||||||
import org.quartz.*;
|
import org.quartz.*;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class EmailTaskHandler extends TaskHandler implements Job {
|
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 static final Integer RUNING = 0;
|
||||||
|
|
||||||
|
|
||||||
|
private AuthUserService authUserService;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected JobDataMap jobDataMap(GlobalTaskEntity taskEntity) {
|
protected JobDataMap jobDataMap(GlobalTaskEntity taskEntity) {
|
||||||
JobDataMap jobDataMap = new JobDataMap();
|
JobDataMap jobDataMap = new JobDataMap();
|
||||||
jobDataMap.put("taskEntity", taskEntity);
|
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;
|
return jobDataMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,7 +57,15 @@ public class EmailTaskHandler extends TaskHandler implements Job {
|
|||||||
GlobalTaskInstance taskInstance = buildInstance(taskEntity);
|
GlobalTaskInstance taskInstance = buildInstance(taskEntity);
|
||||||
Long instanceId = saveInstance(taskInstance);
|
Long instanceId = saveInstance(taskInstance);
|
||||||
taskInstance.setInstanceId(instanceId);
|
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;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package io.dataease.plugins.server;
|
|||||||
|
|
||||||
import com.github.pagehelper.Page;
|
import com.github.pagehelper.Page;
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
|
import io.dataease.commons.utils.AuthUtils;
|
||||||
import io.dataease.commons.utils.BeanUtils;
|
import io.dataease.commons.utils.BeanUtils;
|
||||||
import io.dataease.commons.utils.PageUtils;
|
import io.dataease.commons.utils.PageUtils;
|
||||||
import io.dataease.commons.utils.Pager;
|
import io.dataease.commons.utils.Pager;
|
||||||
@ -42,6 +43,7 @@ public class XEmailTaskServer {
|
|||||||
public void save(@RequestBody XpackEmailCreate param) throws Exception{
|
public void save(@RequestBody XpackEmailCreate param) throws Exception{
|
||||||
XpackEmailTaskRequest request = param.fillContent();
|
XpackEmailTaskRequest request = param.fillContent();
|
||||||
EmailXpackService emailXpackService = SpringContextUtil.getBean(EmailXpackService.class);
|
EmailXpackService emailXpackService = SpringContextUtil.getBean(EmailXpackService.class);
|
||||||
|
request.setCreator(AuthUtils.getUser().getUserId());
|
||||||
emailXpackService.save(request);
|
emailXpackService.save(request);
|
||||||
GlobalTaskEntity globalTask = BeanUtils.copyBean(new GlobalTaskEntity(), request);
|
GlobalTaskEntity globalTask = BeanUtils.copyBean(new GlobalTaskEntity(), request);
|
||||||
scheduleService.addSchedule(globalTask);
|
scheduleService.addSchedule(globalTask);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>dataease-server</artifactId>
|
<artifactId>dataease-server</artifactId>
|
||||||
<groupId>io.dataease</groupId>
|
<groupId>io.dataease</groupId>
|
||||||
<version>1.4.0</version>
|
<version>1.5.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
2
pom.xml
2
pom.xml
@ -4,7 +4,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>io.dataease</groupId>
|
<groupId>io.dataease</groupId>
|
||||||
<artifactId>dataease-server</artifactId>
|
<artifactId>dataease-server</artifactId>
|
||||||
<version>1.4.0</version>
|
<version>1.5.0</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
|
Loading…
Reference in New Issue
Block a user