package com.ruzhoukj.sms.task; import cn.hutool.core.bean.BeanUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.platform.model.resp.Result; import com.ruzhoukj.sms.common.WeChatRobotSender; 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 org.springframework.util.ObjectUtils; 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_496050475", map); //保存短信发送历史记录 smsInformService.save(SmsInformEntity.builder() .name(scheduleEntity.getName()) .phone(scheduleEntity.getPhone()) .createTime(new Date()) .serviceName("月初通知") .isDelete(1) .build()); } // @Scheduled(cron = "0/10 * * * * ?") @Scheduled(cron = "0 0 9 1 * ?") public void inTheEarlyEnterprise() { Date[] dates = DateUtils.getStartAndEndDateOfCurrentMonth(); //查询本月维护人的信息 ScheduleEntity scheduleEntity = scheduleService.getUser(dates[0], dates[1]); if (!ObjectUtils.isEmpty(scheduleEntity)) { String phone = scheduleEntity.getPhone(); String name = scheduleEntity.getName(); String webhookUrl = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=04c5f353-33a7-4cb0-8d00-798dee5df953"; WeChatRobotSender sender = new WeChatRobotSender(webhookUrl); try { // 发送文本消息,并@指定手机号的成员 sender.sendTextMessage(name + "你好" + "公司本月运维工作将由你负责,你需要前往oa系统完成运维项目的维护,确保阿里云账户余额不低于1000元", null, new String[]{phone}); } catch (Exception ignored) { } } } }