添加统计字段

This commit is contained in:
2024-10-08 10:13:06 +08:00
parent 7a07684750
commit 28ca7db56f
3 changed files with 28 additions and 2 deletions

View File

@@ -25,6 +25,7 @@ import java.util.List;
select gen_random_uuid()::text as id,
d.organization_id,
d.name,
d.product_id as product_id,
'' as code,
'' as remarks,
0 as sort_key,
@@ -78,16 +79,17 @@ select gen_random_uuid()::text as id,
array_agg(d.id) as ids
from ((select 1.0 / count(1) over (partition by date_trunc('day', date)) as xx , *
from t_coal_washing_daily_analysis)) d
group by d.organization_id, d.name, date_trunc('month', d.date)
group by d.organization_id, d.name, d.product_id, date_trunc('month', d.date)
""")
@jakarta.persistence.Table(indexes = @jakarta.persistence.Index(name ="idx_coal_washing_month_report_org_id", columnList = "organization_id"))
//@jakarta.persistence.Table(indexes = @jakarta.persistence.Index(name ="idx_coal_washing_month_report_org_id", columnList = "organization_id"))
public class CoalWashingMonthReportEntity extends OrgCommonEntity {
@Comment("日期")
private LocalDate date;
private String productId;
private String remark1;
private String remark2;
private String remark3;

View File

@@ -7,6 +7,9 @@ import cn.lihongjie.coal.pojoProcessor.DictTranslate;
import lombok.Data;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.Formula;
import java.time.LocalDateTime;
@Data
public class MeterDto extends OrgCommonDto {
@@ -23,4 +26,14 @@ public class MeterDto extends OrgCommonDto {
@Comment("ybiot设备id")
private String ybiotDeviceId;
@Formula("(select time from t_meter_log where meter_id = id order by time asc limit 1)")
private LocalDateTime firstLogTime;
@Formula("(select time from t_meter_log where meter_id = id order by time desc limit 1)")
private LocalDateTime lastLogTime;
@Formula("(select value from t_meter_log where meter_id = id order by time desc limit 1)")
private Double lastLogValue;
}

View File

@@ -7,6 +7,9 @@ import jakarta.persistence.Entity;
import lombok.Data;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.Formula;
import java.time.LocalDateTime;
@Data
@Entity
@@ -26,6 +29,14 @@ public class MeterEntity extends OrgCommonEntity {
@Comment("ybiot设备id")
private String ybiotDeviceId;
@Formula("(select time from t_meter_log l where l.meter_id = id order by l.time asc limit 1)")
private LocalDateTime firstLogTime;
@Formula("(select time from t_meter_log l where l.meter_id = id order by l.time desc limit 1)")
private LocalDateTime lastLogTime;
@Formula("(select value from t_meter_log l where l.meter_id = id order by l.time desc limit 1)")
private Double lastLogValue;
}