宜搭api完善

This commit is contained in:
z66
2025-10-11 15:35:15 +08:00
parent 47c42d1a19
commit d6c6ead9f3
10 changed files with 6611 additions and 34 deletions
+10 -2
View File
@@ -285,6 +285,7 @@ class NewExceptionTask:
NGV_data_id = None
reason = None
create_exception =None
# 获取关联数据
for NGV_Data in self.NGV_data_list:
# NGV_Data = NGV_Data.get("data")
@@ -296,9 +297,15 @@ class NewExceptionTask:
# 门店原因
reason = NGV_Data.get("_widget_1758617393828")
logger.info(f"获取关联数据成功:{NGV_data_id}, {province_name}, {city_name}, {area_name}")
# 是否生成异常待办
create_exception = NGV_Data.get("_widget_1758769279995")
# 判断门店原因
if reason in ["门店倒闭", "门店转让", "加盟其他连锁","切换竞品","虚拟门店","重新开户","已退款","二套系统"]:
# if reason in ["门店倒闭", "门店转让", "加盟其他连锁","切换竞品","虚拟门店","重新开户","已退款","二套系统"]:
# continue
# 判断是否继续生成异常待办
if create_exception == "":
continue
@@ -327,7 +334,8 @@ class NewExceptionTask:
"push_day"] != '' else ''},
# 推进日
"_widget_1748246808678": {"value": customer_service}, # 当前跟进人
# "_widget_1748246808678": {"value": customer_service}, # 当前跟进人
"_widget_1748246808678": {"value": "083726094935447433"}, # 当前跟进人
"_widget_1748246808679": {"value": relationship_manager}, # 运营负责人
+1
View File
@@ -13,3 +13,4 @@
2025-09-15 14:06:08,361 - JCB_efficient_car_pickup.py - error_task_logger - ERROR - 接车宝日常派发执行出错:'NoneType' object has no attribute 'iterrows'
2025-09-15 14:14:19,894 - JCB_efficient_car_pickup.py - error_task_logger - ERROR - 接车宝日常派发执行出错:'NoneType' object has no attribute 'iterrows'
2025-09-15 14:17:26,819 - JCB_efficient_car_pickup.py - error_task_logger - ERROR - 接车宝日常派发执行出错:获取接车宝数据失败,返回None
2025-09-26 11:03:13,587 - update_all_NGV_data_daily.py - error_task_logger - ERROR - NGV更新数据执行时发生异常: cannot reindex on an axis with duplicate labels
File diff suppressed because one or more lines are too long
+65 -13
View File
@@ -6,6 +6,7 @@ from api import API
from back_ground_module import CommonModule
from log_config import configure_task_logger, configure_error_task_logger
import concurrent.futures
from tqdm import tqdm
# 获取已经配置好的常规日志记录器
logger = configure_task_logger()
@@ -39,7 +40,9 @@ class UpdateAllNGVDataDaily:
# 获取NGV数据
payload = {"api_key": "675b900991ad2491c69389ca", "entry_id": "675bb02bd2d53c2034c665e4"}
NGV_data_list = api_instance.entry_data_list(payload).get("data", [])
jdy_NGV_data = pd.DataFrame(NGV_data_list)
jdy_NGV_data.to_csv(os.path.join(output_dir, f"jdy_NGV_data.csv"))
payload = {"api_key": "6694d3c4fcb69ca9a111a6c4",
"entry_id": "6769204a1902c9341340a1bc",
@@ -57,6 +60,55 @@ class UpdateAllNGVDataDaily:
data_NGV_j = data_NGV_j[data_NGV_j['org_type'] == '一般']
data_NGV_j1 = data_NGV_j1[data_NGV_j1['org_type'] == '一般']
temp_jdy_NGV_data = jdy_NGV_data.copy()
temp_jdy_NGV_data.reset_index(inplace=True) # 如果 '门店id' 是索引,则先将其转换为普通列
if '_widget_1734062123071' not in temp_jdy_NGV_data.columns:
error_task_logger.error("'门店编码' 不存在")
temp_jdy_NGV_data.rename(columns={'_widget_1734062123071': 'org_code'}, inplace=True)
temp_jdy_NGV_data.set_index('org_code', inplace=True)
# 如果简道云存在,NGV不存在则标记NGV已删除
# 找出在 temp_jdy_NGV_data 中存在,但在 data_NGV_j 中不存在的索引
df1_index = data_NGV_j.set_index('org_code')
ids_in_jdy_not_in_df1 = temp_jdy_NGV_data.index[~temp_jdy_NGV_data.index.isin(df1_index.index)]
# 提取这些行,形成新的 DataFrame
only_in_temp_jdy = temp_jdy_NGV_data.loc[ids_in_jdy_not_in_df1]
# only_in_temp_jdy.to_csv(os.path.join(output_dir, 'only_in_temp_jdy.csv'), index_label='org_code')
# 对数据源已经去掉的门店进行标记
# 标记list
update_list = []
for index, item in only_in_temp_jdy.iterrows():
update_list.append(item["_id"])
data = {
'api_key': Config.SaaS_Tasks_APP_ID,
'entry_id': Config.NGV_TASKS_ENTRY_ID,
"data_ids": update_list,
"data": {"_widget_1754285499851": {"value": "未删除"}}
}
api_instance.entry_data_banch_update(data=data, max_retries=20)
mark_list = []
for index, only_row in only_in_temp_jdy.iterrows():
result = {}
if '_id' in only_in_temp_jdy.columns:
_id_value = str(only_row['_id']) if not pd.isna(only_row['_id']) else None
result["_id"] = _id_value
if result["_id"]:
data = {
'api_key': Config.SaaS_Tasks_APP_ID,
'entry_id': Config.NGV_TASKS_ENTRY_ID,
"data_id": result["_id"],
"data": {"_widget_1754285499851": {"value": "已删除"}}
}
append = {"data_id": result["_id"], "org_code": only_row["org_code"]}
mark_list.append(append)
# print(result["_id"])
api_instance.entry_data_update(data=data, max_retries=20)
# mark_df = pd.DataFrame(mark_list)
# mark_df.to_csv(os.path.join(output_dir, 'mark_list.csv'), index=False)
# 去除不需要的列
columns_to_remove = {'date_id', 'date_fmt', 'pt', 'etl_time'}
@@ -69,8 +121,8 @@ class UpdateAllNGVDataDaily:
df2_filtered = data_NGV_j1[columns_to_keep_df2]
# 设置唯一标识列作为索引
df1_set_index = df1_filtered.set_index('id_own_org')
df2_set_index = df2_filtered.set_index('id_own_org')
df1_set_index = df1_filtered.set_index('org_code')
df2_set_index = df2_filtered.set_index('org_code')
df1_set_index = df1_set_index.astype(str).replace(['nan', 'None'], '', ).fillna("")
df2_set_index = df2_set_index.astype(str).replace(['nan', 'None'], '', ).fillna("")
@@ -108,16 +160,16 @@ class UpdateAllNGVDataDaily:
df2_only_rows = df2_set_index.loc[df2_only_index].copy()
# 保存匹配结果
# df1_common.to_csv(os.path.join(output_dir, 'matched_results.csv'), index_label='id_own_org')
# df1_common.to_csv(os.path.join(output_dir, 'matched_results.csv'), index_label='org_type')
# 保存仅在df1中的行
# df1_only_rows.to_csv(os.path.join(output_dir, 'df1_only_rows.csv'), index_label='id_own_org')
# df1_only_rows.to_csv(os.path.join(output_dir, 'df1_only_rows.csv'), index_label='org_type')
# 保存仅在df2中的行
# df2_only_rows.to_csv(os.path.join(output_dir, 'df2_only_rows.csv'), index_label='id_own_org')
# data_NGV_j.to_csv(os.path.join(output_dir, 'data_NGV_j.csv'), index_label='id_own_org')
# data_NGV_j1.to_csv(os.path.join(output_dir, 'data_NGV_j1.csv'), index_label='id_own_org')
# jdy_NGV_data.to_csv(os.path.join(output_dir, 'jdy_NGV_data.csv'), index_label='id_own_org')
# df2_only_rows.to_csv(os.path.join(output_dir, 'df2_only_rows.csv'), index_label='org_type')
# data_NGV_j.to_csv(os.path.join(output_dir, 'data_NGV_j.csv'), index_label='org_type')
# data_NGV_j1.to_csv(os.path.join(output_dir, 'data_NGV_j1.csv'), index_label='org_type')
# jdy_NGV_data.to_csv(os.path.join(output_dir, 'jdy_NGV_data.csv'), index_label='org_type')
# print(f"\nCSV文件已保存到目录: {output_dir}")
@@ -126,10 +178,10 @@ class UpdateAllNGVDataDaily:
# temp_jdy_NGV_data.to_csv(os.path.join(output_dir, 'jdy_NGV_data.csv'), index=False)
temp_jdy_NGV_data.reset_index(inplace=True) # 如果 '门店id' 是索引,则先将其转换为普通列
# temp_jdy_NGV_data.to_csv(os.path.join(output_dir, 'jdy_NGV_data1.csv'), index=False)
if '_widget_1734062123069' not in temp_jdy_NGV_data.columns:
error_task_logger.error("'门店id' 不存在")
temp_jdy_NGV_data.rename(columns={'_widget_1734062123069': 'id_own_org'}, inplace=True)
temp_jdy_NGV_data.set_index('id_own_org', inplace=True)
if '_widget_1734062123071' not in temp_jdy_NGV_data.columns:
error_task_logger.error("'门店编码' 不存在")
temp_jdy_NGV_data.rename(columns={'_widget_1734062123071': 'org_code'}, inplace=True)
temp_jdy_NGV_data.set_index('org_code', inplace=True)
# 如果简道云存在,NGV不存在则标记NGV已删除
# 找出在 temp_jdy_NGV_data 中存在,但在 df1_common 中不存在的索引
@@ -201,7 +253,7 @@ class UpdateAllNGVDataDaily:
all_data = []
logger.info(f"今日更新数据量为:{len(df1_common)}")
for idx, row in df1_common.iterrows():
for idx, row in tqdm(df1_common.iterrows(), total=len(df1_common), desc="更新数据"):
result = {}
data_dict = {}