|
@@ -1153,26 +1153,44 @@ async def get_inspection_task_list(
|
|
|
area = area_code_get_ancestors_names(db, area)
|
|
|
task_info = {
|
|
|
"id": task.id,
|
|
|
- "children_task_id": task.children_task_id,
|
|
|
- "point_name":task.inspection_point_name,
|
|
|
- "area": area,
|
|
|
- "create_time": task.create_time.strftime('%Y-%m-%d'),
|
|
|
- "nick_name": task.nick_name,
|
|
|
- "result": task.inspection_result,
|
|
|
- "fileList": get_file_query_fun(db=db,from_scenario='RiskManagementRiskTaskChildrenTaskResult', foreign_key=task.id),
|
|
|
- "remark":task.remark
|
|
|
+ "子任务表id": task.children_task_id,
|
|
|
+ "经度":task.longitude,
|
|
|
+ "纬度":task.latitude,
|
|
|
+ "巡查点":task.inspection_point_name,
|
|
|
+ "区划": area,
|
|
|
+ "创建时间": task.create_time.strftime('%Y-%m-%d'),
|
|
|
+ "采集人员": task.nick_name,
|
|
|
+ "采集结果": task.inspection_result,
|
|
|
+ # "fileList": get_file_query_fun(db=db,from_scenario='RiskManagementRiskTaskChildrenTaskResult', foreign_key=task.id),
|
|
|
+ "备注":task.remark
|
|
|
}
|
|
|
InspectionTasks_list.append(task_info)
|
|
|
# 返回结果
|
|
|
- return {
|
|
|
- "code": 200,
|
|
|
- "msg": "成功",
|
|
|
- "data": InspectionTasks_list,
|
|
|
- "total": total_items,
|
|
|
- "page": page,
|
|
|
- "pageSize": pageSize,
|
|
|
- "totalPages": (total_items + pageSize - 1) // pageSize
|
|
|
+ import pandas as pd
|
|
|
+ from io import BytesIO
|
|
|
+ # 将查询结果转换为 DataFrame
|
|
|
+ df = pd.DataFrame(InspectionTasks_list)
|
|
|
+
|
|
|
+ # 将 DataFrame 导出为 Excel 文件
|
|
|
+ output = BytesIO()
|
|
|
+ with pd.ExcelWriter(output, engine='openpyxl') as writer:
|
|
|
+ df.to_excel(writer, index=False)
|
|
|
+
|
|
|
+ # 设置响应头
|
|
|
+ output.seek(0)
|
|
|
+ from urllib.parse import quote
|
|
|
+ encoded_filename = f'救援资源要素巡查结果{datetime.now().strftime("%Y%m%d%H%mi%s")}.xlsx'
|
|
|
+ encoded_filename = quote(encoded_filename, encoding='utf-8')
|
|
|
+ headers = {
|
|
|
+ 'Content-Disposition': f'attachment; filename*=UTF-8\'\'{encoded_filename}',
|
|
|
+ 'Content-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
|
|
}
|
|
|
+
|
|
|
+ db_czrz.log(db, auth_user, "救援资源要素管理", f"救援资源要素巡查结果导出数据成功", request.client.host)
|
|
|
+
|
|
|
+ # 返回文件流
|
|
|
+ return StreamingResponse(output, headers=headers)
|
|
|
+
|
|
|
except Exception as e:
|
|
|
# 处理异常
|
|
|
traceback.print_exc()
|