Ver Fonte

250108-1代码。

baoyubo há 5 meses atrás
pai
commit
78a27ff931

+ 10 - 0
common/db/db_area.py

@@ -12,3 +12,13 @@ from utils import *
 def get_region_code_by_gps(db: Session, lng: str, lat: str):
     return "4409"
 
+def id_get_area_info(db: Session,id):
+    query = db.query(GovdataArea)
+    query = query.filter(GovdataArea.id == id)
+    return query.first()
+def id_get_area_parent_list(db: Session,id,li:list = []):
+    area = id_get_area_info(db,id)
+    li.append({"id":id,'label':area.area_name})
+    if area.parent_id<=1:
+        return li[::-1]
+    return id_get_area_parent_list(db,area.parent_id,li)

+ 14 - 1
models/three_proofing_responsible_base.py

@@ -69,7 +69,6 @@ class ThreeProofingResponsiblePersonOtherInfo(Base):
 
     id = Column(Integer, primary_key=True, autoincrement=True)
     dept_name = Column(String(255), comment='单位名称')
-    other_type_id = Column(String(255), comment='其他责任类别id')
     other_type_2_name = Column(String(255), comment='具体类型名称')
     denger_point_name = Column(String(255), comment='隐患点名称')
     type_parent_id = Column(String(255), nullable=False, comment='责任类型id')
@@ -79,4 +78,18 @@ class ThreeProofingResponsiblePersonOtherInfo(Base):
     create_dept = Column(BigInteger, default=None, comment='创建部门')
     create_by = Column(BigInteger, default=None, comment='创建者')
     update_by = Column(BigInteger, default=None, comment='更新者')
+    del_flag = Column(String(1), default='0', comment='删除标志(0代表存在 2代表删除)')
+
+class ThreeProofingResponsiblePersonOtherType(Base):
+    __tablename__ = 'three_proofing_responsible_person_other_type'
+
+    id = Column(Integer, primary_key=True, autoincrement=True)
+    other_type_id = Column(String(255), comment='其他责任类别id')
+    type_parent_id = Column(String(255), nullable=False, comment='责任类型id')
+    person_id = Column(Integer, nullable=False, comment='责任人id')
+    create_time = Column(DateTime, default=datetime.now, comment='数据创建时间')
+    update_time = Column(DateTime, default=datetime.now, onupdate=datetime.now, comment='数据更新时间')
+    create_dept = Column(BigInteger, default=None, comment='创建部门')
+    create_by = Column(BigInteger, default=None, comment='创建者')
+    update_by = Column(BigInteger, default=None, comment='更新者')
     del_flag = Column(String(1), default='0', comment='删除标志(0代表存在 2代表删除)')

+ 49 - 27
routers/api/ThreeProofingResponsible/person.py

@@ -84,30 +84,36 @@ async def create_contact(
                     )
                     db.add(new_person_type)
                 if type_parent_id in ('5','7','9'):
