diff --git a/pqs-influx/src/main/java/com/njcn/influx/service/impl/CommonServiceImpl.java b/pqs-influx/src/main/java/com/njcn/influx/service/impl/CommonServiceImpl.java index 13f5963b3..7815fdcd1 100644 --- a/pqs-influx/src/main/java/com/njcn/influx/service/impl/CommonServiceImpl.java +++ b/pqs-influx/src/main/java/com/njcn/influx/service/impl/CommonServiceImpl.java @@ -1,11 +1,15 @@ 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.pojo.constant.InfluxDBTableConstant; import com.njcn.influx.pojo.dto.StatisticalDataDTO; import com.njcn.influx.query.InfluxQueryWrapper; import com.njcn.influx.service.CommonService; import com.njcn.influx.utils.ReflectUitl; +import com.njcn.system.api.DicDataFeignClient; +import com.njcn.system.pojo.po.DictData; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -25,10 +29,11 @@ import java.util.Objects; public class CommonServiceImpl implements CommonService { private final CommonMapper commonMapper; - + private final + DicDataFeignClient dicDataFeignClient; @Override 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) .select(StatisticalDataDTO::getPhaseType) .select(StatisticalDataDTO::getValueType) @@ -41,11 +46,11 @@ public class CommonServiceImpl implements CommonService { @Override public List getDeviceRtData(List 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) .select(StatisticalDataDTO::getPhaseType) .select(StatisticalDataDTO::getValueType) - .last(columnName) + .last(columnName,InfluxDBTableConstant.VALUE) .or(InfluxDBTableConstant.LINE_ID,lineIds) .eq(InfluxDBTableConstant.PHASIC_TYPE,phasic) .eq(InfluxDBTableConstant.VALUE_TYPE,dataType).groupBy(InfluxDBTableConstant.LINE_ID); @@ -54,7 +59,7 @@ public class CommonServiceImpl implements CommonService { @Override public List getDeviceRtDataByTime(List 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) .select(StatisticalDataDTO::getPhaseType) .select(StatisticalDataDTO::getValueType) @@ -62,13 +67,13 @@ public class CommonServiceImpl implements CommonService { .or(InfluxDBTableConstant.LINE_ID,lineIds) .eq(InfluxDBTableConstant.PHASIC_TYPE,phasic) .between(InfluxDBTableConstant.TIME, startTime, endTime) - .eq(InfluxDBTableConstant.VALUE_TYPE,dataType); + .eq(InfluxDBTableConstant.VALUE_TYPE,dataType).groupBy(InfluxDBTableConstant.LINE_ID); return commonMapper.getDeviceRtDataByTime(influxQueryWrapper); } @Override 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) .min(columnName,InfluxDBTableConstant.MIN_VALUE) .eq(InfluxDBTableConstant.LINE_ID,lineId) @@ -80,4 +85,13 @@ public class CommonServiceImpl implements CommonService { public StatisticalDataDTO selectBySql(StringBuilder 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(); + } }