Commit 18dd7d2a by 江名洋

feat(analysis): 适配18列新模板并优化报表生成逻辑

1 parent a64a5713
...@@ -672,11 +672,11 @@ class ETLService: ...@@ -672,11 +672,11 @@ class ETLService:
+ IFNULL(sdrh.after_sale_real_equity_to_shop_count, 0)) AS sum_after_sale_to_shop, + IFNULL(sdrh.after_sale_real_equity_to_shop_count, 0)) AS sum_after_sale_to_shop,
SUM(IFNULL(sdrh.not_delivery_count, 0)) AS sum_not_delivery, SUM(IFNULL(sdrh.not_delivery_count, 0)) AS sum_not_delivery,
SUM(IFNULL(sdrh.total_order_count, 0)) AS sum_order_count, SUM(IFNULL(sdrh.total_order_count, 0)) AS sum_order_count,
SUM(IFNULL(sdrh.extended_warranty_count, 0)) AS sum_extended_warranty, IFNULL(order_sub.yb_cnt, 0) AS sum_extended_warranty,
SUM(IFNULL(sdrh.tire_warranty_count, 0)) AS sum_tire_warranty, IFNULL(order_sub.tire_cnt, 0) AS sum_tire_warranty,
IFNULL(ax_sub.ax_cnt, 0) AS sum_ax_package, IFNULL(order_sub.ax_cnt, 0) AS sum_ax_package,
SUM(IFNULL(sdrh.battery_extended_warranty_count, 0)) AS sum_battery_extended, IFNULL(order_sub.battery_cnt, 0) AS sum_battery_extended,
SUM(IFNULL(sdrh.battery_extended_warranty_money, 0)) AS sum_battery_money, IFNULL(order_sub.battery_money, 0) AS sum_battery_money,
0 AS sum_total_order_money 0 AS sum_total_order_money
FROM ods_staff_daily_report_huawei sdrh FROM ods_staff_daily_report_huawei sdrh
LEFT JOIN ( LEFT JOIN (
...@@ -684,21 +684,36 @@ class ETLService: ...@@ -684,21 +684,36 @@ class ETLService:
go.merchant_id, go.merchant_id,
DATE(go.install_upgrade_time) AS install_date, DATE(go.install_upgrade_time) AS install_date,
go.scene_type, go.scene_type,
COUNT(DISTINCT gso.id) AS ax_cnt SUM(CASE WHEN (gso.upgrade_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,
SUM(CASE WHEN (gso.upgrade_goods_type = 184
OR gso.upgrade_secondary_goods_type = 184
OR gso.upgrade_third_level_goods_type = 184) THEN 1 ELSE 0 END) AS tire_cnt,
SUM(CASE WHEN (gso.upgrade_goods_type = 180
OR gso.upgrade_secondary_goods_type = 180
OR gso.upgrade_third_level_goods_type = 180) THEN 1 ELSE 0 END) AS ax_cnt,
SUM(CASE WHEN (gso.upgrade_goods_type = 187
OR gso.upgrade_secondary_goods_type = 187
OR gso.upgrade_third_level_goods_type = 187) THEN 1 ELSE 0 END) AS battery_cnt,
SUM(CASE WHEN (gso.upgrade_goods_type = 187
OR gso.upgrade_secondary_goods_type = 187
OR gso.upgrade_third_level_goods_type = 187)
THEN (gso.total_price - IFNULL(gso.refund_amount, 0)) ELSE 0 END) AS battery_money
FROM ods_goods_order go FROM ods_goods_order go
INNER JOIN ods_goods_sub_order gso INNER JOIN ods_goods_sub_order gso
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
AND (gso.upgrade_goods_type = 180
OR gso.upgrade_secondary_goods_type = 180
OR gso.upgrade_third_level_goods_type = 180)
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)
OR gso.upgrade_secondary_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 GROUP BY go.merchant_id, DATE(go.install_upgrade_time), go.scene_type
) ax_sub ON sdrh.merchant_id = ax_sub.merchant_id ) order_sub ON sdrh.merchant_id = order_sub.merchant_id
AND sdrh.report_date = ax_sub.install_date AND sdrh.report_date = order_sub.install_date
AND sdrh.scene_type = ax_sub.scene_type AND sdrh.scene_type = order_sub.scene_type
WHERE sdrh.deleted_flag = 'N' WHERE sdrh.deleted_flag = 'N'
GROUP BY sdrh.merchant_id, sdrh.report_date, sdrh.scene_type, GROUP BY sdrh.merchant_id, sdrh.report_date, sdrh.scene_type,
IFNULL(sdrh.first_brand_id, 2365), IFNULL(sdrh.first_brand_id, 2365),
......
...@@ -96,6 +96,17 @@ document.addEventListener('DOMContentLoaded', () => { ...@@ -96,6 +96,17 @@ document.addEventListener('DOMContentLoaded', () => {
document.getElementById('task-history-section').style.display = 'block'; document.getElementById('task-history-section').style.display = 'block';
document.getElementById('content-title').textContent = 'DWS/DWM/DWA 加工任务'; document.getElementById('content-title').textContent = 'DWS/DWM/DWA 加工任务';
refreshHistory('dw'); refreshHistory('dw');
// 初始化默认日期: 上月26号 至 今天
const fmt = d => `${d.getFullYear()}-${String(d.getMonth()+1).padStart(2,'0')}-${String(d.getDate()).padStart(2,'0')}`;
const now = new Date();
const todayStr = fmt(now);
const lastMonth26 = new Date(now.getFullYear(), now.getMonth()-1, 26);
const startStr = fmt(lastMonth26);
const startInput = document.getElementById('dw-start-date');
const endInput = document.getElementById('dw-end-date');
if (startInput && !startInput.value) startInput.value = startStr;
if (endInput && !endInput.value) endInput.value = todayStr;
} }
// --- 任务历史刷新与轮询 --- // --- 任务历史刷新与轮询 ---
...@@ -373,14 +384,11 @@ document.addEventListener('DOMContentLoaded', () => { ...@@ -373,14 +384,11 @@ document.addEventListener('DOMContentLoaded', () => {
document.getElementById('content-title').textContent = '数据分析'; document.getElementById('content-title').textContent = '数据分析';
// 初始化默认日期: 上月26号 至 今天 // 初始化默认日期: 上月26号 至 今天
const fmt = d => `${d.getFullYear()}-${String(d.getMonth()+1).padStart(2,'0')}-${String(d.getDate()).padStart(2,'0')}`;
const now = new Date(); const now = new Date();
const todayStr = now.toISOString().split('T')[0]; const todayStr = fmt(now);
const lastMonth26 = new Date(now.getFullYear(), now.getMonth()-1, 26);
// 计算上月26号 const startStr = fmt(lastMonth26);
const firstOfThisMonth = new Date(now.getFullYear(), now.getMonth(), 1);
const lastDayOfLastMonth = new Date(firstOfThisMonth - 86400000);
const lastMonth26 = new Date(lastDayOfLastMonth.getFullYear(), lastDayOfLastMonth.getMonth(), 26);
const startStr = lastMonth26.toISOString().split('T')[0];
const startInput = document.getElementById('analysis-start-date'); const startInput = document.getElementById('analysis-start-date');
const endInput = document.getElementById('analysis-end-date'); const endInput = document.getElementById('analysis-end-date');
......
...@@ -217,7 +217,7 @@ ...@@ -217,7 +217,7 @@
🚀 开始生成分析报表 🚀 开始生成分析报表
</button> </button>
<p style="font-size:12px; color:#999; margin-top:8px;">根据门店数据与主机厂数据,自动计算生态系数并生成Excel报表</p> <p style="font-size:12px; color:#999; margin-top:8px;">根据门店数据与主机厂数据,自动计算生态系数并生成Excel报表</p>
<p style="font-size:11px; color:#faad14;">📌 使用模板: 输出-问界生态系数生态-模板.xlsx</p> <p style="font-size:11px; color:#faad14;">📌 使用模板: 输出-问界生态系数-模板.xlsx</p>
</div> </div>
<!-- 生成结果提示 --> <!-- 生成结果提示 -->
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!