Commit 15118f4d by 周立明

阿维塔数据源表解析及结果表生成

1 parent 2cc64922
......@@ -32,6 +32,7 @@ from scheduler import (
LightReformParkScheduler,
OutputValueScheduler,
StoreEffectSummaryScheduler,
AvitaSpecialScheduler,
)
app = Flask(__name__, static_folder='static', static_url_path='')
......@@ -551,6 +552,7 @@ light_reform_inshop_scheduler = LightReformInshopScheduler(app=app)
light_reform_park_scheduler = LightReformParkScheduler(app=app)
output_value_scheduler = OutputValueScheduler(app=app)
store_effect_summary_scheduler = StoreEffectSummaryScheduler(app=app)
avita_special_scheduler = AvitaSpecialScheduler(app=app)
ALL_SCHEDULERS = [
('budget_achievement', scheduler),
......@@ -560,6 +562,7 @@ ALL_SCHEDULERS = [
('light_reform_park', light_reform_park_scheduler),
('output_value', output_value_scheduler),
('store_effect_summary', store_effect_summary_scheduler),
('avita_special', avita_special_scheduler),
]
......
......@@ -169,8 +169,11 @@ class Config:
'need_period': False,
'forms': [],
},
# 阿维塔专项:当前仅需上传主机厂数据表;
# forms[0] 的附件表名为暂定,后续若改名只需改此处。
# 阿维塔专项:当前仅需上传主机厂数据表(表名暂定,后续若改名只改下方 forms)。
# 注意:此「主机厂数据表」为阿维塔专项独立数据表,格式不保证与现有
# 「鸿蒙主机厂数据表」/「广联主机厂数据表」一致,切勿复用
# report_utils.parse_delivery_table(鸿蒙/广联共用结构);
# 后续接入引擎时须按用户实际提供的附件字段解析并写入阿维塔专属结果表。
'avita_special': {
'name': '阿维塔专项',
'need_period': False,
......
# -*- coding: utf-8 -*-
"""探查 taskId=37(阿维塔专项):任务信息 + 附件实际字段。"""
import os
import sys
# 用户级 site-packages(C:/Python314 默认未纳入 sys.path)
SP = r"C:\Users\66\AppData\Roaming\Python\Python314\site-packages"
if SP not in sys.path:
sys.path.insert(0, SP)
import pymysql
import openpyxl
import oss2
from oss_utils import download_file
BASE = r"F:\data-report\data-process"
# ---- 解析 .env ----
def load_env(path):
env = {}
if os.path.exists(path):
with open(path, encoding="utf-8") as f:
for line in f:
line = line.strip()
if not line or line.startswith("#") or "=" not in line:
continue
k, v = line.split("=", 1)
env[k.strip()] = v.strip()
return env
env = load_env(os.path.join(BASE, ".env"))
DB = env["data_report"] if False else None
host, port, user, pwd, db = (
env["MYSQL_HOST"], int(env["MYSQL_PORT"]),
env["MYSQL_USER"], env["MYSQL_PASSWORD"], env["MYSQL_DB"],
)
conn = pymysql.connect(host=host, port=port, user=user, password=pwd,
database=db, charset="utf8mb4")
try:
with conn.cursor(pymysql.cursors.DictCursor) as cur:
cur.execute(
"SELECT id,data_table_type,data_table_type_name,month,status,"
"result_file_url,period_start,period_end,creator FROM data_process_task WHERE id=37")
print("=== TASK 37 ===")
for r in cur.fetchall():
print(r)
cur.execute(
"SELECT id,task_id,form_type,file_name,file_url,file_size,clean_status "
"FROM data_process_file WHERE task_id=37 AND is_deleted=0")
print("\n=== FILES ===")
files = cur.fetchall()
for f in files:
print(f)
finally:
conn.close()
# ---- 下载第一个附件并读表头 ----
if files:
f0 = files[0]
local = os.path.join(BASE, "uploads", "explore", "task37.xlsx")
os.makedirs(os.path.dirname(local), exist_ok=True)
download_file(f0["file_url"], local)
print(f"\n=== 下载完成: {local} ===")
wb = openpyxl.load_workbook(local, read_only=True, data_only=True)
print("SHEETS:", wb.sheetnames)
for sn in wb.sheetnames:
ws = wb[sn]
print(f"\n--- SHEET: {sn} (max_row={ws.max_row}, max_col={ws.max_column}) ---")
rows = list(ws.iter_rows(values_only=True))
for i, r in enumerate(rows[:12]):
print(f"r{i}:", r)
print("... total rows:", len(rows))
......@@ -699,6 +699,66 @@ class ReportLightReformPark(db.Model):
deleted_at = db.Column(db.DateTime, nullable=True)
class AvitaSpecialMonthData(db.Model):
"""阿维塔专项-月份明细数据表(data_table_type=avita_special 的主表,逐门店一行)"""
__tablename__ = 'avita_special_month_data'
__table_args__ = (
{'comment': '阿维塔专项-月份明细数据表(逐门店一行)'},
)
id = db.Column(db.BigInteger, primary_key=True, autoincrement=True, comment='自增主键')
task_id = db.Column(db.Integer, nullable=False, comment='所属任务单据ID')
stat_month = db.Column(db.String(7), nullable=False, comment='统计月份,格式YYYY-MM,如2026-08')
store_name = db.Column(db.String(255), nullable=False, comment='门店名称')
store_short_name = db.Column(db.String(255), comment='门店简称')
store_mode = db.Column(db.String(50), comment='门店模式')
entry_time = db.Column(db.String(10), comment='入驻时间')
regional_operation = db.Column(db.String(100), comment='区域运营')
resident_name = db.Column(db.String(100), comment='驻店姓名')
oem_delivery_count = db.Column(db.Integer, comment='主机厂数据-交付数')
oem_extended_warranty_deal_count = db.Column(db.Integer, comment='主机厂数据-延保成交数')
oem_worry_free_deal_count = db.Column(db.Integer, comment='主机厂数据-无忧成交数')
oem_revenue_per_vehicle = db.Column(db.DECIMAL(12, 2), comment='主机厂数据-门店单车收入(延保+无忧)')
oem_total_output = db.Column(db.DECIMAL(14, 2), comment='主机厂数据-门店总产值')
cutoff_gl_delivery_count = db.Column(db.Integer, comment='广联数据-交付数')
cutoff_gl_visit_count = db.Column(db.Integer, comment='广联数据-触客数')
cutoff_gl_extended_warranty_deal_count = db.Column(db.Integer, comment='广联数据-延保成交数')
cutoff_gl_worry_free_deal_count = db.Column(db.Integer, comment='广联数据-无忧成交数')
is_deleted = db.Column(db.Integer, nullable=False, default=0, comment='是否删除:0正常 / 1已删除(软删除)')
class AvitaSpecialMonthSummaryMetrics(db.Model):
"""阿维塔专项-汇总指标表(data_table_type=avita_special 的汇总行,单任务一行)"""
__tablename__ = 'avita_special_month_summary_metrics'
__table_args__ = (
{'comment': '阿维塔专项-汇总指标表(单任务一行)'},
)
id = db.Column(db.BigInteger, primary_key=True, autoincrement=True, comment='自增主键')
task_id = db.Column(db.Integer, nullable=False, comment='所属任务单据ID')
stat_month = db.Column(db.String(7), nullable=False, comment='统计月份,格式YYYY-MM,如2026-08')
project_name = db.Column(db.String(100), nullable=False, comment='项目')
brand = db.Column(db.String(100), nullable=False, comment='品牌')
store_count = db.Column(db.Integer, comment='门店数')
output_value = db.Column(db.DECIMAL(16, 2), comment='产值')
delivery_count = db.Column(db.Integer, comment='交付数')
pre_sales_visit_count = db.Column(db.Integer, comment='售前触客数')
pre_sales_visit_rate = db.Column(db.DECIMAL(10, 6), comment='售前触客率')
after_sales_store_count = db.Column(db.Integer, comment='售后门店数')
after_sales_scene_open_rate = db.Column(db.DECIMAL(10, 6), comment='售后场景开通率')
after_sales_order_count = db.Column(db.Integer, comment='售后订单数')
vehicle_extended_warranty_deal_count = db.Column(db.Integer, comment='整车延保成交数')
vehicle_extended_warranty_penetration_rate = db.Column(db.DECIMAL(10, 6), comment='整车延保渗透率')
oem_rights_deal_count = db.Column(db.Integer, comment='原厂权益成交数')
oem_rights_penetration_rate = db.Column(db.DECIMAL(10, 6), comment='原厂权益渗透率')
after_sales_scene_open_rate_mom = db.Column(db.DECIMAL(10, 6), comment='售后场景开通率环比')
pre_sales_visit_rate_mom = db.Column(db.DECIMAL(10, 6), comment='售前触客率环比')
vehicle_extended_warranty_penetration_rate_mom = db.Column(db.DECIMAL(10, 6), comment='整车延保渗透率环比')
oem_rights_penetration_rate_mom = db.Column(db.DECIMAL(10, 6), comment='原厂权益渗透率环比')
created_at = db.Column(db.DateTime, default=datetime.now, comment='创建时间')
is_deleted = db.Column(db.Integer, nullable=False, default=0, comment='是否删除:0正常 / 1已删除(软删除)')
class ReportStoreEffectSummary(db.Model):
"""门店店效人效汇总表(整体合计,单任务一行;合并结果表第5个sheet)"""
__tablename__ = 'report_store_effect_summary'
......
......@@ -1435,6 +1435,12 @@ class DataProcessor:
StoreEffectSummaryProcessor(app=self.app).process(task)
return
if getattr(task, 'data_table_type', None) == 'avita_special':
from avita_special_processor import AvitaSpecialProcessor
logger.info(f"[处理任务] 路由 avita_special 任务 {task_id} 至 AvitaSpecialProcessor")
AvitaSpecialProcessor(app=self.app).process(task)
return
# 类型白名单保护:当前引擎仅支持 SUPPORTED_PROCESS_TYPES
if getattr(task, 'data_table_type', None) not in SUPPORTED_PROCESS_TYPES:
raise Exception(
......
......@@ -395,4 +395,37 @@ class StoreEffectSummaryScheduler(NewReportScheduler):
finally:
self._is_processing = False
self._lock.release()
class AvitaSpecialScheduler(NewReportScheduler):
"""阿维塔专项独立调度器(扫描 avita_special 类型任务,交给 AvitaSpecialProcessor 处理)"""
OUTPUT_CATEGORY = 'avita_special'
JOB_NAME = 'avita_special_scan'
def _execute_scan(self):
if not self._lock.acquire(blocking=False):
logger.debug(f"[{self.JOB_NAME}] 上一轮处理尚未完成,跳过本轮扫描")
return
self._is_processing = True
self._last_run_time = datetime.now()
try:
logger.info(f"[{self.JOB_NAME}] 开始扫描 avita_special 待处理任务")
with self.app.app_context():
from avita_special_processor import AvitaSpecialProcessor
processor = AvitaSpecialProcessor(app=self.app)
result = processor.scan_avita_special()
self._last_run_result = result
logger.info(f"[{self.JOB_NAME}] 扫描完成:成功 {result.get('success', 0)} 个,"
f"失败 {result.get('failed', 0)} 个")
except Exception as e:
logger.error(f"[{self.JOB_NAME}] 扫描执行异常: {str(e)}")
self._last_run_result = {'error': str(e)}
finally:
self._is_processing = False
self._lock.release()
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!