fix(系统管理-定时报告): 定时报告收件人逻辑

This commit is contained in:
fit2cloud-chenyw 2022-09-19 16:04:43 +08:00
parent 633f04e604
commit 459fc98be0
2 changed files with 57 additions and 13 deletions

View File

@ -29,6 +29,7 @@ import io.dataease.plugins.xpack.wecom.dto.entity.WecomMsgResult;
import io.dataease.plugins.xpack.wecom.service.WecomXpackService;
import io.dataease.service.chart.ViewExportExcel;
import io.dataease.service.system.EmailService;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.quartz.*;
@ -152,6 +153,7 @@ public class EmailTaskHandler extends TaskHandler implements Job {
public void sendReport(GlobalTaskInstance taskInstance, XpackEmailTemplateDTO emailTemplateDTO, SysUserEntity user) {
EmailXpackService emailXpackService = SpringContextUtil.getBean(EmailXpackService.class);
AuthUserServiceImpl userService = SpringContextUtil.getBean(AuthUserServiceImpl.class);
try {
XpackEmailTaskRequest taskForm = emailXpackService.taskForm(taskInstance.getTaskId());
if (ObjectUtils.isEmpty(taskForm) || CronUtils.taskExpire(taskForm.getEndTime())) {
@ -168,6 +170,21 @@ public class EmailTaskHandler extends TaskHandler implements Job {
LogUtil.info("picture of " + url + " is finished");
// 下面继续执行发送邮件的
String recipients = emailTemplateDTO.getRecipients();
String reciUsers = emailTemplateDTO.getReciUsers();
List<String> reciLists = null;
if (StringUtils.isNotBlank(reciUsers)) {
String emailUsers = Arrays.stream(reciUsers.split(",")).map(userService::getUserByName).filter(tempUser -> StringUtils.isNotBlank(tempUser.getEmail())).map(SysUserEntity::getEmail).collect(Collectors.joining(","));
if (StringUtils.isNotBlank(emailUsers)) {
if (StringUtils.isNotBlank(recipients)) {
recipients += "," + emailUsers;
} else {
recipients = emailUsers;
}
}
reciLists = Arrays.stream(reciUsers.split(",")).collect(Collectors.toList());
}
byte[] content = emailTemplateDTO.getContent();
EmailService emailService = SpringContextUtil.getBean(EmailService.class);
@ -194,39 +211,62 @@ public class EmailTaskHandler extends TaskHandler implements Job {
channels = Arrays.stream(recisetting.split(",")).collect(Collectors.toList());
}
List<String> reciLists = Arrays.stream(recipients.split(",")).collect(Collectors.toList());
for (int i = 0; i < channels.size(); i++) {
String channel = channels.get(i);
switch (channel) {
case "email" :
if (StringUtils.isNotBlank(recipients))
emailService.sendWithImageAndFiles(recipients, emailTemplateDTO.getTitle(), contentStr, bytes, files);
break;
case "wecom" :
if (SpringContextUtil.getBean(AuthUserService.class).supportWecom()) {
List<String> wecomUsers = reciLists.stream().filter(reci -> {
SysUserEntity userBySub = userService.getUserBySub(reci, 4);
return ObjectUtils.isNotEmpty(userBySub);
}).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(wecomUsers)) {
WecomXpackService wecomXpackService = SpringContextUtil.getBean(WecomXpackService.class);
WecomMsgResult wecomMsgResult = wecomXpackService.pushOaMsg(reciLists, emailTemplateDTO.getTitle(), contentStr, bytes, files);
WecomMsgResult wecomMsgResult = wecomXpackService.pushOaMsg(wecomUsers, emailTemplateDTO.getTitle(), contentStr, bytes, files);
if (wecomMsgResult.getErrcode() != 0) {
DEException.throwException(wecomMsgResult.getErrmsg());
}
}
}
break;
case "dingtalk" :
if (SpringContextUtil.getBean(AuthUserService.class).supportDingtalk()) {
List<String> dingTalkUsers = reciLists.stream().filter(reci -> {
SysUserEntity userBySub = userService.getUserBySub(reci, 5);
return ObjectUtils.isNotEmpty(userBySub);
}).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(dingTalkUsers)) {
DingtalkXpackService dingtalkXpackService = SpringContextUtil.getBean(DingtalkXpackService.class);
DingtalkMsgResult dingtalkMsgResult = dingtalkXpackService.pushOaMsg(reciLists, emailTemplateDTO.getTitle(), contentStr, bytes, files);
DingtalkMsgResult dingtalkMsgResult = dingtalkXpackService.pushOaMsg(dingTalkUsers, emailTemplateDTO.getTitle(), contentStr, bytes, files);
if (dingtalkMsgResult.getErrcode() != 0) {
DEException.throwException(dingtalkMsgResult.getErrmsg());
}
}
}
break;
case "lark" :
if (SpringContextUtil.getBean(AuthUserService.class).supportLark()) {
List<String> larkUsers = reciLists.stream().filter(reci -> {
SysUserEntity userBySub = userService.getUserBySub(reci, 6);
return ObjectUtils.isNotEmpty(userBySub);
}).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(larkUsers)) {
LarkXpackService larkXpackService = SpringContextUtil.getBean(LarkXpackService.class);
LarkMsgResult larkMsgResult = larkXpackService.pushOaMsg(reciLists, emailTemplateDTO.getTitle(), contentStr, bytes, files);
LarkMsgResult larkMsgResult = larkXpackService.pushOaMsg(larkUsers, emailTemplateDTO.getTitle(), contentStr, bytes, files);
if (larkMsgResult.getCode() != 0) {
DEException.throwException(larkMsgResult.getMsg());
}
}
}
break;
default:
break;

View File

@ -64,3 +64,7 @@ ALTER TABLE `sys_task_email`
ADD COLUMN `recisetting` varchar(255) NULL COMMENT '消息渠道' AFTER `view_ids`,
ADD COLUMN `conditions` longtext NULL COMMENT '仪表板条件' AFTER `recisetting`;
ALTER TABLE `sys_task_email`
ADD COLUMN `reci_users` varchar(255) NULL COMMENT '接收人账号' AFTER `conditions`;