开始开发代码生成器,完成数据库 information_schema 的读取
parent
753c7678ee
commit
67c3a62dcf
@ -0,0 +1,21 @@
|
|||||||
|
package cn.iocoder.dashboard.modules.tool.controller.codegen;
|
||||||
|
|
||||||
|
import cn.iocoder.dashboard.common.pojo.CommonResult;
|
||||||
|
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||||
|
import cn.iocoder.dashboard.modules.tool.controller.codegen.vo.ToolCodeGenTablePageItemRespVO;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import static cn.iocoder.dashboard.common.pojo.CommonResult.success;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/tool/code-gen")
|
||||||
|
public class ToolCodeGenController {
|
||||||
|
|
||||||
|
@GetMapping("/table/page")
|
||||||
|
public CommonResult<PageResult<ToolCodeGenTablePageItemRespVO>> getCodeGenTablePage() {
|
||||||
|
return success(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
package cn.iocoder.dashboard.modules.tool.controller.codegen.vo;
|
||||||
|
|
||||||
|
public class ToolCodeGenTableBaseRespVO {
|
||||||
|
}
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
package cn.iocoder.dashboard.modules.tool.controller.codegen.vo;
|
||||||
|
|
||||||
|
public class ToolCodeGenTablePageItemRespVO extends ToolCodeGenTableBaseRespVO {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
package cn.iocoder.dashboard.modules.tool.controller.codegen.vo;
|
||||||
@ -0,0 +1 @@
|
|||||||
|
package cn.iocoder.dashboard.modules.tool.controller;
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
package cn.iocoder.dashboard.modules.tool.dal.mysql.dao.coegen;
|
||||||
|
|
||||||
|
import cn.iocoder.dashboard.framework.mybatis.core.mapper.BaseMapperX;
|
||||||
|
import cn.iocoder.dashboard.modules.tool.dal.mysql.dataobject.codegen.ToolInformationSchemaColumnDO;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface ToolInformationSchemaColumnMapper extends BaseMapperX<ToolInformationSchemaColumnDO> {
|
||||||
|
|
||||||
|
default List<ToolInformationSchemaColumnDO> selectListByTableName(String tableName) {
|
||||||
|
return selectList(new QueryWrapper<ToolInformationSchemaColumnDO>().eq("table_name", tableName)
|
||||||
|
.orderByAsc("ordinal_position"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
package cn.iocoder.dashboard.modules.tool.dal.mysql.dao.coegen;
|
||||||
|
|
||||||
|
import cn.iocoder.dashboard.framework.mybatis.core.mapper.BaseMapperX;
|
||||||
|
import cn.iocoder.dashboard.modules.tool.dal.mysql.dataobject.codegen.ToolInformationSchemaTableDO;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface ToolInformationSchemaTableMapper extends BaseMapperX<ToolInformationSchemaTableDO> {
|
||||||
|
|
||||||
|
default List<ToolInformationSchemaTableDO> selectListByTableSchema(String tableSchema) {
|
||||||
|
return selectList(new QueryWrapper<ToolInformationSchemaTableDO>().eq("table_schema", tableSchema));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
package cn.iocoder.dashboard.modules.tool.dal.mysql.dao;
|
||||||
@ -0,0 +1,22 @@
|
|||||||
|
package cn.iocoder.dashboard.modules.tool.dal.mysql.dataobject.codegen;
|
||||||
|
|
||||||
|
import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代码生成 column 字段定义
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
@TableName(value = "tool_codegen_table_column", autoResultMap = true)
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public class ToolCodegenColumnDO extends BaseDO {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,45 @@
|
|||||||
|
package cn.iocoder.dashboard.modules.tool.dal.mysql.dataobject.codegen;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MySQL 数据库中的 column 字段定义
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
@TableName(value = "information_schema.columns", autoResultMap = true)
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
public class ToolInformationSchemaColumnDO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 表名称
|
||||||
|
*/
|
||||||
|
private String tableName;
|
||||||
|
/**
|
||||||
|
* 字段名
|
||||||
|
*/
|
||||||
|
private String columnName;
|
||||||
|
/**
|
||||||
|
* 字段类型
|
||||||
|
*/
|
||||||
|
private String columnType;
|
||||||
|
/**
|
||||||
|
* 是否允许为空
|
||||||
|
*/
|
||||||
|
@TableField("case when is_nullable = 'yes' then '1' else '0' end")
|
||||||
|
private Boolean nullable;
|
||||||
|
/**
|
||||||
|
* 是否主键
|
||||||
|
*/
|
||||||
|
@TableField("case when column_key = 'PRI' then '1' else '0' end")
|
||||||
|
private Boolean primaryKey;
|
||||||
|
/**
|
||||||
|
* 排序字段
|
||||||
|
*/
|
||||||
|
private Integer ordinalPosition;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,36 @@
|
|||||||
|
package cn.iocoder.dashboard.modules.tool.dal.mysql.dataobject.codegen;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MySQL 数据库中的 table 表定义
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
@TableName(value = "information_schema.tables", autoResultMap = true)
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
public class ToolInformationSchemaTableDO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据库
|
||||||
|
*/
|
||||||
|
private String tableSchema;
|
||||||
|
/**
|
||||||
|
* 表名称
|
||||||
|
*/
|
||||||
|
private String tableName;
|
||||||
|
/**
|
||||||
|
* 表描述
|
||||||
|
*/
|
||||||
|
private String tableComment;
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
package cn.iocoder.dashboard.modules.tool.dal.mysql.dataobject;
|
||||||
@ -0,0 +1,25 @@
|
|||||||
|
package cn.iocoder.dashboard.modules.tool.enums.codegen;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代码生成模板类型
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Getter
|
||||||
|
public enum ToolCodeGenTemplateTypeEnum {
|
||||||
|
|
||||||
|
CRUD(1), // 基础 CRUD
|
||||||
|
TREE(2), // 树形 CRUD
|
||||||
|
SUB(3) // 子表 CRUD
|
||||||
|
;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类型
|
||||||
|
*/
|
||||||
|
private final Integer type;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
package cn.iocoder.dashboard.modules.tool.enums;
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
package cn.iocoder.dashboard;
|
||||||
|
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
public class TestApplication {
|
||||||
|
}
|
||||||
@ -0,0 +1,27 @@
|
|||||||
|
package cn.iocoder.dashboard.modules.tool.dal.mysql.dao.coegen;
|
||||||
|
|
||||||
|
import cn.iocoder.dashboard.TestApplication;
|
||||||
|
import cn.iocoder.dashboard.modules.tool.dal.mysql.dataobject.codegen.ToolInformationSchemaColumnDO;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
|
||||||
|
@SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||||
|
public class ToolInformationSchemaColumnMapperTest {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ToolInformationSchemaColumnMapper toolInformationSchemaColumnMapper;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSelectListByTableName() {
|
||||||
|
List<ToolInformationSchemaColumnDO> columns = toolInformationSchemaColumnMapper
|
||||||
|
.selectListByTableName("inf_config");
|
||||||
|
assertTrue(columns.size() > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,26 @@
|
|||||||
|
package cn.iocoder.dashboard.modules.tool.dal.mysql.dao.coegen;
|
||||||
|
|
||||||
|
import cn.iocoder.dashboard.TestApplication;
|
||||||
|
import cn.iocoder.dashboard.modules.tool.dal.mysql.dataobject.codegen.ToolInformationSchemaTableDO;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
@SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||||
|
class ToolInformationSchemaTableMapperTest {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ToolInformationSchemaTableMapper toolInformationSchemaTableMapper;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void tstSelectListByTableSchema() {
|
||||||
|
List<ToolInformationSchemaTableDO> tables = toolInformationSchemaTableMapper
|
||||||
|
.selectListByTableSchema("ruoyi-vue-pro");
|
||||||
|
assertTrue(tables.size() > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue