This commit is contained in:
Wayne 2024-05-16 10:52:11 +08:00
commit f23427b6bd
5 changed files with 154 additions and 1 deletions

View File

@ -55,11 +55,24 @@
<artifactId>yudao-spring-boot-starter-excel</artifactId>
</dependency>
<!-- Job 定时任务相关 -->
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-spring-boot-starter-job</artifactId>
</dependency>
<!-- Test 测试相关 -->
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-spring-boot-starter-test</artifactId>
</dependency>
<!-- 站内信相关 -->
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-module-system-api</artifactId>
<version>${revision}</version>
</dependency>
</dependencies>
<properties>

View File

@ -0,0 +1,74 @@
package cn.iocoder.yudao.module.fta.dal.dataobject.job;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX;
import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
import cn.iocoder.yudao.module.fta.dal.dataobject.enterpriseinformation.EnterpriseInformationDO;
import cn.iocoder.yudao.module.fta.dal.mysql.enterpriseinformation.EnterpriseInformationMapper;
import cn.iocoder.yudao.module.fta.service.enterpriseinformation.CredentialManagementService;
import cn.iocoder.yudao.module.fta.service.enterpriseinformation.EnterpriseInformationService;
import cn.iocoder.yudao.module.system.api.notify.NotifyMessageSendApi;
import cn.iocoder.yudao.module.system.api.notify.dto.NotifySendSingleToUserReqDTO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.HashMap;
import java.util.Map;
/**
* 企业证件过期查询
*/
@Slf4j
@Component
public class credentialManagementJob implements JobHandler {
@Resource
private NotifyMessageSendApi notifySendApi;
@Resource
private CredentialManagementService credentialManagementService;
private EnterpriseInformationMapper enterpriseInformationMapper;
/**
* 每天凌晨1点执行一次
*/
public void checkCertificateExpiration() {
LocalDate today = LocalDate.now();
int daysDifference = 15; // 证书到期时间和当前时间相差的天数阈值
//查询到到期时间
credentialManagementService.getAllCertificates().forEach(certificate -> {
LocalDate expiryDate = certificate.getExpiryDate();
long daysUntilExpiration = ChronoUnit.DAYS.between(today, expiryDate);
Map<String, Object> templateParams = new HashMap<>();
LambdaQueryWrapper<EnterpriseInformationDO> wrapper = new LambdaQueryWrapper<EnterpriseInformationDO>()
.eq(EnterpriseInformationDO::getId, certificate.getInformationId());
EnterpriseInformationDO enterpriseInformation = enterpriseInformationMapper.selectOne(wrapper);
String templateCode = "fta_credential_management";
templateParams.put("idType","安全证");
// 如果到期时间和当前时间相差15天则发送通知
if (daysUntilExpiration == daysDifference) {
// 执行你的逻辑例如发送通知
log.info("[checkCertificateExpiration][证书 {} 到期时间与当前时间相差 {} 天]", certificate.getCertificateNumber(), daysDifference);
// 这里可以添加发送通知的逻辑
notifySendApi.sendSingleMessageToAdmin(new NotifySendSingleToUserReqDTO()
.setUserId(Long.parseLong(enterpriseInformation.getCreator())).setTemplateCode(templateCode).setTemplateParams(templateParams));
}
});
}
@Override
public String execute(String param) throws Exception {
return null;
}
}

View File

@ -7,6 +7,7 @@ import cn.iocoder.yudao.module.fta.dal.dataobject.enterpriseinformation.Credenti
import javax.validation.*;
import java.util.List;
/**
@ -54,4 +55,13 @@ public interface CredentialManagementService {
*/
PageResult<CredentialManagementDO> getCredentialManagementPage(CredentialManagementPageReqVO pageReqVO);
// 假设这里有一个方法用于从数据库或其他地方获取所有证书的列表
List<CredentialManagementDO> getAllCertificates();
// 假设这里有一个方法用于发送通知
//public void sendNotification(Certificate certificate) {
// // 实现发送通知的逻辑
//}
}

View File

@ -5,12 +5,19 @@ import cn.iocoder.yudao.module.fta.controller.admin.enterpriseinformation.vo.Cre
import cn.iocoder.yudao.module.fta.controller.admin.enterpriseinformation.vo.CredentialManagementSaveReqVO;
import cn.iocoder.yudao.module.fta.dal.dataobject.enterpriseinformation.CredentialManagementDO;
import cn.iocoder.yudao.module.fta.dal.mysql.enterpriseinformation.CredentialManagementMapper;
import com.sun.deploy.security.CredentialInfo;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.fta.enums.ErrorCodeConstants.*;
@ -68,4 +75,53 @@ public class CredentialManagementServiceImpl implements CredentialManagementServ
return credentialManagementMapper.selectPage(pageReqVO);
}
@Override
public List<CredentialManagementDO> getAllCertificates() {
/**
* 1查询出所有的CredentialManagementDO信息
*/
return credentialManagementMapper.selectList();
}
//public List<Map<String, Object>> getAllCertificates() {
// List<Map<String, Object>> certificates = new ArrayList<>();
//
// // 查询出所有的企业ID
// List<String> enterpriseIds = credentialManagementMapper.selectById();
//
// // 查询每个企业的证书到期时间
// for (String enterpriseId : enterpriseIds) {
// // 查询该企业的证书到期时间
// LocalDate expiryDate = credentialManagementMapper.selectExpiryDateByEnterpriseId(enterpriseId);
//
// // 构造证书信息对象包含企业ID和到期时间
// Map<String, Object> certificateInfo = new HashMap<>();
// certificateInfo.put("enterpriseId", enterpriseId);
// certificateInfo.put("expiryDate", expiryDate);
//
// // 将证书信息添加到列表中
// certificates.add(certificateInfo);
// }
//
// return certificates;
//}
//List<CredentialInfo> certificates = new ArrayList<>();
//
//// 在这里查询企业证件信息你的实现可能会有所不同
//
//// 假设这里是一个数据库查询的示例
//List<CredentialManagementDO> credentialManagementList = credentialManagementMapper.selectList();
//
// for (CredentialManagementDO credential : credentialManagementList) {
// // 获取企业ID和到期时间
// String informationId = credential.getInformationId();
// LocalDate expiryDate = credential.getExpiryDate();
//
// // 构造 CredentialInfo 对象
// CredentialInfo credentialInfo = new CredentialInfo(informationId, expiryDate);
// certificates.add(credentialInfo);
//}
}

View File

@ -8,7 +8,7 @@ spring:
autoconfigure:
exclude:
- com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure # 排除 Druid 的自动配置,使用 dynamic-datasource-spring-boot-starter 配置多数据源
- org.springframework.boot.autoconfigure.quartz.QuartzAutoConfiguration # 默认 local 环境,不开启 Quartz 的自动配置
# - org.springframework.boot.autoconfigure.quartz.QuartzAutoConfiguration # 默认 local 环境,不开启 Quartz 的自动配置
- de.codecentric.boot.admin.server.config.AdminServerAutoConfiguration # 禁用 Spring Boot Admin 的 Server 的自动配置
- de.codecentric.boot.admin.server.ui.config.AdminServerUiAutoConfiguration # 禁用 Spring Boot Admin 的 Server UI 的自动配置
- de.codecentric.boot.admin.client.config.SpringBootAdminClientAutoConfiguration # 禁用 Spring Boot Admin 的 Client 的自动配置