mirror of
https://github.com/fastapi-practices/fastapi_best_architecture.git
synced 2026-03-13 09:31:31 +08:00
* fix: 修复PostgreSQL SQL语法错误,将反引号替换为双引号 * feat: 新增雪花算法ID实现 * 优化雪花算法和主键类型 * 修复错误引用 * 添加雪花详情链接 * feat: add snowflake ID parser method * 修复独立执行异常 * 更新系统时间错误类
42 lines
1.7 KiB
Python
42 lines
1.7 KiB
Python
#!/usr/bin/env python3
|
||
# -*- coding: utf-8 -*-
|
||
from __future__ import annotations
|
||
|
||
from typing import TYPE_CHECKING, Optional
|
||
|
||
from sqlalchemy import BigInteger, Boolean, ForeignKey, String
|
||
from sqlalchemy.dialects.postgresql import INTEGER
|
||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||
|
||
from backend.common.model import Base, id_key
|
||
|
||
if TYPE_CHECKING:
|
||
from backend.app.admin.model import User
|
||
|
||
|
||
class Dept(Base):
|
||
"""部门表"""
|
||
|
||
__tablename__ = 'sys_dept'
|
||
|
||
id: Mapped[id_key] = mapped_column(init=False)
|
||
name: Mapped[str] = mapped_column(String(50), comment='部门名称')
|
||
sort: Mapped[int] = mapped_column(default=0, comment='排序')
|
||
leader: Mapped[str | None] = mapped_column(String(20), default=None, comment='负责人')
|
||
phone: Mapped[str | None] = mapped_column(String(11), default=None, comment='手机')
|
||
email: Mapped[str | None] = mapped_column(String(50), default=None, comment='邮箱')
|
||
status: Mapped[int] = mapped_column(default=1, comment='部门状态(0停用 1正常)')
|
||
del_flag: Mapped[bool] = mapped_column(
|
||
Boolean().with_variant(INTEGER, 'postgresql'), default=False, comment='删除标志(0删除 1存在)'
|
||
)
|
||
|
||
# 父级部门一对多
|
||
parent_id: Mapped[int | None] = mapped_column(
|
||
BigInteger, ForeignKey('sys_dept.id', ondelete='SET NULL'), default=None, index=True, comment='父部门ID'
|
||
)
|
||
parent: Mapped[Optional['Dept']] = relationship(init=False, back_populates='children', remote_side=[id])
|
||
children: Mapped[Optional[list['Dept']]] = relationship(init=False, back_populates='parent')
|
||
|
||
# 部门用户一对多
|
||
users: Mapped[list[User]] = relationship(init=False, back_populates='dept')
|