表数据导出优化,增加表关系图功能
This commit is contained in:
@@ -0,0 +1,170 @@
|
||||
package com.zyplayer.doc.data.repository.manage.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import java.util.Date;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 表关系
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2021-06-07
|
||||
*/
|
||||
public class DbTableRelation implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键自增ID
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 数据源ID
|
||||
*/
|
||||
private Long datasourceId;
|
||||
|
||||
/**
|
||||
* 源库名
|
||||
*/
|
||||
private String startDbName;
|
||||
|
||||
/**
|
||||
* 源表名
|
||||
*/
|
||||
private String startTableName;
|
||||
|
||||
/**
|
||||
* 源字段名
|
||||
*/
|
||||
private String startColumnName;
|
||||
|
||||
/**
|
||||
* 目标库名
|
||||
*/
|
||||
private String endDbName;
|
||||
|
||||
/**
|
||||
* 目标表名
|
||||
*/
|
||||
private String endTableName;
|
||||
|
||||
/**
|
||||
* 目标字段名
|
||||
*/
|
||||
private String endColumnName;
|
||||
|
||||
/**
|
||||
* 创建人ID
|
||||
*/
|
||||
private Long createUserId;
|
||||
|
||||
/**
|
||||
* 创建人名字
|
||||
*/
|
||||
private String createUserName;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
public Long getDatasourceId() {
|
||||
return datasourceId;
|
||||
}
|
||||
|
||||
public void setDatasourceId(Long datasourceId) {
|
||||
this.datasourceId = datasourceId;
|
||||
}
|
||||
public String getStartDbName() {
|
||||
return startDbName;
|
||||
}
|
||||
|
||||
public void setStartDbName(String startDbName) {
|
||||
this.startDbName = startDbName;
|
||||
}
|
||||
public String getStartTableName() {
|
||||
return startTableName;
|
||||
}
|
||||
|
||||
public void setStartTableName(String startTableName) {
|
||||
this.startTableName = startTableName;
|
||||
}
|
||||
public String getStartColumnName() {
|
||||
return startColumnName;
|
||||
}
|
||||
|
||||
public void setStartColumnName(String startColumnName) {
|
||||
this.startColumnName = startColumnName;
|
||||
}
|
||||
public String getEndDbName() {
|
||||
return endDbName;
|
||||
}
|
||||
|
||||
public void setEndDbName(String endDbName) {
|
||||
this.endDbName = endDbName;
|
||||
}
|
||||
public String getEndTableName() {
|
||||
return endTableName;
|
||||
}
|
||||
|
||||
public void setEndTableName(String endTableName) {
|
||||
this.endTableName = endTableName;
|
||||
}
|
||||
public String getEndColumnName() {
|
||||
return endColumnName;
|
||||
}
|
||||
|
||||
public void setEndColumnName(String endColumnName) {
|
||||
this.endColumnName = endColumnName;
|
||||
}
|
||||
public Long getCreateUserId() {
|
||||
return createUserId;
|
||||
}
|
||||
|
||||
public void setCreateUserId(Long createUserId) {
|
||||
this.createUserId = createUserId;
|
||||
}
|
||||
public String getCreateUserName() {
|
||||
return createUserName;
|
||||
}
|
||||
|
||||
public void setCreateUserName(String createUserName) {
|
||||
this.createUserName = createUserName;
|
||||
}
|
||||
public Date getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(Date createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DbTableRelation{" +
|
||||
"id=" + id +
|
||||
", datasourceId=" + datasourceId +
|
||||
", startDbName=" + startDbName +
|
||||
", startTableName=" + startTableName +
|
||||
", startColumnName=" + startColumnName +
|
||||
", endDbName=" + endDbName +
|
||||
", endTableName=" + endTableName +
|
||||
", endColumnName=" + endColumnName +
|
||||
", createUserId=" + createUserId +
|
||||
", createUserName=" + createUserName +
|
||||
", createTime=" + createTime +
|
||||
"}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.zyplayer.doc.data.repository.manage.mapper;
|
||||
|
||||
import com.zyplayer.doc.data.repository.manage.entity.DbTableRelation;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 表关系 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2021-06-07
|
||||
*/
|
||||
public interface DbTableRelationMapper extends BaseMapper<DbTableRelation> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.zyplayer.doc.data.repository.manage.param;
|
||||
|
||||
/**
|
||||
* 表关系请求参数
|
||||
* @author 暮光:城中城
|
||||
* @since 2021-06-07
|
||||
*/
|
||||
public class TableRelationParam {
|
||||
private Long sourceId;
|
||||
private String dbName;
|
||||
private String tableName;
|
||||
private String columnName;
|
||||
// 关系JSON,大概是:[{dbName: 'xxx', tableName: 'xxx', columnName: 'xxx'}]
|
||||
private String relation;
|
||||
|
||||
public Long getSourceId() {
|
||||
return sourceId;
|
||||
}
|
||||
|
||||
public void setSourceId(Long sourceId) {
|
||||
this.sourceId = sourceId;
|
||||
}
|
||||
|
||||
public String getDbName() {
|
||||
return dbName;
|
||||
}
|
||||
|
||||
public void setDbName(String dbName) {
|
||||
this.dbName = dbName;
|
||||
}
|
||||
|
||||
public String getTableName() {
|
||||
return tableName;
|
||||
}
|
||||
|
||||
public void setTableName(String tableName) {
|
||||
this.tableName = tableName;
|
||||
}
|
||||
|
||||
public String getRelation() {
|
||||
return relation;
|
||||
}
|
||||
|
||||
public void setRelation(String relation) {
|
||||
this.relation = relation;
|
||||
}
|
||||
|
||||
public String getColumnName() {
|
||||
return columnName;
|
||||
}
|
||||
|
||||
public void setColumnName(String columnName) {
|
||||
this.columnName = columnName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.zyplayer.doc.data.repository.manage.vo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 表关系结构
|
||||
* @author 暮光:城中城
|
||||
* @since 2021-06-07
|
||||
*/
|
||||
public class TableRelationVo {
|
||||
private String dbName;
|
||||
private String tableName;
|
||||
// name和columnName是一个,name给前端使用的
|
||||
private String name;
|
||||
private String columnName;
|
||||
private Integer nodeType;
|
||||
private List<TableRelationVo> children;
|
||||
|
||||
public String getDbName() {
|
||||
return dbName;
|
||||
}
|
||||
|
||||
public void setDbName(String dbName) {
|
||||
this.dbName = dbName;
|
||||
}
|
||||
|
||||
public String getTableName() {
|
||||
return tableName;
|
||||
}
|
||||
|
||||
public void setTableName(String tableName) {
|
||||
this.tableName = tableName;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getColumnName() {
|
||||
return columnName;
|
||||
}
|
||||
|
||||
public void setColumnName(String columnName) {
|
||||
this.columnName = columnName;
|
||||
}
|
||||
|
||||
public List<TableRelationVo> getChildren() {
|
||||
return children;
|
||||
}
|
||||
|
||||
public void setChildren(List<TableRelationVo> children) {
|
||||
this.children = children;
|
||||
}
|
||||
|
||||
public Integer getNodeType() {
|
||||
return nodeType;
|
||||
}
|
||||
|
||||
public void setNodeType(Integer nodeType) {
|
||||
this.nodeType = nodeType;
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ public class CodeGenerator {
|
||||
// final String[] tableName = { "zyplayer_storage", "auth_info", "user_auth", "user_info", "db_datasource" };
|
||||
// final String[] tableName = { "wiki_space", "wiki_page", "wiki_page_content", "wiki_page_file", "wiki_page_comment", "wiki_page_zan" };
|
||||
// final String[] tableName = { "db_datasource", "es_datasource", "db_favorite" };
|
||||
final String[] tableName = {"db_proc_log"};
|
||||
final String[] tableName = {"db_table_relation"};
|
||||
|
||||
// 代码生成器
|
||||
AutoGenerator mpg = new AutoGenerator();
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.zyplayer.doc.data.service.manage;
|
||||
|
||||
import com.zyplayer.doc.data.repository.manage.entity.DbTableRelation;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.zyplayer.doc.data.repository.manage.param.TableRelationParam;
|
||||
import com.zyplayer.doc.data.repository.manage.vo.TableRelationVo;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 表关系 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2021-06-07
|
||||
*/
|
||||
public interface DbTableRelationService extends IService<DbTableRelation> {
|
||||
|
||||
void update(TableRelationParam param);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package com.zyplayer.doc.data.service.manage.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.sun.jersey.server.impl.wadl.WadlResource;
|
||||
import com.zyplayer.doc.data.config.security.DocUserDetails;
|
||||
import com.zyplayer.doc.data.config.security.DocUserUtil;
|
||||
import com.zyplayer.doc.data.repository.manage.entity.DbTableRelation;
|
||||
import com.zyplayer.doc.data.repository.manage.mapper.DbTableRelationMapper;
|
||||
import com.zyplayer.doc.data.repository.manage.param.TableRelationParam;
|
||||
import com.zyplayer.doc.data.repository.manage.vo.TableRelationVo;
|
||||
import com.zyplayer.doc.data.service.manage.DbTableRelationService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 表关系 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2021-06-07
|
||||
*/
|
||||
@Service
|
||||
public class DbTableRelationServiceImpl extends ServiceImpl<DbTableRelationMapper, DbTableRelation> implements DbTableRelationService {
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void update(TableRelationParam param) {
|
||||
UpdateWrapper<DbTableRelation> removeWrapper = new UpdateWrapper<>();
|
||||
removeWrapper.eq("datasource_id", param.getSourceId());
|
||||
removeWrapper.and(wrapper -> wrapper.or(or -> or.eq("start_db_name", param.getDbName())
|
||||
.eq("start_table_name", param.getTableName())
|
||||
.eq("start_column_name", param.getColumnName())
|
||||
).or(or -> or.eq("end_db_name", param.getDbName())
|
||||
.eq("end_table_name", param.getTableName())
|
||||
.eq("end_column_name", param.getColumnName())
|
||||
));
|
||||
this.remove(removeWrapper);
|
||||
if(StringUtils.isEmpty(param.getRelation())) {
|
||||
return;
|
||||
}
|
||||
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
||||
List<TableRelationParam> tableRelationList = JSON.parseArray(param.getRelation(), TableRelationParam.class);
|
||||
for (TableRelationParam relation : tableRelationList) {
|
||||
if (StringUtils.isBlank(relation.getDbName())
|
||||
|| StringUtils.isBlank(relation.getTableName())
|
||||
|| StringUtils.isBlank(relation.getColumnName())) {
|
||||
continue;
|
||||
}
|
||||
DbTableRelation tableRelation = new DbTableRelation();
|
||||
tableRelation.setDatasourceId(param.getSourceId());
|
||||
tableRelation.setStartDbName(param.getDbName());
|
||||
tableRelation.setStartTableName(param.getTableName());
|
||||
tableRelation.setStartColumnName(param.getColumnName());
|
||||
tableRelation.setEndDbName(relation.getDbName());
|
||||
tableRelation.setEndTableName(relation.getTableName());
|
||||
tableRelation.setEndColumnName(relation.getColumnName());
|
||||
tableRelation.setCreateTime(new Date());
|
||||
tableRelation.setCreateUserId(currentUser.getUserId());
|
||||
tableRelation.setCreateUserName(currentUser.getUsername());
|
||||
this.save(tableRelation);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user