简道云V2.0
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
"""
|
||||
BI相关后台任务模块
|
||||
|
||||
本模块包含BI相关的后台任务,包括:
|
||||
- BI数据处理
|
||||
- BI报表生成
|
||||
|
||||
这些任务在后台线程中执行,不会阻塞主请求。
|
||||
执行完成后会更新简道云表单并自动提交工作流。
|
||||
"""
|
||||
import logging
|
||||
import os
|
||||
import requests
|
||||
import pandas as pd
|
||||
from typing import Dict, Any
|
||||
from tqdm import tqdm
|
||||
from app.tasks.common import update_jiandaoyun, approve_workflow
|
||||
|
||||
logger = logging.getLogger('app')
|
||||
|
||||
|
||||
def bi_task_background(data: Dict[str, Any], cookies: Dict[str, str], df: pd.DataFrame = None, save_path: str = None):
|
||||
"""
|
||||
BI任务后台执行函数
|
||||
|
||||
在后台线程中执行BI相关任务,如数据处理、报表生成等。
|
||||
执行完成后会更新简道云表单并自动提交工作流。
|
||||
|
||||
Args:
|
||||
data: 包含表单ID(api_key)、表单ID(entry_id)、数据ID(data_id)的字典
|
||||
cookies: 用户登录 F6 系统的 cookies 信息(如果需要)
|
||||
df: Excel 文件读取的内容,DataFrame 格式(如果需要)
|
||||
save_path: Excel 文件保存的地址,执行完成后会删除此文件(如果需要)
|
||||
|
||||
Returns:
|
||||
None
|
||||
|
||||
注意:
|
||||
- 这是一个示例函数,需要根据实际BI任务需求进行实现
|
||||
- 执行完成后会自动删除上传的文件(如果提供了save_path)
|
||||
- 执行结果会更新到简道云表单
|
||||
"""
|
||||
try:
|
||||
# TODO: 在这里实现具体的BI任务逻辑
|
||||
# 例如:数据处理、报表生成、数据同步等
|
||||
|
||||
# 示例:处理数据
|
||||
results = []
|
||||
if df is not None:
|
||||
df = df.where(pd.notnull(df), None)
|
||||
for index, row in tqdm(df.iterrows(), total=df.shape[0], desc="处理BI数据"):
|
||||
# TODO: 实现具体的数据处理逻辑
|
||||
# 例如:调用BI API、生成报表、数据转换等
|
||||
result_item = {
|
||||
'行号': index + 1,
|
||||
'状态': '处理成功'
|
||||
}
|
||||
results.append(result_item)
|
||||
else:
|
||||
# 如果没有DataFrame,执行其他BI任务
|
||||
# TODO: 实现其他BI任务逻辑
|
||||
results.append({'状态': 'BI任务执行成功'})
|
||||
|
||||
# 删除文件(如果提供了save_path)
|
||||
if save_path and os.path.exists(save_path):
|
||||
os.remove(save_path)
|
||||
logger.info(f'{save_path}已删除')
|
||||
|
||||
# 格式化结果
|
||||
results_str = f'{results}' if results else 'BI任务执行完成'
|
||||
logger.info(f"BI任务执行结果: {results_str}")
|
||||
|
||||
# 调用api回写改掉 执行明细与执行状态
|
||||
msg = update_jiandaoyun(data, results_str)
|
||||
|
||||
if msg.get('msg'):
|
||||
approve_workflow(data)
|
||||
logger.info('表单已自动提交至下一步')
|
||||
|
||||
except Exception as e:
|
||||
error_msg = f'BI任务执行失败: {str(e)}'
|
||||
logger.error(error_msg, exc_info=True)
|
||||
msg = update_jiandaoyun(data, error_msg)
|
||||
if msg.get('msg'):
|
||||
approve_workflow(data)
|
||||
|
||||
Reference in New Issue
Block a user