From c14e433f949c5f8c93f66903d1728c199ee75b34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E9=9B=A8=E7=96=8F?= <35320326+wildeslam@users.noreply.github.com> Date: Fri, 5 Jul 2024 14:38:20 +0800 Subject: [PATCH] Feat/auto save systremConfig (#430) * feat: add queryAppContracts internal interface * feat: add queryAppContracts internal interface * feat: auto save systemConfig * feat: auto save systemConfig --------- Co-authored-by: wildeslam --- .../beans/ExpandableBeanConfiguration.java | 10 +++++ .../service/beans/SystemConfigBootstrap.java | 40 +++++++++++++++++++ .../auto/SystemConfigAutoConfiguration.java | 13 ------ .../mongo/AppContractRepositoryImpl.java | 11 +++-- pom.xml | 4 +- 5 files changed, 60 insertions(+), 18 deletions(-) create mode 100644 arex-web-api/src/main/java/com/arextest/web/api/service/beans/SystemConfigBootstrap.java delete mode 100644 arex-web-api/src/main/java/com/arextest/web/api/service/beans/auto/SystemConfigAutoConfiguration.java diff --git a/arex-web-api/src/main/java/com/arextest/web/api/service/beans/ExpandableBeanConfiguration.java b/arex-web-api/src/main/java/com/arextest/web/api/service/beans/ExpandableBeanConfiguration.java index d96a0609..5e9340ea 100644 --- a/arex-web-api/src/main/java/com/arextest/web/api/service/beans/ExpandableBeanConfiguration.java +++ b/arex-web-api/src/main/java/com/arextest/web/api/service/beans/ExpandableBeanConfiguration.java @@ -2,6 +2,7 @@ import com.arextest.common.cache.CacheProvider; import com.arextest.config.repository.impl.SystemConfigurationRepositoryImpl; +import com.arextest.web.core.business.ConfigLoadService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; @@ -28,4 +29,13 @@ public OldDataCleaner oldDataCleaner(CacheProvider cacheProvider, return new OldDataCleaner(cacheProvider, mongoTemplate, redisLeaseTime, systemConfigurationRepository); } + @Lazy(false) + @Bean + @ConditionalOnMissingBean(name = "systemConfigBootstrap") + public SystemConfigBootstrap systemConfigBootstrap( + ConfigLoadService configLoadService, + SystemConfigurationRepositoryImpl systemConfigurationRepository) { + return new SystemConfigBootstrap(configLoadService, systemConfigurationRepository); + } + } diff --git a/arex-web-api/src/main/java/com/arextest/web/api/service/beans/SystemConfigBootstrap.java b/arex-web-api/src/main/java/com/arextest/web/api/service/beans/SystemConfigBootstrap.java new file mode 100644 index 00000000..88b02757 --- /dev/null +++ b/arex-web-api/src/main/java/com/arextest/web/api/service/beans/SystemConfigBootstrap.java @@ -0,0 +1,40 @@ +package com.arextest.web.api.service.beans; + +import com.arextest.config.model.dao.config.SystemConfigurationCollection.KeySummary; +import com.arextest.config.model.dto.system.SystemConfiguration; +import com.arextest.config.repository.SystemConfigurationRepository; +import com.arextest.web.core.business.ConfigLoadService; +import java.util.HashSet; +import java.util.Set; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.InitializingBean; + +/** + * @author wildeslam. + * @create 2024/7/3 16:15 + */ +@Data +@Slf4j +@AllArgsConstructor +public class SystemConfigBootstrap implements InitializingBean { + + private ConfigLoadService configLoadService; + private SystemConfigurationRepository systemConfigurationRepository; + + + @Override + public void afterPropertiesSet() { + Set ignoreNodeSet = configLoadService.getIgnoreNodeSet(""); + if (ignoreNodeSet == null) { + ignoreNodeSet = new HashSet<>(); + } + SystemConfiguration systemConfiguration = new SystemConfiguration(); + systemConfiguration.setKey(KeySummary.IGNORE_NODE_SET); + systemConfiguration.setIgnoreNodeSet(ignoreNodeSet); + systemConfigurationRepository.saveConfig(systemConfiguration); + } + + +} diff --git a/arex-web-api/src/main/java/com/arextest/web/api/service/beans/auto/SystemConfigAutoConfiguration.java b/arex-web-api/src/main/java/com/arextest/web/api/service/beans/auto/SystemConfigAutoConfiguration.java deleted file mode 100644 index 7a7ce125..00000000 --- a/arex-web-api/src/main/java/com/arextest/web/api/service/beans/auto/SystemConfigAutoConfiguration.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.arextest.web.api.service.beans.auto; - -import org.springframework.context.annotation.Configuration; - -/** - * @author wildeslam. - * @create 2024/6/27 20:20 - */ -@Configuration -public class SystemConfigAutoConfiguration { - - -} diff --git a/arex-web-core/src/main/java/com/arextest/web/core/repository/mongo/AppContractRepositoryImpl.java b/arex-web-core/src/main/java/com/arextest/web/core/repository/mongo/AppContractRepositoryImpl.java index eea61d0f..8c9b2ccd 100644 --- a/arex-web-core/src/main/java/com/arextest/web/core/repository/mongo/AppContractRepositoryImpl.java +++ b/arex-web-core/src/main/java/com/arextest/web/core/repository/mongo/AppContractRepositoryImpl.java @@ -14,6 +14,7 @@ import javax.annotation.Resource; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.data.mongodb.core.BulkOperations; import org.springframework.data.mongodb.core.FindAndModifyOptions; import org.springframework.data.mongodb.core.MongoTemplate; @@ -182,9 +183,13 @@ public AppContractDto queryDependency(String operationId, String operationType, @Override public List queryAppContracts(String appId, String operationId) { - Query query = Query.query( - Criteria.where(AppContractCollection.Fields.operationId).is(operationId) - .and(AppContractCollection.Fields.appId).is(appId)); + Query query = new Query(); + if (StringUtils.isNotBlank(appId)) { + query.addCriteria(Criteria.where(AppContractCollection.Fields.appId).is(appId)); + } + if (StringUtils.isNotBlank(operationId)) { + query.addCriteria(Criteria.where(AppContractCollection.Fields.operationId).is(operationId)); + } List daos = mongoTemplate.find(query, AppContractCollection.class); return daos.stream().map(AppContractMapper.INSTANCE::dtoFromDao).collect(Collectors.toList()); } diff --git a/pom.xml b/pom.xml index baf08a28..be7c7107 100644 --- a/pom.xml +++ b/pom.xml @@ -495,10 +495,10 @@ - 0.6.5 + 0.6.5.1 0.1.28 0.0.1 - 1.2.7 + 1.2.15 1.1.27 0.0.1 2.9.3