-- Spike Status Mapping (G2): seed legado + enum compacto + queries de análise -- Executar APÓS dotnet ef database update -- Uso: sqlcmd -S localhost,1433 -U sa -P "SeaHaven_Dev_2026!" -d SeahavenIndustries -C -i scripts/spike-status-mapping.sql SET NOCOUNT ON; -- --------------------------------------------------------------------------- -- 1. Seed status spike (prefixo SPIKE-STATUS-) -- Cobre formatos legado (com espaço) e canônico API (enum ToString) -- --------------------------------------------------------------------------- IF NOT EXISTS (SELECT 1 FROM workOrders WHERE InternalWONumber LIKE 'SPIKE-STATUS-%') BEGIN DECLARE @weekStart date = CAST(GETDATE() AS date); INSERT INTO workOrders ( InternalWONumber, WorkerOrderTitle, SiteCode, Status, Priority, ScheduledDate, DueDate, Trade, Problem, AssignTo, istemplate, CreatedDate ) VALUES -- Legado Blazor / Sync (com espaço) ('SPIKE-STATUS-001', 'Status spike - Open legado', 'SS1', 'Open', 'Medium', DATEADD(day, 0, @weekStart), DATEADD(day, 5, @weekStart), 'HVAC', 'Repair', NULL, 0, GETDATE()), ('SPIKE-STATUS-002', 'Status spike - In Progress legado','SS2', 'In Progress', 'Medium', DATEADD(day, 1, @weekStart), DATEADD(day, 6, @weekStart), 'Plumbing', 'Repair', NULL, 0, GETDATE()), ('SPIKE-STATUS-003', 'Status spike - On Hold legado', 'SS3', 'On Hold', 'Low', DATEADD(day, 2, @weekStart), DATEADD(day, 10, @weekStart), 'Electrical', 'Hold', NULL, 0, GETDATE()), ('SPIKE-STATUS-004', 'Status spike - Done legado', 'SS4', 'Done', 'Low', DATEADD(day, 3, @weekStart), DATEADD(day, 4, @weekStart), 'General', 'Complete', NULL, 0, GETDATE()), ('SPIKE-STATUS-005', 'Status spike - Cancelled legado', 'SS5', 'Cancelled', 'Low', DATEADD(day, 4, @weekStart), DATEADD(day, 8, @weekStart), 'HVAC', 'Cancelled', NULL, 0, GETDATE()), ('SPIKE-STATUS-006', 'Status spike - UnAssigned legado','SS6', 'UnAssigned', 'Medium', DATEADD(day, 5, @weekStart), DATEADD(day, 7, @weekStart), 'Plumbing', 'Unassigned', NULL, 0, GETDATE()), -- Canônico API (enum ToString) ('SPIKE-STATUS-007', 'Status spike - Open canônico', 'SS7', 'Open', 'Medium', DATEADD(day, 0, @weekStart), DATEADD(day, 5, @weekStart), 'HVAC', 'Repair', NULL, 0, GETDATE()), ('SPIKE-STATUS-008', 'Status spike - InProgress canônico','SS8', 'InProgress', 'High', DATEADD(day, 1, @weekStart), DATEADD(day, 6, @weekStart), 'Plumbing', 'Repair', NULL, 0, GETDATE()), ('SPIKE-STATUS-009', 'Status spike - OnHold canônico', 'SS9', 'OnHold', 'Low', DATEADD(day, 2, @weekStart), DATEADD(day, 10, @weekStart), 'Electrical', 'Hold', NULL, 0, GETDATE()), ('SPIKE-STATUS-010', 'Status spike - Completed canônico','SS10','Completed', 'Low', DATEADD(day, 3, @weekStart), DATEADD(day, 4, @weekStart), 'General', 'Complete', NULL, 0, GETDATE()), ('SPIKE-STATUS-011', 'Status spike - Cancelled canônico','SS11','Cancelled', 'Low', DATEADD(day, 4, @weekStart), DATEADD(day, 8, @weekStart), 'HVAC', 'Cancelled', NULL, 0, GETDATE()), -- Open sem assignee (derivado Unassigned no board) ('SPIKE-STATUS-012', 'Status spike - Open unassigned', 'SS12','Open', 'Medium', DATEADD(day, 1, @weekStart), DATEADD(day, 3, @weekStart), 'HVAC', 'Repair', NULL, 0, GETDATE()), -- Past due candidato (scheduled no passado, status não terminal) ('SPIKE-STATUS-013', 'Status spike - past due candidate','SS13','In Progress', 'High', DATEADD(day, -3, @weekStart), DATEADD(day, -1, @weekStart), 'HVAC', 'Overdue test', NULL, 0, GETDATE()); PRINT 'Seed status spike: 13 work orders inseridos (prefixo SPIKE-STATUS-).'; END ELSE PRINT 'Seed status spike: já existente — pulando INSERT.'; GO -- --------------------------------------------------------------------------- -- 2. Distribuição Status (todos os WOs não-template) -- --------------------------------------------------------------------------- PRINT '--- Distribuição Status ---'; SELECT Status, COUNT(*) AS Cnt FROM workOrders WHERE istemplate IS NULL OR istemplate = 0 GROUP BY Status ORDER BY Cnt DESC; -- --------------------------------------------------------------------------- -- 3. Status x assignee (detectar Unassigned implícito) -- --------------------------------------------------------------------------- PRINT '--- Status x AssignTo (Unassigned implícito) ---'; SELECT Status, CASE WHEN AssignTo IS NULL OR LTRIM(RTRIM(AssignTo)) = '' THEN 1 ELSE 0 END AS IsUnassigned, COUNT(*) AS Cnt FROM workOrders WHERE istemplate IS NULL OR istemplate = 0 GROUP BY Status, CASE WHEN AssignTo IS NULL OR LTRIM(RTRIM(AssignTo)) = '' THEN 1 ELSE 0 END ORDER BY Status, IsUnassigned; -- --------------------------------------------------------------------------- -- 4. Órfãos — valores não mapeáveis pelo mapper G2 (ajustar lista conforme spike) -- --------------------------------------------------------------------------- PRINT '--- Status órfãos (fora do vocabulário conhecido) ---'; SELECT Status, COUNT(*) AS Cnt FROM workOrders WHERE (istemplate IS NULL OR istemplate = 0) AND Status IS NOT NULL AND LTRIM(RTRIM(Status)) NOT IN ( 'Open', 'In Progress', 'On Hold', 'Done', 'Cancelled', 'UnAssigned', 'Unassigned', 'InProgress', 'OnHold', 'Completed', 'new', 'assigned', 'in_progress', 'on_hold', 'completed', 'cancelled', 'unknown' ) GROUP BY Status ORDER BY Cnt DESC; -- --------------------------------------------------------------------------- -- 5. Template query PRODUÇÃO (rodar manualmente em prod/staging) -- --------------------------------------------------------------------------- PRINT '--- Template query PRODUÇÃO ---'; -- SELECT Status, COUNT(*) AS Cnt FROM workOrders WHERE istemplate IS NULL OR istemplate = 0 GROUP BY Status ORDER BY Cnt DESC; GO