396 lines
23 KiB
Python
396 lines
23 KiB
Python
"""数据模型(与 docs/sql/zkxw-requirements-v0.3-schema.sql 对齐的核心系统表)"""
|
||
from datetime import datetime
|
||
import enum
|
||
|
||
from sqlalchemy import Column, String, DateTime, Integer, Text, CHAR, SmallInteger
|
||
|
||
from app.core.database import Base
|
||
|
||
|
||
class UserRole(str, enum.Enum):
|
||
"""Web 管理端约定角色(由 sys_role.role_name 映射而来,非数据库枚举)"""
|
||
|
||
ADMIN = "admin"
|
||
SUPER_ADMIN = "super_admin"
|
||
|
||
|
||
# =============================================================================
|
||
# V0.3 用户 / 角色 / 菜单(2.1.4 ~ 2.1.6)
|
||
# =============================================================================
|
||
|
||
|
||
class SysUser(Base):
|
||
"""用户表 sys_user(V0.3)"""
|
||
|
||
__tablename__ = "sys_user"
|
||
|
||
id = Column(String(64), primary_key=True, comment="主键ID")
|
||
dept_id = Column(String(64), nullable=True, comment="部门ID")
|
||
user_no = Column(String(30), nullable=False, comment="用户账号")
|
||
nick_name = Column(String(30), nullable=False, comment="用户名")
|
||
email = Column(String(50), nullable=False, default="", comment="用户邮箱")
|
||
phone_no = Column(String(11), nullable=False, default="", comment="手机号码")
|
||
sex = Column(CHAR(1), nullable=True, default="0", comment="用户性别")
|
||
avatar = Column(String(512), nullable=True, comment="头像")
|
||
password = Column("password", String(100), nullable=False, default="", comment="密码")
|
||
status = Column(CHAR(1), nullable=False, default="1", comment="帐号状态 1正常 0停用")
|
||
tenant_no = Column(String(64), nullable=False, default="zkxw", comment="租户编号")
|
||
order_num = Column(Integer, nullable=True, comment="排序号")
|
||
remark = Column(String(512), nullable=True, comment="备注")
|
||
create_by = Column(String(64), nullable=True, comment="创建人id")
|
||
create_dept_id = Column(String(64), nullable=False, default="", comment="创建人部门ID")
|
||
create_time = Column(DateTime, nullable=False, default=datetime.now, comment="创建时间")
|
||
update_by = Column(String(64), nullable=True, comment="更新人id")
|
||
update_time = Column(DateTime, nullable=False, default=datetime.now, onupdate=datetime.now, comment="更新时间")
|
||
del_flag = Column(SmallInteger, nullable=False, default=0, comment="删除标记 0正常 1已删除")
|
||
|
||
|
||
class SysRole(Base):
|
||
"""角色表 sys_role(V0.3)"""
|
||
|
||
__tablename__ = "sys_role"
|
||
|
||
id = Column(String(64), primary_key=True, comment="主键ID")
|
||
role_name = Column(String(30), nullable=False, comment="角色名称")
|
||
data_scope = Column(CHAR(1), nullable=True, default="1", comment="数据权限")
|
||
status = Column(CHAR(1), nullable=False, default="1", comment="角色状态")
|
||
tenant_no = Column(String(64), nullable=False, default="zkxw", comment="租户编号")
|
||
order_num = Column(Integer, nullable=True, comment="排序号")
|
||
remark = Column(String(512), nullable=True, comment="备注")
|
||
create_by = Column(String(64), nullable=True, comment="创建人id")
|
||
create_dept_id = Column(String(64), nullable=False, default="", comment="创建人部门ID")
|
||
create_time = Column(DateTime, nullable=False, default=datetime.now, comment="创建时间")
|
||
update_by = Column(String(64), nullable=True, comment="更新人id")
|
||
update_time = Column(DateTime, nullable=False, default=datetime.now, onupdate=datetime.now, comment="更新时间")
|
||
del_flag = Column(SmallInteger, nullable=False, default=0, comment="删除标记")
|
||
|
||
|
||
class SysUserRole(Base):
|
||
"""用户-角色关联 sys_user_role(V0.3)"""
|
||
|
||
__tablename__ = "sys_user_role"
|
||
|
||
id = Column(String(64), primary_key=True, comment="主键ID")
|
||
user_id = Column(String(64), nullable=False, comment="用户ID")
|
||
role_id = Column(String(64), nullable=False, comment="角色ID")
|
||
tenant_no = Column(String(64), nullable=False, default="zkxw", comment="租户编号")
|
||
order_num = Column(Integer, nullable=True, comment="排序号")
|
||
remark = Column(String(512), nullable=True, comment="备注")
|
||
create_by = Column(String(64), nullable=True, comment="创建人id")
|
||
create_dept_id = Column(String(64), nullable=False, default="", comment="创建人部门ID")
|
||
create_time = Column(DateTime, nullable=False, default=datetime.now, comment="创建时间")
|
||
update_by = Column(String(64), nullable=True, comment="更新人id")
|
||
update_time = Column(DateTime, nullable=False, default=datetime.now, onupdate=datetime.now, comment="更新时间")
|
||
del_flag = Column(SmallInteger, nullable=False, default=0, comment="删除标记")
|
||
|
||
|
||
class SysRoleMenu(Base):
|
||
"""角色-菜单关联 sys_role_menu(V0.3)"""
|
||
|
||
__tablename__ = "sys_role_menu"
|
||
|
||
id = Column(String(64), primary_key=True, comment="主键ID")
|
||
role_id = Column(String(64), nullable=False, comment="角色ID")
|
||
menu_id = Column(String(64), nullable=False, comment="菜单ID")
|
||
tenant_no = Column(String(64), nullable=False, default="zkxw", comment="租户编号")
|
||
order_num = Column(Integer, nullable=True, comment="排序号")
|
||
remark = Column(String(512), nullable=True, comment="备注")
|
||
create_by = Column(String(64), nullable=True, comment="创建人id")
|
||
create_dept_id = Column(String(64), nullable=False, default="", comment="创建人部门ID")
|
||
create_time = Column(DateTime, nullable=False, default=datetime.now, comment="创建时间")
|
||
update_by = Column(String(64), nullable=True, comment="更新人id")
|
||
update_time = Column(DateTime, nullable=False, default=datetime.now, onupdate=datetime.now, comment="更新时间")
|
||
del_flag = Column(SmallInteger, nullable=False, default=0, comment="删除标记")
|
||
|
||
|
||
class SysRoleDataScopeDetail(Base):
|
||
"""角色自定义数据权限明细 sys_role_data_scope_detail"""
|
||
|
||
__tablename__ = "sys_role_data_scope_detail"
|
||
|
||
id = Column(String(64), primary_key=True, comment="主键ID")
|
||
role_id = Column(String(64), nullable=False, comment="角色ID")
|
||
scope_type = Column(String(20), nullable=False, comment="范围类型:dept/user")
|
||
scope_value = Column(String(100), nullable=False, comment="范围值:部门ID/用户ID")
|
||
tenant_no = Column(String(64), nullable=False, default="zkxw", comment="租户编号")
|
||
order_num = Column(Integer, nullable=True, comment="排序号")
|
||
remark = Column(String(512), nullable=True, comment="备注")
|
||
create_by = Column(String(64), nullable=True, comment="创建人id")
|
||
create_dept_id = Column(String(64), nullable=False, default="", comment="创建人部门ID")
|
||
create_time = Column(DateTime, nullable=False, default=datetime.now, comment="创建时间")
|
||
update_by = Column(String(64), nullable=True, comment="更新人id")
|
||
update_time = Column(DateTime, nullable=False, default=datetime.now, onupdate=datetime.now, comment="更新时间")
|
||
del_flag = Column(SmallInteger, nullable=False, default=0, comment="删除标记")
|
||
|
||
|
||
class SysMenu(Base):
|
||
"""菜单表 sys_menu(V0.3)"""
|
||
|
||
__tablename__ = "sys_menu"
|
||
|
||
id = Column(String(64), primary_key=True, comment="主键ID")
|
||
menu_name = Column(String(50), nullable=False, comment="菜单名称")
|
||
parent_id = Column(String(64), nullable=False, default="0", comment="父菜单ID")
|
||
menu_type = Column(CHAR(1), nullable=True, default="M", comment="类型 M目录 C菜单 F按钮")
|
||
path = Column(String(200), nullable=False, default="", comment="路由路径")
|
||
component = Column(String(255), nullable=True, comment="组件路径")
|
||
perms = Column(String(100), nullable=True, comment="权限标识")
|
||
is_frame = Column(Integer, nullable=True, default=1, comment="是否外链")
|
||
visible = Column(CHAR(1), nullable=True, default="1", comment="显示状态")
|
||
status = Column(CHAR(1), nullable=False, default="1", comment="菜单状态")
|
||
tenant_no = Column(String(64), nullable=False, default="zkxw", comment="租户编号")
|
||
order_num = Column(Integer, nullable=True, comment="排序号")
|
||
remark = Column(String(512), nullable=True, comment="备注")
|
||
create_by = Column(String(64), nullable=True, comment="创建人id")
|
||
create_dept_id = Column(String(64), nullable=False, default="", comment="创建人部门ID")
|
||
create_time = Column(DateTime, nullable=False, default=datetime.now, comment="创建时间")
|
||
update_by = Column(String(64), nullable=True, comment="更新人id")
|
||
update_time = Column(DateTime, nullable=False, default=datetime.now, onupdate=datetime.now, comment="更新时间")
|
||
del_flag = Column(SmallInteger, nullable=False, default=0, comment="删除标记")
|
||
|
||
|
||
class SysDept(Base):
|
||
"""组织/部门 sys_dept"""
|
||
|
||
__tablename__ = "sys_dept"
|
||
|
||
id = Column(String(64), primary_key=True, comment="主键ID")
|
||
parent_id = Column(String(64), nullable=False, default="0", comment="父组织id")
|
||
dept_name = Column(String(200), nullable=False, comment="组织名称")
|
||
dept_category_code = Column(String(64), nullable=True, comment="组织类别编码")
|
||
status = Column(CHAR(1), nullable=False, default="1", comment="部门状态")
|
||
leader = Column(String(100), nullable=True, comment="部门负责人")
|
||
leader_phone = Column(String(32), nullable=True, comment="部门负责人联系电话")
|
||
tenant_no = Column(String(64), nullable=False, default="zkxw", comment="租户编号")
|
||
order_num = Column(Integer, nullable=True, comment="排序号")
|
||
remark = Column(String(512), nullable=True, comment="备注")
|
||
create_by = Column(String(64), nullable=True, comment="创建人id")
|
||
create_dept_id = Column(String(64), nullable=False, default="", comment="创建人部门ID")
|
||
create_time = Column(DateTime, nullable=False, default=datetime.now, comment="创建时间")
|
||
update_by = Column(String(64), nullable=True, comment="更新人id")
|
||
update_time = Column(DateTime, nullable=False, default=datetime.now, onupdate=datetime.now, comment="更新时间")
|
||
del_flag = Column(SmallInteger, nullable=False, default=0, comment="删除标记")
|
||
|
||
|
||
class SysTenant(Base):
|
||
"""租户表 sys_tenant(V0.3 2.1.1)"""
|
||
|
||
__tablename__ = "sys_tenant"
|
||
|
||
id = Column(String(64), primary_key=True, comment="主键ID")
|
||
tenant_no = Column(String(64), nullable=False, comment="租户编号(业务编码)")
|
||
tenant_name = Column(String(200), nullable=False, comment="租户名称")
|
||
contact_name = Column(String(100), nullable=True, comment="联系人姓名")
|
||
contact_phone = Column(String(32), nullable=True, comment="联系电话")
|
||
order_num = Column(Integer, nullable=True, comment="排序号")
|
||
remark = Column(String(512), nullable=True, comment="备注")
|
||
create_by = Column(String(64), nullable=True, comment="创建人id")
|
||
create_dept_id = Column(String(64), nullable=False, default="", comment="创建人部门ID")
|
||
create_time = Column(DateTime, nullable=False, default=datetime.now, comment="创建时间")
|
||
update_by = Column(String(64), nullable=True, comment="更新人id")
|
||
update_time = Column(DateTime, nullable=False, default=datetime.now, onupdate=datetime.now, comment="更新时间")
|
||
del_flag = Column(SmallInteger, nullable=False, default=0, comment="删除标记:0-正常 1-已删除")
|
||
|
||
|
||
class SysSite(Base):
|
||
"""站点 sys_site"""
|
||
|
||
__tablename__ = "sys_site"
|
||
|
||
id = Column(String(64), primary_key=True, comment="主键ID")
|
||
site_name = Column(String(200), nullable=False, comment="站点名称")
|
||
site_code = Column(String(64), nullable=False, comment="站点编码")
|
||
site_type = Column(String(64), nullable=True, comment="站点类型")
|
||
status = Column(CHAR(1), nullable=False, default="1", comment="状态")
|
||
address = Column(String(512), nullable=True, comment="详细地址")
|
||
contact_name = Column(String(100), nullable=True, comment="联系人")
|
||
contact_phone = Column(String(32), nullable=True, comment="联系电话")
|
||
business_scope = Column(String(256), nullable=True, comment="业务范围")
|
||
tenant_no = Column(String(64), nullable=False, default="zkxw", comment="租户编号")
|
||
order_num = Column(Integer, nullable=True, comment="排序号")
|
||
remark = Column(String(512), nullable=True, comment="备注")
|
||
create_by = Column(String(64), nullable=True, comment="创建人id")
|
||
create_dept_id = Column(String(64), nullable=False, default="", comment="创建人部门ID")
|
||
create_time = Column(DateTime, nullable=False, default=datetime.now, comment="创建时间")
|
||
update_by = Column(String(64), nullable=True, comment="更新人id")
|
||
update_time = Column(DateTime, nullable=False, default=datetime.now, onupdate=datetime.now, comment="更新时间")
|
||
del_flag = Column(SmallInteger, nullable=False, default=0, comment="删除标记")
|
||
|
||
|
||
class SysPost(Base):
|
||
"""职位 sys_post"""
|
||
|
||
__tablename__ = "sys_post"
|
||
|
||
id = Column(String(64), primary_key=True, comment="主键ID")
|
||
post_name = Column(String(100), nullable=False, comment="职位名称")
|
||
post_code = Column(String(64), nullable=False, comment="职位编码")
|
||
status = Column(CHAR(1), nullable=False, default="1", comment="状态")
|
||
tenant_no = Column(String(64), nullable=False, default="zkxw", comment="租户编号")
|
||
order_num = Column(Integer, nullable=True, comment="排序号")
|
||
remark = Column(String(512), nullable=True, comment="备注")
|
||
create_by = Column(String(64), nullable=True, comment="创建人id")
|
||
create_dept_id = Column(String(64), nullable=False, default="", comment="创建人部门ID")
|
||
create_time = Column(DateTime, nullable=False, default=datetime.now, comment="创建时间")
|
||
update_by = Column(String(64), nullable=True, comment="更新人id")
|
||
update_time = Column(DateTime, nullable=False, default=datetime.now, onupdate=datetime.now, comment="更新时间")
|
||
del_flag = Column(SmallInteger, nullable=False, default=0, comment="删除标记")
|
||
|
||
|
||
class SysUserPost(Base):
|
||
"""用户-职位关联 sys_user_post"""
|
||
|
||
__tablename__ = "sys_user_post"
|
||
|
||
id = Column(String(64), primary_key=True, comment="主键ID")
|
||
user_id = Column(String(64), nullable=False, comment="用户ID")
|
||
post_id = Column(String(64), nullable=False, comment="职位ID")
|
||
tenant_no = Column(String(64), nullable=False, default="zkxw", comment="租户编号")
|
||
order_num = Column(Integer, nullable=True, comment="排序号")
|
||
remark = Column(String(512), nullable=True, comment="备注")
|
||
create_by = Column(String(64), nullable=True, comment="创建人id")
|
||
create_dept_id = Column(String(64), nullable=False, default="", comment="创建人部门ID")
|
||
create_time = Column(DateTime, nullable=False, default=datetime.now, comment="创建时间")
|
||
update_by = Column(String(64), nullable=True, comment="更新人id")
|
||
update_time = Column(DateTime, nullable=False, default=datetime.now, onupdate=datetime.now, comment="更新时间")
|
||
del_flag = Column(SmallInteger, nullable=False, default=0, comment="删除标记")
|
||
|
||
|
||
class BizItemUnit(Base):
|
||
"""物品单位 biz_item_unit"""
|
||
|
||
__tablename__ = "biz_item_unit"
|
||
|
||
id = Column(String(64), primary_key=True, comment="主键ID")
|
||
unit_code = Column(String(64), nullable=False, comment="单位编码")
|
||
unit_name = Column(String(100), nullable=False, comment="单位名称")
|
||
tenant_no = Column(String(64), nullable=False, default="zkxw", comment="租户编号")
|
||
order_num = Column(Integer, nullable=True, comment="排序号")
|
||
remark = Column(String(512), nullable=True, comment="备注")
|
||
create_by = Column(String(64), nullable=True, comment="创建人id")
|
||
create_dept_id = Column(String(64), nullable=False, default="", comment="创建人部门ID")
|
||
create_time = Column(DateTime, nullable=False, default=datetime.now, comment="创建时间")
|
||
update_by = Column(String(64), nullable=True, comment="更新人id")
|
||
update_time = Column(DateTime, nullable=False, default=datetime.now, onupdate=datetime.now, comment="更新时间")
|
||
del_flag = Column(SmallInteger, nullable=False, default=0, comment="删除标记")
|
||
|
||
|
||
class BizExpressCompany(Base):
|
||
"""快递公司 biz_express_company"""
|
||
|
||
__tablename__ = "biz_express_company"
|
||
|
||
id = Column(String(64), primary_key=True, comment="主键ID")
|
||
express_code = Column(String(64), nullable=False, comment="快递公司编码")
|
||
express_name = Column(String(200), nullable=False, comment="快递公司名称")
|
||
tenant_no = Column(String(64), nullable=False, default="zkxw", comment="租户编号")
|
||
order_num = Column(Integer, nullable=True, comment="排序号")
|
||
remark = Column(String(512), nullable=True, comment="备注")
|
||
create_by = Column(String(64), nullable=True, comment="创建人id")
|
||
create_dept_id = Column(String(64), nullable=False, default="", comment="创建人部门ID")
|
||
create_time = Column(DateTime, nullable=False, default=datetime.now, comment="创建时间")
|
||
update_by = Column(String(64), nullable=True, comment="更新人id")
|
||
update_time = Column(DateTime, nullable=False, default=datetime.now, onupdate=datetime.now, comment="更新时间")
|
||
del_flag = Column(SmallInteger, nullable=False, default=0, comment="删除标记")
|
||
|
||
|
||
# =============================================================================
|
||
# 字典管理(sys_dict_type / sys_dict_data)
|
||
# =============================================================================
|
||
|
||
|
||
class SysDictType(Base):
|
||
"""字典类型 sys_dict_type"""
|
||
|
||
__tablename__ = "sys_dict_type"
|
||
|
||
id = Column(String(64), primary_key=True, comment="主键ID")
|
||
dict_name = Column(String(100), nullable=False, default="", comment="字典名称")
|
||
dict_type = Column(String(100), nullable=False, default="", comment="字典类型编码")
|
||
tenant_no = Column(String(64), nullable=False, default="zkxw", comment="租户编号")
|
||
order_num = Column(Integer, nullable=True, comment="排序号")
|
||
remark = Column(String(512), nullable=True, comment="备注")
|
||
create_by = Column(String(64), nullable=True, comment="创建人id")
|
||
create_dept_id = Column(String(64), nullable=False, default="", comment="创建人部门ID")
|
||
create_time = Column(DateTime, nullable=False, default=datetime.now, comment="创建时间")
|
||
update_by = Column(String(64), nullable=True, comment="更新人id")
|
||
update_time = Column(DateTime, nullable=False, default=datetime.now, onupdate=datetime.now, comment="更新时间")
|
||
del_flag = Column(SmallInteger, nullable=False, default=0, comment="删除标记")
|
||
|
||
|
||
class SysDictData(Base):
|
||
"""字典数据 sys_dict_data"""
|
||
|
||
__tablename__ = "sys_dict_data"
|
||
|
||
id = Column(String(64), primary_key=True, comment="主键ID")
|
||
dict_label = Column(String(100), nullable=False, default="", comment="字典标签")
|
||
dict_value = Column(String(100), nullable=False, default="", comment="字典键值")
|
||
dict_type = Column(String(100), nullable=False, default="", comment="字典类型")
|
||
tenant_no = Column(String(64), nullable=False, default="zkxw", comment="租户编号")
|
||
order_num = Column(Integer, nullable=True, comment="排序号")
|
||
remark = Column(String(512), nullable=True, comment="备注")
|
||
create_by = Column(String(64), nullable=True, comment="创建人id")
|
||
create_dept_id = Column(String(64), nullable=False, default="", comment="创建人部门ID")
|
||
create_time = Column(DateTime, nullable=False, default=datetime.now, comment="创建时间")
|
||
update_by = Column(String(64), nullable=True, comment="更新人id")
|
||
update_time = Column(DateTime, nullable=False, default=datetime.now, onupdate=datetime.now, comment="更新时间")
|
||
del_flag = Column(SmallInteger, nullable=False, default=0, comment="删除标记")
|
||
|
||
|
||
# =============================================================================
|
||
# 可选:API 请求日志(不在 V0.3 DDL 内;无表时中间件写入会失败并记录 warning)
|
||
# =============================================================================
|
||
|
||
|
||
class SysApiRequestLog(Base):
|
||
"""API 请求日志"""
|
||
|
||
__tablename__ = "sys_api_request_log"
|
||
|
||
id = Column(String(64), primary_key=True, comment="主键ID")
|
||
http_method = Column(String(10), nullable=False, comment="HTTP 方法")
|
||
path = Column(String(500), nullable=False, comment="请求路径")
|
||
query_string = Column(String(2000), nullable=True, comment="Query 字符串")
|
||
request_body = Column(Text, nullable=True, comment="请求体(截断)")
|
||
response_body = Column(Text, nullable=True, comment="响应体(截断)")
|
||
status_code = Column(Integer, nullable=False, comment="HTTP 状态码")
|
||
duration_ms = Column(Integer, nullable=False, comment="耗时(ms)")
|
||
user_id = Column(String(64), nullable=True, comment="用户ID(JWT 解析)")
|
||
username = Column(String(100), nullable=True, comment="用户名")
|
||
role = Column(String(64), nullable=True, comment="角色")
|
||
ip_address = Column(String(50), nullable=True, comment="IP地址")
|
||
user_agent = Column(String(500), nullable=True, comment="User-Agent")
|
||
is_del = Column(Integer, default=0, comment="是否删除")
|
||
create_at = Column(DateTime, default=datetime.now, comment="创建时间")
|
||
create_by = Column(String(32), nullable=True, comment="创建人ID")
|
||
create_name = Column(String(100), nullable=True, comment="创建人姓名")
|
||
update_at = Column(DateTime, default=datetime.now, onupdate=datetime.now, comment="修改时间")
|
||
update_by = Column(String(32), nullable=True, comment="修改人ID")
|
||
|
||
|
||
class SysApiRequestLogHis(Base):
|
||
"""API 请求日志历史表"""
|
||
|
||
__tablename__ = "sys_api_request_log_his"
|
||
|
||
id = Column(String(64), primary_key=True, nullable=False, comment="主键ID")
|
||
http_method = Column(String(10), nullable=False, comment="HTTP 方法")
|
||
path = Column(String(500), nullable=False, comment="请求路径")
|
||
query_string = Column(String(2000), nullable=True, comment="Query 字符串")
|
||
request_body = Column(Text, nullable=True, comment="请求体(截断)")
|
||
response_body = Column(Text, nullable=True, comment="响应体(截断)")
|
||
status_code = Column(Integer, nullable=False, comment="HTTP 状态码")
|
||
duration_ms = Column(Integer, nullable=False, comment="耗时(ms)")
|
||
user_id = Column(String(64), nullable=True, comment="用户ID")
|
||
username = Column(String(100), nullable=True, comment="用户名")
|
||
role = Column(String(64), nullable=True, comment="角色")
|
||
ip_address = Column(String(50), nullable=True, comment="IP地址")
|
||
user_agent = Column(String(500), nullable=True, comment="User-Agent")
|
||
create_at = Column(DateTime, default=datetime.now, comment="创建时间")
|
||
create_by = Column(String(32), nullable=True, comment="创建人ID")
|
||
create_name = Column(String(100), nullable=True, comment="创建人姓名")
|
||
update_at = Column(DateTime, nullable=True, comment="修改时间")
|
||
update_by = Column(String(32), nullable=True, comment="修改人ID")
|
||
his_create_at = Column(DateTime, default=datetime.now, comment="历史记录创建时间")
|