from datetime import datetime from typing import Optional from sqlalchemy import BigInteger, String, DateTime, Integer from sqlalchemy.orm import Mapped, mapped_column, DeclarativeBase from app.database import Base class TenantEntity(Base): __abstract__ = True id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=False, comment="主键ID") tenant_id: Mapped[Optional[str]] = mapped_column(String(20), default="000000", comment="租户编号") create_dept: Mapped[Optional[int]] = mapped_column(BigInteger, comment="创建部门") create_by: Mapped[Optional[int]] = mapped_column(BigInteger, comment="创建者") create_time: Mapped[Optional[datetime]] = mapped_column(DateTime, comment="创建时间") update_by: Mapped[Optional[int]] = mapped_column(BigInteger, comment="更新者") update_time: Mapped[Optional[datetime]] = mapped_column(DateTime, comment="更新时间") del_flag: Mapped[Optional[int]] = mapped_column(Integer, default=0, comment="删除标志(0代表存在 2代表删除)") class SysUser(Base): __tablename__ = "sys_user" user_id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=False) dept_id: Mapped[Optional[int]] = mapped_column(BigInteger, comment="部门ID") tenant_id: Mapped[Optional[str]] = mapped_column(String(20), default="000000") user_name: Mapped[str] = mapped_column(String(30), comment="用户账号") nick_name: Mapped[str] = mapped_column(String(30), default="", comment="用户昵称") user_type: Mapped[str] = mapped_column(String(10), default="sys_user", comment="用户类型") account_type: Mapped[Optional[str]] = mapped_column(String(255), default="1", comment="账号类型(1职工 2学生)") email: Mapped[Optional[str]] = mapped_column(String(50), default="", comment="用户邮箱") phonenumber: Mapped[Optional[str]] = mapped_column(String(11), default="", comment="手机号码") sex: Mapped[str] = mapped_column(String(1), default="0", comment="用户性别") avatar: Mapped[Optional[str]] = mapped_column(String(500), default="", comment="头像地址") password: Mapped[str] = mapped_column(String(100), default="", comment="密码") status: Mapped[str] = mapped_column(String(1), default="0", comment="帐号状态(0正常 1停用)") del_flag: Mapped[str] = mapped_column(String(1), default="0", comment="删除标志(0代表存在 2代表删除)") login_ip: Mapped[Optional[str]] = mapped_column(String(128), default="", comment="最后登录IP") login_date: Mapped[Optional[datetime]] = mapped_column(DateTime, comment="最后登录时间") create_by: Mapped[Optional[int]] = mapped_column(BigInteger, comment="创建者") create_time: Mapped[Optional[datetime]] = mapped_column(DateTime, comment="创建时间") update_by: Mapped[Optional[int]] = mapped_column(BigInteger, comment="更新者") update_time: Mapped[Optional[datetime]] = mapped_column(DateTime, comment="更新时间") remark: Mapped[Optional[str]] = mapped_column(String(500), comment="备注") class SysDept(Base): __tablename__ = "sys_dept" dept_id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=False) parent_id: Mapped[int] = mapped_column(BigInteger, default=0, comment="父部门ID") ancestors: Mapped[str] = mapped_column(String(255), default="", comment="祖级列表") dept_name: Mapped[str] = mapped_column(String(30), default="", comment="部门名称") dept_category: Mapped[Optional[str]] = mapped_column(String(100), comment="部门类别") order_num: Mapped[int] = mapped_column(Integer, default=0, comment="显示顺序") leader: Mapped[Optional[int]] = mapped_column(BigInteger, comment="负责人(用户ID)") phone: Mapped[Optional[str]] = mapped_column(String(11), default="", comment="联系电话") email: Mapped[Optional[str]] = mapped_column(String(50), default="", comment="邮箱") status: Mapped[str] = mapped_column(String(1), default="0", comment="部门状态(0正常 1停用)") del_flag: Mapped[str] = mapped_column(String(1), default="0", comment="删除标志(0代表存在 2代表删除)") tenant_id: Mapped[Optional[str]] = mapped_column(String(20), default="000000") create_by: Mapped[Optional[int]] = mapped_column(BigInteger) create_time: Mapped[Optional[datetime]] = mapped_column(DateTime) update_by: Mapped[Optional[int]] = mapped_column(BigInteger) update_time: Mapped[Optional[datetime]] = mapped_column(DateTime) class SysDictData(Base): __tablename__ = "sys_dict_data" dict_code: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=False) tenant_id: Mapped[Optional[str]] = mapped_column(String(20), default="000000") dict_sort: Mapped[int] = mapped_column(Integer, default=0, comment="字典排序") dict_label: Mapped[str] = mapped_column(String(100), default="", comment="字典标签") dict_value: Mapped[str] = mapped_column(String(100), default="", comment="字典键值") dict_type: Mapped[str] = mapped_column(String(100), default="", comment="字典类型") css_class: Mapped[Optional[str]] = mapped_column(String(100), default="", comment="样式属性") list_class: Mapped[str] = mapped_column(String(100), default="", comment="表格回显样式") is_default: Mapped[str] = mapped_column(String(1), default="N", comment="是否默认(Y是 N否)") create_dept: Mapped[Optional[int]] = mapped_column(BigInteger, comment="创建部门") create_by: Mapped[Optional[int]] = mapped_column(BigInteger) create_time: Mapped[Optional[datetime]] = mapped_column(DateTime) update_by: Mapped[Optional[int]] = mapped_column(BigInteger) update_time: Mapped[Optional[datetime]] = mapped_column(DateTime) remark: Mapped[Optional[str]] = mapped_column(String(500), comment="备注") class SysDictType(Base): __tablename__ = "sys_dict_type" dict_id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=False) tenant_id: Mapped[Optional[str]] = mapped_column(String(20), default="000000") dict_name: Mapped[str] = mapped_column(String(100), default="", comment="字典名称") dict_type: Mapped[str] = mapped_column(String(100), default="", comment="字典类型") status: Mapped[str] = mapped_column(String(1), default="0", comment="状态(0正常 1停用)") create_by: Mapped[Optional[int]] = mapped_column(BigInteger) create_time: Mapped[Optional[datetime]] = mapped_column(DateTime) update_by: Mapped[Optional[int]] = mapped_column(BigInteger) update_time: Mapped[Optional[datetime]] = mapped_column(DateTime) remark: Mapped[Optional[str]] = mapped_column(String(500), comment="备注") class SysOss(Base): __tablename__ = "sys_oss" oss_id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=False) tenant_id: Mapped[Optional[str]] = mapped_column(String(20), default="000000") file_name: Mapped[str] = mapped_column(String(500), default="", comment="文件名") original_name: Mapped[str] = mapped_column(String(500), default="", comment="原名") file_suffix: Mapped[str] = mapped_column(String(10), default="", comment="文件后缀名") url: Mapped[str] = mapped_column(String(500), comment="URL地址") create_by: Mapped[Optional[int]] = mapped_column(BigInteger) create_time: Mapped[Optional[datetime]] = mapped_column(DateTime) update_by: Mapped[Optional[int]] = mapped_column(BigInteger) update_time: Mapped[Optional[datetime]] = mapped_column(DateTime) service: Mapped[Optional[str]] = mapped_column(String(20), default="minio", comment="服务商") class SysTenant(Base): __tablename__ = "sys_tenant" id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=False) tenant_id: Mapped[str] = mapped_column(String(20), comment="租户编号") contact_user_name: Mapped[Optional[str]] = mapped_column(String(30), comment="联系人") contact_phone: Mapped[Optional[str]] = mapped_column(String(20), comment="联系电话") company_name: Mapped[str] = mapped_column(String(50), comment="企业名称") license_number: Mapped[Optional[str]] = mapped_column(String(30), comment="统一社会信用代码") address: Mapped[Optional[str]] = mapped_column(String(200), comment="地址") domain: Mapped[Optional[str]] = mapped_column(String(200), comment="域名") intro: Mapped[Optional[str]] = mapped_column(String(200), comment="企业简介") remark: Mapped[Optional[str]] = mapped_column(String(500), comment="备注") package_id: Mapped[Optional[int]] = mapped_column(BigInteger, comment="租户套餐ID") expire_time: Mapped[Optional[datetime]] = mapped_column(DateTime, comment="过期时间") account_count: Mapped[int] = mapped_column(Integer, default=0, comment="账号数量") status: Mapped[str] = mapped_column(String(1), default="0", comment="状态(0正常 1停用)") del_flag: Mapped[str] = mapped_column(String(1), default="0") create_by: Mapped[Optional[int]] = mapped_column(BigInteger) create_time: Mapped[Optional[datetime]] = mapped_column(DateTime) update_by: Mapped[Optional[int]] = mapped_column(BigInteger) update_time: Mapped[Optional[datetime]] = mapped_column(DateTime) class SysRole(Base): __tablename__ = "sys_role" role_id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=False) tenant_id: Mapped[Optional[str]] = mapped_column(String(20), default="000000") role_name: Mapped[str] = mapped_column(String(30), comment="角色名称") role_key: Mapped[str] = mapped_column(String(100), comment="角色权限字符串") role_sort: Mapped[int] = mapped_column(Integer, default=0, comment="显示顺序") data_scope: Mapped[str] = mapped_column(String(1), default="1", comment="数据范围(1:全部数据权限 2:自定数据权限 3:本部门数据权限 4:本部门及以下数据权限 5:仅本人)") menu_check_strictly: Mapped[int] = mapped_column(Integer, default=1, comment="菜单树选择项是否关联显示") dept_check_strictly: Mapped[int] = mapped_column(Integer, default=1, comment="部门树选择项是否关联显示") status: Mapped[str] = mapped_column(String(1), default="0", comment="状态") del_flag: Mapped[str] = mapped_column(String(1), default="0") create_by: Mapped[Optional[int]] = mapped_column(BigInteger) create_time: Mapped[Optional[datetime]] = mapped_column(DateTime) update_by: Mapped[Optional[int]] = mapped_column(BigInteger) update_time: Mapped[Optional[datetime]] = mapped_column(DateTime) remark: Mapped[Optional[str]] = mapped_column(String(500)) class SysMenu(Base): __tablename__ = "sys_menu" menu_id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=False) menu_name: Mapped[str] = mapped_column(String(50), comment="菜单名称") parent_id: Mapped[int] = mapped_column(BigInteger, default=0, comment="父菜单ID") order_num: Mapped[int] = mapped_column(Integer, default=0, comment="显示顺序") path: Mapped[Optional[str]] = mapped_column(String(200), default="", comment="路由地址") component: Mapped[Optional[str]] = mapped_column(String(255), default="", comment="组件路径") query_param: Mapped[Optional[str]] = mapped_column(String(255), default="", comment="路由参数") is_frame: Mapped[int] = mapped_column(Integer, default=1, comment="是否为外链(0是 1否)") is_cache: Mapped[int] = mapped_column(Integer, default=0, comment="是否缓存(0缓存 1不缓存)") menu_type: Mapped[str] = mapped_column(String(1), default="M", comment="菜单类型(M目录 C菜单 F按钮)") visible: Mapped[str] = mapped_column(String(1), default="0", comment="显示状态(0显示 1隐藏)") status: Mapped[str] = mapped_column(String(1), default="0", comment="状态(0正常 1停用)") perms: Mapped[Optional[str]] = mapped_column(String(100), comment="权限标识") icon: Mapped[Optional[str]] = mapped_column(String(100), default="#", comment="菜单图标") create_by: Mapped[Optional[int]] = mapped_column(BigInteger) create_time: Mapped[Optional[datetime]] = mapped_column(DateTime) update_by: Mapped[Optional[int]] = mapped_column(BigInteger) update_time: Mapped[Optional[datetime]] = mapped_column(DateTime) remark: Mapped[Optional[str]] = mapped_column(String(500)) class SysUserRole(Base): __tablename__ = "sys_user_role" user_id: Mapped[int] = mapped_column(BigInteger, primary_key=True) role_id: Mapped[int] = mapped_column(BigInteger, primary_key=True) class SysRoleMenu(Base): __tablename__ = "sys_role_menu" role_id: Mapped[int] = mapped_column(BigInteger, primary_key=True) menu_id: Mapped[int] = mapped_column(BigInteger, primary_key=True)