import { Router } from 'express' import { prisma } from '../db.js' import { authRequired } from '../middleware.js' const router = Router() router.use(authRequired) // 指标列表: 元数据 + 明细点, 过滤 hidden (数据与脚本保留, 仅不展示) router.get('/indicators', async (_req, res, next) => { try { const rows = await prisma.indicator.findMany({ where: { hidden: false }, include: { points: { orderBy: { period: 'asc' } } }, orderBy: [{ groupName: 'asc' }, { name: 'asc' }], }) // 组装前端友好结构: points 保持从老到新 const indicators = rows.map((r) => ({ id: r.id, name: r.name, groupName: r.groupName, title: r.title, unit: r.unit, source: r.source, frequency: r.frequency, points: r.points.map((p) => ({ period: p.period, value: p.value })), })) res.json({ indicators }) } catch (e) { next(e) } }) router.get('/strategies', async (_req, res, next) => { try { const rows = await prisma.strategy.findMany({ orderBy: { name: 'asc' } }) res.json({ strategies: rows }) } catch (e) { next(e) } }) router.get('/sow', async (_req, res, next) => { try { const rows = await prisma.econ_SowInventory.findMany({ orderBy: { month: 'asc' } }) res.json({ rows }) } catch (e) { next(e) } }) export default router