feat: 到期提醒邮件内容改成表格和提取domain到配置文件

This commit is contained in:
caiyuchao
2025-09-20 17:18:55 +08:00
parent eb882e08e9
commit 6d3cf58e33
3 changed files with 47 additions and 1 deletions

View File

@@ -3,6 +3,7 @@ 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.Setter;
import lombok.extern.slf4j.Slf4j;
import org.agt.framework.common.pojo.CommonResult;
import org.agt.module.license.dal.dataobject.alert.AlertDO;
@@ -20,6 +21,7 @@ import org.agt.module.system.api.notify.NotifyMessageSendApi;
import org.agt.module.system.api.notify.dto.NotifySendSingleToUserReqDTO;
import org.agt.module.system.api.user.AdminUserApi;
import org.agt.module.system.api.user.dto.AdminUserRespDTO;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@@ -27,6 +29,7 @@ import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -67,6 +70,13 @@ public class LicenseTask {
@Resource
private AdminUserApi adminUserApi;
/**
* 邮件的开关,默认为 true
*/
@Value("${agt.domain:http://192.168.9.50}")
@Setter
private String domain;
@Scheduled(cron = "*/5 * * * * ?")
public void task() {
licenseService.genLicenseTask();
@@ -111,6 +121,7 @@ public class LicenseTask {
templateParams.put("sn", licenseDO.getSerialNo());
templateParams.put("days", day);
templateParams.put("url", "http://192.168.9.50#/license");
templateParams.put("id", licenseDO.getId());
try {
templateParams.put("expiryDate", licenseDO.getExpiryDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
@@ -148,12 +159,45 @@ public class LicenseTask {
}
}
String text = " <tr>\n" +
" <td>%s</td>\n" +
" <td>%s</td>\n" +
" <td><a href=\""+ domain +"/#/license/detail?id=%s\">%s</a></td>\n" +
" <td>%s</td>\n" +
" <td>%s</td>\n" +
" <td>%s</td>\n" +
" <td>%s天</td>\n" +
" </tr>";
userMap.forEach((k, v) -> {
v.sort(Comparator.comparingInt(c -> Integer.parseInt(c.get("days").toString())));
StringBuilder stringBuilder = new StringBuilder("<table border=\"1\" style=\"border-collapse: collapse; width: 100%;\">\n" +
" <thead>\n" +
" <tr>\n" +
" <th>客户</th>\n" +
" <th>项目</th>\n" +
" <th>SN</th>\n" +
" <th>到期时间</th>\n" +
" <th>业务负责人</th>\n" +
" <th>技术负责人1</th>\n" +
" <th>距离到期</th>\n" +
" </tr>\n" +
" </thead>\n" +
" <tbody>");
for (Map<String, Object> map : v) {
String formatText = String.format(text, map.get("customer"), map.get("project"), map.get("id"), map.get("sn"), map.get("expiryDate"), map.get("businessOwner"), map.get("technicalOwnerA"), map.get("days"));
stringBuilder.append(formatText);
}
stringBuilder.append(" </tbody>\n" +
"</table>");
mailSendApi.sendSingleMailToAdmins(new MailSendSingleToUserReqDTO()
.setUserId(k).setTemplateCode(templateCode).setTemplateParamsList(v));
.setUserId(k).setTemplateCode(templateCode).setContent(stringBuilder.toString()));
});
}
licenseService.genLicenseTask();
}
}

View File

@@ -205,6 +205,7 @@ agt:
enable: false # 本地环境,暂时关闭图片验证码,方便登录等接口的测试;
mail:
enable: false # 本地环境,暂时关闭邮件发送;
domain: http://localhost:5666
security:
mock-enable: true
pay:

View File

@@ -203,6 +203,7 @@ wx:
agt:
captcha:
enable: false # 本地环境,暂时关闭图片验证码,方便登录等接口的测试;
domain: http://192.168.9.50
security:
mock-enable: true
pay: