提交代码

This commit is contained in:
huangzj
2023-08-28 09:09:05 +08:00
parent c2aed9a9ae
commit ff178a3ee5
2 changed files with 61 additions and 19 deletions

View File

@@ -48,6 +48,12 @@
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.njcn</groupId>
<artifactId>cs-device-api</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

View File

@@ -2,6 +2,8 @@ package com.njcn.influx.service.impl;
import cn.hutool.core.lang.Dict;
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.constant.InfluxDBTableConstant;
import com.njcn.influx.pojo.dto.StatisticalDataDTO;
@@ -9,10 +11,12 @@ 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.enums.DicDataEnum;
import com.njcn.system.pojo.po.DictData;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
@@ -31,6 +35,8 @@ 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);
@@ -47,29 +53,43 @@ public class CommonServiceImpl implements CommonService {
@Override
public List<StatisticalDataDTO> getDeviceRtData(List<String> lineIds, String tableName, String columnName, String phasic, String dataType) {
List<StatisticalDataDTO> resultList = new ArrayList<>();
for (String lineId: lineIds) {
String clDidByLineId = getClDidByLineId(lineId);
InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(getTableNameByClassId(tableName),StatisticalDataDTO.class);
influxQueryWrapper.select(StatisticalDataDTO::getLineId)
.select(StatisticalDataDTO::getPhaseType)
.select(StatisticalDataDTO::getValueType)
.last(columnName,InfluxDBTableConstant.VALUE)
.or(InfluxDBTableConstant.LINE_ID,lineIds)
.eq(InfluxDBTableConstant.LINE_ID,lineId)
.eq(InfluxDBTableConstant.PHASIC_TYPE,phasic)
.eq(InfluxDBTableConstant.VALUE_TYPE,dataType).groupBy(InfluxDBTableConstant.LINE_ID);
return commonMapper.getDeviceRtData(influxQueryWrapper);
.eq(InfluxDBTableConstant.VALUE_TYPE,dataType).eq(InfluxDBTableConstant.CL_DID,clDidByLineId);
List<StatisticalDataDTO> deviceRtData = commonMapper.getDeviceRtData(influxQueryWrapper);
resultList.addAll(deviceRtData);
}
return resultList;
}
@Override
public List<StatisticalDataDTO> getDeviceRtDataByTime(List<String> lineIds, String tableName, String columnName, String phasic, String dataType, String startTime, String endTime) {
List<StatisticalDataDTO> resultList = new ArrayList<>();
for (String lineId: lineIds) {
String clDidByLineId = getClDidByLineId(lineId);
InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(getTableNameByClassId(tableName),StatisticalDataDTO.class);
influxQueryWrapper.select(StatisticalDataDTO::getLineId)
.select(StatisticalDataDTO::getPhaseType)
.select(StatisticalDataDTO::getValueType)
.select(columnName,InfluxDBTableConstant.VALUE)
.or(InfluxDBTableConstant.LINE_ID,lineIds)
.eq(InfluxDBTableConstant.LINE_ID,lineId)
.eq(InfluxDBTableConstant.PHASIC_TYPE,phasic)
.between(InfluxDBTableConstant.TIME, startTime, endTime)
.eq(InfluxDBTableConstant.VALUE_TYPE,dataType).groupBy(InfluxDBTableConstant.LINE_ID);
return commonMapper.getDeviceRtDataByTime(influxQueryWrapper);
.eq(InfluxDBTableConstant.VALUE_TYPE,dataType).eq(InfluxDBTableConstant.CL_DID,clDidByLineId);
List<StatisticalDataDTO> deviceRtData = commonMapper.getDeviceRtDataByTime(influxQueryWrapper);
resultList.addAll(deviceRtData);
}
return resultList;
}
@Override
@@ -96,4 +116,20 @@ public class CommonServiceImpl implements CommonService {
}
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.LOAD_SIDE.getCode())){
clDid = "1";
} else if (Objects.equals(areaCode, DicDataEnum.GRID_SIDE.getCode())){
clDid = "2";
}
return clDid;
}
}