新增并注册项目信息修改
This commit is contained in:
@@ -9,6 +9,7 @@ F6 后台执行模块
|
||||
- 车辆信息管理
|
||||
- 项目信息批量启停
|
||||
- 材料信息批量修改
|
||||
- 项目信息批量修改
|
||||
|
||||
依赖:
|
||||
- requests: HTTP 请求
|
||||
@@ -438,11 +439,11 @@ class F6PluginModule:
|
||||
return {'msg': '正在执行', 'msg_details': '正在执行,请稍后看结果'}
|
||||
|
||||
@staticmethod
|
||||
def disable_material(data: Dict[str, Any]) -> Dict[str, str]:
|
||||
def modify_material(data: Dict[str, Any]) -> Dict[str, str]:
|
||||
"""
|
||||
材料批量启停
|
||||
材料批量修改
|
||||
|
||||
从简道云获取材料批量启停请求,读取 Excel 文件,并在后台线程中批量启停材料。
|
||||
从简道云获取材料批量修改请求,读取 Excel 文件,并在后台线程中批量修改材料。
|
||||
立即返回"正在执行"的提示,实际创建在后台线程中执行。
|
||||
|
||||
Args:
|
||||
@@ -452,12 +453,12 @@ class F6PluginModule:
|
||||
Dict[str, str]: 包含执行状态的字典,{'msg': '正在执行', 'msg_details': '正在执行,请稍后看结果'}
|
||||
"""
|
||||
entry_data = api_instance.entry_data_get(data=data, replace=True)
|
||||
print('执行 材料批量停用/启用')
|
||||
print('执行 材料信息批量修改')
|
||||
username = entry_data['data']['账号']
|
||||
password = entry_data['data']['密码']
|
||||
company_name = entry_data['data']['公司名称']
|
||||
save_path = entry_data['data']['文件保存地址']
|
||||
option = entry_data['data']['项目材料批量操作']
|
||||
option = entry_data['data']['材料信息批量修改']
|
||||
|
||||
login_response = F6Module.login_in(username, password, company_name)
|
||||
if login_response is None:
|
||||
@@ -479,10 +480,52 @@ class F6PluginModule:
|
||||
|
||||
return {'msg': '正在执行', 'msg_details': '正在执行,请稍后看结果'}
|
||||
|
||||
@staticmethod
|
||||
def modify_project(data: Dict[str, Any]) -> Dict[str, str]:
|
||||
"""
|
||||
项目批量修改
|
||||
|
||||
从简道云获取项目批量修改请求,读取 Excel 文件,并在后台线程中批量修改项目。
|
||||
立即返回"正在执行"的提示,实际创建在后台线程中执行。
|
||||
|
||||
Args:
|
||||
data: 包含表单ID(api_key)、表单ID(entry_id)、数据ID(data_id)的字典
|
||||
|
||||
Returns:
|
||||
Dict[str, str]: 包含执行状态的字典,{'msg': '正在执行', 'msg_details': '正在执行,请稍后看结果'}
|
||||
"""
|
||||
entry_data = api_instance.entry_data_get(data=data, replace=True)
|
||||
print('执行 项目信息批量修改')
|
||||
username = entry_data['data']['账号']
|
||||
password = entry_data['data']['密码']
|
||||
company_name = entry_data['data']['公司名称']
|
||||
save_path = entry_data['data']['文件保存地址']
|
||||
option = entry_data['data']['项目信息批量修改']
|
||||
|
||||
login_response = F6Module.login_in(username, password, company_name)
|
||||
if login_response is None:
|
||||
return {'msg': '登录失败'}
|
||||
|
||||
try:
|
||||
df = pd.read_excel(save_path, sheet_name=0, dtype='string')
|
||||
except Exception as e:
|
||||
return {'msg': f'读取Excel文件失败: {str(e)},文件路径:{save_path}'}
|
||||
|
||||
cookies = requests.utils.dict_from_cookiejar(login_response.cookies)
|
||||
|
||||
try:
|
||||
thread = threading.Thread(target=batch_modify_projects,
|
||||
args=(data, cookies, df, save_path, option))
|
||||
thread.start()
|
||||
except Exception as e:
|
||||
print(f'创建线程失败: {str(e)}')
|
||||
|
||||
return {'msg': '正在执行', 'msg_details': '正在执行,请稍后看结果'}
|
||||
|
||||
@staticmethod
|
||||
def bi_task(data: Dict[str, Any]) -> Dict[str, str]:
|
||||
"""
|
||||
BI任务
|
||||
BI任务(示例)
|
||||
|
||||
从简道云获取BI任务请求,读取 Excel 文件(如果需要),并在后台线程中执行BI任务。
|
||||
立即返回"正在执行"的提示,实际执行在后台线程中完成。
|
||||
|
||||
@@ -30,6 +30,7 @@ from app.tasks.customer_tasks import modify_customer_info_background
|
||||
from app.tasks.bi_tasks import bi_task_background
|
||||
|
||||
from app.tasks.material_tasks import ( \
|
||||
batch_modify_projects,
|
||||
batch_modify_materials,
|
||||
batch_disable_projects
|
||||
)
|
||||
@@ -51,4 +52,5 @@ __all__ = [
|
||||
# 项目材料任务
|
||||
'batch_disable_projects',
|
||||
'batch_modify_materials',
|
||||
'batch_modify_projects',
|
||||
]
|
||||
|
||||
+10
-10
@@ -25,7 +25,7 @@ logger = logging.getLogger('app')
|
||||
def batch_disable_projects(data: Dict[str, Any], cookies: Dict[str, str], df: pd.DataFrame, save_path: str,
|
||||
option) -> None:
|
||||
"""
|
||||
项目批量停用后台任务
|
||||
项目批量启停后台任务
|
||||
|
||||
在后台线程中批量停用项目,从 Excel 文件中读取项目编码。
|
||||
执行完成后会更新简道云表单并自动提交工作流。
|
||||
@@ -417,15 +417,15 @@ def batch_modify_projects(data: Dict[str, Any], cookies: Dict[str, str], df: pd.
|
||||
logger.warning(f"业务分类 '{cat_name_clean}' 未在系统中找到")
|
||||
|
||||
update_map[orig_code] = {
|
||||
"new_customCode": row.iloc[1],
|
||||
"new_name": row.iloc[2],
|
||||
"new_serviceCategoryId": category_pk,
|
||||
"new_taxRate": row.iloc[4],
|
||||
"new_memo": row.iloc[5],
|
||||
"new_carCategoryName": row.iloc[6],
|
||||
"new_price": price,
|
||||
"new_workHour": work_hour,
|
||||
"new_amount": amount,
|
||||
"new_customCode": row.iloc[1], # 新的自定义编码,取自当前行的第2列(索引为1)
|
||||
"new_name": row.iloc[2], # 新的名称,取自当前行的第3列(索引为2)
|
||||
"new_serviceCategoryId": category_pk, # 新的服务分类ID,由变量 category_pk 提供(通常为主键)
|
||||
"new_taxRate": row.iloc[4], # 新的税率,取自当前行的第5列(索引为4)
|
||||
"new_memo": row.iloc[5], # 新的备注信息,取自当前行的第6列(索引为5)
|
||||
"new_carCategoryName": row.iloc[6], # 新的车型分类名称,取自当前行的第7列(索引为6)
|
||||
"new_price": price, # 新的价格,由变量 price 提供(可能经过处理或计算)
|
||||
"new_workHour": work_hour, # 新的工时数,由变量 work_hour 提供
|
||||
"new_amount": amount, # 新的金额(可能是价格 × 工时等计算结果),由变量 amount 提供
|
||||
}
|
||||
|
||||
# 第三步:遍历项目,按需更新
|
||||
|
||||
@@ -74,6 +74,12 @@ async def lifespan(app: FastAPI):
|
||||
description='短信签名状态')
|
||||
core_manager.register_action('modify_customer_info', f6_plugin_module.modify_customer_info, 'f6_plugin_module',
|
||||
description='修改客户信息')
|
||||
core_manager.register_action('disable_project', f6_plugin_module.disable_projects, 'f6_plugin_module',
|
||||
description='项目信息批量启停')
|
||||
core_manager.register_action('batch_modify_materials', f6_plugin_module.modify_material, 'f6_plugin_module',
|
||||
description='材料信息批量修改')
|
||||
core_manager.register_action('batch_modify_projects', f6_plugin_module.modify_project, 'f6_plugin_module',
|
||||
description='项目信息批量修改')
|
||||
core_manager.register_action('bi_task', f6_plugin_module.bi_task, 'f6_plugin_module',
|
||||
description='BI任务')
|
||||
|
||||
@@ -86,7 +92,6 @@ async def lifespan(app: FastAPI):
|
||||
app.state.app_tools.scheduler.shutdown(wait=False)
|
||||
app.state.logger.info("应用关闭")
|
||||
|
||||
|
||||
app = FastAPI(
|
||||
title="简道云FastAPI服务",
|
||||
description="简道云插件后端服务,提供数据同步和处理功能",
|
||||
@@ -202,8 +207,6 @@ async def general_exception_handler(request: Request, exc: Exception):
|
||||
error_code="INTERNAL_ERROR"
|
||||
).model_dump(),
|
||||
)
|
||||
|
||||
|
||||
# 路由已移动到 app/api/routes.py
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user