package com.ruzhoukj.sms.task; import cn.hutool.core.bean.BeanUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.ruzhoukj.sms.entity.SmsInformEntity; import com.ruzhoukj.sms.service.SmsInformService; import com.ruzhoukj.sms.util.DateUtils; import com.ruzhoukj.sms.util.SmsUtil; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.util.HashMap; import java.util.Map; /** * @author wujipeng * @version 1.0 * @create 2024-08-29 14:36 */ @Component public class SmsTask { @Resource private SmsInformService smsInformService; /** * 每十五分钟执行一次 */ @Scheduled(cron = "0 */15 * * * ?") // @Scheduled(fixedRate = 10000) public void projectRemind() { //查询最新的一条数据 SmsInformEntity smsInformEntity = smsInformService .getOne(new LambdaQueryWrapper().orderByAsc(SmsInformEntity::getCreateTime), false); if (BeanUtil.isNotEmpty(smsInformEntity)) { Map map = new HashMap<>(); map.put("name", smsInformEntity.getName()); map.put("service_name", smsInformEntity.getServiceName()); map.put("date", DateUtils.formatDate(smsInformEntity.getDate())); map.put("num", String.valueOf(smsInformEntity.getNum())); if(smsInformEntity.getNum() > 0){ SmsUtil.sendMsg(smsInformEntity.getPhone(), "SMS_472285139", map); } smsInformService.removeById(smsInformEntity.getId()); } } }