|
@@ -0,0 +1,60 @@
|
|
|
+#!/usr/bin/env python3
|
|
|
+# -*- coding: utf-8 -*-
|
|
|
+
|
|
|
+from fastapi import APIRouter, Request, Depends
|
|
|
+from fastapi.responses import JSONResponse
|
|
|
+from database import get_db
|
|
|
+from sqlalchemy.orm import Session
|
|
|
+from models import *
|
|
|
+import json
|
|
|
+
|
|
|
+router = APIRouter()
|
|
|
+
|
|
|
+@router.get('/list')
|
|
|
+async def get_emergency_plan_list(
|
|
|
+ plan_type: str = Query(None, description='预案类型'),
|
|
|
+ publish_date: datetime = Query(None, description='发布日期'),
|
|
|
+ plan_name: str = Query(None, description='预案名称'),
|
|
|
+ db: Session = Depends(database.get_db)
|
|
|
+):
|
|
|
+ try:
|
|
|
+ # 构建查询
|
|
|
+ query = db.query(models.EmergencyPlan)
|
|
|
+
|
|
|
+ # 应用查询条件
|
|
|
+ if plan_type:
|
|
|
+ query = query.filter(models.EmergencyPlan.plan_type == plan_type)
|
|
|
+ if publish_date:
|
|
|
+ query = query.filter(models.EmergencyPlan.publish_date == publish_date)
|
|
|
+ if plan_name:
|
|
|
+ query = query.filter(models.EmergencyPlan.plan_name.like(f'%{plan_name}%'))
|
|
|
+
|
|
|
+ # 执行查询
|
|
|
+ emergency_plans = query.all()
|
|
|
+
|
|
|
+ # 将查询结果转换为列表形式的字典
|
|
|
+ emergency_plans_list = [
|
|
|
+ {
|
|
|
+ "id": plan.id,
|
|
|
+ "plan_id": plan.plan_id,
|
|
|
+ "plan_number": plan.plan_number,
|
|
|
+ "plan_name": plan.plan_name,
|
|
|
+ "plan_type": plan.plan_type,
|
|
|
+ "plan_type_desc": plan.plan_type_desc,
|
|
|
+ "publish_date": plan.publish_date.strftime('%Y-%m-%d %H:%M:%S'),
|
|
|
+ "organizing_unit": plan.organizing_unit,
|
|
|
+ "document_number": plan.document_number,
|
|
|
+ # 其他需要的字段...
|
|
|
+ }
|
|
|
+ for plan in emergency_plans
|
|
|
+ ]
|
|
|
+
|
|
|
+ # 返回结果
|
|
|
+ return {
|
|
|
+ "code": 200,
|
|
|
+ "msg": "成功获取预案列表",
|
|
|
+ "data": emergency_plans_list
|
|
|
+ }
|
|
|
+ except Exception as e:
|
|
|
+ # 处理异常
|
|
|
+ raise HTTPException(status_code=500, detail=str(e))
|