Files
pqs-influx/src/main/java/com/njcn/influx/service/impl/CommonServiceImpl.java
2024-11-05 08:52:26 +08:00

166 lines
8.8 KiB
Java

package com.njcn.influx.service.impl;
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 lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
* Description:
* Date: 2023/6/2 16:04【需求编号】
*
* @author clam
* @version V1.0.0
*/
@Service
@RequiredArgsConstructor
public class CommonServiceImpl implements CommonService {
private final CommonMapper commonMapper;
@Override
public StatisticalDataDTO getLineRtData(String lineId, String tableName, String columnName, String phasic, String dataType, String clDid) {
InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(tableName,StatisticalDataDTO.class);
influxQueryWrapper.select(StatisticalDataDTO::getLineId)
.select(StatisticalDataDTO::getPhaseType)
.select(StatisticalDataDTO::getValueType)
.last(columnName)
.eq(InfluxDBTableConstant.LINE_ID,lineId)
.eq(InfluxDBTableConstant.PHASIC_TYPE,phasic)
.eq(InfluxDBTableConstant.VALUE_TYPE,dataType)
.eq(InfluxDBTableConstant.CL_DID,clDid);
return commonMapper.getLineRtData(influxQueryWrapper);
}
@Override
public List<StatisticalDataDTO> getDeviceRtData(List<CommonQueryParam> commonQueryParams) {
List<StatisticalDataDTO> resultList = new ArrayList<>();
for (CommonQueryParam commonQueryParam: commonQueryParams) {
InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(commonQueryParam.getTableName(),StatisticalDataDTO.class);
influxQueryWrapper.select(StatisticalDataDTO::getLineId)
.select(StatisticalDataDTO::getPhaseType)
.select(StatisticalDataDTO::getValueType)
.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);
}
return resultList;
}
@Override
public List<StatisticalDataDTO> getDeviceRtDataByTime(List<CommonQueryParam> commonQueryParams) {
List<StatisticalDataDTO> resultList = new ArrayList<>();
for (CommonQueryParam commonQueryParam: commonQueryParams) {
InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(commonQueryParam.getTableName(), StatisticalDataDTO.class);
influxQueryWrapper.select(StatisticalDataDTO::getLineId)
.select(StatisticalDataDTO::getPhaseType)
.select(StatisticalDataDTO::getValueType)
.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);
}
return resultList;
}
@Override
public List<StatisticalDataDTO> getNewDeviceRtDataByTime(List<CommonQueryParam> commonQueryParams) {
List<StatisticalDataDTO> resultList = new ArrayList<>();
for (CommonQueryParam commonQueryParam: commonQueryParams) {
InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(commonQueryParam.getTableName(), StatisticalDataDTO.class);
influxQueryWrapper.select(StatisticalDataDTO::getLineId)
.select(StatisticalDataDTO::getPhaseType)
.select(StatisticalDataDTO::getValueType)
.select(commonQueryParam.getColumnName(), InfluxDBTableConstant.VALUE)
//查询条件开始和结束时间是必须的
.between(InfluxDBTableConstant.TIME, commonQueryParam.getStartTime(), commonQueryParam.getEndTime());
//此方法和getDeviceRtDataByTime方法逻辑一致,只是在以下条件判断中允许部分查询参数为空,也即可以不带入查询
if(commonQueryParam.getLineId() != null) {
influxQueryWrapper.eq(InfluxDBTableConstant.LINE_ID, commonQueryParam.getLineId());
}
if(commonQueryParam.getPhasic() != null) {
influxQueryWrapper.eq(InfluxDBTableConstant.PHASIC_TYPE, commonQueryParam.getPhasic());
}
if(commonQueryParam.getProcess() != null) {
influxQueryWrapper.eq(InfluxDBTableConstant.PROCESS, commonQueryParam.getProcess());
}
if(commonQueryParam.getDataType() != null) {
influxQueryWrapper.eq(InfluxDBTableConstant.VALUE_TYPE, commonQueryParam.getDataType());
}
if(commonQueryParam.getClDid() != null) {
influxQueryWrapper.eq(InfluxDBTableConstant.CL_DID, commonQueryParam.getClDid());
}
List<StatisticalDataDTO> deviceRtData = commonMapper.getDeviceRtDataByTime(influxQueryWrapper);
for(StatisticalDataDTO statisticalDataDTO : deviceRtData){
statisticalDataDTO.setFrequency(commonQueryParam.getFrequency());
}
resultList.addAll(deviceRtData);
}
return resultList;
}
@Override
public StatisticalDataDTO getLineHistoryData(String lineId, String tableName, String columnName, String startTime, String endTime, String clDid) {
InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(tableName,StatisticalDataDTO.class);
influxQueryWrapper.max(columnName,InfluxDBTableConstant.MAX_VALUE)
.min(columnName,InfluxDBTableConstant.MIN_VALUE)
.mean(columnName,InfluxDBTableConstant.AVG_VALUE)
.eq(InfluxDBTableConstant.LINE_ID,lineId)
.eq(InfluxDBTableConstant.CL_DID,clDid)
.between(InfluxDBTableConstant.TIME, startTime, endTime);
return commonMapper.getLineHistoryData(influxQueryWrapper);
}
@Override
public StatisticalDataDTO selectBySql(StringBuilder sql) {
return commonMapper.selectBySql(sql);
}
@Override
public List<StatisticalDataDTO> getTopTemperature(String lineId, String tableName, String columnName,String process) {
InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(tableName,StatisticalDataDTO.class);
influxQueryWrapper.select(StatisticalDataDTO::getLineId)
.select(StatisticalDataDTO::getClDid)
.last(columnName,InfluxDBTableConstant.VALUE)
.eq(InfluxDBTableConstant.LINE_ID,lineId)
.eq(InfluxDBTableConstant.PHASIC_TYPE, "M")
.eq(InfluxDBTableConstant.PROCESS,process)
.groupBy(InfluxDBTableConstant.CL_DID);
return commonMapper.getTopTemperature(influxQueryWrapper);
}
@Override
public StatisticalDataDTO getCounts(String lineId, String tableName, String columnName,String resultName, String phasic, String dataType, String clDid,String process,String startTime, String endTime) {
InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(tableName,StatisticalDataDTO.class);
influxQueryWrapper.select(StatisticalDataDTO::getLineId)
.count(columnName,resultName)
.eq(InfluxDBTableConstant.LINE_ID,lineId)
.eq(InfluxDBTableConstant.PHASIC_TYPE,phasic)
.eq(InfluxDBTableConstant.VALUE_TYPE,dataType)
.eq(InfluxDBTableConstant.CL_DID,clDid)
.eq(InfluxDBTableConstant.PROCESS,process)
.between(InfluxDBTableConstant.TIME, startTime, endTime);;
return commonMapper.getLineRtData(influxQueryWrapper);
}
}