feat: 初始化仓库

This commit is contained in:
2025-02-12 02:38:29 +08:00
commit 46e9e79670
67 changed files with 8960 additions and 0 deletions

155
models/department.py Normal file
View File

@@ -0,0 +1,155 @@
# _*_ coding : UTF-8 _*_
# @Time : 2025/01/18 03:21
# @UpdateTime : 2025/01/18 03:21
# @Author : sonder
# @File : department.py
# @Software : PyCharm
# @Comment : 本程序
from tortoise import fields
from models.common import BaseModel
class Department(BaseModel):
"""
部门表模型。
"""
name = fields.CharField(
max_length=100,
description="部门名称",
source_field="name" # 映射到数据库字段 name
)
"""
部门名称。
- 最大长度为 100 个字符。
- 映射到数据库字段 name。
"""
parent_id = fields.CharField(
max_length=36,
default="",
null=True,
description="父部门ID",
source_field="parent_id" # 映射到数据库字段 parent_id
)
"""
父部门ID。
- 用于表示部门的层级关系。
- 默认为空字符串,表示顶级部门。
- 映射到数据库字段 parent_id。
"""
sort = fields.IntField(
default=0,
description="排序权重0最高",
source_field="sort" # 映射到数据库字段 sort
)
"""
排序权重。
- 用于部门列表的排序,值越小越靠前。
- 默认为 0。
- 映射到数据库字段 sort。
"""
phone = fields.CharField(
max_length=30,
null=True,
description="部门电话",
source_field="phone" # 映射到数据库字段 phone
)
"""
部门电话。
- 最大长度为 30 个字符。
- 允许为空。
- 映射到数据库字段 phone。
"""
principal = fields.CharField(
max_length=64,
description="部门负责人",
source_field="principal" # 映射到数据库字段 principal
)
"""
部门负责人。
- 最大长度为 64 个字符。
- 映射到数据库字段 principal。
"""
email = fields.CharField(
max_length=128,
null=True,
description="部门邮箱",
source_field="email" # 映射到数据库字段 email
)
"""
部门邮箱。
- 最大长度为 128 个字符。
- 允许为空。
- 映射到数据库字段 email。
"""
status = fields.SmallIntField(
default=1,
description="状态0正常 1停用",
source_field="status" # 映射到数据库字段 status
)
"""
状态。
- 1 表示正常0 表示停用。
- 默认为 1。
- 映射到数据库字段 status。
"""
remark = fields.CharField(
max_length=255,
null=True,
description="备注信息",
source_field="remark" # 映射到数据库字段 remark
)
"""
备注信息。
- 最大长度为 255 个字符。
- 允许为空。
- 映射到数据库字段 remark。
"""
class Meta:
table = "department" # 数据库表名
table_description = "部门表" # 表描述
ordering = ["sort", "-create_time"] # 默认按排序权重和创建时间排序
class DepartmentRole(BaseModel):
"""
部门角色表模型。
"""
department = fields.ForeignKeyField(
"models.Department",
related_name="department_roles",
description="部门ID",
source_field="department_id" # 映射到数据库字段 department_id
)
"""
部门ID。
- 外键关联到 Department 表。
- 映射到数据库字段 department_id。
"""
role = fields.ForeignKeyField(
"models.Role",
related_name="department_roles",
description="角色ID",
source_field="role_id" # 映射到数据库字段 role_id
)
"""
角色ID。
- 外键关联到 Role 表。
- 映射到数据库字段 role_id。
"""
class Meta:
table = "department_role" # 数据库表名
table_description = "部门角色表" # 表描述
unique_together = (("department_id", "role_id"),) # 唯一约束,防止重复分配