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 getDeviceRtData(List commonQueryParams) { List 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 deviceRtData = commonMapper.getDeviceRtData(influxQueryWrapper); resultList.addAll(deviceRtData); } return resultList; } @Override public List getDeviceRtDataByTime(List commonQueryParams) { List 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 deviceRtData = commonMapper.getDeviceRtDataByTime(influxQueryWrapper); resultList.addAll(deviceRtData); } return resultList; } @Override public List getNewDeviceRtDataByTime(List commonQueryParams) { List 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()) .between(InfluxDBTableConstant.TIME, commonQueryParam.getStartTime(), commonQueryParam.getEndTime()); //此方法和getDeviceRtDataByTime方法逻辑一致,只是在以下条件判断中允许部分查询参数为空,也即可以不带入查询 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 deviceRtData = commonMapper.getDeviceRtDataByTime(influxQueryWrapper); 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 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.PROCESS,process) .groupBy(InfluxDBTableConstant.CL_DID); return commonMapper.getTopTemperature(influxQueryWrapper); } }