Commit 4f29d01af456f70a42f3928ded7acb966b9527a2
1 parent
aed69510
feat(storage): 新增根据租户ID和管道码查询功能
- 在ITaxTenantService接口中新增findByTenantIdAndPipelineCode方法 - 在TaxTenantService实现类中实现新的查询方法 - 优化TenantStorageContext上下文加载逻辑 - 移除CommandLineRunner接口改为使用ApplicationReadyEvent事件监听 - 更新租户管道查询逻辑,支持通过tenantId直接查询 - 清理无用的事件发布代码和相关依赖注入
Showing
4 changed files
with
18 additions
and
34 deletions
tax-boot/src/main/resources/application.properties
| @@ -11,21 +11,3 @@ spring.cloud.nacos.config.server-addr=nacos.diligrp.com:8848 | @@ -11,21 +11,3 @@ spring.cloud.nacos.config.server-addr=nacos.diligrp.com:8848 | ||
| 11 | spring.cloud.nacos.config.namespace=54c39cfe-d1c4-4022-a94b-a3486c5927fc | 11 | spring.cloud.nacos.config.namespace=54c39cfe-d1c4-4022-a94b-a3486c5927fc |
| 12 | spring.config.import[0]=nacos:${spring.application.name}.properties | 12 | spring.config.import[0]=nacos:${spring.application.name}.properties |
| 13 | spring.config.import[1]=nacos:${spring.application.name}-${spring.profiles.active}.properties | 13 | spring.config.import[1]=nacos:${spring.application.name}-${spring.profiles.active}.properties |
| 14 | -#mybatis-plus | ||
| 15 | -logging.config=classpath:logback-spring.xml | ||
| 16 | -mybatis-plus.mapper-locations=classpath*:com/diligrp/tax/**/repo/*.xml | ||
| 17 | -mybatis-plus.configuration.map-underscore-to-camel-case=true | ||
| 18 | -mybatis-plus.configuration.cache-enabled=true | ||
| 19 | -mybatis-plus.global-config.banner=false | ||
| 20 | -spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver | ||
| 21 | -spring.datasource.url=jdbc:mysql://mysql.diligrp.com:3306/dili_tax?useUnicode=true&characterEncoding=utf8&useSSL=false&allowMultiQueries=true&serverTimezone=GMT%2B8 | ||
| 22 | -spring.datasource.username=root | ||
| 23 | -spring.datasource.password=OTM0NjAwMTMyMjZlNzgy | ||
| 24 | -spring.datasource.type=com.zaxxer.hikari.HikariDataSource | ||
| 25 | -spring.datasource.hikari.pool-name=ErpHikariPool | ||
| 26 | -spring.datasource.hikari.minimum-idle=4 | ||
| 27 | -spring.datasource.hikari.maximum-pool-size=60 | ||
| 28 | -spring.datasource.hikari.idle-timeout=120000 | ||
| 29 | -spring.datasource.hikari.max-lifetime=900000 | ||
| 30 | -spring.datasource.hikari.connection-timeout=15000 | ||
| 31 | -spring.datasource.hikari.connection-test-query=SELECT 1 |
tax-central/src/main/java/com/diligrp/tax/central/context/TenantStorageContext.java
| 1 | package com.diligrp.tax.central.context; | 1 | package com.diligrp.tax.central.context; |
| 2 | 2 | ||
| 3 | -import com.diligrp.tax.central.event.RestoreTenantEvent; | ||
| 4 | import com.diligrp.tax.central.model.TenantPipeline; | 3 | import com.diligrp.tax.central.model.TenantPipeline; |
| 5 | import com.diligrp.tax.central.service.ITaxTenantService; | 4 | import com.diligrp.tax.central.service.ITaxTenantService; |
| 6 | import com.diligrp.tax.central.type.SystemType; | 5 | import com.diligrp.tax.central.type.SystemType; |
| 7 | import jakarta.annotation.Resource; | 6 | import jakarta.annotation.Resource; |
| 8 | import lombok.extern.slf4j.Slf4j; | 7 | import lombok.extern.slf4j.Slf4j; |
| 9 | -import org.springframework.boot.CommandLineRunner; | 8 | +import org.springframework.boot.context.event.ApplicationReadyEvent; |
| 10 | import org.springframework.context.ApplicationEventPublisher; | 9 | import org.springframework.context.ApplicationEventPublisher; |
| 10 | +import org.springframework.context.event.EventListener; | ||
| 11 | import org.springframework.stereotype.Component; | 11 | import org.springframework.stereotype.Component; |
| 12 | 12 | ||
| 13 | import java.util.List; | 13 | import java.util.List; |
| @@ -24,12 +24,10 @@ import java.util.stream.Collectors; | @@ -24,12 +24,10 @@ import java.util.stream.Collectors; | ||
| 24 | */ | 24 | */ |
| 25 | @Slf4j | 25 | @Slf4j |
| 26 | @Component | 26 | @Component |
| 27 | -public class TenantStorageContext implements CommandLineRunner { | 27 | +public class TenantStorageContext { |
| 28 | 28 | ||
| 29 | @Resource | 29 | @Resource |
| 30 | private ITaxTenantService tenantTaxService; | 30 | private ITaxTenantService tenantTaxService; |
| 31 | - @Resource | ||
| 32 | - private ApplicationEventPublisher publisher; | ||
| 33 | 31 | ||
| 34 | private static final ConcurrentHashMap<Long, Map<SystemType, Map<String, TenantPipeline>>> TENANT_PIPELINE_MAP = new ConcurrentHashMap<>(); | 32 | private static final ConcurrentHashMap<Long, Map<SystemType, Map<String, TenantPipeline>>> TENANT_PIPELINE_MAP = new ConcurrentHashMap<>(); |
| 35 | 33 | ||
| @@ -42,24 +40,16 @@ public class TenantStorageContext implements CommandLineRunner { | @@ -42,24 +40,16 @@ public class TenantStorageContext implements CommandLineRunner { | ||
| 42 | if (Objects.isNull(pipelineMap)) { | 40 | if (Objects.isNull(pipelineMap)) { |
| 43 | return Optional.empty(); | 41 | return Optional.empty(); |
| 44 | } | 42 | } |
| 45 | - return Optional.ofNullable(pipelineMap.get(pipelineCode)); | 43 | + return Optional.ofNullable(pipelineMap.get(pipelineCode)).or(() -> tenantTaxService.findByTenantIdAndPipelineCode(tenantId, pipelineCode)); |
| 46 | } | 44 | } |
| 47 | 45 | ||
| 46 | + @EventListener(ApplicationReadyEvent.class) | ||
| 48 | public void loadTenantPipeline() { | 47 | public void loadTenantPipeline() { |
| 49 | List<TenantPipeline> taxPipelineVOS = tenantTaxService.listAllEnablePipeline(); | 48 | List<TenantPipeline> taxPipelineVOS = tenantTaxService.listAllEnablePipeline(); |
| 50 | Optional.ofNullable(taxPipelineVOS).ifPresent(pipelines -> { | 49 | Optional.ofNullable(taxPipelineVOS).ifPresent(pipelines -> { |
| 51 | - var tenantPipelineMap = pipelines.stream() | ||
| 52 | - .collect(Collectors.groupingBy(TenantPipeline::getTenantId, | ||
| 53 | - Collectors.groupingBy(TenantPipeline::getSystemType, | ||
| 54 | - Collectors.toMap(TenantPipeline::getCode, e -> e))) | ||
| 55 | - ); | 50 | + var tenantPipelineMap = pipelines.stream().collect(Collectors.groupingBy(TenantPipeline::getTenantId, Collectors.groupingBy(TenantPipeline::getSystemType, Collectors.toMap(TenantPipeline::getCode, e -> e)))); |
| 56 | TENANT_PIPELINE_MAP.clear(); | 51 | TENANT_PIPELINE_MAP.clear(); |
| 57 | TENANT_PIPELINE_MAP.putAll(tenantPipelineMap); | 52 | TENANT_PIPELINE_MAP.putAll(tenantPipelineMap); |
| 58 | }); | 53 | }); |
| 59 | } | 54 | } |
| 60 | - | ||
| 61 | - @Override | ||
| 62 | - public void run(String... args) throws Exception { | ||
| 63 | - publisher.publishEvent(new RestoreTenantEvent(this)); | ||
| 64 | - } | ||
| 65 | } | 55 | } |
tax-central/src/main/java/com/diligrp/tax/central/service/ITaxTenantService.java
| @@ -38,6 +38,13 @@ public interface ITaxTenantService { | @@ -38,6 +38,13 @@ public interface ITaxTenantService { | ||
| 38 | Optional<TenantPipeline> findByTenantAndPipelineCode(String group,String entity,String pipelineCode); | 38 | Optional<TenantPipeline> findByTenantAndPipelineCode(String group,String entity,String pipelineCode); |
| 39 | 39 | ||
| 40 | /** | 40 | /** |
| 41 | + * 列出所有启用管道 | ||
| 42 | + * | ||
| 43 | + * @return {@link List }<{@link TenantPipeline }> | ||
| 44 | + */ | ||
| 45 | + Optional<TenantPipeline> findByTenantIdAndPipelineCode(Long tenantId,String pipelineCode); | ||
| 46 | + | ||
| 47 | + /** | ||
| 41 | * 按管道 ID 列出 | 48 | * 按管道 ID 列出 |
| 42 | * | 49 | * |
| 43 | * @param pipelineId 管道 ID | 50 | * @param pipelineId 管道 ID |
tax-storage/src/main/java/com/diligrp/tax/storage/service/TaxTenantService.java
| @@ -79,6 +79,11 @@ public class TaxTenantService implements ITaxTenantService { | @@ -79,6 +79,11 @@ public class TaxTenantService implements ITaxTenantService { | ||
| 79 | @Override | 79 | @Override |
| 80 | public Optional<TenantPipeline> findByTenantAndPipelineCode(String group, String entity, String pipelineCode) { | 80 | public Optional<TenantPipeline> findByTenantAndPipelineCode(String group, String entity, String pipelineCode) { |
| 81 | Long tenantId = getTenantId(group, entity); | 81 | Long tenantId = getTenantId(group, entity); |
| 82 | + return findByTenantIdAndPipelineCode(tenantId, pipelineCode); | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + @Override | ||
| 86 | + public Optional<TenantPipeline> findByTenantIdAndPipelineCode(Long tenantId, String pipelineCode) { | ||
| 82 | LambdaQueryWrapper<TaxPipeline> queryWrapper = new LambdaQueryWrapper<>(); | 87 | LambdaQueryWrapper<TaxPipeline> queryWrapper = new LambdaQueryWrapper<>(); |
| 83 | queryWrapper.eq(TaxPipeline::getCode, pipelineCode); | 88 | queryWrapper.eq(TaxPipeline::getCode, pipelineCode); |
| 84 | queryWrapper.eq(TaxPipeline::getTenantId, tenantId); | 89 | queryWrapper.eq(TaxPipeline::getTenantId, tenantId); |