From 2c5b03e41b07582c56dbef8b10a127cf19dd3221 Mon Sep 17 00:00:00 2001 From: freedakgmail Date: Tue, 11 Aug 2026 22:43:18 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=A4=9A=E4=B8=AAAPI?= =?UTF-8?q?=E5=9B=A0schema=E5=89=8D=E7=BC=80=E5=92=8C=E4=B8=8D=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=E5=88=97=E5=AF=BC=E8=87=B4=E7=9A=84=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - /stores/risk: 移除不存在的列名(risk_score等),改回SELECT * - /platform/economics: 移除不存在的列名(platform_share等),改回SELECT * - /stores/:code: 公司均值查询中移除mv_store_risk_rating_monthly不存在的列(repeat_rate_pct等) - /channel: mv_channel_daily在public schema,移除错误的analytics.前缀 - 重建mv_risk_anomaly物化视图:异常阈值从0.05元提高到1元 --- server/src/routes/data.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/server/src/routes/data.ts b/server/src/routes/data.ts index 6fe2567..283ab16 100644 --- a/server/src/routes/data.ts +++ b/server/src/routes/data.ts @@ -129,7 +129,7 @@ router.get('/stores', async (req: AuthRequest, res) => { router.get('/stores/risk', async (req: AuthRequest, res) => { try { const month = parseMonth(req) - const result = await query(`SELECT store_code, store_name, risk_level, risk_score, received, bill_count, avg_daily_received, avg_bill_value, discount_rate_pct, theoretical_margin_pct, member_bill_share_pct, anomaly_rate_pct, repeat_rate_pct, delivery_bill_share_pct, combo_rate_pct, avg_items_per_bill, primary_issue, month_start FROM analytics.mv_store_risk_rating_monthly WHERE month_start = $1 ORDER BY risk_level, received DESC`, [month]) + const result = await query(`SELECT * FROM analytics.mv_store_risk_rating_monthly WHERE month_start = $1 ORDER BY risk_level, received DESC`, [month]) sendSuccess(res, result.rows) } catch (err: any) { sendError(res, err.message) @@ -205,10 +205,10 @@ router.get('/stores/:code', async (req: AuthRequest, res) => { round(avg(discount_rate_pct)::numeric, 1) AS discount, round(avg(theoretical_margin_pct)::numeric, 1) AS margin, round(avg(member_bill_share_pct)::numeric, 1) AS member, - round(avg(COALESCE(repeat_rate_pct, 0))::numeric, 1) AS repeat, - round(avg(COALESCE(delivery_bill_share_pct, 0))::numeric, 1) AS delivery, - round(avg(COALESCE(combo_rate_pct, 0))::numeric, 1) AS combo, - round(avg(COALESCE(avg_items_per_bill, 0))::numeric, 2) AS items + 0 AS repeat, + 0 AS delivery, + 0 AS combo, + 0 AS items FROM analytics.mv_store_risk_rating_monthly WHERE month_start = $1 `, [month]), @@ -353,7 +353,7 @@ router.get('/cost/inventory', async (req: AuthRequest, res) => { router.get('/platform/economics', async (req: AuthRequest, res) => { try { const month = parseMonth(req) - const result = await query(`SELECT store_code, store_name, month_start, platform_share, meituan_received, meituan_cost_rate_pct, eleme_received, eleme_cost_rate_pct, douyin_received, douyin_cost_rate_pct, self_delivery_received, dine_in_received, dine_in_share_pct, delivery_bill_share_pct FROM analytics.mv_store_platform_economics_monthly WHERE month_start = $1 ORDER BY meituan_received DESC NULLS LAST LIMIT 200`, [month]) + const result = await query(`SELECT * FROM analytics.mv_store_platform_economics_monthly WHERE month_start = $1 ORDER BY meituan_received DESC NULLS LAST LIMIT 200`, [month]) sendSuccess(res, result.rows) } catch (err: any) { sendError(res, err.message) @@ -611,7 +611,7 @@ router.get('/channel', async (req: AuthRequest, res) => { const month = parseMonth(req) const result = await query(` SELECT business_date, cash, alipay, wechat, meituan, unionpay, douyin, credit, jd_delivery, meituan_delivery, taobao_delivery - FROM analytics.mv_channel_daily + FROM mv_channel_daily WHERE month = to_char($1::date, 'YYYY-MM') ORDER BY business_date `, [month])