|
@@ -62,42 +62,54 @@ async def create_contact(
|
|
|
create_by=user_id
|
|
|
)
|
|
|
# 添加到数据库会话并提交
|
|
|
- db.add(new_person)
|
|
|
- db.commit()
|
|
|
type_list = body['type_list']
|
|
|
- for type_info in type_list:
|
|
|
- type_parent_id = type_info['type_parent_id']#get_type_parent_id_by_type_id(db,type_id)
|
|
|
- for type_id in type_info['children']:
|
|
|
- new_person_type = ThreeProofingResponsiblePersonType(
|
|
|
- type_parent_id = type_parent_id,
|
|
|
- type_id = type_id,
|
|
|
- person_id = new_person.id,
|
|
|
- create_by=user_id
|
|
|
- )
|
|
|
- db.add(new_person_type)
|
|
|
- if type_parent_id in ('5','7','9'):
|
|
|
- dept_name = None
|
|
|
- if 'dept_name' in type_info:
|
|
|
- dept_name = type_info['dept_name']
|
|
|
- other_type_id = None
|
|
|
- if 'other_type_id' in type_info:
|
|
|
- other_type_id = type_info['other_type_id']
|
|
|
- other_type_2_name = None
|
|
|
- if 'other_type_2_name' in type_info:
|
|
|
- other_type_2_name = type_info['other_type_2_name']
|
|
|
- denger_point_name = None
|
|
|
- if 'denger_point_name' in type_info:
|
|
|
- denger_point_name = type_info['denger_point_name']
|
|
|
- new_person_other_type = ThreeProofingResponsiblePersonOtherInfo(
|
|
|
- type_parent_id = type_parent_id,
|
|
|
- dept_name = dept_name,
|
|
|
- other_type_id = other_type_id,
|
|
|
- other_type_2_name = other_type_2_name,
|
|
|
- denger_point_name = denger_point_name,
|
|
|
- person_id = new_person.id,
|
|
|
- create_by=user_id
|
|
|
- )
|
|
|
- db.add(new_person_other_type)
|
|
|
+ if isinstance(type_list,list) and len(type_list)>0:
|
|
|
+
|
|
|
+ db.add(new_person)
|
|
|
+ db.commit()
|
|
|
+ else:
|
|
|
+ return JSONResponse(status_code=404,content={
|
|
|
+ 'code': 404,
|
|
|
+ 'msg': '责任类型不能为空'
|
|
|
+ })
|
|
|
+ try:
|
|
|
+ for type_info in type_list:
|
|
|
+ type_parent_id = type_info['type_parent_id']#get_type_parent_id_by_type_id(db,type_id)
|
|
|
+ for type_id in type_info['children']:
|
|
|
+ new_person_type = ThreeProofingResponsiblePersonType(
|
|
|
+ type_parent_id = type_parent_id,
|
|
|
+ type_id = type_id,
|
|
|
+ person_id = new_person.id,
|
|
|
+ create_by=user_id
|
|
|
+ )
|
|
|
+ db.add(new_person_type)
|
|
|
+ if type_parent_id in ('5','7','9'):
|
|
|
+ dept_name = None
|
|
|
+ if 'dept_name' in type_info:
|
|
|
+ dept_name = type_info['dept_name']
|
|
|
+ other_type_id = None
|
|
|
+ if 'other_type_id' in type_info:
|
|
|
+ other_type_id = type_info['other_type_id']
|
|
|
+ other_type_2_name = None
|
|
|
+ if 'other_type_2_name' in type_info:
|
|
|
+ other_type_2_name = type_info['other_type_2_name']
|
|
|
+ denger_point_name = None
|
|
|
+ if 'denger_point_name' in type_info:
|
|
|
+ denger_point_name = type_info['denger_point_name']
|
|
|
+ new_person_other_type = ThreeProofingResponsiblePersonOtherInfo(
|
|
|
+ type_parent_id = type_parent_id,
|
|
|
+ dept_name = dept_name,
|
|
|
+ other_type_id = other_type_id,
|
|
|
+ other_type_2_name = other_type_2_name,
|
|
|
+ denger_point_name = denger_point_name,
|
|
|
+ person_id = new_person.id,
|
|
|
+ create_by=user_id
|
|
|
+ )
|
|
|
+ db.add(new_person_other_type)
|
|
|
+ except:
|
|
|
+
|
|
|
+ traceback.print_exc()
|
|
|
+ new_person.del_flag='2'
|
|
|
db.commit()
|
|
|
# 返回创建成功的响应
|
|
|
return {
|
|
@@ -223,6 +235,7 @@ async def get_emergency_contact_list(
|
|
|
# 排序
|
|
|
|
|
|
query = query.order_by(ThreeProofingResponsiblePerson.order_num.asc())
|
|
|
+ query = query.order_by(ThreeProofingResponsiblePerson.create_time.desc())
|
|
|
# 执行分页查询
|
|
|
contact_infos = query.offset((page - 1) * pageSize).limit(pageSize).all()
|
|
|
|