+                    if 'children2' in type_info:
+                        for other_type_id in type_info['children2']:
+                            new_person_other_type = ThreeProofingResponsiblePersonOtherType(
+                                type_parent_id=type_parent_id,
+                                other_type_id=other_type_id,
+                                person_id=new_person.id,
+                                create_by=user_id
+                            )
+                            db.add(new_person_other_type)
+                if type_parent_id in ('4','5','7','10','11'):
                     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(
+                    new_person_other_info = 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.add(new_person_other_info)
         except:
-
+            db.rollback()
             traceback.print_exc()
             new_person.del_flag='2'
         db.commit()
@@ -154,7 +160,7 @@ async def update_contact(
         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'
-        old_person_other_type_list = get_person_other_type_by_person_id(db,person.id)
+        old_person_other_type_list = get_person_other_info_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:
@@ -168,28 +174,34 @@ async def update_contact(
                 )
                 db.add(new_person_type)
             if type_parent_id in ('5', '7', '9'):
+                if 'children2' in type_info:
+                    for other_type_id in type_info['children2']:
+                        new_person_other_type = ThreeProofingResponsiblePersonOtherType(
+                            type_parent_id=type_parent_id,
+                            other_type_id=other_type_id,
+                            person_id=person.id,
+                            create_by=user_id
+                        )
+                        db.add(new_person_other_type)
+            if type_parent_id in ('4', '5', '7', '10', '11'):
                 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(
+                new_person_other_info = 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,
+                    person_id=person.id,
                     create_by=user_id
                 )
-                db.add(new_person_other_type)
+                db.add(new_person_other_info)
         # 更新到数据库会话并提交
         db.commit()
 
@@ -244,16 +256,21 @@ async def get_emergency_contact_list(
         for info in contact_infos:
             type_parent_id_list = get_type_parent_id_by_person_id(db,info.id)
             type_parent_list = []
+            type_parent_list2 = []
             for type_parent in type_parent_id_list:
-                dict_data = get_dict_data_info(db,'three_proofing',type_parent)
-                type_parent_list.append({"type_parent_id":type_parent,"type_parent":dict_data.dict_label})
+                if type_parent not in type_parent_list2:
+                    dict_data = get_dict_data_info(db,'three_proofing',type_parent)
+                    type_parent_list2.append(type_parent)
+                    type_parent_list.append({"type_parent_id":type_parent,"type_parent":dict_data.dict_label})
             area_info = id_get_area_info(db,info.area_code)
             user_info = user_id_get_user_info(db,info.create_by)
+            area_list = db_area.id_get_area_parent_list(db,info.area_code)
             contact_infos_list.append({
                 "id": info.id,
                 "unit_id": info.unit_id,
                 "unit_name": info.unit_name,
                 "name": info.name,
+                "area_list":area_list,
                 "area_code": info.area_code,
                 "area_name": area_info.area_name,
                 "position": info.position,
@@ -326,16 +343,21 @@ async def get_emergency_contact_id_info(
             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
+                type_data['children'].append({"id": type_info.type_id, "label": type_data_info.type_name})
+            other_info = get_person_other_info_by_person_id_and_type_parent_id(db, contact.id, type_parent_id)
+            if other_info:
+                type_data['dept_name'] = other_info.dept_name
+                type_data['denger_point_name'] = other_info.denger_point_name
+                type_data['other_type_2_name'] = other_info.other_type_2_name
+            other_type_list = get_person_other_type_by_person_id_and_type_parent_id(db, contact.id, type_parent_id)
+            if other_type_list:
+                type_data['children2'] = []
+            for other_type in other_type_list:
+                other_type_info = get_other_type_info_by_id(db, other_type.other_type_id)
+                label= ''
+                if other_type_info:
+                    label = other_type_info.type_name
+                type_data['children2'].append({"id": other_type.other_type_id, "label": label})
 
             contact_result['type_list'].append(type_data)
         # 返回结果

+ 41 - 26
routers/api/ThreeProofingResponsible/person_self.py

@@ -84,28 +84,34 @@ async def create_contact(
                     )
                     db.add(new_person_type)
                 if type_parent_id in ('5', '7', '9'):
+                    if 'children2' in type_info:
+                        for other_type_id in type_info['children2']:
+                            new_person_other_type = ThreeProofingResponsiblePersonOtherType(
+                                type_parent_id=type_parent_id,
+                                other_type_id=other_type_id,
+                                person_id=new_person.id,
+                                create_by=user_id
+                            )
+                            db.add(new_person_other_type)
+                if type_parent_id in ('4', '5', '7', '10', '11'):
                     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(
+                    new_person_other_info = 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.add(new_person_other_info)
         except:
 
             traceback.print_exc()
@@ -154,7 +160,7 @@ async def update_contact(
         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'
-        old_person_other_type_list = get_person_other_type_by_person_id(db, person.id)
+        old_person_other_type_list = get_person_other_info_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:
@@ -168,28 +174,34 @@ async def update_contact(
                 )
                 db.add(new_person_type)
             if type_parent_id in ('5', '7', '9'):
+                if 'children2' in type_info:
+                    for other_type_id in type_info['children2']:
+                        new_person_other_type = ThreeProofingResponsiblePersonOtherType(
+                            type_parent_id=type_parent_id,
+                            other_type_id=other_type_id,
+                            person_id=person.id,
+                            create_by=user_id
+                        )
+                        db.add(new_person_other_type)
+            if type_parent_id in ('4', '5', '7', '10', '11'):
                 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(
+                new_person_other_info = 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,
+                    person_id=person.id,
                     create_by=user_id
                 )
-                db.add(new_person_other_type)
+                db.add(new_person_other_info)
         # 更新到数据库会话并提交
         db.commit()
 
@@ -324,18 +336,21 @@ async def get_emergency_contact_id_info(
             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)
+                type_data['children'].append({"id": type_info.type_id, "label": type_data_info.type_name})
+            other_info = get_person_other_info_by_person_id_and_type_parent_id(db, contact.id, type_parent_id)
+            if other_info:
+                type_data['dept_name'] = other_info.dept_name
+                type_data['denger_point_name'] = other_info.denger_point_name
+                type_data['other_type_2_name'] = other_info.other_type_2_name
+            other_type_list = get_person_other_type_by_person_id_and_type_parent_id(db, contact.id, type_parent_id)
+            if other_type_list:
+                type_data['children2'] = []
+            for other_type in other_type_list:
+                other_type_info = get_other_type_info_by_id(db, other_type.other_type_id)
+                label = ''
+                if other_type_info:
+                    label = other_type_info.type_name
+                type_data['children2'].append({"id": other_type.other_type_id, "label": label})
         # 返回结果
         return {
             "code": 200,

+ 6 - 2
utils/three_proofing_responsible_util.py

@@ -30,7 +30,7 @@ def get_person_type_by_person_id_and_type_parent_id(db,person_id,type_parent_id)
     query = db.query(ThreeProofingResponsiblePersonType)
     query = query.filter_by(person_id = person_id,type_parent_id=type_parent_id,del_flag = '0')
     return query.all()
-def get_person_other_type_by_person_id(db,person_id):
+def get_person_other_info_by_person_id(db,person_id):
     query = db.query(ThreeProofingResponsiblePersonOtherInfo)
     query = query.filter_by(person_id = person_id,del_flag = '0')
     return query.all()
@@ -38,10 +38,14 @@ def get_other_type_list_by_type_parent_id(db,type_parent_id):
     query = db.query(ThreeProofingResponsibleOtherType)
     query = query.filter_by(type_parent_id = type_parent_id,del_flag = '0')
     return query.all()
-def get_person_other_type_by_person_id_and_type_parent_id(db,person_id,type_parent_id):
+def get_person_other_info_by_person_id_and_type_parent_id(db,person_id,type_parent_id):
     query = db.query(ThreeProofingResponsiblePersonOtherInfo)
     query = query.filter_by(person_id = person_id,type_parent_id=type_parent_id,del_flag = '0')
     return query.first()
+def get_person_other_type_by_person_id_and_type_parent_id(db,person_id,type_parent_id):
+    query = db.query(ThreeProofingResponsiblePersonOtherType)
+    query = query.filter_by(person_id = person_id,type_parent_id=type_parent_id,del_flag = '0')
+    return query.all()
 def get_other_type_info_by_id(db,id):
     query = db.query(ThreeProofingResponsibleOtherType)
     query = query.filter_by(id = id,del_flag = '0')