mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-22 21:06:32 +00:00
- 重构GenTableDao和GenTableColumnDao,继承CRUDBase,添加权限鉴权支持 - 优化分页逻辑,支持非分页时返回完整结果集 - 调整查询条件,支持大小写不敏感模糊查询和时间范围过滤 - 统一接口响应格式,返回SuccessResponse或ErrorResponse - 替换旧的依赖和注解,改用新的认证和日志中间件 - 文档README.en.md和README.md内容格式及示例完善与优化 - alembic/env.py中数据库URL配置优化,增加异常检测保障环境配置正确 - 代码生成控制器genController新增代码批量生成下载流和本地生成文件覆盖检测 - 删除或更新废弃代码,清理无用导入,提升项目整体代码质量和可维护性
82 lines
5.8 KiB
Python
82 lines
5.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
from datetime import datetime
|
|
from typing import Optional, List
|
|
from sqlalchemy import String, Integer, Text, DateTime, Boolean, ForeignKey, text
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship, declared_attr
|
|
|
|
from app.core.base_model import CreatorMixin
|
|
|
|
|
|
class GenTableModel(CreatorMixin):
|
|
"""
|
|
代码生成表
|
|
"""
|
|
|
|
@declared_attr.directive
|
|
def __tablename__(cls) -> str:
|
|
return 'gen_table'
|
|
|
|
@declared_attr.directive
|
|
def __table_args__(cls) -> dict:
|
|
return {'comment': '代码生成表'}
|
|
|
|
table_name: Mapped[Optional[str]] = mapped_column(String(200), nullable=True, default='', comment='表名称')
|
|
table_comment: Mapped[Optional[str]] = mapped_column(String(500), nullable=True, default='', comment='表描述')
|
|
sub_table_name: Mapped[Optional[str]] = mapped_column(String(64), nullable=True, comment='关联子表的表名')
|
|
sub_table_fk_name: Mapped[Optional[str]] = mapped_column(String(64), nullable=True, comment='子表关联的外键名')
|
|
class_name: Mapped[Optional[str]] = mapped_column(String(100), nullable=True, default='', comment='实体类名称')
|
|
tpl_category: Mapped[Optional[str]] = mapped_column(String(200), nullable=True, default='crud', comment='使用的模板(crud单表操作 tree树表操作)')
|
|
tpl_web_type: Mapped[Optional[str]] = mapped_column(String(30), nullable=True, default='', comment='前端模板类型(element-ui模版 element-plus模版)')
|
|
package_name: Mapped[Optional[str]] = mapped_column(String(100), nullable=True, comment='生成包路径')
|
|
module_name: Mapped[Optional[str]] = mapped_column(String(30), nullable=True, comment='生成模块名')
|
|
business_name: Mapped[Optional[str]] = mapped_column(String(30), nullable=True, comment='生成业务名')
|
|
function_name: Mapped[Optional[str]] = mapped_column(String(100), nullable=True, comment='生成功能名')
|
|
function_author: Mapped[Optional[str]] = mapped_column(String(100), nullable=True, comment='生成功能作者')
|
|
gen_type: Mapped[Optional[str]] = mapped_column(String(1), nullable=True, default='0', comment='生成代码方式(0zip压缩包 1自定义路径)')
|
|
gen_path: Mapped[Optional[str]] = mapped_column(String(200), nullable=True, default='/', comment='生成路径(不填默认项目路径)')
|
|
options: Mapped[Optional[str]] = mapped_column(String(1000), nullable=True, comment='其它生成选项')
|
|
|
|
del_flag: Mapped[str] = mapped_column(String(1), nullable=False, default='0', server_default=text("'0'"), comment='删除标志(0代表存在 2代表删除)')
|
|
create_by: Mapped[Optional[str]] = mapped_column(String(64), default='', comment='创建者')
|
|
create_time: Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True, default=None, comment='创建时间')
|
|
update_by: Mapped[Optional[str]] = mapped_column(String(64), default='', comment='更新者')
|
|
update_time: Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True, default=None, comment='更新时间')
|
|
remark: Mapped[Optional[str]] = mapped_column(Text, nullable=True, default=None, comment='备注')
|
|
|
|
columns: Mapped[List['GenTableColumnModel']] = relationship('GenTableColumnModel', order_by='GenTableColumnModel.sort', back_populates='table')
|
|
|
|
|
|
class GenTableColumnModel(CreatorMixin):
|
|
"""
|
|
代码生成表字段
|
|
"""
|
|
|
|
@declared_attr.directive
|
|
def __tablename__(cls) -> str:
|
|
return 'gen_table_column'
|
|
|
|
@declared_attr.directive
|
|
def __table_args__(cls) -> dict:
|
|
return {'comment': '代码生成表字段'}
|
|
|
|
table_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey('gen_table.id'), nullable=True, comment='归属表编号')
|
|
column_name: Mapped[Optional[str]] = mapped_column(String(200), nullable=True, comment='列名称')
|
|
column_comment: Mapped[Optional[str]] = mapped_column(String(500), nullable=True, comment='列描述')
|
|
column_type: Mapped[Optional[str]] = mapped_column(String(100), nullable=True, comment='列类型')
|
|
python_type: Mapped[Optional[str]] = mapped_column(String(500), nullable=True, comment='PYTHON类型')
|
|
python_field: Mapped[Optional[str]] = mapped_column(String(200), nullable=True, comment='PYTHON字段名')
|
|
is_pk: Mapped[Optional[str]] = mapped_column(String(1), nullable=True, comment='是否主键(1是)')
|
|
is_increment: Mapped[Optional[str]] = mapped_column(String(1), nullable=True, comment='是否自增(1是)')
|
|
is_required: Mapped[Optional[str]] = mapped_column(String(1), nullable=True, comment='是否必填(1是)')
|
|
is_unique: Mapped[Optional[str]] = mapped_column(String(1), nullable=True, comment='是否唯一(1是)')
|
|
is_insert: Mapped[Optional[str]] = mapped_column(String(1), nullable=True, comment='是否为插入字段(1是)')
|
|
is_edit: Mapped[Optional[str]] = mapped_column(String(1), nullable=True, comment='是否编辑字段(1是)')
|
|
is_list: Mapped[Optional[str]] = mapped_column(String(1), nullable=True, comment='是否列表字段(1是)')
|
|
is_query: Mapped[Optional[str]] = mapped_column(String(1), nullable=True, comment='是否查询字段(1是)')
|
|
query_type: Mapped[Optional[str]] = mapped_column(String(200), nullable=True, default='EQ', comment='查询方式(等于、不等于、大于、小于、范围)')
|
|
html_type: Mapped[Optional[str]] = mapped_column(String(200), nullable=True, comment='显示类型(文本框、文本域、下拉框、复选框、单选框、日期控件)')
|
|
dict_type: Mapped[Optional[str]] = mapped_column(String(200), nullable=True, default='', comment='字典类型')
|
|
sort: Mapped[Optional[int]] = mapped_column(Integer, nullable=True, comment='排序')
|
|
|
|
table: Mapped['GenTableModel'] = relationship('GenTableModel', back_populates='columns') |