from sqlalchemy import create_engine, Column, Integer, String, ForeignKey, DateTime, Table, MetaData,Text from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import relationship, sessionmaker from datetime import datetime Base = declarative_base() metadata = MetaData() from sqlalchemy import Column, Integer, String, Text, DateTime, ForeignKey from sqlalchemy.orm import relationship class KnowledgeFile(Base): __tablename__ = 'knowledge_file' id = Column(Integer, primary_key=True, autoincrement=True, comment="id") file_identifier = Column(String(50), unique=True, nullable=False, comment='文件唯一标识符') file_path = Column(Text, nullable=False, comment='文件路径') file_name = Column(String(255), nullable=False, comment='文件名字') is_deleted = Column(Integer, default=0, comment='是否删除') createTime = Column(DateTime, comment='创建时间') updateTime = Column(DateTime, comment='更新时间') storage_file_name = Column(Text,comment = '文件存储名字') knowledge_base_code = Column(String(50), ForeignKey('knowledge_base.base_code'), nullable=False) knowledge_base = relationship("KnowledgeBase", back_populates="files") class KnowledgeBase(Base): __tablename__ = 'knowledge_base' id = Column(Integer, primary_key=True, autoincrement=True, comment="id") reportId = Column(String(255),comment='报告ID') reportUid = Column(String(255),comment='报告UUID') reportName = Column(String(400), comment='报告名称') subject = Column(String(100), comment='主题词') eventType = Column(String(10), comment='事件类型') publishDate = Column(DateTime, comment='发布日期') publishingUnit = Column(String(255), comment='来源单位') summary = Column(String(100), comment='摘要') notificationType = Column(String(100), comment='知识类型') updateTime = Column(DateTime, comment='更新时间') base_code = Column(String(50), unique=True, comment='知识库的基础编码') del_flag = Column(String(10), comment='是否删除') files = relationship("KnowledgeFile", order_by=KnowledgeFile.id, back_populates="knowledge_base") class HazardStandardsFile(Base): __tablename__ = 'hazard_standards_file' id = Column(Integer, primary_key=True, autoincrement=True) file_id = Column(String(50), nullable=False, comment='文件id')#uuid file_number = Column(String(50), nullable=False, comment='文件编号')#YHBZ+10位随机数字 file_name = Column(String(255), nullable=False, comment='文件名称')#url standard_type = Column(String(255), nullable=False, comment='标准类型 1国家版,2广东省版')#标准类型 file_name_desc = Column(String(255), nullable=False, comment='文件名称原名')#name file_title = Column(String(255), nullable=False, comment='标准文件名称')#name file_path = Column(String(255), nullable=True, comment='文件存储路径') file_size = Column(String(50), nullable=True, comment='文件大小') status = Column(String(50), nullable=True, comment='文件状态') foreign_key = Column(String(50), nullable=True, comment='文件外键 --技术字段') from_scenario = Column(String(50), nullable=True, comment='对应标识 --技术字段') del_flag = Column(String(1), default='0', comment='删除标志(0代表存在 2代表删除)') create_dept = Column(Integer, default=None, comment='创建部门') create_by = Column(Integer, default=None, comment='创建者') create_time = Column(DateTime, default=datetime.now, comment='创建时间') update_time = Column(DateTime, default=datetime.now, onupdate=datetime.now, comment='更新时间')