init
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>data-metadata-service-parent</artifactId>
|
||||
<groupId>com.platform</groupId>
|
||||
<version>0.4.x</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<version>0.4.x</version>
|
||||
<artifactId>data-metadata-service-api</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-micro-spring-boot-starter</artifactId>
|
||||
<version>${knife4j.version}</version>
|
||||
</dependency>
|
||||
<!--feign 依赖-->
|
||||
<dependency>
|
||||
<groupId>io.github.openfeign</groupId>
|
||||
<artifactId>feign-okhttp</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.platform</groupId>
|
||||
<artifactId>common-core</artifactId>
|
||||
<version>0.4.x</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-web</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,25 @@
|
||||
package cn.datax.service.data.metadata.api.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.Serializable;
|
||||
|
||||
@ApiModel(value = "数据授权信息Model")
|
||||
@Data
|
||||
public class AuthorizeData implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
@NotBlank(message = "目标表主键ID不能为空")
|
||||
@ApiModelProperty(value = "目标表主键ID")
|
||||
private String objectId;
|
||||
@NotBlank(message = "角色ID不能为空")
|
||||
@ApiModelProperty(value = "角色ID")
|
||||
private String roleId;
|
||||
@NotBlank(message = "目标表类型不能为空")
|
||||
@ApiModelProperty(value = "目标表类型")
|
||||
private String objectType;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package cn.datax.service.data.metadata.api.dto;
|
||||
|
||||
import cn.datax.common.validate.ValidationGroups;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
@ApiModel(value = "数据源连接信息Model")
|
||||
@Data
|
||||
public class DbSchema implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
@ApiModelProperty(value = "主机")
|
||||
@NotBlank(message = "主机不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String host;
|
||||
@ApiModelProperty(value = "端口")
|
||||
@NotNull(message = "端口不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private Integer port;
|
||||
@ApiModelProperty(value = "用户名")
|
||||
@NotBlank(message = "用户名不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String username;
|
||||
@ApiModelProperty(value = "密码")
|
||||
@NotBlank(message = "密码不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String password;
|
||||
@ApiModelProperty(value = "数据库")
|
||||
private String dbName;
|
||||
@ApiModelProperty(value = "服务名")
|
||||
private String sid;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package cn.datax.service.data.metadata.api.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据授权信息表 实体DTO
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-23
|
||||
*/
|
||||
@ApiModel(value = "数据授权信息表Model")
|
||||
@Data
|
||||
public class MetadataAuthorizeDto implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
@NotBlank(message = "角色ID不能为空")
|
||||
@ApiModelProperty(value = "角色ID")
|
||||
private String roleId;
|
||||
|
||||
@Valid
|
||||
@ApiModelProperty(value = "授权信息")
|
||||
private List<AuthorizeData> authorizeDataList;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package cn.datax.service.data.metadata.api.dto;
|
||||
|
||||
import cn.datax.common.validate.ValidationGroups;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 元数据变更记录表 实体DTO
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-30
|
||||
*/
|
||||
@ApiModel(value = "元数据变更记录表Model")
|
||||
@Data
|
||||
public class MetadataChangeRecordDto implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
@ApiModelProperty(value = "主键ID")
|
||||
@NotBlank(message = "主键ID不能为空", groups = {ValidationGroups.Update.class})
|
||||
private String id;
|
||||
@ApiModelProperty(value = "版本号")
|
||||
private Integer version;
|
||||
@ApiModelProperty(value = "更改类型")
|
||||
private String objectType;
|
||||
@ApiModelProperty(value = "源数据表主键")
|
||||
private String objectId;
|
||||
@ApiModelProperty(value = "修改的源数据表的字段名")
|
||||
private String fieldName;
|
||||
@ApiModelProperty(value = "该字段原来的值")
|
||||
private String fieldOldValue;
|
||||
@ApiModelProperty(value = "该字段最新的值")
|
||||
private String fieldNewValue;
|
||||
@ApiModelProperty(value = "状态")
|
||||
@NotNull(message = "状态不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String status;
|
||||
@ApiModelProperty(value = "备注")
|
||||
private String remark;
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package cn.datax.service.data.metadata.api.dto;
|
||||
|
||||
import cn.datax.common.validate.ValidationGroups;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 元数据信息表 实体DTO
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-29
|
||||
*/
|
||||
@ApiModel(value = "元数据信息表Model")
|
||||
@Data
|
||||
public class MetadataColumnDto implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
@ApiModelProperty(value = "主键ID")
|
||||
@NotBlank(message = "主键ID不能为空", groups = {ValidationGroups.Update.class})
|
||||
private String id;
|
||||
@ApiModelProperty(value = "所属数据源")
|
||||
private String sourceId;
|
||||
@ApiModelProperty(value = "所属数据表")
|
||||
private String tableId;
|
||||
@ApiModelProperty(value = "字段名称")
|
||||
private String columnName;
|
||||
@ApiModelProperty(value = "字段注释")
|
||||
private String columnComment;
|
||||
@ApiModelProperty(value = "字段是否主键(1是0否)")
|
||||
private String columnKey;
|
||||
@ApiModelProperty(value = "字段是否允许为空(1是0否)")
|
||||
private String columnNullable;
|
||||
@ApiModelProperty(value = "字段序号")
|
||||
private String columnPosition;
|
||||
@ApiModelProperty(value = "数据类型")
|
||||
private String dataType;
|
||||
@ApiModelProperty(value = "数据长度")
|
||||
private String dataLength;
|
||||
@ApiModelProperty(value = "数据精度")
|
||||
private String dataPrecision;
|
||||
@ApiModelProperty(value = "数据小数位")
|
||||
private String dataScale;
|
||||
@ApiModelProperty(value = "数据默认值")
|
||||
private String dataDefault;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package cn.datax.service.data.metadata.api.dto;
|
||||
|
||||
import cn.datax.common.validate.ValidationGroups;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据源信息表 实体DTO
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-14
|
||||
*/
|
||||
@ApiModel(value = "数据源信息表Model")
|
||||
@Data
|
||||
public class MetadataSourceDto implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
@ApiModelProperty(value = "主键ID")
|
||||
@NotBlank(message = "主键ID不能为空", groups = {ValidationGroups.Update.class})
|
||||
private String id;
|
||||
@ApiModelProperty(value = "数据源类型")
|
||||
@NotBlank(message = "数据源类型不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String dbType;
|
||||
@ApiModelProperty(value = "数据源名称")
|
||||
@NotBlank(message = "数据源名称不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String sourceName;
|
||||
@ApiModelProperty(value = "数据源连接信息")
|
||||
@Valid
|
||||
private DbSchema dbSchema;
|
||||
@ApiModelProperty(value = "状态")
|
||||
@NotNull(message = "状态不能为空", groups = {ValidationGroups.Insert.class, ValidationGroups.Update.class})
|
||||
private String status;
|
||||
@ApiModelProperty(value = "备注")
|
||||
private String remark;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package cn.datax.service.data.metadata.api.dto;
|
||||
|
||||
import cn.datax.common.validate.ValidationGroups;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据库表信息表 实体DTO
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-29
|
||||
*/
|
||||
@ApiModel(value = "数据库表信息表Model")
|
||||
@Data
|
||||
public class MetadataTableDto implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
@ApiModelProperty(value = "主键ID")
|
||||
@NotBlank(message = "主键ID不能为空", groups = {ValidationGroups.Update.class})
|
||||
private String id;
|
||||
@ApiModelProperty(value = "所属数据源")
|
||||
private String sourceId;
|
||||
@ApiModelProperty(value = "表名")
|
||||
private String tableName;
|
||||
@ApiModelProperty(value = "表注释")
|
||||
private String tableComment;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package cn.datax.service.data.metadata.api.dto;
|
||||
|
||||
import cn.datax.common.validate.ValidationGroups;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class SqlConsoleDto implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
@ApiModelProperty(value = "当前时间戳")
|
||||
@NotBlank(message = "时间戳不能为空", groups = {ValidationGroups.Other.class})
|
||||
private String sqlKey;
|
||||
|
||||
@ApiModelProperty(value = "数据源")
|
||||
@NotBlank(message = "数据源不能为空")
|
||||
private String sourceId;
|
||||
|
||||
@ApiModelProperty(value = "SQL文本")
|
||||
@NotBlank(message = "SQL不能为空")
|
||||
private String sqlText;
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package cn.datax.service.data.metadata.api.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import cn.datax.common.base.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据授权信息表
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-23
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@TableName("metadata_authorize")
|
||||
public class MetadataAuthorizeEntity implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.ASSIGN_ID)
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 目标表主键ID
|
||||
*/
|
||||
private String objectId;
|
||||
|
||||
/**
|
||||
* 角色ID
|
||||
*/
|
||||
private String roleId;
|
||||
|
||||
/**
|
||||
* 目标表类型
|
||||
*/
|
||||
private String objectType;
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package cn.datax.service.data.metadata.api.entity;
|
||||
|
||||
import cn.datax.common.base.DataScopeBaseEntity;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 元数据变更记录表
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-30
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Accessors(chain = true)
|
||||
@TableName(value = "metadata_change_record", autoResultMap = true)
|
||||
public class MetadataChangeRecordEntity extends DataScopeBaseEntity {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
/**
|
||||
* 版本号
|
||||
*/
|
||||
private Integer version;
|
||||
|
||||
/**
|
||||
* 源数据的表名或者能唯一对应的源数据表的标识(可废弃)
|
||||
*/
|
||||
private String objectType;
|
||||
|
||||
/**
|
||||
* 源数据表主键
|
||||
*/
|
||||
private String objectId;
|
||||
|
||||
/**
|
||||
* 修改的源数据表的字段名
|
||||
*/
|
||||
private String fieldName;
|
||||
|
||||
/**
|
||||
* 该字段原来的值
|
||||
*/
|
||||
private String fieldOldValue;
|
||||
|
||||
/**
|
||||
* 该字段最新的值
|
||||
*/
|
||||
private String fieldNewValue;
|
||||
|
||||
/**
|
||||
* 数据源
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private String sourceId;
|
||||
@TableField(exist = false)
|
||||
private String sourceName;
|
||||
|
||||
/**
|
||||
* 数据库表
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private String tableId;
|
||||
@TableField(exist = false)
|
||||
private String tableName;
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package cn.datax.service.data.metadata.api.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 元数据信息表
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-29
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@TableName(value = "metadata_column", autoResultMap = true)
|
||||
public class MetadataColumnEntity implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.ASSIGN_ID)
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 所属数据源
|
||||
*/
|
||||
private String sourceId;
|
||||
|
||||
/**
|
||||
* 所属数据表
|
||||
*/
|
||||
private String tableId;
|
||||
|
||||
/**
|
||||
* 字段名称
|
||||
*/
|
||||
private String columnName;
|
||||
|
||||
/**
|
||||
* 字段注释
|
||||
*/
|
||||
private String columnComment;
|
||||
|
||||
/**
|
||||
* 字段是否主键(1是0否)
|
||||
*/
|
||||
private String columnKey;
|
||||
|
||||
/**
|
||||
* 字段是否允许为空(1是0否)
|
||||
*/
|
||||
private String columnNullable;
|
||||
|
||||
/**
|
||||
* 字段序号
|
||||
*/
|
||||
private String columnPosition;
|
||||
|
||||
/**
|
||||
* 数据类型
|
||||
*/
|
||||
private String dataType;
|
||||
|
||||
/**
|
||||
* 数据长度
|
||||
*/
|
||||
private String dataLength;
|
||||
|
||||
/**
|
||||
* 数据精度
|
||||
*/
|
||||
private String dataPrecision;
|
||||
|
||||
/**
|
||||
* 数据小数位
|
||||
*/
|
||||
private String dataScale;
|
||||
|
||||
/**
|
||||
* 数据默认值
|
||||
*/
|
||||
private String dataDefault;
|
||||
|
||||
@TableField(exist = false)
|
||||
private String sourceName;
|
||||
|
||||
@TableField(exist = false)
|
||||
private String tableName;
|
||||
|
||||
@TableField(exist = false)
|
||||
private String tableComment;
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package cn.datax.service.data.metadata.api.entity;
|
||||
|
||||
import cn.datax.common.base.DataScopeBaseEntity;
|
||||
import cn.datax.service.data.metadata.api.dto.DbSchema;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据源信息表
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-14
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Accessors(chain = true)
|
||||
@TableName(value = "metadata_source", autoResultMap = true)
|
||||
public class MetadataSourceEntity extends DataScopeBaseEntity {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
/**
|
||||
* 数据源类型
|
||||
*/
|
||||
private String dbType;
|
||||
|
||||
/**
|
||||
* 数据源名称
|
||||
*/
|
||||
private String sourceName;
|
||||
|
||||
/**
|
||||
* 元数据同步(0否,1同步中, 2是 3-出错)
|
||||
*/
|
||||
private String isSync;
|
||||
|
||||
/**
|
||||
* 数据源连接信息
|
||||
*/
|
||||
@TableField(typeHandler = JacksonTypeHandler.class)
|
||||
private DbSchema dbSchema;
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package cn.datax.service.data.metadata.api.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据库表信息表
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-29
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@TableName(value = "metadata_table", autoResultMap = true)
|
||||
public class MetadataTableEntity implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.ASSIGN_ID)
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 所属数据源
|
||||
*/
|
||||
private String sourceId;
|
||||
|
||||
/**
|
||||
* 表名
|
||||
*/
|
||||
private String tableName;
|
||||
|
||||
/**
|
||||
* 表注释
|
||||
*/
|
||||
private String tableComment;
|
||||
|
||||
@TableField(exist = false)
|
||||
private String sourceName;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package cn.datax.service.data.metadata.api.enums;
|
||||
|
||||
public enum DataLevel {
|
||||
|
||||
DATABASE("database", 1),
|
||||
TABLE("table", 2),
|
||||
COLUMN("column", 3);
|
||||
|
||||
private final String key;
|
||||
|
||||
private final Integer level;
|
||||
|
||||
DataLevel(String key, Integer level) {
|
||||
this.key = key;
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public Integer getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public static DataLevel getLevel(String key) {
|
||||
for (DataLevel type : DataLevel.values()) {
|
||||
if (type.key.equals(key)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return DATABASE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package cn.datax.service.data.metadata.api.enums;
|
||||
|
||||
public enum SyncStatus {
|
||||
|
||||
NotSync("0"),
|
||||
InSync("1"),
|
||||
IsSync("2"),
|
||||
SyncError("3");
|
||||
|
||||
private final String key;
|
||||
|
||||
SyncStatus(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package cn.datax.service.data.metadata.api.feign;
|
||||
|
||||
import cn.datax.service.data.metadata.api.entity.MetadataSourceEntity;
|
||||
import cn.datax.service.data.metadata.api.feign.factory.MetadataSourceServiceFeignFallbackFactory;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@FeignClient(contextId = "metadataSourceServiceFeign", value = "service-data-metadata", fallbackFactory = MetadataSourceServiceFeignFallbackFactory.class)
|
||||
public interface MetadataSourceServiceFeign {
|
||||
|
||||
@GetMapping("/inner/sources/{id}")
|
||||
MetadataSourceEntity getMetadataSourceById(@PathVariable("id") String id);
|
||||
|
||||
@GetMapping("/inner/sources/list")
|
||||
List<MetadataSourceEntity> getMetadataSourceList();
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package cn.datax.service.data.metadata.api.feign.factory;
|
||||
|
||||
import cn.datax.service.data.metadata.api.feign.MetadataSourceServiceFeign;
|
||||
import cn.datax.service.data.metadata.api.feign.fallback.MetadataSourceServiceFeignFallbackImpl;
|
||||
import feign.hystrix.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class MetadataSourceServiceFeignFallbackFactory implements FallbackFactory<MetadataSourceServiceFeign> {
|
||||
|
||||
@Override
|
||||
public MetadataSourceServiceFeign create(Throwable throwable) {
|
||||
MetadataSourceServiceFeignFallbackImpl metadataSourceServiceFeignFallback = new MetadataSourceServiceFeignFallbackImpl();
|
||||
metadataSourceServiceFeignFallback.setCause(throwable);
|
||||
return metadataSourceServiceFeignFallback;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package cn.datax.service.data.metadata.api.feign.fallback;
|
||||
|
||||
import cn.datax.service.data.metadata.api.entity.MetadataSourceEntity;
|
||||
import cn.datax.service.data.metadata.api.feign.MetadataSourceServiceFeign;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class MetadataSourceServiceFeignFallbackImpl implements MetadataSourceServiceFeign {
|
||||
|
||||
@Setter
|
||||
private Throwable cause;
|
||||
|
||||
@Override
|
||||
public MetadataSourceEntity getMetadataSourceById(String id) {
|
||||
log.error("feign 调用{}出错", id, cause);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MetadataSourceEntity> getMetadataSourceList() {
|
||||
log.error("feign 调用出错", cause);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package cn.datax.service.data.metadata.api.query;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据查询 查询实体
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-14
|
||||
*/
|
||||
@Data
|
||||
public class DbDataQuery implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@NotBlank(message = "数据源不能为空")
|
||||
private String dataSourceId;
|
||||
@NotBlank(message = "查询sql不能为空")
|
||||
private String sql;
|
||||
// 当前页码
|
||||
private Integer pageNum = 1;
|
||||
// 分页条数
|
||||
private Integer pageSize = 20;
|
||||
|
||||
public Integer getOffset() {
|
||||
pageSize = pageSize == null ? 20 : pageSize;
|
||||
pageNum = pageNum == null ? 1 : pageNum;
|
||||
int offset = pageNum > 0 ? (pageNum - 1) * pageSize : 0;
|
||||
return offset;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package cn.datax.service.data.metadata.api.query;
|
||||
|
||||
import cn.datax.common.base.BaseQueryParams;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据授权信息表 查询实体
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-23
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class MetadataAuthorizeQuery extends BaseQueryParams {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package cn.datax.service.data.metadata.api.query;
|
||||
|
||||
import cn.datax.common.base.BaseQueryParams;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 元数据变更记录表 查询实体
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-30
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class MetadataChangeRecordQuery extends BaseQueryParams {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
private String objectId;
|
||||
private String fieldName;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package cn.datax.service.data.metadata.api.query;
|
||||
|
||||
import cn.datax.common.base.BaseQueryParams;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 元数据信息表 查询实体
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-29
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class MetadataColumnQuery extends BaseQueryParams {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
private String sourceId;
|
||||
|
||||
private String tableId;
|
||||
|
||||
private String columnName;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package cn.datax.service.data.metadata.api.query;
|
||||
|
||||
import cn.datax.common.base.BaseQueryParams;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据源信息表 查询实体
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-14
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class MetadataSourceQuery extends BaseQueryParams {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
private String sourceName;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package cn.datax.service.data.metadata.api.query;
|
||||
|
||||
import cn.datax.common.base.BaseQueryParams;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据库表信息表 查询实体
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-29
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class MetadataTableQuery extends BaseQueryParams {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
private String sourceId;
|
||||
|
||||
private String tableName;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package cn.datax.service.data.metadata.api.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据授权信息表 实体VO
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-23
|
||||
*/
|
||||
@Data
|
||||
public class MetadataAuthorizeVo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
private String id;
|
||||
private String objectId;
|
||||
private String roleId;
|
||||
private String objectType;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package cn.datax.service.data.metadata.api.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 元数据变更记录表 实体VO
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-30
|
||||
*/
|
||||
@Data
|
||||
public class MetadataChangeRecordVo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
private String id;
|
||||
private String status;
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private LocalDateTime createTime;
|
||||
private Integer version;
|
||||
private String objectType;
|
||||
private String objectId;
|
||||
private String fieldName;
|
||||
private String fieldOldValue;
|
||||
private String fieldNewValue;
|
||||
private String sourceId;
|
||||
private String sourceName;
|
||||
private String tableId;
|
||||
private String tableName;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package cn.datax.service.data.metadata.api.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 元数据信息表 实体VO
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-29
|
||||
*/
|
||||
@Data
|
||||
public class MetadataColumnVo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
private String id;
|
||||
private String sourceId;
|
||||
private String tableId;
|
||||
private String columnName;
|
||||
private String columnComment;
|
||||
private String columnKey;
|
||||
private String columnNullable;
|
||||
private String columnPosition;
|
||||
private String dataType;
|
||||
private String dataLength;
|
||||
private String dataPrecision;
|
||||
private String dataScale;
|
||||
private String dataDefault;
|
||||
private String sourceName;
|
||||
private String tableName;
|
||||
private String tableComment;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package cn.datax.service.data.metadata.api.vo;
|
||||
|
||||
import cn.datax.service.data.metadata.api.dto.DbSchema;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据源信息表 实体VO
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-14
|
||||
*/
|
||||
@Data
|
||||
public class MetadataSourceVo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
private String id;
|
||||
private String status;
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private LocalDateTime createTime;
|
||||
private String remark;
|
||||
private String dbType;
|
||||
private String sourceName;
|
||||
private DbSchema dbSchema;
|
||||
private String isSync;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package cn.datax.service.data.metadata.api.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据库表信息表 实体VO
|
||||
* </p>
|
||||
*
|
||||
* @author AllDataDC
|
||||
* @date 2022-11-29
|
||||
*/
|
||||
@Data
|
||||
public class MetadataTableVo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
private String id;
|
||||
private String sourceId;
|
||||
private String tableName;
|
||||
private String tableComment;
|
||||
private String sourceName;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package cn.datax.service.data.metadata.api.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class MetadataTreeVo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
private String id;
|
||||
/**
|
||||
* 数据层级 database、table、column
|
||||
*/
|
||||
private String type;
|
||||
private String label;
|
||||
private String name;
|
||||
private String code;
|
||||
private List<MetadataTreeVo> children;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package cn.datax.service.data.metadata.api.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
public class SqlConsoleVo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
private String sql;
|
||||
private Long time;
|
||||
private Boolean success;
|
||||
private Integer count;
|
||||
private List<String> columnList;
|
||||
private List<Map<String, Object>> dataList;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
cn.datax.service.data.metadata.api.feign.factory.MetadataSourceServiceFeignFallbackFactory,\
|
||||
cn.datax.service.data.metadata.api.feign.fallback.MetadataSourceServiceFeignFallbackImpl
|
||||
@@ -0,0 +1,87 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>data-metadata-service-parent</artifactId>
|
||||
<groupId>com.platform</groupId>
|
||||
<version>0.4.x</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<version>0.4.x</version>
|
||||
<artifactId>data-metadata-service-console</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<!--web 模块-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>spring-boot-starter-tomcat</artifactId>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-undertow</artifactId>
|
||||
</dependency>
|
||||
<!--配置中心客户端 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-config</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mapstruct</groupId>
|
||||
<artifactId>mapstruct</artifactId>
|
||||
<version>${mapstruct.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mapstruct</groupId>
|
||||
<artifactId>mapstruct-processor</artifactId>
|
||||
<version>${mapstruct.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.platform</groupId>
|
||||
<artifactId>common-mybatis</artifactId>
|
||||
<version>0.4.x</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.platform</groupId>
|
||||
<artifactId>common-redis</artifactId>
|
||||
<version>0.4.x</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.platform</groupId>
|
||||
<artifactId>common-security</artifactId>
|
||||
<version>0.4.x</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.platform</groupId>
|
||||
<artifactId>common-database</artifactId>
|
||||
<version>0.4.x</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.platform</groupId>
|
||||
<artifactId>common-log</artifactId>
|
||||
<version>0.4.x</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.platform</groupId>
|
||||
<artifactId>data-metadata-service-api</artifactId>
|
||||
<version>0.4.x</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,16 @@
|
||||
package cn.datax.service.data.metadata.console;
|
||||
|
||||
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.metadata.api.feign"})
|
||||
@SpringBootApplication
|
||||
public class DataxConsoleApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(DataxConsoleApplication.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package cn.datax.service.data.metadata.console.concurrent;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* 多线程模板类
|
||||
*/
|
||||
@Slf4j
|
||||
public abstract class CallableTemplate<V> implements Callable<V> {
|
||||
|
||||
/**
|
||||
* 前置处理,子类可以Override该方法
|
||||
*/
|
||||
public void beforeProcess() {
|
||||
log.info("before process....");
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理业务逻辑的方法,需要子类去Override
|
||||
* @return
|
||||
*/
|
||||
public abstract V process();
|
||||
|
||||
/**
|
||||
* 后置处理,子类可以Override该方法
|
||||
*/
|
||||
public void afterProcess() {
|
||||
log.info("after process....");
|
||||
}
|
||||
|
||||
@Override
|
||||
public V call() {
|
||||
beforeProcess();
|
||||
V result = process();
|
||||
afterProcess();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
package cn.datax.service.data.metadata.console.concurrent;
|
||||
|
||||
import cn.datax.service.data.metadata.api.vo.SqlConsoleVo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
@Slf4j
|
||||
public class DateHander extends CallableTemplate<SqlConsoleVo> {
|
||||
|
||||
private CountDownLatch latch;
|
||||
|
||||
private Connection conn;
|
||||
|
||||
private String sql;
|
||||
|
||||
public DateHander(CountDownLatch latch, Connection conn, String sql) {
|
||||
this.latch = latch;
|
||||
this.conn = conn;
|
||||
this.sql = sql;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqlConsoleVo process() {
|
||||
log.info("执行sql:" + sql);
|
||||
long start = System.currentTimeMillis();
|
||||
Statement stmt = null;
|
||||
ResultSet rs = null;
|
||||
// 将查询数据存储到数据中
|
||||
List<Map<String, Object>> dataList = new ArrayList<>();
|
||||
// 存储列名的数组
|
||||
List<String> columnList = new LinkedList<>();
|
||||
// 新增、修改、删除受影响行数
|
||||
Integer updateCount = null;
|
||||
SqlConsoleVo sqlConsoleVo = new SqlConsoleVo();
|
||||
sqlConsoleVo.setSuccess(true);
|
||||
try {
|
||||
// 为了设置fetchSize,必须设置为false
|
||||
conn.setAutoCommit(false);
|
||||
stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
|
||||
stmt.setFetchSize(200);
|
||||
// 是否查询操作
|
||||
boolean execute = stmt.execute(sql);
|
||||
if (execute) {
|
||||
// 限制下最大数量
|
||||
stmt.setMaxRows(1000);
|
||||
rs = stmt.getResultSet();
|
||||
// 获取结果集的元数据信息
|
||||
ResultSetMetaData rsmd = rs.getMetaData();
|
||||
// 获取列字段的个数
|
||||
int colunmCount = rsmd.getColumnCount();
|
||||
for (int i = 1; i <= colunmCount; i++) {
|
||||
// 获取所有的字段名称
|
||||
columnList.add(rsmd.getColumnName(i));
|
||||
}
|
||||
while(rs.next()){
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
for (int i = 1; i <= colunmCount; i++) {
|
||||
// 获取列名
|
||||
String columnName = rsmd.getColumnName(i);
|
||||
Object val = null;
|
||||
switch (rsmd.getColumnType(i)) {
|
||||
case Types.ARRAY:
|
||||
val = rs.getArray(columnName);
|
||||
break;
|
||||
case Types.BIGINT:
|
||||
val = rs.getLong(columnName);
|
||||
break;
|
||||
case Types.BOOLEAN:
|
||||
case Types.BIT:
|
||||
val = rs.getBoolean(columnName);
|
||||
break;
|
||||
case Types.DOUBLE:
|
||||
val = rs.getDouble(columnName);
|
||||
break;
|
||||
case Types.FLOAT:
|
||||
case Types.REAL:
|
||||
val = rs.getFloat(columnName);
|
||||
break;
|
||||
case Types.INTEGER:
|
||||
val = rs.getInt(columnName);
|
||||
break;
|
||||
case Types.NVARCHAR:
|
||||
case Types.NCHAR:
|
||||
case Types.LONGNVARCHAR:
|
||||
val = rs.getNString(columnName);
|
||||
break;
|
||||
case Types.VARCHAR:
|
||||
case Types.CHAR:
|
||||
case Types.LONGVARCHAR:
|
||||
val = rs.getString(columnName);
|
||||
break;
|
||||
case Types.TINYINT:
|
||||
case Types.BINARY:
|
||||
case Types.VARBINARY:
|
||||
val = rs.getByte(columnName);
|
||||
break;
|
||||
case Types.SMALLINT:
|
||||
val = rs.getShort(columnName);
|
||||
break;
|
||||
case Types.DATE:
|
||||
val = rs.getDate(columnName);
|
||||
break;
|
||||
case Types.TIME:
|
||||
val = rs.getTime(columnName);
|
||||
break;
|
||||
case Types.TIMESTAMP:
|
||||
val = rs.getTimestamp(columnName);
|
||||
break;
|
||||
case Types.NUMERIC:
|
||||
case Types.DECIMAL:
|
||||
val = rs.getBigDecimal(columnName);
|
||||
break;
|
||||
case Types.BLOB:
|
||||
case Types.CLOB:
|
||||
case Types.LONGVARBINARY:
|
||||
case Types.DATALINK:
|
||||
case Types.REF:
|
||||
case Types.STRUCT:
|
||||
case Types.DISTINCT:
|
||||
case Types.JAVA_OBJECT:
|
||||
break;
|
||||
default:
|
||||
val = rs.getObject(columnName);
|
||||
break;
|
||||
}
|
||||
map.put(columnName, val);
|
||||
}
|
||||
dataList.add(map);
|
||||
}
|
||||
} else {
|
||||
// 执行新增、修改、删除受影响行数
|
||||
updateCount = stmt.getUpdateCount();
|
||||
}
|
||||
conn.commit();
|
||||
} catch (SQLException e) {
|
||||
sqlConsoleVo.setSuccess(false);
|
||||
if(conn != null){
|
||||
try {
|
||||
conn.rollback();
|
||||
} catch (SQLException e1) {
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
try {
|
||||
if(rs != null){
|
||||
rs.close();
|
||||
}
|
||||
if (stmt != null) {
|
||||
stmt.close();
|
||||
}
|
||||
if (conn != null) {
|
||||
conn.close();
|
||||
}
|
||||
} catch (SQLException e) {}
|
||||
}
|
||||
latch.countDown();
|
||||
long end = System.currentTimeMillis();
|
||||
log.info("线程查询数据用时:" + (end - start) + "ms");
|
||||
sqlConsoleVo.setSql(sql);
|
||||
sqlConsoleVo.setCount(updateCount);
|
||||
sqlConsoleVo.setColumnList(columnList);
|
||||
sqlConsoleVo.setDataList(dataList);
|
||||
sqlConsoleVo.setTime(end - start);
|
||||
return sqlConsoleVo;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package cn.datax.service.data.metadata.console.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,31 @@
|
||||
package cn.datax.service.data.metadata.console.config;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class StartedUpRunner implements ApplicationRunner {
|
||||
|
||||
private final ConfigurableApplicationContext context;
|
||||
private final Environment environment;
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
package cn.datax.service.data.metadata.console.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.console.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.console.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,11 @@
|
||||
package cn.datax.service.data.metadata.console.controller;
|
||||
|
||||
import cn.datax.common.base.BaseController;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/inner")
|
||||
public class InnerController extends BaseController {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package cn.datax.service.data.metadata.console.controller;
|
||||
|
||||
import cn.datax.common.base.BaseController;
|
||||
import cn.datax.common.core.R;
|
||||
import cn.datax.common.validate.ValidationGroups;
|
||||
import cn.datax.service.data.metadata.api.dto.SqlConsoleDto;
|
||||
import cn.datax.service.data.metadata.api.vo.SqlConsoleVo;
|
||||
import cn.datax.service.data.metadata.console.service.SqlConsoleService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/sql")
|
||||
public class SqlConsoleController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private SqlConsoleService sqlConsoleService;
|
||||
|
||||
@PostMapping("/run")
|
||||
public R sqlRun(@RequestBody @Validated SqlConsoleDto sqlConsoleDto){
|
||||
List<SqlConsoleVo> list = sqlConsoleService.sqlRun(sqlConsoleDto);
|
||||
return R.ok().setData(list);
|
||||
}
|
||||
|
||||
@PostMapping("/stop")
|
||||
public R sqlStop(@RequestBody @Validated({ValidationGroups.Other.class}) SqlConsoleDto sqlConsoleDto){
|
||||
sqlConsoleService.sqlStop(sqlConsoleDto);
|
||||
return R.ok();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package cn.datax.service.data.metadata.console.service;
|
||||
|
||||
import cn.datax.service.data.metadata.api.dto.SqlConsoleDto;
|
||||
import cn.datax.service.data.metadata.api.vo.SqlConsoleVo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SqlConsoleService {
|
||||
|
||||
List<SqlConsoleVo> sqlRun(SqlConsoleDto sqlConsoleDto);
|
||||
|
||||
void sqlStop(SqlConsoleDto sqlConsoleDto);
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
package cn.datax.service.data.metadata.console.service.impl;
|
||||
|
||||
import cn.datax.common.database.DataSourceFactory;
|
||||
import cn.datax.common.database.DbQuery;
|
||||
import cn.datax.common.database.constants.DbQueryProperty;
|
||||
import cn.datax.common.exception.DataException;
|
||||
import cn.datax.common.utils.ThrowableUtil;
|
||||
import cn.datax.service.data.metadata.api.dto.DbSchema;
|
||||
import cn.datax.service.data.metadata.api.dto.SqlConsoleDto;
|
||||
import cn.datax.service.data.metadata.api.entity.MetadataSourceEntity;
|
||||
import cn.datax.service.data.metadata.api.feign.MetadataSourceServiceFeign;
|
||||
import cn.datax.service.data.metadata.api.vo.SqlConsoleVo;
|
||||
import cn.datax.service.data.metadata.console.concurrent.CallableTemplate;
|
||||
import cn.datax.service.data.metadata.console.concurrent.DateHander;
|
||||
import cn.datax.service.data.metadata.console.service.SqlConsoleService;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.sf.jsqlparser.JSQLParserException;
|
||||
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
|
||||
import net.sf.jsqlparser.statement.Statement;
|
||||
import net.sf.jsqlparser.statement.Statements;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class SqlConsoleServiceImpl implements SqlConsoleService {
|
||||
|
||||
@Autowired
|
||||
private DataSourceFactory dataSourceFactory;
|
||||
|
||||
@Autowired
|
||||
private MetadataSourceServiceFeign metadataSourceServiceFeign;
|
||||
|
||||
private static Map<String, List<Connection>> connectionMap = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
public List<SqlConsoleVo> sqlRun(SqlConsoleDto sqlConsoleDto) {
|
||||
String sqlKey = sqlConsoleDto.getSqlKey();
|
||||
Statements stmts;
|
||||
try {
|
||||
stmts = CCJSqlParserUtil.parseStatements(sqlConsoleDto.getSqlText());
|
||||
} catch (JSQLParserException e) {
|
||||
log.error("全局异常信息ex={}, StackTrace={}", e.getMessage(), ThrowableUtil.getStackTrace(e));
|
||||
throw new DataException("SQL语法有问题,解析出错");
|
||||
}
|
||||
List<Statement> sqls = stmts.getStatements();
|
||||
if (CollUtil.isEmpty(sqls)) {
|
||||
throw new DataException("未解析到SQL语句");
|
||||
}
|
||||
MetadataSourceEntity dataSource = metadataSourceServiceFeign.getMetadataSourceById(sqlConsoleDto.getSourceId());
|
||||
if(dataSource == null){
|
||||
throw new DataException("SQL工作台查询数据源出错");
|
||||
}
|
||||
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);
|
||||
// 定义计数器
|
||||
final CountDownLatch latch = new CountDownLatch(sqls.size());
|
||||
// 定义固定长度的线程池
|
||||
ExecutorService executorService = Executors.newFixedThreadPool(sqls.size());
|
||||
// Callable用于产生结果
|
||||
List<CallableTemplate<SqlConsoleVo>> tasks = new ArrayList<>();
|
||||
List<Connection> conns = new ArrayList<>();
|
||||
for (int i = 0; i < sqls.size(); i++) {
|
||||
Connection conn = dbQuery.getConnection();
|
||||
conns.add(conn);
|
||||
DateHander dateHander = new DateHander(latch, conn, sqls.get(i).toString());
|
||||
tasks.add(dateHander);
|
||||
}
|
||||
connectionMap.put(sqlKey, conns);
|
||||
// Future用于获取结果
|
||||
List<SqlConsoleVo> result = new ArrayList<>();
|
||||
List<Future<SqlConsoleVo>> futures;
|
||||
try {
|
||||
futures = executorService.invokeAll(tasks);
|
||||
// 主线程阻塞,等待所有子线程执行完成
|
||||
latch.await();
|
||||
// 处理线程返回结果
|
||||
for (Future<SqlConsoleVo> future : futures) {
|
||||
result.add(future.get());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("全局异常信息ex={}, StackTrace={}", e.getMessage(), ThrowableUtil.getStackTrace(e));
|
||||
}
|
||||
// 关闭线程池
|
||||
executorService.shutdown();
|
||||
// 执行完清除
|
||||
connectionMap.remove(sqlKey);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sqlStop(SqlConsoleDto sqlConsoleDto) {
|
||||
String sqlKey = sqlConsoleDto.getSqlKey();
|
||||
List<Connection> conns = connectionMap.get(sqlKey);
|
||||
if (CollUtil.isNotEmpty(conns)) {
|
||||
for (int i = 0; i < conns.size(); i++) {
|
||||
Connection conn = conns.get(i);
|
||||
try {
|
||||
if (null != conn && !conn.isClosed()) {
|
||||
conn.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new DataException("SQL工作台停止出错");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
server:
|
||||
port: 8821
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: service-data-console
|
||||
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
|
||||
@@ -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-console"/>
|
||||
<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,25 @@
|
||||
module.log=com.p6spy.engine.logging.P6LogFactory,com.p6spy.engine.outage.P6OutageFactory
|
||||
# <20>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>־<EFBFBD><D6BE>ӡ
|
||||
logMessageFormat=com.baomidou.mybatisplus.extension.p6spy.P6SpyLogger
|
||||
#<23><>־<EFBFBD><D6BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̨
|
||||
appender=com.baomidou.mybatisplus.extension.p6spy.StdoutLogger
|
||||
# ʹ<><CAB9><EFBFBD><EFBFBD>־ϵͳ<CFB5><CDB3>¼ sql
|
||||
#appender=com.p6spy.engine.spy.appender.Slf4JLogger
|
||||
# <20><><EFBFBD><EFBFBD> p6spy driver <20><><EFBFBD><EFBFBD>
|
||||
deregisterdrivers=true
|
||||
# ȡ<><C8A1>JDBC URLǰ
|
||||
useprefix=true
|
||||
# <20><><EFBFBD>ü<EFBFBD>¼ Log <20><><EFBFBD><EFBFBD>,<2C><>ȥ<EFBFBD><C8A5><EFBFBD>Ľ<EFBFBD><C4BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>error,info,batch,debug,statement,commit,rollback,result,resultset.
|
||||
excludecategories=info,debug,result,batch,resultset
|
||||
# <20><><EFBFBD>ڸ<EFBFBD>ʽ
|
||||
dateformat=yyyy-MM-dd HH:mm:ss
|
||||
# ʵ<><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɶ<EFBFBD><C9B6><EFBFBD>
|
||||
#driverlist=org.h2.Driver
|
||||
# <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>SQL<51><4C>¼
|
||||
outagedetection=true
|
||||
# <20><>SQL<51><4C>¼<EFBFBD><C2BC> 2 <20><>
|
||||
outagedetectioninterval=2
|
||||
# <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
filter=true
|
||||
# <20><><EFBFBD>ò<EFBFBD><C3B2><EFBFBD>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
exclude=select 1
|
||||
Binary file not shown.
@@ -0,0 +1,168 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>data-metadata-service-parent</artifactId>
|
||||
<groupId>com.platform</groupId>
|
||||
<version>0.4.x</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<version>0.4.x</version>
|
||||
<artifactId>data-metadata-service</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<!--web 模块-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>spring-boot-starter-tomcat</artifactId>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-undertow</artifactId>
|
||||
</dependency>
|
||||
<!--配置中心客户端 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-config</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mapstruct</groupId>
|
||||
<artifactId>mapstruct</artifactId>
|
||||
<version>${mapstruct.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mapstruct</groupId>
|
||||
<artifactId>mapstruct-processor</artifactId>
|
||||
<version>${mapstruct.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.platform</groupId>
|
||||
<artifactId>common-mybatis</artifactId>
|
||||
<version>0.4.x</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.platform</groupId>
|
||||
<artifactId>common-office</artifactId>
|
||||
<version>0.4.x</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.platform</groupId>
|
||||
<artifactId>common-redis</artifactId>
|
||||
<version>0.4.x</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.platform</groupId>
|
||||
<artifactId>common-database</artifactId>
|
||||
<version>0.4.x</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.platform</groupId>
|
||||
<artifactId>common-log</artifactId>
|
||||
<version>0.4.x</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.platform</groupId>
|
||||
<artifactId>common-security</artifactId>
|
||||
<version>0.4.x</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.platform</groupId>
|
||||
<artifactId>data-metadata-service-api</artifactId>
|
||||
<version>0.4.x</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.platform</groupId>
|
||||
<artifactId>data-standard-service-api</artifactId>
|
||||
<version>0.4.x</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.platform</groupId>
|
||||
<artifactId>data-quality-service-api</artifactId>
|
||||
<version>0.4.x</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.platform</groupId>
|
||||
<artifactId>data-visual-service-api</artifactId>
|
||||
<version>0.4.x</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.platform</groupId>
|
||||
<artifactId>data-market-service-api</artifactId>
|
||||
<version>0.4.x</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.easyproject</groupId>
|
||||
<artifactId>orai18n</artifactId>
|
||||
<version>${orai18n.version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<!-- jwt -->
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt-api</artifactId>
|
||||
<version>${jjwt.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt-impl</artifactId>
|
||||
<version>${jjwt.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt-jackson</artifactId>
|
||||
<version>${jjwt.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aspose</groupId>
|
||||
<artifactId>aspose-words</artifactId>
|
||||
<version>20.3.1</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/lib/aspose-words-20.3.1.jar</systemPath>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/java</directory>
|
||||
<includes>
|
||||
<include>**/*.xml</include>
|
||||
</includes>
|
||||
<filtering>false</filtering>
|
||||
</resource>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<includes>
|
||||
<include>**/*.*</include>
|
||||
</includes>
|
||||
<filtering>false</filtering>
|
||||
</resource>
|
||||
<resource>
|
||||
<directory>../data-metadata-service/lib</directory>
|
||||
<targetPath>BOOT-INF/lib/</targetPath>
|
||||
<includes>
|
||||
<include>**/*.jar</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user