|
@@ -14,13 +14,42 @@ import json
|
|
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
+
|
|
|
+class File(BaseModel):
|
|
|
+ fileName:str
|
|
|
+ fileNameDesc:str
|
|
|
+ filePath : str = 'null'
|
|
|
+
|
|
|
+class PlanCreateForm(BaseModel):
|
|
|
+ planName : str
|
|
|
+ planType : int
|
|
|
+ # planTypeDesc : str
|
|
|
+ publishDate: str
|
|
|
+ organizingUnit : str
|
|
|
+ document : str
|
|
|
+ fileList : List[File] = []
|
|
|
+
|
|
|
+class DrillCreateForm(BaseModel):
|
|
|
+ planNumber : str
|
|
|
+ drillName : str
|
|
|
+ organizingUnit : str
|
|
|
+ plannedAnnual : int
|
|
|
+ plannedTime: str
|
|
|
+ drillLocation : str
|
|
|
+ drillLon : float
|
|
|
+ drillLat : float
|
|
|
+ drillProject : List[File] = []
|
|
|
+ drillVideo : List[File] = []
|
|
|
+ drillPicture : List[File] = []
|
|
|
+
|
|
|
+
|
|
|
@router.get('/plan/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='预案名称'),
|
|
|
+ planType: str = Query(None, description='预案类型'),
|
|
|
+ publishDate: datetime = Query(None, description='发布日期'),
|
|
|
+ planName: str = Query(None, description='预案名称'),
|
|
|
page: int = Query(1, gt=0, description='页码'),
|
|
|
- page_size: int = Query(10, gt=0, description='每页条目数量'),
|
|
|
+ pageSize: int = Query(10, gt=0, description='每页条目数量'),
|
|
|
db: Session = Depends(get_db)
|
|
|
):
|
|
|
try:
|
|
@@ -28,18 +57,18 @@ async def get_emergency_plan_list(
|
|
|
query = db.query(EmergencyPlan)
|
|
|
query = query.filter(EmergencyPlan.del_flag != '2')
|
|
|
# 应用查询条件
|
|
|
- if plan_type:
|
|
|
- query = query.filter(EmergencyPlan.plan_type == plan_type)
|
|
|
- if publish_date:
|
|
|
- query = query.filter(EmergencyPlan.publish_date == publish_date)
|
|
|
- if plan_name:
|
|
|
- query = query.filter(EmergencyPlan.plan_name.like(f'%{plan_name}%'))
|
|
|
+ if planType:
|
|
|
+ query = query.filter(EmergencyPlan.plan_type == planType)
|
|
|
+ if publishDate:
|
|
|
+ query = query.filter(EmergencyPlan.publish_date == publishDate)
|
|
|
+ if planName:
|
|
|
+ query = query.filter(EmergencyPlan.plan_name.like(f'%{planName}%'))
|
|
|
|
|
|
# 计算总条目数
|
|
|
total_items = query.count()
|
|
|
|
|
|
# 执行分页查询
|
|
|
- emergency_plans = query.offset((page - 1) * page_size).limit(page_size).all()
|
|
|
+ emergency_plans = query.offset((page - 1) * pageSize).limit(pageSize).all()
|
|
|
|
|
|
# 将查询结果转换为列表形式的字典
|
|
|
emergency_plans_list = [
|
|
@@ -47,10 +76,10 @@ async def get_emergency_plan_list(
|
|
|
"planUid": plan.plan_id,
|
|
|
"planId": plan.plan_number,
|
|
|
"planName": plan.plan_name,
|
|
|
- "planType": plan.plan_type_desc,
|
|
|
+ "planType": plan.plan_type,
|
|
|
"organUnit": plan.organizing_unit,
|
|
|
"document": plan.document_number,
|
|
|
- "publish_date": plan.publish_date.strftime('%Y-%m-%d')
|
|
|
+ "publishDate": plan.publish_date.strftime('%Y-%m-%d')
|
|
|
}
|
|
|
for plan in emergency_plans
|
|
|
]
|
|
@@ -67,8 +96,8 @@ async def get_emergency_plan_list(
|
|
|
"data": emergency_plans_list,
|
|
|
"total": total_items,
|
|
|
"page": page,
|
|
|
- "page_size": page_size,
|
|
|
- "total_pages": (total_items + page_size - 1) // page_size
|
|
|
+ "pageSize": pageSize,
|
|
|
+ "totalPages": (total_items + pageSize - 1) // pageSize
|
|
|
}
|
|
|
except Exception as e:
|
|
|
# 处理异常
|
|
@@ -97,19 +126,18 @@ async def get_emergency_plan(
|
|
|
file_query = file_query.filter(EmergencyFile.foreign_key == emergency_plan.plan_id)
|
|
|
files = file_query.all()
|
|
|
# 将查询结果转换为列表形式的字典
|
|
|
- emergency_plans =
|
|
|
- {
|
|
|
+ emergency_plans ={
|
|
|
"planUid": emergency_plan.plan_id,
|
|
|
"planId": emergency_plan.plan_number,
|
|
|
"planName": emergency_plan.plan_name,
|
|
|
- "planType": emergency_plan.plan_type_desc,
|
|
|
+ "planType": emergency_plan.plan_type,
|
|
|
"organUnit": emergency_plan.organizing_unit,
|
|
|
"document": emergency_plan.document_number,
|
|
|
"publish_date": emergency_plan.publish_date.strftime('%Y-%m-%d'),
|
|
|
- file_list:[{
|
|
|
- "file_name":file.file_name,
|
|
|
- "file_name_desc":file.file_name_desc,
|
|
|
- "file_url":"/api/file/download/%s"%file.file_name
|
|
|
+ "fileList":[{
|
|
|
+ "fileName":file.file_name,
|
|
|
+ "fileNameDesc":file.file_name_desc,
|
|
|
+ "fileUrl":"/api/file/download/%s"%file.file_name
|
|
|
} for file in files ]
|
|
|
}
|
|
|
|
|
@@ -124,19 +152,7 @@ async def get_emergency_plan(
|
|
|
raise HTTPException(status_code=500, detail=str(e))
|
|
|
|
|
|
|
|
|
-class File(BaseModel):
|
|
|
- file_name:str
|
|
|
- file_name_desc:str
|
|
|
- file_path : str = 'null'
|
|
|
|
|
|
-class PlanCreateForm(BaseModel):
|
|
|
- plan_name : str
|
|
|
- plan_type : int
|
|
|
- plan_type_desc : str
|
|
|
- publish_date: str
|
|
|
- organizing_unit : str
|
|
|
- document_number : str
|
|
|
- file_list : List[File] = []
|
|
|
|
|
|
@router.post('/plan/create')
|
|
|
async def create_emergency_plan(
|
|
@@ -145,19 +161,19 @@ async def create_emergency_plan(
|
|
|
):
|
|
|
try:
|
|
|
# 提取请求数据
|
|
|
- plan_name = form_data.plan_name
|
|
|
- plan_type = form_data.plan_type
|
|
|
- plan_type_desc = form_data.plan_type_desc
|
|
|
- publish_date = form_data.publish_date # 如果没有提供发布日期,则使用当前时间
|
|
|
- organizing_unit = form_data.organizing_unit # 使用用户位置作为编制单位
|
|
|
- document_number = form_data.document_number
|
|
|
+ plan_name = form_data.planName
|
|
|
+ plan_type = form_data.planType
|
|
|
+ # plan_type_desc = form_data.planTypeDesc
|
|
|
+ publish_date = form_data.publishDate # 如果没有提供发布日期,则使用当前时间
|
|
|
+ organizing_unit = form_data.organizingUnit # 使用用户位置作为编制单位
|
|
|
+ document_number = form_data.document
|
|
|
|
|
|
# 创建新的预案记录
|
|
|
new_plan = EmergencyPlan(
|
|
|
plan_id=new_guid(), # 假设使用 UUID 作为预案 UID
|
|
|
plan_name=plan_name,
|
|
|
plan_type=plan_type,
|
|
|
- plan_type_desc=plan_type_desc,
|
|
|
+ # plan_type_desc=plan_type_desc,
|
|
|
publish_date=publish_date,
|
|
|
organizing_unit=organizing_unit,
|
|
|
document_number=document_number
|
|
@@ -169,10 +185,10 @@ async def create_emergency_plan(
|
|
|
db.refresh(new_plan) # 可选,如果需要刷新实例状态
|
|
|
new_plan.plan_number= f'YJYA{str(new_plan.id).zfill(10)}'
|
|
|
db.commit()
|
|
|
- for file in form_data.file_list:
|
|
|
- file_name = file.file_name
|
|
|
- file_name_desc = file.file_name_desc
|
|
|
- file_path = file.file_path
|
|
|
+ for file in form_data.fileList:
|
|
|
+ file_name = file.fileName
|
|
|
+ file_name_desc = file.fileNameDesc
|
|
|
+ file_path = file.filePath
|
|
|
new_file = EmergencyFile(
|
|
|
file_id = new_guid(),
|
|
|
foreign_key = new_plan.plan_id,
|
|
@@ -274,7 +290,7 @@ async def create_emergency_plan(
|
|
|
async def get_emergency_drill_list(
|
|
|
planNum: str = Query(None, description='预案编号'),
|
|
|
page: int = Query(1, gt=0, description='页码'),
|
|
|
- page_size: int = Query(10, gt=0, description='每页条目数量'),
|
|
|
+ pageSize: int = Query(10, gt=0, description='每页条目数量'),
|
|
|
db: Session = Depends(get_db)
|
|
|
):
|
|
|
try:
|
|
@@ -291,10 +307,29 @@ async def get_emergency_drill_list(
|
|
|
total_items = query.count()
|
|
|
|
|
|
# 执行分页查询
|
|
|
- emergency_drill = query.all() # .offset((page - 1) * page_size).limit(page_size)
|
|
|
+ emergency_drill = query.offset((page - 1) * pageSize).limit(pageSize).all() #
|
|
|
print(emergency_drill)
|
|
|
# 将查询结果转换为列表形式的字典
|
|
|
- emergency_drill_list = [
|
|
|
+ emergency_drill_list = []
|
|
|
+ for drill in emergency_drill:
|
|
|
+ project_query = db.query(EmergencyFile)
|
|
|
+ project_query = project_query.filter(EmergencyFile.del_flag != '2')
|
|
|
+ project_query = project_query.filter(EmergencyFile.from_scenario == 'emergencyPlans_plan')
|
|
|
+ project_query = project_query.filter(EmergencyFile.foreign_key == emergency_plan.plan_id)
|
|
|
+ projects = project_query.all()
|
|
|
+
|
|
|
+ video_query = db.query(EmergencyFile)
|
|
|
+ video_query = video_query.filter(EmergencyFile.del_flag != '2')
|
|
|
+ video_query = video_query.filter(EmergencyFile.from_scenario == 'emergencyPlans_plan')
|
|
|
+ video_query = video_query.filter(EmergencyFile.foreign_key == emergency_plan.plan_id)
|
|
|
+ videos = video_query.all()
|
|
|
+
|
|
|
+ picture_query = db.query(EmergencyFile)
|
|
|
+ picture_query = picture_query.filter(EmergencyFile.del_flag != '2')
|
|
|
+ picture_query = picture_query.filter(EmergencyFile.from_scenario == 'emergencyPlans_plan')
|
|
|
+ picture_query = picture_query.filter(EmergencyFile.foreign_key == emergency_plan.plan_id)
|
|
|
+ pictures = picture_query.all()
|
|
|
+
|
|
|
{
|
|
|
"drillId": drill.drill_id,
|
|
|
"drillName": drill.drill_name,
|
|
@@ -302,14 +337,24 @@ async def get_emergency_drill_list(
|
|
|
"year": "%s年"%drill.planned_annual,
|
|
|
"drillTime": drill.planned_time.strftime('%Y-%m-%d %H:%M:%S'),
|
|
|
"drillAddress": drill.drill_location,
|
|
|
- "drillProject":drill.drillProject,
|
|
|
- "drillVideo":[{ 'file_name':'123456.mp4',
|
|
|
- 'file_name_desc':'测试.mp4'}],
|
|
|
- "drillPicture": [{ 'file_name':'123456.png',
|
|
|
- 'file_name_desc':'测试.png'}]
|
|
|
+ "drillProject":[{
|
|
|
+ "fileName":file.file_name,
|
|
|
+ "fileNameDesc":file.file_name_desc,
|
|
|
+ "fileUrl":"/api/file/download/%s"%file.file_name
|
|
|
+ } for file in projects ],
|
|
|
+ "drillVideo":[{
|
|
|
+ "fileName":file.file_name,
|
|
|
+ "fileNameDesc":file.file_name_desc,
|
|
|
+ "fileUrl":"/api/file/download/%s"%file.file_name
|
|
|
+ } for file in videos ],
|
|
|
+ "drillPicture":[{
|
|
|
+ "fileName":file.file_name,
|
|
|
+ "fileNameDesc":file.file_name_desc,
|
|
|
+ "fileUrl":"/api/file/download/%s"%file.file_name
|
|
|
+ } for file in pictures ]
|
|
|
}
|
|
|
- for drill in emergency_drill
|
|
|
- ]
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
# 返回结果
|
|
@@ -319,25 +364,14 @@ async def get_emergency_drill_list(
|
|
|
"data": emergency_drill_list,
|
|
|
"total": total_items,
|
|
|
"page": page,
|
|
|
- "page_size": page_size,
|
|
|
- "total_pages": (total_items + page_size - 1) // page_size
|
|
|
+ "pageSize": pageSize,
|
|
|
+ "totalPages": (total_items + pageSize - 1) // pageSize
|
|
|
}
|
|
|
except Exception as e:
|
|
|
# 处理异常
|
|
|
raise HTTPException(status_code=500, detail=str(e))
|
|
|
|
|
|
-class DrillCreateForm(BaseModel):
|
|
|
- plan_number : str
|
|
|
- drill_name : str
|
|
|
- organizing_unit : str
|
|
|
- planned_annual : int
|
|
|
- planned_time: str
|
|
|
- drill_location : str
|
|
|
- drill_lon : float
|
|
|
- drill_lat : float
|
|
|
- scheme_file_list : List[File] = []
|
|
|
- video_file_list : List[File] = []
|
|
|
- pic_file_list : List[File] = []
|
|
|
+
|
|
|
|
|
|
@router.post('/drill/create')
|
|
|
async def create_emergency_drill(
|
|
@@ -346,14 +380,14 @@ async def create_emergency_drill(
|
|
|
):
|
|
|
try:
|
|
|
# 提取请求数据
|
|
|
- plan_number = form_data.plan_number
|
|
|
- drill_name = form_data.drill_name
|
|
|
- organizing_unit = form_data.organizing_unit
|
|
|
- planned_annual = form_data.planned_annual
|
|
|
- planned_time = form_data.planned_time
|
|
|
- drill_location = form_data.drill_location
|
|
|
- drill_lon = form_data.drill_lon
|
|
|
- drill_lat = form_data.drill_lat
|
|
|
+ plan_number = form_data.planNumber
|
|
|
+ drill_name = form_data.drillName
|
|
|
+ organizing_unit = form_data.organizingUnit
|
|
|
+ planned_annual = form_data.plannedAnnual
|
|
|
+ planned_time = form_data.plannedTime
|
|
|
+ drill_location = form_data.drillLocation
|
|
|
+ drill_lon = form_data.drillLon
|
|
|
+ drill_lat = form_data.drillLat
|
|
|
|
|
|
|
|
|
# 创建新的预案记录
|
|
@@ -374,14 +408,14 @@ async def create_emergency_drill(
|
|
|
db.commit()
|
|
|
db.refresh(new_drill) # 可选,如果需要刷新实例状态
|
|
|
|
|
|
- for file in form_data.scheme_file_list:
|
|
|
- file_name = file.file_name
|
|
|
- file_name_desc = file.file_name_desc
|
|
|
- file_path = file.file_path
|
|
|
+ for file in form_data.drillProject:
|
|
|
+ file_name = file.fileName
|
|
|
+ file_name_desc = file.fileNameDesc
|
|
|
+ file_path = file.filePath
|
|
|
new_file = EmergencyFile(
|
|
|
file_id = new_guid(),
|
|
|
foreign_key = new_drill.drill_id,
|
|
|
- from_scenario = 'emergencyPlans_drill_scheme',
|
|
|
+ from_scenario = 'emergencyPlans_drill_project',
|
|
|
file_name=file_name,
|
|
|
file_name_desc = file_name_desc,
|
|
|
file_path = file_path
|
|
@@ -389,10 +423,10 @@ async def create_emergency_drill(
|
|
|
db.add(new_file)
|
|
|
db.commit()
|
|
|
db.refresh(new_file)
|
|
|
- for file in form_data.video_file_list:
|
|
|
- file_name = file.file_name
|
|
|
- file_name_desc = file.file_name_desc
|
|
|
- file_path = file.file_path
|
|
|
+ for file in form_data.drillVideo:
|
|
|
+ file_name = file.fileName
|
|
|
+ file_name_desc = file.fileNameDesc
|
|
|
+ file_path = file.filePath
|
|
|
new_file = EmergencyFile(
|
|
|
file_id = new_guid(),
|
|
|
foreign_key = new_drill.drill_id,
|
|
@@ -404,10 +438,10 @@ async def create_emergency_drill(
|
|
|
db.add(new_file)
|
|
|
db.commit()
|
|
|
db.refresh(new_file)
|
|
|
- for file in form_data.pic_file_list:
|
|
|
- file_name = file.file_name
|
|
|
- file_name_desc = file.file_name_desc
|
|
|
- file_path = file.file_path
|
|
|
+ for file in form_data.drillPicture:
|
|
|
+ file_name = file.fileName
|
|
|
+ file_name_desc = file.fileNameDesc
|
|
|
+ file_path = file.filePath
|
|
|
new_file = EmergencyFile(
|
|
|
file_id = new_guid(),
|
|
|
foreign_key = new_drill.drill_id,
|
|
@@ -437,7 +471,7 @@ async def create_emergency_drill(
|
|
|
async def get_emergency_training_list(
|
|
|
planNum: str = Query(None, description='预案编号'),
|
|
|
page: int = Query(1, gt=0, description='页码'),
|
|
|
- page_size: int = Query(10, gt=0, description='每页条目数量'),
|
|
|
+ pageSize: int = Query(10, gt=0, description='每页条目数量'),
|
|
|
db: Session = Depends(get_db)
|
|
|
):
|
|
|
try:
|
|
@@ -454,7 +488,7 @@ async def get_emergency_training_list(
|
|
|
total_items = query.count()
|
|
|
|
|
|
# 执行分页查询
|
|
|
- emergency_training = query.all() # .offset((page - 1) * page_size).limit(page_size)
|
|
|
+ emergency_training = query.offset((page - 1) * pageSize).limit(pageSize).all() #
|
|
|
# print(emergency_drill)
|
|
|
# 将查询结果转换为列表形式的字典
|
|
|
emergency_training_list = [
|
|
@@ -480,24 +514,24 @@ async def get_emergency_training_list(
|
|
|
"data": emergency_training_list,
|
|
|
"total": total_items,
|
|
|
"page": page,
|
|
|
- "page_size": page_size,
|
|
|
- "total_pages": (total_items + page_size - 1) // page_size
|
|
|
+ "pageSize": pageSize,
|
|
|
+ "totalPages": (total_items + pageSize - 1) // pageSize
|
|
|
}
|
|
|
except Exception as e:
|
|
|
# 处理异常
|
|
|
raise HTTPException(status_code=500, detail=str(e))
|
|
|
|
|
|
class TrainingCreateForm(BaseModel):
|
|
|
- training_theme : str
|
|
|
- training_unit : str
|
|
|
- training_method : str
|
|
|
- participant_count: int
|
|
|
- start_time : str
|
|
|
- end_time : str
|
|
|
- training_content :str
|
|
|
- drill_location : str
|
|
|
- drill_lon : float
|
|
|
- drill_lat : float
|
|
|
+ trainingTheme : str
|
|
|
+ trainingUnit : str
|
|
|
+ trainingMethod : str
|
|
|
+ participantCount: int
|
|
|
+ startTime : str
|
|
|
+ endTime : str
|
|
|
+ trainingContent :str
|
|
|
+ drillLocation : str
|
|
|
+ drillLon : float
|
|
|
+ drillLat : float
|
|
|
|
|
|
@router.post('/training/create')
|
|
|
async def create_emergency_training(
|
|
@@ -508,16 +542,16 @@ async def create_emergency_training(
|
|
|
# 创建新的预案记录
|
|
|
new_training = EmergencyTrainingSession(
|
|
|
training_id=new_guid(), # 假设使用 UUID 作为预案 UID
|
|
|
- training_theme=form_data.training_theme,
|
|
|
- training_unit=form_data.training_unit,
|
|
|
- training_method=form_data.training_method,
|
|
|
- participant_count=form_data.participant_count,
|
|
|
- start_time=form_data.start_time,
|
|
|
- end_time=form_data.end_time,
|
|
|
- training_content=form_data.training_content,
|
|
|
- drill_location=form_data.drill_location,
|
|
|
- drill_lon=form_data.drill_lon,
|
|
|
- drill_lat=form_data.drill_lat
|
|
|
+ training_theme=form_data.trainingTheme,
|
|
|
+ training_unit=form_data.trainingUnit,
|
|
|
+ training_method=form_data.trainingMethod,
|
|
|
+ participant_count=form_data.participantCount,
|
|
|
+ start_time=form_data.startTime,
|
|
|
+ end_time=form_data.endTime,
|
|
|
+ training_content=form_data.trainingContent,
|
|
|
+ drill_location=form_data.drillLocation,
|
|
|
+ drill_lon=form_data.drillLon,
|
|
|
+ drill_lat=form_data.drillLat
|
|
|
)
|
|
|
|
|
|
# 添加到数据库会话并提交
|