增加了日程管理定时发送短信通知/邮件通知/站内通知
This commit is contained in:
parent
2da1e82eb0
commit
a2ac8e6dc0
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user