feat: 代码生成功能适配pg数据库
This commit is contained in:
@@ -1,3 +1,6 @@
|
|||||||
|
from config.env import DataBaseConfig
|
||||||
|
|
||||||
|
|
||||||
class CommonConstant:
|
class CommonConstant:
|
||||||
"""
|
"""
|
||||||
常用常量
|
常用常量
|
||||||
@@ -155,42 +158,87 @@ class MenuConstant:
|
|||||||
class GenConstant:
|
class GenConstant:
|
||||||
"""
|
"""
|
||||||
代码生成常量
|
代码生成常量
|
||||||
|
|
||||||
|
TPL_CRUD: 单表(增删改查
|
||||||
|
TPL_TREE: 树表(增删改查)
|
||||||
|
TPL_SUB: 主子表(增删改查)
|
||||||
|
TREE_CODE: 树编码字段
|
||||||
|
TREE_PARENT_CODE: 树父编码字段
|
||||||
|
TREE_NAME: 树名称字段
|
||||||
|
PARENT_MENU_ID: 上级菜单ID字段
|
||||||
|
PARENT_MENU_NAME: 上级菜单名称字段
|
||||||
|
COLUMNTYPE_STR: 数据库字符串类型
|
||||||
|
COLUMNTYPE_TEXT: 数据库文本类型
|
||||||
|
COLUMNTYPE_TIME: 数据库时间类型
|
||||||
|
COLUMNTYPE_GEOMETRY: 数据库字空间类型
|
||||||
|
COLUMNTYPE_NUMBER: 数据库数字类型
|
||||||
|
COLUMNNAME_NOT_EDIT: 页面不需要编辑字段
|
||||||
|
COLUMNNAME_NOT_LIST: 页面不需要显示的列表字段
|
||||||
|
COLUMNNAME_NOT_QUERY: 页面不需要查询字段
|
||||||
|
BASE_ENTITY: Entity基类字段
|
||||||
|
TREE_ENTITY: Tree基类字段
|
||||||
|
HTML_INPUT: 文本框
|
||||||
|
HTML_TEXTAREA: 文本域
|
||||||
|
HTML_SELECT: 下拉框
|
||||||
|
HTML_RADIO: 单选框
|
||||||
|
HTML_CHECKBOX: 复选框
|
||||||
|
HTML_DATETIME: 日期控件
|
||||||
|
HTML_IMAGE_UPLOAD: 图片上传控件
|
||||||
|
HTML_FILE_UPLOAD: 文件上传控件
|
||||||
|
HTML_EDITOR: 富文本控件
|
||||||
|
TYPE_DECIMAL: 高精度计算类型
|
||||||
|
TYPE_DATE: 时间类型
|
||||||
|
QUERY_LIKE: 模糊查询
|
||||||
|
QUERY_EQ: 相等查询
|
||||||
|
REQUIRE: 需要
|
||||||
|
DB_TO_SQLALCHEMY_TYPE_MAPPING: 数据库类型与sqlalchemy类型映射
|
||||||
|
DB_TO_PYTHON_TYPE_MAPPING: 数据库类型与python类型映射
|
||||||
"""
|
"""
|
||||||
|
|
||||||
"""单表(增删改查)"""
|
|
||||||
TPL_CRUD = 'crud'
|
TPL_CRUD = 'crud'
|
||||||
|
|
||||||
"""树表(增删改查)"""
|
|
||||||
TPL_TREE = 'tree'
|
TPL_TREE = 'tree'
|
||||||
|
|
||||||
"""主子表(增删改查)"""
|
|
||||||
TPL_SUB = 'sub'
|
TPL_SUB = 'sub'
|
||||||
|
|
||||||
"""树编码字段"""
|
|
||||||
TREE_CODE = 'treeCode'
|
TREE_CODE = 'treeCode'
|
||||||
|
|
||||||
"""树父编码字段"""
|
|
||||||
TREE_PARENT_CODE = 'treeParentCode'
|
TREE_PARENT_CODE = 'treeParentCode'
|
||||||
|
|
||||||
"""树名称字段"""
|
|
||||||
TREE_NAME = 'treeName'
|
TREE_NAME = 'treeName'
|
||||||
|
|
||||||
"""上级菜单ID字段"""
|
|
||||||
PARENT_MENU_ID = 'parentMenuId'
|
PARENT_MENU_ID = 'parentMenuId'
|
||||||
|
|
||||||
"""上级菜单名称字段"""
|
|
||||||
PARENT_MENU_NAME = 'parentMenuName'
|
PARENT_MENU_NAME = 'parentMenuName'
|
||||||
|
COLUMNTYPE_STR = (
|
||||||
"""数据库字符串类型"""
|
['character varying', 'varchar', 'character', 'char']
|
||||||
COLUMNTYPE_STR = ['char', 'varchar', 'nvarchar', 'varchar2']
|
if DataBaseConfig.db_type == 'postgresql'
|
||||||
|
else ['char', 'varchar', 'nvarchar', 'varchar2']
|
||||||
"""数据库文本类型"""
|
)
|
||||||
COLUMNTYPE_TEXT = ['tinytext', 'text', 'mediumtext', 'longtext']
|
COLUMNTYPE_TEXT = (
|
||||||
|
['text', 'citext'] if DataBaseConfig.db_type == 'postgresql' else ['tinytext', 'text', 'mediumtext', 'longtext']
|
||||||
"""数据库时间类型"""
|
)
|
||||||
COLUMNTYPE_TIME = ['datetime', 'time', 'date', 'timestamp']
|
COLUMNTYPE_TIME = (
|
||||||
|
[
|
||||||
"""数据库数字类型"""
|
'date',
|
||||||
|
'time',
|
||||||
|
'time with time zone',
|
||||||
|
'time without time zone',
|
||||||
|
'timestamp',
|
||||||
|
'timestamp with time zone',
|
||||||
|
'timestamp without time zone',
|
||||||
|
'interval',
|
||||||
|
]
|
||||||
|
if DataBaseConfig.db_type == 'postgresql'
|
||||||
|
else ['datetime', 'time', 'date', 'timestamp']
|
||||||
|
)
|
||||||
|
COLUMNTYPE_GEOMETRY = (
|
||||||
|
['point', 'line', 'lseg', 'box', 'path', 'polygon', 'circle']
|
||||||
|
if DataBaseConfig.db_type == 'postgresql'
|
||||||
|
else [
|
||||||
|
'geometry',
|
||||||
|
'point',
|
||||||
|
'linestring',
|
||||||
|
'polygon',
|
||||||
|
'multipoint',
|
||||||
|
'multilinestring',
|
||||||
|
'multipolygon',
|
||||||
|
'geometrycollection',
|
||||||
|
]
|
||||||
|
)
|
||||||
COLUMNTYPE_NUMBER = [
|
COLUMNTYPE_NUMBER = [
|
||||||
'tinyint',
|
'tinyint',
|
||||||
'smallint',
|
'smallint',
|
||||||
@@ -204,65 +252,83 @@ class GenConstant:
|
|||||||
'double',
|
'double',
|
||||||
'decimal',
|
'decimal',
|
||||||
]
|
]
|
||||||
|
|
||||||
"""页面不需要编辑字段"""
|
|
||||||
COLUMNNAME_NOT_EDIT = ['id', 'create_by', 'create_time', 'del_flag']
|
COLUMNNAME_NOT_EDIT = ['id', 'create_by', 'create_time', 'del_flag']
|
||||||
|
|
||||||
"""页面不需要显示的列表字段"""
|
|
||||||
COLUMNNAME_NOT_LIST = ['id', 'create_by', 'create_time', 'del_flag', 'update_by', 'update_time']
|
COLUMNNAME_NOT_LIST = ['id', 'create_by', 'create_time', 'del_flag', 'update_by', 'update_time']
|
||||||
|
|
||||||
"""页面不需要查询字段"""
|
|
||||||
COLUMNNAME_NOT_QUERY = ['id', 'create_by', 'create_time', 'del_flag', 'update_by', 'update_time', 'remark']
|
COLUMNNAME_NOT_QUERY = ['id', 'create_by', 'create_time', 'del_flag', 'update_by', 'update_time', 'remark']
|
||||||
|
|
||||||
"""Entity基类字段"""
|
|
||||||
BASE_ENTITY = ['createBy', 'createTime', 'updateBy', 'updateTime', 'remark']
|
BASE_ENTITY = ['createBy', 'createTime', 'updateBy', 'updateTime', 'remark']
|
||||||
|
|
||||||
"""Tree基类字段"""
|
|
||||||
TREE_ENTITY = ['parentName', 'parentId', 'orderNum', 'ancestors', 'children']
|
TREE_ENTITY = ['parentName', 'parentId', 'orderNum', 'ancestors', 'children']
|
||||||
|
|
||||||
"""文本框"""
|
|
||||||
HTML_INPUT = 'input'
|
HTML_INPUT = 'input'
|
||||||
|
|
||||||
"""文本域"""
|
|
||||||
HTML_TEXTAREA = 'textarea'
|
HTML_TEXTAREA = 'textarea'
|
||||||
|
|
||||||
"""下拉框"""
|
|
||||||
HTML_SELECT = 'select'
|
HTML_SELECT = 'select'
|
||||||
|
|
||||||
"""单选框"""
|
|
||||||
HTML_RADIO = 'radio'
|
HTML_RADIO = 'radio'
|
||||||
|
|
||||||
"""复选框"""
|
|
||||||
HTML_CHECKBOX = 'checkbox'
|
HTML_CHECKBOX = 'checkbox'
|
||||||
|
|
||||||
"""日期控件"""
|
|
||||||
HTML_DATETIME = 'datetime'
|
HTML_DATETIME = 'datetime'
|
||||||
|
|
||||||
"""图片上传控件"""
|
|
||||||
HTML_IMAGE_UPLOAD = 'imageUpload'
|
HTML_IMAGE_UPLOAD = 'imageUpload'
|
||||||
|
|
||||||
"""文件上传控件"""
|
|
||||||
HTML_FILE_UPLOAD = 'fileUpload'
|
HTML_FILE_UPLOAD = 'fileUpload'
|
||||||
|
|
||||||
"""富文本控件"""
|
|
||||||
HTML_EDITOR = 'editor'
|
HTML_EDITOR = 'editor'
|
||||||
|
|
||||||
"""高精度计算类型"""
|
|
||||||
TYPE_DECIMAL = 'Decimal'
|
TYPE_DECIMAL = 'Decimal'
|
||||||
|
|
||||||
"""时间类型"""
|
|
||||||
TYPE_DATE = ['date', 'time', 'datetime']
|
TYPE_DATE = ['date', 'time', 'datetime']
|
||||||
|
|
||||||
"""模糊查询"""
|
|
||||||
QUERY_LIKE = 'LIKE'
|
QUERY_LIKE = 'LIKE'
|
||||||
|
|
||||||
"""相等查询"""
|
|
||||||
QUERY_EQ = 'EQ'
|
QUERY_EQ = 'EQ'
|
||||||
|
|
||||||
"""需要"""
|
|
||||||
REQUIRE = '1'
|
REQUIRE = '1'
|
||||||
|
DB_TO_SQLALCHEMY_TYPE_MAPPING = (
|
||||||
MYSQL_TO_SQLALCHEMY_TYPE_MAPPING = {
|
{
|
||||||
|
'boolean': 'Boolean',
|
||||||
|
'smallint': 'SmallInteger',
|
||||||
|
'integer': 'Integer',
|
||||||
|
'bigint': 'BigInteger',
|
||||||
|
'real': 'Float',
|
||||||
|
'double precision': 'Float',
|
||||||
|
'numeric': 'Numeric',
|
||||||
|
'character varying': 'String',
|
||||||
|
'character': 'String',
|
||||||
|
'text': 'Text',
|
||||||
|
'bytea': 'LargeBinary',
|
||||||
|
'date': 'Date',
|
||||||
|
'time': 'Time',
|
||||||
|
'time with time zone': 'Time',
|
||||||
|
'time without time zone': 'Time',
|
||||||
|
'timestamp': 'DateTime',
|
||||||
|
'timestamp with time zone': 'DateTime',
|
||||||
|
'timestamp without time zone': 'DateTime',
|
||||||
|
'interval': 'Interval',
|
||||||
|
'json': 'JSON',
|
||||||
|
'jsonb': 'JSONB',
|
||||||
|
'uuid': 'Uuid',
|
||||||
|
'inet': 'INET',
|
||||||
|
'cidr': 'CIDR',
|
||||||
|
'macaddr': 'MACADDR',
|
||||||
|
'point': 'Geometry',
|
||||||
|
'line': 'Geometry',
|
||||||
|
'lseg': 'Geometry',
|
||||||
|
'box': 'Geometry',
|
||||||
|
'path': 'Geometry',
|
||||||
|
'polygon': 'Geometry',
|
||||||
|
'circle': 'Geometry',
|
||||||
|
'bit': 'Bit',
|
||||||
|
'bit varying': 'Bit',
|
||||||
|
'tsvector': 'TSVECTOR',
|
||||||
|
'tsquery': 'TSQUERY',
|
||||||
|
'xml': 'String',
|
||||||
|
'array': 'ARRAY',
|
||||||
|
'composite': 'JSON',
|
||||||
|
'enum': 'Enum',
|
||||||
|
'range': 'Range',
|
||||||
|
'money': 'Numeric',
|
||||||
|
'pg_lsn': 'BigInteger',
|
||||||
|
'txid_snapshot': 'String',
|
||||||
|
'oid': 'BigInteger',
|
||||||
|
'regproc': 'String',
|
||||||
|
'regclass': 'String',
|
||||||
|
'regtype': 'String',
|
||||||
|
'regrole': 'String',
|
||||||
|
'regnamespace': 'String',
|
||||||
|
'int2vector': 'ARRAY',
|
||||||
|
'oidvector': 'ARRAY',
|
||||||
|
'pg_node_tree': 'Text',
|
||||||
|
}
|
||||||
|
if DataBaseConfig.db_type == 'postgresql'
|
||||||
|
else {
|
||||||
# 数值类型
|
# 数值类型
|
||||||
'TINYINT': 'SmallInteger',
|
'TINYINT': 'SmallInteger',
|
||||||
'SMALLINT': 'SmallInteger',
|
'SMALLINT': 'SmallInteger',
|
||||||
@@ -299,17 +365,74 @@ class GenConstant:
|
|||||||
# JSON 类型
|
# JSON 类型
|
||||||
'JSON': 'JSON',
|
'JSON': 'JSON',
|
||||||
# 空间数据类型(需要扩展支持,如 GeoAlchemy2)
|
# 空间数据类型(需要扩展支持,如 GeoAlchemy2)
|
||||||
'GEOMETRY': 'geoalchemy2.Geometry', # 需要安装 geoalchemy2
|
'GEOMETRY': 'Geometry', # 需要安装 geoalchemy2
|
||||||
'POINT': 'geoalchemy2.Geometry',
|
'POINT': 'Geometry',
|
||||||
'LINESTRING': 'geoalchemy2.Geometry',
|
'LINESTRING': 'Geometry',
|
||||||
'POLYGON': 'geoalchemy2.Geometry',
|
'POLYGON': 'Geometry',
|
||||||
'MULTIPOINT': 'geoalchemy2.Geometry',
|
'MULTIPOINT': 'Geometry',
|
||||||
'MULTILINESTRING': 'geoalchemy2.Geometry',
|
'MULTILINESTRING': 'Geometry',
|
||||||
'MULTIPOLYGON': 'geoalchemy2.Geometry',
|
'MULTIPOLYGON': 'Geometry',
|
||||||
'GEOMETRYCOLLECTION': 'geoalchemy2.Geometry',
|
'GEOMETRYCOLLECTION': 'Geometry',
|
||||||
}
|
}
|
||||||
|
)
|
||||||
MYSQL_TO_PYTHON_TYPE_MAPPING = {
|
DB_TO_PYTHON_TYPE_MAPPING = (
|
||||||
|
{
|
||||||
|
'boolean': 'bool',
|
||||||
|
'smallint': 'int',
|
||||||
|
'integer': 'int',
|
||||||
|
'bigint': 'int',
|
||||||
|
'real': 'float',
|
||||||
|
'double precision': 'float',
|
||||||
|
'numeric': 'Decimal',
|
||||||
|
'character varying': 'str',
|
||||||
|
'character': 'str',
|
||||||
|
'text': 'str',
|
||||||
|
'bytea': 'bytes',
|
||||||
|
'date': 'date',
|
||||||
|
'time': 'time',
|
||||||
|
'time with time zone': 'time',
|
||||||
|
'time without time zone': 'time',
|
||||||
|
'timestamp': 'datetime',
|
||||||
|
'timestamp with time zone': 'datetime',
|
||||||
|
'timestamp without time zone': 'datetime',
|
||||||
|
'interval': 'timedelta',
|
||||||
|
'json': 'dict',
|
||||||
|
'jsonb': 'dict',
|
||||||
|
'uuid': 'str',
|
||||||
|
'inet': 'str',
|
||||||
|
'cidr': 'str',
|
||||||
|
'macaddr': 'str',
|
||||||
|
'point': 'list',
|
||||||
|
'line': 'list',
|
||||||
|
'lseg': 'list',
|
||||||
|
'box': 'list',
|
||||||
|
'path': 'list',
|
||||||
|
'polygon': 'list',
|
||||||
|
'circle': 'list',
|
||||||
|
'bit': 'int',
|
||||||
|
'bit varying': 'int',
|
||||||
|
'tsvector': 'str',
|
||||||
|
'tsquery': 'str',
|
||||||
|
'xml': 'str',
|
||||||
|
'array': 'list',
|
||||||
|
'composite': 'dict',
|
||||||
|
'enum': 'str',
|
||||||
|
'range': 'list',
|
||||||
|
'money': 'Decimal',
|
||||||
|
'pg_lsn': 'int',
|
||||||
|
'txid_snapshot': 'str',
|
||||||
|
'oid': 'int',
|
||||||
|
'regproc': 'str',
|
||||||
|
'regclass': 'str',
|
||||||
|
'regtype': 'str',
|
||||||
|
'regrole': 'str',
|
||||||
|
'regnamespace': 'str',
|
||||||
|
'int2vector': 'list',
|
||||||
|
'oidvector': 'list',
|
||||||
|
'pg_node_tree': 'str',
|
||||||
|
}
|
||||||
|
if DataBaseConfig.db_type == 'postgresql'
|
||||||
|
else {
|
||||||
# 数值类型
|
# 数值类型
|
||||||
'TINYINT': 'int',
|
'TINYINT': 'int',
|
||||||
'SMALLINT': 'int',
|
'SMALLINT': 'int',
|
||||||
@@ -355,3 +478,4 @@ class GenConstant:
|
|||||||
'MULTIPOLYGON': 'bytes',
|
'MULTIPOLYGON': 'bytes',
|
||||||
'GEOMETRYCOLLECTION': 'bytes',
|
'GEOMETRYCOLLECTION': 'bytes',
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
@@ -278,7 +278,13 @@ class GenTableColumnDao:
|
|||||||
:return: 需要生成的业务表字段列表信息对象
|
:return: 需要生成的业务表字段列表信息对象
|
||||||
"""
|
"""
|
||||||
gen_table_column_list = (
|
gen_table_column_list = (
|
||||||
(await db.execute(select(GenTableColumn).where(GenTableColumn.table_id == table_id))).scalars().all()
|
(
|
||||||
|
await db.execute(
|
||||||
|
select(GenTableColumn).where(GenTableColumn.table_id == table_id).order_by(GenTableColumn.sort)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.scalars()
|
||||||
|
.all()
|
||||||
)
|
)
|
||||||
|
|
||||||
return gen_table_column_list
|
return gen_table_column_list
|
||||||
|
@@ -12,10 +12,10 @@ from config.enums import BusinessType
|
|||||||
from config.get_db import get_db
|
from config.get_db import get_db
|
||||||
from module_admin.annotation.log_annotation import Log
|
from module_admin.annotation.log_annotation import Log
|
||||||
from module_admin.aspect.interface_auth import CheckUserInterfaceAuth
|
from module_admin.aspect.interface_auth import CheckUserInterfaceAuth
|
||||||
|
from module_admin.entity.vo.user_vo import CurrentUserModel
|
||||||
from module_admin.service.login_service import LoginService
|
from module_admin.service.login_service import LoginService
|
||||||
from {{ packageName }}.service.{{ businessName }}_service import {{ BusinessName }}Service
|
from {{ packageName }}.service.{{ businessName }}_service import {{ BusinessName }}Service
|
||||||
from {{ packageName }}.entity.vo.{{ businessName }}_vo import Delete{{ BusinessName }}Model, {{ BusinessName }}Model, {{ BusinessName }}PageQueryModel
|
from {{ packageName }}.entity.vo.{{ businessName }}_vo import Delete{{ BusinessName }}Model, {{ BusinessName }}Model, {{ BusinessName }}PageQueryModel
|
||||||
from {{ packageName }}.entity.vo.user_vo import CurrentUserModel
|
|
||||||
from utils.common_util import bytes2file_response
|
from utils.common_util import bytes2file_response
|
||||||
from utils.log_util import logger
|
from utils.log_util import logger
|
||||||
from utils.page_util import PageResponseModel
|
from utils.page_util import PageResponseModel
|
||||||
@@ -30,7 +30,7 @@ from utils.response_util import ResponseUtil
|
|||||||
)
|
)
|
||||||
async def get_{{ moduleName }}_{{ businessName }}_list(
|
async def get_{{ moduleName }}_{{ businessName }}_list(
|
||||||
request: Request,
|
request: Request,
|
||||||
{{ businessName }}_page_query: {{ BusinessName }}PageQueryModel = Depends({{ BusinessName }}PageQueryModel.as_query),
|
{% if table.crud or table.sub %}{{ businessName }}_page_query{% elif table.tree %}{{ businessName }}_query{% endif %}: {{ BusinessName }}PageQueryModel = Depends({{ BusinessName }}PageQueryModel.as_query),
|
||||||
query_db: AsyncSession = Depends(get_db),
|
query_db: AsyncSession = Depends(get_db),
|
||||||
):
|
):
|
||||||
{% if table.crud or table.sub %}
|
{% if table.crud or table.sub %}
|
||||||
|
@@ -3,7 +3,7 @@
|
|||||||
{% set pkParentheseIndex = pkColumn.column_comment.find("(") %}
|
{% set pkParentheseIndex = pkColumn.column_comment.find("(") %}
|
||||||
{% set pk_field_comment = pkColumn.column_comment[:pkParentheseIndex] if pkParentheseIndex != -1 else pkColumn.column_comment %}
|
{% set pk_field_comment = pkColumn.column_comment[:pkParentheseIndex] if pkParentheseIndex != -1 else pkColumn.column_comment %}
|
||||||
{% for column in columns %}
|
{% for column in columns %}
|
||||||
{% if column.python_field == "createTime" %}
|
{% if column.query and column.query_type == 'BETWEEN' and column.python_field == "createTime" %}
|
||||||
from datetime import datetime, time
|
from datetime import datetime, time
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
@@ -12,8 +12,13 @@ from sqlalchemy.ext.asyncio import AsyncSession
|
|||||||
{% if table.sub %}
|
{% if table.sub %}
|
||||||
from sqlalchemy.orm import selectinload
|
from sqlalchemy.orm import selectinload
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if table.sub %}
|
||||||
|
from {{ packageName }}.entity.do.{{ businessName }}_do import {{ ClassName }}, {{ subClassName }}
|
||||||
|
from {{ packageName }}.entity.vo.{{ businessName }}_vo import {{ BusinessName }}Model, {{ BusinessName }}PageQueryModel, {{ subTable.business_name | capitalize }}Model
|
||||||
|
{% else %}
|
||||||
from {{ packageName }}.entity.do.{{ businessName }}_do import {{ ClassName }}
|
from {{ packageName }}.entity.do.{{ businessName }}_do import {{ ClassName }}
|
||||||
from {{ packageName }}.entity.vo.{{ businessName }}_vo import {{ BusinessName }}Model, {{ BusinessName }}PageQueryModel
|
from {{ packageName }}.entity.vo.{{ businessName }}_vo import {{ BusinessName }}Model, {{ BusinessName }}PageQueryModel
|
||||||
|
{% endif %}
|
||||||
from utils.page_util import PageUtil
|
from utils.page_util import PageUtil
|
||||||
|
|
||||||
|
|
||||||
|
@@ -75,7 +75,7 @@ class {{ BusinessName }}Service:
|
|||||||
{% set parentheseIndex = column.column_comment.find("(") %}
|
{% set parentheseIndex = column.column_comment.find("(") %}
|
||||||
{% set comment = column.column_comment[:parentheseIndex] if parentheseIndex != -1 else column.column_comment %}
|
{% set comment = column.column_comment[:parentheseIndex] if parentheseIndex != -1 else column.column_comment %}
|
||||||
{% if column.required %}
|
{% if column.required %}
|
||||||
if not await cls.check_{{ column.python_field | camel_to_snake }}_unique_services(query_db, page_object)
|
if not await cls.check_{{ column.python_field | camel_to_snake }}_unique_services(query_db, page_object):
|
||||||
raise ServiceException(message=f'新增{{ functionName }}{page_object.{{ column.python_field | camel_to_snake }}}失败,{{ comment }}已存在')
|
raise ServiceException(message=f'新增{{ functionName }}{page_object.{{ column.python_field | camel_to_snake }}}失败,{{ comment }}已存在')
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
@@ -110,7 +110,7 @@ class {{ BusinessName }}Service:
|
|||||||
{% set parentheseIndex = column.column_comment.find("(") %}
|
{% set parentheseIndex = column.column_comment.find("(") %}
|
||||||
{% set comment = column.column_comment[:parentheseIndex] if parentheseIndex != -1 else column.column_comment %}
|
{% set comment = column.column_comment[:parentheseIndex] if parentheseIndex != -1 else column.column_comment %}
|
||||||
{% if column.required %}
|
{% if column.required %}
|
||||||
if not await cls.check_{{ column.python_field | camel_to_snake }}_unique_services(query_db, page_object)
|
if not await cls.check_{{ column.python_field | camel_to_snake }}_unique_services(query_db, page_object):
|
||||||
raise ServiceException(message=f'修改{{ functionName }}{page_object.{{ column.python_field | camel_to_snake }}}失败,{{ comment }}已存在')
|
raise ServiceException(message=f'修改{{ functionName }}{page_object.{{ column.python_field | camel_to_snake }}}失败,{{ comment }}已存在')
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
@@ -1,26 +1,26 @@
|
|||||||
{% if dbType == 'postgresql' %}
|
{% if dbType == 'postgresql' %}
|
||||||
-- 菜单 SQL
|
-- 菜单 SQL
|
||||||
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
||||||
values('${functionName}', '${parentMenuId}', '1', '${businessName}', '${moduleName}/${businessName}/index', 1, 0, 'C', '0', '0', '${permissionPrefix}:list', '#', 'admin', current_timestamp, '', null, '${functionName}菜单');
|
values('{{ functionName }}', '{{ parentMenuId }}', '1', '{{ businessName }}', '{{ moduleName }}/{{ businessName }}/index', 1, 0, 'C', '0', '0', '{{ permissionPrefix }}:list', '#', 'admin', current_timestamp, '', null, '{{ functionName }}菜单');
|
||||||
|
|
||||||
-- 按钮父菜单ID
|
-- 按钮父菜单ID
|
||||||
select max(menu_id) from sys_menu;
|
select max(menu_id) from sys_menu;
|
||||||
|
|
||||||
-- 按钮 SQL
|
-- 按钮 SQL
|
||||||
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
||||||
values('${functionName}查询', max(menu_id), '1', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:query', '#', 'admin', current_timestamp, '', null, '');
|
values('{{ functionName }}查询', max(menu_id), '1', '#', '', 1, 0, 'F', '0', '0', '{{ permissionPrefix }}:query', '#', 'admin', current_timestamp, '', null, '');
|
||||||
|
|
||||||
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
||||||
values('${functionName}新增', max(menu_id), '2', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:add', '#', 'admin', current_timestamp, '', null, '');
|
values('{{ functionName }}新增', max(menu_id), '2', '#', '', 1, 0, 'F', '0', '0', '{{ permissionPrefix }}:add', '#', 'admin', current_timestamp, '', null, '');
|
||||||
|
|
||||||
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
||||||
values('${functionName}修改', max(menu_id), '3', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:edit', '#', 'admin', current_timestamp, '', null, '');
|
values('{{ functionName }}修改', max(menu_id), '3', '#', '', 1, 0, 'F', '0', '0', '{{ permissionPrefix }}:edit', '#', 'admin', current_timestamp, '', null, '');
|
||||||
|
|
||||||
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
||||||
values('${functionName}删除', max(menu_id), '4', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:remove', '#', 'admin', current_timestamp, '', null, '');
|
values('{{ functionName }}删除', max(menu_id), '4', '#', '', 1, 0, 'F', '0', '0', '{{ permissionPrefix }}:remove', '#', 'admin', current_timestamp, '', null, '');
|
||||||
|
|
||||||
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
||||||
values('${functionName}导出', max(menu_id), '5', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:export', '#', 'admin', current_timestamp, '', null, '');
|
values('{{ functionName }}导出', max(menu_id), '5', '#', '', 1, 0, 'F', '0', '0', '{{ permissionPrefix }}:export', '#', 'admin', current_timestamp, '', null, '');
|
||||||
{% else %}
|
{% else %}
|
||||||
-- 菜单 SQL
|
-- 菜单 SQL
|
||||||
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
|
||||||
|
@@ -398,7 +398,7 @@ function toggleExpandAll() {
|
|||||||
/** 修改按钮操作 */
|
/** 修改按钮操作 */
|
||||||
function handleUpdate(row) {
|
function handleUpdate(row) {
|
||||||
reset();
|
reset();
|
||||||
await getTreeselect();
|
getTreeselect();
|
||||||
if (row != null) {
|
if (row != null) {
|
||||||
form.value.{{ treeParentCode }} = row.{{ treeParentCode }};
|
form.value.{{ treeParentCode }} = row.{{ treeParentCode }};
|
||||||
}
|
}
|
||||||
|
@@ -976,7 +976,7 @@ $BODY$
|
|||||||
LANGUAGE plpgsql VOLATILE
|
LANGUAGE plpgsql VOLATILE
|
||||||
COST 100;
|
COST 100;
|
||||||
|
|
||||||
create view list_column as
|
create or replace view list_column as
|
||||||
SELECT c.relname AS table_name,
|
SELECT c.relname AS table_name,
|
||||||
a.attname AS column_name,
|
a.attname AS column_name,
|
||||||
d.description AS column_comment,
|
d.description AS column_comment,
|
||||||
@@ -1016,7 +1016,7 @@ WHERE (c.relkind = ANY (ARRAY['r'::"char", 'p'::"char"]))
|
|||||||
AND not a.attisdropped
|
AND not a.attisdropped
|
||||||
ORDER BY c.relname, a.attnum;
|
ORDER BY c.relname, a.attnum;
|
||||||
|
|
||||||
create view list_table as
|
create or replace view list_table as
|
||||||
SELECT c.relname AS table_name,
|
SELECT c.relname AS table_name,
|
||||||
obj_description(c.oid) AS table_comment,
|
obj_description(c.oid) AS table_comment,
|
||||||
CURRENT_TIMESTAMP AS create_time,
|
CURRENT_TIMESTAMP AS create_time,
|
||||||
|
@@ -47,7 +47,7 @@ class GenUtils:
|
|||||||
column.python_field = cls.to_camel_case(column_name)
|
column.python_field = cls.to_camel_case(column_name)
|
||||||
# 设置默认类型
|
# 设置默认类型
|
||||||
column.python_type = StringUtil.get_mapping_value_by_key_ignore_case(
|
column.python_type = StringUtil.get_mapping_value_by_key_ignore_case(
|
||||||
GenConstant.MYSQL_TO_PYTHON_TYPE_MAPPING, data_type
|
GenConstant.DB_TO_PYTHON_TYPE_MAPPING, data_type
|
||||||
)
|
)
|
||||||
column.query_type = GenConstant.QUERY_EQ
|
column.query_type = GenConstant.QUERY_EQ
|
||||||
|
|
||||||
|
@@ -210,7 +210,7 @@ class TemplateUtils:
|
|||||||
return f'{cls.BACKEND_PROJECT_PATH}/sql/{business_name}_menu.sql'
|
return f'{cls.BACKEND_PROJECT_PATH}/sql/{business_name}_menu.sql'
|
||||||
elif 'api.js.jinja2' in template:
|
elif 'api.js.jinja2' in template:
|
||||||
return f'{vue_path}/api/{module_name}/{business_name}.js'
|
return f'{vue_path}/api/{module_name}/{business_name}.js'
|
||||||
elif 'index.vue.jinja2' in template or 'index-tree.vue.j2' in template:
|
elif 'index.vue.jinja2' in template or 'index-tree.vue.jinja2' in template:
|
||||||
return f'{vue_path}/views/{module_name}/{business_name}/index.vue'
|
return f'{vue_path}/views/{module_name}/{business_name}/index.vue'
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
@@ -261,16 +261,18 @@ class TemplateUtils:
|
|||||||
import_list.add('from sqlalchemy import Column')
|
import_list.add('from sqlalchemy import Column')
|
||||||
for column in columns:
|
for column in columns:
|
||||||
data_type = cls.get_db_type(column.column_type)
|
data_type = cls.get_db_type(column.column_type)
|
||||||
|
if data_type in GenConstant.COLUMNTYPE_GEOMETRY:
|
||||||
|
import_list.add('from geoalchemy2 import Geometry')
|
||||||
import_list.add(
|
import_list.add(
|
||||||
f'from sqlalchemy import {StringUtil.get_mapping_value_by_key_ignore_case(GenConstant.MYSQL_TO_SQLALCHEMY_TYPE_MAPPING, data_type)}'
|
f'from sqlalchemy import {StringUtil.get_mapping_value_by_key_ignore_case(GenConstant.DB_TO_SQLALCHEMY_TYPE_MAPPING, data_type)}'
|
||||||
)
|
)
|
||||||
if gen_table.sub:
|
if gen_table.sub:
|
||||||
sub_columns = gen_table.sub_table.columns or []
|
sub_columns = gen_table.sub_table.columns or []
|
||||||
for sub_column in sub_columns:
|
for sub_column in sub_columns:
|
||||||
if sub_column.python_type in GenConstant.TYPE_DATE:
|
data_type = cls.get_db_type(sub_column.column_type)
|
||||||
import_list.add(f'from datetime import {column.python_type}')
|
import_list.add(
|
||||||
elif sub_column.python_type == GenConstant.TYPE_DECIMAL:
|
f'from sqlalchemy import {StringUtil.get_mapping_value_by_key_ignore_case(GenConstant.DB_TO_SQLALCHEMY_TYPE_MAPPING, data_type)}'
|
||||||
import_list.add('from decimal import Decimal')
|
)
|
||||||
return cls.merge_same_imports(list(import_list), 'from sqlalchemy import')
|
return cls.merge_same_imports(list(import_list), 'from sqlalchemy import')
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -444,14 +446,14 @@ class TemplateUtils:
|
|||||||
column_type_list = column_type.split('(')
|
column_type_list = column_type.split('(')
|
||||||
sqlalchemy_type = (
|
sqlalchemy_type = (
|
||||||
StringUtil.get_mapping_value_by_key_ignore_case(
|
StringUtil.get_mapping_value_by_key_ignore_case(
|
||||||
GenConstant.MYSQL_TO_SQLALCHEMY_TYPE_MAPPING, column_type_list[0]
|
GenConstant.DB_TO_SQLALCHEMY_TYPE_MAPPING, column_type_list[0]
|
||||||
)
|
)
|
||||||
+ '('
|
+ '('
|
||||||
+ column_type_list[1]
|
+ column_type_list[1]
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
sqlalchemy_type = StringUtil.get_mapping_value_by_key_ignore_case(
|
sqlalchemy_type = StringUtil.get_mapping_value_by_key_ignore_case(
|
||||||
GenConstant.MYSQL_TO_SQLALCHEMY_TYPE_MAPPING, column_type
|
GenConstant.DB_TO_SQLALCHEMY_TYPE_MAPPING, column_type
|
||||||
)
|
)
|
||||||
|
|
||||||
return sqlalchemy_type
|
return sqlalchemy_type
|
||||||
|
@@ -36,6 +36,7 @@
|
|||||||
<el-option label="datetime" value="datetime" />
|
<el-option label="datetime" value="datetime" />
|
||||||
<el-option label="bytes" value="bytes" />
|
<el-option label="bytes" value="bytes" />
|
||||||
<el-option label="dict" value="dict" />
|
<el-option label="dict" value="dict" />
|
||||||
|
<el-option label="list" value="list" />
|
||||||
</el-select>
|
</el-select>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
|
Reference in New Issue
Block a user