Files
fastapi-best-architecture/backend/app/models/sys_dept.py
T
Wu Clan 6c5e7a6881 Add department-related interfaces and others (#101)
* Add tool to build tree structure data

* Update to keyword parameter style

* Add department-related interfaces

* Update departmental section interface permissions

* Add TODO and minor fixes

* Fix department relationships

* Fix user foreign key relationship deletion setting

* Add path parameters to the operation log

* Complete todo items

* Update department deletion logic

* Update operation log entry records

* Add AES encryption algorithm

* Add operation log request entry to the secret

* Fix naming prefixes

* Add easy encryption tools

* FIX CASBIN_EXCLUDE typing

* Update user password reset interface

* Add confirm_password to the operation log encryption
2023-06-09 11:00:13 +08:00

33 lines
1.5 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from typing import Union
from sqlalchemy import String, ForeignKey
from sqlalchemy.orm import Mapped, mapped_column, relationship
from backend.app.database.base_class import Base, id_key
class Dept(Base):
"""部门表"""
__tablename__ = 'sys_dept'
id: Mapped[id_key] = mapped_column(init=False)
name: Mapped[str] = mapped_column(String(50), unique=True, comment='部门名称')
level: Mapped[int] = mapped_column(default=0, 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[bool] = mapped_column(default=True, comment='部门状态(0停用 1正常)')
del_flag: Mapped[bool] = mapped_column(default=False, comment='删除标志(0删除 1存在)')
parent_id: Mapped[int | None] = mapped_column(
ForeignKey('sys_dept.id', ondelete='SET NULL'), default=None, index=True, comment='父部门ID'
)
# 父级部门一对多
parent: Mapped[Union['Dept', None]] = relationship(init=False, back_populates='children', remote_side=[id])
children: Mapped[list['Dept'] | None] = relationship(init=False, back_populates='parent')
# 部门用户一对多
users: Mapped[list['User']] = relationship(init=False, back_populates='dept') # noqa: F821