diff --git a/src/main/java/cn/com/tenlion/systemoa/task/ScheduleMessage.java b/src/main/java/cn/com/tenlion/systemoa/task/ScheduleMessage.java index 3372e20..0df88a9 100644 --- a/src/main/java/cn/com/tenlion/systemoa/task/ScheduleMessage.java +++ b/src/main/java/cn/com/tenlion/systemoa/task/ScheduleMessage.java @@ -1,12 +1,15 @@ package cn.com.tenlion.systemoa.task; import cn.com.tenlion.schedule.pojo.dtos.schedule.ScheduleDTO; +import cn.com.tenlion.schedule.pojo.dtos.schedulelog.ScheduleLogDTO; +import cn.com.tenlion.schedule.pojo.vos.schedulelog.ScheduleLogVO; import cn.com.tenlion.schedule.service.schedule.IScheduleService; +import cn.com.tenlion.schedule.service.schedulelog.IScheduleLogService; 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 ink.wgink.util.date.DateUtil; import org.quartz.DisallowConcurrentExecution; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -14,8 +17,8 @@ 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.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -41,49 +44,102 @@ public class ScheduleMessage { @Autowired private IMailService iMailService; + @Autowired + private IScheduleLogService iScheduleLogService; + @Value("${spring.mail.username}") //发送人的邮箱 private String from; - @Scheduled(cron="0 0/4 * * * ?") // 4分钟执行1次 + @Scheduled(cron="0 0/1 * * * ?") // 4分钟执行1次 public void sendMessage() throws Exception { // 查出已经开始的日程 , 但没有通知的 List list = iScheduleService.notNoticeList(); for(ScheduleDTO dto : list) { + // 查找通知记录 + Map logMap = iScheduleLogService.getByScheduleId(dto.getScheduleId(), "1"); + String levelName = dto.getScheduleLevel().equals("2") ? "【紧急日程】" : ""; // 1:站内,2:短信,3:邮件 // 站内通知 - if(dto.getScheduleMessageType().contains("1")) { + if(dto.getScheduleMessageType().contains("1") && logMap.get("1") == null) { 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 + "开始" ); + String content = name + ",您的日程(" + dto.getScheduleTitle() + ")即将在 " + time + "开始" + levelName; + // 保存记录 + ScheduleLogVO logVO = new ScheduleLogVO(); + logVO.setScheduleId(dto.getScheduleId()); + logVO.setScheduleLogContent(content); + logVO.setScheduleLogStatus("1"); + logVO.setScheduleLogTime(DateUtil.getTime()); + logVO.setScheduleLogType("1"); + try{ + iMailService.cbcSendMail("1", dto.getCreator(), username + "[" + name+ "]", "日程提醒", content); + }catch(Exception e) { + logVO.setScheduleLogContent("站内发送失败:" + content); + logVO.setScheduleLogStatus("0"); + } + iScheduleLogService.saveData(logVO); } // 短信通知 - if(dto.getScheduleMessageType().contains("2")) { + if(dto.getScheduleMessageType().contains("2") && logMap.get("2") == null) { // 校验手机号是否正确 - String phone = dto.getCreatorName().split("\\|")[0]; + UserDTO userDTO = iUserBaseService.get(dto.getCreator()); + String phone = userDTO.getUserPhone(); String name = dto.getCreatorName().split("\\|")[1]; + String time = dto.getScheduleStartTime().substring(0, 5); + String content = name + ",您的日程(" + dto.getScheduleTitle() + ")即将在 " + time + "开始" + levelName; + // 保存记录 + ScheduleLogVO logVO = new ScheduleLogVO(); + logVO.setScheduleId(dto.getScheduleId()); + logVO.setScheduleLogContent(content); + logVO.setScheduleLogStatus("1"); + logVO.setScheduleLogTime(DateUtil.getTime()); + logVO.setScheduleLogType("2"); if(checkMobileNumber(phone)) { - String time = dto.getScheduleStartTime().substring(0, 5); - SendShortMessage.send(phone, name + ",您的日程(" + dto.getScheduleTitle() + ")即将在 " + time + "开始" , null); + try{ + SendShortMessage.send(phone, content , null); + }catch(Exception e) { + logVO.setScheduleLogContent("短信发送失败:" + content); + logVO.setScheduleLogStatus("0"); + } + }else { + logVO.setScheduleLogContent("手机号错误:" + content); + logVO.setScheduleLogStatus("0"); } + iScheduleLogService.saveData(logVO); } // 邮箱通知 - if(dto.getScheduleMessageType().contains("3")) { + if(dto.getScheduleMessageType().contains("3") && logMap.get("3") == null) { String name = dto.getCreatorName().split("\\|")[1]; String time = dto.getScheduleStartTime().substring(0, 5); UserDTO userDTO = iUserBaseService.get(dto.getCreator()); String email = userDTO.getUserEmail(); + String content = name + ",您的日程(" + dto.getScheduleTitle() + ")即将在 " + time + "开始" + levelName; + // 保存记录 + ScheduleLogVO logVO = new ScheduleLogVO(); + logVO.setScheduleId(dto.getScheduleId()); + logVO.setScheduleLogContent(content); + logVO.setScheduleLogStatus("1"); + logVO.setScheduleLogTime(DateUtil.getTime()); + logVO.setScheduleLogType("3"); if(checkEmail(email)) { SimpleMailMessage message = new SimpleMailMessage(); - message.setText(name + ",您的日程(" + dto.getScheduleTitle() + ")即将在 " + time + "开始"); - message.setSubject("日程提醒"); + message.setText(content); + message.setSubject("日程提醒" + levelName); message.setTo(email); message.setFrom(from); - javaMailSender.send(message); + try{ + javaMailSender.send(message); + }catch(Exception e) { + logVO.setScheduleLogContent("邮箱发送失败:" + content); + logVO.setScheduleLogStatus("0"); + } + }else { + logVO.setScheduleLogContent("邮箱号错误:" + content); + logVO.setScheduleLogStatus("0"); } + iScheduleLogService.saveData(logVO); } - // 更改提醒状态为已提醒 - iScheduleService.updateMessageStatus(dto.getScheduleId()); } }