forked from github/dataease
Merge pull request #1259 from dataease/pr@dev@refactor_format_code_style
refactor: 格式化代码
This commit is contained in:
commit
ee4fe0cb7f
@ -5,7 +5,6 @@ import io.dataease.plugins.config.SpringContextUtil;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.net.InetAddress;
|
||||
@ -13,26 +12,26 @@ import java.net.UnknownHostException;
|
||||
|
||||
public class ServletUtils {
|
||||
|
||||
public static HttpServletRequest request(){
|
||||
public static HttpServletRequest request() {
|
||||
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
HttpServletRequest request = servletRequestAttributes.getRequest();
|
||||
return request;
|
||||
}
|
||||
|
||||
public static HttpServletResponse response(){
|
||||
public static HttpServletResponse response() {
|
||||
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
HttpServletResponse response = servletRequestAttributes.getResponse();
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
public static void setToken(String token){
|
||||
public static void setToken(String token) {
|
||||
HttpServletResponse httpServletResponse = response();
|
||||
httpServletResponse.addHeader("Access-Control-Expose-Headers", "Authorization");
|
||||
httpServletResponse.setHeader(AuthConstants.TOKEN_KEY, token);
|
||||
}
|
||||
|
||||
public static String getToken(){
|
||||
public static String getToken() {
|
||||
HttpServletRequest request = request();
|
||||
String token = request.getHeader(AuthConstants.TOKEN_KEY);
|
||||
return token;
|
||||
@ -49,10 +48,8 @@ public class ServletUtils {
|
||||
}
|
||||
Environment environment = SpringContextUtil.getBean(Environment.class);
|
||||
Integer port = environment.getProperty("server.port", Integer.class);
|
||||
return "http://" + hostAddress + ":"+port ;
|
||||
return "http://" + hostAddress + ":" + port;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import io.dataease.plugins.common.entity.GlobalTaskEntity;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.quartz.*;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
@ -31,17 +32,17 @@ public abstract class TaskHandler implements InitializingBean {
|
||||
}
|
||||
Class executor = this.getClass();
|
||||
String cron = cron(taskEntity);
|
||||
scheduleManager.addOrUpdateCronJob(jobKey, triggerKey, executor , cron, start, end, jobDataMap(taskEntity));
|
||||
scheduleManager.addOrUpdateCronJob(jobKey, triggerKey, executor, cron, start, end, jobDataMap(taskEntity));
|
||||
}
|
||||
|
||||
|
||||
protected abstract JobDataMap jobDataMap( GlobalTaskEntity taskEntity);
|
||||
protected abstract JobDataMap jobDataMap(GlobalTaskEntity taskEntity);
|
||||
|
||||
private String cron(GlobalTaskEntity taskEntity) {
|
||||
if(taskEntity.getRateType() == -1) {
|
||||
if (taskEntity.getRateType() == -1) {
|
||||
return taskEntity.getRateVal();
|
||||
}
|
||||
SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" );
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
Date date = null;
|
||||
try {
|
||||
@ -55,22 +56,22 @@ public abstract class TaskHandler implements InitializingBean {
|
||||
if (taskEntity.getRateType() == 0) {
|
||||
return
|
||||
instance.get(Calendar.SECOND) + " " +
|
||||
instance.get(Calendar.MINUTE) + " " +
|
||||
instance.get(Calendar.HOUR_OF_DAY) + " * * ?";
|
||||
instance.get(Calendar.MINUTE) + " " +
|
||||
instance.get(Calendar.HOUR_OF_DAY) + " * * ?";
|
||||
}
|
||||
if (taskEntity.getRateType() == 1) {
|
||||
return
|
||||
instance.get(Calendar.SECOND) + " " +
|
||||
instance.get(Calendar.MINUTE) + " " +
|
||||
instance.get(Calendar.HOUR_OF_DAY) + " ? * " +
|
||||
getDayOfWeek(instance);
|
||||
instance.get(Calendar.MINUTE) + " " +
|
||||
instance.get(Calendar.HOUR_OF_DAY) + " ? * " +
|
||||
getDayOfWeek(instance);
|
||||
}
|
||||
if (taskEntity.getRateType() == 2) {
|
||||
return
|
||||
instance.get(Calendar.SECOND) + " " +
|
||||
instance.get(Calendar.MINUTE) + " " +
|
||||
instance.get(Calendar.HOUR_OF_DAY) + " " +
|
||||
instance.get(Calendar.DATE) + " * ?";
|
||||
instance.get(Calendar.MINUTE) + " " +
|
||||
instance.get(Calendar.HOUR_OF_DAY) + " " +
|
||||
instance.get(Calendar.DATE) + " * ?";
|
||||
}
|
||||
|
||||
return null;
|
||||
@ -82,20 +83,18 @@ public abstract class TaskHandler implements InitializingBean {
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void removeTask(ScheduleManager scheduleManager, GlobalTaskEntity taskEntity){
|
||||
public void removeTask(ScheduleManager scheduleManager, GlobalTaskEntity taskEntity) {
|
||||
JobKey jobKey = new JobKey(taskEntity.getTaskId().toString());
|
||||
TriggerKey triggerKey = new TriggerKey(taskEntity.getTaskId().toString());
|
||||
scheduleManager.removeJob(jobKey, triggerKey);
|
||||
}
|
||||
|
||||
public void executeTask(ScheduleManager scheduleManager, GlobalTaskEntity taskEntity) throws Exception{
|
||||
public void executeTask(ScheduleManager scheduleManager, GlobalTaskEntity taskEntity) throws Exception {
|
||||
JobKey jobKey = new JobKey(taskEntity.getTaskId().toString());
|
||||
scheduleManager.fireNow(jobKey);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//判断任务是否过期
|
||||
public Boolean taskExpire(Long endTime) {
|
||||
if (ObjectUtils.isEmpty(endTime)) return false;
|
||||
@ -108,12 +107,12 @@ public abstract class TaskHandler implements InitializingBean {
|
||||
String beanName = null;
|
||||
String className = this.getClass().getName();
|
||||
className = className.substring(className.lastIndexOf(".") + 1);
|
||||
if(className.length() > 1) {
|
||||
if (className.length() > 1) {
|
||||
beanName = className.substring(0, 1).toLowerCase() + className.substring(1);
|
||||
} else {
|
||||
beanName = className.toLowerCase();
|
||||
}
|
||||
TaskStrategyFactory.register( beanName, this);
|
||||
TaskStrategyFactory.register(beanName, this);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
package io.dataease.job.sechedule.strategy;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class TaskStrategyFactory {
|
||||
|
||||
|
||||
|
||||
private static Map<String, TaskHandler> strategyMap = new ConcurrentHashMap<>();
|
||||
|
||||
public static TaskHandler getInvokeStrategy(String name) {
|
||||
|
@ -46,9 +46,7 @@ public class EmailTaskHandler extends TaskHandler implements Job {
|
||||
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());*/
|
||||
SysUserEntity creator =authUserServiceImpl.getUserByIdNoCache(taskEntity.getCreator());
|
||||
SysUserEntity creator = authUserServiceImpl.getUserByIdNoCache(taskEntity.getCreator());
|
||||
jobDataMap.put("creator", creator);
|
||||
return jobDataMap;
|
||||
}
|
||||
@ -56,10 +54,10 @@ public class EmailTaskHandler extends TaskHandler implements Job {
|
||||
@Override
|
||||
public void execute(JobExecutionContext context) throws JobExecutionException {
|
||||
// 插件没有加载 空转
|
||||
if(!CommonBeanFactory.getBean(AuthUserService.class).pluginLoaded()) return;
|
||||
if (!CommonBeanFactory.getBean(AuthUserService.class).pluginLoaded()) return;
|
||||
|
||||
JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
|
||||
GlobalTaskEntity taskEntity = (GlobalTaskEntity)jobDataMap.get("taskEntity");
|
||||
GlobalTaskEntity taskEntity = (GlobalTaskEntity) jobDataMap.get("taskEntity");
|
||||
if (taskExpire(taskEntity.getEndTime())) {
|
||||
ScheduleManager scheduleManager = SpringContextUtil.getBean(ScheduleManager.class);
|
||||
removeTask(scheduleManager, taskEntity);
|
||||
@ -81,7 +79,7 @@ public class EmailTaskHandler extends TaskHandler implements Job {
|
||||
return CommonBeanFactory.getBean(EmailTaskHandler.class);
|
||||
}
|
||||
|
||||
public Long saveInstance(GlobalTaskInstance taskInstance){
|
||||
public Long saveInstance(GlobalTaskInstance taskInstance) {
|
||||
EmailXpackService emailXpackService = SpringContextUtil.getBean(EmailXpackService.class);
|
||||
return emailXpackService.saveInstance(taskInstance);
|
||||
}
|
||||
@ -109,11 +107,10 @@ public class EmailTaskHandler extends TaskHandler implements Job {
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Async
|
||||
public void sendReport(GlobalTaskInstance taskInstance, XpackEmailTemplateDTO emailTemplateDTO, SysUserEntity user) {
|
||||
EmailXpackService emailXpackService = SpringContextUtil.getBean(EmailXpackService.class);
|
||||
try{
|
||||
try {
|
||||
byte[] bytes = emailXpackService.printData(panelUrl(emailTemplateDTO.getPanelId()), tokenByUser(user), buildPixel(emailTemplateDTO));
|
||||
// 下面继续执行发送邮件的
|
||||
String recipients = emailTemplateDTO.getRecipients();
|
||||
@ -125,7 +122,7 @@ public class EmailTaskHandler extends TaskHandler implements Job {
|
||||
}
|
||||
emailService.sendWithImage(recipients, emailTemplateDTO.getTitle(), contentStr, bytes);
|
||||
success(taskInstance);
|
||||
}catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
error(taskInstance, e);
|
||||
LogUtil.error(e.getMessage(), e);
|
||||
}
|
||||
@ -143,14 +140,12 @@ public class EmailTaskHandler extends TaskHandler implements Job {
|
||||
pixelEntity.setX(String.valueOf(x));
|
||||
pixelEntity.setY(String.valueOf(y));
|
||||
return pixelEntity;
|
||||
}catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private String tokenByUser(SysUserEntity user) {
|
||||
TokenInfo tokenInfo = TokenInfo.builder().userId(user.getUserId()).username(user.getUsername()).build();
|
||||
String token = JWTUtils.sign(tokenInfo, user.getPassword());
|
||||
|
@ -22,6 +22,7 @@ import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Api(tags = "xpack:定时报告")
|
||||
@ -42,7 +43,7 @@ public class XEmailTaskServer {
|
||||
}
|
||||
|
||||
@PostMapping("/save")
|
||||
public void save(@RequestBody XpackEmailCreate param) throws Exception{
|
||||
public void save(@RequestBody XpackEmailCreate param) throws Exception {
|
||||
XpackEmailTaskRequest request = param.fillContent();
|
||||
EmailXpackService emailXpackService = SpringContextUtil.getBean(EmailXpackService.class);
|
||||
request.setCreator(AuthUtils.getUser().getUserId());
|
||||
@ -59,7 +60,7 @@ public class XEmailTaskServer {
|
||||
XpackEmailCreate xpackEmailCreate = new XpackEmailCreate();
|
||||
byte[] bytes = taskForm.getContent();
|
||||
|
||||
if(ObjectUtils.isNotEmpty(bytes)) {
|
||||
if (ObjectUtils.isNotEmpty(bytes)) {
|
||||
String emailContent;
|
||||
try {
|
||||
emailContent = new String(bytes, "UTF-8");
|
||||
@ -91,8 +92,8 @@ public class XEmailTaskServer {
|
||||
}
|
||||
String imageUrl = "/system/ui/image/" + fileId;
|
||||
String html = "<div>" +
|
||||
"<h2>"+content+"</h2>" +
|
||||
"<img style='width: 100%;' id='"+panelId+"' src='"+imageUrl+"' />" +
|
||||
"<h2>" + content + "</h2>" +
|
||||
"<img style='width: 100%;' id='" + panelId + "' src='" + imageUrl + "' />" +
|
||||
"</div>";
|
||||
|
||||
return html;
|
||||
@ -141,7 +142,7 @@ public class XEmailTaskServer {
|
||||
result.setX(String.valueOf(x));
|
||||
result.setY(String.valueOf(y));
|
||||
return result;
|
||||
}catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,6 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.mail.javamail.JavaMailSenderImpl;
|
||||
import org.springframework.mail.javamail.MimeMessageHelper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.activation.DataHandler;
|
||||
import javax.annotation.Resource;
|
||||
import javax.mail.Message;
|
||||
@ -49,18 +48,16 @@ public class EmailService {
|
||||
private static final String SMTP_CONNECTIONTIMEOUT_VAL = "5000";
|
||||
|
||||
|
||||
|
||||
@Resource
|
||||
private SystemParameterMapper systemParameterMapper;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param to 收件人
|
||||
* @param title 标题
|
||||
* @param content 内容
|
||||
*/
|
||||
public void send(String to, String title, String content) {
|
||||
if (StringUtils.isBlank(to)) return ;
|
||||
if (StringUtils.isBlank(to)) return;
|
||||
MailInfo mailInfo = proxy().mailInfo();
|
||||
JavaMailSenderImpl driver = driver(mailInfo);
|
||||
|
||||
@ -69,7 +66,7 @@ public class EmailService {
|
||||
try {
|
||||
helper = new MimeMessageHelper(mimeMessage, true);
|
||||
helper.setFrom(driver.getUsername());
|
||||
helper.setSubject(title );
|
||||
helper.setSubject(title);
|
||||
helper.setText(content, true);
|
||||
helper.setTo(to);
|
||||
driver.send(mimeMessage);
|
||||
@ -80,7 +77,7 @@ public class EmailService {
|
||||
}
|
||||
|
||||
public void sendWithImage(String to, String title, String content, byte[] bytes) {
|
||||
if (StringUtils.isBlank(to)) return ;
|
||||
if (StringUtils.isBlank(to)) return;
|
||||
MailInfo mailInfo = proxy().mailInfo();
|
||||
JavaMailSenderImpl driver = driver(mailInfo);
|
||||
MimeMessage mimeMessage = driver.createMimeMessage();
|
||||
@ -92,7 +89,7 @@ public class EmailService {
|
||||
MimeBodyPart text = new MimeBodyPart();
|
||||
try {
|
||||
|
||||
text.setContent("<h2>"+content+"</h2>" + "<br/><img src='cid:"+uuid+"' />", "text/html; charset=gb2312");
|
||||
text.setContent("<h2>" + content + "</h2>" + "<br/><img src='cid:" + uuid + "' />", "text/html; charset=gb2312");
|
||||
image.setDataHandler(png);
|
||||
image.setContentID(uuid);
|
||||
MimeMultipart multipart = new MimeMultipart();
|
||||
@ -107,7 +104,6 @@ public class EmailService {
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e.getMessage(), e);
|
||||
throw new RuntimeException(e);
|
||||
// DEException.throwException(Translator.get("connection_failed"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -215,13 +211,13 @@ public class EmailService {
|
||||
LogUtil.error(e.getMessage(), e);
|
||||
DEException.throwException(Translator.get("connection_failed"));
|
||||
}
|
||||
if(!StringUtils.isBlank(recipients)){
|
||||
if (!StringUtils.isBlank(recipients)) {
|
||||
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
|
||||
MimeMessageHelper helper;
|
||||
try {
|
||||
helper = new MimeMessageHelper(mimeMessage, true);
|
||||
helper.setFrom(javaMailSender.getUsername());
|
||||
helper.setSubject("DataEase测试邮件 " );
|
||||
helper.setSubject("DataEase测试邮件 ");
|
||||
helper.setText("这是一封测试邮件,邮件发送成功", true);
|
||||
helper.setTo(recipients);
|
||||
javaMailSender.send(mimeMessage);
|
||||
|
Loading…
Reference in New Issue
Block a user