Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
614af1f131
@ -12,7 +12,9 @@ import ink.wgink.common.base.DefaultBaseService;
|
|||||||
import ink.wgink.common.component.SecurityComponent;
|
import ink.wgink.common.component.SecurityComponent;
|
||||||
import ink.wgink.pojo.ListPage;
|
import ink.wgink.pojo.ListPage;
|
||||||
import ink.wgink.pojo.bos.UserInfoBO;
|
import ink.wgink.pojo.bos.UserInfoBO;
|
||||||
|
import ink.wgink.pojo.dtos.user.UserDTO;
|
||||||
import ink.wgink.pojo.result.SuccessResultList;
|
import ink.wgink.pojo.result.SuccessResultList;
|
||||||
|
import ink.wgink.service.user.service.IUserService;
|
||||||
import ink.wgink.util.UUIDUtil;
|
import ink.wgink.util.UUIDUtil;
|
||||||
import ink.wgink.util.date.DateUtil;
|
import ink.wgink.util.date.DateUtil;
|
||||||
import ink.wgink.util.map.HashMapUtil;
|
import ink.wgink.util.map.HashMapUtil;
|
||||||
@ -36,6 +38,8 @@ public class MailServiceImpl extends DefaultBaseService implements IMailService
|
|||||||
private IMailDao mailDao;
|
private IMailDao mailDao;
|
||||||
@Autowired
|
@Autowired
|
||||||
private SecurityComponent securityComponent;
|
private SecurityComponent securityComponent;
|
||||||
|
@Autowired
|
||||||
|
private IUserService userService;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@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 = "<p><br></p><p><br></p><p><br></p><p>在 "+ dto.getGmtCreate() + ", "
|
String spx = "<p><br></p><p><br></p><p><br></p><p>在 "+ dto.getGmtCreate() + ", "
|
||||||
+"<span style='color: blue;'>"+ currentUser.getUserUsername() + " [" + currentUser.getUserName() + "]</span> 写道:" +"</p>" +
|
+"<span style='color: blue;'>"+ currentUser.getUserUsername() + " [" + currentUser.getUserName() + "]</span> 写道:" +"</p>" +
|
||||||
"<p><hr style='border: 1px dashed'></hr></p>";
|
"<p><hr style='border: 1px dashed'></hr></p>";
|
||||||
|
138
src/main/java/cn/com/tenlion/systemoa/task/ScheduleMessage.java
Normal file
138
src/main/java/cn/com/tenlion/systemoa/task/ScheduleMessage.java
Normal file
@ -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<ScheduleDTO> 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -25,6 +25,24 @@ spring:
|
|||||||
multipart:
|
multipart:
|
||||||
max-file-size: 1GB
|
max-file-size: 1GB
|
||||||
max-request-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:
|
datasource:
|
||||||
druid:
|
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
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user