Browse Source

250105-2代码。

baoyubo 4 months ago
parent
commit
c8bf746049

+ 29 - 0
models/three_proofing_responsible_base.py

@@ -36,7 +36,19 @@ class ThreeProofingResponsibleType(Base):
     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 ThreeProofingResponsibleOtherType(Base):
+    __tablename__ = 'three_proofing_responsible_other_type'
 
+    id = Column(Integer, primary_key=True, autoincrement=True)
+    type_parent_id = Column(String(255), comment='责任类型id')
+    type_name = Column(String(255), nullable=False, comment='责任类别')
+    order_num = Column(Integer, default=100, comment='排序顺序')
+    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代表删除)')
 
 class ThreeProofingResponsiblePersonType(Base):
     __tablename__ = 'three_proofing_responsible_person_type'
@@ -50,4 +62,21 @@ class ThreeProofingResponsiblePersonType(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 ThreeProofingResponsiblePersonOtherInfo(Base):
+    __tablename__ = 'three_proofing_responsible_person_other_info'
+
+    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')
+    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代表删除)')

+ 88 - 23
routers/api/ThreeProofingResponsible/person.py

@@ -65,16 +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()
         # 返回创建成功的响应
         return {
@@ -118,15 +141,42 @@ 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'
-        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_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,12 +299,27 @@ async def get_emergency_contact_id_info(
             "create_user":user_info.nick_name,
             "type_list":[]
         }
-
+        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['denger_point_name']=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)
         # 返回结果

+ 6 - 0
routers/api/ThreeProofingResponsible/type_data.py

@@ -277,6 +277,12 @@ async def get_dict_data_by_type(
                 for type_info in type_list:
                     children.append({"id":type_info.id,"label":type_info.type_name,"parent_id":type_info.type_parent_id})
                 data['children']=children
+            other_type_list = get_other_type_list_by_type_parent_id(db,parent_info.dict_value)
+            if other_type_list:
+                children = []
+                for type_info in other_type_list:
+                    children.append({"id":type_info.id,"label":type_info.type_name,"parent_id":type_info.type_parent_id})
+                data['children2']=children
             dict_data_list.append(data)
         result = {
             "rows": dict_data_list,

+ 20 - 0
utils/three_proofing_responsible_util.py

@@ -26,6 +26,26 @@ def get_person_type_by_person_id(db,person_id):
     query = db.query(ThreeProofingResponsiblePersonType)
     query = query.filter_by(person_id = person_id,del_flag = '0')
     return query.all()
+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.first()
+def get_person_other_type_by_person_id(db,person_id):
+    query = db.query(ThreeProofingResponsiblePersonOtherInfo)
+    query = query.filter_by(person_id = person_id,del_flag = '0')
+    return query.all()
+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):
+    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_other_type_info_by_id(db,id):
+    query = db.query(ThreeProofingResponsibleOtherType)
+    query = query.filter_by(id = id,del_flag = '0')
+    return query.first()
 def get_person_list_by_type_parent_id(db,type_parent_id):
     query = db.query(ThreeProofingResponsiblePersonType)
     query = query.filter_by(type_parent_id = type_parent_id,del_flag = '0')