feat: License到期提醒
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
package org.agt.module.license.controller.admin.alert.vo;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import org.agt.framework.common.pojo.PageParam;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import static org.agt.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@@ -16,10 +19,10 @@ import static org.agt.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY
|
||||
public class AlertPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "提醒人")
|
||||
private String users;
|
||||
private List<Long> users;
|
||||
|
||||
@Schema(description = "提醒天数")
|
||||
private String days;
|
||||
private List<Integer> days;
|
||||
|
||||
@Schema(description = "提醒内容")
|
||||
private String content;
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
package org.agt.module.license.controller.admin.alert.vo;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import com.alibaba.excel.annotation.*;
|
||||
import java.util.List;
|
||||
|
||||
@Schema(description = "管理后台 - 告警 Response VO")
|
||||
@Data
|
||||
@@ -18,11 +19,11 @@ public class AlertRespVO {
|
||||
|
||||
@Schema(description = "提醒人")
|
||||
@ExcelProperty("提醒人")
|
||||
private String users;
|
||||
private List<Long> users;
|
||||
|
||||
@Schema(description = "提醒天数")
|
||||
@ExcelProperty("提醒天数")
|
||||
private String days;
|
||||
private List<Integer> days;
|
||||
|
||||
@Schema(description = "提醒内容")
|
||||
@ExcelProperty("提醒内容")
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package org.agt.module.license.controller.admin.alert.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import jakarta.validation.constraints.*;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Schema(description = "管理后台 - 告警新增/修改 Request VO")
|
||||
@Data
|
||||
@@ -13,10 +14,10 @@ public class AlertSaveReqVO {
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "提醒人")
|
||||
private String users;
|
||||
private List<Long> users;
|
||||
|
||||
@Schema(description = "提醒天数")
|
||||
private String days;
|
||||
private List<Integer> days;
|
||||
|
||||
@Schema(description = "提醒内容")
|
||||
private String content;
|
||||
|
||||
@@ -1,18 +1,26 @@
|
||||
package org.agt.module.license.dal.dataobject.alert;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalDateTime;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
import org.agt.framework.mybatis.core.dataobject.BaseDO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 告警 DO
|
||||
*
|
||||
* @author super
|
||||
*/
|
||||
@TableName("crm_alert")
|
||||
@TableName(value = "crm_alert", autoResultMap = true)
|
||||
@KeySequence("crm_alert_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@@ -30,11 +38,13 @@ public class AlertDO extends BaseDO {
|
||||
/**
|
||||
* 提醒人
|
||||
*/
|
||||
private String users;
|
||||
@TableField(typeHandler = JacksonTypeHandler.class)
|
||||
private List<Long> users;
|
||||
/**
|
||||
* 提醒天数
|
||||
*/
|
||||
private String days;
|
||||
@TableField(typeHandler = JacksonTypeHandler.class)
|
||||
private List<Integer> days;
|
||||
/**
|
||||
* 提醒内容
|
||||
*/
|
||||
|
||||
@@ -7,6 +7,10 @@ import org.agt.module.license.controller.admin.alert.vo.AlertPageReqVO;
|
||||
import org.agt.module.license.controller.admin.alert.vo.AlertSaveReqVO;
|
||||
import org.agt.module.license.dal.dataobject.alert.AlertDO;
|
||||
import org.agt.module.license.dal.mysql.alert.AlertMapper;
|
||||
import org.agt.module.system.api.mail.MailTemplateApi;
|
||||
import org.agt.module.system.api.mail.dto.MailTemplateSaveReqDTO;
|
||||
import org.agt.module.system.api.notify.NotifyTemplateApi;
|
||||
import org.agt.module.system.api.notify.dto.NotifyTemplateSaveReqDTO;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
@@ -25,11 +29,20 @@ public class AlertServiceImpl implements AlertService {
|
||||
@Resource
|
||||
private AlertMapper alertMapper;
|
||||
|
||||
@Resource
|
||||
private MailTemplateApi mailTemplateApi;
|
||||
|
||||
@Resource
|
||||
private NotifyTemplateApi notifyTemplateApi;
|
||||
|
||||
@Override
|
||||
public Long createAlert(AlertSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
AlertDO alert = BeanUtils.toBean(createReqVO, AlertDO.class);
|
||||
alertMapper.insert(alert);
|
||||
|
||||
mailTemplateApi.updateMailTemplate(new MailTemplateSaveReqDTO().setId(18L).setContent(createReqVO.getContent()));
|
||||
notifyTemplateApi.updateNotifyTemplate(new NotifyTemplateSaveReqDTO().setId(2L).setContent(createReqVO.getContent()));
|
||||
// 返回
|
||||
return alert.getId();
|
||||
}
|
||||
@@ -41,6 +54,9 @@ public class AlertServiceImpl implements AlertService {
|
||||
// 更新
|
||||
AlertDO updateObj = BeanUtils.toBean(updateReqVO, AlertDO.class);
|
||||
alertMapper.updateById(updateObj);
|
||||
|
||||
mailTemplateApi.updateMailTemplate(new MailTemplateSaveReqDTO().setId(18L).setContent(updateReqVO.getContent()));
|
||||
notifyTemplateApi.updateNotifyTemplate(new NotifyTemplateSaveReqDTO().setId(2L).setContent(updateReqVO.getContent()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,22 +1,99 @@
|
||||
package org.agt.module.license.service.license;
|
||||
|
||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.agt.module.license.dal.dataobject.alert.AlertDO;
|
||||
import org.agt.module.license.dal.dataobject.license.LicenseDO;
|
||||
import org.agt.module.license.dal.mysql.alert.AlertMapper;
|
||||
import org.agt.module.license.dal.mysql.license.LicenseMapper;
|
||||
import org.agt.module.license.enums.LicenseStatusEnum;
|
||||
import org.agt.module.system.api.mail.MailSendApi;
|
||||
import org.agt.module.system.api.mail.dto.MailSendSingleToUserReqDTO;
|
||||
import org.agt.module.system.api.notify.NotifyMessageSendApi;
|
||||
import org.agt.module.system.api.notify.dto.NotifySendSingleToUserReqDTO;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @description: License 定时任务
|
||||
* @author: cyc
|
||||
* @since: 2025-07-28
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class LicenseTask {
|
||||
|
||||
@Resource
|
||||
private LicenseServiceImpl licenseService;
|
||||
|
||||
@Scheduled(cron ="*/8 * * * * ?")
|
||||
@Resource
|
||||
private AlertMapper alertMapper;
|
||||
|
||||
@Resource
|
||||
private LicenseMapper licenseMapper;
|
||||
|
||||
@Resource
|
||||
private MailSendApi mailSendApi;
|
||||
|
||||
@Resource
|
||||
private NotifyMessageSendApi notifySendApi;
|
||||
|
||||
@Scheduled(cron = "*/8 * * * * ?")
|
||||
public void task() {
|
||||
licenseService.genLicenseTask();
|
||||
}
|
||||
|
||||
@Scheduled(cron = "0 0 0 * * ?")
|
||||
public void remind() {
|
||||
log.info("开始查询马上到期提醒的License");
|
||||
List<AlertDO> alertList = alertMapper.selectList(Wrappers.<AlertDO>lambdaQuery().eq(AlertDO::getStatus, 1));
|
||||
Optional<AlertDO> alertOptional = alertList.stream().findFirst();
|
||||
if (alertOptional.isPresent()) {
|
||||
AlertDO alertDO = alertOptional.get();
|
||||
|
||||
List<Integer> days = alertDO.getDays();
|
||||
List<Long> users = alertDO.getUsers();
|
||||
String templateCode = alertDO.getTemplateCode();
|
||||
|
||||
List<LicenseDO> licenseList = licenseMapper.selectList(Wrappers.<LicenseDO>lambdaQuery()
|
||||
.eq(LicenseDO::getStatus, LicenseStatusEnum.COMPLETED.getCode())
|
||||
.gt(LicenseDO::getExpiryDate, LocalDateTime.now()));
|
||||
|
||||
for (LicenseDO licenseDO : licenseList) {
|
||||
for (Integer day : days) {
|
||||
long between = LocalDateTimeUtil.between(LocalDateTime.now(), licenseDO.getExpiryDate(), ChronoUnit.DAYS);
|
||||
if (between == day) {
|
||||
for (Long userId : users) {
|
||||
// 1. 准备参数
|
||||
Map<String, Object> templateParams = new HashMap<>();
|
||||
templateParams.put("sn", licenseDO.getSerialNo());
|
||||
templateParams.put("days", day);
|
||||
|
||||
log.info("已发送到期提醒邮件:{}", licenseDO.getSerialNo());
|
||||
// 2. 发送邮件
|
||||
mailSendApi.sendSingleMailToAdmin(new MailSendSingleToUserReqDTO()
|
||||
.setUserId(userId).setTemplateCode(templateCode).setTemplateParams(templateParams));
|
||||
|
||||
// 发送站内信
|
||||
notifySendApi.sendSingleMessageToAdmin(new NotifySendSingleToUserReqDTO()
|
||||
.setUserId(userId).setTemplateCode(templateCode).setTemplateParams(templateParams));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
licenseService.genLicenseTask();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user