查询最新一条数据方法优化。添加时间条件,在当前时间之前的最新一条数据

This commit is contained in:
xy
2026-04-09 11:28:36 +08:00
parent 20b0c44874
commit bce83bd8e8

View File

@@ -1,6 +1,5 @@
package com.njcn.influx.service.impl; package com.njcn.influx.service.impl;
import cn.hutool.core.util.ObjectUtil;
import com.njcn.influx.imapper.CommonMapper; import com.njcn.influx.imapper.CommonMapper;
import com.njcn.influx.pojo.bo.CommonQueryParam; import com.njcn.influx.pojo.bo.CommonQueryParam;
import com.njcn.influx.pojo.constant.InfluxDBTableConstant; import com.njcn.influx.pojo.constant.InfluxDBTableConstant;
@@ -10,7 +9,9 @@ import com.njcn.influx.service.CommonService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.*; import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
/** /**
* Description: * Description:
@@ -32,6 +33,7 @@ public class CommonServiceImpl implements CommonService {
.select(StatisticalDataDTO::getPhaseType) .select(StatisticalDataDTO::getPhaseType)
.select(StatisticalDataDTO::getValueType) .select(StatisticalDataDTO::getValueType)
.last(columnName) .last(columnName)
.le(InfluxDBTableConstant.TIME, LocalDateTime.now())
.eq(InfluxDBTableConstant.LINE_ID,lineId) .eq(InfluxDBTableConstant.LINE_ID,lineId)
.eq(InfluxDBTableConstant.PHASIC_TYPE,phasic) .eq(InfluxDBTableConstant.PHASIC_TYPE,phasic)
.eq(InfluxDBTableConstant.VALUE_TYPE,dataType) .eq(InfluxDBTableConstant.VALUE_TYPE,dataType)