init
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
package cn.datax.service.data.metadata;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.cloud.client.SpringCloudApplication;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
|
||||
@EnableFeignClients(basePackages = {"cn.datax.service.system.api.feign"
|
||||
, "cn.datax.service.data.standard.api.feign"
|
||||
, "cn.datax.service.data.quality.api.feign"
|
||||
, "cn.datax.service.data.market.api.feign"
|
||||
, "cn.datax.service.data.visual.api.feign"})
|
||||
@SpringBootApplication
|
||||
public class DataxMetadataApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(DataxMetadataApplication.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
package cn.datax.service.data.metadata.async;
|
||||
|
||||
import cn.datax.common.database.DataSourceFactory;
|
||||
import cn.datax.common.database.DbQuery;
|
||||
import cn.datax.common.database.constants.DbQueryProperty;
|
||||
import cn.datax.common.database.core.DbColumn;
|
||||
import cn.datax.common.database.core.DbTable;
|
||||
import cn.datax.service.data.metadata.api.dto.DbSchema;
|
||||
import cn.datax.service.data.metadata.api.entity.MetadataColumnEntity;
|
||||
import cn.datax.service.data.metadata.api.entity.MetadataSourceEntity;
|
||||
import cn.datax.service.data.metadata.api.entity.MetadataTableEntity;
|
||||
import cn.datax.service.data.metadata.api.enums.SyncStatus;
|
||||
import cn.datax.service.data.metadata.dao.MetadataColumnDao;
|
||||
import cn.datax.service.data.metadata.dao.MetadataSourceDao;
|
||||
import cn.datax.service.data.metadata.dao.MetadataTableDao;
|
||||
import cn.datax.service.data.metadata.service.MetadataSourceService;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 异步处理
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class AsyncTask {
|
||||
|
||||
@Autowired
|
||||
private DataSourceFactory dataSourceFactory;
|
||||
|
||||
@Autowired
|
||||
private MetadataSourceDao metadataSourceDao;
|
||||
|
||||
@Autowired
|
||||
private MetadataTableDao metadataTableDao;
|
||||
|
||||
@Autowired
|
||||
private MetadataColumnDao metadataColumnDao;
|
||||
|
||||
@Async("taskExecutor")
|
||||
public void doTask(MetadataSourceEntity dataSource, MetadataSourceService metadataSourceService) {
|
||||
dataSource.setIsSync(SyncStatus.InSync.getKey());
|
||||
metadataSourceDao.updateById(dataSource);
|
||||
long start = System.currentTimeMillis();
|
||||
try {
|
||||
DbSchema dbSchema = dataSource.getDbSchema();
|
||||
DbQueryProperty dbQueryProperty = new DbQueryProperty(dataSource.getDbType(), dbSchema.getHost(),
|
||||
dbSchema.getUsername(), dbSchema.getPassword(), dbSchema.getPort(), dbSchema.getDbName(), dbSchema.getSid());
|
||||
DbQuery dbQuery = dataSourceFactory.createDbQuery(dbQueryProperty);
|
||||
List<DbTable> tables = dbQuery.getTables(dbSchema.getDbName());
|
||||
if (CollUtil.isNotEmpty(tables)) {
|
||||
List<MetadataTableEntity> metadataTableEntityList = tables.stream().map(table -> {
|
||||
MetadataTableEntity metadataTable = new MetadataTableEntity();
|
||||
metadataTable.setSourceId(dataSource.getId());
|
||||
metadataTable.setTableName(table.getTableName());
|
||||
metadataTable.setTableComment(table.getTableComment());
|
||||
return metadataTable;
|
||||
}).collect(Collectors.toList());
|
||||
if (CollUtil.isNotEmpty(metadataTableEntityList)) {
|
||||
for (MetadataTableEntity table : metadataTableEntityList) {
|
||||
MetadataTableEntity tableEntity = metadataTableDao.selectOne(new QueryWrapper<MetadataTableEntity>()
|
||||
.eq("source_id", dataSource.getId())
|
||||
.eq("table_name", table.getTableName())
|
||||
.last("limit 1"));
|
||||
if (tableEntity != null) {
|
||||
table.setId(tableEntity.getId());
|
||||
metadataTableDao.updateById(table);
|
||||
} else {
|
||||
metadataTableDao.insert(table);
|
||||
}
|
||||
List<DbColumn> columns = dbQuery.getTableColumns(dbSchema.getDbName(), table.getTableName());
|
||||
if (CollUtil.isNotEmpty(columns)) {
|
||||
List<MetadataColumnEntity> metadataColumnEntityList = columns.stream().map(column -> {
|
||||
MetadataColumnEntity metadataColumn = new MetadataColumnEntity();
|
||||
metadataColumn.setSourceId(dataSource.getId());
|
||||
metadataColumn.setTableId(table.getId());
|
||||
metadataColumn.setColumnName(column.getColName());
|
||||
metadataColumn.setColumnComment(column.getColComment());
|
||||
metadataColumn.setColumnKey(column.getColKey() ? "1" : "0");
|
||||
metadataColumn.setColumnNullable(column.getNullable() ? "1" : "0");
|
||||
metadataColumn.setColumnPosition(column.getColPosition().toString());
|
||||
metadataColumn.setDataType(column.getDataType());
|
||||
metadataColumn.setDataLength(column.getDataLength());
|
||||
metadataColumn.setDataPrecision(column.getDataPrecision());
|
||||
metadataColumn.setDataScale(column.getDataScale());
|
||||
metadataColumn.setDataDefault(column.getDataDefault());
|
||||
return metadataColumn;
|
||||
}).collect(Collectors.toList());
|
||||
if (CollUtil.isNotEmpty(metadataColumnEntityList)) {
|
||||
for (MetadataColumnEntity column : metadataColumnEntityList) {
|
||||
MetadataColumnEntity columnEntity = metadataColumnDao.selectOne(new QueryWrapper<MetadataColumnEntity>()
|
||||
.eq("table_id", table.getId())
|
||||
.eq("column_name", column.getColumnName())
|
||||
.last("limit 1"));
|
||||
if (columnEntity != null) {
|
||||
column.setId(columnEntity.getId());
|
||||
metadataColumnDao.updateById(column);
|
||||
} else {
|
||||
metadataColumnDao.insert(column);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
dataSource.setIsSync(SyncStatus.SyncError.getKey());
|
||||
metadataSourceDao.updateById(dataSource);
|
||||
log.error("异步数据源 {} 同步出错!", dataSource.getSourceName(), e);
|
||||
return;
|
||||
}
|
||||
dataSource.setIsSync(SyncStatus.IsSync.getKey());
|
||||
metadataSourceDao.updateById(dataSource);
|
||||
metadataSourceService.refreshMetadata();
|
||||
log.info("异步数据源 {} 同步任务执行完成!耗时{}秒", dataSource.getSourceName(), (System.currentTimeMillis() - start / 1000));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package cn.datax.service.data.metadata.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
@EnableAsync
|
||||
@Configuration
|
||||
public class AsyncConfig {
|
||||
|
||||
@Bean("taskExecutor")
|
||||
public Executor taskExecutor() {
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
executor.setCorePoolSize(5);
|
||||
executor.setMaxPoolSize(20);
|
||||
executor.setQueueCapacity(100);
|
||||
executor.setKeepAliveSeconds(30);
|
||||
executor.setThreadNamePrefix("async-service-");
|
||||
executor.setWaitForTasksToCompleteOnShutdown(true);
|
||||
executor.setAwaitTerminationSeconds(60);
|
||||
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
||||
executor.initialize();
|
||||
executor.setTaskDecorator(new CustomTaskDecorator());
|
||||
return executor;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package cn.datax.service.data.metadata.config;
|
||||
|
||||
|
||||
import org.springframework.core.task.TaskDecorator;
|
||||
import org.springframework.web.context.request.RequestAttributes;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
public class CustomTaskDecorator implements TaskDecorator {
|
||||
@Override
|
||||
public Runnable decorate(Runnable runnable) {
|
||||
// 获取主线程中的请求信息(我们的用户信息也放在里面)
|
||||
RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
|
||||
attributes.setAttribute("token",((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest().getHeader("Authorization"),1);
|
||||
return () -> {
|
||||
try {
|
||||
// 将主线程的请求信息,设置到子线程中
|
||||
RequestContextHolder.setRequestAttributes(attributes);
|
||||
// 执行子线程,这一步不要忘了
|
||||
runnable.run();
|
||||
} finally {
|
||||
// 线程结束,清空这些信息,否则可能造成内存泄漏
|
||||
RequestContextHolder.resetRequestAttributes();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
package cn.datax.service.data.metadata.config;
|
||||
|
||||
import com.baomidou.dynamic.datasource.DynamicRoutingDataSource;
|
||||
import com.baomidou.dynamic.datasource.aop.DynamicDataSourceAnnotationAdvisor;
|
||||
import com.baomidou.dynamic.datasource.aop.DynamicDataSourceAnnotationInterceptor;
|
||||
import com.baomidou.dynamic.datasource.processor.DsProcessor;
|
||||
import com.baomidou.dynamic.datasource.provider.DynamicDataSourceProvider;
|
||||
import com.baomidou.dynamic.datasource.provider.YmlDynamicDataSourceProvider;
|
||||
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty;
|
||||
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSourceCreatorAutoConfiguration;
|
||||
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSourceProperties;
|
||||
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.druid.DruidDynamicDataSourceConfiguration;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.context.annotation.Role;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 动态数据源核心自动配置类
|
||||
* @author AllDataDC
|
||||
* @date 2023/03/17
|
||||
*/
|
||||
@Slf4j
|
||||
@Configuration
|
||||
@AllArgsConstructor
|
||||
@EnableConfigurationProperties(DynamicDataSourceProperties.class)
|
||||
@AutoConfigureBefore(DataSourceAutoConfiguration.class)
|
||||
@Import(value = {DruidDynamicDataSourceConfiguration.class, DynamicDataSourceCreatorAutoConfiguration.class})
|
||||
@ConditionalOnProperty(prefix = DynamicDataSourceProperties.PREFIX, name = "enabled", havingValue = "true", matchIfMissing = true)
|
||||
public class DynamicDSConfiguration {
|
||||
|
||||
private final DynamicDataSourceProperties properties;
|
||||
|
||||
//读取多数据源配置,注入到spring容器中
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public DynamicDataSourceProvider dynamicDataSourceProvider() {
|
||||
Map<String, DataSourceProperty> datasourceMap = properties.getDatasource();
|
||||
return new YmlDynamicDataSourceProvider(datasourceMap);
|
||||
}
|
||||
|
||||
//注册自己的动态多数据源DataSource
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public DataSource dataSource(DynamicDataSourceProvider dynamicDataSourceProvider) {
|
||||
DynamicRoutingDataSource dataSource = new DynamicRoutingDataSource();
|
||||
dataSource.setPrimary(properties.getPrimary());
|
||||
dataSource.setStrict(properties.getStrict());
|
||||
dataSource.setStrategy(properties.getStrategy());
|
||||
dataSource.setProvider(dynamicDataSourceProvider);
|
||||
dataSource.setP6spy(properties.getP6spy());
|
||||
dataSource.setSeata(properties.getSeata());
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
//AOP切面,对DS注解过的方法进行增强,达到切换数据源的目的
|
||||
@Role(value = BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public DynamicDataSourceAnnotationAdvisor dynamicDatasourceAnnotationAdvisor(DsProcessor dsProcessor) {
|
||||
DynamicDataSourceAnnotationInterceptor interceptor = new DynamicDataSourceAnnotationInterceptor(properties.isAllowedPublicOnly(), dsProcessor);
|
||||
DynamicDataSourceAnnotationAdvisor advisor = new DynamicDataSourceAnnotationAdvisor(interceptor);
|
||||
advisor.setOrder(properties.getOrder());
|
||||
return advisor;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package cn.datax.service.data.metadata.config;
|
||||
|
||||
import cn.datax.common.core.RedisConstant;
|
||||
import cn.datax.common.redis.service.RedisService;
|
||||
import cn.datax.service.data.metadata.api.entity.MetadataAuthorizeEntity;
|
||||
import cn.datax.service.data.metadata.api.entity.MetadataColumnEntity;
|
||||
import cn.datax.service.data.metadata.api.entity.MetadataSourceEntity;
|
||||
import cn.datax.service.data.metadata.api.entity.MetadataTableEntity;
|
||||
import cn.datax.service.data.metadata.dao.MetadataAuthorizeDao;
|
||||
import cn.datax.service.data.metadata.dao.MetadataColumnDao;
|
||||
import cn.datax.service.data.metadata.dao.MetadataSourceDao;
|
||||
import cn.datax.service.data.metadata.dao.MetadataTableDao;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class StartedUpRunner implements ApplicationRunner {
|
||||
|
||||
private final ConfigurableApplicationContext context;
|
||||
private final Environment environment;
|
||||
|
||||
@Autowired
|
||||
private MetadataSourceDao metadataSourceDao;
|
||||
|
||||
@Autowired
|
||||
private MetadataTableDao metadataTableDao;
|
||||
|
||||
@Autowired
|
||||
private MetadataColumnDao metadataColumnDao;
|
||||
|
||||
@Autowired
|
||||
private MetadataAuthorizeDao metadataAuthorizeDao;
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) {
|
||||
if (context.isActive()) {
|
||||
String banner = "-----------------------------------------\n" +
|
||||
"服务启动成功,时间:" + DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.now()) + "\n" +
|
||||
"服务名称:" + environment.getProperty("spring.application.name") + "\n" +
|
||||
"端口号:" + environment.getProperty("server.port") + "\n" +
|
||||
"-----------------------------------------";
|
||||
System.out.println(banner);
|
||||
|
||||
// 项目启动时,初始化缓存
|
||||
String sourceKey = RedisConstant.METADATA_SOURCE_KEY;
|
||||
Boolean hasSourceKey = redisService.hasKey(sourceKey);
|
||||
if (!hasSourceKey) {
|
||||
List<MetadataSourceEntity> sourceEntityList = metadataSourceDao.selectList(Wrappers.emptyWrapper());
|
||||
redisService.set(sourceKey, sourceEntityList);
|
||||
}
|
||||
|
||||
String tableKey = RedisConstant.METADATA_TABLE_KEY;
|
||||
Boolean hasTableKey = redisService.hasKey(tableKey);
|
||||
if (!hasTableKey) {
|
||||
List<MetadataTableEntity> tableEntityList = metadataTableDao.selectList(Wrappers.emptyWrapper());
|
||||
Map<String, List<MetadataTableEntity>> tableListMap = tableEntityList.stream().collect(Collectors.groupingBy(MetadataTableEntity::getSourceId));
|
||||
redisTemplate.opsForHash().putAll(tableKey, tableListMap);
|
||||
}
|
||||
|
||||
String columnKey = RedisConstant.METADATA_COLUMN_KEY;
|
||||
Boolean hasColumnKey = redisService.hasKey(columnKey);
|
||||
if (!hasColumnKey) {
|
||||
List<MetadataColumnEntity> columnEntityList = metadataColumnDao.selectList(Wrappers.emptyWrapper());
|
||||
Map<String, List<MetadataColumnEntity>> columnListMap = columnEntityList.stream().collect(Collectors.groupingBy(MetadataColumnEntity::getTableId));
|
||||
redisTemplate.opsForHash().putAll(columnKey, columnListMap);
|
||||
}
|
||||
|
||||
String authorizeKey = RedisConstant.METADATA_AUTHORIZE_KEY;
|
||||
Boolean hasAuthorizeKey = redisService.hasKey(authorizeKey);
|
||||
if (!hasAuthorizeKey) {
|
||||
List<MetadataAuthorizeEntity> metadataAuthorizeList = metadataAuthorizeDao.selectList(Wrappers.emptyWrapper());
|
||||
Map<String, List<MetadataAuthorizeEntity>> authorizeListMap = metadataAuthorizeList.stream().collect(Collectors.groupingBy(MetadataAuthorizeEntity::getRoleId));
|
||||
redisTemplate.opsForHash().putAll(authorizeKey, authorizeListMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
package cn.datax.service.data.metadata.config;
|
||||
|
||||
import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration;
|
||||
import springfox.documentation.builders.*;
|
||||
import springfox.documentation.schema.ModelRef;
|
||||
import springfox.documentation.service.*;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnProperty(prefix = "swagger", name = "enable", havingValue = "true")
|
||||
@EnableConfigurationProperties(SwaggerProperties.class)
|
||||
@EnableSwagger2
|
||||
@EnableKnife4j
|
||||
@Import(BeanValidatorPluginsConfiguration.class)
|
||||
public class SwaggerConfig {
|
||||
|
||||
@Autowired
|
||||
private SwaggerProperties swaggerProperties;
|
||||
|
||||
/**
|
||||
* 创建API应用
|
||||
* apiInfo() 增加API相关信息
|
||||
* 通过select()函数返回一个ApiSelectorBuilder实例,用来控制哪些接口暴露给Swagger来展现,
|
||||
* 本例采用指定扫描的包路径来定义指定要建立API的目录。
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public Docket createRestApi(){
|
||||
//版本类型是swagger2
|
||||
return new Docket(DocumentationType.SWAGGER_2)
|
||||
//通过调用自定义方法apiInfo,获得文档的主要信息
|
||||
.apiInfo(apiInfo())
|
||||
//设置全局参数
|
||||
.globalOperationParameters(globalParamBuilder())
|
||||
//设置全局响应参数
|
||||
.globalResponseMessage(RequestMethod.GET,responseBuilder())
|
||||
.globalResponseMessage(RequestMethod.POST,responseBuilder())
|
||||
.globalResponseMessage(RequestMethod.PUT,responseBuilder())
|
||||
.globalResponseMessage(RequestMethod.DELETE,responseBuilder())
|
||||
.select()
|
||||
//扫描该包下面的API注解
|
||||
.apis(RequestHandlerSelectors.basePackage(swaggerProperties.getBasePackage()))
|
||||
.paths(PathSelectors.any())
|
||||
.build()
|
||||
//设置安全认证
|
||||
;
|
||||
}
|
||||
/**
|
||||
* 创建该API的基本信息(这些基本信息会展现在文档页面中)
|
||||
* 访问地址:http://项目实际地址/swagger-ui.html
|
||||
* @return
|
||||
*/
|
||||
private ApiInfo apiInfo() {
|
||||
return new ApiInfoBuilder()
|
||||
.title(swaggerProperties.getTitle())
|
||||
.description(swaggerProperties.getDescription())
|
||||
.termsOfServiceUrl(swaggerProperties.getTermsOfServiceUrl())
|
||||
.version(swaggerProperties.getVersion())
|
||||
.contact(new Contact(swaggerProperties.getContact().getName(), swaggerProperties.getContact().getUrl(), swaggerProperties.getContact().getEmail()))
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 安全认证参数
|
||||
* @return
|
||||
*/
|
||||
private List<ApiKey> security() {
|
||||
List<ApiKey> apiKeys = new ArrayList<>();
|
||||
apiKeys.add(new ApiKey("Authorization", "Authorization", "header"));
|
||||
return apiKeys;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建全局参数列表
|
||||
* @return
|
||||
*/
|
||||
private List<Parameter> globalParamBuilder(){
|
||||
List<Parameter> pars = new ArrayList<>();
|
||||
pars.add(parameterBuilder("Authorization","令牌","string","header",false).build());
|
||||
return pars;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建参数
|
||||
* @return
|
||||
*/
|
||||
private ParameterBuilder parameterBuilder(String name, String desc, String type, String parameterType, boolean required) {
|
||||
ParameterBuilder tokenPar = new ParameterBuilder();
|
||||
tokenPar.name(name).description(desc).modelRef(new ModelRef(type)).parameterType(parameterType).required(required).build();
|
||||
return tokenPar;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建全局响应值
|
||||
* @return
|
||||
*/
|
||||
private List<ResponseMessage> responseBuilder() {
|
||||
List<ResponseMessage> responseMessageList = new ArrayList<>();
|
||||
responseMessageList.add(new ResponseMessageBuilder().code(200).message("响应成功").build());
|
||||
responseMessageList.add(new ResponseMessageBuilder().code(500).message("服务器内部错误").build());
|
||||
return responseMessageList;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package cn.datax.service.data.metadata.config;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
@ConfigurationProperties(ignoreUnknownFields = false, prefix = "swagger")
|
||||
public class SwaggerProperties {
|
||||
|
||||
private Boolean enable;
|
||||
private String title;
|
||||
private String description;
|
||||
private String version;
|
||||
private String termsOfServiceUrl;
|
||||
private String basePackage;
|
||||
private Contact contact;
|
||||
|
||||
public Boolean getEnable() {
|
||||
return enable;
|
||||
}
|
||||
|
||||
public void setEnable(Boolean enable) {
|
||||
this.enable = enable;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public String getTermsOfServiceUrl() {
|
||||
return termsOfServiceUrl;
|
||||
}
|
||||
|
||||
public void setTermsOfServiceUrl(String termsOfServiceUrl) {
|
||||
this.termsOfServiceUrl = termsOfServiceUrl;
|
||||
}
|
||||
|
||||
public String getBasePackage() {
|
||||
return basePackage;
|
||||
}
|
||||
|
||||
public void setBasePackage(String basePackage) {
|
||||
this.basePackage = basePackage;
|
||||
}
|
||||
|
||||
public Contact getContact() {
|
||||
return contact;
|
||||
}
|
||||
|
||||
public void setContact(Contact contact) {
|
||||
this.contact = contact;
|
||||
}
|
||||
|
||||
public static class Contact {
|
||||
private String name;
|
||||
private String url;
|
||||
private String email;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package cn.datax.service.data.metadata.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
|
||||
@Configuration
|
||||
@EnableWebSecurity(debug = false)
|
||||
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
|
||||
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
http.csrf().disable().authorizeRequests().anyRequest().permitAll().and().logout().permitAll();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package cn.datax.service.data.metadata.controller;
|
||||
|
||||
import cn.datax.common.base.BaseController;
|
||||
import cn.datax.common.core.DataConstant;
|
||||
import cn.datax.common.security.annotation.DataInner;
|
||||
import cn.datax.service.data.metadata.api.entity.MetadataSourceEntity;
|
||||
import cn.datax.service.data.metadata.service.MetadataSourceService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/inner")
|
||||
public class InnerController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private MetadataSourceService metadataSourceService;
|
||||
|
||||
@DataInner
|
||||
@GetMapping("/sources/{id}")
|
||||
public MetadataSourceEntity getMetadataSourceById(@PathVariable("id") String id) {
|
||||
MetadataSourceEntity metadataSourceEntity = metadataSourceService.getMetadataSourceById(id);
|
||||
return metadataSourceEntity;
|
||||
}
|
||||
|
||||
@DataInner
|
||||
@GetMapping("/sources/list")
|
||||
public List<MetadataSourceEntity> getMetadataSourceList() {
|
||||
QueryWrapper<MetadataSourceEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("status", DataConstant.EnableState.ENABLE.getKey());
|
||||
List<MetadataSourceEntity> list = metadataSourceService.list(queryWrapper);
|
||||
return list;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package cn.datax.service.data.metadata.controller;
|
||||
|
||||
import cn.datax.common.core.R;
|
||||
import cn.datax.service.data.metadata.api.dto.MetadataAuthorizeDto;
|
||||
import cn.datax.service.data.metadata.mapstruct.MetadataAuthorizeMapper;
|
||||
import cn.datax.service.data.metadata.service.MetadataAuthorizeService;
|
||||
import io.swagger.annotations.Api;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import cn.datax.common.base.BaseController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据授权信息表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-23
|
||||
*/
|
||||
@Api(tags = {"元数据授权信息表"})
|
||||
@RestController
|
||||
@RequestMapping("/authorizes")
|
||||
public class MetadataAuthorizeController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private MetadataAuthorizeService metadataAuthorizeService;
|
||||
|
||||
|
||||
@GetMapping("/getAuthorizedMetadata/{id}")
|
||||
public R getAuthorizedMetadata(@PathVariable String id) {
|
||||
List<String> list = metadataAuthorizeService.getAuthorizedMetadata(id);
|
||||
return R.ok().setData(list);
|
||||
}
|
||||
|
||||
@PostMapping("/metadata")
|
||||
public R metadataAuthorize(@RequestBody @Validated MetadataAuthorizeDto metadataAuthorizeDto) {
|
||||
metadataAuthorizeService.metadataAuthorize(metadataAuthorizeDto);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新缓存
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/refresh")
|
||||
public R refreshCache() {
|
||||
metadataAuthorizeService.refreshCache();
|
||||
return R.ok();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
package cn.datax.service.data.metadata.controller;
|
||||
|
||||
import cn.datax.common.core.JsonPage;
|
||||
import cn.datax.common.core.R;
|
||||
import cn.datax.common.validate.ValidationGroups;
|
||||
import cn.datax.service.data.metadata.api.dto.MetadataChangeRecordDto;
|
||||
import cn.datax.service.data.metadata.api.entity.MetadataChangeRecordEntity;
|
||||
import cn.datax.service.data.metadata.api.vo.MetadataChangeRecordVo;
|
||||
import cn.datax.service.data.metadata.api.query.MetadataChangeRecordQuery;
|
||||
import cn.datax.service.data.metadata.mapstruct.MetadataChangeRecordMapper;
|
||||
import cn.datax.service.data.metadata.service.MetadataChangeRecordService;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import cn.datax.common.base.BaseController;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 元数据变更记录表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-30
|
||||
*/
|
||||
@Api(tags = {"元数据变更记录表"})
|
||||
@RestController
|
||||
@RequestMapping("/changeRecords")
|
||||
public class MetadataChangeRecordController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private MetadataChangeRecordService metadataChangeRecordService;
|
||||
|
||||
@Autowired
|
||||
private MetadataChangeRecordMapper metadataChangeRecordMapper;
|
||||
|
||||
/**
|
||||
* 通过ID查询信息
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "获取详细信息", notes = "根据url的id来获取详细信息")
|
||||
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String", paramType = "path")
|
||||
@GetMapping("/{id}")
|
||||
public R getMetadataChangeRecordById(@PathVariable String id) {
|
||||
MetadataChangeRecordEntity metadataChangeRecordEntity = metadataChangeRecordService.getMetadataChangeRecordById(id);
|
||||
return R.ok().setData(metadataChangeRecordMapper.toVO(metadataChangeRecordEntity));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询信息
|
||||
*
|
||||
* @param metadataChangeRecordQuery
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "分页查询", notes = "")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "metadataChangeRecordQuery", value = "查询实体metadataChangeRecordQuery", required = true, dataTypeClass = MetadataChangeRecordQuery.class)
|
||||
})
|
||||
@GetMapping("/page")
|
||||
public R getMetadataChangeRecordPage(MetadataChangeRecordQuery metadataChangeRecordQuery) {
|
||||
QueryWrapper<MetadataChangeRecordEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq(StrUtil.isNotBlank(metadataChangeRecordQuery.getObjectId()), "r.object_id", metadataChangeRecordQuery.getObjectId());
|
||||
queryWrapper.like(StrUtil.isNotBlank(metadataChangeRecordQuery.getFieldName()), "r.field_name", metadataChangeRecordQuery.getFieldName());
|
||||
IPage<MetadataChangeRecordEntity> page = metadataChangeRecordService.page(new Page<>(metadataChangeRecordQuery.getPageNum(), metadataChangeRecordQuery.getPageSize()), queryWrapper);
|
||||
List<MetadataChangeRecordVo> collect = page.getRecords().stream().map(metadataChangeRecordMapper::toVO).collect(Collectors.toList());
|
||||
JsonPage<MetadataChangeRecordVo> jsonPage = new JsonPage<>(page.getCurrent(), page.getSize(), page.getTotal(), collect);
|
||||
return R.ok().setData(jsonPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
* @param metadataChangeRecord
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "添加信息", notes = "根据metadataChangeRecord对象添加信息")
|
||||
@ApiImplicitParam(name = "metadataChangeRecord", value = "详细实体metadataChangeRecord", required = true, dataType = "MetadataChangeRecordDto")
|
||||
@PostMapping()
|
||||
public R saveMetadataChangeRecord(@RequestBody @Validated({ValidationGroups.Insert.class}) MetadataChangeRecordDto metadataChangeRecord) {
|
||||
MetadataChangeRecordEntity metadataChangeRecordEntity = metadataChangeRecordService.saveMetadataChangeRecord(metadataChangeRecord);
|
||||
return R.ok().setData(metadataChangeRecordMapper.toVO(metadataChangeRecordEntity));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
* @param metadataChangeRecord
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "修改信息", notes = "根据url的id来指定修改对象,并根据传过来的信息来修改详细信息")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String", paramType = "path"),
|
||||
@ApiImplicitParam(name = "metadataChangeRecord", value = "详细实体metadataChangeRecord", required = true, dataType = "MetadataChangeRecordDto")
|
||||
})
|
||||
@PutMapping("/{id}")
|
||||
public R updateMetadataChangeRecord(@PathVariable String id, @RequestBody @Validated({ValidationGroups.Update.class}) MetadataChangeRecordDto metadataChangeRecord) {
|
||||
MetadataChangeRecordEntity metadataChangeRecordEntity = metadataChangeRecordService.updateMetadataChangeRecord(metadataChangeRecord);
|
||||
return R.ok().setData(metadataChangeRecordMapper.toVO(metadataChangeRecordEntity));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "删除", notes = "根据url的id来指定删除对象")
|
||||
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String", paramType = "path")
|
||||
@DeleteMapping("/{id}")
|
||||
public R deleteMetadataChangeRecordById(@PathVariable String id) {
|
||||
metadataChangeRecordService.deleteMetadataChangeRecordById(id);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "批量删除角色", notes = "根据url的ids来批量删除对象")
|
||||
@ApiImplicitParam(name = "ids", value = "ID集合", required = true, dataType = "List", paramType = "path")
|
||||
@DeleteMapping("/batch/{ids}")
|
||||
public R deleteMetadataChangeRecordBatch(@PathVariable List<String> ids) {
|
||||
metadataChangeRecordService.deleteMetadataChangeRecordBatch(ids);
|
||||
return R.ok();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
package cn.datax.service.data.metadata.controller;
|
||||
|
||||
import cn.datax.common.core.JsonPage;
|
||||
import cn.datax.common.core.R;
|
||||
import cn.datax.common.validate.ValidationGroups;
|
||||
import cn.datax.service.data.metadata.api.dto.MetadataColumnDto;
|
||||
import cn.datax.service.data.metadata.api.entity.MetadataColumnEntity;
|
||||
import cn.datax.service.data.metadata.api.vo.MetadataColumnVo;
|
||||
import cn.datax.service.data.metadata.api.query.MetadataColumnQuery;
|
||||
import cn.datax.service.data.metadata.api.vo.MetadataTreeVo;
|
||||
import cn.datax.service.data.metadata.mapstruct.MetadataColumnMapper;
|
||||
import cn.datax.service.data.metadata.service.MetadataColumnService;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import cn.datax.common.base.BaseController;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 元数据信息表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-29
|
||||
*/
|
||||
@Api(tags = {"元数据信息表"})
|
||||
@RestController
|
||||
@RequestMapping("/columns")
|
||||
public class MetadataColumnController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private MetadataColumnService metadataColumnService;
|
||||
|
||||
@Autowired
|
||||
private MetadataColumnMapper metadataColumnMapper;
|
||||
|
||||
/**
|
||||
* 通过ID查询信息
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "获取详细信息", notes = "根据url的id来获取详细信息")
|
||||
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String", paramType = "path")
|
||||
@GetMapping("/{id}")
|
||||
public R getDataMetadataColumnById(@PathVariable String id) {
|
||||
MetadataColumnEntity metadataColumnEntity = metadataColumnService.getMetadataColumnById(id);
|
||||
return R.ok().setData(metadataColumnMapper.toVO(metadataColumnEntity));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取列表", notes = "")
|
||||
@GetMapping("/list")
|
||||
public R getDataMetadataColumnList(MetadataColumnQuery metadataColumnQuery) {
|
||||
// QueryWrapper<MetadataColumnEntity> queryWrapper = new QueryWrapper<>();
|
||||
// queryWrapper.like(StrUtil.isNotBlank(metadataColumnQuery.getColumnName()), "column_name", metadataColumnQuery.getColumnName());
|
||||
// queryWrapper.eq(StrUtil.isNotBlank(metadataColumnQuery.getSourceId()), "source_id", metadataColumnQuery.getSourceId());
|
||||
// queryWrapper.eq(StrUtil.isNotBlank(metadataColumnQuery.getTableId()), "table_id", metadataColumnQuery.getTableId());
|
||||
// List<MetadataColumnEntity> list = metadataColumnService.list(queryWrapper);
|
||||
List<MetadataColumnEntity> list = metadataColumnService.getDataMetadataColumnList(metadataColumnQuery);
|
||||
List<MetadataColumnVo> collect = list.stream().map(metadataColumnMapper::toVO).collect(Collectors.toList());
|
||||
return R.ok().setData(collect);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询信息
|
||||
*
|
||||
* @param metadataColumnQuery
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "分页查询", notes = "")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "dataMetadataColumnQuery", value = "查询实体dataMetadataColumnQuery", required = true, dataTypeClass = MetadataColumnQuery.class)
|
||||
})
|
||||
@GetMapping("/page")
|
||||
public R getDataMetadataColumnPage(MetadataColumnQuery metadataColumnQuery) {
|
||||
QueryWrapper<MetadataColumnEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.like(StrUtil.isNotBlank(metadataColumnQuery.getColumnName()), "c.column_name", metadataColumnQuery.getColumnName());
|
||||
queryWrapper.eq(StrUtil.isNotBlank(metadataColumnQuery.getSourceId()), "c.source_id", metadataColumnQuery.getSourceId());
|
||||
queryWrapper.eq(StrUtil.isNotBlank(metadataColumnQuery.getTableId()), "c.table_id", metadataColumnQuery.getTableId());
|
||||
IPage<MetadataColumnEntity> page = metadataColumnService.pageWithAuth(new Page<>(metadataColumnQuery.getPageNum(), metadataColumnQuery.getPageSize()), queryWrapper);
|
||||
List<MetadataColumnVo> collect = page.getRecords().stream().map(metadataColumnMapper::toVO).collect(Collectors.toList());
|
||||
JsonPage<MetadataColumnVo> jsonPage = new JsonPage<>(page.getCurrent(), page.getSize(), page.getTotal(), collect);
|
||||
return R.ok().setData(jsonPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
* @param dataMetadataColumn
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "添加信息", notes = "根据dataMetadataColumn对象添加信息")
|
||||
@ApiImplicitParam(name = "dataMetadataColumn", value = "详细实体dataMetadataColumn", required = true, dataType = "DataMetadataColumnDto")
|
||||
@PostMapping()
|
||||
public R saveDataMetadataColumn(@RequestBody @Validated({ValidationGroups.Insert.class}) MetadataColumnDto dataMetadataColumn) {
|
||||
MetadataColumnEntity metadataColumnEntity = metadataColumnService.saveMetadataColumn(dataMetadataColumn);
|
||||
return R.ok().setData(metadataColumnMapper.toVO(metadataColumnEntity));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
* @param dataMetadataColumn
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "修改信息", notes = "根据url的id来指定修改对象,并根据传过来的信息来修改详细信息")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String", paramType = "path"),
|
||||
@ApiImplicitParam(name = "dataMetadataColumn", value = "详细实体dataMetadataColumn", required = true, dataType = "DataMetadataColumnDto")
|
||||
})
|
||||
@PutMapping("/{id}")
|
||||
public R updateDataMetadataColumn(@PathVariable String id, @RequestBody @Validated({ValidationGroups.Update.class}) MetadataColumnDto dataMetadataColumn) {
|
||||
MetadataColumnEntity metadataColumnEntity = metadataColumnService.updateMetadataColumn(dataMetadataColumn);
|
||||
return R.ok().setData(metadataColumnMapper.toVO(metadataColumnEntity));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "删除", notes = "根据url的id来指定删除对象")
|
||||
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String", paramType = "path")
|
||||
@DeleteMapping("/{id}")
|
||||
public R deleteDataMetadataColumnById(@PathVariable String id) {
|
||||
metadataColumnService.deleteMetadataColumnById(id);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "批量删除角色", notes = "根据url的ids来批量删除对象")
|
||||
@ApiImplicitParam(name = "ids", value = "ID集合", required = true, dataType = "List", paramType = "path")
|
||||
@DeleteMapping("/batch/{ids}")
|
||||
public R deleteDataMetadataColumnBatch(@PathVariable List<String> ids) {
|
||||
metadataColumnService.deleteMetadataColumnBatch(ids);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取层级树
|
||||
* @param level 层级database、table、column
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "获取层级树", notes = "根据url的层级来获取树对象")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "level", value = "层级", required = true, dataType = "String", paramType = "path"),
|
||||
@ApiImplicitParam(name = "metadataColumnQuery", value = "查询实体metadataColumnQuery", required = false, dataType = "MetadataColumnQuery")
|
||||
})
|
||||
@GetMapping("/tree/{level}")
|
||||
public R getDataMetadataTree(@PathVariable String level, MetadataColumnQuery metadataColumnQuery) {
|
||||
List<MetadataTreeVo> list = metadataColumnService.getDataMetadataTree(level, metadataColumnQuery);
|
||||
return R.ok().setData(list);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,258 @@
|
||||
package cn.datax.service.data.metadata.controller;
|
||||
|
||||
import cn.datax.common.base.BaseController;
|
||||
import cn.datax.common.core.JsonPage;
|
||||
import cn.datax.common.core.R;
|
||||
import cn.datax.common.database.DbQuery;
|
||||
import cn.datax.common.database.core.DbColumn;
|
||||
import cn.datax.common.database.core.DbTable;
|
||||
import cn.datax.common.database.core.PageResult;
|
||||
import cn.datax.common.validate.ValidationGroups;
|
||||
import cn.datax.service.data.metadata.api.dto.MetadataSourceDto;
|
||||
import cn.datax.service.data.metadata.api.entity.MetadataSourceEntity;
|
||||
import cn.datax.service.data.metadata.api.query.DbDataQuery;
|
||||
import cn.datax.service.data.metadata.api.query.MetadataSourceQuery;
|
||||
import cn.datax.service.data.metadata.api.vo.MetadataSourceVo;
|
||||
import cn.datax.service.data.metadata.mapstruct.MetadataSourceMapper;
|
||||
import cn.datax.service.data.metadata.service.MetadataSourceService;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.aspose.words.Document;
|
||||
import com.aspose.words.SaveFormat;
|
||||
import com.aspose.words.SaveOptions;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据源信息表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-14
|
||||
*/
|
||||
@Api(tags = {"数据源信息表"})
|
||||
@RestController
|
||||
@RequestMapping("/sources")
|
||||
public class MetadataSourceController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private MetadataSourceService metadataSourceService;
|
||||
|
||||
@Autowired
|
||||
private MetadataSourceMapper metadataSourceMapper;
|
||||
|
||||
/**
|
||||
* 通过ID查询信息
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "获取详细信息", notes = "根据url的id来获取详细信息")
|
||||
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String", paramType = "path")
|
||||
@GetMapping("/{id}")
|
||||
public R getMetadataSourceById(@PathVariable String id) {
|
||||
MetadataSourceEntity metadataSourceEntity = metadataSourceService.getMetadataSourceById(id);
|
||||
return R.ok().setData(metadataSourceMapper.toVO(metadataSourceEntity));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取列表", notes = "")
|
||||
@GetMapping("/list")
|
||||
public R getMetadataSourceList() {
|
||||
// QueryWrapper<MetadataSourceEntity> queryWrapper = new QueryWrapper<>();
|
||||
// queryWrapper.eq("status", DataConstant.EnableState.ENABLE.getKey());
|
||||
// List<MetadataSourceEntity> list = metadataSourceService.list(queryWrapper);
|
||||
List<MetadataSourceEntity> list = metadataSourceService.getMetadataSourceList();
|
||||
List<MetadataSourceVo> collect = list.stream().map(metadataSourceMapper::toVO).collect(Collectors.toList());
|
||||
return R.ok().setData(collect);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询信息
|
||||
*
|
||||
* @param metadataSourceQuery
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "分页查询", notes = "")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "metadataSourceQuery", value = "查询实体metadataSourceQuery", required = true, dataTypeClass = MetadataSourceQuery.class)
|
||||
})
|
||||
@GetMapping("/page")
|
||||
public R getMetadataSourcePage(MetadataSourceQuery metadataSourceQuery) {
|
||||
QueryWrapper<MetadataSourceEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.like(StrUtil.isNotBlank(metadataSourceQuery.getSourceName()), "s.source_name", metadataSourceQuery.getSourceName());
|
||||
IPage<MetadataSourceEntity> page = metadataSourceService.pageWithAuth(new Page<>(metadataSourceQuery.getPageNum(), metadataSourceQuery.getPageSize()), queryWrapper);
|
||||
List<MetadataSourceVo> collect = page.getRecords().stream().map(metadataSourceMapper::toVO).collect(Collectors.toList());
|
||||
JsonPage<MetadataSourceVo> jsonPage = new JsonPage<>(page.getCurrent(), page.getSize(), page.getTotal(), collect);
|
||||
return R.ok().setData(jsonPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
* @param metadataSourceDto
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "添加信息", notes = "根据metadataSourceDto对象添加信息")
|
||||
@ApiImplicitParam(name = "metadataSourceDto", value = "详细实体metadataSourceDto", required = true, dataType = "MetadataSourceDto")
|
||||
@PostMapping()
|
||||
public R saveMetadataSource(@RequestBody @Validated({ValidationGroups.Insert.class}) MetadataSourceDto metadataSourceDto) {
|
||||
metadataSourceService.saveMetadataSource(metadataSourceDto);
|
||||
metadataSourceService.refreshMetadata();
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
* @param metadataSourceDto
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "修改信息", notes = "根据url的id来指定修改对象,并根据传过来的信息来修改详细信息")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String", paramType = "path"),
|
||||
@ApiImplicitParam(name = "metadataSourceDto", value = "详细实体metadataSourceDto", required = true, dataType = "MetadataSourceDto")
|
||||
})
|
||||
@PutMapping("/{id}")
|
||||
public R updateMetadataSource(@PathVariable String id, @RequestBody @Validated({ValidationGroups.Update.class}) MetadataSourceDto metadataSourceDto) {
|
||||
metadataSourceService.updateMetadataSource(metadataSourceDto);
|
||||
metadataSourceService.refreshMetadata();
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "删除", notes = "根据url的id来指定删除对象")
|
||||
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String", paramType = "path")
|
||||
@DeleteMapping("/{id}")
|
||||
public R deleteMetadataSourceById(@PathVariable String id) {
|
||||
metadataSourceService.deleteMetadataSourceById(id);
|
||||
metadataSourceService.refreshMetadata();
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "批量删除", notes = "根据url的ids来批量删除对象")
|
||||
@ApiImplicitParam(name = "ids", value = "ID集合", required = true, dataType = "List", paramType = "path")
|
||||
@DeleteMapping("/batch/{ids}")
|
||||
public R deleteMetadataSourceBatch(@PathVariable List<String> ids) {
|
||||
metadataSourceService.deleteMetadataSourceBatch(ids);
|
||||
metadataSourceService.refreshMetadata();
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测数据库连通性
|
||||
* @param metadataSourceDto
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "数据库连通性", notes = "根据数据库配置信息检测数据库连通性")
|
||||
@ApiImplicitParam(name = "dataSource", value = "详细实体dataSource", required = true, dataType = "DataSourceDto")
|
||||
@PostMapping("/checkConnection")
|
||||
public R checkConnection(@RequestBody @Validated({ValidationGroups.Insert.class}) MetadataSourceDto metadataSourceDto) {
|
||||
DbQuery dbQuery = metadataSourceService.checkConnection(metadataSourceDto);
|
||||
Boolean valid = dbQuery.valid();
|
||||
return valid ? R.ok() : R.error("数据库连接有误,请检查数据库配置是否正确");
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据库表
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "数据库表", notes = "根据数据源的id来获取指定数据库表")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String", paramType = "path")
|
||||
})
|
||||
@GetMapping("/{id}/tables")
|
||||
public R getDbTables(@PathVariable String id) {
|
||||
List<DbTable> tables = metadataSourceService.getDbTables(id);
|
||||
return R.ok().setData(tables);
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据库表结构
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "数据库表结构", notes = "根据数据源的id来获取指定数据库表的表结构")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String", paramType = "path"),
|
||||
@ApiImplicitParam(name = "tableName", value = "数据库表", required = true, dataType = "String", paramType = "path")
|
||||
})
|
||||
@GetMapping("/{id}/{tableName}/columns")
|
||||
public R getDbTableColumns(@PathVariable String id, @PathVariable String tableName) {
|
||||
List<DbColumn> columns = metadataSourceService.getDbTableColumns(id, tableName);
|
||||
return R.ok().setData(columns);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取SQL结果", notes = "根据数据源的id来获取SQL结果")
|
||||
@ApiImplicitParam(name = "dbDataQuery", value = "详细实体dbDataQuery", required = true, dataType = "DbDataQuery")
|
||||
@PostMapping("/queryList")
|
||||
public R queryList(@RequestBody @Validated DbDataQuery dbDataQuery) {
|
||||
DbQuery dbQuery = metadataSourceService.getDbQuery(dbDataQuery.getDataSourceId());
|
||||
List<Map<String, Object>> list = dbQuery.queryList(dbDataQuery.getSql());
|
||||
return R.ok().setData(list);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "分页获取SQL结果", notes = "根据数据源的id来分页获取SQL结果")
|
||||
@ApiImplicitParam(name = "dbDataQuery", value = "详细实体dbDataQuery", required = true, dataType = "DbDataQuery")
|
||||
@PostMapping("/queryByPage")
|
||||
public R queryByPage(@RequestBody @Validated DbDataQuery dbDataQuery) {
|
||||
DbQuery dbQuery = metadataSourceService.getDbQuery(dbDataQuery.getDataSourceId());
|
||||
PageResult<Map<String, Object>> page = dbQuery.queryByPage(dbDataQuery.getSql(), dbDataQuery.getOffset(), dbDataQuery.getPageSize());
|
||||
page.setPageNum(dbDataQuery.getPageNum()).setPageSize(dbDataQuery.getPageSize());
|
||||
return R.ok().setData(page);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "同步", notes = "根据url的id来指定同步对象")
|
||||
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String", paramType = "path")
|
||||
@PostMapping("/sync/{id}")
|
||||
public R syncMetadata(@PathVariable String id) {
|
||||
metadataSourceService.syncMetadata(id);
|
||||
return R.ok();
|
||||
|
||||
}
|
||||
|
||||
@ApiOperation(value = "数据库设计文档", notes = "根据url的id来指定生成数据库设计文档对象")
|
||||
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String", paramType = "path")
|
||||
@PostMapping("/word/{id}")
|
||||
public void wordMetadata(@PathVariable String id, HttpServletResponse response) throws Exception {
|
||||
// 清空response
|
||||
response.reset();
|
||||
// 设置response的Header
|
||||
response.setContentType("application/octet-stream;charset=utf-8");
|
||||
// 设置content-disposition响应头控制浏览器以下载的形式打开文件
|
||||
response.addHeader("Content-Disposition", "attachment;filename=" + new String("数据库设计文档.doc".getBytes()));
|
||||
Document doc = metadataSourceService.wordMetadata(id);
|
||||
OutputStream out = response.getOutputStream();
|
||||
doc.save(out, SaveOptions.createSaveOptions(SaveFormat.DOC));
|
||||
out.flush();
|
||||
out.close();
|
||||
//return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新参数缓存
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/refresh")
|
||||
public R refreshMetadata() {
|
||||
metadataSourceService.refreshMetadata();
|
||||
return R.ok();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
package cn.datax.service.data.metadata.controller;
|
||||
|
||||
import cn.datax.common.core.JsonPage;
|
||||
import cn.datax.common.core.R;
|
||||
import cn.datax.common.validate.ValidationGroups;
|
||||
import cn.datax.service.data.metadata.api.dto.MetadataTableDto;
|
||||
import cn.datax.service.data.metadata.api.entity.MetadataTableEntity;
|
||||
import cn.datax.service.data.metadata.api.vo.MetadataTableVo;
|
||||
import cn.datax.service.data.metadata.api.query.MetadataTableQuery;
|
||||
import cn.datax.service.data.metadata.mapstruct.MetadataTableMapper;
|
||||
import cn.datax.service.data.metadata.service.MetadataTableService;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import cn.datax.common.base.BaseController;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据库表信息表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-29
|
||||
*/
|
||||
@Api(tags = {"数据库表信息表"})
|
||||
@RestController
|
||||
@RequestMapping("/tables")
|
||||
public class MetadataTableController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private MetadataTableService metadataTableService;
|
||||
|
||||
@Autowired
|
||||
private MetadataTableMapper metadataTableMapper;
|
||||
|
||||
/**
|
||||
* 通过ID查询信息
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "获取详细信息", notes = "根据url的id来获取详细信息")
|
||||
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String", paramType = "path")
|
||||
@GetMapping("/{id}")
|
||||
public R getDataMetadataTableById(@PathVariable String id) {
|
||||
MetadataTableEntity metadataTableEntity = metadataTableService.getMetadataTableById(id);
|
||||
return R.ok().setData(metadataTableMapper.toVO(metadataTableEntity));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取列表", notes = "")
|
||||
@GetMapping("/list")
|
||||
public R getDataMetadataTableList(MetadataTableQuery metadataTableQuery) {
|
||||
// QueryWrapper<MetadataTableEntity> queryWrapper = new QueryWrapper<>();
|
||||
// queryWrapper.like(StrUtil.isNotBlank(metadataTableQuery.getTableName()), "table_name", metadataTableQuery.getTableName());
|
||||
// queryWrapper.eq(StrUtil.isNotBlank(metadataTableQuery.getSourceId()), "source_id", metadataTableQuery.getSourceId());
|
||||
// List<MetadataTableEntity> list = metadataTableService.list(queryWrapper);
|
||||
List<MetadataTableEntity> list = metadataTableService.getDataMetadataTableList(metadataTableQuery);
|
||||
List<MetadataTableVo> collect = list.stream().map(metadataTableMapper::toVO).collect(Collectors.toList());
|
||||
return R.ok().setData(collect);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询信息
|
||||
*
|
||||
* @param metadataTableQuery
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "分页查询", notes = "")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "dataMetadataTableQuery", value = "查询实体dataMetadataTableQuery", required = true, dataTypeClass = MetadataTableQuery.class)
|
||||
})
|
||||
@GetMapping("/page")
|
||||
public R getDataMetadataTablePage(MetadataTableQuery metadataTableQuery) {
|
||||
QueryWrapper<MetadataTableEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.like(StrUtil.isNotBlank(metadataTableQuery.getTableName()), "t.table_name", metadataTableQuery.getTableName());
|
||||
queryWrapper.eq(StrUtil.isNotBlank(metadataTableQuery.getSourceId()), "t.source_id", metadataTableQuery.getSourceId());
|
||||
IPage<MetadataTableEntity> page = metadataTableService.pageWithAuth(new Page<>(metadataTableQuery.getPageNum(), metadataTableQuery.getPageSize()), queryWrapper);
|
||||
List<MetadataTableVo> collect = page.getRecords().stream().map(metadataTableMapper::toVO).collect(Collectors.toList());
|
||||
JsonPage<MetadataTableVo> jsonPage = new JsonPage<>(page.getCurrent(), page.getSize(), page.getTotal(), collect);
|
||||
return R.ok().setData(jsonPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
* @param dataMetadataTable
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "添加信息", notes = "根据dataMetadataTable对象添加信息")
|
||||
@ApiImplicitParam(name = "dataMetadataTable", value = "详细实体dataMetadataTable", required = true, dataType = "DataMetadataTableDto")
|
||||
@PostMapping()
|
||||
public R saveDataMetadataTable(@RequestBody @Validated({ValidationGroups.Insert.class}) MetadataTableDto dataMetadataTable) {
|
||||
MetadataTableEntity metadataTableEntity = metadataTableService.saveMetadataTable(dataMetadataTable);
|
||||
return R.ok().setData(metadataTableMapper.toVO(metadataTableEntity));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
* @param dataMetadataTable
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "修改信息", notes = "根据url的id来指定修改对象,并根据传过来的信息来修改详细信息")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String", paramType = "path"),
|
||||
@ApiImplicitParam(name = "dataMetadataTable", value = "详细实体dataMetadataTable", required = true, dataType = "DataMetadataTableDto")
|
||||
})
|
||||
@PutMapping("/{id}")
|
||||
public R updateDataMetadataTable(@PathVariable String id, @RequestBody @Validated({ValidationGroups.Update.class}) MetadataTableDto dataMetadataTable) {
|
||||
MetadataTableEntity metadataTableEntity = metadataTableService.updateMetadataTable(dataMetadataTable);
|
||||
return R.ok().setData(metadataTableMapper.toVO(metadataTableEntity));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "删除", notes = "根据url的id来指定删除对象")
|
||||
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String", paramType = "path")
|
||||
@DeleteMapping("/{id}")
|
||||
public R deleteDataMetadataTableById(@PathVariable String id) {
|
||||
metadataTableService.deleteMetadataTableById(id);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "批量删除角色", notes = "根据url的ids来批量删除对象")
|
||||
@ApiImplicitParam(name = "ids", value = "ID集合", required = true, dataType = "List", paramType = "path")
|
||||
@DeleteMapping("/batch/{ids}")
|
||||
public R deleteDataMetadataTableBatch(@PathVariable List<String> ids) {
|
||||
metadataTableService.deleteMetadataTableBatch(ids);
|
||||
return R.ok();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package cn.datax.service.data.metadata.dao;
|
||||
|
||||
import cn.datax.common.base.BaseDao;
|
||||
import cn.datax.service.data.metadata.api.entity.MetadataAuthorizeEntity;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据授权信息表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-23
|
||||
*/
|
||||
@Mapper
|
||||
public interface MetadataAuthorizeDao extends BaseDao<MetadataAuthorizeEntity> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package cn.datax.service.data.metadata.dao;
|
||||
|
||||
import cn.datax.common.base.BaseDao;
|
||||
import cn.datax.service.data.metadata.api.entity.MetadataChangeRecordEntity;
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 元数据变更记录表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-30
|
||||
*/
|
||||
@Mapper
|
||||
public interface MetadataChangeRecordDao extends BaseDao<MetadataChangeRecordEntity> {
|
||||
|
||||
@Override
|
||||
MetadataChangeRecordEntity selectById(Serializable id);
|
||||
|
||||
@Override
|
||||
<E extends IPage<MetadataChangeRecordEntity>> E selectPage(E page, @Param(Constants.WRAPPER) Wrapper<MetadataChangeRecordEntity> queryWrapper);
|
||||
|
||||
MetadataChangeRecordEntity selectRelColumnBySourceId(@Param("id") String id);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package cn.datax.service.data.metadata.dao;
|
||||
|
||||
import cn.datax.common.base.BaseDao;
|
||||
import cn.datax.service.data.metadata.api.entity.MetadataColumnEntity;
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 元数据信息表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-29
|
||||
*/
|
||||
@Mapper
|
||||
public interface MetadataColumnDao extends BaseDao<MetadataColumnEntity> {
|
||||
|
||||
<E extends IPage<MetadataColumnEntity>> E selectPageWithAuth(E page, @Param(Constants.WRAPPER) Wrapper<MetadataColumnEntity> queryWrapper, @Param("roles") List<String> roles);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package cn.datax.service.data.metadata.dao;
|
||||
|
||||
import cn.datax.common.base.BaseDao;
|
||||
import cn.datax.service.data.metadata.api.entity.MetadataSourceEntity;
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据源信息表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-14
|
||||
*/
|
||||
@Mapper
|
||||
public interface MetadataSourceDao extends BaseDao<MetadataSourceEntity> {
|
||||
|
||||
@Override
|
||||
MetadataSourceEntity selectById(Serializable id);
|
||||
|
||||
@Override
|
||||
List<MetadataSourceEntity> selectList(@Param(Constants.WRAPPER) Wrapper<MetadataSourceEntity> queryWrapper);
|
||||
|
||||
<E extends IPage<MetadataSourceEntity>> E selectPageWithAuth(E page, @Param(Constants.WRAPPER) Wrapper<MetadataSourceEntity> queryWrapper, @Param("roles") List<String> roles);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package cn.datax.service.data.metadata.dao;
|
||||
|
||||
import cn.datax.common.base.BaseDao;
|
||||
import cn.datax.service.data.metadata.api.entity.MetadataTableEntity;
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据库表信息表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-29
|
||||
*/
|
||||
@Mapper
|
||||
public interface MetadataTableDao extends BaseDao<MetadataTableEntity> {
|
||||
|
||||
<E extends IPage<MetadataTableEntity>> E selectPageWithAuth(E page, @Param(Constants.WRAPPER) Wrapper<MetadataTableEntity> queryWrapper, @Param("roles") List<String> roles);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package cn.datax.service.data.metadata.mapstruct;
|
||||
|
||||
import cn.datax.common.mapstruct.EntityMapper;
|
||||
import cn.datax.service.data.metadata.api.dto.MetadataAuthorizeDto;
|
||||
import cn.datax.service.data.metadata.api.entity.MetadataAuthorizeEntity;
|
||||
import cn.datax.service.data.metadata.api.vo.MetadataAuthorizeVo;
|
||||
import org.mapstruct.Mapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据授权信息表 Mapper 实体映射
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-23
|
||||
*/
|
||||
@Mapper(componentModel = "spring")
|
||||
public interface MetadataAuthorizeMapper extends EntityMapper<MetadataAuthorizeDto, MetadataAuthorizeEntity, MetadataAuthorizeVo> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package cn.datax.service.data.metadata.mapstruct;
|
||||
|
||||
import cn.datax.common.mapstruct.EntityMapper;
|
||||
import cn.datax.service.data.metadata.api.dto.MetadataChangeRecordDto;
|
||||
import cn.datax.service.data.metadata.api.entity.MetadataChangeRecordEntity;
|
||||
import cn.datax.service.data.metadata.api.vo.MetadataChangeRecordVo;
|
||||
import org.mapstruct.Mapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 元数据变更记录表 Mapper 实体映射
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-30
|
||||
*/
|
||||
@Mapper(componentModel = "spring")
|
||||
public interface MetadataChangeRecordMapper extends EntityMapper<MetadataChangeRecordDto, MetadataChangeRecordEntity, MetadataChangeRecordVo> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package cn.datax.service.data.metadata.mapstruct;
|
||||
|
||||
import cn.datax.common.mapstruct.EntityMapper;
|
||||
import cn.datax.service.data.metadata.api.dto.MetadataColumnDto;
|
||||
import cn.datax.service.data.metadata.api.entity.MetadataColumnEntity;
|
||||
import cn.datax.service.data.metadata.api.vo.MetadataColumnVo;
|
||||
import org.mapstruct.Mapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 元数据信息表 Mapper 实体映射
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-29
|
||||
*/
|
||||
@Mapper(componentModel = "spring")
|
||||
public interface MetadataColumnMapper extends EntityMapper<MetadataColumnDto, MetadataColumnEntity, MetadataColumnVo> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package cn.datax.service.data.metadata.mapstruct;
|
||||
|
||||
import cn.datax.common.mapstruct.EntityMapper;
|
||||
import cn.datax.service.data.metadata.api.dto.MetadataSourceDto;
|
||||
import cn.datax.service.data.metadata.api.entity.MetadataSourceEntity;
|
||||
import cn.datax.service.data.metadata.api.vo.MetadataSourceVo;
|
||||
import org.mapstruct.Mapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据源信息表 Mapper 实体映射
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-14
|
||||
*/
|
||||
@Mapper(componentModel = "spring")
|
||||
public interface MetadataSourceMapper extends EntityMapper<MetadataSourceDto, MetadataSourceEntity, MetadataSourceVo> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package cn.datax.service.data.metadata.mapstruct;
|
||||
|
||||
import cn.datax.common.mapstruct.EntityMapper;
|
||||
import cn.datax.service.data.metadata.api.dto.MetadataTableDto;
|
||||
import cn.datax.service.data.metadata.api.entity.MetadataTableEntity;
|
||||
import cn.datax.service.data.metadata.api.vo.MetadataTableVo;
|
||||
import org.mapstruct.Mapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据库表信息表 Mapper 实体映射
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-29
|
||||
*/
|
||||
@Mapper(componentModel = "spring")
|
||||
public interface MetadataTableMapper extends EntityMapper<MetadataTableDto, MetadataTableEntity, MetadataTableVo> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
package cn.datax.service.data.metadata.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
|
||||
/**
|
||||
* 避免序列化问题
|
||||
* @author AllDataDC
|
||||
* @date 2023-01-27
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class AuthorityDto implements GrantedAuthority {
|
||||
|
||||
private String authority;
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
|
||||
package cn.datax.service.data.metadata.model;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author AllDataDC
|
||||
* @date 2023-01-27
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class JwtUserDto implements UserDetails {
|
||||
|
||||
public final UserLoginDto user;
|
||||
|
||||
private final List<Long> dataScopes;
|
||||
|
||||
private final List<AuthorityDto> authorities;
|
||||
|
||||
public Set<String> getRoles() {
|
||||
return authorities.stream().map(AuthorityDto::getAuthority).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
@JSONField(serialize = false)
|
||||
public String getPassword() {
|
||||
return user.getPassword();
|
||||
}
|
||||
|
||||
@Override
|
||||
@JSONField(serialize = false)
|
||||
public String getUsername() {
|
||||
return user.getUsername();
|
||||
}
|
||||
|
||||
@JSONField(serialize = false)
|
||||
@Override
|
||||
public boolean isAccountNonExpired() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@JSONField(serialize = false)
|
||||
@Override
|
||||
public boolean isAccountNonLocked() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@JSONField(serialize = false)
|
||||
@Override
|
||||
public boolean isCredentialsNonExpired() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JSONField(serialize = false)
|
||||
public boolean isEnabled() {
|
||||
return user.getEnabled();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
|
||||
package cn.datax.service.data.metadata.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 在线用户
|
||||
* @author AllDataDC
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class OnlineUserDto {
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 昵称
|
||||
*/
|
||||
private String nickName;
|
||||
|
||||
/**
|
||||
* 岗位
|
||||
*/
|
||||
private String dept;
|
||||
|
||||
/**
|
||||
* 浏览器
|
||||
*/
|
||||
private String browser;
|
||||
|
||||
/**
|
||||
* IP
|
||||
*/
|
||||
private String ip;
|
||||
|
||||
/**
|
||||
* 地址
|
||||
*/
|
||||
private String address;
|
||||
|
||||
/**
|
||||
* token
|
||||
*/
|
||||
private String key;
|
||||
|
||||
/**
|
||||
* 登录时间
|
||||
*/
|
||||
private Date loginTime;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
|
||||
package cn.datax.service.data.metadata.model;
|
||||
|
||||
import cn.datax.service.system.api.dto.UserDto;
|
||||
|
||||
/**
|
||||
* @author AllDataDC
|
||||
* @description 用户缓存时使用
|
||||
* @date 2023-01-27
|
||||
**/
|
||||
public class UserLoginDto extends UserDto {
|
||||
|
||||
private String password;
|
||||
|
||||
public Boolean isAdmin;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
|
||||
package cn.datax.service.data.metadata.rest;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* @author AllDataDC
|
||||
* 用于标记匿名访问方法
|
||||
*/
|
||||
@Inherited
|
||||
@Documented
|
||||
@Target({ElementType.METHOD,ElementType.ANNOTATION_TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface AnonymousAccess {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package cn.datax.service.data.metadata.rest;
|
||||
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* Annotation for mapping HTTP {@code DELETE} requests onto specific handler
|
||||
* methods.
|
||||
* 支持匿名访问 DeleteMapping
|
||||
*
|
||||
* @author liaojinlong
|
||||
* @see AnonymousGetMapping
|
||||
* @see AnonymousPostMapping
|
||||
* @see AnonymousPutMapping
|
||||
* @see AnonymousPatchMapping
|
||||
* @see RequestMapping
|
||||
*/
|
||||
@AnonymousAccess
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@RequestMapping(method = RequestMethod.DELETE)
|
||||
public @interface AnonymousDeleteMapping {
|
||||
|
||||
/**
|
||||
* Alias for {@link RequestMapping#name}.
|
||||
*/
|
||||
@AliasFor(annotation = RequestMapping.class)
|
||||
String name() default "";
|
||||
|
||||
/**
|
||||
* Alias for {@link RequestMapping#value}.
|
||||
*/
|
||||
@AliasFor(annotation = RequestMapping.class)
|
||||
String[] value() default {};
|
||||
|
||||
/**
|
||||
* Alias for {@link RequestMapping#path}.
|
||||
*/
|
||||
@AliasFor(annotation = RequestMapping.class)
|
||||
String[] path() default {};
|
||||
|
||||
/**
|
||||
* Alias for {@link RequestMapping#params}.
|
||||
*/
|
||||
@AliasFor(annotation = RequestMapping.class)
|
||||
String[] params() default {};
|
||||
|
||||
/**
|
||||
* Alias for {@link RequestMapping#headers}.
|
||||
*/
|
||||
@AliasFor(annotation = RequestMapping.class)
|
||||
String[] headers() default {};
|
||||
|
||||
/**
|
||||
* Alias for {@link RequestMapping#consumes}.
|
||||
*/
|
||||
@AliasFor(annotation = RequestMapping.class)
|
||||
String[] consumes() default {};
|
||||
|
||||
/**
|
||||
* Alias for {@link RequestMapping#produces}.
|
||||
*/
|
||||
@AliasFor(annotation = RequestMapping.class)
|
||||
String[] produces() default {};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package cn.datax.service.data.metadata.rest;
|
||||
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* Annotation for mapping HTTP {@code GET} requests onto specific handler
|
||||
* methods.
|
||||
* <p>
|
||||
* 支持匿名访问 GetMapping
|
||||
*
|
||||
* @author liaojinlong
|
||||
* @see RequestMapping
|
||||
*/
|
||||
@AnonymousAccess
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
public @interface AnonymousGetMapping {
|
||||
|
||||
/**
|
||||
* Alias for {@link RequestMapping#name}.
|
||||
*/
|
||||
@AliasFor(annotation = RequestMapping.class)
|
||||
String name() default "";
|
||||
|
||||
/**
|
||||
* Alias for {@link RequestMapping#value}.
|
||||
*/
|
||||
@AliasFor(annotation = RequestMapping.class)
|
||||
String[] value() default {};
|
||||
|
||||
/**
|
||||
* Alias for {@link RequestMapping#path}.
|
||||
*/
|
||||
@AliasFor(annotation = RequestMapping.class)
|
||||
String[] path() default {};
|
||||
|
||||
/**
|
||||
* Alias for {@link RequestMapping#params}.
|
||||
*/
|
||||
@AliasFor(annotation = RequestMapping.class)
|
||||
String[] params() default {};
|
||||
|
||||
/**
|
||||
* Alias for {@link RequestMapping#headers}.
|
||||
*/
|
||||
@AliasFor(annotation = RequestMapping.class)
|
||||
String[] headers() default {};
|
||||
|
||||
/**
|
||||
* Alias for {@link RequestMapping#consumes}.
|
||||
*
|
||||
* @since 4.3.5
|
||||
*/
|
||||
@AliasFor(annotation = RequestMapping.class)
|
||||
String[] consumes() default {};
|
||||
|
||||
/**
|
||||
* Alias for {@link RequestMapping#produces}.
|
||||
*/
|
||||
@AliasFor(annotation = RequestMapping.class)
|
||||
String[] produces() default {};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package cn.datax.service.data.metadata.rest;
|
||||
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* Annotation for mapping HTTP {@code PATCH} requests onto specific handler
|
||||
* methods.
|
||||
* * 支持匿名访问 PatchMapping
|
||||
*
|
||||
* @author liaojinlong
|
||||
* @see AnonymousGetMapping
|
||||
* @see AnonymousPostMapping
|
||||
* @see AnonymousPutMapping
|
||||
* @see AnonymousDeleteMapping
|
||||
* @see RequestMapping
|
||||
*/
|
||||
@AnonymousAccess
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@RequestMapping(method = RequestMethod.PATCH)
|
||||
public @interface AnonymousPatchMapping {
|
||||
|
||||
/**
|
||||
* Alias for {@link RequestMapping#name}.
|
||||
*/
|
||||
@AliasFor(annotation = RequestMapping.class)
|
||||
String name() default "";
|
||||
|
||||
/**
|
||||
* Alias for {@link RequestMapping#value}.
|
||||
*/
|
||||
@AliasFor(annotation = RequestMapping.class)
|
||||
String[] value() default {};
|
||||
|
||||
/**
|
||||
* Alias for {@link RequestMapping#path}.
|
||||
*/
|
||||
@AliasFor(annotation = RequestMapping.class)
|
||||
String[] path() default {};
|
||||
|
||||
/**
|
||||
* Alias for {@link RequestMapping#params}.
|
||||
*/
|
||||
@AliasFor(annotation = RequestMapping.class)
|
||||
String[] params() default {};
|
||||
|
||||
/**
|
||||
* Alias for {@link RequestMapping#headers}.
|
||||
*/
|
||||
@AliasFor(annotation = RequestMapping.class)
|
||||
String[] headers() default {};
|
||||
|
||||
/**
|
||||
* Alias for {@link RequestMapping#consumes}.
|
||||
*/
|
||||
@AliasFor(annotation = RequestMapping.class)
|
||||
String[] consumes() default {};
|
||||
|
||||
/**
|
||||
* Alias for {@link RequestMapping#produces}.
|
||||
*/
|
||||
@AliasFor(annotation = RequestMapping.class)
|
||||
String[] produces() default {};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package cn.datax.service.data.metadata.rest;
|
||||
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* Annotation for mapping HTTP {@code POST} requests onto specific handler
|
||||
* methods.
|
||||
* 支持匿名访问 PostMapping
|
||||
*
|
||||
* @author liaojinlong
|
||||
* @see AnonymousGetMapping
|
||||
* @see AnonymousPostMapping
|
||||
* @see AnonymousPutMapping
|
||||
* @see AnonymousDeleteMapping
|
||||
* @see RequestMapping
|
||||
*/
|
||||
@AnonymousAccess
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@RequestMapping(method = RequestMethod.POST)
|
||||
public @interface AnonymousPostMapping {
|
||||
|
||||
/**
|
||||
* Alias for {@link RequestMapping#name}.
|
||||
*/
|
||||
@AliasFor(annotation = RequestMapping.class)
|
||||
String name() default "";
|
||||
|
||||
/**
|
||||
* Alias for {@link RequestMapping#value}.
|
||||
*/
|
||||
@AliasFor(annotation = RequestMapping.class)
|
||||
String[] value() default {};
|
||||
|
||||
/**
|
||||
* Alias for {@link RequestMapping#path}.
|
||||
*/
|
||||
@AliasFor(annotation = RequestMapping.class)
|
||||
String[] path() default {};
|
||||
|
||||
/**
|
||||
* Alias for {@link RequestMapping#params}.
|
||||
*/
|
||||
@AliasFor(annotation = RequestMapping.class)
|
||||
String[] params() default {};
|
||||
|
||||
/**
|
||||
* Alias for {@link RequestMapping#headers}.
|
||||
*/
|
||||
@AliasFor(annotation = RequestMapping.class)
|
||||
String[] headers() default {};
|
||||
|
||||
/**
|
||||
* Alias for {@link RequestMapping#consumes}.
|
||||
*/
|
||||
@AliasFor(annotation = RequestMapping.class)
|
||||
String[] consumes() default {};
|
||||
|
||||
/**
|
||||
* Alias for {@link RequestMapping#produces}.
|
||||
*/
|
||||
@AliasFor(annotation = RequestMapping.class)
|
||||
String[] produces() default {};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package cn.datax.service.data.metadata.rest;
|
||||
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* Annotation for mapping HTTP {@code PUT} requests onto specific handler
|
||||
* methods.
|
||||
* * 支持匿名访问 PutMapping
|
||||
*
|
||||
* @author liaojinlong
|
||||
* @see AnonymousGetMapping
|
||||
* @see AnonymousPostMapping
|
||||
* @see AnonymousPutMapping
|
||||
* @see AnonymousDeleteMapping
|
||||
* @see RequestMapping
|
||||
*/
|
||||
@AnonymousAccess
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@RequestMapping(method = RequestMethod.PUT)
|
||||
public @interface AnonymousPutMapping {
|
||||
|
||||
/**
|
||||
* Alias for {@link RequestMapping#name}.
|
||||
*/
|
||||
@AliasFor(annotation = RequestMapping.class)
|
||||
String name() default "";
|
||||
|
||||
/**
|
||||
* Alias for {@link RequestMapping#value}.
|
||||
*/
|
||||
@AliasFor(annotation = RequestMapping.class)
|
||||
String[] value() default {};
|
||||
|
||||
/**
|
||||
* Alias for {@link RequestMapping#path}.
|
||||
*/
|
||||
@AliasFor(annotation = RequestMapping.class)
|
||||
String[] path() default {};
|
||||
|
||||
/**
|
||||
* Alias for {@link RequestMapping#params}.
|
||||
*/
|
||||
@AliasFor(annotation = RequestMapping.class)
|
||||
String[] params() default {};
|
||||
|
||||
/**
|
||||
* Alias for {@link RequestMapping#headers}.
|
||||
*/
|
||||
@AliasFor(annotation = RequestMapping.class)
|
||||
String[] headers() default {};
|
||||
|
||||
/**
|
||||
* Alias for {@link RequestMapping#consumes}.
|
||||
*/
|
||||
@AliasFor(annotation = RequestMapping.class)
|
||||
String[] consumes() default {};
|
||||
|
||||
/**
|
||||
* Alias for {@link RequestMapping#produces}.
|
||||
*/
|
||||
@AliasFor(annotation = RequestMapping.class)
|
||||
String[] produces() default {};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
|
||||
package cn.datax.service.data.metadata.rest;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author AllDataDC
|
||||
* @description
|
||||
* @date 2023-01-27
|
||||
**/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum RequestMethodEnum {
|
||||
|
||||
/**
|
||||
* 搜寻 @AnonymousGetMapping
|
||||
*/
|
||||
GET("GET"),
|
||||
|
||||
/**
|
||||
* 搜寻 @AnonymousPostMapping
|
||||
*/
|
||||
POST("POST"),
|
||||
|
||||
/**
|
||||
* 搜寻 @AnonymousPutMapping
|
||||
*/
|
||||
PUT("PUT"),
|
||||
|
||||
/**
|
||||
* 搜寻 @AnonymousPatchMapping
|
||||
*/
|
||||
PATCH("PATCH"),
|
||||
|
||||
/**
|
||||
* 搜寻 @AnonymousDeleteMapping
|
||||
*/
|
||||
DELETE("DELETE"),
|
||||
|
||||
/**
|
||||
* 否则就是所有 Request 接口都放行
|
||||
*/
|
||||
ALL("All");
|
||||
|
||||
/**
|
||||
* Request 类型
|
||||
*/
|
||||
private final String type;
|
||||
|
||||
public static RequestMethodEnum find(String type) {
|
||||
for (RequestMethodEnum value : RequestMethodEnum.values()) {
|
||||
if (value.getType().equals(type)) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return ALL;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
|
||||
package cn.datax.service.data.metadata.security;
|
||||
|
||||
import org.springframework.security.access.AccessDeniedException;
|
||||
import org.springframework.security.web.access.AccessDeniedHandler;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author AllDataDC
|
||||
*/
|
||||
@Component
|
||||
public class JwtAccessDeniedHandler implements AccessDeniedHandler {
|
||||
|
||||
@Override
|
||||
public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException {
|
||||
//当用户在没有授权的情况下访问受保护的REST资源时,将调用此方法发送403 Forbidden响应
|
||||
response.sendError(HttpServletResponse.SC_FORBIDDEN, accessDeniedException.getMessage());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
|
||||
package cn.datax.service.data.metadata.security;
|
||||
|
||||
import org.springframework.security.core.AuthenticationException;
|
||||
import org.springframework.security.web.AuthenticationEntryPoint;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author AllDataDC
|
||||
*/
|
||||
@Component
|
||||
public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint {
|
||||
|
||||
@Override
|
||||
public void commence(HttpServletRequest request,
|
||||
HttpServletResponse response,
|
||||
AuthenticationException authException) throws IOException {
|
||||
// 当用户尝试访问安全的REST资源而不提供任何凭据时,将调用此方法发送401 响应
|
||||
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, authException==null?"Unauthorized":authException.getMessage());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
|
||||
package cn.datax.service.data.metadata.security;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Jwt参数配置
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2023-01-27
|
||||
*/
|
||||
@Data
|
||||
public class SecurityProperties {
|
||||
|
||||
/**
|
||||
* Request Headers : Authorization
|
||||
*/
|
||||
private String header = "Authorization";
|
||||
|
||||
/**
|
||||
* 令牌前缀,最后留个空格 Bearer
|
||||
*/
|
||||
private String tokenStartWith = "Bearer ";
|
||||
|
||||
/**
|
||||
* 必须使用最少88位的Base64对该令牌进行编码
|
||||
*/
|
||||
private String base64Secret = "ZmQ0ZGI5NjQ0MDQwY2I4MjMxY2Y3ZmI3MjdhN2ZmMjNhODViOTg1ZGE0NTBjMGM4NDA5NzYxMjdjOWMwYWRmZTBlZjlhNGY3ZTg4Y2U3YTE1ODVkZDU5Y2Y3OGYwZWE1NzUzNWQ2YjFjZDc0NGMxZWU2MmQ3MjY1NzJmNTE0MzI=";
|
||||
|
||||
/**
|
||||
* 令牌过期时间 此处单位/毫秒
|
||||
*/
|
||||
private Long tokenValidityInSeconds = 14400000L;
|
||||
|
||||
/**
|
||||
* 在线用户 key,根据 key 查询 redis 中在线用户的数据
|
||||
*/
|
||||
private String onlineKey = "online-token-";
|
||||
|
||||
/**
|
||||
* 验证码 key
|
||||
*/
|
||||
private String codeKey = "code-key-";
|
||||
|
||||
/**
|
||||
* token 续期检查
|
||||
*/
|
||||
private Long detect = 1800000L;
|
||||
|
||||
/**
|
||||
* 续期时间
|
||||
*/
|
||||
private Long renew = 3600000L;
|
||||
|
||||
public String getTokenStartWith() {
|
||||
return tokenStartWith + " ";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package cn.datax.service.data.metadata.security;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.security.config.annotation.SecurityConfigurerAdapter;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.web.DefaultSecurityFilterChain;
|
||||
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
||||
|
||||
/**
|
||||
* @author AllDataDC
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
public class TokenConfigurer extends SecurityConfigurerAdapter<DefaultSecurityFilterChain, HttpSecurity> {
|
||||
|
||||
private final TokenProvider tokenProvider;
|
||||
private final SecurityProperties properties;
|
||||
|
||||
@Override
|
||||
public void configure(HttpSecurity http) {
|
||||
TokenFilter customFilter = new TokenFilter(tokenProvider, properties);
|
||||
http.addFilterBefore(customFilter, UsernamePasswordAuthenticationFilter.class);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
|
||||
package cn.datax.service.data.metadata.security;
|
||||
|
||||
import cn.datax.common.redis.service.RedisService;
|
||||
import cn.datax.service.data.metadata.model.OnlineUserDto;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
import io.jsonwebtoken.ExpiredJwtException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.filter.GenericFilterBean;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author AllDataDC
|
||||
*/
|
||||
public class TokenFilter extends GenericFilterBean {
|
||||
private static final Logger log = LoggerFactory.getLogger(TokenFilter.class);
|
||||
|
||||
private final TokenProvider tokenProvider;
|
||||
private final SecurityProperties properties;
|
||||
@Resource
|
||||
private RedisService redisUtils;
|
||||
|
||||
/**
|
||||
* @param tokenProvider Token
|
||||
* @param properties JWT
|
||||
*/
|
||||
public TokenFilter(TokenProvider tokenProvider, SecurityProperties properties) {
|
||||
this.properties = properties;
|
||||
this.tokenProvider = tokenProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
|
||||
throws IOException, ServletException {
|
||||
HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
|
||||
String token = resolveToken(httpServletRequest);
|
||||
// 对于 Token 为空的不需要去查 Redis
|
||||
if (StrUtil.isNotBlank(token)) {
|
||||
OnlineUserDto onlineUserDto = null;
|
||||
boolean cleanUserCache = false;
|
||||
try {
|
||||
onlineUserDto = getOne(properties.getOnlineKey() + token);
|
||||
} catch (ExpiredJwtException e) {
|
||||
log.error(e.getMessage());
|
||||
cleanUserCache = true;
|
||||
} finally {
|
||||
if (cleanUserCache || Objects.isNull(onlineUserDto)) {
|
||||
cleanUserCache(String.valueOf(tokenProvider.getClaims(token).get(TokenProvider.AUTHORITIES_KEY)));
|
||||
}
|
||||
}
|
||||
if (onlineUserDto != null && StringUtils.hasText(token)) {
|
||||
Authentication authentication = tokenProvider.getAuthentication(token);
|
||||
SecurityContextHolder.getContext().setAuthentication(authentication);
|
||||
// Token 续期
|
||||
tokenProvider.checkRenewal(token);
|
||||
}
|
||||
}
|
||||
filterChain.doFilter(servletRequest, servletResponse);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初步检测Token
|
||||
*
|
||||
* @param request /
|
||||
* @return /
|
||||
*/
|
||||
private String resolveToken(HttpServletRequest request) {
|
||||
String bearerToken = request.getHeader(properties.getHeader());
|
||||
if (StringUtils.hasText(bearerToken) && bearerToken.startsWith(properties.getTokenStartWith())) {
|
||||
// 去掉令牌前缀
|
||||
return bearerToken.replace(properties.getTokenStartWith(), "");
|
||||
} else {
|
||||
log.debug("非法Token:{}", bearerToken);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询用户
|
||||
* @param key /
|
||||
* @return /
|
||||
*/
|
||||
public OnlineUserDto getOne(String key) {
|
||||
return (OnlineUserDto)redisUtils.get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理用户缓存信息
|
||||
* 用户信息变更时
|
||||
* @param userName 用户名
|
||||
*/
|
||||
@Async
|
||||
public void cleanUserCache(String userName) {
|
||||
if (!StringUtils.isEmpty(userName)) {
|
||||
// 清除数据
|
||||
redisUtils.hdel("USER-LOGIN-DATA", userName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
|
||||
package cn.datax.service.data.metadata.security;
|
||||
|
||||
import cn.datax.common.redis.service.RedisService;
|
||||
import cn.hutool.core.date.DateField;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import io.jsonwebtoken.*;
|
||||
import io.jsonwebtoken.io.Decoders;
|
||||
import io.jsonwebtoken.security.Keys;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
import org.springframework.stereotype.Component;
|
||||
import cn.datax.service.data.metadata.security.SecurityProperties;
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.security.Key;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author AllDataDC
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class TokenProvider implements InitializingBean {
|
||||
|
||||
|
||||
private final SecurityProperties properties = new SecurityProperties();
|
||||
@Autowired
|
||||
private RedisService redisUtils;
|
||||
public static final String AUTHORITIES_KEY = "user";
|
||||
private JwtParser jwtParser;
|
||||
private JwtBuilder jwtBuilder;
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
byte[] keyBytes = Decoders.BASE64.decode(properties.getBase64Secret());
|
||||
Key key = Keys.hmacShaKeyFor(keyBytes);
|
||||
jwtParser = Jwts.parserBuilder()
|
||||
.setSigningKey(properties.getBase64Secret())
|
||||
.build();
|
||||
jwtBuilder = Jwts.builder()
|
||||
.signWith( SignatureAlgorithm.HS512,properties.getBase64Secret());
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建Token 设置永不过期,
|
||||
* Token 的时间有效性转到Redis 维护
|
||||
*
|
||||
* @param authentication /
|
||||
* @return /
|
||||
*/
|
||||
public String createToken(Authentication authentication) {
|
||||
return jwtBuilder
|
||||
// 加入ID确保生成的 Token 都不一致
|
||||
.setId(IdUtil.simpleUUID())
|
||||
.claim(AUTHORITIES_KEY, authentication.getName())
|
||||
.setSubject(authentication.getName())
|
||||
.compact();
|
||||
}
|
||||
|
||||
/**
|
||||
* 依据Token 获取鉴权信息
|
||||
*
|
||||
* @param token /
|
||||
* @return /
|
||||
*/
|
||||
Authentication getAuthentication(String token) {
|
||||
Claims claims = getClaims(token);
|
||||
User principal = new User(claims.getSubject(), "******", new ArrayList<>());
|
||||
return new UsernamePasswordAuthenticationToken(principal, token, new ArrayList<>());
|
||||
}
|
||||
|
||||
public Claims getClaims(String token) {
|
||||
return jwtParser
|
||||
.parseClaimsJws(token)
|
||||
.getBody();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param token 需要检查的token
|
||||
*/
|
||||
public void checkRenewal(String token) {
|
||||
// 判断是否续期token,计算token的过期时间
|
||||
long time = redisUtils.getExpire(properties.getOnlineKey() + token) * 1000;
|
||||
Date expireDate = DateUtil.offset(new Date(), DateField.MILLISECOND, (int) time);
|
||||
// 判断当前时间与过期时间的时间差
|
||||
long differ = expireDate.getTime() - System.currentTimeMillis();
|
||||
// 如果在续期检查的范围内,则续期
|
||||
if (differ <= properties.getDetect()) {
|
||||
long renew = time + properties.getRenew();
|
||||
redisUtils.expire(properties.getOnlineKey() + token, renew);
|
||||
}
|
||||
}
|
||||
|
||||
public String getToken(HttpServletRequest request) {
|
||||
final String requestHeader = request.getHeader(properties.getHeader());
|
||||
if (requestHeader != null && requestHeader.startsWith(properties.getTokenStartWith())) {
|
||||
return requestHeader.substring(7);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package cn.datax.service.data.metadata.service;
|
||||
|
||||
import cn.datax.service.data.metadata.api.dto.MetadataAuthorizeDto;
|
||||
import cn.datax.service.data.metadata.api.entity.MetadataAuthorizeEntity;
|
||||
import cn.datax.common.base.BaseService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据授权信息表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-23
|
||||
*/
|
||||
public interface MetadataAuthorizeService extends BaseService<MetadataAuthorizeEntity> {
|
||||
|
||||
List<String> getAuthorizedMetadata(String id);
|
||||
|
||||
void metadataAuthorize(MetadataAuthorizeDto metadataAuthorizeDto);
|
||||
|
||||
void refreshCache();
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package cn.datax.service.data.metadata.service;
|
||||
|
||||
import cn.datax.service.data.metadata.api.entity.MetadataChangeRecordEntity;
|
||||
import cn.datax.service.data.metadata.api.dto.MetadataChangeRecordDto;
|
||||
import cn.datax.common.base.BaseService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 元数据变更记录表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-30
|
||||
*/
|
||||
public interface MetadataChangeRecordService extends BaseService<MetadataChangeRecordEntity> {
|
||||
|
||||
MetadataChangeRecordEntity saveMetadataChangeRecord(MetadataChangeRecordDto metadataChangeRecord);
|
||||
|
||||
MetadataChangeRecordEntity updateMetadataChangeRecord(MetadataChangeRecordDto metadataChangeRecord);
|
||||
|
||||
MetadataChangeRecordEntity getMetadataChangeRecordById(String id);
|
||||
|
||||
void deleteMetadataChangeRecordById(String id);
|
||||
|
||||
void deleteMetadataChangeRecordBatch(List<String> ids);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package cn.datax.service.data.metadata.service;
|
||||
|
||||
import cn.datax.service.data.metadata.api.dto.MetadataColumnDto;
|
||||
import cn.datax.common.base.BaseService;
|
||||
import cn.datax.service.data.metadata.api.entity.MetadataColumnEntity;
|
||||
import cn.datax.service.data.metadata.api.query.MetadataColumnQuery;
|
||||
import cn.datax.service.data.metadata.api.vo.MetadataTreeVo;
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 元数据信息表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-29
|
||||
*/
|
||||
public interface MetadataColumnService extends BaseService<MetadataColumnEntity> {
|
||||
|
||||
MetadataColumnEntity saveMetadataColumn(MetadataColumnDto metadataColumn);
|
||||
|
||||
MetadataColumnEntity updateMetadataColumn(MetadataColumnDto metadataColumn);
|
||||
|
||||
MetadataColumnEntity getMetadataColumnById(String id);
|
||||
|
||||
void deleteMetadataColumnById(String id);
|
||||
|
||||
void deleteMetadataColumnBatch(List<String> ids);
|
||||
|
||||
List<MetadataTreeVo> getDataMetadataTree(String level, MetadataColumnQuery metadataColumnQuery);
|
||||
|
||||
List<MetadataColumnEntity> getDataMetadataColumnList(MetadataColumnQuery metadataColumnQuery);
|
||||
|
||||
<E extends IPage<MetadataColumnEntity>> E pageWithAuth(E page, Wrapper<MetadataColumnEntity> queryWrapper);
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package cn.datax.service.data.metadata.service;
|
||||
|
||||
import cn.datax.common.base.BaseService;
|
||||
import cn.datax.common.database.DbQuery;
|
||||
import cn.datax.common.database.core.DbColumn;
|
||||
import cn.datax.common.database.core.DbTable;
|
||||
import cn.datax.service.data.metadata.api.dto.MetadataSourceDto;
|
||||
import cn.datax.service.data.metadata.api.entity.MetadataSourceEntity;
|
||||
import com.aspose.words.Document;
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据源信息表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-14
|
||||
*/
|
||||
public interface MetadataSourceService extends BaseService<MetadataSourceEntity> {
|
||||
|
||||
void saveMetadataSource(MetadataSourceDto metadataSourceDto);
|
||||
|
||||
void updateMetadataSource(MetadataSourceDto metadataSourceDto);
|
||||
|
||||
MetadataSourceEntity getMetadataSourceById(String id);
|
||||
|
||||
void deleteMetadataSourceById(String id);
|
||||
|
||||
void deleteTableAndCol(String id);
|
||||
|
||||
void deleteMetadataSourceBatch(List<String> ids);
|
||||
|
||||
DbQuery checkConnection(MetadataSourceDto metadataSourceDto);
|
||||
|
||||
DbQuery getDbQuery(String id);
|
||||
|
||||
List<DbTable> getDbTables(String id);
|
||||
|
||||
List<DbColumn> getDbTableColumns(String id, String tableName);
|
||||
|
||||
void syncMetadata(String id);
|
||||
|
||||
Document wordMetadata(String id) throws Exception;
|
||||
|
||||
void refreshMetadata();
|
||||
|
||||
List<MetadataSourceEntity> getMetadataSourceList();
|
||||
|
||||
<E extends IPage<MetadataSourceEntity>> E pageWithAuth(E page, Wrapper<MetadataSourceEntity> queryWrapper);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package cn.datax.service.data.metadata.service;
|
||||
|
||||
import cn.datax.service.data.metadata.api.entity.MetadataTableEntity;
|
||||
import cn.datax.service.data.metadata.api.dto.MetadataTableDto;
|
||||
import cn.datax.common.base.BaseService;
|
||||
import cn.datax.service.data.metadata.api.query.MetadataTableQuery;
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据库表信息表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-29
|
||||
*/
|
||||
public interface MetadataTableService extends BaseService<MetadataTableEntity> {
|
||||
|
||||
MetadataTableEntity saveMetadataTable(MetadataTableDto metadataTable);
|
||||
|
||||
MetadataTableEntity updateMetadataTable(MetadataTableDto metadataTable);
|
||||
|
||||
MetadataTableEntity getMetadataTableById(String id);
|
||||
|
||||
void deleteMetadataTableById(String id);
|
||||
|
||||
void deleteMetadataTableBatch(List<String> ids);
|
||||
|
||||
List<MetadataTableEntity> getDataMetadataTableList(MetadataTableQuery metadataTableQuery);
|
||||
|
||||
<E extends IPage<MetadataTableEntity>> E pageWithAuth(E page, Wrapper<MetadataTableEntity> queryWrapper);
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package cn.datax.service.data.metadata.service.impl;
|
||||
|
||||
import cn.datax.common.core.RedisConstant;
|
||||
import cn.datax.common.redis.service.RedisService;
|
||||
import cn.datax.service.data.metadata.api.dto.MetadataAuthorizeDto;
|
||||
import cn.datax.service.data.metadata.api.entity.MetadataAuthorizeEntity;
|
||||
import cn.datax.service.data.metadata.service.MetadataAuthorizeService;
|
||||
import cn.datax.service.data.metadata.mapstruct.MetadataAuthorizeMapper;
|
||||
import cn.datax.service.data.metadata.dao.MetadataAuthorizeDao;
|
||||
import cn.datax.common.base.BaseServiceImpl;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据授权信息表 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-23
|
||||
*/
|
||||
@Service
|
||||
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
|
||||
public class MetadataAuthorizeServiceImpl extends BaseServiceImpl<MetadataAuthorizeDao, MetadataAuthorizeEntity> implements MetadataAuthorizeService {
|
||||
|
||||
@Autowired
|
||||
private MetadataAuthorizeDao metadataAuthorizeDao;
|
||||
|
||||
@Autowired
|
||||
private MetadataAuthorizeMapper metadataAuthorizeMapper;
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
|
||||
@Override
|
||||
public List<String> getAuthorizedMetadata(String id) {
|
||||
List<MetadataAuthorizeEntity> metadataAuthorizeList = metadataAuthorizeDao.selectList(Wrappers.<MetadataAuthorizeEntity>lambdaQuery().eq(MetadataAuthorizeEntity::getRoleId, id));
|
||||
return metadataAuthorizeList.stream().map(MetadataAuthorizeEntity::getObjectId).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void metadataAuthorize(MetadataAuthorizeDto metadataAuthorizeDto) {
|
||||
// 先删除
|
||||
metadataAuthorizeDao.delete(Wrappers.<MetadataAuthorizeEntity>lambdaQuery().eq(MetadataAuthorizeEntity::getRoleId, metadataAuthorizeDto.getRoleId()));
|
||||
metadataAuthorizeDto.getAuthorizeDataList().forEach(s -> {
|
||||
MetadataAuthorizeEntity metadataAuthorizeEntity = new MetadataAuthorizeEntity();
|
||||
metadataAuthorizeEntity.setRoleId(s.getRoleId());
|
||||
metadataAuthorizeEntity.setObjectId(s.getObjectId());
|
||||
metadataAuthorizeEntity.setObjectType(s.getObjectType());
|
||||
metadataAuthorizeDao.insert(metadataAuthorizeEntity);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshCache() {
|
||||
String authorizeKey = RedisConstant.METADATA_AUTHORIZE_KEY;
|
||||
Boolean hasAuthorizeKey = redisService.hasKey(authorizeKey);
|
||||
if (hasAuthorizeKey) {
|
||||
redisService.del(authorizeKey);
|
||||
}
|
||||
List<MetadataAuthorizeEntity> metadataAuthorizeList = metadataAuthorizeDao.selectList(Wrappers.emptyWrapper());
|
||||
Map<String, List<MetadataAuthorizeEntity>> authorizeListMap = metadataAuthorizeList.stream().collect(Collectors.groupingBy(MetadataAuthorizeEntity::getRoleId));
|
||||
redisTemplate.opsForHash().putAll(authorizeKey, authorizeListMap);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package cn.datax.service.data.metadata.service.impl;
|
||||
|
||||
import cn.datax.service.data.metadata.api.entity.MetadataChangeRecordEntity;
|
||||
import cn.datax.service.data.metadata.api.dto.MetadataChangeRecordDto;
|
||||
import cn.datax.service.data.metadata.service.MetadataChangeRecordService;
|
||||
import cn.datax.service.data.metadata.mapstruct.MetadataChangeRecordMapper;
|
||||
import cn.datax.service.data.metadata.dao.MetadataChangeRecordDao;
|
||||
import cn.datax.common.base.BaseServiceImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 元数据变更记录表 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-30
|
||||
*/
|
||||
@Service
|
||||
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
|
||||
public class MetadataChangeRecordServiceImpl extends BaseServiceImpl<MetadataChangeRecordDao, MetadataChangeRecordEntity> implements MetadataChangeRecordService {
|
||||
|
||||
@Autowired
|
||||
private MetadataChangeRecordDao metadataChangeRecordDao;
|
||||
|
||||
@Autowired
|
||||
private MetadataChangeRecordMapper metadataChangeRecordMapper;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public MetadataChangeRecordEntity saveMetadataChangeRecord(MetadataChangeRecordDto metadataChangeRecordDto) {
|
||||
MetadataChangeRecordEntity metadataChangeRecord = metadataChangeRecordMapper.toEntity(metadataChangeRecordDto);
|
||||
metadataChangeRecordDao.insert(metadataChangeRecord);
|
||||
return metadataChangeRecord;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public MetadataChangeRecordEntity updateMetadataChangeRecord(MetadataChangeRecordDto metadataChangeRecordDto) {
|
||||
MetadataChangeRecordEntity metadataChangeRecord = metadataChangeRecordMapper.toEntity(metadataChangeRecordDto);
|
||||
metadataChangeRecordDao.updateById(metadataChangeRecord);
|
||||
return metadataChangeRecord;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetadataChangeRecordEntity getMetadataChangeRecordById(String id) {
|
||||
MetadataChangeRecordEntity metadataChangeRecordEntity = super.getById(id);
|
||||
return metadataChangeRecordEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteMetadataChangeRecordById(String id) {
|
||||
metadataChangeRecordDao.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteMetadataChangeRecordBatch(List<String> ids) {
|
||||
metadataChangeRecordDao.deleteBatchIds(ids);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,211 @@
|
||||
package cn.datax.service.data.metadata.service.impl;
|
||||
|
||||
import cn.datax.common.core.DataConstant;
|
||||
import cn.datax.common.core.RedisConstant;
|
||||
import cn.datax.common.exception.DataException;
|
||||
import cn.datax.common.redis.service.RedisService;
|
||||
import cn.datax.common.utils.SecurityUtil;
|
||||
import cn.datax.service.data.metadata.api.dto.MetadataColumnDto;
|
||||
import cn.datax.service.data.metadata.api.entity.MetadataAuthorizeEntity;
|
||||
import cn.datax.service.data.metadata.api.entity.MetadataColumnEntity;
|
||||
import cn.datax.service.data.metadata.api.entity.MetadataSourceEntity;
|
||||
import cn.datax.service.data.metadata.api.entity.MetadataTableEntity;
|
||||
import cn.datax.service.data.metadata.api.enums.DataLevel;
|
||||
import cn.datax.service.data.metadata.api.query.MetadataColumnQuery;
|
||||
import cn.datax.service.data.metadata.api.vo.MetadataTreeVo;
|
||||
import cn.datax.service.data.metadata.service.MetadataColumnService;
|
||||
import cn.datax.service.data.metadata.mapstruct.MetadataColumnMapper;
|
||||
import cn.datax.service.data.metadata.dao.MetadataColumnDao;
|
||||
import cn.datax.common.base.BaseServiceImpl;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 元数据信息表 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-29
|
||||
*/
|
||||
@Service
|
||||
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
|
||||
public class MetadataColumnServiceImpl extends BaseServiceImpl<MetadataColumnDao, MetadataColumnEntity> implements MetadataColumnService {
|
||||
|
||||
@Autowired
|
||||
private MetadataColumnDao metadataColumnDao;
|
||||
|
||||
@Autowired
|
||||
private MetadataColumnMapper metadataColumnMapper;
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public MetadataColumnEntity saveMetadataColumn(MetadataColumnDto metadataColumnDto) {
|
||||
MetadataColumnEntity metadataColumn = metadataColumnMapper.toEntity(metadataColumnDto);
|
||||
metadataColumnDao.insert(metadataColumn);
|
||||
return metadataColumn;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public MetadataColumnEntity updateMetadataColumn(MetadataColumnDto metadataColumnDto) {
|
||||
MetadataColumnEntity metadataColumn = metadataColumnMapper.toEntity(metadataColumnDto);
|
||||
metadataColumnDao.updateById(metadataColumn);
|
||||
return metadataColumn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetadataColumnEntity getMetadataColumnById(String id) {
|
||||
MetadataColumnEntity metadataColumnEntity = super.getById(id);
|
||||
return metadataColumnEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteMetadataColumnById(String id) {
|
||||
metadataColumnDao.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteMetadataColumnBatch(List<String> ids) {
|
||||
metadataColumnDao.deleteBatchIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MetadataTreeVo> getDataMetadataTree(String level, MetadataColumnQuery metadataColumnQuery) {
|
||||
boolean admin = SecurityUtil.isAdmin();
|
||||
List<MetadataSourceEntity> sourceList = (List<MetadataSourceEntity>) redisService.get(RedisConstant.METADATA_SOURCE_KEY);
|
||||
Stream<MetadataSourceEntity> stream = Optional.ofNullable(sourceList).orElseGet(ArrayList::new).stream().filter(s -> DataConstant.EnableState.ENABLE.getKey().equals(s.getStatus()));
|
||||
if (StrUtil.isNotBlank(metadataColumnQuery.getSourceId())) {
|
||||
stream = stream.filter(s -> metadataColumnQuery.getSourceId().equals(s.getId()));
|
||||
}
|
||||
if (!admin) {
|
||||
Set<String> set = new HashSet<>();
|
||||
List<String> roleIds = SecurityUtil.getUserRoleIds();
|
||||
roleIds.stream().forEach(role -> {
|
||||
List<MetadataAuthorizeEntity> list = (List<MetadataAuthorizeEntity>) redisService.hget(RedisConstant.METADATA_AUTHORIZE_KEY, role);
|
||||
set.addAll(Optional.ofNullable(list).orElseGet(ArrayList::new).stream()
|
||||
.filter(s -> Objects.equals(DataLevel.DATABASE.getKey(), s.getObjectType()))
|
||||
.map(s -> s.getObjectId()).collect(Collectors.toSet()));
|
||||
});
|
||||
stream = stream.filter(s -> set.contains(s.getId()));
|
||||
}
|
||||
List<MetadataTreeVo> list = stream.map(m -> {
|
||||
MetadataTreeVo tree = new MetadataTreeVo();
|
||||
tree.setId(m.getId());
|
||||
tree.setType(DataLevel.DATABASE.getKey());
|
||||
tree.setLabel(m.getSourceName());
|
||||
tree.setName(m.getSourceName());
|
||||
if (DataLevel.getLevel(level).getLevel() >= DataLevel.TABLE.getLevel()) {
|
||||
tree.setChildren(getTableChildrens(m.getId(), level, metadataColumnQuery.getTableId()));
|
||||
}
|
||||
return tree;
|
||||
}).collect(Collectors.toList());
|
||||
return list;
|
||||
}
|
||||
|
||||
private List<MetadataTreeVo> getTableChildrens(String id, String level, String tableId) {
|
||||
boolean admin = SecurityUtil.isAdmin();
|
||||
List<MetadataTableEntity> tableList = (List<MetadataTableEntity>) redisService.hget(RedisConstant.METADATA_TABLE_KEY, id);
|
||||
Stream<MetadataTableEntity> stream = Optional.ofNullable(tableList).orElseGet(ArrayList::new).stream();
|
||||
if (StrUtil.isNotBlank(tableId)) {
|
||||
stream = stream.filter(s -> tableId.equals(s.getId()));
|
||||
}
|
||||
if (!admin) {
|
||||
Set<String> set = new HashSet<>();
|
||||
List<String> roleIds = SecurityUtil.getUserRoleIds();
|
||||
roleIds.stream().forEach(role -> {
|
||||
List<MetadataAuthorizeEntity> list = (List<MetadataAuthorizeEntity>) redisService.hget(RedisConstant.METADATA_AUTHORIZE_KEY, role);
|
||||
set.addAll(Optional.ofNullable(list).orElseGet(ArrayList::new).stream()
|
||||
.filter(s -> Objects.equals(DataLevel.TABLE.getKey(), s.getObjectType()))
|
||||
.map(s -> s.getObjectId()).collect(Collectors.toSet()));
|
||||
});
|
||||
stream = stream.filter(s -> set.contains(s.getId()));
|
||||
}
|
||||
List<MetadataTreeVo> children = stream.map(m -> {
|
||||
MetadataTreeVo tree = new MetadataTreeVo();
|
||||
tree.setId(m.getId());
|
||||
tree.setType(DataLevel.TABLE.getKey());
|
||||
tree.setName(m.getTableComment());
|
||||
tree.setCode(m.getTableName());
|
||||
tree.setLabel(StrUtil.isBlank(m.getTableComment()) ? m.getTableName() : m.getTableComment());
|
||||
if (DataLevel.getLevel(level).getLevel() >= DataLevel.COLUMN.getLevel()) {
|
||||
tree.setChildren(getColumnChildrens(m.getId()));
|
||||
}
|
||||
return tree;
|
||||
}).collect(Collectors.toList());
|
||||
return children;
|
||||
}
|
||||
|
||||
private List<MetadataTreeVo> getColumnChildrens(String id) {
|
||||
boolean admin = SecurityUtil.isAdmin();
|
||||
List<MetadataColumnEntity> columnList = (List<MetadataColumnEntity>) redisService.hget(RedisConstant.METADATA_COLUMN_KEY, id);
|
||||
Stream<MetadataColumnEntity> stream = Optional.ofNullable(columnList).orElseGet(ArrayList::new).stream();
|
||||
if (!admin) {
|
||||
Set<String> set = new HashSet<>();
|
||||
List<String> roleIds = SecurityUtil.getUserRoleIds();
|
||||
roleIds.stream().forEach(role -> {
|
||||
List<MetadataAuthorizeEntity> list = (List<MetadataAuthorizeEntity>) redisService.hget(RedisConstant.METADATA_AUTHORIZE_KEY, role);
|
||||
set.addAll(Optional.ofNullable(list).orElseGet(ArrayList::new).stream()
|
||||
.filter(s -> Objects.equals(DataLevel.COLUMN.getKey(), s.getObjectType()))
|
||||
.map(s -> s.getObjectId()).collect(Collectors.toSet()));
|
||||
});
|
||||
stream = stream.filter(s -> set.contains(s.getId()));
|
||||
}
|
||||
List<MetadataTreeVo> children = stream.map(m -> {
|
||||
MetadataTreeVo tree = new MetadataTreeVo();
|
||||
tree.setId(m.getId());
|
||||
tree.setType(DataLevel.COLUMN.getKey());
|
||||
tree.setName(m.getColumnComment());
|
||||
tree.setCode(m.getColumnName());
|
||||
tree.setLabel(StrUtil.isBlank(m.getColumnComment()) ? m.getColumnName() : m.getColumnComment());
|
||||
return tree;
|
||||
}).collect(Collectors.toList());
|
||||
return children;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MetadataColumnEntity> getDataMetadataColumnList(MetadataColumnQuery metadataColumnQuery) {
|
||||
boolean admin = SecurityUtil.isAdmin();
|
||||
if (StrUtil.isBlank(metadataColumnQuery.getTableId())) {
|
||||
throw new DataException("数据表不能为空");
|
||||
}
|
||||
List<MetadataColumnEntity> columnList = (List<MetadataColumnEntity>) redisService.hget(RedisConstant.METADATA_COLUMN_KEY, metadataColumnQuery.getTableId());
|
||||
Stream<MetadataColumnEntity> stream = Optional.ofNullable(columnList).orElseGet(ArrayList::new).stream();
|
||||
if (!admin) {
|
||||
Set<String> set = new HashSet<>();
|
||||
List<String> roleIds = SecurityUtil.getUserRoleIds();
|
||||
roleIds.stream().forEach(role -> {
|
||||
List<MetadataAuthorizeEntity> list = (List<MetadataAuthorizeEntity>) redisService.hget(RedisConstant.METADATA_AUTHORIZE_KEY, role);
|
||||
set.addAll(Optional.ofNullable(list).orElseGet(ArrayList::new).stream()
|
||||
.filter(s -> Objects.equals(DataLevel.COLUMN.getKey(), s.getObjectType()))
|
||||
.map(s -> s.getObjectId()).collect(Collectors.toSet()));
|
||||
});
|
||||
stream = stream.filter(s -> set.contains(s.getId()));
|
||||
}
|
||||
return stream.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E extends IPage<MetadataColumnEntity>> E pageWithAuth(E page, Wrapper<MetadataColumnEntity> queryWrapper) {
|
||||
boolean admin = SecurityUtil.isAdmin();
|
||||
List<String> roles = new ArrayList<>();
|
||||
if (!admin) {
|
||||
roles = SecurityUtil.getUserRoleIds();
|
||||
}
|
||||
return metadataColumnDao.selectPageWithAuth(page, queryWrapper, roles);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,398 @@
|
||||
package cn.datax.service.data.metadata.service.impl;
|
||||
|
||||
import cn.datax.commo.office.word.WordUtil;
|
||||
import cn.datax.common.base.BaseServiceImpl;
|
||||
import cn.datax.common.core.DataConstant;
|
||||
import cn.datax.common.core.RedisConstant;
|
||||
import cn.datax.common.database.DataSourceFactory;
|
||||
import cn.datax.common.database.DbQuery;
|
||||
import cn.datax.common.database.constants.DbQueryProperty;
|
||||
import cn.datax.common.database.core.DbColumn;
|
||||
import cn.datax.common.database.core.DbTable;
|
||||
import cn.datax.common.exception.DataException;
|
||||
import cn.datax.common.redis.service.RedisService;
|
||||
import cn.datax.common.utils.SecurityUtil;
|
||||
import cn.datax.service.data.market.api.entity.DataApiEntity;
|
||||
import cn.datax.service.data.market.api.feign.DataApiServiceFeign;
|
||||
import cn.datax.service.data.metadata.api.dto.DbSchema;
|
||||
import cn.datax.service.data.metadata.api.dto.MetadataSourceDto;
|
||||
import cn.datax.service.data.metadata.api.entity.MetadataAuthorizeEntity;
|
||||
import cn.datax.service.data.metadata.api.entity.MetadataChangeRecordEntity;
|
||||
import cn.datax.service.data.metadata.api.entity.MetadataColumnEntity;
|
||||
import cn.datax.service.data.metadata.api.entity.MetadataSourceEntity;
|
||||
import cn.datax.service.data.metadata.api.entity.MetadataTableEntity;
|
||||
import cn.datax.service.data.metadata.api.enums.DataLevel;
|
||||
import cn.datax.service.data.metadata.api.enums.SyncStatus;
|
||||
import cn.datax.service.data.metadata.async.AsyncTask;
|
||||
import cn.datax.service.data.metadata.dao.MetadataAuthorizeDao;
|
||||
import cn.datax.service.data.metadata.dao.MetadataChangeRecordDao;
|
||||
import cn.datax.service.data.metadata.dao.MetadataColumnDao;
|
||||
import cn.datax.service.data.metadata.dao.MetadataSourceDao;
|
||||
import cn.datax.service.data.metadata.dao.MetadataTableDao;
|
||||
import cn.datax.service.data.metadata.mapstruct.MetadataSourceMapper;
|
||||
import cn.datax.service.data.metadata.service.MetadataSourceService;
|
||||
import cn.datax.service.data.quality.api.entity.CheckRuleEntity;
|
||||
import cn.datax.service.data.quality.api.feign.QualityServiceFeign;
|
||||
import cn.datax.service.data.standard.api.entity.ContrastEntity;
|
||||
import cn.datax.service.data.standard.api.feign.StandardServiceFeign;
|
||||
import cn.datax.service.data.visual.api.entity.DataSetEntity;
|
||||
import cn.datax.service.data.visual.api.feign.VisualServiceFeign;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.aspose.words.Document;
|
||||
import com.aspose.words.MailMerge;
|
||||
import com.aspose.words.net.System.Data.DataRelation;
|
||||
import com.aspose.words.net.System.Data.DataRow;
|
||||
import com.aspose.words.net.System.Data.DataSet;
|
||||
import com.aspose.words.net.System.Data.DataTable;
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据源信息表 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-14
|
||||
*/
|
||||
@Service
|
||||
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
|
||||
public class MetadataSourceServiceImpl extends BaseServiceImpl<MetadataSourceDao, MetadataSourceEntity> implements MetadataSourceService {
|
||||
|
||||
@Autowired
|
||||
private MetadataSourceDao metadataSourceDao;
|
||||
|
||||
@Autowired
|
||||
private MetadataSourceMapper metadataSourceMapper;
|
||||
|
||||
@Autowired
|
||||
private DataSourceFactory dataSourceFactory;
|
||||
|
||||
@Autowired
|
||||
private AsyncTask asyncTask;
|
||||
|
||||
@Autowired
|
||||
private MetadataTableDao metadataTableDao;
|
||||
|
||||
@Autowired
|
||||
private MetadataColumnDao metadataColumnDao;
|
||||
|
||||
@Autowired
|
||||
private MetadataAuthorizeDao metadataAuthorizeDao;
|
||||
|
||||
@Autowired
|
||||
private MetadataChangeRecordDao metadataChangeRecordDao;
|
||||
|
||||
@Autowired
|
||||
private StandardServiceFeign standardServiceFeign;
|
||||
|
||||
@Autowired
|
||||
private QualityServiceFeign qualityServiceFeign;
|
||||
|
||||
@Autowired
|
||||
private DataApiServiceFeign dataApiServiceFeign;
|
||||
|
||||
@Autowired
|
||||
private VisualServiceFeign visualServiceFeign;
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void saveMetadataSource(MetadataSourceDto metadataSourceDto) {
|
||||
MetadataSourceEntity dataSource = metadataSourceMapper.toEntity(metadataSourceDto);
|
||||
dataSource.setIsSync(SyncStatus.NotSync.getKey());
|
||||
metadataSourceDao.insert(dataSource);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateMetadataSource(MetadataSourceDto metadataSourceDto) {
|
||||
MetadataSourceEntity dataSource = metadataSourceMapper.toEntity(metadataSourceDto);
|
||||
metadataSourceDao.updateById(dataSource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetadataSourceEntity getMetadataSourceById(String id) {
|
||||
MetadataSourceEntity metadataSourceEntity = super.getById(id);
|
||||
return metadataSourceEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MetadataSourceEntity> getMetadataSourceList() {
|
||||
boolean admin = SecurityUtil.isAdmin();
|
||||
List<MetadataSourceEntity> sourceList = (List<MetadataSourceEntity>) redisService.get(RedisConstant.METADATA_SOURCE_KEY);
|
||||
Stream<MetadataSourceEntity> stream = Optional.ofNullable(sourceList).orElseGet(ArrayList::new).stream()
|
||||
.filter(s -> DataConstant.EnableState.ENABLE.getKey().equals(s.getStatus()));
|
||||
if (!admin) {
|
||||
Set<String> set = new HashSet<>();
|
||||
List<String> roleIds = SecurityUtil.getUserRoleIds();
|
||||
roleIds.stream().forEach(role -> {
|
||||
List<MetadataAuthorizeEntity> list = (List<MetadataAuthorizeEntity>) redisService.hget(RedisConstant.METADATA_AUTHORIZE_KEY, role);
|
||||
set.addAll(Optional.ofNullable(list).orElseGet(ArrayList::new).stream()
|
||||
.filter(s -> Objects.equals(DataLevel.DATABASE.getKey(), s.getObjectType()))
|
||||
.map(s -> s.getObjectId()).collect(Collectors.toSet()));
|
||||
});
|
||||
stream = stream.filter(s -> set.contains(s.getId()));
|
||||
}
|
||||
return stream.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E extends IPage<MetadataSourceEntity>> E pageWithAuth(E page, Wrapper<MetadataSourceEntity> queryWrapper) {
|
||||
boolean admin = SecurityUtil.isAdmin();
|
||||
List<String> roles = new ArrayList<>();
|
||||
if (!admin) {
|
||||
roles = SecurityUtil.getUserRoleIds();
|
||||
}
|
||||
return metadataSourceDao.selectPageWithAuth(page, queryWrapper, roles);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteMetadataSourceById(String id) {
|
||||
checkSourceRel(id);
|
||||
deleteTableAndCol(id);
|
||||
metadataSourceDao.deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查与数据源的依赖
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
private void checkSourceRel(String id) {
|
||||
//查询授权关联
|
||||
MetadataAuthorizeEntity metadataAuthorizeEntity = metadataAuthorizeDao.selectOne(new QueryWrapper<MetadataAuthorizeEntity>().eq("object_id", id).eq("object_type", "database").last("limit 1"));
|
||||
if (metadataAuthorizeEntity != null) {
|
||||
throw new RuntimeException("元数据管理-数据授权有与之关联的数据,不允许删除!");
|
||||
}
|
||||
//查询变更记录关联
|
||||
MetadataChangeRecordEntity recordEntity = metadataChangeRecordDao.selectRelColumnBySourceId(id);
|
||||
if (recordEntity != null) {
|
||||
throw new RuntimeException("元数据管理-数据变更记录有与之关联的数据,不允许删除!");
|
||||
}
|
||||
//对照表关联
|
||||
ContrastEntity contrastEntity = standardServiceFeign.getBySourceId(id);
|
||||
if (contrastEntity != null) {
|
||||
throw new RuntimeException("数据标准管理-对照表有与之关联的数据,不允许删除!");
|
||||
}
|
||||
//数据质量关联
|
||||
CheckRuleEntity checkRuleEntity = qualityServiceFeign.getBySourceId(id);
|
||||
if (checkRuleEntity != null) {
|
||||
throw new RuntimeException("数据质量管理-规则配置有与之关联的数据,不允许删除!");
|
||||
}
|
||||
//数据集市关联
|
||||
DataApiEntity dataApiEntity = dataApiServiceFeign.getBySourceId(id);
|
||||
if (dataApiEntity != null) {
|
||||
throw new RuntimeException("数据集市管理-数据服务有与之关联的数据,不允许删除!");
|
||||
}
|
||||
//数据可视化关联
|
||||
DataSetEntity dataSetEntity = visualServiceFeign.getBySourceId(id);
|
||||
if (dataSetEntity != null) {
|
||||
throw new RuntimeException("可视化管理-数据集有与之关联的数据,不允许删除!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteTableAndCol(String id) {
|
||||
//同步删除表和字段
|
||||
metadataTableDao.delete(new QueryWrapper<MetadataTableEntity>().eq("source_id", id));
|
||||
metadataColumnDao.delete(new QueryWrapper<MetadataColumnEntity>().eq("source_id", id));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteMetadataSourceBatch(List<String> ids) {
|
||||
for (String id : ids) {
|
||||
deleteMetadataSourceById(id);
|
||||
}
|
||||
//metadataSourceDao.deleteBatchIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DbQuery checkConnection(MetadataSourceDto metadataSourceDto) {
|
||||
MetadataSourceEntity dataSource = metadataSourceMapper.toEntity(metadataSourceDto);
|
||||
DbSchema dbSchema = dataSource.getDbSchema();
|
||||
DbQueryProperty dbQueryProperty = new DbQueryProperty(dataSource.getDbType(), dbSchema.getHost(),
|
||||
dbSchema.getUsername(), dbSchema.getPassword(), dbSchema.getPort(), dbSchema.getDbName(), dbSchema.getSid());
|
||||
DbQuery dbQuery = dataSourceFactory.createDbQuery(dbQueryProperty);
|
||||
return dbQuery;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DbQuery getDbQuery(String id) {
|
||||
MetadataSourceEntity dataSource = super.getById(id);
|
||||
DbSchema dbSchema = dataSource.getDbSchema();
|
||||
DbQueryProperty dbQueryProperty = new DbQueryProperty(dataSource.getDbType(), dbSchema.getHost(),
|
||||
dbSchema.getUsername(), dbSchema.getPassword(), dbSchema.getPort(), dbSchema.getDbName(), dbSchema.getSid());
|
||||
DbQuery dbQuery = dataSourceFactory.createDbQuery(dbQueryProperty);
|
||||
return dbQuery;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DbTable> getDbTables(String id) {
|
||||
MetadataSourceEntity dataSource = super.getById(id);
|
||||
DbSchema dbSchema = dataSource.getDbSchema();
|
||||
DbQueryProperty dbQueryProperty = new DbQueryProperty(dataSource.getDbType(), dbSchema.getHost(),
|
||||
dbSchema.getUsername(), dbSchema.getPassword(), dbSchema.getPort(), dbSchema.getDbName(), dbSchema.getSid());
|
||||
DbQuery dbQuery = dataSourceFactory.createDbQuery(dbQueryProperty);
|
||||
List<DbTable> tables = dbQuery.getTables(dbSchema.getDbName());
|
||||
return tables;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DbColumn> getDbTableColumns(String id, String tableName) {
|
||||
MetadataSourceEntity dataSource = super.getById(id);
|
||||
DbSchema dbSchema = dataSource.getDbSchema();
|
||||
DbQueryProperty dbQueryProperty = new DbQueryProperty(dataSource.getDbType(), dbSchema.getHost(),
|
||||
dbSchema.getUsername(), dbSchema.getPassword(), dbSchema.getPort(), dbSchema.getDbName(), dbSchema.getSid());
|
||||
DbQuery dbQuery = dataSourceFactory.createDbQuery(dbQueryProperty);
|
||||
List<DbColumn> columns = dbQuery.getTableColumns(dbSchema.getDbName(), tableName);
|
||||
return columns;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void syncMetadata(String id) {
|
||||
MetadataSourceEntity metadataSourceEntity = super.getById(id);
|
||||
if (SyncStatus.InSync.getKey().equals(metadataSourceEntity.getIsSync())) {
|
||||
throw new DataException("元数据同步中");
|
||||
}
|
||||
// 异步执行同步任务
|
||||
asyncTask.doTask(metadataSourceEntity, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Document wordMetadata(String id) throws Exception {
|
||||
MetadataSourceEntity metadataSourceEntity = super.getById(id);
|
||||
DbSchema dbSchema = metadataSourceEntity.getDbSchema();
|
||||
String dbName = dbSchema.getDbName();
|
||||
if (StrUtil.isBlank(dbName)) {
|
||||
dbName = dbSchema.getUsername();
|
||||
}
|
||||
QueryWrapper<MetadataTableEntity> tableQueryWrapper = new QueryWrapper<>();
|
||||
tableQueryWrapper.eq("source_id", id);
|
||||
List<MetadataTableEntity> tableEntityList = metadataTableDao.selectList(tableQueryWrapper);
|
||||
// 数据表(主表) TableStart:TableList TableEnd:TableList
|
||||
DataTable tableTable = new DataTable("TableList");
|
||||
tableTable.getColumns().add("id");
|
||||
tableTable.getColumns().add("tableName");
|
||||
tableTable.getColumns().add("tableComment");
|
||||
for (int i = 0; i < tableEntityList.size(); i++) {
|
||||
DataRow row = tableTable.newRow();
|
||||
MetadataTableEntity table = tableEntityList.get(i);
|
||||
row.set(0, table.getId());
|
||||
row.set(1, table.getTableName());
|
||||
row.set(2, table.getTableComment());
|
||||
tableTable.getRows().add(row);
|
||||
}
|
||||
QueryWrapper<MetadataColumnEntity> columnQueryWrapper = new QueryWrapper<>();
|
||||
columnQueryWrapper.eq("source_id", id);
|
||||
columnQueryWrapper.orderByAsc("column_position");
|
||||
List<MetadataColumnEntity> columnEntityList = metadataColumnDao.selectList(columnQueryWrapper);
|
||||
// 元数据(子表) TableStart:ColumnList TableEnd:ColumnList
|
||||
DataTable columnTable = new DataTable("ColumnList");
|
||||
columnTable.getColumns().add("id");
|
||||
columnTable.getColumns().add("tid");
|
||||
columnTable.getColumns().add("columnPosition");
|
||||
columnTable.getColumns().add("columnName");
|
||||
columnTable.getColumns().add("dataType");
|
||||
columnTable.getColumns().add("dataLength");
|
||||
columnTable.getColumns().add("dataPrecision");
|
||||
columnTable.getColumns().add("dataScale");
|
||||
columnTable.getColumns().add("columnNullable");
|
||||
columnTable.getColumns().add("columnKey");
|
||||
columnTable.getColumns().add("dataDefault");
|
||||
columnTable.getColumns().add("columnComment");
|
||||
for (int i = 0; i < columnEntityList.size(); i++) {
|
||||
DataRow row = columnTable.newRow();
|
||||
MetadataColumnEntity column = columnEntityList.get(i);
|
||||
row.set(0, column.getId());
|
||||
row.set(1, column.getTableId());
|
||||
row.set(2, column.getColumnPosition());
|
||||
row.set(3, column.getColumnName());
|
||||
row.set(4, column.getDataType());
|
||||
row.set(5, column.getDataLength());
|
||||
row.set(6, column.getDataPrecision());
|
||||
row.set(7, column.getDataScale());
|
||||
row.set(8, "1".equals(column.getColumnNullable()) ? "Y" : "N");
|
||||
row.set(9, "1".equals(column.getColumnKey()) ? "Y" : "N");
|
||||
row.set(10, column.getDataDefault());
|
||||
row.set(11, column.getColumnComment());
|
||||
columnTable.getRows().add(row);
|
||||
}
|
||||
// 提供数据源
|
||||
DataSet dataSet = new DataSet();
|
||||
dataSet.getTables().add(tableTable);
|
||||
dataSet.getTables().add(columnTable);
|
||||
DataRelation dataRelation = new DataRelation("TableColumnRelation", tableTable.getColumns().get("id"), columnTable.getColumns().get("tid"));
|
||||
dataSet.getRelations().add(dataRelation);
|
||||
// 合并模版
|
||||
ClassPathResource classPathResource = new ClassPathResource("templates/metadata_1.0.0.doc");
|
||||
InputStream inputStream = classPathResource.getInputStream();
|
||||
Document doc = WordUtil.getInstance().getDocument(inputStream);
|
||||
// 提供数据源
|
||||
String[] fieldNames = new String[] {"database"};
|
||||
Object[] fieldValues = new Object[] {dbName.toUpperCase()};
|
||||
MailMerge mailMerge = doc.getMailMerge();
|
||||
mailMerge.execute(fieldNames, fieldValues);
|
||||
mailMerge.executeWithRegions(dataSet);
|
||||
WordUtil.getInstance().insertWatermarkText(doc, SecurityUtil.getUserName());
|
||||
return doc;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Async("taskExecutor")
|
||||
public void refreshMetadata() {
|
||||
String sourceKey = RedisConstant.METADATA_SOURCE_KEY;
|
||||
Boolean hasSourceKey = redisService.hasKey(sourceKey);
|
||||
if (hasSourceKey) {
|
||||
redisService.del(sourceKey);
|
||||
}
|
||||
List<MetadataSourceEntity> sourceEntityList = metadataSourceDao.selectList(Wrappers.emptyWrapper());
|
||||
redisService.set(sourceKey, sourceEntityList);
|
||||
|
||||
String tableKey = RedisConstant.METADATA_TABLE_KEY;
|
||||
Boolean hasTableKey = redisService.hasKey(tableKey);
|
||||
if (hasTableKey) {
|
||||
redisService.del(tableKey);
|
||||
}
|
||||
List<MetadataTableEntity> tableEntityList = metadataTableDao.selectList(Wrappers.emptyWrapper());
|
||||
Map<String, List<MetadataTableEntity>> tableListMap = tableEntityList.stream().collect(Collectors.groupingBy(MetadataTableEntity::getSourceId));
|
||||
redisTemplate.opsForHash().putAll(tableKey, tableListMap);
|
||||
|
||||
String columnKey = RedisConstant.METADATA_COLUMN_KEY;
|
||||
Boolean hasColumnKey = redisService.hasKey(columnKey);
|
||||
if (hasColumnKey) {
|
||||
redisService.del(columnKey);
|
||||
}
|
||||
List<MetadataColumnEntity> columnEntityList = metadataColumnDao.selectList(Wrappers.emptyWrapper());
|
||||
Map<String, List<MetadataColumnEntity>> columnListMap = columnEntityList.stream().collect(Collectors.groupingBy(MetadataColumnEntity::getTableId));
|
||||
redisTemplate.opsForHash().putAll(columnKey, columnListMap);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
package cn.datax.service.data.metadata.service.impl;
|
||||
|
||||
import cn.datax.common.core.RedisConstant;
|
||||
import cn.datax.common.exception.DataException;
|
||||
import cn.datax.common.redis.service.RedisService;
|
||||
import cn.datax.common.utils.SecurityUtil;
|
||||
import cn.datax.service.data.metadata.api.entity.MetadataAuthorizeEntity;
|
||||
import cn.datax.service.data.metadata.api.entity.MetadataTableEntity;
|
||||
import cn.datax.service.data.metadata.api.dto.MetadataTableDto;
|
||||
import cn.datax.service.data.metadata.api.enums.DataLevel;
|
||||
import cn.datax.service.data.metadata.api.query.MetadataTableQuery;
|
||||
import cn.datax.service.data.metadata.service.MetadataTableService;
|
||||
import cn.datax.service.data.metadata.mapstruct.MetadataTableMapper;
|
||||
import cn.datax.service.data.metadata.dao.MetadataTableDao;
|
||||
import cn.datax.common.base.BaseServiceImpl;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据库表信息表 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-29
|
||||
*/
|
||||
@Service
|
||||
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
|
||||
public class MetadataTableServiceImpl extends BaseServiceImpl<MetadataTableDao, MetadataTableEntity> implements MetadataTableService {
|
||||
|
||||
@Autowired
|
||||
private MetadataTableDao metadataTableDao;
|
||||
|
||||
@Autowired
|
||||
private MetadataTableMapper metadataTableMapper;
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public MetadataTableEntity saveMetadataTable(MetadataTableDto metadataTableDto) {
|
||||
MetadataTableEntity metadataTableEntity = metadataTableMapper.toEntity(metadataTableDto);
|
||||
metadataTableDao.insert(metadataTableEntity);
|
||||
return metadataTableEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public MetadataTableEntity updateMetadataTable(MetadataTableDto metadataTableDto) {
|
||||
MetadataTableEntity metadataTableEntity = metadataTableMapper.toEntity(metadataTableDto);
|
||||
metadataTableDao.updateById(metadataTableEntity);
|
||||
return metadataTableEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetadataTableEntity getMetadataTableById(String id) {
|
||||
MetadataTableEntity metadataTableEntity = super.getById(id);
|
||||
return metadataTableEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteMetadataTableById(String id) {
|
||||
metadataTableDao.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteMetadataTableBatch(List<String> ids) {
|
||||
metadataTableDao.deleteBatchIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MetadataTableEntity> getDataMetadataTableList(MetadataTableQuery metadataTableQuery) {
|
||||
boolean admin = SecurityUtil.isAdmin();
|
||||
if (StrUtil.isBlank(metadataTableQuery.getSourceId())) {
|
||||
throw new DataException("数据源不能为空");
|
||||
}
|
||||
List<MetadataTableEntity> tableList = (List<MetadataTableEntity>) redisService.hget(RedisConstant.METADATA_TABLE_KEY, metadataTableQuery.getSourceId());
|
||||
Stream<MetadataTableEntity> stream = Optional.ofNullable(tableList).orElseGet(ArrayList::new).stream();
|
||||
if (!admin) {
|
||||
Set<String> set = new HashSet<>();
|
||||
List<String> roleIds = SecurityUtil.getUserRoleIds();
|
||||
roleIds.stream().forEach(role -> {
|
||||
List<MetadataAuthorizeEntity> list = (List<MetadataAuthorizeEntity>) redisService.hget(RedisConstant.METADATA_AUTHORIZE_KEY, role);
|
||||
set.addAll(Optional.ofNullable(list).orElseGet(ArrayList::new).stream()
|
||||
.filter(s -> Objects.equals(DataLevel.TABLE.getKey(), s.getObjectType()))
|
||||
.map(s -> s.getObjectId()).collect(Collectors.toSet()));
|
||||
});
|
||||
stream = stream.filter(s -> set.contains(s.getId()));
|
||||
}
|
||||
return stream.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E extends IPage<MetadataTableEntity>> E pageWithAuth(E page, Wrapper<MetadataTableEntity> queryWrapper) {
|
||||
boolean admin = SecurityUtil.isAdmin();
|
||||
List<String> roles = new ArrayList<>();
|
||||
if (!admin) {
|
||||
roles = SecurityUtil.getUserRoleIds();
|
||||
}
|
||||
return metadataTableDao.selectPageWithAuth(page, queryWrapper, roles);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
package cn.datax.service.data.metadata.util;
|
||||
|
||||
import cn.datax.service.system.api.dto.JwtUserDto;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.jsonwebtoken.Claims;
|
||||
import io.jsonwebtoken.Jwts;
|
||||
import io.jsonwebtoken.SignatureAlgorithm;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Date;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class JwtUtil {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取凭证信息
|
||||
*
|
||||
* @param token jwt token串
|
||||
* @return Claims
|
||||
*/
|
||||
public static Claims getClaimByToken(String token) {
|
||||
try {
|
||||
if (StringUtils.startsWithIgnoreCase(token, "Bearer ")) {
|
||||
token = token.split(" ")[1];
|
||||
}
|
||||
return Jwts.parser()
|
||||
.setSigningKey("ZmQ0ZGI5NjQ0MDQwY2I4MjMxY2Y3ZmI3MjdhN2ZmMjNhODViOTg1ZGE0NTBjMGM4NDA5NzYxMjdjOWMwYWRmZTBlZjlhNGY3ZTg4Y2U3YTE1ODVkZDU5Y2Y3OGYwZWE1NzUzNWQ2YjFjZDc0NGMxZWU2MmQ3MjY1NzJmNTE0MzI=")
|
||||
.parseClaimsJws(token)
|
||||
.getBody();
|
||||
}catch (Exception e){
|
||||
HttpServletRequest request =((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
||||
String authorization = request.getHeader("Authorization");
|
||||
String url = request.getRequestURL().toString();
|
||||
String uri = request.getRequestURI();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取过期时间
|
||||
*
|
||||
* @param token jwt token 串
|
||||
* @return Date
|
||||
*/
|
||||
public Date getExpiration(String token) {
|
||||
return getClaimByToken(token).getExpiration();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 验证token是否失效
|
||||
*
|
||||
* @param token token
|
||||
* @return true:过期 false:没过期
|
||||
*/
|
||||
public boolean isExpired(String token) {
|
||||
try {
|
||||
final Date expiration = getExpiration(token);
|
||||
return expiration.before(new Date());
|
||||
} catch (Exception e) {
|
||||
log.error("[JwtUtils --> isExpired]: {}", e.getMessage());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// /**
|
||||
// * 检验是否为 jwt 格式的字符串
|
||||
// *
|
||||
// * 说明: jwt 字符串由三部分组成, 分别用 . 分隔开, 所以认为有两个 . 的字符串就是jwt形式的字符串
|
||||
// * @param token jwt token串
|
||||
// * @return boolean
|
||||
// */
|
||||
// public boolean isJwtStr(String token){
|
||||
// return StringUtils.countOccurrencesOf(token, ".") == 2;
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* 获取 jwt 中的账户名
|
||||
*
|
||||
* @param token jwt token 串
|
||||
* @return String
|
||||
*/
|
||||
public String getAccountName(String token){
|
||||
String subject = getClaimByToken(token).getSubject();
|
||||
JwtUserDto jwtContent = JSONObject.parseObject(subject, JwtUserDto.class);
|
||||
jwtContent.getUsername();
|
||||
return jwtContent.getUsername();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取 jwt 的账户对象
|
||||
* @param token
|
||||
* @return
|
||||
*/
|
||||
public static JwtUserDto getTokenSubjectObject(String token){
|
||||
Claims claimByToken = getClaimByToken(token);
|
||||
String subject = claimByToken.getSubject();
|
||||
String body = JSONObject.toJSONString(subject);
|
||||
Object parse = JSON.parse(body);
|
||||
String s = parse.toString();
|
||||
return JSONObject.parseObject(s,JwtUserDto.class);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取 jwt 账户信息的json字符串
|
||||
* @param token
|
||||
* @return
|
||||
*/
|
||||
public String getTokenSubjectStr(String token){
|
||||
String body = JSONObject.toJSONString(getClaimByToken(token).getSubject());
|
||||
Object parse = JSON.parse(body);
|
||||
return parse.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
package cn.datax.service.data.metadata.util;
|
||||
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 获取 HttpServletRequest
|
||||
* @author AllDataDC
|
||||
* @date 2023-01-27
|
||||
*/
|
||||
public class RequestHolder {
|
||||
|
||||
public static HttpServletRequest getHttpServletRequest() {
|
||||
return ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
server:
|
||||
port: 8820
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: service-data-metadata
|
||||
profiles:
|
||||
active: dev
|
||||
cloud:
|
||||
config:
|
||||
label: master
|
||||
name: ${spring.application.name}
|
||||
profile: ${spring.profiles.active}
|
||||
discovery:
|
||||
enabled: true
|
||||
service-id: config
|
||||
|
||||
# 注册中心配置
|
||||
eureka:
|
||||
instance:
|
||||
lease-renewal-interval-in-seconds: 20
|
||||
prefer-ip-address: true
|
||||
ip-address: 192.168.1.169
|
||||
client:
|
||||
register-with-eureka: true
|
||||
fetch-registry: true
|
||||
instance-info-replication-interval-seconds: 30
|
||||
registry-fetch-interval-seconds: 3
|
||||
service-url:
|
||||
defaultZone: http://192.168.1.169:8610/eureka
|
||||
#jwt
|
||||
jwt:
|
||||
header: Authorization
|
||||
# 令牌前缀
|
||||
token-start-with: Bearer
|
||||
# 必须使用最少88位的Base64对该令牌进行编码
|
||||
base64-secret: ZmQ0ZGI5NjQ0MDQwY2I4MjMxY2Y3ZmI3MjdhN2ZmMjNhODViOTg1ZGE0NTBjMGM4NDA5NzYxMjdjOWMwYWRmZTBlZjlhNGY3ZTg4Y2U3YTE1ODVkZDU5Y2Y3OGYwZWE1NzUzNWQ2YjFjZDc0NGMxZWU2MmQ3MjY1NzJmNTE0MzI=
|
||||
# 令牌过期时间 此处单位/毫秒 ,默认4小时,可在此网站生成 https://www.convertworld.com/zh-hans/time/milliseconds.html
|
||||
token-validity-in-seconds: 14400000
|
||||
# 在线用户key
|
||||
online-key: online-token-
|
||||
# 验证码
|
||||
code-key: code-key-
|
||||
# token 续期检查时间范围(默认30分钟,单位毫秒),在token即将过期的一段时间内用户操作了,则给用户的token续期
|
||||
detect: 1800000
|
||||
# 续期时间范围,默认1小时,单位毫秒
|
||||
renew: 3600000
|
||||
@@ -0,0 +1,78 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
||||
<springProperty scope="context" name="springAppName" source="spring.application.name"/>
|
||||
<property name="log.path" value="logs/service-data-metadata"/>
|
||||
<property name="log.maxHistory" value="15"/>
|
||||
<property name="log.totalSizeCap" value="500MB"/>
|
||||
<property name="log.maxFileSize" value="10MB"/>
|
||||
<property name="log.colorPattern"
|
||||
value="%magenta(%d{yyyy-MM-dd HH:mm:ss}) %highlight(%-5level) %boldCyan(${springAppName:-}) %yellow(%thread) %green(%logger) %msg%n"/>
|
||||
<property name="log.pattern" value="%d{yyyy-MM-dd HH:mm:ss} %-5level ${springAppName:-} %thread %logger %msg%n"/>
|
||||
|
||||
<!--输出到控制台-->
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>${log.colorPattern}</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!--输出到文件-->
|
||||
<!-- RollingFileAppender:滚动记录文件,先将日志记录到指定文件,当符合某个条件时,将日志记录到其他文件 -->
|
||||
<!-- 以下的大概意思是:1.先按日期存日志,日期变了,将前一天的日志文件名重命名为XXX%日期%索引,新的日志仍然是project_info.log -->
|
||||
<!-- 2.如果日期没有发生变化,但是当前日志的文件大小超过10MB时,对当前日志进行分割 重命名-->
|
||||
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<!--日志文件路径和名称-->
|
||||
<File>${log.path}/info/info.log</File>
|
||||
<!--是否追加到文件末尾,默认为true-->
|
||||
<append>true</append>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||
<!-- 日志文件的名字会根据fileNamePattern的值,每隔一段时间改变一次 -->
|
||||
<!-- 文件名:logs/project_info.2017-12-05.0.log -->
|
||||
<!-- 注意:SizeAndTimeBasedRollingPolicy中 %i和%d令牌都是强制性的,必须存在,要不会报错 -->
|
||||
<fileNamePattern>${log.path}/info/info.%d.%i.log</fileNamePattern>
|
||||
<!-- 每产生一个日志文件,该日志文件的保存期限为30天, ps:maxHistory的单位是根据fileNamePattern中的翻转策略自动推算出来的,例如上面选用了yyyy-MM-dd,则单位为天
|
||||
如果上面选用了yyyy-MM,则单位为月,另外上面的单位默认为yyyy-MM-dd-->
|
||||
<MaxHistory>${log.maxHistory}</MaxHistory>
|
||||
<!-- 每个日志文件到2mb的时候开始切分,最多保留30天,但最大到500MB,哪怕没到30天也要删除多余的日志 -->
|
||||
<totalSizeCap>${log.totalSizeCap}</totalSizeCap>
|
||||
<!-- maxFileSize:这是活动文件的大小,默认值是10MB,测试时可改成5KB看效果 -->
|
||||
<maxFileSize>${log.maxFileSize}</maxFileSize>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>${log.pattern}</pattern>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<level>INFO</level>
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<File>${log.path}/error/error.log</File>
|
||||
<append>true</append>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||
<fileNamePattern>${log.path}/error/error.%d.%i.log</fileNamePattern>
|
||||
<MaxHistory>${log.maxHistory}</MaxHistory>
|
||||
<totalSizeCap>${log.totalSizeCap}</totalSizeCap>
|
||||
<maxFileSize>${log.maxFileSize}</maxFileSize>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>${log.pattern}</pattern>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<level>ERROR</level>
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<root level="debug">
|
||||
<appender-ref ref="console"/>
|
||||
</root>
|
||||
|
||||
<root level="info">
|
||||
<appender-ref ref="file_info"/>
|
||||
<appender-ref ref="file_error"/>
|
||||
</root>
|
||||
</configuration>
|
||||
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.datax.service.data.metadata.dao.MetadataAuthorizeDao">
|
||||
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="cn.datax.service.data.metadata.api.entity.MetadataAuthorizeEntity">
|
||||
<result column="id" property="id" />
|
||||
<result column="object_id" property="objectId" />
|
||||
<result column="role_id" property="roleId" />
|
||||
<result column="object_type" property="objectType" />
|
||||
</resultMap>
|
||||
|
||||
<!-- 通用查询结果列 -->
|
||||
<sql id="Base_Column_List">
|
||||
id,
|
||||
object_id, role_id, object_type
|
||||
</sql>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,76 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.datax.service.data.metadata.dao.MetadataChangeRecordDao">
|
||||
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="cn.datax.service.data.metadata.api.entity.MetadataChangeRecordEntity">
|
||||
<result column="id" property="id" />
|
||||
<result column="status" property="status" />
|
||||
<result column="create_by" property="createBy" />
|
||||
<result column="create_time" property="createTime" />
|
||||
<result column="create_dept" property="createDept" />
|
||||
<result column="update_by" property="updateBy" />
|
||||
<result column="update_time" property="updateTime" />
|
||||
<result column="remark" property="remark" />
|
||||
<result column="version" property="version" />
|
||||
<result column="object_type" property="objectType" />
|
||||
<result column="object_id" property="objectId" />
|
||||
<result column="field_name" property="fieldName" />
|
||||
<result column="field_old_value" property="fieldOldValue" />
|
||||
<result column="field_new_value" property="fieldNewValue" />
|
||||
<result column="source_id" property="sourceId" />
|
||||
<result column="source_name" property="sourceName" />
|
||||
<result column="table_id" property="tableId" />
|
||||
<result column="table_name" property="tableName" />
|
||||
</resultMap>
|
||||
|
||||
<!-- 通用查询结果列 -->
|
||||
<sql id="Base_Column_List">
|
||||
id,
|
||||
status,
|
||||
create_by,
|
||||
create_time,
|
||||
create_dept,
|
||||
update_by,
|
||||
update_time,
|
||||
remark,
|
||||
version, object_type, object_id, field_name, field_old_value, field_new_value
|
||||
</sql>
|
||||
|
||||
<sql id="Record_Column_List">
|
||||
${alias}.id,
|
||||
${alias}.status,
|
||||
${alias}.create_by,
|
||||
${alias}.create_time,
|
||||
${alias}.create_dept,
|
||||
${alias}.update_by,
|
||||
${alias}.update_time,
|
||||
${alias}.remark,
|
||||
${alias}.version, ${alias}.object_type, ${alias}.object_id, ${alias}.field_name, ${alias}.field_old_value, ${alias}.field_new_value
|
||||
</sql>
|
||||
|
||||
<select id="selectById" resultMap="BaseResultMap">
|
||||
SELECT c.source_id, s.source_name, c.table_id, t.table_name,
|
||||
<include refid="Record_Column_List"><property name="alias" value="r"/></include>
|
||||
FROM metadata_change_record r
|
||||
LEFT JOIN metadata_column c ON c.id = r.object_id
|
||||
LEFT JOIN metadata_source s ON s.id = c.source_id
|
||||
LEFT JOIN metadata_table t ON t.id = c.table_id
|
||||
WHERE 1 = 1 AND r.id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="selectPage" resultMap="BaseResultMap">
|
||||
SELECT c.source_id, s.source_name, c.table_id, t.table_name,
|
||||
<include refid="Record_Column_List"><property name="alias" value="r"/></include>
|
||||
FROM metadata_change_record r
|
||||
LEFT JOIN metadata_column c ON c.id = r.object_id
|
||||
LEFT JOIN metadata_source s ON s.id = c.source_id
|
||||
LEFT JOIN metadata_table t ON t.id = c.table_id
|
||||
${ew.customSqlSegment}
|
||||
</select>
|
||||
|
||||
<select id="selectRelColumnBySourceId" resultType="cn.datax.service.data.metadata.api.entity.MetadataChangeRecordEntity">
|
||||
SELECT id FROM metadata_change_record WHERE object_id in (SELECT id FROM metadata_column WHERE source_id=#{id}) LIMIT 1
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,59 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.datax.service.data.metadata.dao.MetadataColumnDao">
|
||||
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="cn.datax.service.data.metadata.api.entity.MetadataColumnEntity">
|
||||
<result column="id" property="id" />
|
||||
<result column="source_id" property="sourceId" />
|
||||
<result column="table_id" property="tableId" />
|
||||
<result column="column_name" property="columnName" />
|
||||
<result column="column_comment" property="columnComment" />
|
||||
<result column="column_key" property="columnKey" />
|
||||
<result column="column_nullable" property="columnNullable" />
|
||||
<result column="column_position" property="columnPosition" />
|
||||
<result column="data_type" property="dataType" />
|
||||
<result column="data_length" property="dataLength" />
|
||||
<result column="data_precision" property="dataPrecision" />
|
||||
<result column="data_scale" property="dataScale" />
|
||||
<result column="data_default" property="dataDefault" />
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="ExtendResultMap" type="cn.datax.service.data.metadata.api.entity.MetadataColumnEntity" extends="BaseResultMap">
|
||||
<result column="source_name" property="sourceName" />
|
||||
<result column="table_name" property="tableName" />
|
||||
<result column="table_comment" property="tableComment" />
|
||||
</resultMap>
|
||||
|
||||
<!-- 通用查询结果列 -->
|
||||
<sql id="Base_Column_List">
|
||||
id,
|
||||
source_id, table_id, column_name, column_comment, column_key, column_nullable, column_position, data_type, data_length, data_precision, data_scale, data_default
|
||||
</sql>
|
||||
|
||||
<sql id="Column_Column_List">
|
||||
${alias}.id,
|
||||
${alias}.source_id, ${alias}.table_id, ${alias}.column_name, ${alias}.column_comment, ${alias}.column_key, ${alias}.column_nullable, ${alias}.column_position, ${alias}.data_type, ${alias}.data_length, ${alias}.data_precision, ${alias}.data_scale, ${alias}.data_default
|
||||
</sql>
|
||||
|
||||
<select id="selectPageWithAuth" resultMap="ExtendResultMap">
|
||||
SELECT s.source_name, t.table_name, t.table_comment,
|
||||
<include refid="Column_Column_List"><property name="alias" value="c"/></include>
|
||||
FROM metadata_column c
|
||||
LEFT JOIN metadata_source s ON s.id = c.source_id
|
||||
LEFT JOIN metadata_table t ON t.id = c.table_id
|
||||
<trim prefix="WHERE" prefixOverrides="WHERE |AND |OR ">
|
||||
${ew.customSqlSegment}
|
||||
<if test="roles != null and roles.size > 0">
|
||||
AND EXISTS (
|
||||
SELECT 1 FROM metadata_authorize auth WHERE auth.object_id = c.id AND auth.object_type = 'column'
|
||||
AND auth.role_id IN
|
||||
<foreach collection="roles" index="index" item="item" open="(" separator="," close=")">
|
||||
#{item}
|
||||
</foreach>
|
||||
)
|
||||
</if>
|
||||
</trim>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,81 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.datax.service.data.metadata.dao.MetadataSourceDao">
|
||||
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="cn.datax.service.data.metadata.api.entity.MetadataSourceEntity">
|
||||
<result column="id" property="id" />
|
||||
<result column="status" property="status" />
|
||||
<result column="create_by" property="createBy" />
|
||||
<result column="create_time" property="createTime" />
|
||||
<result column="create_dept" property="createDept" />
|
||||
<result column="update_by" property="updateBy" />
|
||||
<result column="update_time" property="updateTime" />
|
||||
<result column="remark" property="remark" />
|
||||
<result column="db_type" property="dbType" />
|
||||
<result column="source_name" property="sourceName" />
|
||||
<result column="is_sync" property="isSync" />
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="ExtendResultMap" type="cn.datax.service.data.metadata.api.entity.MetadataSourceEntity" extends="BaseResultMap">
|
||||
<result column="db_schema" property="dbSchema" typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler" />
|
||||
</resultMap>
|
||||
|
||||
<!-- 通用查询结果列 -->
|
||||
<sql id="Base_Column_List">
|
||||
id,
|
||||
status,
|
||||
create_by,
|
||||
create_time,
|
||||
create_dept,
|
||||
update_by,
|
||||
update_time,
|
||||
remark,
|
||||
db_type, source_name, is_sync
|
||||
</sql>
|
||||
|
||||
<sql id="Source_Column_List">
|
||||
${alias}.id,
|
||||
${alias}.status,
|
||||
${alias}.create_by,
|
||||
${alias}.create_time,
|
||||
${alias}.create_dept,
|
||||
${alias}.update_by,
|
||||
${alias}.update_time,
|
||||
${alias}.remark,
|
||||
${alias}.db_type, ${alias}.source_name, ${alias}.is_sync, ${alias}.db_schema
|
||||
</sql>
|
||||
|
||||
<select id="selectById" resultMap="ExtendResultMap">
|
||||
SELECT
|
||||
<include refid="Source_Column_List"><property name="alias" value="s"/></include>
|
||||
FROM metadata_source s
|
||||
WHERE 1=1 AND s.id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="selectList" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"></include>
|
||||
FROM metadata_source
|
||||
${ew.customSqlSegment}
|
||||
</select>
|
||||
|
||||
<select id="selectPageWithAuth" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Source_Column_List"><property name="alias" value="s"/></include>
|
||||
FROM metadata_source s
|
||||
<trim prefix="WHERE" prefixOverrides="WHERE |AND |OR ">
|
||||
${ew.customSqlSegment}
|
||||
<if test="roles != null and roles.size > 0">
|
||||
AND EXISTS (
|
||||
SELECT 1 FROM metadata_authorize auth WHERE auth.object_id = s.id AND auth.object_type = 'database'
|
||||
AND auth.role_id IN
|
||||
<foreach collection="roles" index="index" item="item" open="(" separator="," close=")">
|
||||
#{item}
|
||||
</foreach>
|
||||
)
|
||||
</if>
|
||||
</trim>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.datax.service.data.metadata.dao.MetadataTableDao">
|
||||
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="cn.datax.service.data.metadata.api.entity.MetadataTableEntity">
|
||||
<result column="id" property="id" />
|
||||
<result column="source_id" property="sourceId" />
|
||||
<result column="table_name" property="tableName" />
|
||||
<result column="table_comment" property="tableComment" />
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="ExtendResultMap" type="cn.datax.service.data.metadata.api.entity.MetadataTableEntity" extends="BaseResultMap">
|
||||
<result column="source_name" property="sourceName" />
|
||||
</resultMap>
|
||||
|
||||
<!-- 通用查询结果列 -->
|
||||
<sql id="Base_Column_List">
|
||||
id,
|
||||
source_id, table_name, table_comment
|
||||
</sql>
|
||||
|
||||
<sql id="Table_Column_List">
|
||||
${alias}.id,
|
||||
${alias}.source_id, ${alias}.table_name, ${alias}.table_comment
|
||||
</sql>
|
||||
|
||||
<select id="selectPageWithAuth" resultMap="ExtendResultMap">
|
||||
SELECT s.source_name,
|
||||
<include refid="Table_Column_List"><property name="alias" value="t"/></include>
|
||||
FROM metadata_table t
|
||||
LEFT JOIN metadata_source s ON s.id = t.source_id
|
||||
<trim prefix="WHERE" prefixOverrides="WHERE |AND |OR ">
|
||||
${ew.customSqlSegment}
|
||||
<if test="roles != null and roles.size > 0">
|
||||
AND EXISTS (
|
||||
SELECT 1 FROM metadata_authorize auth WHERE auth.object_id = t.id AND auth.object_type = 'table'
|
||||
AND auth.role_id IN
|
||||
<foreach collection="roles" index="index" item="item" open="(" separator="," close=")">
|
||||
#{item}
|
||||
</foreach>
|
||||
)
|
||||
</if>
|
||||
</trim>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,25 @@
|
||||
module.log=com.p6spy.engine.logging.P6LogFactory,com.p6spy.engine.outage.P6OutageFactory
|
||||
# 自定义日志打印
|
||||
logMessageFormat=com.baomidou.mybatisplus.extension.p6spy.P6SpyLogger
|
||||
#日志输出到控制台
|
||||
appender=com.baomidou.mybatisplus.extension.p6spy.StdoutLogger
|
||||
# 使用日志系统记录 sql
|
||||
#appender=com.p6spy.engine.spy.appender.Slf4JLogger
|
||||
# 设置 p6spy driver 代理
|
||||
deregisterdrivers=true
|
||||
# 取消JDBC URL前缀
|
||||
useprefix=true
|
||||
# 配置记录 Log 例外,可去掉的结果集有error,info,batch,debug,statement,commit,rollback,result,resultset.
|
||||
excludecategories=info,debug,result,batch,resultset
|
||||
# 日期格式
|
||||
dateformat=yyyy-MM-dd HH:mm:ss
|
||||
# 实际驱动可多个
|
||||
#driverlist=org.h2.Driver
|
||||
# 是否开启慢SQL记录
|
||||
outagedetection=true
|
||||
# 慢SQL记录标准 2 秒
|
||||
outagedetectioninterval=2
|
||||
# 开启过滤
|
||||
filter=true
|
||||
# 配置不打印的内容
|
||||
exclude=select 1
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user