diff --git a/easy-retry-datasource/easy-retry-mariadb-datasource/src/main/resources/mariadb/mapper/JobSummaryMapper.xml b/easy-retry-datasource/easy-retry-mariadb-datasource/src/main/resources/mariadb/mapper/JobSummaryMapper.xml index ebfee3b87..4017a30da 100644 --- a/easy-retry-datasource/easy-retry-mariadb-datasource/src/main/resources/mariadb/mapper/JobSummaryMapper.xml +++ b/easy-retry-datasource/easy-retry-mariadb-datasource/src/main/resources/mariadb/mapper/JobSummaryMapper.xml @@ -77,6 +77,12 @@ ifnull(SUM(success_num + fail_num + stop_num + cancel_num), 0) AS total FROM job_summary + + AND group_name IN + + #{groupName} + + AND group_name = #{groupName} @@ -94,6 +100,12 @@ ifnull(sum(success_num + fail_num + stop_num + cancel_num), 0) AS totalNum FROM job_summary WHERE namespace_id = #{namespaceId} + + AND group_name IN + + #{groupName} + + diff --git a/easy-retry-datasource/easy-retry-mariadb-datasource/src/main/resources/mariadb/mapper/RetrySummaryMapper.xml b/easy-retry-datasource/easy-retry-mariadb-datasource/src/main/resources/mariadb/mapper/RetrySummaryMapper.xml index b85f03ada..e3563a264 100644 --- a/easy-retry-datasource/easy-retry-mariadb-datasource/src/main/resources/mariadb/mapper/RetrySummaryMapper.xml +++ b/easy-retry-datasource/easy-retry-mariadb-datasource/src/main/resources/mariadb/mapper/RetrySummaryMapper.xml @@ -48,6 +48,12 @@ ifnull(sum(running_num + finish_num + max_count_num + suspend_num), 0) AS totalNum FROM retry_summary WHERE namespace_id = #{namespaceId} + + AND group_name IN + + #{groupName} + + diff --git a/easy-retry-datasource/easy-retry-mysql-datasource/src/main/resources/mysql/mapper/RetrySummaryMapper.xml b/easy-retry-datasource/easy-retry-mysql-datasource/src/main/resources/mysql/mapper/RetrySummaryMapper.xml index d52273ee3..e3563a264 100644 --- a/easy-retry-datasource/easy-retry-mysql-datasource/src/main/resources/mysql/mapper/RetrySummaryMapper.xml +++ b/easy-retry-datasource/easy-retry-mysql-datasource/src/main/resources/mysql/mapper/RetrySummaryMapper.xml @@ -114,17 +114,17 @@ ifnull(SUM(finish_num + running_num + max_count_num + suspend_num), 0) AS total FROM retry_summary + + AND group_name IN + + #{groupName} + + AND group_name = #{groupName} AND namespace_id = #{namespaceId} AND trigger_at BETWEEN #{from} AND #{to} - - AND group_name IN - - #{groupName} - - GROUP BY createDt @@ -134,18 +134,18 @@ CONCAT(group_name, '/', scene_name) `name`, SUM(running_num + finish_num + max_count_num + suspend_num) AS total FROM retry_summary + + AND group_name IN + + #{groupName} + + AND group_name = #{groupName} AND namespace_id = #{namespaceId} AND trigger_at >= #{startTime} AND trigger_at <= #{endTime} - - AND group_name IN - - #{groupName} - - GROUP BY namespace_id, group_name, scene_name HAVING total > 0 ORDER BY total DESC LIMIT 10 diff --git a/easy-retry-datasource/easy-retry-postgres-datasource/src/main/resources/postgres/mapper/JobSummaryMapper.xml b/easy-retry-datasource/easy-retry-postgres-datasource/src/main/resources/postgres/mapper/JobSummaryMapper.xml index f5bcba14d..f90941725 100644 --- a/easy-retry-datasource/easy-retry-postgres-datasource/src/main/resources/postgres/mapper/JobSummaryMapper.xml +++ b/easy-retry-datasource/easy-retry-postgres-datasource/src/main/resources/postgres/mapper/JobSummaryMapper.xml @@ -77,6 +77,12 @@ COALESCE(SUM(success_num + fail_num + stop_num + cancel_num), 0) AS total FROM job_summary + + AND group_name IN + + #{groupName} + + AND group_name = #{groupName} @@ -94,6 +100,12 @@ COALESCE(sum(success_num + fail_num + stop_num + cancel_num), 0) AS totalNum FROM job_summary WHERE namespace_id = #{namespaceId} + + AND group_name IN + + #{groupName} + + diff --git a/easy-retry-datasource/easy-retry-postgres-datasource/src/main/resources/postgres/mapper/RetrySummaryMapper.xml b/easy-retry-datasource/easy-retry-postgres-datasource/src/main/resources/postgres/mapper/RetrySummaryMapper.xml index 8a6680bd2..8e8a9319b 100644 --- a/easy-retry-datasource/easy-retry-postgres-datasource/src/main/resources/postgres/mapper/RetrySummaryMapper.xml +++ b/easy-retry-datasource/easy-retry-postgres-datasource/src/main/resources/postgres/mapper/RetrySummaryMapper.xml @@ -48,6 +48,12 @@ COALESCE(sum(running_num + finish_num + max_count_num + suspend_num), 0) AS totalNum FROM retry_summary WHERE namespace_id = #{namespaceId} + + AND group_name IN + + #{groupName} + + diff --git a/easy-retry-server/easy-retry-server-web/src/main/java/com/aizuda/easy/retry/server/web/controller/GroupConfigController.java b/easy-retry-server/easy-retry-server-web/src/main/java/com/aizuda/easy/retry/server/web/controller/GroupConfigController.java index 8250faafe..5db42ccda 100644 --- a/easy-retry-server/easy-retry-server-web/src/main/java/com/aizuda/easy/retry/server/web/controller/GroupConfigController.java +++ b/easy-retry-server/easy-retry-server-web/src/main/java/com/aizuda/easy/retry/server/web/controller/GroupConfigController.java @@ -12,11 +12,19 @@ import com.aizuda.easy.retry.server.web.annotation.LoginRequired; import com.aizuda.easy.retry.server.web.annotation.RoleEnum; import com.aizuda.easy.retry.server.web.service.GroupConfigService; import com.aizuda.easy.retry.template.datasource.enums.DbTypeEnum; +import com.google.common.collect.Lists; +import com.zaxxer.hikari.HikariDataSource; +import org.jetbrains.annotations.NotNull; +import org.slf4j.helpers.MessageFormatter; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import javax.sql.DataSource; +import java.sql.Connection; +import java.sql.SQLException; +import java.text.MessageFormat; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; @@ -33,10 +41,6 @@ public class GroupConfigController { @Autowired private GroupConfigService groupConfigService; - @Autowired - private SystemProperties systemProperties; - @Autowired - private JdbcTemplate jdbcTemplate; @LoginRequired(role = RoleEnum.ADMIN) @PostMapping("") @@ -91,20 +95,7 @@ public class GroupConfigController { @LoginRequired(role = RoleEnum.ADMIN) @GetMapping("/partition-table/list") public List getTablePartitionList() { - // https://gitee.com/aizuda/easy-retry/issues/I8DAMH - String sql; - if (systemProperties.getDbType().getDb().equals(DbTypeEnum.POSTGRES.getDb())) { - sql = "SELECT table_name\n" - + "FROM information_schema.tables\n" - + "WHERE table_name LIKE 'retry_task_%' AND table_schema = 'public'"; - } else { - sql = "SHOW TABLES LIKE 'retry_task_%'"; - } - - List tableList = jdbcTemplate.queryForList(sql, String.class); - return tableList.stream().map(ReUtil::getFirstNumber).filter(i -> - !Objects.isNull(i) && i <= systemProperties.getTotalPartition()).distinct().collect(Collectors.toList()); + return groupConfigService.getTablePartitionList(); } - } diff --git a/easy-retry-server/easy-retry-server-web/src/main/java/com/aizuda/easy/retry/server/web/service/GroupConfigService.java b/easy-retry-server/easy-retry-server-web/src/main/java/com/aizuda/easy/retry/server/web/service/GroupConfigService.java index 472b0f5e1..dbbade44b 100644 --- a/easy-retry-server/easy-retry-server-web/src/main/java/com/aizuda/easy/retry/server/web/service/GroupConfigService.java +++ b/easy-retry-server/easy-retry-server-web/src/main/java/com/aizuda/easy/retry/server/web/service/GroupConfigService.java @@ -29,4 +29,6 @@ public interface GroupConfigService { List getAllGroupNameList(); List getOnlinePods(String groupName); + + List getTablePartitionList(); } diff --git a/easy-retry-server/easy-retry-server-web/src/main/java/com/aizuda/easy/retry/server/web/service/impl/GroupConfigServiceImpl.java b/easy-retry-server/easy-retry-server-web/src/main/java/com/aizuda/easy/retry/server/web/service/impl/GroupConfigServiceImpl.java index ac94c120a..c9bbec9b0 100644 --- a/easy-retry-server/easy-retry-server-web/src/main/java/com/aizuda/easy/retry/server/web/service/impl/GroupConfigServiceImpl.java +++ b/easy-retry-server/easy-retry-server-web/src/main/java/com/aizuda/easy/retry/server/web/service/impl/GroupConfigServiceImpl.java @@ -2,6 +2,7 @@ package com.aizuda.easy.retry.server.web.service.impl; import cn.hutool.core.lang.Assert; import cn.hutool.core.util.HashUtil; +import cn.hutool.core.util.ReUtil; import cn.hutool.core.util.StrUtil; import com.aizuda.easy.retry.server.common.config.SystemProperties; import com.aizuda.easy.retry.server.common.enums.IdGeneratorMode; @@ -26,13 +27,20 @@ import com.aizuda.easy.retry.template.datasource.persistence.po.*; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO; +import com.google.common.collect.Lists; +import org.jetbrains.annotations.NotNull; +import org.slf4j.helpers.MessageFormatter; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; import org.springframework.jdbc.BadSqlGrammarException; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; +import javax.sql.DataSource; +import java.sql.Connection; +import java.sql.SQLException; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; @@ -59,9 +67,10 @@ public class GroupConfigServiceImpl implements GroupConfigService { @Autowired @Lazy private ConfigVersionSyncHandler configVersionSyncHandler; - @Autowired private SystemProperties systemProperties; + @Autowired + private JdbcTemplate jdbcTemplate; @Override @Transactional @@ -321,4 +330,40 @@ public class GroupConfigServiceImpl implements GroupConfigService { .collect(Collectors.toList()); } + @Override + public List getTablePartitionList() { + DataSource dataSource = jdbcTemplate.getDataSource(); + Connection connection = null; + try { + connection = dataSource.getConnection(); + String catalog = connection.getCatalog(); + String schema = connection.getSchema(); + + // https://gitee.com/aizuda/easy-retry/issues/I8DAMH + String sql = MessageFormatter.arrayFormat("SELECT table_name\n" + + "FROM information_schema.tables\n" + + "WHERE table_name LIKE 'retry_task_%' AND table_schema = '{}' and table_catalog = '{}'", new Object[]{schema, catalog}).getMessage(); + + List tableList = jdbcTemplate.queryForList(sql, String.class); + return tableList.stream().map(ReUtil::getFirstNumber).filter(i -> + !Objects.isNull(i) && i <= systemProperties.getTotalPartition()).distinct() + .collect(Collectors.toList()); + } catch (SQLException ignored) { + } finally { + if (Objects.nonNull(connection)) { + try { + connection.close(); + } catch (SQLException ignored) { + } + } + } + + // 兜底 + List tableList = Lists.newArrayList(); + for (int i = 0; i < systemProperties.getTotalPartition(); i++) { + tableList.add(i); + } + return tableList; + } + }