package com.ruzhoukj.sms.task; import cn.hutool.core.bean.BeanUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 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 com.ruzhoukj.sms.util.SmsUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.util.Date; import java.util.HashMap; import java.util.Map; /** * @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()); } } //短信通知 // @Scheduled(cron = "0/10 * * * * ?") @Scheduled(cron = "0 0 9 1 * ?") public void inTheEarlySms() { Date[] dates = DateUtils.getStartAndEndDateOfCurrentMonth(); //查询本月维护人的信息 ScheduleEntity scheduleEntity = scheduleService.getUser(dates[0], dates[1]); Map map = new HashMap<>(); map.put("name", scheduleEntity.getName()); SmsUtil.sendMsg(scheduleEntity.getPhone(), "SMS_490030330", map); //保存短信发送历史记录 smsInformService.save(SmsInformEntity.builder() .name(scheduleEntity.getName()) .phone(scheduleEntity.getPhone()) .createTime(new Date()) .serviceName("月初通知") .isDelete(1) .build()); } }