处理皮带秤实时数据查询历史记录

This commit is contained in:
2024-06-02 21:29:20 +08:00
parent 8eb44f5dc5
commit 40782eb282

View File

@@ -132,29 +132,39 @@ public class PdcDeviceRealTimeDataService
em.createNativeQuery(
"""
with tmp as (
select dd.device_id, min(dd.total_data) as min_total, max(dd.total_data) as max_total from t_pdc_device_data dd
where dd.device_id in :deviceIds and dd.time >= :startTime and dd.time <= :endTime
group by dd.device_id
)
,
tmp2 as (select rtd.*, d.sort_key as d_sort_key, d.coal_type as coal_type, d.name as device_name, d.code as device_code, d.device_group as device_group, round(cast(rtd.total_data - tmp.min_total as numeric), 3) as time_total
from t_pdc_device_real_time_data rtd
inner join t_pdc_device d on rtd.device_id = d.id
inner join tmp on rtd.device_id = tmp.device_id)
select a.*, round(cast(case when b.time_total is null or b.time_total = 0 then 0 else ((a.time_total / b.time_total) * 100.0) end as numeric),3)as time_percent, b.time_total as bt from tmp2 a left join tmp2 b on b.coal_type = '2'
order by a.d_sort_key
with tmp as (
select dd.device_id, min(dd.total_data) as min_total, max(dd.total_data) as max_total from t_pdc_device_data dd
where dd.device_id in :deviceIds and dd.time >= :startTime and dd.time <= :endTime
group by dd.device_id
)
,
tmp1 as (
select dd.*, rank() over (partition by dd.device_id order by dd.time desc ,dd.create_time desc) as rk from t_pdc_device_data dd where dd.device_id in :deviceIds and dd.time >= :startTime and dd.time <= :endTime
),
tmp11 as (
select * from tmp1 where rk = 1
),
tmp2 as (select rtd.*, d.sort_key as d_sort_key, d.coal_type as coal_type, d.name as device_name, d.code as device_code, d.device_group as device_group, round(cast(rtd.total_data - tmp.min_total as numeric), 3) as time_total
from tmp11 rtd
inner join t_pdc_device d on rtd.device_id = d.id
inner join tmp on rtd.device_id = tmp.device_id
)
select a.*, round(cast(case when b.time_total is null or b.time_total = 0 then 0 else ((a.time_total / b.time_total) * 100.0) end as numeric),3)as time_percent, b.time_total as bt from tmp2 a left join tmp2 b on b.coal_type = '2'
order by a.d_sort_key
""",
""",
Tuple.class);