소스 검색

250119-1代码。

baoyubo 4 달 전
부모
커밋
2eaf08c82a
3개의 변경된 파일116개의 추가작업 그리고 37개의 파일을 삭제
  1. 90 32
      routers/api/ThreeProofingResponsible/person.py
  2. 17 1
      routers/prod_api/system/area/__init__.py
  3. 9 4
      utils/three_proofing_responsible_util.py

+ 90 - 32
routers/api/ThreeProofingResponsible/person.py

@@ -496,7 +496,7 @@ def other_type_string_type_parent_id_create_data(db,string,type_parent_id,file_i
     type_name_list = [i for i in string.split(',')]
     reslte = []
     for other_type_name in type_name_list:
-        other_type_id = get_type_id_by_type_parent_id_and_type_name(db, type_parent_id, other_type_name)
+        other_type_id = get_other_type_id_by_type_parent_id_and_other_type_name(db, type_parent_id, other_type_name)
         if other_type_id:
             new_person_type = ThreeProofingResponsiblePersonOtherType(
                 type_parent_id=type_parent_id,
@@ -525,27 +525,23 @@ def import_data(db,file_path,user_id,file_info):
         if name == '':
             file_info.remark = file_info.remark+f'\n行<{row+1}>姓名不能为空<{name}>'
             import_status = False
-            continue
         # 所属单位
         unit_name = sheet.cell(row, 1).value
         if unit_name == '':
             file_info.remark = file_info.remark+f'\n行<{row+1}>所属单位不能为空<{unit_name}>'
             import_status = False
-            continue
         unit_id = db_dept.get_dept_id_by_name(db, unit_name)
         # 职务
         position = sheet.cell(row, 2).value
         if position =='':
             file_info.remark = file_info.remark+f'\n行<{row+1}>职务不能为空<{position}>'
             import_status = False
-            continue
 
         # 电话号码(如有多个手机号请用“,”分隔)
-        phone = int(sheet.cell(row, 3).value)
+        phone = str(sheet.cell(row, 3).value)
         if phone =='':
             file_info.remark = file_info.remark+f'\n行<{row+1}>电话号码不能为空<{phone}>'
             import_status = False
-            continue
         phone_list = [i for i in phone.split(',')]
         user_id_1=-1
         for i in phone_list:
@@ -568,9 +564,9 @@ def import_data(db,file_path,user_id,file_info):
         else:
             area_code=get_area_info_by_area_name(db,area_name)
             if area_code is None:
-                file_info.remark = file_info.remark+f'\n行<{row+1}>责任区域未找到<{area_name}>'
+                file_info.remark = file_info.remark+f'\n行<{row+1}>责任区域未找到'
                 import_status = False
-                continue
+            area_code = area_code.id
 
         new_person = ThreeProofingResponsiblePerson(
             unit_id=unit_id,
@@ -591,10 +587,11 @@ def import_data(db,file_path,user_id,file_info):
         a1 = sheet.cell(row, 6).value
         if a1 != '':
             new_type_list,status = string_type_parent_id_create_data(db,a1,'1',file_info,new_person,user_id,row)
-            import_status = status
             if status:
                 db.add_all(new_type_list)
                 data +=new_type_list
+            else:
+                import_status = status
             # type_name_list = [i for i in a1.split(',')]
             # for type_name in type_name_list:
             #     type_id = get_type_id_by_type_parent_id_and_type_name(db, '1', type_name)
@@ -604,10 +601,11 @@ def import_data(db,file_path,user_id,file_info):
         b1 = sheet.cell(row, 8).value
         if b1 != '':
             new_type_list,status = string_type_parent_id_create_data(db,b1,'2',file_info,new_person,user_id,row)
-            import_status = status
             if status:
                 db.add_all(new_type_list)
                 data +=new_type_list
+            else:
+                import_status = status
 
         b2 = sheet.cell(row, 9).value
 
@@ -615,18 +613,22 @@ def import_data(db,file_path,user_id,file_info):
         c1 = sheet.cell(row, 10).value
         if c1!='':
             new_type_list, status = string_type_parent_id_create_data(db, c1, '3', file_info, new_person, user_id,row)
-            import_status = status
+
             if status:
                 db.add_all(new_type_list)
                 data += new_type_list
+            else:
+                import_status = status
         # 成员单位
         d1 = sheet.cell(row, 11).value
         if d1!='':
             new_type_list, status = string_type_parent_id_create_data(db, d1, '4', file_info, new_person, user_id,row)
-            import_status = status
+
             if status:
                 db.add_all(new_type_list)
                 data += new_type_list
+            else:
+                import_status = status
         d2 = sheet.cell(row, 12).value
         if d2!='':
             dept_name = d2
@@ -642,10 +644,12 @@ def import_data(db,file_path,user_id,file_info):
         e1 = sheet.cell(row, 13).value
         if e1!='':
             new_type_list, status = string_type_parent_id_create_data(db, e1, '5', file_info, new_person, user_id,row)
-            import_status = status
+
             if status:
                 db.add_all(new_type_list)
                 data += new_type_list
+            else:
+                import_status = status
         e2 = sheet.cell(row, 14).value
         if e2!='':
             dept_name = e2
@@ -660,29 +664,35 @@ def import_data(db,file_path,user_id,file_info):
         e3 = sheet.cell(row, 15).value
         if e3!='':
             new_type_list,status = other_type_string_type_parent_id_create_data(db,e3,'5',file_info,new_person,user_id,row)
-            import_status = status
+
             if status:
                 db.add_all(new_type_list)
                 data +=new_type_list
+            else:
+                import_status = status
 
         # 行政村
         f1 = sheet.cell(row, 16).value
         if f1!='':
             new_type_list, status = string_type_parent_id_create_data(db, f1, '6', file_info, new_person, user_id,row)
-            import_status = status
+
             if status:
                 db.add_all(new_type_list)
                 data += new_type_list
+            else:
+                import_status = status
 
         # 水利工程
-        g1 = sheet.cell(row, 10).value
+        g1 = sheet.cell(row, 17).value
         if g1!='':
             new_type_list, status = string_type_parent_id_create_data(db, g1, '7', file_info, new_person, user_id,row)
-            import_status = status
+
             if status:
                 db.add_all(new_type_list)
                 data += new_type_list
-        g2 = sheet.cell(row, 11).value
+            else:
+                import_status = status
+        g2 = sheet.cell(row, 18).value
         if g2!='':
             dept_name = g2
             new_person_other_info = ThreeProofingResponsiblePersonOtherInfo(
@@ -693,49 +703,59 @@ def import_data(db,file_path,user_id,file_info):
             )
             db.add(new_person_other_info)
             data.append(new_person_other_info)
-        g3 = sheet.cell(row, 12).value
+        g3 = sheet.cell(row, 19).value
         if g3!='':
             new_type_list, status = other_type_string_type_parent_id_create_data(db, g3, '11', file_info, new_person, user_id,
                                                                       row)
-            import_status = status
+
             if status:
                 db.add_all(new_type_list)
                 data += new_type_list
+            else:
+                import_status = status
 
         # 受威胁转移
-        h1 = sheet.cell(row, 13).value
+        h1 = sheet.cell(row, 20).value
         if h1!='':
             new_type_list, status = string_type_parent_id_create_data(db, h1, '8', file_info, new_person, user_id,row)
-            import_status = status
+
             if status:
                 db.add_all(new_type_list)
                 data += new_type_list
+            else:
+                import_status = status
 
         # 抢险队伍
-        j1 = sheet.cell(row, 14).value
+        j1 = sheet.cell(row, 21).value
         if j1!='':
             new_type_list, status = string_type_parent_id_create_data(db, j1, '9', file_info, new_person, user_id,row)
-            import_status = status
+
             if status:
                 db.add_all(new_type_list)
                 data += new_type_list
-        j2 = sheet.cell(row, 15).value
+            else:
+                import_status = status
+        j2 = sheet.cell(row, 22).value
         if j2!='':
             new_type_list, status = other_type_string_type_parent_id_create_data(db, j2, '9', file_info, new_person, user_id,
                                                                       row)
-            import_status = status
+
             if status:
                 db.add_all(new_type_list)
                 data += new_type_list
+            else:
+                import_status = status
         # 地质灾害
-        k1 = sheet.cell(row, 16).value
+        k1 = sheet.cell(row, 23).value
         if k1!='':
             new_type_list, status = string_type_parent_id_create_data(db, k1, '10', file_info, new_person, user_id,row)
-            import_status = status
+
             if status:
                 db.add_all(new_type_list)
                 data += new_type_list
-        k2 = sheet.cell(row, 17).value
+            else:
+                import_status = status
+        k2 = sheet.cell(row, 24).value
         if k2!='':
             denger_point_name = k2
             new_person_other_info = ThreeProofingResponsiblePersonOtherInfo(
@@ -748,14 +768,16 @@ def import_data(db,file_path,user_id,file_info):
             data.append(new_person_other_info)
 
         # 其他
-        l1 = sheet.cell(row, 18).value
+        l1 = sheet.cell(row, 25).value
         if l1!='':
             new_type_list, status = string_type_parent_id_create_data(db, l1, '11', file_info, new_person, user_id,row)
-            import_status = status
+
             if status:
                 db.add_all(new_type_list)
                 data += new_type_list
-        l2 = sheet.cell(row, 19).value
+            else:
+                import_status = status
+        l2 = sheet.cell(row, 26).value
         if l2!='':
             other_type_2_name = l2
             new_person_other_info = ThreeProofingResponsiblePersonOtherInfo(
@@ -771,6 +793,7 @@ def import_data(db,file_path,user_id,file_info):
     if import_status == False:
         for info in data:
             db.delete(info)
+    file_info.status = 2
     db.commit()
 @router.post('/createImport')
 async def create_contact(
@@ -800,6 +823,7 @@ async def create_contact(
             file_uuid=filename,
             file_name = file_name_desc,
             status = '1',
+            remark = '',
             user_id=user_id
         )
         db.add(new_file)
@@ -824,4 +848,38 @@ async def create_contact(
         traceback.print_exc()
         # 处理异常
         db.rollback()
+        raise HTTPException(status_code=500, detail=str(e))
+
+@router.get("/download/{filename}")
+async def download_file(filename: str,filenameDesc: str = None):
+    """
+    根据提供的文件名下载文件。
+    :param filename: 要下载的文件的名称。
+    """
+    try:
+        # 构造文件的完整路径
+        file_path = os.path.join('', 'uploads/', filename)
+
+        # 检查文件是否存在
+        if not os.path.isfile(file_path):
+            raise HTTPException(status_code=404, detail="文件未找到")
+
+        if not filenameDesc:
+            filenameDesc = filename
+        # 设置文件头部和内容类型
+        headers = {
+            'Content-Disposition': f'attachment; filename={filenameDesc}'
+        }
+
+        # 使用FileResponse返回文件流
+        return FileResponse(
+            path=file_path,
+            headers=headers,
+            media_type='application/octet-stream'  # 可以按需更改为适当的MIME类型
+        )
+
+    except HTTPException as e:
+        raise e
+    except Exception as e:
+        # 处理其他异常情况
         raise HTTPException(status_code=500, detail=str(e))

+ 17 - 1
routers/prod_api/system/area/__init__.py

@@ -84,4 +84,20 @@ def read_all_areas(parent_id:int = 1,db: Session = Depends(get_db)):
         }
     except Exception as e:
         traceback.print_exc()
-        raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
+        raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
+
+
+@router.get("/allTree")
+def read_all_areas(db: Session = Depends(get_db)):
+
+    filename = '/home/python3/xh_twapi01/routers/api/riskManagement/area_tree.json'
+
+    # 打开文件并读取内容
+    with open(filename, 'r', encoding='utf-8') as file:
+        # 加载JSON内容到一个字典
+        data = json.load(file)
+    return {
+        "code": 200,
+        "msg": "成功",
+        "data": data
+        }

+ 9 - 4
utils/three_proofing_responsible_util.py

@@ -22,12 +22,17 @@ def get_type_parent_id_by_type_id(db,type_id):
 def get_type_id_by_type_parent_id_and_type_name(db,type_parent_id,type_name):
     query = db.query(ThreeProofingResponsibleType)
     query = query.filter_by(type_parent_id = type_parent_id,type_name=type_name,del_flag = '0')
-    return query.first().id
-
+    query = query.first()
+    if query:
+        return query.id
+    return None
 def get_other_type_id_by_type_parent_id_and_other_type_name(db,type_parent_id,other_type_name):
     query = db.query(ThreeProofingResponsibleOtherType)
-    query = query.filter_by(type_parent_id = type_parent_id,other_type_name=other_type_name,del_flag = '0')
-    return query.first().id
+    query = query.filter_by(type_parent_id = type_parent_id,type_name=other_type_name,del_flag = '0')
+    query = query.first()
+    if query:
+        return query.id
+    return None
 
 def get_type_parent_id_by_type_list(db,type_parent_id):
     query = db.query(ThreeProofingResponsibleType)