Обновить gantReport.sql
This commit is contained in:
+6
-6
@@ -50,7 +50,7 @@ checks AS (
|
||||
-- AND UPPER(h.host) NOT LIKE 'IRZ%'
|
||||
-- Период: май 2026 года (измените под свои даты)
|
||||
and hinv.notes is not null and hinv.notes <> ''
|
||||
--and hinv.notes = 'ОБЪЕКТ № 67' --and hinv.name like '%Маршрутизатор%'
|
||||
--and hinv.notes = 'ОБЪЕКТ № 14' --and hinv.name like '%Маршрутизатор%'
|
||||
and CAST(nullif(regexp_replace(hinv.notes, 'ОБЪЕКТ №\s*', '', 'g'),'') as INTEGER)
|
||||
--between 1 and 85
|
||||
in (1,2,4,5,8,9,11,12,14,24,25,27,28,29,30,31,32,34,35,36,38,40,41,42,43,44,45,46,48,49,50,51,53,54,55,57,58,60,62,63,64,65,66,67,68,69,70,76,77,81,82,84,85)
|
||||
@@ -63,7 +63,7 @@ checks_with_prev AS (
|
||||
SELECT
|
||||
*,
|
||||
LAG(status) OVER (PARTITION BY host_name ORDER BY ts) AS prev_status,
|
||||
coalesce(lead(ts) OVER (PARTITION BY host_name ORDER BY ts), date_trunc('month', to_date(${start_dt}, 'yyyymmdd')) + interval '1 month') AS next_ts
|
||||
coalesce(lead(ts) OVER (PARTITION BY host_name ORDER BY ts), date_trunc('day', ts) + interval '1 day') AS next_ts
|
||||
FROM checks
|
||||
), --3. Определяем моменты смены статуса (начало нового интервала)
|
||||
status_changes AS (
|
||||
@@ -110,7 +110,7 @@ intervals AS (
|
||||
SUM(is_start) OVER (PARTITION BY host_name ORDER BY ts) AS interval_id
|
||||
FROM status_changes
|
||||
WHERE status IS NOT null
|
||||
and date_trunc('day', ts) >= to_date(${start_dt}, 'yyyymmdd') and date_trunc('day', ts) <= to_date(${end_dt}, 'yyyymmdd')
|
||||
and date_trunc('day', ts) >= to_date(${start_dt}, 'yyyymmdd') and date_trunc('day', ts) <= to_date(${end_dt}, 'yyyymmdd') and ts <= now()
|
||||
), -- 5. Агрегируем каждый непрерывный интервал
|
||||
grouped_intervals AS (
|
||||
SELECT
|
||||
@@ -307,7 +307,7 @@ router as
|
||||
left join sum_interval i on g.object_num = i.object_num
|
||||
and g.equipment_id = i.equipment_id
|
||||
and g.date_check = i.date_check
|
||||
where abs(extract('minute' from g.time_end_tm - i.available_hours)::int) > 5
|
||||
where (abs(extract('minute' from g.time_end_tm - i.available_hours)::int) > 5 or abs(extract('hours' from g.time_end_tm - i.available_hours)::int) > 0)
|
||||
and g.status = 1
|
||||
union all
|
||||
select g.*, i.available_hours, INTERVAL '00:00:00' as diff_tm, null as diff_fl
|
||||
@@ -377,8 +377,8 @@ SELECT
|
||||
m.equipment_type as "Тип оборудования",
|
||||
m.object_name as "Номер_объекта_ИТС_РО",
|
||||
m.coordinates as "Координаты_расположения",
|
||||
TO_CHAR(u.time_start, 'HH24:MI:SS') AS "Время начала статуса",
|
||||
TO_CHAR(u.time_end, 'HH24:MI:SS') as "Время окончания статуса",
|
||||
case when TO_CHAR(u.time_start, 'HH24:MI:SS') = '24:00:00' then '00:00:00' else TO_CHAR(u.time_start, 'HH24:MI:SS') end AS "Время начала статуса",
|
||||
case when TO_CHAR(u.time_end, 'HH24:MI:SS') = '24:00:00' then '00:00:00' else TO_CHAR(u.time_end, 'HH24:MI:SS') end as "Время окончания статуса",
|
||||
CASE
|
||||
WHEN u.status = 1 THEN 'доступно'
|
||||
ELSE 'недоступно'
|
||||
|
||||
Reference in New Issue
Block a user