From 28ca7db56f5b754bf9421b82f0b41e670362c32d Mon Sep 17 00:00:00 2001 From: lihongjie0209 Date: Tue, 8 Oct 2024 10:13:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=BB=9F=E8=AE=A1=E5=AD=97?= =?UTF-8?q?=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/CoalWashingMonthReportEntity.java | 6 ++++-- .../java/cn/lihongjie/coal/meter/dto/MeterDto.java | 13 +++++++++++++ .../cn/lihongjie/coal/meter/entity/MeterEntity.java | 11 +++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/main/java/cn/lihongjie/coal/coalWashingMonthReport/entity/CoalWashingMonthReportEntity.java b/src/main/java/cn/lihongjie/coal/coalWashingMonthReport/entity/CoalWashingMonthReportEntity.java index 0360dafd..9b65648a 100644 --- a/src/main/java/cn/lihongjie/coal/coalWashingMonthReport/entity/CoalWashingMonthReportEntity.java +++ b/src/main/java/cn/lihongjie/coal/coalWashingMonthReport/entity/CoalWashingMonthReportEntity.java @@ -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; diff --git a/src/main/java/cn/lihongjie/coal/meter/dto/MeterDto.java b/src/main/java/cn/lihongjie/coal/meter/dto/MeterDto.java index 4fae8085..88b14b39 100644 --- a/src/main/java/cn/lihongjie/coal/meter/dto/MeterDto.java +++ b/src/main/java/cn/lihongjie/coal/meter/dto/MeterDto.java @@ -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; } diff --git a/src/main/java/cn/lihongjie/coal/meter/entity/MeterEntity.java b/src/main/java/cn/lihongjie/coal/meter/entity/MeterEntity.java index 9e9a5384..97d731ee 100644 --- a/src/main/java/cn/lihongjie/coal/meter/entity/MeterEntity.java +++ b/src/main/java/cn/lihongjie/coal/meter/entity/MeterEntity.java @@ -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; } \ No newline at end of file