|
@@ -1,4 +1,4 @@
|
|
|
-from fastapi import APIRouter, Request, Depends, HTTPException, Query, BackgroundTasks
|
|
|
+from fastapi import APIRouter, Request, Depends, HTTPException, Query, BackgroundTasks,status
|
|
|
from sqlalchemy.exc import IntegrityError
|
|
|
from fastapi.responses import HTMLResponse, FileResponse
|
|
|
from fastapi.responses import JSONResponse
|
|
@@ -211,28 +211,31 @@ async def post_edit_event(
|
|
|
body = Depends(remove_xss_json),
|
|
|
db: Session = Depends(get_db),
|
|
|
user_id = Depends(valid_access_token)):
|
|
|
+ try:
|
|
|
+ eventId = body['eventId']
|
|
|
+ del body['eventId']
|
|
|
+ body['recorded_by'] = user_id
|
|
|
|
|
|
- eventId = body['eventId']
|
|
|
- del body['eventId']
|
|
|
- body['recorded_by'] = user_id
|
|
|
-
|
|
|
- # 未上报时清空伤亡人数
|
|
|
- if body['casualties'] == '0':
|
|
|
- body['deaths'] = None
|
|
|
- body['injuries'] = None
|
|
|
- body['missing'] = None
|
|
|
-
|
|
|
- if 'deaths' in body or 'injuries' in body or 'missing' in body:
|
|
|
- body['casualties'] = '1'
|
|
|
-
|
|
|
- db.query(EventBase).filter(EventBase.event_code == eventId).update(body)
|
|
|
- db.commit()
|
|
|
+ # 未上报时清空伤亡人数
|
|
|
+ if body['casualties'] == '0':
|
|
|
+ body['deaths'] = None
|
|
|
+ body['injuries'] = None
|
|
|
+ body['missing'] = None
|
|
|
|
|
|
- return {
|
|
|
- "code": 200,
|
|
|
- "msg": "保存事件成功"
|
|
|
- }
|
|
|
+ if 'deaths' in body or 'injuries' in body or 'missing' in body:
|
|
|
+ body['casualties'] = '1'
|
|
|
+ # print(body)
|
|
|
+ db.query(EventBase).filter(EventBase.event_code == eventId).update(body)
|
|
|
+ db.commit()
|
|
|
|
|
|
+ return {
|
|
|
+ "code": 200,
|
|
|
+ "msg": "保存事件成功"
|
|
|
+ }
|
|
|
+ except Exception as e:
|
|
|
+ # 处理异常
|
|
|
+ traceback.print_exc()
|
|
|
+ raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=str(e))
|
|
|
@router.post("/uploadEventCasualties")
|
|
|
async def uploadEventCasualties(
|
|
|
request: Request,
|