代码调整
This commit is contained in:
@@ -51,7 +51,7 @@ public class CsLedgerController extends BaseController {
|
|||||||
|
|
||||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||||
@PostMapping("/lineTree")
|
@PostMapping("/lineTree")
|
||||||
@ApiOperation("监测点树")
|
@ApiOperation("治理监测点树")
|
||||||
public HttpResult<List<CsLedgerVO>> lineTree(){
|
public HttpResult<List<CsLedgerVO>> lineTree(){
|
||||||
String methodDescribe = getMethodDescribe("lineTree");
|
String methodDescribe = getMethodDescribe("lineTree");
|
||||||
List<CsLedgerVO> list = csLedgerService.getLineTree();
|
List<CsLedgerVO> list = csLedgerService.getLineTree();
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ import lombok.Data;
|
|||||||
@Data
|
@Data
|
||||||
public class RtDataVO extends CsCommon {
|
public class RtDataVO extends CsCommon {
|
||||||
|
|
||||||
|
private String targetTag;
|
||||||
|
|
||||||
private String targetName;
|
private String targetName;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -106,14 +107,15 @@ public class LineTargetServiceImpl implements ILineTargetService {
|
|||||||
//influx的原始方法获取数据
|
//influx的原始方法获取数据
|
||||||
if (CollectionUtil.isNotEmpty(list)){
|
if (CollectionUtil.isNotEmpty(list)){
|
||||||
list.forEach(item->{
|
list.forEach(item->{
|
||||||
String targetName = item.getTargetId().stream().reduce((first, second) -> second).orElse("no last element");
|
String targetTag = item.getTargetId().stream().reduce((first, second) -> second).orElse("no last element");
|
||||||
if (CollectionUtil.isNotEmpty(dataArrayFeignClient.getDataArrayById(item.getTargetPid(),targetName).getData())){
|
if (CollectionUtil.isNotEmpty(dataArrayFeignClient.getDataArrayById(item.getTargetPid(),targetTag).getData())){
|
||||||
String dataId = dataArrayFeignClient.getDataArrayById(item.getTargetPid(),targetName).getData().get(0).getDataId();
|
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 classId = epdFeignClient.selectById(dataId).getData().getClassId();
|
||||||
String lineId = item.getLineId().stream().reduce((first, second) -> second).orElse("no last element");
|
String lineId = item.getLineId().stream().reduce((first, second) -> second).orElse("no last element");
|
||||||
String dataType = item.getDataType();
|
String dataType = item.getDataType();
|
||||||
String phasic = item.getPhasic();
|
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();
|
HashMap<String, Class<?>> entityClassesByAnnotation = CsReflectUitl.getEntityClassesByAnnotation();
|
||||||
Class<?> aClass = entityClassesByAnnotation.get(tableName);
|
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')";
|
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);
|
QueryResult sqlResult = influxDbUtils.query(sql);
|
||||||
InfluxDBResultMapper resultMapper = new InfluxDBResultMapper();
|
InfluxDBResultMapper resultMapper = new InfluxDBResultMapper();
|
||||||
List<?> list = resultMapper.toPOJO(sqlResult, aClass);
|
List<?> list = resultMapper.toPOJO(sqlResult, aClass);
|
||||||
@@ -176,14 +179,17 @@ public class LineTargetServiceImpl implements ILineTargetService {
|
|||||||
RtDataVO vo = new RtDataVO();
|
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')";
|
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);
|
QueryResult sqlResult = influxDbUtils.query(sql);
|
||||||
if (CollectionUtil.isNotEmpty(sqlResult.getResults())){
|
if (CollectionUtil.isNotEmpty(sqlResult.getResults().get(0).getSeries())){
|
||||||
vo.setRtData(Double.parseDouble(sqlResult.getResults().get(0).getSeries().get(0).getValues().get(0).get(4).toString()));
|
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.setLineId(lineId);
|
||||||
vo.setPhaseType(phasic);
|
vo.setPhaseType(phasic);
|
||||||
vo.setValueType(dataType);
|
vo.setValueType(dataType);
|
||||||
vo.setValueType(dataType);
|
vo.setValueType(dataType);
|
||||||
vo.setTargetName(target);
|
vo.setTargetName(target);
|
||||||
|
vo.setTargetTag(columnName);
|
||||||
return vo;
|
return vo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,15 +26,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class InfluxDbTest {
|
public class InfluxDbTest {
|
||||||
|
|
||||||
private final MqttPublisher publisher;
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void insert() {
|
|
||||||
InfluxDbUtils influxDbUtils = new InfluxDbUtils("admin", "123456", "http://192.168.1.16:8086", "pqsbase_zl", "");
|
InfluxDbUtils influxDbUtils = new InfluxDbUtils("admin", "123456", "http://192.168.1.16:8086", "pqsbase_zl", "");
|
||||||
List<String> records = new ArrayList<>();
|
List<String> records = new ArrayList<>();
|
||||||
List<String> phasic = Arrays.asList("A","B","C");
|
List<String> phasic = Arrays.asList("A","B","C");
|
||||||
@@ -44,13 +36,13 @@ public class InfluxDbTest {
|
|||||||
for (String item2 : dataType) {
|
for (String item2 : dataType) {
|
||||||
Map<String, String> tags = new HashMap<>();
|
Map<String, String> tags = new HashMap<>();
|
||||||
Map<String, Object> fields = 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("phasic_type",item1);
|
||||||
tags.put("value_type",item2);
|
tags.put("value_type",item2);
|
||||||
fields.put("W",new Random().nextDouble());
|
fields.put("W",new Random().nextDouble());
|
||||||
fields.put("PhV",new Random().nextDouble());
|
fields.put("PhV",new Random().nextDouble());
|
||||||
Point point = influxDbUtils.pointBuilder("pqd_data", time, TimeUnit.MILLISECONDS, tags, fields);
|
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);
|
batchPoints.point(point);
|
||||||
records.add(batchPoints.lineProtocol());
|
records.add(batchPoints.lineProtocol());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user