Initial GLPI daily report workflow
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
-- Query diaria base. No workflow N8N, a data alvo e substituida dinamicamente.
|
||||
-- Regra:
|
||||
-- - abertos: glpi_tickets.date na data alvo
|
||||
-- - fechados: glpi_tickets.closedate na data alvo
|
||||
-- - fechados podem ter sido abertos em dias/semanas anteriores
|
||||
-- - categorias filtradas pelas arvores 7, 16, 17 e 18
|
||||
|
||||
SELECT
|
||||
'{DATA_ALVO}' AS data_alvo,
|
||||
COALESCE(abertos.abertos, 0) AS abertos,
|
||||
COALESCE(fechados.fechados, 0) AS fechados,
|
||||
COALESCE(fechados.fechados, 0) - COALESCE(abertos.abertos, 0) AS saldo,
|
||||
COALESCE(pendentes.pendentes, 0) AS pendentes,
|
||||
COALESCE(alta_prioridade.alta_prioridade_pendentes, 0) AS alta_prioridade_pendentes,
|
||||
COALESCE(categorias.categorias, 'Sem registros') AS categorias_recorrentes,
|
||||
COALESCE(clientes.clientes, 'Sem registros') AS clientes_volume
|
||||
FROM
|
||||
(
|
||||
SELECT COUNT(*) AS abertos
|
||||
FROM glpi_tickets
|
||||
WHERE is_deleted = false
|
||||
AND DATE(date) = '{DATA_ALVO}'
|
||||
AND itilcategories_id IN (
|
||||
SELECT id FROM glpi_itilcategories
|
||||
WHERE JSON_CONTAINS(ancestors_cache, '{"7":7}') OR id = 7
|
||||
OR JSON_CONTAINS(ancestors_cache, '{"16":16}') OR id = 16
|
||||
OR JSON_CONTAINS(ancestors_cache, '{"17":17}') OR id = 17
|
||||
OR JSON_CONTAINS(ancestors_cache, '{"18":18}') OR id = 18
|
||||
)
|
||||
) abertos
|
||||
CROSS JOIN
|
||||
(
|
||||
SELECT COUNT(*) AS fechados
|
||||
FROM glpi_tickets
|
||||
WHERE closedate IS NOT NULL
|
||||
AND is_deleted = false
|
||||
AND DATE(closedate) = '{DATA_ALVO}'
|
||||
AND itilcategories_id IN (
|
||||
SELECT id FROM glpi_itilcategories
|
||||
WHERE JSON_CONTAINS(ancestors_cache, '{"7":7}') OR id = 7
|
||||
OR JSON_CONTAINS(ancestors_cache, '{"16":16}') OR id = 16
|
||||
OR JSON_CONTAINS(ancestors_cache, '{"17":17}') OR id = 17
|
||||
OR JSON_CONTAINS(ancestors_cache, '{"18":18}') OR id = 18
|
||||
)
|
||||
) fechados
|
||||
CROSS JOIN
|
||||
(
|
||||
SELECT COUNT(*) AS pendentes
|
||||
FROM glpi_tickets
|
||||
WHERE is_deleted = false
|
||||
AND status NOT IN (5, 6)
|
||||
AND itilcategories_id IN (
|
||||
SELECT id FROM glpi_itilcategories
|
||||
WHERE JSON_CONTAINS(ancestors_cache, '{"7":7}') OR id = 7
|
||||
OR JSON_CONTAINS(ancestors_cache, '{"16":16}') OR id = 16
|
||||
OR JSON_CONTAINS(ancestors_cache, '{"17":17}') OR id = 17
|
||||
OR JSON_CONTAINS(ancestors_cache, '{"18":18}') OR id = 18
|
||||
)
|
||||
) pendentes
|
||||
CROSS JOIN
|
||||
(
|
||||
SELECT COUNT(*) AS alta_prioridade_pendentes
|
||||
FROM glpi_tickets
|
||||
WHERE is_deleted = false
|
||||
AND status NOT IN (5, 6)
|
||||
AND priority >= 4
|
||||
AND itilcategories_id IN (
|
||||
SELECT id FROM glpi_itilcategories
|
||||
WHERE JSON_CONTAINS(ancestors_cache, '{"7":7}') OR id = 7
|
||||
OR JSON_CONTAINS(ancestors_cache, '{"16":16}') OR id = 16
|
||||
OR JSON_CONTAINS(ancestors_cache, '{"17":17}') OR id = 17
|
||||
OR JSON_CONTAINS(ancestors_cache, '{"18":18}') OR id = 18
|
||||
)
|
||||
) alta_prioridade
|
||||
CROSS JOIN
|
||||
(
|
||||
SELECT COALESCE(GROUP_CONCAT(CONCAT(nome, ': ', total) ORDER BY total DESC SEPARATOR '\n'), 'Sem registros') AS categorias
|
||||
FROM (
|
||||
SELECT COALESCE(c.completename, c.name, 'Nao informado') AS nome, COUNT(*) AS total
|
||||
FROM glpi_tickets t
|
||||
LEFT JOIN glpi_itilcategories c ON c.id = t.itilcategories_id
|
||||
WHERE t.is_deleted = false
|
||||
AND (DATE(t.date) = '{DATA_ALVO}' OR DATE(t.closedate) = '{DATA_ALVO}')
|
||||
AND t.itilcategories_id IN (
|
||||
SELECT id FROM glpi_itilcategories
|
||||
WHERE JSON_CONTAINS(ancestors_cache, '{"7":7}') OR id = 7
|
||||
OR JSON_CONTAINS(ancestors_cache, '{"16":16}') OR id = 16
|
||||
OR JSON_CONTAINS(ancestors_cache, '{"17":17}') OR id = 17
|
||||
OR JSON_CONTAINS(ancestors_cache, '{"18":18}') OR id = 18
|
||||
)
|
||||
GROUP BY t.itilcategories_id, c.completename, c.name
|
||||
ORDER BY total DESC
|
||||
LIMIT 5
|
||||
) ranking_categorias
|
||||
) categorias
|
||||
CROSS JOIN
|
||||
(
|
||||
SELECT COALESCE(GROUP_CONCAT(CONCAT(nome, ': ', total, ' chamados') ORDER BY total DESC SEPARATOR '\n'), 'Sem registros') AS clientes
|
||||
FROM (
|
||||
SELECT COALESCE(e.completename, e.name, 'Nao informado') AS nome, COUNT(*) AS total
|
||||
FROM glpi_tickets t
|
||||
LEFT JOIN glpi_entities e ON e.id = t.entities_id
|
||||
WHERE t.is_deleted = false
|
||||
AND (DATE(t.date) = '{DATA_ALVO}' OR DATE(t.closedate) = '{DATA_ALVO}')
|
||||
AND t.itilcategories_id IN (
|
||||
SELECT id FROM glpi_itilcategories
|
||||
WHERE JSON_CONTAINS(ancestors_cache, '{"7":7}') OR id = 7
|
||||
OR JSON_CONTAINS(ancestors_cache, '{"16":16}') OR id = 16
|
||||
OR JSON_CONTAINS(ancestors_cache, '{"17":17}') OR id = 17
|
||||
OR JSON_CONTAINS(ancestors_cache, '{"18":18}') OR id = 18
|
||||
)
|
||||
GROUP BY t.entities_id, e.completename, e.name
|
||||
ORDER BY total DESC
|
||||
LIMIT 5
|
||||
) ranking_clientes
|
||||
) clientes;
|
||||
Reference in New Issue
Block a user