ifnluxdb模块代码重构
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package com.njcn.influx.pojo.bo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Date: 2024/1/24 9:05【需求编号】
|
||||
*
|
||||
* @author clam
|
||||
* @version V1.0.0
|
||||
*/
|
||||
@Data
|
||||
public class CommonQueryParam {
|
||||
private String lineId;
|
||||
private String tableName;
|
||||
private String columnName;
|
||||
private String phasic;
|
||||
private String startTime;
|
||||
private String endTime;
|
||||
private String dataType;
|
||||
private String process;
|
||||
private String clDid;
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.njcn.influx.service;
|
||||
|
||||
import com.njcn.influx.pojo.bo.CommonQueryParam;
|
||||
import com.njcn.influx.pojo.dto.StatisticalDataDTO;
|
||||
|
||||
import java.util.List;
|
||||
@@ -28,28 +29,17 @@ public interface CommonService {
|
||||
/**
|
||||
* 根据条件获取监测点数据
|
||||
*
|
||||
* @param lineIds 监测点Id
|
||||
* @param tableName 表名
|
||||
* @param columnName 字段名
|
||||
* @param phasic 相别
|
||||
* @param dataType 数据类型
|
||||
*/
|
||||
List<StatisticalDataDTO> getDeviceRtData(List<String> lineIds, String tableName, String columnName, String phasic, String dataType,String process);
|
||||
List<StatisticalDataDTO> getDeviceRtData(List<CommonQueryParam> commonQueryParams);
|
||||
|
||||
/**
|
||||
* @param lineIds 监测点Id
|
||||
* @param tableName 表名
|
||||
* @param columnName 字段名
|
||||
* @param phasic 相别
|
||||
* @param dataType 数据类型
|
||||
* @param startTime start time
|
||||
* @param endTime end time
|
||||
|
||||
* @Description: getDeviceRtDataByTime
|
||||
* @return: java.util.List<com.njcn.influx.pojo.dto.StatisticalDataDTO>
|
||||
* @Author: clam
|
||||
* @Date: 2023/6/13
|
||||
*/
|
||||
List<StatisticalDataDTO> getDeviceRtDataByTime(List<String> lineIds, String tableName, String columnName, String phasic, String dataType, String startTime, String endTime,String process);
|
||||
List<StatisticalDataDTO> getDeviceRtDataByTime(List<CommonQueryParam> commonQueryParams);
|
||||
|
||||
/**
|
||||
* 根据条件获取监测点时间范围内的最大最小值
|
||||
|
||||
@@ -1,22 +1,16 @@
|
||||
package com.njcn.influx.service.impl;
|
||||
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.csdevice.api.CsLineFeignClient;
|
||||
import com.njcn.csdevice.enums.AlgorithmResponseEnum;
|
||||
import com.njcn.influx.imapper.CommonMapper;
|
||||
import com.njcn.influx.pojo.bo.CommonQueryParam;
|
||||
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.system.api.DicDataFeignClient;
|
||||
import com.njcn.system.enums.DicDataEnum;
|
||||
import com.njcn.system.pojo.po.DictData;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
@@ -31,12 +25,9 @@ public class CommonServiceImpl implements CommonService {
|
||||
|
||||
private final CommonMapper commonMapper;
|
||||
|
||||
private final DicDataFeignClient dicDataFeignClient;
|
||||
|
||||
private final CsLineFeignClient csLineFeignClient;
|
||||
@Override
|
||||
public StatisticalDataDTO getLineRtData(String lineId, String tableName, String columnName, String phasic, String dataType, String clDid) {
|
||||
InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(getTableNameByClassId(tableName),StatisticalDataDTO.class);
|
||||
InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(tableName,StatisticalDataDTO.class);
|
||||
influxQueryWrapper.select(StatisticalDataDTO::getLineId)
|
||||
.select(StatisticalDataDTO::getPhaseType)
|
||||
.select(StatisticalDataDTO::getValueType)
|
||||
@@ -49,19 +40,18 @@ public class CommonServiceImpl implements CommonService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<StatisticalDataDTO> getDeviceRtData(List<String> lineIds, String tableName, String columnName, String phasic, String dataType,String process) {
|
||||
public List<StatisticalDataDTO> getDeviceRtData(List<CommonQueryParam> commonQueryParams) {
|
||||
List<StatisticalDataDTO> resultList = new ArrayList<>();
|
||||
for (String lineId: lineIds) {
|
||||
String clDidByLineId = getClDidByLineId(lineId);
|
||||
InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(getTableNameByClassId(tableName),StatisticalDataDTO.class);
|
||||
for (CommonQueryParam commonQueryParam: commonQueryParams) {
|
||||
InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(commonQueryParam.getTableName(),StatisticalDataDTO.class);
|
||||
influxQueryWrapper.select(StatisticalDataDTO::getLineId)
|
||||
.select(StatisticalDataDTO::getPhaseType)
|
||||
.select(StatisticalDataDTO::getValueType)
|
||||
.last(columnName,InfluxDBTableConstant.VALUE)
|
||||
.eq(InfluxDBTableConstant.LINE_ID,lineId)
|
||||
.eq(InfluxDBTableConstant.PROCESS,process)
|
||||
.eq(InfluxDBTableConstant.PHASIC_TYPE,phasic)
|
||||
.eq(InfluxDBTableConstant.VALUE_TYPE,dataType).eq(InfluxDBTableConstant.CL_DID,clDidByLineId);
|
||||
.last(commonQueryParam.getColumnName(),InfluxDBTableConstant.VALUE)
|
||||
.eq(InfluxDBTableConstant.LINE_ID,commonQueryParam.getLineId())
|
||||
.eq(InfluxDBTableConstant.PROCESS,commonQueryParam.getProcess())
|
||||
.eq(InfluxDBTableConstant.PHASIC_TYPE,commonQueryParam.getPhasic())
|
||||
.eq(InfluxDBTableConstant.VALUE_TYPE,commonQueryParam.getDataType()).eq(InfluxDBTableConstant.CL_DID,commonQueryParam.getClDid());
|
||||
List<StatisticalDataDTO> deviceRtData = commonMapper.getDeviceRtData(influxQueryWrapper);
|
||||
resultList.addAll(deviceRtData);
|
||||
}
|
||||
@@ -70,20 +60,19 @@ public class CommonServiceImpl implements CommonService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<StatisticalDataDTO> getDeviceRtDataByTime(List<String> lineIds, String tableName, String columnName, String phasic, String dataType, String startTime, String endTime,String process) {
|
||||
public List<StatisticalDataDTO> getDeviceRtDataByTime(List<CommonQueryParam> commonQueryParams) {
|
||||
List<StatisticalDataDTO> resultList = new ArrayList<>();
|
||||
for (String lineId: lineIds) {
|
||||
String clDidByLineId = getClDidByLineId(lineId);
|
||||
InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(getTableNameByClassId(tableName),StatisticalDataDTO.class);
|
||||
for (CommonQueryParam commonQueryParam: commonQueryParams) {
|
||||
InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(commonQueryParam.getTableName(), StatisticalDataDTO.class);
|
||||
influxQueryWrapper.select(StatisticalDataDTO::getLineId)
|
||||
.select(StatisticalDataDTO::getPhaseType)
|
||||
.select(StatisticalDataDTO::getValueType)
|
||||
.select(columnName,InfluxDBTableConstant.VALUE)
|
||||
.eq(InfluxDBTableConstant.LINE_ID,lineId)
|
||||
.eq(InfluxDBTableConstant.PHASIC_TYPE,phasic)
|
||||
.eq(InfluxDBTableConstant.PROCESS,process)
|
||||
.between(InfluxDBTableConstant.TIME, startTime, endTime)
|
||||
.eq(InfluxDBTableConstant.VALUE_TYPE,dataType).eq(InfluxDBTableConstant.CL_DID,clDidByLineId);
|
||||
.select(commonQueryParam.getColumnName(), InfluxDBTableConstant.VALUE)
|
||||
.eq(InfluxDBTableConstant.LINE_ID, commonQueryParam.getLineId())
|
||||
.eq(InfluxDBTableConstant.PHASIC_TYPE, commonQueryParam.getPhasic())
|
||||
.eq(InfluxDBTableConstant.PROCESS, commonQueryParam.getProcess())
|
||||
.between(InfluxDBTableConstant.TIME, commonQueryParam.getStartTime(), commonQueryParam.getEndTime())
|
||||
.eq(InfluxDBTableConstant.VALUE_TYPE, commonQueryParam.getDataType()).eq(InfluxDBTableConstant.CL_DID, commonQueryParam.getClDid());
|
||||
List<StatisticalDataDTO> deviceRtData = commonMapper.getDeviceRtDataByTime(influxQueryWrapper);
|
||||
resultList.addAll(deviceRtData);
|
||||
}
|
||||
@@ -93,7 +82,7 @@ public class CommonServiceImpl implements CommonService {
|
||||
|
||||
@Override
|
||||
public StatisticalDataDTO getLineHistoryData(String lineId, String tableName, String columnName, String startTime, String endTime, String clDid) {
|
||||
InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(getTableNameByClassId(tableName),StatisticalDataDTO.class);
|
||||
InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(tableName,StatisticalDataDTO.class);
|
||||
influxQueryWrapper.max(columnName,InfluxDBTableConstant.MAX_VALUE)
|
||||
.min(columnName,InfluxDBTableConstant.MIN_VALUE)
|
||||
.mean(columnName,InfluxDBTableConstant.AVG_VALUE)
|
||||
@@ -120,28 +109,6 @@ public class CommonServiceImpl implements CommonService {
|
||||
return commonMapper.getTopTemperature(influxQueryWrapper);
|
||||
}
|
||||
|
||||
/*表名换成了id本方法做转换*/
|
||||
private String getTableNameByClassId(String classId){
|
||||
DictData data = dicDataFeignClient.getDicDataById(classId).getData();
|
||||
if(Objects.isNull(data)){
|
||||
throw new BusinessException("数据缺失");
|
||||
}
|
||||
return data.getCode();
|
||||
}
|
||||
private String getClDidByLineId(String lineId){
|
||||
String position = csLineFeignClient.getPositionById(lineId).getData();
|
||||
if (Objects.isNull(position)){
|
||||
throw new BusinessException(AlgorithmResponseEnum.POSITION_ERROR);
|
||||
}
|
||||
String clDid = null;
|
||||
String areaCode = dicDataFeignClient.getDicDataById(position).getData().getCode();
|
||||
if (Objects.equals(areaCode, DicDataEnum.OUTPUT_SIDE.getCode())){
|
||||
clDid = "0";
|
||||
} else if (Objects.equals(areaCode, DicDataEnum.GRID_SIDE.getCode())){
|
||||
clDid = "1";
|
||||
} else if (Objects.equals(areaCode, DicDataEnum.LOAD_SIDE.getCode())){
|
||||
clDid = "2";
|
||||
}
|
||||
return clDid;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.njcn.influx.service.impl;
|
||||
|
||||
import com.njcn.common.utils.HarmonicTimesUtil;
|
||||
import com.njcn.influx.imapper.DataVMapper;
|
||||
import com.njcn.influx.pojo.po.DataV;
|
||||
import com.njcn.influx.query.InfluxQueryWrapper;
|
||||
@@ -8,6 +7,7 @@ import com.njcn.influx.service.IDataVService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -28,7 +28,7 @@ public class DataVServiceImpl implements IDataVService {
|
||||
//最小值
|
||||
List<DataV> result1 ;
|
||||
InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(DataV.class);
|
||||
influxQueryWrapper.minSamePrefixAndSuffix("v_","", HarmonicTimesUtil.harmonicTimesList(1,50,1));
|
||||
influxQueryWrapper.minSamePrefixAndSuffix("v_","", this.harmonicTimesList(1,50,1));
|
||||
influxQueryWrapper.eq(DataV::getLineId, lineIndex)
|
||||
.eq(DataV::getValueType, "MIN")
|
||||
.min(DataV::getFreq)
|
||||
@@ -60,4 +60,20 @@ public class DataVServiceImpl implements IDataVService {
|
||||
result1 = dataVMapper.getStatisticsByWraper(influxQueryWrapper);
|
||||
return result1;
|
||||
}
|
||||
|
||||
/***
|
||||
* 自定义需要查询的谐波次数
|
||||
* @author xuyang
|
||||
* @param start 起始次数@Min(value = 1) @Max(value = 100)
|
||||
* @param end 结束次数 @Min(value = 1) @Max(value = 100)
|
||||
* @param interval 间隔
|
||||
* @return List<Object>
|
||||
*/
|
||||
public List<Object> harmonicTimesList(Integer start, Integer end, Integer interval) {
|
||||
List<Object> timesList = new ArrayList<>();
|
||||
for (int i = start; i <= end;i = i+interval) {
|
||||
timesList.add(i);
|
||||
}
|
||||
return timesList;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user