feat: 到期提醒邮件内容改成表格和提取domain到配置文件
This commit is contained in:
@@ -3,6 +3,7 @@ package org.agt.module.license.service.license;
|
|||||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
|
import lombok.Setter;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.agt.framework.common.pojo.CommonResult;
|
import org.agt.framework.common.pojo.CommonResult;
|
||||||
import org.agt.module.license.dal.dataobject.alert.AlertDO;
|
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.notify.dto.NotifySendSingleToUserReqDTO;
|
||||||
import org.agt.module.system.api.user.AdminUserApi;
|
import org.agt.module.system.api.user.AdminUserApi;
|
||||||
import org.agt.module.system.api.user.dto.AdminUserRespDTO;
|
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.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@@ -27,6 +29,7 @@ import java.time.LocalDateTime;
|
|||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -67,6 +70,13 @@ public class LicenseTask {
|
|||||||
@Resource
|
@Resource
|
||||||
private AdminUserApi adminUserApi;
|
private AdminUserApi adminUserApi;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邮件的开关,默认为 true
|
||||||
|
*/
|
||||||
|
@Value("${agt.domain:http://192.168.9.50}")
|
||||||
|
@Setter
|
||||||
|
private String domain;
|
||||||
|
|
||||||
@Scheduled(cron = "*/5 * * * * ?")
|
@Scheduled(cron = "*/5 * * * * ?")
|
||||||
public void task() {
|
public void task() {
|
||||||
licenseService.genLicenseTask();
|
licenseService.genLicenseTask();
|
||||||
@@ -111,6 +121,7 @@ public class LicenseTask {
|
|||||||
templateParams.put("sn", licenseDO.getSerialNo());
|
templateParams.put("sn", licenseDO.getSerialNo());
|
||||||
templateParams.put("days", day);
|
templateParams.put("days", day);
|
||||||
templateParams.put("url", "http://192.168.9.50#/license");
|
templateParams.put("url", "http://192.168.9.50#/license");
|
||||||
|
templateParams.put("id", licenseDO.getId());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
templateParams.put("expiryDate", licenseDO.getExpiryDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
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) -> {
|
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()
|
mailSendApi.sendSingleMailToAdmins(new MailSendSingleToUserReqDTO()
|
||||||
.setUserId(k).setTemplateCode(templateCode).setTemplateParamsList(v));
|
.setUserId(k).setTemplateCode(templateCode).setContent(stringBuilder.toString()));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
licenseService.genLicenseTask();
|
licenseService.genLicenseTask();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -205,6 +205,7 @@ agt:
|
|||||||
enable: false # 本地环境,暂时关闭图片验证码,方便登录等接口的测试;
|
enable: false # 本地环境,暂时关闭图片验证码,方便登录等接口的测试;
|
||||||
mail:
|
mail:
|
||||||
enable: false # 本地环境,暂时关闭邮件发送;
|
enable: false # 本地环境,暂时关闭邮件发送;
|
||||||
|
domain: http://localhost:5666
|
||||||
security:
|
security:
|
||||||
mock-enable: true
|
mock-enable: true
|
||||||
pay:
|
pay:
|
||||||
|
|||||||
@@ -203,6 +203,7 @@ wx:
|
|||||||
agt:
|
agt:
|
||||||
captcha:
|
captcha:
|
||||||
enable: false # 本地环境,暂时关闭图片验证码,方便登录等接口的测试;
|
enable: false # 本地环境,暂时关闭图片验证码,方便登录等接口的测试;
|
||||||
|
domain: http://192.168.9.50
|
||||||
security:
|
security:
|
||||||
mock-enable: true
|
mock-enable: true
|
||||||
pay:
|
pay:
|
||||||
|
|||||||
Reference in New Issue
Block a user