diff --git a/yudao-module-fta/yudao-module-fta-biz/pom.xml b/yudao-module-fta/yudao-module-fta-biz/pom.xml index 39796ec..4b3ba1e 100644 --- a/yudao-module-fta/yudao-module-fta-biz/pom.xml +++ b/yudao-module-fta/yudao-module-fta-biz/pom.xml @@ -55,11 +55,24 @@ yudao-spring-boot-starter-excel + + + cn.iocoder.boot + yudao-spring-boot-starter-job + + cn.iocoder.boot yudao-spring-boot-starter-test + + + + cn.iocoder.boot + yudao-module-system-api + ${revision} + diff --git a/yudao-module-fta/yudao-module-fta-biz/src/main/java/cn/iocoder/yudao/module/fta/dal/dataobject/job/credentialManagementJob.java b/yudao-module-fta/yudao-module-fta-biz/src/main/java/cn/iocoder/yudao/module/fta/dal/dataobject/job/credentialManagementJob.java new file mode 100644 index 0000000..f0abd99 --- /dev/null +++ b/yudao-module-fta/yudao-module-fta-biz/src/main/java/cn/iocoder/yudao/module/fta/dal/dataobject/job/credentialManagementJob.java @@ -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 templateParams = new HashMap<>(); + + LambdaQueryWrapper wrapper = new LambdaQueryWrapper() + .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; + } +} diff --git a/yudao-module-fta/yudao-module-fta-biz/src/main/java/cn/iocoder/yudao/module/fta/service/enterpriseinformation/CredentialManagementService.java b/yudao-module-fta/yudao-module-fta-biz/src/main/java/cn/iocoder/yudao/module/fta/service/enterpriseinformation/CredentialManagementService.java index a39fb9e..a051f22 100644 --- a/yudao-module-fta/yudao-module-fta-biz/src/main/java/cn/iocoder/yudao/module/fta/service/enterpriseinformation/CredentialManagementService.java +++ b/yudao-module-fta/yudao-module-fta-biz/src/main/java/cn/iocoder/yudao/module/fta/service/enterpriseinformation/CredentialManagementService.java @@ -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 getCredentialManagementPage(CredentialManagementPageReqVO pageReqVO); + + // 假设这里有一个方法用于从数据库或其他地方获取所有证书的列表 + List getAllCertificates(); + + // 假设这里有一个方法用于发送通知 + //public void sendNotification(Certificate certificate) { + // // 实现发送通知的逻辑 + //} + } \ No newline at end of file diff --git a/yudao-module-fta/yudao-module-fta-biz/src/main/java/cn/iocoder/yudao/module/fta/service/enterpriseinformation/CredentialManagementServiceImpl.java b/yudao-module-fta/yudao-module-fta-biz/src/main/java/cn/iocoder/yudao/module/fta/service/enterpriseinformation/CredentialManagementServiceImpl.java index 7d120c0..817bc9c 100644 --- a/yudao-module-fta/yudao-module-fta-biz/src/main/java/cn/iocoder/yudao/module/fta/service/enterpriseinformation/CredentialManagementServiceImpl.java +++ b/yudao-module-fta/yudao-module-fta-biz/src/main/java/cn/iocoder/yudao/module/fta/service/enterpriseinformation/CredentialManagementServiceImpl.java @@ -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 getAllCertificates() { + /** + * 1、查询出所有的CredentialManagementDO信息 + */ + return credentialManagementMapper.selectList(); + } + + //public List> getAllCertificates() { + // List> certificates = new ArrayList<>(); + // + // // 查询出所有的企业ID + // List enterpriseIds = credentialManagementMapper.selectById(); + // + // // 查询每个企业的证书到期时间 + // for (String enterpriseId : enterpriseIds) { + // // 查询该企业的证书到期时间 + // LocalDate expiryDate = credentialManagementMapper.selectExpiryDateByEnterpriseId(enterpriseId); + // + // // 构造证书信息对象,包含企业ID和到期时间 + // Map certificateInfo = new HashMap<>(); + // certificateInfo.put("enterpriseId", enterpriseId); + // certificateInfo.put("expiryDate", expiryDate); + // + // // 将证书信息添加到列表中 + // certificates.add(certificateInfo); + // } + // + // return certificates; + //} + + + + //List certificates = new ArrayList<>(); + // + //// 在这里查询企业证件信息,你的实现可能会有所不同 + // + //// 假设这里是一个数据库查询的示例 + //List 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); + //} } \ No newline at end of file diff --git a/yudao-server/src/main/resources/application-local.yaml b/yudao-server/src/main/resources/application-local.yaml index 5185b1c..966a61b 100644 --- a/yudao-server/src/main/resources/application-local.yaml +++ b/yudao-server/src/main/resources/application-local.yaml @@ -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 的自动配置