mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 10:43:13 +00:00
61 lines
1.8 KiB
PowerShell
61 lines
1.8 KiB
PowerShell
# Volume Discovery — Work Orders
|
|
# Executa queries do volume-discovery-report.md contra staging/prod read-only.
|
|
#
|
|
# Uso:
|
|
# $env:SQL_CONNECTION_STRING = "Server=...;Database=...;User Id=...;Password=...;TrustServerCertificate=True"
|
|
# .\scripts\volume-discovery.ps1
|
|
|
|
param(
|
|
[string]$ConnectionString = $env:SQL_CONNECTION_STRING
|
|
)
|
|
|
|
function Get-SqlConnectionArgs([string]$cs) {
|
|
return @("-C", $cs)
|
|
}
|
|
|
|
if ([string]::IsNullOrWhiteSpace($ConnectionString)) {
|
|
Write-Error "Defina SQL_CONNECTION_STRING ou passe -ConnectionString."
|
|
exit 1
|
|
}
|
|
|
|
$queries = @{
|
|
TotalWorkOrders = @"
|
|
SELECT COUNT(*) AS TotalWorkOrders
|
|
FROM workOrders
|
|
WHERE IsDeleted IS NULL OR IsDeleted = 0;
|
|
"@
|
|
P95ProxyMaxPerWeek = @"
|
|
WITH WeeklyCounts AS (
|
|
SELECT DATEPART(iso_week, ScheduledDate) AS IsoWeek,
|
|
YEAR(ScheduledDate) AS IsoYear,
|
|
COUNT(*) AS Cnt
|
|
FROM workOrders
|
|
WHERE ScheduledDate IS NOT NULL
|
|
AND (IsDeleted IS NULL OR IsDeleted = 0)
|
|
GROUP BY DATEPART(iso_week, ScheduledDate), YEAR(ScheduledDate)
|
|
)
|
|
SELECT MAX(Cnt) AS P95ProxyMaxPerWeek,
|
|
AVG(Cnt * 1.0) AS AvgPerWeek
|
|
FROM WeeklyCounts;
|
|
"@
|
|
UnscheduledCount = @"
|
|
SELECT COUNT(*) AS UnscheduledCount
|
|
FROM workOrders
|
|
WHERE ScheduledDate IS NULL
|
|
AND (IsDeleted IS NULL OR IsDeleted = 0)
|
|
AND Status NOT IN ('Completed', 'Complete', 'Cancelled', 'Canceled');
|
|
"@
|
|
}
|
|
|
|
$connArgs = Get-SqlConnectionArgs $ConnectionString
|
|
|
|
Write-Host "=== Volume Discovery ===" -ForegroundColor Cyan
|
|
Write-Host ""
|
|
|
|
foreach ($name in $queries.Keys) {
|
|
Write-Host "--- $name ---" -ForegroundColor Yellow
|
|
sqlcmd @connArgs -Q $queries[$name] -W
|
|
Write-Host ""
|
|
}
|
|
|
|
Write-Host "Preencha docs/work-orders/phase-0/volume-discovery-report.md e docs/work-orders/phase-4/search-tier-decision.md com os resultados."
|