|
@@ -0,0 +1,115 @@
|
|
|
|
+#!/usr/bin/env python3
|
|
|
|
+# -*- coding: utf-8 -*-
|
|
|
|
+
|
|
|
|
+from fastapi import APIRouter, Request, Depends, Query, HTTPException, status
|
|
|
|
+from common.security import valid_access_token
|
|
|
|
+from fastapi.responses import JSONResponse
|
|
|
|
+from sqlalchemy.orm import Session
|
|
|
|
+from sqlalchemy import and_, or_,text,literal
|
|
|
|
+from sqlalchemy.sql import func
|
|
|
|
+from sqlalchemy.future import select
|
|
|
|
+from common.auth_user import *
|
|
|
|
+from pydantic import BaseModel
|
|
|
|
+from database import get_db,get_share_db
|
|
|
|
+from typing import List
|
|
|
|
+from models import *
|
|
|
|
+from utils import *
|
|
|
|
+from utils.ry_system_util import *
|
|
|
|
+from utils.video_util import *
|
|
|
|
+from collections import defaultdict
|
|
|
|
+import traceback
|
|
|
|
+from concurrent.futures import ThreadPoolExecutor, as_completed
|
|
|
|
+from multiprocessing import Pool, cpu_count
|
|
|
|
+import json
|
|
|
|
+import time
|
|
|
|
+import math
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+router = APIRouter()
|
|
|
|
+
|
|
|
|
+@router.put("/update/{id}")
|
|
|
|
+async def update_info(
|
|
|
|
+ id :str ,
|
|
|
|
+ user_id=Depends(valid_access_token),
|
|
|
|
+ body=Depends(remove_xss_json),
|
|
|
|
+ db: Session = Depends(get_share_db)
|
|
|
|
+):
|
|
|
|
+ try:
|
|
|
|
+ query = db.query(EmergencyExpertInfo)
|
|
|
|
+ query = query.filter(EmergencyExpertInfo.id == id)
|
|
|
|
+ update_info = query.first()
|
|
|
|
+ if not update_info:
|
|
|
|
+ return JSONResponse(status_code=404, content={'msg':'信息不存在','code':404})
|
|
|
|
+
|
|
|
|
+ update_info.county = body['county']
|
|
|
|
+ update_info.expert_type = body['expert_type']
|
|
|
|
+ update_info.honorary_title = body['honorary_title']
|
|
|
|
+ update_info.unit = body['unit']
|
|
|
|
+ update_info.position = body['position']
|
|
|
|
+ update_info.professional_title = body['professional_title']
|
|
|
|
+ update_info.specialty = body['specialty']
|
|
|
|
+ update_info.rescue_experience = body['rescue_experience']
|
|
|
|
+ update_info.birth_date = body['birth_date']
|
|
|
|
+ update_info.work_start_date = body['work_start_date']
|
|
|
|
+ update_info.certificate_issue_date = body['certificate_issue_date']
|
|
|
|
+ update_info.professional_group = body['professional_group']
|
|
|
|
+ update_info.professional_field = body['professional_field']
|
|
|
|
+ update_info.work_phone = body['work_phone']
|
|
|
|
+ update_info.home_phone = body['home_phone']
|
|
|
|
+ update_info.mobile_phone = body['mobile_phone']
|
|
|
|
+ update_info.email = body['email']
|
|
|
|
+ update_info.contact_address = body['contact_address']
|
|
|
|
+ update_info.longitude = body['longitude']
|
|
|
|
+ update_info.latitude = body['latitude']
|
|
|
|
+ db.commit()
|
|
|
|
+ return {"code": 200, "msg": "更新成功"}
|
|
|
|
+ except Exception as e:
|
|
|
|
+ traceback.print_exc()
|
|
|
|
+ return JSONResponse(status_code=500, content={'msg': f"Internal server error: {str(e)}", 'code': 500})
|
|
|
|
+
|
|
|
|
+@router.get("/info/{id}")
|
|
|
|
+async def get_info(
|
|
|
|
+ id: str,
|
|
|
|
+ db: Session = Depends(get_share_db)
|
|
|
|
+):
|
|
|
|
+ try:
|
|
|
|
+ query = db.query(EmergencyExpertInfo)
|
|
|
|
+ query = query.filter(EmergencyExpertInfo.id == id)
|
|
|
|
+ info = query.first()
|
|
|
|
+ # pattern = db.query(TpPatternList).filter(TpPatternList.id == pattern_id).first()
|
|
|
|
+ if not info:
|
|
|
|
+ return JSONResponse(status_code=404, content={'msg':'信息不存在','code':404})
|
|
|
|
+
|
|
|
|
+ return {"code": 200, "msg": "获取成功", "data": dict(info)}
|
|
|
|
+ except Exception as e:
|
|
|
|
+ traceback.print_exc()
|
|
|
|
+ return JSONResponse(status_code=500, content={'msg': f"Internal server error: {str(e)}", 'code': 500})
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+@router.get("/list")
|
|
|
|
+async def get_list_info(
|
|
|
|
+ keyword : str = Query(None),
|
|
|
|
+ page: int = Query(1, gt=0, description='页码'),
|
|
|
|
+ pageSize: int = Query(5, gt=0, description='每页条目数量'),
|
|
|
|
+ db: Session = Depends(get_share_db)
|
|
|
|
+):
|
|
|
|
+ try:
|
|
|
|
+ query = db.query(EmergencyExpertInfo)
|
|
|
|
+ if keyword:
|
|
|
|
+ query = db.query(or_(EmergencyExpertInfo.name.like(f'%keyword%'),
|
|
|
|
+ EmergencyExpertInfo.unit.like(f'%keyword%'),
|
|
|
|
+ EmergencyExpertInfo.professional_title.like(f'%keyword%'),
|
|
|
|
+ EmergencyExpertInfo.professional_group.like(f'%keyword%'),
|
|
|
|
+ EmergencyExpertInfo.professional_field.like(f'%keyword%')))
|
|
|
|
+ total_items = query.count()
|
|
|
|
+ query = query.offset((page - 1) * pageSize).limit(pageSize)
|
|
|
|
+ data = query.all()
|
|
|
|
+
|
|
|
|
+ return {"code": 200, "msg": "获取成功", "data": [dict(info) for info in data],
|
|
|
|
+ "total": total_items,
|
|
|
|
+ "page": page,
|
|
|
|
+ "pageSize": pageSize,
|
|
|
|
+ "totalPages": (total_items + pageSize - 1) // pageSize}
|
|
|
|
+ except Exception as e:
|
|
|
|
+ traceback.print_exc()
|
|
|
|
+ return JSONResponse(status_code=500, content={'msg': f"Internal server error: {str(e)}", 'code': 500})
|