修改查询逻辑

This commit is contained in:
huangzj
2023-08-18 09:07:26 +08:00
parent a85d09c486
commit 2aad522104

View File

@@ -1,11 +1,15 @@
package com.njcn.influx.service.impl; package com.njcn.influx.service.impl;
import cn.hutool.core.lang.Dict;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.influx.imapper.CommonMapper; import com.njcn.influx.imapper.CommonMapper;
import com.njcn.influx.pojo.constant.InfluxDBTableConstant; import com.njcn.influx.pojo.constant.InfluxDBTableConstant;
import com.njcn.influx.pojo.dto.StatisticalDataDTO; import com.njcn.influx.pojo.dto.StatisticalDataDTO;
import com.njcn.influx.query.InfluxQueryWrapper; import com.njcn.influx.query.InfluxQueryWrapper;
import com.njcn.influx.service.CommonService; import com.njcn.influx.service.CommonService;
import com.njcn.influx.utils.ReflectUitl; import com.njcn.influx.utils.ReflectUitl;
import com.njcn.system.api.DicDataFeignClient;
import com.njcn.system.pojo.po.DictData;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -25,10 +29,11 @@ import java.util.Objects;
public class CommonServiceImpl implements CommonService { public class CommonServiceImpl implements CommonService {
private final CommonMapper commonMapper; private final CommonMapper commonMapper;
private final
DicDataFeignClient dicDataFeignClient;
@Override @Override
public StatisticalDataDTO getLineRtData(String lineId, String tableName, String columnName, String phasic, String dataType) { public StatisticalDataDTO getLineRtData(String lineId, String tableName, String columnName, String phasic, String dataType) {
InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(tableName,StatisticalDataDTO.class); InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(getTableNameByClassId(tableName),StatisticalDataDTO.class);
influxQueryWrapper.select(StatisticalDataDTO::getLineId) influxQueryWrapper.select(StatisticalDataDTO::getLineId)
.select(StatisticalDataDTO::getPhaseType) .select(StatisticalDataDTO::getPhaseType)
.select(StatisticalDataDTO::getValueType) .select(StatisticalDataDTO::getValueType)
@@ -41,11 +46,11 @@ public class CommonServiceImpl implements CommonService {
@Override @Override
public List<StatisticalDataDTO> getDeviceRtData(List<String> lineIds, String tableName, String columnName, String phasic, String dataType) { public List<StatisticalDataDTO> getDeviceRtData(List<String> lineIds, String tableName, String columnName, String phasic, String dataType) {
InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(tableName,StatisticalDataDTO.class); InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(getTableNameByClassId(tableName),StatisticalDataDTO.class);
influxQueryWrapper.select(StatisticalDataDTO::getLineId) influxQueryWrapper.select(StatisticalDataDTO::getLineId)
.select(StatisticalDataDTO::getPhaseType) .select(StatisticalDataDTO::getPhaseType)
.select(StatisticalDataDTO::getValueType) .select(StatisticalDataDTO::getValueType)
.last(columnName) .last(columnName,InfluxDBTableConstant.VALUE)
.or(InfluxDBTableConstant.LINE_ID,lineIds) .or(InfluxDBTableConstant.LINE_ID,lineIds)
.eq(InfluxDBTableConstant.PHASIC_TYPE,phasic) .eq(InfluxDBTableConstant.PHASIC_TYPE,phasic)
.eq(InfluxDBTableConstant.VALUE_TYPE,dataType).groupBy(InfluxDBTableConstant.LINE_ID); .eq(InfluxDBTableConstant.VALUE_TYPE,dataType).groupBy(InfluxDBTableConstant.LINE_ID);
@@ -54,7 +59,7 @@ public class CommonServiceImpl implements CommonService {
@Override @Override
public List<StatisticalDataDTO> getDeviceRtDataByTime(List<String> lineIds, String tableName, String columnName, String phasic, String dataType, String startTime, String endTime) { public List<StatisticalDataDTO> getDeviceRtDataByTime(List<String> lineIds, String tableName, String columnName, String phasic, String dataType, String startTime, String endTime) {
InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(tableName,StatisticalDataDTO.class); InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(getTableNameByClassId(tableName),StatisticalDataDTO.class);
influxQueryWrapper.select(StatisticalDataDTO::getLineId) influxQueryWrapper.select(StatisticalDataDTO::getLineId)
.select(StatisticalDataDTO::getPhaseType) .select(StatisticalDataDTO::getPhaseType)
.select(StatisticalDataDTO::getValueType) .select(StatisticalDataDTO::getValueType)
@@ -62,13 +67,13 @@ public class CommonServiceImpl implements CommonService {
.or(InfluxDBTableConstant.LINE_ID,lineIds) .or(InfluxDBTableConstant.LINE_ID,lineIds)
.eq(InfluxDBTableConstant.PHASIC_TYPE,phasic) .eq(InfluxDBTableConstant.PHASIC_TYPE,phasic)
.between(InfluxDBTableConstant.TIME, startTime, endTime) .between(InfluxDBTableConstant.TIME, startTime, endTime)
.eq(InfluxDBTableConstant.VALUE_TYPE,dataType); .eq(InfluxDBTableConstant.VALUE_TYPE,dataType).groupBy(InfluxDBTableConstant.LINE_ID);
return commonMapper.getDeviceRtDataByTime(influxQueryWrapper); return commonMapper.getDeviceRtDataByTime(influxQueryWrapper);
} }
@Override @Override
public StatisticalDataDTO getLineHistoryData(String lineId, String tableName, String columnName, String startTime, String endTime) { public StatisticalDataDTO getLineHistoryData(String lineId, String tableName, String columnName, String startTime, String endTime) {
InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(tableName,StatisticalDataDTO.class); InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(getTableNameByClassId(tableName),StatisticalDataDTO.class);
influxQueryWrapper.max(columnName,InfluxDBTableConstant.MAX_VALUE) influxQueryWrapper.max(columnName,InfluxDBTableConstant.MAX_VALUE)
.min(columnName,InfluxDBTableConstant.MIN_VALUE) .min(columnName,InfluxDBTableConstant.MIN_VALUE)
.eq(InfluxDBTableConstant.LINE_ID,lineId) .eq(InfluxDBTableConstant.LINE_ID,lineId)
@@ -80,4 +85,13 @@ public class CommonServiceImpl implements CommonService {
public StatisticalDataDTO selectBySql(StringBuilder sql) { public StatisticalDataDTO selectBySql(StringBuilder sql) {
return commonMapper.selectBySql(sql); return commonMapper.selectBySql(sql);
} }
/*表名换成了id本方法做转换*/
private String getTableNameByClassId(String classId){
DictData data = dicDataFeignClient.getDicDataById(classId).getData();
if(Objects.isNull(data)){
throw new BusinessException("数据缺失");
}
return data.getCode();
}
} }