add
This commit is contained in:
34
qiaoba-modules/qiaoba-module-generator/pom.xml
Normal file
34
qiaoba-modules/qiaoba-module-generator/pom.xml
Normal file
@ -0,0 +1,34 @@
|
||||
<?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>qiaoba-modules</artifactId>
|
||||
<groupId>com.qiaoba</groupId>
|
||||
<version>1.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>qiaoba-module-generator</artifactId>
|
||||
|
||||
<description> 代码生成 </description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.qiaoba</groupId>
|
||||
<artifactId>qiaoba-common-base</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.qiaoba</groupId>
|
||||
<artifactId>qiaoba-common-datasource</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.qiaoba</groupId>
|
||||
<artifactId>qiaoba-common-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.velocity</groupId>
|
||||
<artifactId>velocity-engine-core</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -0,0 +1,20 @@
|
||||
package com.qiaoba.module.generator.controller;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 代码生成 Web层
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023/6/26 9:09
|
||||
*/
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/tool/gen")
|
||||
public class GenController {
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package com.qiaoba.module.generator.entity.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 数据库表信息
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023/6/26 9:21
|
||||
*/
|
||||
@Data
|
||||
public class TableDto implements Serializable {
|
||||
|
||||
/**
|
||||
* 表名称
|
||||
*/
|
||||
private String tableName;
|
||||
|
||||
/**
|
||||
* 表描述
|
||||
*/
|
||||
private String tableComment;
|
||||
|
||||
/**
|
||||
* 数据库类型 Mysql/Oracle/PgSql/Sql Server
|
||||
*/
|
||||
private String dbType;
|
||||
|
||||
/**
|
||||
* 模式
|
||||
*/
|
||||
private String schema;
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package com.qiaoba.module.generator.entity.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 数据库表信息
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023/6/26 9:21
|
||||
*/
|
||||
@Data
|
||||
public class DbTableVo implements Serializable {
|
||||
|
||||
/**
|
||||
* 表名称
|
||||
*/
|
||||
private String tableName;
|
||||
|
||||
/**
|
||||
* 表描述
|
||||
*/
|
||||
private String tableComment;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package com.qiaoba.module.generator.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.qiaoba.module.generator.entity.dto.TableDto;
|
||||
import com.qiaoba.module.generator.entity.vo.DbTableVo;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* 数据库表 数据层
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023/6/26 9:24
|
||||
*/
|
||||
public interface TableMapper {
|
||||
|
||||
/**
|
||||
* 查询数据库表
|
||||
*
|
||||
* @param page 分页
|
||||
* @param dto 查询参数
|
||||
* @return list
|
||||
*/
|
||||
Page<DbTableVo> selectPageDbTableList(Page page, @Param("dto") TableDto dto);
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package com.qiaoba.module.generator.service;
|
||||
|
||||
import com.qiaoba.common.database.entity.PageQuery;
|
||||
import com.qiaoba.common.database.entity.TableDataInfo;
|
||||
import com.qiaoba.module.generator.entity.dto.TableDto;
|
||||
import com.qiaoba.module.generator.entity.vo.DbTableVo;
|
||||
|
||||
/**
|
||||
* 数据库表 服务层
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023/6/26 9:24
|
||||
*/
|
||||
public interface TableService {
|
||||
|
||||
/**
|
||||
* 分页查询数据库表
|
||||
*
|
||||
* @param dto 查询条件
|
||||
* @param pageQuery 分页信息
|
||||
* @return list
|
||||
*/
|
||||
TableDataInfo<DbTableVo> selectPageDbTableList(TableDto dto, PageQuery pageQuery);
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package com.qiaoba.module.generator.service.impl;
|
||||
|
||||
import com.qiaoba.common.base.context.BaseContext;
|
||||
import com.qiaoba.common.base.enums.DataBaseEnum;
|
||||
import com.qiaoba.common.database.config.DynamicDataSourceConfig;
|
||||
import com.qiaoba.common.database.entity.PageQuery;
|
||||
import com.qiaoba.common.database.entity.TableDataInfo;
|
||||
import com.qiaoba.module.generator.entity.dto.TableDto;
|
||||
import com.qiaoba.module.generator.entity.vo.DbTableVo;
|
||||
import com.qiaoba.module.generator.mapper.TableMapper;
|
||||
import com.qiaoba.module.generator.service.TableService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 数据库表 服务层实现
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023/6/26 10:12
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class TableServiceImpl implements TableService {
|
||||
|
||||
private final TableMapper tableMapper;
|
||||
|
||||
@Override
|
||||
public TableDataInfo<DbTableVo> selectPageDbTableList(TableDto dto, PageQuery pageQuery) {
|
||||
String dbType = DynamicDataSourceConfig.TENANT_DATASOURCE_TYPE_MAP.get(BaseContext.getTenantId());
|
||||
dto.setDbType(dbType);
|
||||
dto.setSchema(selectSchema());
|
||||
return TableDataInfo.build(tableMapper.selectPageDbTableList(pageQuery.build(), dto));
|
||||
}
|
||||
|
||||
private String selectSchema() {
|
||||
// PgSQL 需要设置 schema
|
||||
//DataBaseEnum.POSTGRE_SQL.getType().equals(dbType)
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.qiaoba.module.generator.mapper.TableMapper">
|
||||
|
||||
<resultMap type="com.qiaoba.module.generator.entity.vo.DbTableVo" id="DbTableVoResult">
|
||||
<result property="tableName" column="table_name"/>
|
||||
<result property="tableComment" column="table_comment"/>
|
||||
<result property="createTime" column="create_time"/>
|
||||
<result property="updateTime" column="update_time"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="selectPageDbTableList" resultMap="DbTableVoResult">
|
||||
<if test="dto.dbType=='MySQL'.toString()">
|
||||
select table_name, table_comment, create_time, update_time from information_schema.tables
|
||||
where table_schema = (select database())
|
||||
AND table_name NOT LIKE 'qrtz_%' AND table_name NOT LIKE 'gen_%'
|
||||
AND table_name NOT IN (select table_name from gen_table)
|
||||
<if test="dto.tableName != null and dto.tableName != ''">
|
||||
AND lower(table_name) like lower(concat('%', #{dto.tableName}, '%'))
|
||||
</if>
|
||||
<if test="dto.tableComment != null and dto.tableComment != ''">
|
||||
AND lower(table_comment) like lower(concat('%', #{dto.tableComment}, '%'))
|
||||
</if>
|
||||
order by create_time desc
|
||||
</if>
|
||||
|
||||
<if test="dto.dbType=='Oracle'.toString()">
|
||||
select lower(dt.table_name) as table_name, dtc.comments as table_comment, uo.created as create_time, uo.last_ddl_time as update_time
|
||||
from user_tables dt, user_tab_comments dtc, user_objects uo
|
||||
where dt.table_name = dtc.table_name
|
||||
and dt.table_name = uo.object_name
|
||||
and uo.object_type = 'TABLE'
|
||||
AND dt.table_name NOT LIKE 'XXL_JOB_%' AND dt.table_name NOT LIKE 'GEN_%'
|
||||
AND dt.table_name NOT IN (select table_name from gen_table)
|
||||
<if test="dto.tableName != null and dto.tableName != ''">
|
||||
AND lower(dt.table_name) like lower(concat(concat('%', #{dto.tableName}), '%'))
|
||||
</if>
|
||||
<if test="dto.tableComment != null and dto.tableComment != ''">
|
||||
AND lower(dtc.comments) like lower(concat(concat('%', #{dto.tableComment}), '%'))
|
||||
</if>
|
||||
order by create_time desc
|
||||
</if>
|
||||
|
||||
<if test="dto.dbType=='PostgreSQL'.toString()">
|
||||
select table_name, table_comment, create_time, update_time
|
||||
from (
|
||||
SELECT c.relname AS table_name,
|
||||
obj_description(c.oid) AS table_comment,
|
||||
CURRENT_TIMESTAMP AS create_time,
|
||||
CURRENT_TIMESTAMP AS update_time
|
||||
FROM pg_class c
|
||||
LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
|
||||
WHERE (c.relkind = ANY (ARRAY ['r'::"char", 'p'::"char"]))
|
||||
AND c.relname != 'spatial_%'::text
|
||||
AND n.nspname = #{dto.schema}::name
|
||||
AND n.nspname <![CDATA[ <> ]]> ''::name
|
||||
) list_table
|
||||
where table_name NOT LIKE 'xxl_job_%' AND table_name NOT LIKE 'gen_%'
|
||||
AND table_name NOT IN (select table_name from gen_table)
|
||||
<if test="dto.tableName != null and dto.tableName != ''">
|
||||
AND lower(table_name) like lower(concat('%', #{dto.tableName}, '%'))
|
||||
</if>
|
||||
<if test="dto.tableComment != null and dto.tableComment != ''">
|
||||
AND lower(table_comment) like lower(concat('%', #{dto.tableComment}, '%'))
|
||||
</if>
|
||||
order by create_time desc
|
||||
</if>
|
||||
</select>
|
||||
</mapper>
|
Reference in New Issue
Block a user