mirror of
https://github.com/R0m1k3/CollectFlow.git
synced 2026-10-18 04:36:21 +02:00
feat: Implement PostgreSQL client for FF Nancy to replace per-article HTTP calls with bulk SQL queries.
This commit is contained in:
1 parent
eb8ca92847
commit
1e393753fa
2 files changed
+33
-10
No files matched your search
@@ -311,7 +311,7 @@ export default async function DashboardPage() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const { dateHier, sites, top10Ca, top10Qte, top10Marge, evolution } = data;
|
const { dateHier, sites, top10Ca, top10Qte, top10Marge, evolution, debug } = data;
|
||||||
|
|
||||||
// Totaux réseau
|
// Totaux réseau
|
||||||
const totalCa = sites.reduce((s, r) => s + r.ca_hier, 0);
|
const totalCa = sites.reduce((s, r) => s + r.ca_hier, 0);
|
||||||
@@ -336,6 +336,11 @@ export default async function DashboardPage() {
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* Debug probe — à supprimer une fois les colonnes confirmées */}
|
||||||
|
<div className="rounded-lg px-4 py-2 text-xs font-mono" style={{ background: "var(--bg-elevated)", border: "1px solid var(--border)", color: "var(--text-muted)" }}>
|
||||||
|
🔍 probe: cumstatCol="{debug.cumstatCol ?? "null"}" · mvtart(genremvt=3,400j)={debug.mvtartCount} · statopcajour={debug.statopCount} · cols=[{debug.statopCols.join(", ")}]
|
||||||
|
</div>
|
||||||
|
|
||||||
{/* KPI réseau */}
|
{/* KPI réseau */}
|
||||||
<div className="grid grid-cols-2 md:grid-cols-4 gap-4">
|
<div className="grid grid-cols-2 md:grid-cols-4 gap-4">
|
||||||
<KpiCard
|
<KpiCard
|
||||||
|
|||||||
+27
-9
@@ -499,6 +499,12 @@ export interface DashboardData {
|
|||||||
top10Qte: DashboardTopItem[];
|
top10Qte: DashboardTopItem[];
|
||||||
top10Marge: DashboardTopItem[];
|
top10Marge: DashboardTopItem[];
|
||||||
evolution: DashboardMonthStats[]; // 25 mois pour N vs N-1
|
evolution: DashboardMonthStats[]; // 25 mois pour N vs N-1
|
||||||
|
debug: {
|
||||||
|
cumstatCol: string | null;
|
||||||
|
statopCols: string[];
|
||||||
|
mvtartCount: number;
|
||||||
|
statopCount: number;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -513,27 +519,38 @@ export async function pgGetDashboardData(): Promise<DashboardData> {
|
|||||||
yesterday.setDate(yesterday.getDate() - 1);
|
yesterday.setDate(yesterday.getDate() - 1);
|
||||||
const dateHier = yesterday.toISOString().split("T")[0];
|
const dateHier = yesterday.toISOString().split("T")[0];
|
||||||
|
|
||||||
// Probe schéma : vérifier l'existence de cumstat dans mvtart et de statopcajour
|
// Probe schéma en parallèle avec les vraies requêtes
|
||||||
const [schemaCheck, statopCheck] = await Promise.all([
|
const [schemaCheck, statopCheck, mvtCountCheck, statopCountCheck] = await Promise.all([
|
||||||
db.execute(sql`
|
db.execute(sql`
|
||||||
SELECT column_name FROM information_schema.columns
|
SELECT column_name FROM information_schema.columns
|
||||||
WHERE table_name = 'mvtart' AND column_name ILIKE 'cum%'
|
WHERE table_name = 'mvtart' AND column_name ILIKE 'cum%'
|
||||||
LIMIT 5
|
LIMIT 5
|
||||||
`).catch(() => ({ rows: [] })),
|
`).catch(() => ({ rows: [] })),
|
||||||
db.execute(sql`
|
db.execute(sql`
|
||||||
SELECT column_name FROM information_schema.columns
|
SELECT table_name, column_name FROM information_schema.columns
|
||||||
WHERE table_name ILIKE 'statop%'
|
WHERE table_name ILIKE 'statop%'
|
||||||
ORDER BY table_name, column_name
|
ORDER BY table_name, column_name LIMIT 20
|
||||||
LIMIT 20
|
|
||||||
`).catch(() => ({ rows: [] })),
|
`).catch(() => ({ rows: [] })),
|
||||||
|
db.execute(sql`
|
||||||
|
SELECT COUNT(*)::int AS cnt FROM mvtart
|
||||||
|
WHERE genremvt = 3 AND site IN ('292', '579')
|
||||||
|
AND datmvt >= CURRENT_DATE - 400
|
||||||
|
`).catch(() => ({ rows: [{ cnt: -1 }] })),
|
||||||
|
db.execute(sql`
|
||||||
|
SELECT COUNT(*)::int AS cnt FROM statopcajour
|
||||||
|
WHERE site IN ('292', '579') LIMIT 1
|
||||||
|
`).catch(() => ({ rows: [{ cnt: -1 }] })),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const cumstatCol = (schemaCheck.rows as { column_name: string }[])[0]?.column_name ?? null;
|
const cumstatCol = (schemaCheck.rows as { column_name: string }[])[0]?.column_name ?? null;
|
||||||
const statopCols = (statopCheck.rows as { column_name: string }[]).map(r => r.column_name);
|
const statopCols = (statopCheck.rows as { table_name: string; column_name: string }[]).map(r => `${r.table_name}.${r.column_name}`);
|
||||||
console.log(`[pg-ff] Dashboard schema probe → mvtart cumstat col: "${cumstatCol}", statopcajour cols: [${statopCols.join(", ")}]`);
|
const mvtartCount = Number((mvtCountCheck.rows as { cnt: number }[])[0]?.cnt ?? -1);
|
||||||
|
const statopCount = Number((statopCountCheck.rows as { cnt: number }[])[0]?.cnt ?? -1);
|
||||||
|
console.log(`[pg-ff] Dashboard probe: cumstatCol="${cumstatCol}", mvtart rows(genremvt=3,last400d)=${mvtartCount}, statopcajour rows=${statopCount}`);
|
||||||
|
console.log(`[pg-ff] statopcajour cols: [${statopCols.join(", ")}]`);
|
||||||
|
|
||||||
// Filtre cumstat dynamique selon disponibilité de la colonne
|
// Pas de filtre cumstat pour l'instant — on le ré-ajoutera avec le bon nom de colonne
|
||||||
const cumstatFilter = cumstatCol ? sql`AND m.${sql.raw(cumstatCol)} = 1` : sql``;
|
const cumstatFilter = sql``;
|
||||||
|
|
||||||
const [caTicketsResult, mvtSitesResult, top10CaResult, top10QteResult, top10MargeResult, evolutionResult] =
|
const [caTicketsResult, mvtSitesResult, top10CaResult, top10QteResult, top10MargeResult, evolutionResult] =
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
@@ -685,5 +702,6 @@ export async function pgGetDashboardData(): Promise<DashboardData> {
|
|||||||
top10Qte: top10QteResult.rows as unknown as DashboardTopItem[],
|
top10Qte: top10QteResult.rows as unknown as DashboardTopItem[],
|
||||||
top10Marge: top10MargeResult.rows as unknown as DashboardTopItem[],
|
top10Marge: top10MargeResult.rows as unknown as DashboardTopItem[],
|
||||||
evolution: evolutionResult.rows as unknown as DashboardMonthStats[],
|
evolution: evolutionResult.rows as unknown as DashboardMonthStats[],
|
||||||
|
debug: { cumstatCol, statopCols, mvtartCount, statopCount },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user