From 6ece4076eb68e07b62bcd133cbbd4b8c3d3b165c Mon Sep 17 00:00:00 2001 From: wans <747101512@qq.com> Date: Fri, 15 Apr 2022 11:25:02 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=94=B6=E4=BB=B6?= =?UTF-8?q?=E4=BA=BA=E6=98=BE=E7=A4=BA=E9=94=99=E8=AF=AF=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../systemoa/service/mail/impl/MailServiceImpl.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/cn/com/tenlion/systemoa/service/mail/impl/MailServiceImpl.java b/src/main/java/cn/com/tenlion/systemoa/service/mail/impl/MailServiceImpl.java index 8198250..b9f225c 100644 --- a/src/main/java/cn/com/tenlion/systemoa/service/mail/impl/MailServiceImpl.java +++ b/src/main/java/cn/com/tenlion/systemoa/service/mail/impl/MailServiceImpl.java @@ -12,7 +12,9 @@ import ink.wgink.common.base.DefaultBaseService; import ink.wgink.common.component.SecurityComponent; import ink.wgink.pojo.ListPage; import ink.wgink.pojo.bos.UserInfoBO; +import ink.wgink.pojo.dtos.user.UserDTO; import ink.wgink.pojo.result.SuccessResultList; +import ink.wgink.service.user.service.IUserService; import ink.wgink.util.UUIDUtil; import ink.wgink.util.date.DateUtil; import ink.wgink.util.map.HashMapUtil; @@ -36,6 +38,8 @@ public class MailServiceImpl extends DefaultBaseService implements IMailService private IMailDao mailDao; @Autowired private SecurityComponent securityComponent; + @Autowired + private IUserService userService; @Override @@ -133,7 +137,8 @@ public class MailServiceImpl extends DefaultBaseService implements IMailService } } } - dto.setCreatorNames(currentUser.getUserUsername() + "[" + currentUser.getUserName() + "]"); + UserDTO sendDto = userService.get(dto.getCreator()); + dto.setCreatorNames(sendDto.getUserUsername() + "[" + sendDto.getUserName() + "]"); String spx = "




在 "+ dto.getGmtCreate() + ", " +""+ currentUser.getUserUsername() + " [" + currentUser.getUserName() + "] 写道:" +"

" + "


