ソースを参照

250414-1代码。

baoyubo 2 ヶ月 前
コミット
947ca98907

+ 1 - 1
routers/api/resourceProvison/MaterialReserveManagement/material_type.py

@@ -114,7 +114,7 @@ async def get_pattern_list(
         # 排序
         if pageSize is None:
             pageSize=total_items
-        query = query.order_by(ResourceProvisionMaterialType.create_time.desc())
+        query = query.order_by(ResourceProvisionMaterialType.sort_order.asc())
         # 执行分页查询
         lists = query.offset((page - 1) * pageSize).limit(pageSize).all()
         data = [{"parent_id": info.parent_id,

+ 44 - 0
routers/api/spatialAnalysis/__init__.py

@@ -148,6 +148,50 @@ async def mine(request: Request,body = Depends(remove_xss_json),db: Session = De
         traceback.print_exc()
         raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
 
+@router.post('/get_area_count')
+async def mine(request: Request,body = Depends(remove_xss_json),db: Session = Depends(get_db)):
+    try:
+        town_count = 0
+        village_count = 0
+        populationSize = 0
+        areaSize = 0
+        GDP= 0
+        if body:
+            query = []
+            print(time.time())
+            for location in body:
+                location = convert_to_polygon(location)  # ,geometry
+                query.append(f" ST_Intersects(geometry,ST_PolygonFromText( '{location}', 4326 )) ")
+            querystr = 'or'.join(query)
+            print(time.time())
+            townsql = text(
+                f"""SELECT DISTINCT pac FROM tp_geojson_data_zj WHERE {querystr} """)
+            # print(sql)
+            townresutl = db.execute(townsql).all()
+            town_count = len(townresutl)
+            town_list = [i['pac'] for i in townresutl]
+            print(time.time())
+            villagesql = text(
+                f"""SELECT count(1)as cn FROM tp_geojson_data_cj_sq WHERE {querystr} """)
+            print(villagesql)
+            villageresutl = db.execute(villagesql).first()
+            village_count = villageresutl['cn']
+            print(time.time())
+        return {
+            "code": 200,
+            "msg": "成功",
+            "data": {
+                "townCount": town_count,
+                "villageCount": village_count,
+                "populationSize": populationSize,
+                "areaSize": areaSize,
+                "GDP": GDP,
+                "town_list":town_list
+            }
+        }
+    except Exception as e:
+        traceback.print_exc()
+        raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
 @router.get('/get_mms_area_info')
 async def mine(request: Request,body = Depends(remove_xss_json),db: Session = Depends(get_db)):
     try:

+ 2 - 0
routers/prod_api/system/dic/__init__.py

@@ -290,6 +290,8 @@ async def get_dict_data_by_type(
 
         # 计算总记录数
         total_count = query.count()
+        # 排序
+        query = query.order_by(SysDictData.dict_sort.asc())
 
         # 计算分页
         offset = (pageNum - 1) * pageSize

+ 49 - 0
routers/prod_api/system/user/__init__.py

@@ -2,8 +2,10 @@
 # -*- coding: utf-8 -*-
 
 from fastapi import APIRouter, Request, Depends,Query,HTTPException
+from fastapi.responses import StreamingResponse
 from database import get_db
 from sqlalchemy.orm import Session
+from sqlalchemy import inspect,text
 from fastapi.responses import JSONResponse
 from models import *
 from utils import *
@@ -180,6 +182,53 @@ async def userupdate(
         raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
 
 
+@router.post("/export")
+async def export_to_excel(
+    db: Session = Depends(get_db),
+    user_id: str = Depends(valid_access_token)
+):
+    # 获取对应填报ID的数据表名称
+
+
+    data_table_name = 'sys_user'
+    # 获取表结构(用户填报的字段)
+    inspector = inspect(db.bind)
+    columns = inspector.get_columns(data_table_name)
+
+    # 提取用户填报的字段注释
+    user_report_columns = [col for col in columns if col['name'] in ['user_id', 'dept_id', 'user_name', 'nick_name', 'phonenumber']]
+    column_comments = [col.get('comment', '') for col in user_report_columns]
+
+    # 构建查询SQL,关联 sys_user 表获取 nick_name
+    query_sql = f"""
+        SELECT  {', '.join([f'rd.{col["name"]}' for col in user_report_columns])}
+        FROM {data_table_name} rd where del_flag<>'2'
+    """
+
+    # 使用 text 包装查询字符串
+    result = db.execute(text(query_sql))
+    rows = result.fetchall()
+    import pandas as pd
+    from io import BytesIO
+    # 将查询结果转换为 DataFrame
+    df = pd.DataFrame(rows, columns= column_comments)
+
+    # 将 DataFrame 导出为 Excel 文件
+    output = BytesIO()
+    with pd.ExcelWriter(output, engine='openpyxl') as writer:
+        df.to_excel(writer, index=False, sheet_name='用户列表')
+
+    # 设置响应头
+    output.seek(0)
+    headers = {
+        'Content-Disposition': 'attachment; filename="report_data.xlsx"',
+        'Content-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
+    }
+
+    # 返回文件流
+    return StreamingResponse(output, headers=headers)
+
+
 
 
 

+ 0 - 11
utils/spatial/__init__.py

@@ -103,17 +103,6 @@ def get_bqw_yj_quyu_data(area_code,db):
 def get_town_village_list(locations,db):
     # 初始化一个空的MultiPolygon来容纳所有多边形
 
-    # multi_polygon = MultiPolygon()
-    #
-    # # 遍历每个位置,创建多边形并添加到multi_polygon中
-    # for location in locations:
-    #     # 将边界列表转换为Polygon
-    #     polygon = Polygon([(item['x'], item['y']) for item in location])
-    #     multi_polygon = multi_polygon.union(polygon)
-
-    # intersected_towns = db.query(TpZjGeoJSONData).filter(
-    #     func.ST_Intersects(TpZjGeoJSONData.geometry, multi_polygon) == True
-    # ).all()
     intersected_towns = get_town_list2(locations,db)
 
     # 初始化一个空列表来存储结果