mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-13 14:09:00 +08:00
✨ Introducing new features. #2151 【代码生成】 支持ORACEL / SQL SERVER /PG 等其他数据源类型代码生成
This commit is contained in:
1 parent
193a1f478b
commit
e69a50c5ee
34 files changed
+826
-193
No files matched your search
@@ -1,37 +1,59 @@
|
||||
#\u4EE3\u7801\u751F\u6210\u5668\uFF0C\u914D\u7F6E\u4FE1\u606F
|
||||
|
||||
mainPath=com.pig4cloud.pigx
|
||||
#\u5305\u540D
|
||||
package=com.pig4cloud.pigx
|
||||
moduleName=generator
|
||||
#\u4F5C\u8005
|
||||
author=pigx code generator
|
||||
|
||||
#\u8868\u524D\u7F00(\u7C7B\u540D\u4E0D\u4F1A\u5305\u542B\u8868\u524D\u7F00)
|
||||
tablePrefix=tb_
|
||||
# hidden columns in Swagger Models
|
||||
hiddenColumn=tenant_id
|
||||
|
||||
#\u7C7B\u578B\u8F6C\u6362\uFF0C\u914D\u7F6E\u4FE1\u606F
|
||||
#MYSQL \u7C7B\u578B\u8F6C\u6362
|
||||
tinyint=Integer
|
||||
smallint=Integer
|
||||
mediumint=Integer
|
||||
int=Integer
|
||||
int=Integer
|
||||
integer=Integer
|
||||
bigint=Long
|
||||
float=Float
|
||||
double=Double
|
||||
decimal=BigDecimal
|
||||
bit=Boolean
|
||||
|
||||
char=String
|
||||
varchar=String
|
||||
tinytext=String
|
||||
text=String
|
||||
mediumtext=String
|
||||
longtext=String
|
||||
|
||||
date=LocalDateTime
|
||||
datetime=LocalDateTime
|
||||
timestamp=LocalDateTime
|
||||
|
||||
# hidden columns in Swagger Models
|
||||
hiddenColumn=tenant_id
|
||||
# PG \u7C7B\u578B\u8F6C\u5316\u89C4\u5219
|
||||
int2=Integer
|
||||
int4=Integer
|
||||
int8=Long
|
||||
|
||||
#ORACLE \u7279\u6B8A\u7C7B\u578B\u8F6C\u6362\u89C4\u5219
|
||||
INT=Integer
|
||||
INTEGER=Integer
|
||||
LONG=LONG
|
||||
NUMBER=Integer
|
||||
BINARY_INTEGER=Integer
|
||||
FLOAT=Float
|
||||
BINARY_FLOAT=Float
|
||||
DOUBLE=Double
|
||||
BINARY_DOUBLE=Double
|
||||
DECIMAL=BigDecimal
|
||||
CHAR=String
|
||||
VARCHAR=String
|
||||
VARCHAR2=String
|
||||
NVARCHAR=String
|
||||
NVARCHAR2=String
|
||||
DATE=LocalDateTime
|
||||
DATETIME=LocalDateTime
|
||||
TIMESTAMP=LocalDateTime
|
||||
CLOB=String
|
||||
BLOB=String
|
||||
@@ -1,47 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--
|
||||
~ Copyright (c) 2018-2025, lengleng All rights reserved.
|
||||
~
|
||||
~ Redistribution and use in source and binary forms, with or without
|
||||
~ modification, are permitted provided that the following conditions are met:
|
||||
~
|
||||
~ Redistributions of source code must retain the above copyright notice,
|
||||
~ this list of conditions and the following disclaimer.
|
||||
~ Redistributions in binary form must reproduce the above copyright
|
||||
~ notice, this list of conditions and the following disclaimer in the
|
||||
~ documentation and/or other materials provided with the distribution.
|
||||
~ Neither the name of the pig4cloud.com developer nor the names of its
|
||||
~ contributors may be used to endorse or promote products derived from
|
||||
~ this software without specific prior written permission.
|
||||
~ Author: lengleng (wangiegie@gmail.com)
|
||||
-->
|
||||
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.pig4cloud.pigx.codegen.mapper.GenTableColumnMapper">
|
||||
|
||||
<sql id="queryColumn">
|
||||
SELECT
|
||||
column_name columnName,
|
||||
data_type dataType,
|
||||
column_comment comments,
|
||||
column_key columnKey,
|
||||
extra,
|
||||
is_nullable AS isNullable,
|
||||
column_type AS columnType
|
||||
FROM
|
||||
information_schema.COLUMNS
|
||||
WHERE
|
||||
table_name = #{tableName} and table_schema = (select database()) order by ordinal_position
|
||||
</sql>
|
||||
|
||||
<select id="selectTableColumn" resultType="com.pig4cloud.pigx.codegen.entity.ColumnEntity">
|
||||
<include refid="queryColumn"/>
|
||||
</select>
|
||||
|
||||
<select id="selectMapTableColumn" resultType="map">
|
||||
<include refid="queryColumn"/>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -1,19 +0,0 @@
|
||||
<?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.pig4cloud.pigx.codegen.mapper.GeneratorMapper">
|
||||
<select id="queryList" resultType="map">
|
||||
select table_name tableName, engine, table_comment tableComment, table_collation tableCollation, create_time createTime from information_schema.tables
|
||||
where table_schema = (select database())
|
||||
<if test="tableName != null and tableName.trim() != ''">
|
||||
and table_name like concat('%', #{tableName}, '%')
|
||||
</if>
|
||||
order by create_time desc
|
||||
</select>
|
||||
|
||||
<select id="queryTable" resultType="map">
|
||||
select table_name tableName, engine, table_comment tableComment, create_time createTime from information_schema.tables
|
||||
where table_schema = (select database()) and table_name = #{tableName}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
<?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.pig4cloud.pigx.codegen.mapper.GeneratorMssqlMapper">
|
||||
|
||||
<select id="queryTable" resultType="map">
|
||||
SELECT *
|
||||
FROM (
|
||||
SELECT CAST
|
||||
(so.NAME AS nvarchar(500)) AS tableName,
|
||||
CAST(sep.VALUE AS nvarchar(500)) AS tableComment
|
||||
FROM sysobjects so
|
||||
LEFT JOIN sys.extended_properties sep ON sep.major_id = so.ID
|
||||
AND sep.minor_id = 0
|
||||
WHERE (xtype = 'U' OR xtype = 'v')
|
||||
) T
|
||||
<where>
|
||||
<if test="tableName != null and tableName.trim() != ''">
|
||||
and T.tableName like concat('%', #{tableName}, '%')
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY T.tableName
|
||||
</select>
|
||||
|
||||
<sql id="queryColumn">
|
||||
SELECT
|
||||
'mssql' AS dbType,
|
||||
CAST ( b.NAME AS NVARCHAR ( 500 ) ) AS columnName,
|
||||
CAST ( sys.types.NAME AS NVARCHAR ( 500 ) ) AS dataType,
|
||||
CAST ( sys.types.NAME AS NVARCHAR ( 500 ) ) AS columnType,
|
||||
CAST ( c.VALUE AS NVARCHAR ( 500 ) ) AS comments,
|
||||
(
|
||||
SELECT
|
||||
CASE
|
||||
COUNT
|
||||
( 1 )
|
||||
WHEN 1 THEN
|
||||
'PRI' ELSE ''
|
||||
END
|
||||
FROM
|
||||
syscolumns,
|
||||
sysobjects,
|
||||
sysindexes,
|
||||
sysindexkeys,
|
||||
systypes
|
||||
WHERE
|
||||
syscolumns.xusertype = systypes.xusertype
|
||||
AND syscolumns.id = object_id( A.NAME )
|
||||
AND sysobjects.xtype = 'PK'
|
||||
AND sysobjects.parent_obj = syscolumns.id
|
||||
AND sysindexes.id = syscolumns.id
|
||||
AND sysobjects.NAME = sysindexes.NAME
|
||||
AND sysindexkeys.id = syscolumns.id
|
||||
AND sysindexkeys.indid = sysindexes.indid
|
||||
AND syscolumns.colid = sysindexkeys.colid
|
||||
AND syscolumns.NAME = B.NAME
|
||||
) AS columnKey,
|
||||
'' AS extra
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
name,
|
||||
object_id
|
||||
FROM
|
||||
sys.tables UNION ALL
|
||||
SELECT
|
||||
name,
|
||||
object_id
|
||||
FROM
|
||||
sys.views
|
||||
) a
|
||||
INNER JOIN sys.COLUMNS b ON b.object_id = a.object_id
|
||||
LEFT JOIN sys.types ON b.user_type_id = sys.types.user_type_id
|
||||
LEFT JOIN sys.extended_properties c ON c.major_id = b.object_id
|
||||
AND c.minor_id = b.column_id
|
||||
WHERE a.NAME = #{tableName} and sys.types.NAME != 'sysname'
|
||||
</sql>
|
||||
|
||||
<select id="selectTableColumn" resultType="com.pig4cloud.pigx.codegen.entity.ColumnEntity">
|
||||
<include refid="queryColumn"/>
|
||||
</select>
|
||||
|
||||
<select id="selectMapTableColumn" resultType="map">
|
||||
<include refid="queryColumn"/>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
<?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.pig4cloud.pigx.codegen.mapper.GeneratorMySqlMapper">
|
||||
|
||||
<select id="queryTable" resultType="map">
|
||||
SELECT
|
||||
'mysql' AS dbType,
|
||||
table_name AS tableName,
|
||||
ENGINE,
|
||||
table_comment AS tableComment,
|
||||
create_time AS createTime
|
||||
FROM
|
||||
information_schema.TABLES
|
||||
WHERE
|
||||
table_schema = (
|
||||
SELECT DATABASE
|
||||
())
|
||||
<if test="tableName != null and tableName.trim() != ''">
|
||||
and table_name like concat('%', #{tableName}, '%')
|
||||
</if>
|
||||
order by create_time desc
|
||||
</select>
|
||||
|
||||
|
||||
<sql id="queryColumn">
|
||||
SELECT
|
||||
column_name columnName,
|
||||
data_type dataType,
|
||||
column_comment comments,
|
||||
column_key columnKey,
|
||||
extra,
|
||||
is_nullable AS isNullable,
|
||||
column_type AS columnType
|
||||
FROM
|
||||
information_schema.COLUMNS
|
||||
WHERE
|
||||
table_name = #{tableName} and table_schema = (select database()) order by ordinal_position
|
||||
</sql>
|
||||
|
||||
<select id="selectTableColumn" resultType="com.pig4cloud.pigx.codegen.entity.ColumnEntity">
|
||||
<include refid="queryColumn"/>
|
||||
</select>
|
||||
|
||||
<select id="selectMapTableColumn" resultType="map">
|
||||
<include refid="queryColumn"/>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
<?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.pig4cloud.pigx.codegen.mapper.GeneratorOracleMapper">
|
||||
|
||||
<select id="queryTable" resultType="map">
|
||||
SELECT
|
||||
ut.TABLE_NAME AS "tableName",
|
||||
utc.comments AS "tableComment"
|
||||
FROM
|
||||
user_tables ut,
|
||||
user_tab_comments utc
|
||||
WHERE
|
||||
ut.TABLE_NAME = utc.TABLE_NAME
|
||||
<if test="tableName != null and tableName.trim() != ''">
|
||||
and ut.TABLE_NAME = UPPER ( #{tableName} )
|
||||
</if>
|
||||
ORDER BY ut.TABLE_NAME
|
||||
</select>
|
||||
|
||||
<sql id="queryColumn">
|
||||
SELECT
|
||||
'oracle' AS "dbType",
|
||||
TEMP.COLUMN_NAME AS "columnName",
|
||||
TEMP.data_type AS "columnType",
|
||||
TEMP.data_type AS "dataType",
|
||||
TEMP.comments AS comments,
|
||||
CASE
|
||||
TEMP.constraint_type
|
||||
WHEN 'P' THEN
|
||||
'PRI'
|
||||
WHEN 'C' THEN
|
||||
'UNI' ELSE''
|
||||
END "COLUMNKEY"
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
col.column_id,
|
||||
col.COLUMN_NAME,
|
||||
col.data_type,
|
||||
colc.comments,
|
||||
uc.constraint_type,
|
||||
ROW_NUMBER ( ) OVER (
|
||||
PARTITION BY col.COLUMN_NAME
|
||||
ORDER BY
|
||||
uc.constraint_type DESC
|
||||
) AS row_flg
|
||||
FROM
|
||||
user_tab_columns col
|
||||
LEFT JOIN user_col_comments colc ON colc.TABLE_NAME = col.TABLE_NAME
|
||||
AND colc.COLUMN_NAME = col.
|
||||
COLUMN_NAME LEFT JOIN user_cons_columns ucc ON ucc.TABLE_NAME = col.TABLE_NAME
|
||||
AND ucc.COLUMN_NAME = col.
|
||||
COLUMN_NAME LEFT JOIN user_constraints uc ON uc.CONSTRAINT_NAME = ucc.CONSTRAINT_NAME
|
||||
WHERE
|
||||
col.TABLE_NAME = UPPER ( #{tableName} )
|
||||
) TEMP
|
||||
WHERE
|
||||
TEMP.row_flg = 1
|
||||
ORDER BY
|
||||
TEMP.column_id
|
||||
</sql>
|
||||
|
||||
<select id="selectTableColumn" resultType="com.pig4cloud.pigx.codegen.entity.ColumnEntity">
|
||||
<include refid="queryColumn"/>
|
||||
</select>
|
||||
|
||||
<select id="selectMapTableColumn" resultType="map">
|
||||
<include refid="queryColumn"/>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,57 @@
|
||||
<?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.pig4cloud.pigx.codegen.mapper.GeneratorPgMapper">
|
||||
|
||||
<select id="queryTable" resultType="map">
|
||||
SELECT
|
||||
relname AS "tableName",
|
||||
obj_description ( oid ) AS "tableComment"
|
||||
FROM
|
||||
pg_class pc
|
||||
WHERE
|
||||
relkind = 'r'
|
||||
AND relname NOT LIKE'pg_%'
|
||||
AND relname NOT LIKE'sql_%'
|
||||
AND relchecks = 0
|
||||
<if test="tableName != null and tableName.trim() != ''">
|
||||
and pc.relname like concat('%', #{tableName}, '%')
|
||||
</if>
|
||||
ORDER BY relname
|
||||
</select>
|
||||
|
||||
|
||||
<sql id="queryColumn">
|
||||
SELECT
|
||||
'pg' AS "dbType",
|
||||
pa.attname AS "columnName",
|
||||
pg_type.typname AS "columnType",
|
||||
pg_type.typname AS "dataType",
|
||||
col_description ( pa.attrelid, pa.attnum ) AS "comments",
|
||||
(
|
||||
CASE
|
||||
pcon.contype
|
||||
WHEN 'p' THEN
|
||||
'PRI' ELSE''
|
||||
END
|
||||
) AS "columnKey"
|
||||
FROM
|
||||
pg_class AS pc,
|
||||
pg_attribute AS pa
|
||||
INNER JOIN pg_type ON pg_type.oid = pa.atttypid
|
||||
LEFT JOIN pg_constraint pcon ON pa.attnum = pcon.conkey[1]
|
||||
AND pa.attrelid = pcon.conrelid
|
||||
WHERE
|
||||
pc.relname = #{ tableName }
|
||||
AND pa.attrelid = pc.oid
|
||||
AND pa.attnum > 0;
|
||||
</sql>
|
||||
|
||||
<select id="selectTableColumn" resultType="com.pig4cloud.pigx.codegen.entity.ColumnEntity">
|
||||
<include refid="queryColumn"/>
|
||||
</select>
|
||||
|
||||
<select id="selectMapTableColumn" resultType="map">
|
||||
<include refid="queryColumn"/>
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -17,6 +17,9 @@
|
||||
|
||||
package ${package}.${moduleName}.entity;
|
||||
|
||||
#if($dbType != "mysql")
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
#end
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
@@ -41,16 +44,22 @@ import java.time.LocalDateTime;
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ApiModel(value = "${comments}")
|
||||
public class ${className} extends Model<${className}> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
#foreach ($column in $columns)
|
||||
/**
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
#foreach ($column in $columns)
|
||||
/**
|
||||
* $column.comments
|
||||
*/
|
||||
#if($column.columnName == $pk.columnName)
|
||||
@TableId
|
||||
#end
|
||||
@ApiModelProperty(value="$column.comments"#if($column.hidden),hidden=$column.hidden#end)
|
||||
#if($column.columnName == $pk.columnName)
|
||||
#if($dbType == "mysql")
|
||||
@TableId
|
||||
#else
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
#end
|
||||
#end
|
||||
@ApiModelProperty(value="$column.comments"#if($column.hidden),hidden=$column.hidden#end)
|
||||
private $column.attrType $column.lowerAttrName;
|
||||
#end
|
||||
|
||||
#end
|
||||
}
|
||||
Reference in new issue
Block a user