完成责任量化功能
This commit is contained in:
@@ -12,54 +12,60 @@ import java.util.List;
|
||||
* @version V1.0.0
|
||||
*/
|
||||
public interface CommonService {
|
||||
List<StatisticalDataDTO> commonquery(String lineId, String tableName, String columnName);
|
||||
|
||||
/**
|
||||
* 根据条件获取监测点数据
|
||||
* @param lineId 监测点Id
|
||||
* @param tableName 表名
|
||||
* @param columnName 字段名
|
||||
* @param phasic 相别
|
||||
* @param dataType 数据类型
|
||||
* @return
|
||||
*/
|
||||
StatisticalDataDTO getLineRtData(String lineId, String tableName, String columnName, String phasic, String dataType);
|
||||
/**
|
||||
* 根据条件获取监测点数据
|
||||
*
|
||||
* @param lineId 监测点Id
|
||||
* @param tableName 表名
|
||||
* @param columnName 字段名
|
||||
* @param phasic 相别
|
||||
* @param dataType 数据类型
|
||||
* @return
|
||||
*/
|
||||
StatisticalDataDTO getLineRtData(String lineId, String tableName, String columnName, String phasic, String dataType);
|
||||
|
||||
/**
|
||||
* 根据条件获取监测点数据
|
||||
* @param lineIds 监测点Id
|
||||
* @param tableName 表名
|
||||
* @param columnName 字段名
|
||||
* @param phasic 相别
|
||||
* @param dataType 数据类型
|
||||
* @return
|
||||
*/
|
||||
List<StatisticalDataDTO> getDeviceRtData(List<String> lineIds, String tableName, String columnName, String phasic, String dataType);
|
||||
/**
|
||||
* @Description: getDeviceRtDataByTime
|
||||
* @param lineIds 监测点Id
|
||||
* @param tableName 表名
|
||||
* @param columnName 字段名
|
||||
* @param phasic 相别
|
||||
* @param dataType 数据类型
|
||||
*@param startTime start time
|
||||
* @param endTime end time
|
||||
* @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);
|
||||
/**
|
||||
* 根据条件获取监测点数据
|
||||
*
|
||||
* @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);
|
||||
|
||||
/**
|
||||
* 根据条件获取监测点时间范围内的最大最小值
|
||||
* @param lineId 监测点Id
|
||||
* @param tableName 表名
|
||||
* @param columnName 字段名
|
||||
* @param phasic 相别
|
||||
* @param dataType 数据类型
|
||||
* @return
|
||||
*/
|
||||
StatisticalDataDTO getLineHistoryData(String lineId, String tableName, String columnName, String startTime, String endTime);
|
||||
/**
|
||||
* @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);
|
||||
|
||||
/**
|
||||
* 根据条件获取监测点时间范围内的最大最小值
|
||||
*
|
||||
* @param lineId 监测点Id
|
||||
* @param tableName 表名
|
||||
* @param columnName 字段名
|
||||
*/
|
||||
StatisticalDataDTO getLineHistoryData(String lineId, String tableName, String columnName, String startTime, String endTime);
|
||||
|
||||
/***
|
||||
* 当表名、字段、统计方式均不确定时,代码拼接好sql
|
||||
* @author hongawen
|
||||
* @date 2023/7/14 15:23
|
||||
* @param sql influx-sql语句
|
||||
* @return StatisticalDataDTO
|
||||
*/
|
||||
StatisticalDataDTO selectBySql(StringBuilder sql);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.njcn.influx.service;
|
||||
|
||||
import com.njcn.influx.pojo.po.DataHarmRateV;
|
||||
import com.njcn.influx.query.InfluxQueryWrapper;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2023年07月17日 11:01
|
||||
*/
|
||||
public interface DataHarmRateVService {
|
||||
DataHarmRateV getMeanAllTimesData(InfluxQueryWrapper influxQueryWrapper);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.njcn.influx.service;
|
||||
|
||||
import com.njcn.influx.pojo.po.DataI;
|
||||
import com.njcn.influx.query.InfluxQueryWrapper;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2023年07月17日 11:04
|
||||
*/
|
||||
public interface IDataIService {
|
||||
|
||||
DataI getMeanAllTimesData(InfluxQueryWrapper influxQueryWrapper);
|
||||
}
|
||||
@@ -1,15 +1,8 @@
|
||||
package com.njcn.influx.service.impl;
|
||||
|
||||
import com.njcn.common.pojo.constant.PatternRegex;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.HttpResultUtil;
|
||||
import com.njcn.common.utils.PubUtils;
|
||||
import com.njcn.influx.ano.Select;
|
||||
import com.njcn.influx.imapper.CommonMapper;
|
||||
import com.njcn.influx.pojo.constant.InfluxDBTableConstant;
|
||||
import com.njcn.influx.pojo.dto.StatisticalDataDTO;
|
||||
import com.njcn.influx.pojo.po.HarmonicRatioData;
|
||||
import com.njcn.influx.query.InfluxQueryWrapper;
|
||||
import com.njcn.influx.service.CommonService;
|
||||
import com.njcn.influx.utils.ReflectUitl;
|
||||
@@ -29,23 +22,9 @@ import java.util.List;
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class CommonServiceImpl implements CommonService {
|
||||
|
||||
private final CommonMapper commonMapper;
|
||||
|
||||
@Override
|
||||
public List<StatisticalDataDTO> commonquery(String lineId ,String tableName, String columnName) {
|
||||
HashMap<String, Class<?>> entityClassesByAnnotation = ReflectUitl.getEntityClassesByAnnotation();
|
||||
Class<?> aClass = entityClassesByAnnotation.get(tableName);
|
||||
InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(aClass,StatisticalDataDTO.class);
|
||||
influxQueryWrapper.eq("LineId",lineId).
|
||||
last(columnName,"statisticalData").
|
||||
groupBy(StatisticalDataDTO::getLineId, StatisticalDataDTO::getValueType, StatisticalDataDTO::getPhaseType);
|
||||
|
||||
List<StatisticalDataDTO> statistical = commonMapper.getStatistical(influxQueryWrapper);
|
||||
|
||||
return statistical;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public StatisticalDataDTO getLineRtData(String lineId, String tableName, String columnName, String phasic, String dataType) {
|
||||
InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(tableName,StatisticalDataDTO.class);
|
||||
@@ -53,9 +32,9 @@ public class CommonServiceImpl implements CommonService {
|
||||
.select(StatisticalDataDTO::getPhaseType)
|
||||
.select(StatisticalDataDTO::getValueType)
|
||||
.last(columnName)
|
||||
.eq("line_id",lineId)
|
||||
.eq("phasic_type",phasic)
|
||||
.eq("value_type",dataType);
|
||||
.eq(InfluxDBTableConstant.LINE_ID,lineId)
|
||||
.eq(InfluxDBTableConstant.PHASIC_TYPE,phasic)
|
||||
.eq(InfluxDBTableConstant.VALUE_TYPE,dataType);
|
||||
return commonMapper.getLineRtData(influxQueryWrapper);
|
||||
}
|
||||
|
||||
@@ -66,9 +45,9 @@ public class CommonServiceImpl implements CommonService {
|
||||
.select(StatisticalDataDTO::getPhaseType)
|
||||
.select(StatisticalDataDTO::getValueType)
|
||||
.last(columnName)
|
||||
.or("line_id",lineIds)
|
||||
.eq("phasic_type",phasic)
|
||||
.eq("value_type",dataType).groupBy("line_id");
|
||||
.or(InfluxDBTableConstant.LINE_ID,lineIds)
|
||||
.eq(InfluxDBTableConstant.PHASIC_TYPE,phasic)
|
||||
.eq(InfluxDBTableConstant.VALUE_TYPE,dataType).groupBy(InfluxDBTableConstant.LINE_ID);
|
||||
return commonMapper.getDeviceRtData(influxQueryWrapper);
|
||||
}
|
||||
|
||||
@@ -78,21 +57,26 @@ public class CommonServiceImpl implements CommonService {
|
||||
influxQueryWrapper.select(StatisticalDataDTO::getLineId)
|
||||
.select(StatisticalDataDTO::getPhaseType)
|
||||
.select(StatisticalDataDTO::getValueType)
|
||||
.select(columnName,"value")
|
||||
.or("line_id",lineIds)
|
||||
.eq("phasic_type",phasic)
|
||||
.between("time", startTime, endTime)
|
||||
.eq("value_type",dataType);
|
||||
.select(columnName,InfluxDBTableConstant.VALUE)
|
||||
.or(InfluxDBTableConstant.LINE_ID,lineIds)
|
||||
.eq(InfluxDBTableConstant.PHASIC_TYPE,phasic)
|
||||
.between(InfluxDBTableConstant.TIME, startTime, endTime)
|
||||
.eq(InfluxDBTableConstant.VALUE_TYPE,dataType);
|
||||
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.max(columnName,"maxValue")
|
||||
.min(columnName,"minValue")
|
||||
.eq("line_id",lineId)
|
||||
.between("time", startTime, endTime);
|
||||
influxQueryWrapper.max(columnName,InfluxDBTableConstant.MAX_VALUE)
|
||||
.min(columnName,InfluxDBTableConstant.MIN_VALUE)
|
||||
.eq(InfluxDBTableConstant.LINE_ID,lineId)
|
||||
.between(InfluxDBTableConstant.TIME, startTime, endTime);
|
||||
return commonMapper.getLineHistoryData(influxQueryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StatisticalDataDTO selectBySql(StringBuilder sql) {
|
||||
return commonMapper.selectBySql(sql);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,9 +7,6 @@ import com.njcn.influx.pojo.dto.DataFlickerDTO;
|
||||
import com.njcn.influx.pojo.po.DataFlicker;
|
||||
import com.njcn.influx.query.InfluxQueryWrapper;
|
||||
import com.njcn.influx.service.DataFlickerService;
|
||||
import com.njcn.influx.utils.InfluxDbUtil;
|
||||
import org.influxdb.dto.QueryResult;
|
||||
import org.influxdb.impl.InfluxDBResultMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -30,49 +27,6 @@ public class DataFlickerServiceImpl implements DataFlickerService {
|
||||
|
||||
@Override
|
||||
public List<DataFlickerDTO> getDataFlicker(String lineIndex, String startTime, String endTime) {
|
||||
InfluxDbUtil influxDbUtils = new InfluxDbUtil("admin", "123456", "http://192.168.1.16:8086", "pqsbase_sjzx", "autogen");
|
||||
|
||||
List<DataFlickerDTO> result = new ArrayList<>();
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.append("line_id='").append(lineIndex).append("' and ");
|
||||
//最小值
|
||||
String sql1 = "select min(fluc) AS fluc,min(plt) AS plt,min(pst) AS pst from data_flicker where " + stringBuilder + " time >= '" + startTime + "' and time <= '" + endTime + "' group by line_id,phasic_type,quality_flag tz('Asia/Shanghai')";
|
||||
QueryResult sqlResult1 = influxDbUtils.query(sql1);
|
||||
InfluxDBResultMapper resultMapper1 = new InfluxDBResultMapper();
|
||||
List<DataFlickerDTO> list1 = resultMapper1.toPOJO(sqlResult1, DataFlickerDTO.class);
|
||||
list1.forEach(item -> {
|
||||
item.setValueType("MIN");
|
||||
});
|
||||
//最大值
|
||||
String sql2 = "select max(fluc) AS fluc,max(plt) AS plt,max(pst) AS pst from data_flicker where " + stringBuilder + " time >= '" + startTime + "' and time <= '" + endTime + "' group by line_id,phasic_type,quality_flag tz('Asia/Shanghai')";
|
||||
QueryResult sqlResult2 = influxDbUtils.query(sql2);
|
||||
InfluxDBResultMapper resultMapper2 = new InfluxDBResultMapper();
|
||||
List<DataFlickerDTO> list2 = resultMapper2.toPOJO(sqlResult2, DataFlickerDTO.class);
|
||||
list2.forEach(item -> {
|
||||
item.setValueType("MAX");
|
||||
});
|
||||
//平均值
|
||||
String sql3 = "select mean(fluc) AS fluc,mean(plt) AS plt,mean(pst) AS pst from data_flicker where " + stringBuilder + " time >= '" + startTime + "' and time <= '" + endTime + "' group by line_id,phasic_type,quality_flag tz('Asia/Shanghai')";
|
||||
QueryResult sqlResult3 = influxDbUtils.query(sql3);
|
||||
InfluxDBResultMapper resultMapper3 = new InfluxDBResultMapper();
|
||||
List<DataFlickerDTO> list3 = resultMapper3.toPOJO(sqlResult3, DataFlickerDTO.class);
|
||||
list3.forEach(item -> {
|
||||
item.setValueType("AVG");
|
||||
});
|
||||
//CP95值
|
||||
String sql4 = "select percentile(fluc,95) AS fluc,percentile(plt,95) AS plt,percentile(pst,95) AS pst from data_flicker where " + stringBuilder + " time >= '" + startTime + "' and time <= '" + endTime + "' group by line_id,phasic_type,quality_flag tz('Asia/Shanghai')";
|
||||
QueryResult sqlResult4 = influxDbUtils.query(sql4);
|
||||
InfluxDBResultMapper resultMapper4 = new InfluxDBResultMapper();
|
||||
List<DataFlickerDTO> list4 = resultMapper4.toPOJO(sqlResult4, DataFlickerDTO.class);
|
||||
list4.forEach(item -> {
|
||||
item.setValueType("CP95");
|
||||
});
|
||||
result.addAll(list1);
|
||||
result.addAll(list2);
|
||||
result.addAll(list3);
|
||||
result.addAll(list4);
|
||||
|
||||
/////改造前↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑改造后↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
|
||||
//最小值
|
||||
List<DataFlickerDTO> result1 ;
|
||||
InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(DataFlicker.class, DataFlickerDTO.class);
|
||||
@@ -125,16 +79,14 @@ public class DataFlickerServiceImpl implements DataFlickerService {
|
||||
result4.forEach(item -> {
|
||||
item.setValueType("CP95");
|
||||
});
|
||||
List<DataFlickerDTO> result5 = new ArrayList<>();
|
||||
result5.addAll(result1);
|
||||
result5.addAll(result2);
|
||||
result5.addAll(result3);
|
||||
result5.addAll(result4);
|
||||
|
||||
List<DataFlickerDTO> result = new ArrayList<>();
|
||||
result.addAll(result1);
|
||||
result.addAll(result2);
|
||||
result.addAll(result3);
|
||||
result.addAll(result4);
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
try {
|
||||
System.out.println(objectMapper.writeValueAsString(result));
|
||||
System.out.println(objectMapper.writeValueAsString(result5));
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.njcn.influx.service.impl;
|
||||
|
||||
import com.njcn.influx.imapper.DataHarmRateVMapper;
|
||||
import com.njcn.influx.pojo.po.DataHarmRateV;
|
||||
import com.njcn.influx.query.InfluxQueryWrapper;
|
||||
import com.njcn.influx.service.DataHarmRateVService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2023年07月17日 11:02
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DataHarmRateVServiceImpl implements DataHarmRateVService {
|
||||
|
||||
private final DataHarmRateVMapper dataHarmRateVMapper;
|
||||
|
||||
|
||||
@Override
|
||||
public DataHarmRateV getMeanAllTimesData(InfluxQueryWrapper influxQueryWrapper) {
|
||||
return dataHarmRateVMapper.getMeanAllTimesData(influxQueryWrapper);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.njcn.influx.service.impl;
|
||||
|
||||
import com.njcn.influx.imapper.IDataIMapper;
|
||||
import com.njcn.influx.pojo.po.DataI;
|
||||
import com.njcn.influx.query.InfluxQueryWrapper;
|
||||
import com.njcn.influx.service.IDataIService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2023年07月17日 11:05
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class IDataIServiceImpl implements IDataIService {
|
||||
|
||||
private final IDataIMapper dataIMapper;
|
||||
|
||||
@Override
|
||||
public DataI getMeanAllTimesData(InfluxQueryWrapper influxQueryWrapper) {
|
||||
return dataIMapper.getMeanAllTimesData(influxQueryWrapper);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user