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])