续约待办派发添加子表单逻辑
This commit is contained in:
@@ -214,6 +214,124 @@ class CommonModule:
|
||||
error_task_logger.error(f"获取续约待办数据时出错: {e}")
|
||||
return None
|
||||
|
||||
def get_renewal_franchisee_details(self):
|
||||
"""
|
||||
从固定数据库中获取续约待办加盟商数据
|
||||
"""
|
||||
try:
|
||||
conn = pymysql.connect(
|
||||
host=Config.BI_CONN_host,
|
||||
database=Config.BI_CONN_INFO_database,
|
||||
user=Config.BI_CONN_INFO_user,
|
||||
password=Config.BI_CONN_INFO_password,
|
||||
)
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("SELECT * FROM ngv_org_code_franchise_group_name")
|
||||
|
||||
rows = cursor.fetchall()
|
||||
cols = [desc[0] or f"col_{i}" for i, desc in enumerate(cursor.description or [])]
|
||||
|
||||
# 构建 DataFrame
|
||||
df = pd.DataFrame(rows, columns=cols) if cols else pd.DataFrame()
|
||||
|
||||
# 重命名前两列为中文
|
||||
rename_map = {df.columns[i]: name for i, name in enumerate(["门店编码", "加盟商"]) if i < len(df.columns)}
|
||||
df.rename(columns=rename_map, inplace=True)
|
||||
|
||||
cursor.close()
|
||||
conn.close()
|
||||
return df
|
||||
|
||||
except Exception as e:
|
||||
error_task_logger.error(f"获取续约待办加盟商数据时出错: {e}")
|
||||
return None
|
||||
|
||||
def get_renewal_last_price_details(self, ):
|
||||
"""
|
||||
从固定数据库中获取续约待办上次购买价格数据
|
||||
"""
|
||||
try:
|
||||
# 获得连接
|
||||
conn = pymysql.connect(
|
||||
host=Config.BI_CONN_host,
|
||||
database=Config.BI_CONN_INFO_database,
|
||||
user=Config.BI_CONN_INFO_user,
|
||||
password=Config.BI_CONN_INFO_password,
|
||||
# charset='utf8mb4', # 设置字符集以避免编码问题
|
||||
# cursorclass=pymysql.cursors.DictCursor # 返回字典形式的结果
|
||||
)
|
||||
cursor = conn.cursor()
|
||||
|
||||
sql = f"""SELECT * FROM saas_renewal_rate_org_code_version_amount_saas;"""
|
||||
# 执行语句并获取结果集
|
||||
cursor.execute(sql)
|
||||
rows = cursor.fetchall()
|
||||
all_fields = cursor.description # 获取所有字段名
|
||||
|
||||
# 执行结果转化为dataframe
|
||||
if rows: # 如果有数据
|
||||
data_NGV = pd.DataFrame(rows)
|
||||
else: # 如果没有数据,返回空 DataFrame
|
||||
data_NGV = pd.DataFrame()
|
||||
headers = [
|
||||
"门店编码", "上次购买价格",
|
||||
]
|
||||
|
||||
data_NGV.columns = headers
|
||||
|
||||
# 关闭数据库连接
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
return data_NGV
|
||||
except Exception as e:
|
||||
error_task_logger.error(f"获取续约待办上次购买价格数据时出错: {e}")
|
||||
return None
|
||||
|
||||
def get_cyclic_increasing_renewal_details(self, ):
|
||||
"""
|
||||
从固定数据库中获取续约待办周期性增购相关数据
|
||||
"""
|
||||
try:
|
||||
# 获得连接
|
||||
conn = pymysql.connect(
|
||||
host=Config.BI_CONN_host,
|
||||
database=Config.BI_CONN_INFO_database,
|
||||
user=Config.BI_CONN_INFO_user,
|
||||
password=Config.BI_CONN_INFO_password,
|
||||
# charset='utf8mb4', # 设置字符集以避免编码问题
|
||||
# cursorclass=pymysql.cursors.DictCursor # 返回字典形式的结果
|
||||
)
|
||||
cursor = conn.cursor()
|
||||
|
||||
sql = f"""SELECT * FROM saas_period_product_fenmu;"""
|
||||
# 执行语句并获取结果集
|
||||
cursor.execute(sql)
|
||||
rows = cursor.fetchall()
|
||||
all_fields = cursor.description # 获取所有字段名
|
||||
|
||||
# 执行结果转化为dataframe
|
||||
if rows: # 如果有数据
|
||||
data_NGV = pd.DataFrame(rows)
|
||||
else: # 如果没有数据,返回空 DataFrame
|
||||
data_NGV = pd.DataFrame()
|
||||
headers = [
|
||||
"应续约月份", "商户中心id", "门店id", "门店编码", "门店名称", "是否主店",
|
||||
"商品名称", "应续约日", "公司id", "公司名称", "公司等级", "加盟商名称",
|
||||
"开户时间", "开户渠道来源", "门店状态", "大区", "小区", "省份", "城市",
|
||||
"区域经理", "运营负责人", "技术专家", "商品数量", "分母金额", "是否续约", "elt时间","月分区",
|
||||
]
|
||||
|
||||
data_NGV.columns = headers
|
||||
# 关闭数据库连接
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
return data_NGV
|
||||
except Exception as e:
|
||||
error_task_logger.error(f"获取续约待办周期性增购数据时出错: {e}")
|
||||
return None
|
||||
|
||||
def get_jcb_details(self, ):
|
||||
"""
|
||||
从固定的数据库中获取前几天的借车宝。
|
||||
|
||||
Reference in New Issue
Block a user