"; From a2ac8e6dc06cabe98093e1bf2c39031c2ae6d604 Mon Sep 17 00:00:00 2001 From: cuibaocheng Date: Fri, 15 Apr 2022 17:39:50 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E6=97=A5?= =?UTF-8?q?=E7=A8=8B=E7=AE=A1=E7=90=86=E5=AE=9A=E6=97=B6=E5=8F=91=E9=80=81?= =?UTF-8?q?=E7=9F=AD=E4=BF=A1=E9=80=9A=E7=9F=A5/=E9=82=AE=E4=BB=B6?= =?UTF-8?q?=E9=80=9A=E7=9F=A5/=E7=AB=99=E5=86=85=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../systemoa/task/ScheduleMessage.java | 138 ++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 src/main/java/cn/com/tenlion/systemoa/task/ScheduleMessage.java diff --git a/src/main/java/cn/com/tenlion/systemoa/task/ScheduleMessage.java b/src/main/java/cn/com/tenlion/systemoa/task/ScheduleMessage.java new file mode 100644 index 0000000..3372e20 --- /dev/null +++ b/src/main/java/cn/com/tenlion/systemoa/task/ScheduleMessage.java @@ -0,0 +1,138 @@ +package cn.com.tenlion.systemoa.task; + +import cn.com.tenlion.schedule.pojo.dtos.schedule.ScheduleDTO; +import cn.com.tenlion.schedule.service.schedule.IScheduleService; +import cn.com.tenlion.schedule.util.SendShortMessage; +import cn.com.tenlion.systemoa.service.mail.IMailService; +import ink.wgink.interfaces.user.IUserBaseService; +import ink.wgink.module.sms.service.email.IEmailService; +import ink.wgink.pojo.dtos.user.UserDTO; +import org.quartz.DisallowConcurrentExecution; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.mail.SimpleMailMessage; +import org.springframework.mail.javamail.JavaMailSender; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * 日程管理 + * 轮巡向用户发送日程提醒 + * 2022年4月14日15:29:01 + * 崔宝铖 - 来自日程管理模块 + */ +@Component +@DisallowConcurrentExecution // 防止定时任务并行执行(防止1个没有执行完,另一个又开始了) +public class ScheduleMessage { + + @Autowired + private IScheduleService iScheduleService; + + @Autowired + private JavaMailSender javaMailSender; + + @Autowired + private IUserBaseService iUserBaseService; + + @Autowired + private IMailService iMailService; + + @Value("${spring.mail.username}") //发送人的邮箱 + private String from; + + @Scheduled(cron="0 0/4 * * * ?") // 4分钟执行1次 + public void sendMessage() throws Exception { + // 查出已经开始的日程 , 但没有通知的 + List list = iScheduleService.notNoticeList(); + for(ScheduleDTO dto : list) { + // 1:站内,2:短信,3:邮件 + // 站内通知 + if(dto.getScheduleMessageType().contains("1")) { + String username = dto.getCreatorName().split("\\|")[0]; + String name = dto.getCreatorName().split("\\|")[1]; + String time = dto.getScheduleStartTime().substring(0, 5); + iMailService.cbcSendMail("1", dto.getCreator(), username + "[" + name+ "]", "日程提醒", name + ",您的日程(" + dto.getScheduleTitle() + ")即将在 " + time + "开始" ); + } + // 短信通知 + if(dto.getScheduleMessageType().contains("2")) { + // 校验手机号是否正确 + String phone = dto.getCreatorName().split("\\|")[0]; + String name = dto.getCreatorName().split("\\|")[1]; + if(checkMobileNumber(phone)) { + String time = dto.getScheduleStartTime().substring(0, 5); + SendShortMessage.send(phone, name + ",您的日程(" + dto.getScheduleTitle() + ")即将在 " + time + "开始" , null); + } + } + // 邮箱通知 + if(dto.getScheduleMessageType().contains("3")) { + String name = dto.getCreatorName().split("\\|")[1]; + String time = dto.getScheduleStartTime().substring(0, 5); + UserDTO userDTO = iUserBaseService.get(dto.getCreator()); + String email = userDTO.getUserEmail(); + if(checkEmail(email)) { + SimpleMailMessage message = new SimpleMailMessage(); + message.setText(name + ",您的日程(" + dto.getScheduleTitle() + ")即将在 " + time + "开始"); + message.setSubject("日程提醒"); + message.setTo(email); + message.setFrom(from); + javaMailSender.send(message); + } + } + // 更改提醒状态为已提醒 + iScheduleService.updateMessageStatus(dto.getScheduleId()); + } + } + + /** + * 验证邮箱 + * @param email + * @return + */ + + public static boolean checkEmail(String email) { + boolean flag = false; + try { + String check = "^([a-z0-9A-Z]+[-|_|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$"; + Pattern regex = Pattern.compile(check); + Matcher matcher = regex.matcher(email); + flag = matcher.matches(); + } catch (Exception e) { + flag = false; + } + return flag; + } + + /** + * 验证手机号码 + * @Title : checkMobileNumber + * @功能描述 : TODO + * @设定文件 : @param mobileNumber 手机号 + * @设定文件 : @return + * @返回类型 : boolean false 未通过 | true 通过 + * @throws : + */ + public boolean checkMobileNumber(String mobileNumber) { + boolean flag = false; + try { + // 移动 + String CM = "^1(3[4-9]|4[7]|5[0-27-9]|7[08]|8[2-478])\\d{8}$"; + // 联通 + String CU = "^1(3[0-2]|4[5]|5[56]|7[0156]|8[56])\\d{8}$"; + // 电信 + String CT = "^1(3[3]|4[9]|53|7[037]|8[019])\\d{8}$"; + // 进行匹配 + if(mobileNumber.matches(CM)||mobileNumber.matches(CU)||mobileNumber.matches(CT)) { + flag = true; + } + } catch (Exception e) { + flag = false; + } + return flag; + } + +} + From 39fe376aaf43f0b89ffcc3956cd179460f5115bc Mon Sep 17 00:00:00 2001 From: cuibaocheng Date: Fri, 15 Apr 2022 17:46:35 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E5=A4=96?= =?UTF-8?q?=E7=BD=91=E9=82=AE=E4=BB=B6=E5=8F=91=E9=80=81=E7=9A=84=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application-prod.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index 7dac270..75d1763 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -25,6 +25,24 @@ spring: multipart: max-file-size: 1GB max-request-size: 1GB + mail: + # 配置 SMTP 服务器地址 + host: smtp.163.com + # 发送者邮箱 + username: gotowuyuan@163.com + # 配置密码,注意不是真正的密码,而是刚刚申请到的授权码 + password: OIFUJJYQKGRFPADX + # 端口号465或587 + port: 25 + # 默认的邮件编码为UTF-8 + default-encoding: UTF-8 + # 配置SSL 加密工厂 + properties: + mail: + smtp: + socketFactoryClass: javax.net.ssl.SSLSocketFactory + #表示开启 DEBUG 模式,这样,邮件发送过程的日志会在控制台打印出来,方便排查错误 + debug: false datasource: druid: url: jdbc:mysql://192.168.158.18:3306/db_smart_city_house?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&autoReconnect=true&failOverReadOnly=false&useSSL=false&serverTimezone=UTC&nullCatalogMeansCurrent=true