|
@@ -65,15 +65,39 @@ async def create_contact(
|
|
|
db.add(new_person)
|
|
|
db.commit()
|
|
|
type_list = body['type_list']
|
|
|
- for type_id in type_list:
|
|
|
- type_parent_id = get_type_parent_id_by_type_id(db,type_id)
|
|
|
- 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)
|
|
|
+ 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)
|
|
|
|
|
|
db.commit()
|
|
|
# 返回创建成功的响应
|
|
@@ -115,18 +139,45 @@ async def update_contact(
|
|
|
person.order_num = body['order_num']
|
|
|
person.unit_id = db_dept.get_dept_id_by_name(db, body['unit_name'])
|
|
|
type_list = body['type_list']
|
|
|
- old_person_type_list=get_person_type_by_person_id(db,person.id)
|
|
|
+ old_person_type_list = get_person_type_by_person_id(db, person.id)
|
|
|
for old_person_type in old_person_type_list:
|
|
|
- old_person_type.del_flag='2'
|
|
|
- for type_id in type_list:
|
|
|
- type_parent_id = get_type_parent_id_by_type_id(db, type_id)
|
|
|
- new_person_type = ThreeProofingResponsiblePersonType(
|
|
|
- type_parent_id=type_parent_id,
|
|
|
- type_id=type_id,
|
|
|
- person_id=person.id,
|
|
|
- create_by=user_id
|
|
|
- )
|
|
|
- db.add(new_person_type)
|
|
|
+ old_person_type.del_flag = '2'
|
|
|
+ old_person_other_type_list = get_person_other_type_by_person_id(db, person.id)
|
|
|
+ for old_person_other_type in old_person_other_type_list:
|
|
|
+ old_person_other_type.del_flag = '2'
|
|
|
+ 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=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=id,
|
|
|
+ create_by=user_id
|
|
|
+ )
|
|
|
+ db.add(new_person_other_type)
|
|
|
# 更新到数据库会话并提交
|
|
|
db.commit()
|
|
|
|
|
@@ -249,11 +300,27 @@ async def get_emergency_contact_id_info(
|
|
|
"type_list":[]
|
|
|
}
|
|
|
|
|
|
- type_list = get_person_type_by_person_id(db,contact.id)
|
|
|
+ type_parent_id_list = []
|
|
|
+ type_list = get_person_type_by_person_id(db, contact.id)
|
|
|
for type_info in type_list:
|
|
|
- dict_data = get_dict_data_info(db, 'three_proofing', type_info.type_parent_id)
|
|
|
- type_data = get_type_info_by_id(db,type_info.type_id)
|
|
|
- type_data = {"type_parent_id": type_info.type_parent_id, "type_parent": dict_data.dict_label,"type_id":type_info.type_id,"type_name":type_data.type_name}
|
|
|
+ if type_info.type_parent_id not in type_parent_id_list:
|
|
|
+ type_parent_id_list.append(type_info.type_parent_id)
|
|
|
+
|
|
|
+ for type_parent_id in type_parent_id_list:
|
|
|
+ dict_data = get_dict_data_info(db, 'three_proofing', type_parent_id)
|
|
|
+ type_data = {"type_parent_id": type_parent_id, "type_parent": dict_data.dict_label, "children": []}
|
|
|
+ for type_info in get_person_type_by_person_id_and_type_parent_id(db, contact.id, type_parent_id):
|
|
|
+ type_data_info = get_type_info_by_id(db, type_info.type_id)
|
|
|
+ type_data['children'].append({"type_id": type_info.type_id, "type_name": type_data_info.type_name})
|
|
|
+ type_other_info = get_person_other_type_by_person_id_and_type_parent_id(db, contact.id, type_parent_id)
|
|
|
+ if type_other_info:
|
|
|
+ type_data['dept_name'] = type_other_info.dept_name
|
|
|
+ if type_other_info.other_type_id:
|
|
|
+ other_type_info = get_other_type_info_by_id(db, type_other_info.other_type_id)
|
|
|
+ type_data['other_type_name'] = other_type_info.type_name
|
|
|
+ type_data['other_type_id'] = type_other_info.other_type_id
|
|
|
+ type_data['1'] = type_other_info.denger_point_name
|
|
|
+ type_data['other_type_2_name'] = type_other_info.other_type_2_name
|
|
|
|
|
|
contact_result['type_list'].append(type_data)
|
|
|
# 返回结果
|