From 459fc98be062c193846aa6446041b8c2ffd482d1 Mon Sep 17 00:00:00 2001 From: fit2cloud-chenyw Date: Mon, 19 Sep 2022 16:04:43 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E7=B3=BB=E7=BB=9F=E7=AE=A1=E7=90=86-?= =?UTF-8?q?=E5=AE=9A=E6=97=B6=E6=8A=A5=E5=91=8A):=20=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E6=8A=A5=E5=91=8A=E6=94=B6=E4=BB=B6=E4=BA=BA=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../strategy/impl/EmailTaskHandler.java | 66 +++++++++++++++---- .../main/resources/db/migration/V40__1.15.sql | 4 ++ 2 files changed, 57 insertions(+), 13 deletions(-) diff --git a/backend/src/main/java/io/dataease/job/sechedule/strategy/impl/EmailTaskHandler.java b/backend/src/main/java/io/dataease/job/sechedule/strategy/impl/EmailTaskHandler.java index 6b7becc484..2833af3d71 100644 --- a/backend/src/main/java/io/dataease/job/sechedule/strategy/impl/EmailTaskHandler.java +++ b/backend/src/main/java/io/dataease/job/sechedule/strategy/impl/EmailTaskHandler.java @@ -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 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,38 +211,61 @@ public class EmailTaskHandler extends TaskHandler implements Job { channels = Arrays.stream(recisetting.split(",")).collect(Collectors.toList()); } - List 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()) { - WecomXpackService wecomXpackService = SpringContextUtil.getBean(WecomXpackService.class); - WecomMsgResult wecomMsgResult = wecomXpackService.pushOaMsg(reciLists, emailTemplateDTO.getTitle(), contentStr, bytes, files); - if (wecomMsgResult.getErrcode() != 0) { - DEException.throwException(wecomMsgResult.getErrmsg()); + + List 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(wecomUsers, emailTemplateDTO.getTitle(), contentStr, bytes, files); + if (wecomMsgResult.getErrcode() != 0) { + DEException.throwException(wecomMsgResult.getErrmsg()); + } } + } break; case "dingtalk" : if (SpringContextUtil.getBean(AuthUserService.class).supportDingtalk()) { - DingtalkXpackService dingtalkXpackService = SpringContextUtil.getBean(DingtalkXpackService.class); - DingtalkMsgResult dingtalkMsgResult = dingtalkXpackService.pushOaMsg(reciLists, emailTemplateDTO.getTitle(), contentStr, bytes, files); - if (dingtalkMsgResult.getErrcode() != 0) { - DEException.throwException(dingtalkMsgResult.getErrmsg()); + List 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(dingTalkUsers, emailTemplateDTO.getTitle(), contentStr, bytes, files); + if (dingtalkMsgResult.getErrcode() != 0) { + DEException.throwException(dingtalkMsgResult.getErrmsg()); + } } + } break; case "lark" : if (SpringContextUtil.getBean(AuthUserService.class).supportLark()) { - LarkXpackService larkXpackService = SpringContextUtil.getBean(LarkXpackService.class); - LarkMsgResult larkMsgResult = larkXpackService.pushOaMsg(reciLists, emailTemplateDTO.getTitle(), contentStr, bytes, files); - if (larkMsgResult.getCode() != 0) { - DEException.throwException(larkMsgResult.getMsg()); + List 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(larkUsers, emailTemplateDTO.getTitle(), contentStr, bytes, files); + if (larkMsgResult.getCode() != 0) { + DEException.throwException(larkMsgResult.getMsg()); + } } + } break; default: diff --git a/backend/src/main/resources/db/migration/V40__1.15.sql b/backend/src/main/resources/db/migration/V40__1.15.sql index 0399731308..37325010ad 100644 --- a/backend/src/main/resources/db/migration/V40__1.15.sql +++ b/backend/src/main/resources/db/migration/V40__1.15.sql @@ -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`; \ No newline at end of file