29 lines
1.1 KiB
Python
29 lines
1.1 KiB
Python
|
|
"""部门/分组模型。"""
|
|||
|
|
from sqlalchemy import Column, Integer, String, Text, TIMESTAMP, func
|
|||
|
|
from insurance.db.compat import db
|
|||
|
|
|
|||
|
|
|
|||
|
|
class Department(db.Model):
|
|||
|
|
"""部门/分组表。"""
|
|||
|
|
__tablename__ = "insurance_departments"
|
|||
|
|
|
|||
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|||
|
|
name = Column(String(128), nullable=False, comment="部门名称")
|
|||
|
|
code = Column(String(64), unique=True, nullable=False, comment="部门编码")
|
|||
|
|
parent_id = Column(Integer, default=0, comment="上级部门ID,0表示顶级")
|
|||
|
|
description = Column(String(256), default="", comment="部门描述")
|
|||
|
|
sort_order = Column(Integer, default=0, comment="排序")
|
|||
|
|
created_at = Column(TIMESTAMP, server_default=func.now())
|
|||
|
|
updated_at = Column(TIMESTAMP, server_default=func.now(), onupdate=func.now())
|
|||
|
|
|
|||
|
|
def to_dict(self):
|
|||
|
|
return {
|
|||
|
|
"id": self.id,
|
|||
|
|
"name": self.name,
|
|||
|
|
"code": self.code,
|
|||
|
|
"parent_id": self.parent_id,
|
|||
|
|
"description": self.description,
|
|||
|
|
"sort_order": self.sort_order,
|
|||
|
|
"created_at": str(self.created_at) if self.created_at else None,
|
|||
|
|
}
|