# -*- coding: utf-8 -*- from sqlalchemy import String, Column, Integer,DateTime,Text,BigInteger,Boolean,PrimaryKeyConstraint,Index,UniqueConstraint,CHAR,LargeBinary,TIMESTAMP,ForeignKey,Numeric from sqlalchemy.dialects.mysql import TINYINT from sqlalchemy.orm import relationship from sqlalchemy.sql import func from database import Base from datetime import datetime class EmergencyPlan(Base): __tablename__ = 'emergency_plans' # 表名 # 定义字段 id = Column(Integer, autoincrement=True, primary_key=True) # 主键 plan_id = Column(String(50),comment='预案uid') plan_number = Column(String(15), comment='预案编号') plan_name = Column(String(255), nullable=False, comment='预案名称') plan_type = Column(String(100), nullable=False, comment='预案类型') plan_type_desc = Column(String(100), comment='预案类型(中文名称)') publish_date = Column(DateTime, default=datetime.now, comment='发布日期') organizing_unit = Column(String(255), comment='编制单位') document_number = Column(String(100), comment='发文字号') create_time = Column(DateTime, default=datetime.now, comment='数据创建时间') update_time = Column(DateTime, default=datetime.now, onupdate=datetime.now, comment='数据更新时间') create_dept = Column(BigInteger, default=None, comment='创建部门') create_by = Column(BigInteger, default=None, comment='创建者') del_flag = Column(String(1), default='0', comment='删除标志(0代表存在 2代表删除)') response_level = Column(String(2), comment='响应级别') event_type = Column(String(10), comment='对应事件类型') class Config: orm_mode = True # def create_new_plan_with_number(session, name): # new_plan = EmergencyPlan( # name=name # ) # session.add(new_plan) # session.commit() # session.refresh(new_plan) # 刷新实例以获取数据库分配的 id # new_plan.plan_number = f'YJYA{str(new_plan.id).zfill(10)}' # session.commit() # return new_plan class EmergencyFile(Base): __tablename__ = 'emergency_file' id = Column(Integer, autoincrement=True, primary_key=True) file_id = Column(String(50), nullable=False, comment='文件id') file_name = Column(String(255), nullable=False, comment='文件名称') file_name_desc = Column(String(255), nullable=False, comment='文件名称原名') file_path = Column(String(255), comment='文件存储路径') file_size = Column(String(50), comment='文件大小') status = Column(String(50), comment='文件状态') foreign_key = Column(String(50), comment='文件外键 --技术字段') from_scenario = Column(String(50), comment='对应标识 --技术字段') create_time = Column(DateTime, default=datetime.now, comment='数据创建时间') update_time = Column(DateTime, default=datetime.now, onupdate=datetime.now, comment='数据更新时间') create_dept = Column(BigInteger, default=None, comment='创建部门') create_by = Column(BigInteger, default=None, comment='创建者') del_flag = Column(String(1), default='0', comment='删除标志(0代表存在 2代表删除)') #更新预案信息的时候 先将原有的进行备注删除 # 关联到 EmergencyPlan 实例 class Config: orm_mode = True class EmergencyDrill(Base): __tablename__ = 'emergency_drills' id = Column(Integer, autoincrement=True, primary_key=True) drill_id = Column(String(50), comment='演练uid' ) drill_name = Column(String(255), nullable=False, comment='演练名称') organizing_unit = Column(String(255), nullable=False, comment='演练单位') plan_number = Column(String(50), nullable=False,comment='预案编号') # 前端确认传输什么数据 drill_location = Column(String(255), comment='演练地点') drillProject = Column(String(255), comment='演练方案') drill_lon = Column(Numeric(9, 6), comment='演练经度') drill_lat = Column(Numeric(9, 6), comment='演练纬度') planned_annual = Column(Integer, comment='计划年度') planned_time = Column(DateTime, comment='计划演练时间') create_time = Column(DateTime, default=datetime.now, comment='数据创建时间') update_time = Column(DateTime, default=datetime.now, onupdate=datetime.now, comment='数据更新时间') create_dept = Column(BigInteger, default=None, comment='创建部门') create_by = Column(BigInteger, default=None, comment='创建者') del_flag = Column(String(1), default='0', comment='删除标志(0代表存在 2代表删除)') class Config: orm_mode = True class EmergencyTrainingSession(Base): __tablename__ = 'emergency_training_sessions' id = Column(Integer, autoincrement=True, primary_key=True) training_id = Column(String(50), nullable=False,comment='培训uid') training_theme = Column(String(100), nullable=False,comment='培训主题') training_unit = Column(String(255), nullable=False, comment='培训单位') participant_count = Column(Integer, comment='参与人数') training_method = Column(String(255), comment='培训方式') start_time = Column(DateTime, comment='培训开始时间') end_time = Column(DateTime, comment='培训结束时间') training_location = Column(String(255), comment='培训地点') training_content = Column(Text, nullable=False, comment='培训内容') training_lon = Column(Numeric(9, 6), comment='培训经度') training_lat = Column(Numeric(9, 6), comment='培训纬度') plan_number = Column(String(50), nullable=False,comment='预案编号') create_time = Column(DateTime, default=datetime.now, comment='数据创建时间') update_time = Column(DateTime, default=datetime.now, onupdate=datetime.now, comment='数据更新时间') create_dept = Column(BigInteger, default=None, comment='创建部门') create_by = Column(BigInteger, default=None, comment='创建者') del_flag = Column(String(1), default='0', comment='删除标志(0代表存在 2代表删除)') class Config: orm_mode = True class EmergencyResponse(Base): __tablename__ = 'emergency_responses' id = Column(Integer, autoincrement=True, primary_key=True) plan_id = Column(String(50), nullable=False,comment='预案id') response_id = Column(String(50), nullable=False, comment='响应编号') event_name = Column(String(255), nullable=False, comment='事件名称') event_type = Column(String(100), nullable=False, comment='事件类型') response_unit = Column(String(255), comment='响应单位') event_address = Column(String(255), comment='事件地点') response_level = Column(String(100), comment='响应级别') response_start_time = Column(DateTime, comment='响应开始时间') response_end_time = Column(DateTime, comment='响应结束时间') create_time = Column(DateTime, default=datetime.now, comment='数据创建时间') update_time = Column(DateTime, default=datetime.now, onupdate=datetime.now, comment='数据更新时间') create_dept = Column(BigInteger, default=None, comment='创建部门') create_by = Column(BigInteger, default=None, comment='创建者') del_flag = Column(String(1), default='0', comment='删除标志(0代表存在 2代表删除)') class Config: orm_mode = True class EmergencyUnit(Base): __tablename__ = 'emergency_unit' id = Column(Integer, autoincrement=True, primary_key=True) plan_id = Column(String(50), nullable=False,comment='预案id') dept_id = Column(Integer, nullable=False,comment='部门id') dept_name = Column(String(100), nullable=False,comment='部门名称') content = Column(String(255), nullable=False,comment='单位职责') dept_order = Column(Integer, comment='排序') class Config: orm_mode = True class EmergencyDoc(Base): __tablename__ = 'emergency_doc' id = Column(Integer, autoincrement=True, primary_key=True) title = Column(String, nullable=False,comment='标题') value = Column(String, nullable=False,comment='内容') pid = Column(Integer, comment='父级ID') plan_id = Column(String, nullable=False,comment='预案id') class Config: orm_mode = True ''' 应急预案人员信息 ''' class EmergencyContactInfo(Base): __tablename__ = 'emergency_contact_info' id = Column(Integer, autoincrement=True, primary_key=True) unit_id = Column(Integer, nullable=False, comment='单位ID') unit_name = Column(String, nullable=False, default='', comment='单位名称') contact_name = Column(String, nullable=False, default='', comment='联系人') position = Column(String, default='', comment='职务') yue_gov_ease_phone = Column(String, default='', comment='粤政易手机号码') create_time = Column(DateTime, default=datetime.now, comment='数据创建时间') update_time = Column(DateTime, default=datetime.now, onupdate=datetime.now, comment='数据更新时间') create_dept = Column(BigInteger, default=None, comment='创建部门') create_by = Column(BigInteger, default=None, comment='创建者') del_flag = Column(String, default='0', comment='删除标志(0代表存在 2代表删除)') sign = Column(String, server_default='', default='', comment='HMACSM3数值') class Config: orm_mode = True