Commit 6fb95cc5 authored by wujipeng's avatar wujipeng
Browse files

增加月初运维

parent c2a85dbc
package com.ruzhoukj.sms.entity; package com.ruzhoukj.sms.entity;
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
...@@ -32,4 +33,6 @@ public class SmsInformEntity { ...@@ -32,4 +33,6 @@ public class SmsInformEntity {
private Date date; private Date date;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createTime; private Date createTime;
@TableField(value = "is_delete")
private Integer isDelete;
} }
...@@ -21,7 +21,6 @@ import org.springframework.scheduling.annotation.Scheduled; ...@@ -21,7 +21,6 @@ import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.math.BigDecimal;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZoneId; import java.time.ZoneId;
......
package com.ruzhoukj.sms.task;
import cn.hutool.core.bean.BeanUtil;
import com.ruzhoukj.sms.entity.EmailRecordEntity;
import com.ruzhoukj.sms.entity.ScheduleEntity;
import com.ruzhoukj.sms.entity.SmsInformEntity;
import com.ruzhoukj.sms.service.EmailRecordService;
import com.ruzhoukj.sms.service.ScheduleService;
import com.ruzhoukj.sms.service.SmsInformService;
import com.ruzhoukj.sms.util.DateUtils;
import com.ruzhoukj.sms.util.EmailUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Date;
/**
* @author : wujipeng
* @date : 2025/7/3 15:55
* @Version: 1.0
* @Desc : 月初运维通知
*/
@Component
@Slf4j
public class InTheEarlyTask {
@Resource
private ScheduleService scheduleService;
@Resource
private EmailRecordService emailRecordService;
@Resource
private SmsInformService smsInformService;
//邮箱通知
// @Scheduled(cron = "0/10 * * * * ?")
@Scheduled(cron = "0 0 9 1 * ?")
public void inTheEarlyEmail() {
Date[] dates = DateUtils.getStartAndEndDateOfCurrentMonth();
//查询本月维护人的信息
ScheduleEntity scheduleEntity = scheduleService.getUser(dates[0], dates[1]);
if (BeanUtil.isNotEmpty(scheduleEntity)) {
//发送邮件
EmailUtil.sendInTheEarlyEmail(scheduleEntity.getName(), scheduleEntity.getEmail());
//保存历史记录
emailRecordService.save(EmailRecordEntity.builder()
.name(scheduleEntity.getName())
.email(scheduleEntity.getEmail())
.info("月初通知")
.createTime(new Date())
.build());
//保存短信信息
smsInformService.save(SmsInformEntity.builder()
.date(new Date())
.name(scheduleEntity.getName())
.num(0)
.phone(scheduleEntity.getPhone())
.serviceName("月初通知")
.build());
}
}
}
...@@ -27,12 +27,14 @@ public class SmsTask { ...@@ -27,12 +27,14 @@ public class SmsTask {
/** /**
* 每十五分钟执行一次 * 每十五分钟执行一次
*/ */
@Scheduled(cron = "0 */15 * * * ?") // @Scheduled(cron = "0 */15 * * * ?")
// @Scheduled(fixedRate = 10000) @Scheduled(fixedRate = 10000)
public void projectRemind() { public void projectRemind() {
//查询最新的一条数据 //查询最新的一条数据
SmsInformEntity smsInformEntity = smsInformService SmsInformEntity smsInformEntity = smsInformService
.getOne(new LambdaQueryWrapper<SmsInformEntity>().orderByAsc(SmsInformEntity::getCreateTime), false); .getOne(new LambdaQueryWrapper<SmsInformEntity>()
.eq(SmsInformEntity::getIsDelete, 0)
.orderByAsc(SmsInformEntity::getCreateTime), false);
if (BeanUtil.isNotEmpty(smsInformEntity)) { if (BeanUtil.isNotEmpty(smsInformEntity)) {
Map<String, String> map = new HashMap<>(); Map<String, String> map = new HashMap<>();
map.put("name", smsInformEntity.getName()); map.put("name", smsInformEntity.getName());
...@@ -42,7 +44,8 @@ public class SmsTask { ...@@ -42,7 +44,8 @@ public class SmsTask {
if(smsInformEntity.getNum() > 0){ if(smsInformEntity.getNum() > 0){
SmsUtil.sendMsg(smsInformEntity.getPhone(), "SMS_472285139", map); SmsUtil.sendMsg(smsInformEntity.getPhone(), "SMS_472285139", map);
} }
smsInformService.removeById(smsInformEntity.getId()); smsInformEntity.setIsDelete(1);
smsInformService.updateById(smsInformEntity);
} }
} }
} }
...@@ -165,12 +165,9 @@ public class EmailUtil { ...@@ -165,12 +165,9 @@ public class EmailUtil {
stringJoiner.add("备注:" + projectEntity.getDescribe()); stringJoiner.add("备注:" + projectEntity.getDescribe());
stringJoiner.add("请您及时进行处理,以确保服务的连续性。"); stringJoiner.add("请您及时进行处理,以确保服务的连续性。");
stringJoiner.add("From:研发部"); stringJoiner.add("From:研发部");
message.setText(stringJoiner.toString()); message.setText(stringJoiner.toString());
Transport.send(message); Transport.send(message);
log.info("Email sent successfully"); log.info("Email sent successfully");
} catch (MessagingException e) { } catch (MessagingException e) {
...@@ -201,12 +198,10 @@ public class EmailUtil { ...@@ -201,12 +198,10 @@ public class EmailUtil {
Message message = new MimeMessage(session); Message message = new MimeMessage(session);
message.setSubject("项目到期提醒"); message.setSubject("项目到期提醒");
message.setFrom(new InternetAddress(username)); message.setFrom(new InternetAddress(username));
// 添加多个收件人 // 添加多个收件人
String[] toAddresses = {email}; String[] toAddresses = {email};
message.setRecipients(Message.RecipientType.TO, message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(String.join(", ", toAddresses))); InternetAddress.parse(String.join(", ", toAddresses)));
StringJoiner stringJoiner = new StringJoiner("\n"); StringJoiner stringJoiner = new StringJoiner("\n");
stringJoiner.add("尊敬的" + name + ","); stringJoiner.add("尊敬的" + name + ",");
stringJoiner.add("您和" + contractVO.getClient() + "签订的:" + contractVO.getCode() + "合同即将到期。"); stringJoiner.add("您和" + contractVO.getClient() + "签订的:" + contractVO.getCode() + "合同即将到期。");
...@@ -215,14 +210,50 @@ public class EmailUtil { ...@@ -215,14 +210,50 @@ public class EmailUtil {
stringJoiner.add("距今还有:" + (int) DateUtils.daysBetween(new Date(), contractVO.getEndTime()) + "天"); stringJoiner.add("距今还有:" + (int) DateUtils.daysBetween(new Date(), contractVO.getEndTime()) + "天");
stringJoiner.add("请您及时进行处理,以确保合同的连续性。"); stringJoiner.add("请您及时进行处理,以确保合同的连续性。");
stringJoiner.add("From:研发部"); stringJoiner.add("From:研发部");
message.setText(stringJoiner.toString()); message.setText(stringJoiner.toString());
Transport.send(message); Transport.send(message);
log.info("Email sent successfully");
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
public static void sendInTheEarlyEmail(String name, String email) {
final String username = "2404263178@qq.com";
final String password = "eryzvsveckiudiee";
log.info("Email sent successfully"); // QQ Mail SMTP server information
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "smtp.qq.com");
props.put("mail.smtp.port", "587");
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
@Override
protected javax.mail.PasswordAuthentication getPasswordAuthentication() {
return new javax.mail.PasswordAuthentication(username, password);
}
});
try {
Message message = new MimeMessage(session);
message.setSubject("项目到期提醒");
message.setFrom(new InternetAddress(username));
// 添加多个收件人
String[] toAddresses = {email};
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(String.join(", ", toAddresses)));
StringJoiner stringJoiner = new StringJoiner("\n");
stringJoiner.add("尊敬的" + name + ",");
stringJoiner.add("本月由你负责公司的项目运维");
stringJoiner.add("请检查是否有运维工作待完成");
stringJoiner.add("From:研发部");
message.setText(stringJoiner.toString());
Transport.send(message);
log.info("Email sent successfully");
} catch (MessagingException e) { } catch (MessagingException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment