|
@@ -18,13 +18,14 @@ import traceback
|
|
|
from utils import *
|
|
|
from datetime import datetime, timedelta
|
|
|
import pandas as pd
|
|
|
+from common.db import db_dept
|
|
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get('/list')
|
|
|
async def get_emergency_contact_list(
|
|
|
- unitName: str = Query(None, description='单位名称'),
|
|
|
- contactCame: str = Query(None, description='联系人'),
|
|
|
+ unitId: str = Query(None, description='单位名称'),
|
|
|
+ contactName: str = Query(None, description='联系人'),
|
|
|
page: int = Query(1, gt=0, description='页码'),
|
|
|
pageSize: int = Query(10, gt=0, description='每页条目数量'),
|
|
|
db: Session = Depends(get_db),
|
|
@@ -35,10 +36,10 @@ async def get_emergency_contact_list(
|
|
|
query = db.query(EmergencyContactInfo)
|
|
|
query = query.filter(EmergencyContactInfo.del_flag != '2')
|
|
|
# 应用查询条件
|
|
|
- if unitName:
|
|
|
- query = query.filter(EmergencyContactInfo.unit_name == unitName)
|
|
|
- if contactCame:
|
|
|
- query = query.filter(EmergencyContactInfo.contact_name.like(f'%{contactCame}%'))
|
|
|
+ if unitId:
|
|
|
+ query = query.filter(EmergencyContactInfo.unit_id == unitId)
|
|
|
+ if contactName:
|
|
|
+ query = query.filter(EmergencyContactInfo.contact_name.like(f'%{contactName}%'))
|
|
|
|
|
|
# 计算总条目数
|
|
|
total_items = query.count()
|
|
@@ -53,6 +54,7 @@ async def get_emergency_contact_list(
|
|
|
contact_infos_list = [
|
|
|
{
|
|
|
"id": info.id,
|
|
|
+ "unitId": info.unit_id,
|
|
|
"unitName": info.unit_name,
|
|
|
"contactName": info.contact_name,
|
|
|
"position": info.position,
|
|
@@ -67,10 +69,7 @@ async def get_emergency_contact_list(
|
|
|
"code": 200,
|
|
|
"msg": "成功",
|
|
|
"data": contact_infos_list,
|
|
|
- "total": total_items,
|
|
|
- "page": page,
|
|
|
- "pageSize": pageSize,
|
|
|
- "totalPages": (total_items + pageSize - 1) // pageSize
|
|
|
+ "total": total_items
|
|
|
}
|
|
|
|
|
|
except Exception as e:
|
|
@@ -106,6 +105,7 @@ async def get_emergency_contact_id_info(
|
|
|
# 将查询结果转换为列表形式的字典
|
|
|
contact_result = {
|
|
|
"id": contact.id,
|
|
|
+ "unitId": contact.unit_id,
|
|
|
"unitName": contact.unit_name,
|
|
|
"contactName": contact.contact_name,
|
|
|
"position": contact.position,
|
|
@@ -131,14 +131,19 @@ async def create_contact(
|
|
|
):
|
|
|
try:
|
|
|
# 提取请求数据
|
|
|
- unit_name = body['unitName']
|
|
|
+ unit_id = body['unitId']
|
|
|
contact_name = body['contactName']
|
|
|
position = body['position']
|
|
|
yue_gov_ease_phone = body['phone']
|
|
|
|
|
|
+ unit_name = db_dept.get_dept_name_by_id(db, unit_id)
|
|
|
+ if unit_name == '':
|
|
|
+ raise Exception('单位不正确')
|
|
|
+
|
|
|
# 创建新的预案记录
|
|
|
new_contact = EmergencyContactInfo(
|
|
|
- unit_name=unit_name,
|
|
|
+ unit_id = unit_id,
|
|
|
+ unit_name = unit_name,
|
|
|
contact_name = contact_name,
|
|
|
position = position,
|
|
|
yue_gov_ease_phone = yue_gov_ease_phone,
|
|
@@ -179,8 +184,12 @@ async def update_contact(
|
|
|
'errmsg': '联系人不存在'
|
|
|
})
|
|
|
|
|
|
- if "unitName" in body:
|
|
|
- contact.unit_name = body['unitName']
|
|
|
+ if "unitId" in body:
|
|
|
+ unit_name = db_dept.get_dept_name_by_id(db, body['unitId'])
|
|
|
+ if unit_name == '':
|
|
|
+ raise Exception('单位不正确')
|
|
|
+ contact.unit_id = body['unitId']
|
|
|
+ contact.unit_name = unit_name
|
|
|
if "contactName" in body:
|
|
|
contact.contact_name = body['contactName']
|
|
|
if "position" in body:
|
|
@@ -276,7 +285,11 @@ async def create_contact(
|
|
|
):
|
|
|
try:
|
|
|
# 提取请求数据
|
|
|
- file_name = body['file_name']
|
|
|
+ filename = body['filename']
|
|
|
+ if len(filename) == 0:
|
|
|
+ raise Exception()
|
|
|
+
|
|
|
+ file_name = filename[0]['url']
|
|
|
file_path = f'/data/upload/mergefile/uploads/{file_name}'
|
|
|
|
|
|
# 检查文件是否存在
|
|
@@ -313,20 +326,23 @@ async def create_contact(
|
|
|
actual_columns = first_two_rows.columns.tolist()
|
|
|
print(actual_columns)
|
|
|
missing_columns = [col for col in expected_columns.keys() if col not in actual_columns]
|
|
|
- if missing_columns:
|
|
|
+
|
|
|
+ if len(missing_columns) > 0:
|
|
|
return JSONResponse(status_code=404, content={
|
|
|
'errcode': 502,
|
|
|
- 'errmsg': "请按模板上传"
|
|
|
+ 'errmsg': "请按模板上传."
|
|
|
})
|
|
|
+
|
|
|
head1 = df.head(1)
|
|
|
head1data = head1.to_dict(orient='records')[0]
|
|
|
+ print(head1data)
|
|
|
if head1data['单位名称'] == '填写单位名称' and head1data['联系人'] == '填写单位职责' and head1data['职务'] == '填写联系人职务' and \
|
|
|
head1data['粤政易手机号码'] == '填写联系人的粤政易注册手机号码':
|
|
|
df = df.drop(index=0)
|
|
|
else:
|
|
|
return JSONResponse(status_code=404, content={
|
|
|
'errcode': 502,
|
|
|
- 'errmsg': "请按模板上传"
|
|
|
+ 'errmsg': "请按模板上传!"
|
|
|
})
|
|
|
|
|
|
# 检查前两行的字段长度
|
|
@@ -374,5 +390,6 @@ async def create_contact(
|
|
|
"data": None
|
|
|
}
|
|
|
except Exception as e:
|
|
|
+ traceback.print_exc()
|
|
|
# 处理异常
|
|
|
raise HTTPException(status_code=500, detail=str(e))
|