代码调整
This commit is contained in:
@@ -31,6 +31,7 @@ import org.springframework.stereotype.Service;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.math.BigDecimal;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -106,14 +107,15 @@ public class LineTargetServiceImpl implements ILineTargetService {
|
||||
//influx的原始方法获取数据
|
||||
if (CollectionUtil.isNotEmpty(list)){
|
||||
list.forEach(item->{
|
||||
String targetName = item.getTargetId().stream().reduce((first, second) -> second).orElse("no last element");
|
||||
if (CollectionUtil.isNotEmpty(dataArrayFeignClient.getDataArrayById(item.getTargetPid(),targetName).getData())){
|
||||
String dataId = dataArrayFeignClient.getDataArrayById(item.getTargetPid(),targetName).getData().get(0).getDataId();
|
||||
String targetTag = item.getTargetId().stream().reduce((first, second) -> second).orElse("no last element");
|
||||
if (CollectionUtil.isNotEmpty(dataArrayFeignClient.getDataArrayById(item.getTargetPid(),targetTag).getData())){
|
||||
String targetName = dataArrayFeignClient.getDataArrayById(item.getTargetPid(),targetTag).getData().get(0).getAnotherName();
|
||||
String dataId = dataArrayFeignClient.getDataArrayById(item.getTargetPid(),targetTag).getData().get(0).getDataId();
|
||||
String classId = epdFeignClient.selectById(dataId).getData().getClassId();
|
||||
String lineId = item.getLineId().stream().reduce((first, second) -> second).orElse("no last element");
|
||||
String dataType = item.getDataType();
|
||||
String phasic = item.getPhasic();
|
||||
result.add(getLineRtData2(lineId,classId,targetName,phasic,dataType,targetName));
|
||||
result.add(getLineRtData2(lineId,classId,targetTag,phasic,dataType,targetName));
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -154,6 +156,7 @@ public class LineTargetServiceImpl implements ILineTargetService {
|
||||
HashMap<String, Class<?>> entityClassesByAnnotation = CsReflectUitl.getEntityClassesByAnnotation();
|
||||
Class<?> aClass = entityClassesByAnnotation.get(tableName);
|
||||
String sql = "select line_id,phasic_type,value_type,last(" + columnName + ") AS rtData from "+ tableName +" where line_id = '" + lineId + "' and phasic_type = '" + phasic + "' and value_type = '" + dataType + "' tz('Asia/Shanghai')";
|
||||
System.out.println("sql==:" + sql);
|
||||
QueryResult sqlResult = influxDbUtils.query(sql);
|
||||
InfluxDBResultMapper resultMapper = new InfluxDBResultMapper();
|
||||
List<?> list = resultMapper.toPOJO(sqlResult, aClass);
|
||||
@@ -176,14 +179,17 @@ public class LineTargetServiceImpl implements ILineTargetService {
|
||||
RtDataVO vo = new RtDataVO();
|
||||
String sql = "select line_id,phasic_type,value_type,last(" + columnName + ") AS rtData from "+ tableName +" where line_id = '" + lineId + "' and phasic_type = '" + phasic + "' and value_type = '" + dataType + "' tz('Asia/Shanghai')";
|
||||
QueryResult sqlResult = influxDbUtils.query(sql);
|
||||
if (CollectionUtil.isNotEmpty(sqlResult.getResults())){
|
||||
vo.setRtData(Double.parseDouble(sqlResult.getResults().get(0).getSeries().get(0).getValues().get(0).get(4).toString()));
|
||||
if (CollectionUtil.isNotEmpty(sqlResult.getResults().get(0).getSeries())){
|
||||
vo.setRtData(BigDecimal.valueOf(Double.parseDouble(sqlResult.getResults().get(0).getSeries().get(0).getValues().get(0).get(4).toString())).setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue());
|
||||
} else {
|
||||
vo.setRtData(3.1415926);
|
||||
}
|
||||
vo.setLineId(lineId);
|
||||
vo.setPhaseType(phasic);
|
||||
vo.setValueType(dataType);
|
||||
vo.setValueType(dataType);
|
||||
vo.setTargetName(target);
|
||||
vo.setTargetTag(columnName);
|
||||
return vo;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,15 +26,7 @@ import java.util.concurrent.TimeUnit;
|
||||
@AllArgsConstructor
|
||||
public class InfluxDbTest {
|
||||
|
||||
private final MqttPublisher publisher;
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void insert() {
|
||||
InfluxDbUtils influxDbUtils = new InfluxDbUtils("admin", "123456", "http://192.168.1.16:8086", "pqsbase_zl", "");
|
||||
List<String> records = new ArrayList<>();
|
||||
List<String> phasic = Arrays.asList("A","B","C");
|
||||
@@ -44,13 +36,13 @@ public class InfluxDbTest {
|
||||
for (String item2 : dataType) {
|
||||
Map<String, String> tags = new HashMap<>();
|
||||
Map<String, Object> fields = new HashMap<>();
|
||||
tags.put("line_id","4");
|
||||
tags.put("line_id","7f6753c721dbf1ce37117073eddf2215");
|
||||
tags.put("phasic_type",item1);
|
||||
tags.put("value_type",item2);
|
||||
fields.put("W",new Random().nextDouble());
|
||||
fields.put("PhV",new Random().nextDouble());
|
||||
Point point = influxDbUtils.pointBuilder("pqd_data", time, TimeUnit.MILLISECONDS, tags, fields);
|
||||
BatchPoints batchPoints = BatchPoints.database(influxDbUtils.getDbName ()).tag(InfluxDBPublicParam.LINE_ID, "4").tag(InfluxDBPublicParam.PHASIC_TYPE,item1).tag(InfluxDBPublicParam.VALUE_TYPE,item2).retentionPolicy("").consistency(InfluxDB.ConsistencyLevel.ALL).build();
|
||||
BatchPoints batchPoints = BatchPoints.database(influxDbUtils.getDbName ()).tag(InfluxDBPublicParam.LINE_ID, "7f6753c721dbf1ce37117073eddf2215").tag(InfluxDBPublicParam.PHASIC_TYPE,item1).tag(InfluxDBPublicParam.VALUE_TYPE,item2).retentionPolicy("").consistency(InfluxDB.ConsistencyLevel.ALL).build();
|
||||
batchPoints.point(point);
|
||||
records.add(batchPoints.lineProtocol());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user