Commit 33316239 by 江名洋

feat(analysis): 合并生态与自然月至单sheet并优化品牌归属及赔付逻辑

1 parent 66b82271
...@@ -316,7 +316,7 @@ async def analysis_generate( ...@@ -316,7 +316,7 @@ async def analysis_generate(
"status": "success", "status": "success",
"message": "分析报表已生成", "message": "分析报表已生成",
"file_path": output_path, "file_path": output_path,
"download_url": "/api/analysis/download", "download_url": "api/analysis/download",
"ecology_store_count": len(ecology_stores), "ecology_store_count": len(ecology_stores),
"nature_store_count": len(nature_stores), "nature_store_count": len(nature_stores),
"ecology_factory_sheets": list(ecology_factory.keys()) if ecology_factory else [], "ecology_factory_sheets": list(ecology_factory.keys()) if ecology_factory else [],
......
...@@ -690,7 +690,7 @@ class ETLService: ...@@ -690,7 +690,7 @@ class ETLService:
SUM(IFNULL(delivery_count, 0)) AS delivery_count, SUM(IFNULL(delivery_count, 0)) AS delivery_count,
SUM(IFNULL(customer_loss_count, 0)) AS customer_loss_count SUM(IFNULL(customer_loss_count, 0)) AS customer_loss_count
FROM ods_merchant_daily_report_huawei FROM ods_merchant_daily_report_huawei
WHERE deleted_flag = 'N' WHERE deleted_flag = 'N'
GROUP BY merchant_id, report_date, scene_type, GROUP BY merchant_id, report_date, scene_type,
IFNULL(first_brand_id, 2365), IFNULL(first_brand_id, 2365),
IFNULL(NULLIF(brand_id, -1), 2695) IFNULL(NULLIF(brand_id, -1), 2695)
...@@ -756,7 +756,10 @@ class ETLService: ...@@ -756,7 +756,10 @@ class ETLService:
""" """
# ========== SQL2: 订单数据写入(仅更新订单列 + 不存在时插入新行)========== # ========== SQL2: 订单数据写入(仅更新订单列 + 不存在时插入新行)==========
sql2 = f""" # 通过 ods_goods_order_customer 获取订单对应的品牌(子品牌),
# 与 ods_merchant_brand_model 直接关联,避免 MAX(child_id) 导致品牌归属错误
order_filter = f"AND DATE(go.install_upgrade_time) BETWEEN '{start}' AND '{end}'" if start and end else ""
sql2: str = f"""
INSERT INTO dws_merchant_daily_wide ( INSERT INTO dws_merchant_daily_wide (
report_date, merchant_id, merchant_name, store_code, report_date, merchant_id, merchant_name, store_code,
province_id, province_name, city_name, region, channel_type, province_id, province_name, city_name, region, channel_type,
...@@ -780,7 +783,7 @@ class ETLService: ...@@ -780,7 +783,7 @@ class ETLService:
os.scene_type, os.scene_type,
IFNULL(bm.brand_id, 2365) AS first_brand_id, IFNULL(bm.brand_id, 2365) AS first_brand_id,
IFNULL(bm.brand_name, '鸿蒙智行') AS first_brand_name, IFNULL(bm.brand_name, '鸿蒙智行') AS first_brand_name,
IFNULL(bm.child_id, 2695) AS brand_id, IFNULL(os.car_childs_brand_id, 2695) AS brand_id,
IFNULL(bm.child_name, '问界') AS brand_name, IFNULL(bm.child_name, '问界') AS brand_name,
0 AS delivery_count, 0 AS delivery_count,
0 AS customer_loss_count, 0 AS customer_loss_count,
...@@ -805,6 +808,8 @@ class ETLService: ...@@ -805,6 +808,8 @@ class ETLService:
go.merchant_id, go.merchant_id,
DATE(go.install_upgrade_time) AS report_date, DATE(go.install_upgrade_time) AS report_date,
go.scene_type, go.scene_type,
goc.car_brand_id,
goc.car_childs_brand_id,
SUM(CASE WHEN (gso.upgrade_goods_type = 178 SUM(CASE WHEN (gso.upgrade_goods_type = 178
OR gso.upgrade_secondary_goods_type = 178 OR gso.upgrade_secondary_goods_type = 178
OR gso.upgrade_third_level_goods_type = 178) THEN 1 ELSE 0 END) AS yb_cnt, OR gso.upgrade_third_level_goods_type = 178) THEN 1 ELSE 0 END) AS yb_cnt,
...@@ -826,25 +831,23 @@ class ETLService: ...@@ -826,25 +831,23 @@ class ETLService:
ON go.order_code = gso.order_code ON go.order_code = gso.order_code
AND gso.deleted_flag = 'N' AND gso.deleted_flag = 'N'
AND gso.status = 1 AND gso.status = 1
INNER JOIN ods_goods_order_customer goc
ON go.order_code = goc.order_code
WHERE go.deleted_flag = 'N' WHERE go.deleted_flag = 'N'
AND go.status IN (4, 6, 12) AND go.status IN (4, 6, 12)
AND (gso.upgrade_goods_type IN (178, 184, 180, 187) AND (gso.upgrade_goods_type IN (178, 184, 180, 187)
OR gso.upgrade_secondary_goods_type IN (178, 184, 180, 187) OR gso.upgrade_secondary_goods_type IN (178, 184, 180, 187)
OR gso.upgrade_third_level_goods_type IN (178, 184, 180, 187)) OR gso.upgrade_third_level_goods_type IN (178, 184, 180, 187))
GROUP BY go.merchant_id, DATE(go.install_upgrade_time), go.scene_type {order_filter}
GROUP BY go.merchant_id, DATE(go.install_upgrade_time), go.scene_type,
goc.car_brand_id, goc.car_childs_brand_id
) os ) os
LEFT JOIN ods_service_merchant sm LEFT JOIN ods_service_merchant sm
ON os.merchant_id = sm.merchant_id AND sm.deleted_flag = 'N' ON os.merchant_id = sm.merchant_id AND sm.deleted_flag = 'N'
LEFT JOIN ( LEFT JOIN ods_merchant_brand_model bm
SELECT merchant_id, ON os.merchant_id = bm.merchant_id
MAX(brand_id) AS brand_id, AND bm.deleted_flag = 'N'
MAX(brand_name) AS brand_name, AND os.car_childs_brand_id = bm.child_id
MAX(child_id) AS child_id,
MAX(child_name) AS child_name
FROM ods_merchant_brand_model
WHERE deleted_flag = 'N'
GROUP BY merchant_id
) bm ON os.merchant_id = bm.merchant_id
LEFT JOIN ( LEFT JOIN (
SELECT merchant_id, SELECT merchant_id,
GROUP_CONCAT(DISTINCT director_name SEPARATOR '/') AS director_name GROUP_CONCAT(DISTINCT director_name SEPARATOR '/') AS director_name
...@@ -866,7 +869,7 @@ class ETLService: ...@@ -866,7 +869,7 @@ class ETLService:
WHERE director_type IN (13, 6) AND deleted_flag = 'N' WHERE director_type IN (13, 6) AND deleted_flag = 'N'
GROUP BY merchant_id GROUP BY merchant_id
) dir_flight ON os.merchant_id = dir_flight.merchant_id ) dir_flight ON os.merchant_id = dir_flight.merchant_id
{filter_str.replace('drv.', 'os.')} WHERE 1=1 {filter_str.replace('drv.', 'os.')}
ON DUPLICATE KEY UPDATE ON DUPLICATE KEY UPDATE
sum_extended_warranty = VALUES(sum_extended_warranty), sum_extended_warranty = VALUES(sum_extended_warranty),
sum_tire_warranty = VALUES(sum_tire_warranty), sum_tire_warranty = VALUES(sum_tire_warranty),
......
...@@ -52,59 +52,59 @@ header { ...@@ -52,59 +52,59 @@ header {
background-color: #34495e; background-color: #34495e;
} }
/* 主体内容布局 */ /* 下拉菜单样式 */
main { .nav-dropdown {
display: flex; position: relative;
flex: 1;
overflow: hidden;
} }
/* 左侧明细导航栏 */ .nav-dropdown-menu {
aside { display: none;
width: 240px; position: absolute;
background-color: white; top: 100%;
border-right: 1px solid #ddd; left: 0;
display: flex; min-width: 180px;
flex-direction: column; background-color: #fff;
overflow-y: auto; border-radius: 4px;
} box-shadow: 0 4px 12px rgba(0,0,0,0.15);
padding: 4px 0;
.menu-group { z-index: 200;
padding: 15px 0; list-style: none;
} }
.menu-title { .nav-dropdown-menu.show {
padding: 0 20px 10px; display: block;
font-size: 12px;
color: #999;
text-transform: uppercase;
letter-spacing: 1px;
} }
.menu-item { .nav-sub-item {
padding: 12px 20px; padding: 10px 20px;
cursor: pointer; cursor: pointer;
color: #333; color: #333;
transition: all 0.3s; font-size: 14px;
white-space: nowrap;
transition: all 0.2s;
} }
.menu-item:hover { .nav-sub-item:hover {
background-color: #f0f2f5; background-color: #f0f2f5;
color: #3498db; color: #1890ff;
} }
.menu-item.active { .nav-sub-item.active-sub {
background-color: #e6f7ff; background-color: #e6f7ff;
color: #1890ff; color: #1890ff;
border-right: 3px solid #1890ff;
} }
/* 右侧内容展示区 */ /* 主体内容布局(全宽,无侧边栏) */
#content-area { main {
flex: 1; flex: 1;
overflow: auto;
}
/* 全宽内容展示区 */
#content-area {
padding: 20px; padding: 20px;
overflow-y: auto;
background-color: #f9f9f9; background-color: #f9f9f9;
min-height: 100%;
} }
.card { .card {
......
...@@ -9,30 +9,35 @@ ...@@ -9,30 +9,35 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>问界门店运营数据分析平台</title> <title>问界门店运营数据分析平台</title>
<link rel="stylesheet" href="/static/css/style.css"> <link rel="stylesheet" href="static/css/style.css">
</head> </head>
<body> <body>
<!-- 顶部导航栏 --> <!-- 顶部导航栏:所有入口集中在下拉菜单中 -->
<header> <header>
<div class="logo">问界运营分析平台</div> <div class="logo">问界运营分析平台</div>
<nav class="nav-links"> <nav class="nav-links">
<div class="nav-item active" data-module="task">任务调度</div> <!-- 任务调度下拉 -->
<div class="nav-item" data-module="analysis">数据分析</div> <div class="nav-item nav-dropdown" data-module="task">
<span class="nav-dropdown-label">任务调度 ▾</span>
<ul class="nav-dropdown-menu">
<li class="nav-sub-item" data-section="ods">ODS 同步任务</li>
<li class="nav-sub-item" data-section="dw">DWS/DWM/DWA 任务</li>
</ul>
</div>
<!-- 数据分析下拉 -->
<div class="nav-item nav-dropdown" data-module="analysis">
<span class="nav-dropdown-label">数据分析 ▾</span>
<ul class="nav-dropdown-menu">
<li class="nav-sub-item" data-section="upload">数据上传</li>
<li class="nav-sub-item" data-section="analysis-modal">模板分析</li>
</ul>
</div>
</nav> </nav>
<div class="user-info">管理员</div> <div class="user-info">管理员</div>
</header> </header>
<main> <main>
<!-- 左侧明细导航栏 --> <!-- 全宽内容展示区(左侧边栏已移除) -->
<aside id="sidebar">
<div class="menu-group">
<div class="menu-title">任务管理</div>
<div class="menu-item active">ODS 同步任务</div>
<div class="menu-item">DWS/DWM/DWA 任务</div>
</div>
</aside>
<!-- 右侧内容展示区 -->
<section id="content-area"> <section id="content-area">
<div class="card"> <div class="card">
<h2 id="content-title">任务调度</h2> <h2 id="content-title">任务调度</h2>
...@@ -152,7 +157,7 @@ ...@@ -152,7 +157,7 @@
</div> </div>
<div id="upload-status-tip" style="margin-top: 20px; display: none; padding: 15px; background: #e6f7ff; border: 1px solid #91d5ff; border-radius: 4px;"> <div id="upload-status-tip" style="margin-top: 20px; display: none; padding: 15px; background: #e6f7ff; border: 1px solid #91d5ff; border-radius: 4px;">
<span style="color: #1890ff;">ℹ️ 正在处理中,您可以前往“数据目录”查看已生成的表。</span> <span style="color: #1890ff;">ℹ️ 正在处理中,您可以前往"数据目录"查看已生成的表。</span>
</div> </div>
</div> </div>
...@@ -166,7 +171,7 @@ ...@@ -166,7 +171,7 @@
<input type="file" id="store-file-input" style="display:none;" accept=".xlsx,.xls"> <input type="file" id="store-file-input" style="display:none;" accept=".xlsx,.xls">
<div style="font-size:30px; margin-bottom:8px;">🏪</div> <div style="font-size:30px; margin-bottom:8px;">🏪</div>
<p id="store-file-name" style="margin:0; font-size:13px; color:#999;">点击选择门店列表文件</p> <p id="store-file-name" style="margin:0; font-size:13px; color:#999;">点击选择门店列表文件</p>
<a href="/api/analysis/template/store" style="font-size:12px; color:#1890ff; text-decoration:none; margin-top:8px; display:inline-block;"> <a href="api/analysis/template/store" style="font-size:12px; color:#1890ff; text-decoration:none; margin-top:8px; display:inline-block;">
📥 下载门店列表模板 📥 下载门店列表模板
</a> </a>
</div> </div>
...@@ -216,7 +221,7 @@ ...@@ -216,7 +221,7 @@
<div id="analysis-result" style="display:none; background: #f6ffed; border: 1px solid #b7eb8f; padding: 20px; border-radius: 8px; text-align: center;"> <div id="analysis-result" style="display:none; background: #f6ffed; border: 1px solid #b7eb8f; padding: 20px; border-radius: 8px; text-align: center;">
<h3 style="color:#52c41a; margin:0 0 10px;">✅ 报表生成成功</h3> <h3 style="color:#52c41a; margin:0 0 10px;">✅ 报表生成成功</h3>
<div id="analysis-result-info" style="font-size:13px; color:#666; margin-bottom:15px;"></div> <div id="analysis-result-info" style="font-size:13px; color:#666; margin-bottom:15px;"></div>
<a id="btn-download-report" href="/api/analysis/download" <a id="btn-download-report" href="api/analysis/download"
style="display:inline-block; padding: 10px 32px; background: #52c41a; color: white; border: none; border-radius: 4px; font-size: 14px; text-decoration: none; cursor: pointer;"> style="display:inline-block; padding: 10px 32px; background: #52c41a; color: white; border: none; border-radius: 4px; font-size: 14px; text-decoration: none; cursor: pointer;">
📥 下载分析报表 📥 下载分析报表
</a> </a>
...@@ -229,7 +234,7 @@ ...@@ -229,7 +234,7 @@
</div> </div>
<div id="welcome-message"> <div id="welcome-message">
<p>欢迎来到问界门店运营数据分析平台。请从左侧选择具体功能进行操作。</p> <p>欢迎来到问界门店运营数据分析平台。请从顶部导航选择功能进行操作。</p>
</div> </div>
</div> </div>
</div> </div>
...@@ -262,6 +267,6 @@ ...@@ -262,6 +267,6 @@
</div> </div>
</div> </div>
<script src="/static/js/app.js"></script> <script src="static/js/app.js"></script>
</body> </body>
</html> </html>
# 文件名: docker-compose.yml version: '3.8'
# 职责: 编排多容器服务,包括后端 API 服务和 MySQL 8 数据库服务。
# 注意: 不要删除这个注释。 services:
app:
build:
context: .
dockerfile: docker/Dockerfile
container_name: data-analyze-webui
ports:
- "9500:9500"
volumes:
- ./app/templates:/app/app/templates
- ./temp_uploads:/app/temp_uploads
env_file:
- .env
restart: unless-stopped
# 文件名: docker/Dockerfile FROM python:3.11-slim
# 职责: 定义后端应用容器镜像构建过程,安装 Python 环境及依赖。
# 注意: 不要删除这个注释。 WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 9500
CMD ["python", "main.py"]
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!