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