提交一次接线图实时调试
This commit is contained in:
@@ -13,10 +13,7 @@ import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.njcn.csharmonic.handler;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.github.tocrhz.mqtt.annotation.MqttSubscribe;
|
||||
@@ -16,8 +17,11 @@ import com.njcn.csdevice.api.EquipmentFeignClient;
|
||||
import com.njcn.csdevice.pojo.vo.CsEquipmentDeliveryVO;
|
||||
import com.njcn.csharmonic.param.CommonStatisticalQueryParam;
|
||||
import com.njcn.csharmonic.param.FrequencyStatisticalQueryParam;
|
||||
import com.njcn.csharmonic.pojo.dto.RealTimeDataDTO;
|
||||
import com.njcn.csharmonic.pojo.vo.CsRtDataVO;
|
||||
import com.njcn.csharmonic.pojo.vo.CsWarnDescVO;
|
||||
import com.njcn.csharmonic.pojo.vo.ThdDataVO;
|
||||
import com.njcn.csharmonic.service.CsEventPOService;
|
||||
import com.njcn.csharmonic.service.ILineTargetService;
|
||||
import com.njcn.csharmonic.service.StableDataService;
|
||||
import com.njcn.csharmonic.service.TemperatureService;
|
||||
@@ -34,12 +38,10 @@ import org.apache.commons.lang.StringUtils;
|
||||
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@@ -64,7 +66,7 @@ public class MqttMessageHandler {
|
||||
private final TemperatureService temperatureService;
|
||||
|
||||
private final DevCapacityFeignClient devCapacityFeignClient;
|
||||
private final DecimalFormat df = new DecimalFormat("#0.000");
|
||||
private final DecimalFormat df = new DecimalFormat("#0.000");
|
||||
private final ChannelObjectUtil channelObjectUtil;
|
||||
private final EquipmentFeignClient equipmentFeignClient;
|
||||
private final CsTopicFeignClient csTopicFeignClient;
|
||||
@@ -72,26 +74,61 @@ public class MqttMessageHandler {
|
||||
private static Integer mid = 1;
|
||||
private final FileFeignClient fileFeignClient;
|
||||
|
||||
CsEventPOService csEventPOService;
|
||||
|
||||
/**
|
||||
* 实时数据应答
|
||||
*/
|
||||
@MqttSubscribe(value = "/zl/askRtData/{pageId}",qos = 1)
|
||||
@MqttSubscribe(value = "/zl/askRtData/{pageId}", qos = 1)
|
||||
public void responseRtData(String topic, @NamedValue("pageId") String pageId, MqttMessage message, @Payload String payload) {
|
||||
List<CsRtDataVO> list = lineTargetService.getLineData(pageId);
|
||||
Gson gson = new Gson();
|
||||
publisher.send("/zl/rtData/"+pageId,gson.toJson(list),1,false);
|
||||
publisher.send("/zl/rtData/" + pageId, gson.toJson(list), 1, false);
|
||||
}
|
||||
|
||||
@MqttSubscribe(value = "/zl/askTemperData/{devId}",qos = 1)
|
||||
@MqttSubscribe(value = "/zl/askTemperData/{devId}", qos = 1)
|
||||
public void responseTemperData(String topic, @NamedValue("devId") String devId, MqttMessage message, @Payload String payload) {
|
||||
List<StatisticalDataDTO> statisticalDataDTOS = temperatureService.queryTemperature(devId);
|
||||
statisticalDataDTOS.stream().forEach(temp->{
|
||||
statisticalDataDTOS.stream().forEach(temp -> {
|
||||
temp.setClDid(getCldidName(temp.getClDid()));
|
||||
});
|
||||
Gson gson = new Gson();
|
||||
publisher.send("/zl/TemperData/"+devId,gson.toJson(statisticalDataDTOS),1,false);
|
||||
publisher.send("/zl/TemperData/" + devId, gson.toJson(statisticalDataDTOS), 1, false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 物联平台的组态实时数据调试
|
||||
*/
|
||||
@MqttSubscribe(value = "/zl/askCSConfigRtData/{pageId}", qos = 1)
|
||||
public void responseCSConfigRtData(String topic, @NamedValue("pageId") String pageId, MqttMessage message, @Payload String payload) {
|
||||
List<String> lineIdList = Arrays.stream(payload.substring(1, payload.length() - 1).split(","))
|
||||
.map(String::trim)
|
||||
.collect(Collectors.toList());
|
||||
List<CsRtDataVO> lineData = lineTargetService.getLineDataNew(pageId);
|
||||
List<CsRtDataVO> collect = lineData.stream().filter(temp -> (!CollectionUtils.isEmpty(lineIdList)) && lineIdList.contains(temp.getLineId())).collect(Collectors.toList());
|
||||
RealTimeDataDTO recallReplyDTO = new RealTimeDataDTO();
|
||||
recallReplyDTO.setCode(200);
|
||||
recallReplyDTO.setMessage(JSONObject.toJSONString(collect));
|
||||
Gson gson = new Gson();
|
||||
publisher.send("/zl/csConfigRtData/" + pageId, gson.toJson(recallReplyDTO), 1, false);
|
||||
}
|
||||
|
||||
@MqttSubscribe(value = "/zl/askCSConfigWarnData/{pageId}", qos = 1)
|
||||
public void responseCSConfigWarnData(String topic, @NamedValue("pageId") String pageId, MqttMessage message, @Payload String payload) {
|
||||
List<String> lineIdList = Arrays.stream(payload.substring(1, payload.length() - 1).split(","))
|
||||
.map(String::trim)
|
||||
.collect(Collectors.toList());
|
||||
// 目前暂且查最近的60条记录
|
||||
List<CsWarnDescVO> csWarnDescVOList = csEventPOService.getEventDesc(lineIdList);
|
||||
RealTimeDataDTO recallReplyDTO = new RealTimeDataDTO();
|
||||
recallReplyDTO.setCode(200);
|
||||
recallReplyDTO.setMessage(JSONObject.toJSONString(csWarnDescVOList));
|
||||
Gson gson = new Gson();
|
||||
publisher.send("/zl/TemperData/" + pageId, gson.toJson(recallReplyDTO), 1, false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 实时数据应答
|
||||
*/
|
||||
@@ -195,20 +232,21 @@ public class MqttMessageHandler {
|
||||
// }
|
||||
// publisher.send("/zl/devData/"+devId,topoDataJson,1,false);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 实时数据应答
|
||||
*/
|
||||
@MqttSubscribe(value = "/zl/askDevData/{devId}/{typeId}",qos = 1)
|
||||
public void responseTopoDataByType(String topic, @NamedValue("devId") String devId,@NamedValue("typeId") String typeId, MqttMessage message, @Payload String payload) {
|
||||
String topoDataJson =redisUtil.getStringByKey (devId+"#"+typeId);
|
||||
if(StringUtils.isEmpty(topoDataJson)){
|
||||
@MqttSubscribe(value = "/zl/askDevData/{devId}/{typeId}", qos = 1)
|
||||
public void responseTopoDataByType(String topic, @NamedValue("devId") String devId, @NamedValue("typeId") String typeId, MqttMessage message, @Payload String payload) {
|
||||
String topoDataJson = redisUtil.getStringByKey(devId + "#" + typeId);
|
||||
if (StringUtils.isEmpty(topoDataJson)) {
|
||||
List<ThdDataVO> result = new ArrayList<>();
|
||||
List<ThdDataVO> tempList = new ArrayList<>();
|
||||
|
||||
//1.查询拓扑图配置的指标:拓扑图扑图配置:7677f94c749dedaff30f911949cbd724
|
||||
List<EleEpdPqd> data = csStatisticalSetFeignClient.queryStatisticalSelect(typeId).getData();
|
||||
data.forEach(temp->{
|
||||
if(Objects.nonNull(temp.getHarmStart())&&Objects.nonNull(temp.getHarmEnd())){
|
||||
data.forEach(temp -> {
|
||||
if (Objects.nonNull(temp.getHarmStart()) && Objects.nonNull(temp.getHarmEnd())) {
|
||||
FrequencyStatisticalQueryParam frequencyStatisticalQueryParam = new FrequencyStatisticalQueryParam();
|
||||
frequencyStatisticalQueryParam.setDevId(devId);
|
||||
frequencyStatisticalQueryParam.setStatisticalId(temp.getId());
|
||||
@@ -218,12 +256,12 @@ public class MqttMessageHandler {
|
||||
List<ThdDataVO> thdDataVOList = stableDataService.QuerySqlData(frequencyStatisticalQueryParam);
|
||||
tempList.addAll(thdDataVOList);
|
||||
|
||||
}else {
|
||||
} else {
|
||||
CommonStatisticalQueryParam commonStatisticalQueryParam = new CommonStatisticalQueryParam();
|
||||
commonStatisticalQueryParam.setDevId(devId);
|
||||
commonStatisticalQueryParam.setStatisticalId(temp.getId());
|
||||
commonStatisticalQueryParam.setValueType("avg");
|
||||
List<ThdDataVO> listFuture= stableDataService.queryFisrtCommonStatistical(commonStatisticalQueryParam);
|
||||
List<ThdDataVO> listFuture = stableDataService.queryFisrtCommonStatistical(commonStatisticalQueryParam);
|
||||
tempList.addAll(listFuture);
|
||||
}
|
||||
|
||||
@@ -231,23 +269,23 @@ public class MqttMessageHandler {
|
||||
|
||||
//过滤M相
|
||||
List<ThdDataVO> m = tempList.stream().filter(temp -> Objects.equals(temp.getPhase(), "M")).collect(Collectors.toList());
|
||||
m.stream().forEach(temp->{
|
||||
Stream.of("A","B","C").forEach(phase->{
|
||||
m.stream().forEach(temp -> {
|
||||
Stream.of("A", "B", "C").forEach(phase -> {
|
||||
ThdDataVO thdDataVO = new ThdDataVO();
|
||||
BeanUtils.copyProperties(temp,thdDataVO);
|
||||
BeanUtils.copyProperties(temp, thdDataVO);
|
||||
thdDataVO.setPhase(phase);
|
||||
result.add(thdDataVO);
|
||||
});
|
||||
});
|
||||
//如果是基础数据则添加拓扑图的数据
|
||||
if(Objects.equals("fc8c86dbc3f2d9810f5cd8f53c295415",typeId)){
|
||||
if (Objects.equals("fc8c86dbc3f2d9810f5cd8f53c295415", typeId)) {
|
||||
List<ThdDataVO> apfThdI = tempList.stream().filter(temp -> Objects.equals(temp.getStatisticalName(), "Apf_ThdA_Load(%)")).collect(Collectors.toList());
|
||||
Map<String, List<ThdDataVO>> collect3 = apfThdI.stream().collect(Collectors.groupingBy(ThdDataVO::getLineId));
|
||||
collect3.forEach((k,v)->{
|
||||
if(!CollectionUtil.isEmpty(v)){
|
||||
collect3.forEach((k, v) -> {
|
||||
if (!CollectionUtil.isEmpty(v)) {
|
||||
double asDouble = v.stream().mapToDouble(ThdDataVO::getStatisticalData).average().getAsDouble();
|
||||
ThdDataVO thdDataVO = new ThdDataVO();
|
||||
BeanUtils.copyProperties(v.get(0),thdDataVO);
|
||||
BeanUtils.copyProperties(v.get(0), thdDataVO);
|
||||
thdDataVO.setStatisticalData(Double.valueOf(df.format(asDouble)));
|
||||
thdDataVO.setPhase("avg");
|
||||
result.add(thdDataVO);
|
||||
@@ -255,11 +293,11 @@ public class MqttMessageHandler {
|
||||
});
|
||||
List<ThdDataVO> apfRmsI = tempList.stream().filter(temp -> Objects.equals(temp.getStatisticalName(), "Apf_RmsI_TolOut(A)")).collect(Collectors.toList());
|
||||
Map<String, List<ThdDataVO>> collect2 = apfRmsI.stream().collect(Collectors.groupingBy(ThdDataVO::getLineId));
|
||||
collect2.forEach((k,v)->{
|
||||
if(!CollectionUtil.isEmpty(v)){
|
||||
collect2.forEach((k, v) -> {
|
||||
if (!CollectionUtil.isEmpty(v)) {
|
||||
double asDouble = v.stream().mapToDouble(ThdDataVO::getStatisticalData).average().getAsDouble();
|
||||
ThdDataVO thdDataVO = new ThdDataVO();
|
||||
BeanUtils.copyProperties(v.get(0),thdDataVO);
|
||||
BeanUtils.copyProperties(v.get(0), thdDataVO);
|
||||
thdDataVO.setStatisticalData(Double.valueOf(df.format(asDouble)));
|
||||
thdDataVO.setPhase("avg");
|
||||
result.add(thdDataVO);
|
||||
@@ -267,11 +305,11 @@ public class MqttMessageHandler {
|
||||
});
|
||||
List<ThdDataVO> apfThdISys = tempList.stream().filter(temp -> Objects.equals(temp.getStatisticalName(), "Apf_ThdA_Sys(%)")).collect(Collectors.toList());
|
||||
Map<String, List<ThdDataVO>> collect4 = apfThdISys.stream().collect(Collectors.groupingBy(ThdDataVO::getLineId));
|
||||
collect4.forEach((k,v)->{
|
||||
if(!CollectionUtil.isEmpty(v)){
|
||||
collect4.forEach((k, v) -> {
|
||||
if (!CollectionUtil.isEmpty(v)) {
|
||||
double asDouble = v.stream().mapToDouble(ThdDataVO::getStatisticalData).average().getAsDouble();
|
||||
ThdDataVO thdDataVO = new ThdDataVO();
|
||||
BeanUtils.copyProperties(v.get(0),thdDataVO);
|
||||
BeanUtils.copyProperties(v.get(0), thdDataVO);
|
||||
thdDataVO.setStatisticalData(Double.valueOf(df.format(asDouble)));
|
||||
thdDataVO.setPhase("avg");
|
||||
result.add(thdDataVO);
|
||||
@@ -279,16 +317,16 @@ public class MqttMessageHandler {
|
||||
}
|
||||
});
|
||||
Double capacity = devCapacityFeignClient.getDevCapacity(devId).getData();
|
||||
apfRmsI.forEach(temp->{
|
||||
apfRmsI.forEach(temp -> {
|
||||
ThdDataVO thdDataVO = new ThdDataVO();
|
||||
BeanUtils.copyProperties(temp,thdDataVO);
|
||||
BeanUtils.copyProperties(temp, thdDataVO);
|
||||
thdDataVO.setUnit("%");
|
||||
thdDataVO.setStatisticalName("load_Rate");
|
||||
thdDataVO.setAnotherName("负载率");
|
||||
if (capacity<=0){
|
||||
if (capacity <= 0) {
|
||||
thdDataVO.setStatisticalData(3.1415926);
|
||||
}else {
|
||||
double v = temp.getStatisticalData()*100 / capacity;
|
||||
} else {
|
||||
double v = temp.getStatisticalData() * 100 / capacity;
|
||||
thdDataVO.setStatisticalData(Double.valueOf(df.format(v)));
|
||||
}
|
||||
result.add(thdDataVO);
|
||||
@@ -299,14 +337,13 @@ public class MqttMessageHandler {
|
||||
result.addAll(notM);
|
||||
Gson gson = new Gson();
|
||||
topoDataJson = gson.toJson(result);
|
||||
redisUtil.saveByKeyWithExpire(devId+"#"+typeId, (Object) topoDataJson, 30L);
|
||||
redisUtil.saveByKeyWithExpire(devId + "#" + typeId, (Object) topoDataJson, 30L);
|
||||
}
|
||||
publisher.send("/zl/devData/"+devId+"/"+typeId,topoDataJson,1,false);
|
||||
publisher.send("/zl/devData/" + devId + "/" + typeId, topoDataJson, 1, false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getCldidName( String cldid) {
|
||||
public String getCldidName(String cldid) {
|
||||
|
||||
switch (cldid) {
|
||||
case "0":
|
||||
@@ -361,7 +398,7 @@ public class MqttMessageHandler {
|
||||
/**
|
||||
* 处理补召数据
|
||||
*/
|
||||
@MqttSubscribe(value = "/makeUpData/{nDid}/{lineId}",qos = 1)
|
||||
@MqttSubscribe(value = "/makeUpData/{nDid}/{lineId}", qos = 1)
|
||||
public void responseRtData(String topic, @NamedValue("nDid") String nDid, @NamedValue("lineId") String lineId, MqttMessage message, @Payload String payload) {
|
||||
//下载文件
|
||||
fileFeignClient.downloadMakeUpFile(nDid);
|
||||
|
||||
@@ -2,6 +2,10 @@ package com.njcn.csharmonic.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.njcn.csharmonic.pojo.po.CsEventPO;
|
||||
import com.njcn.csharmonic.pojo.vo.CsWarnDescVO;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -12,4 +16,5 @@ import com.njcn.csharmonic.pojo.po.CsEventPO;
|
||||
* @version V1.0.0
|
||||
*/
|
||||
public interface CsEventPOMapper extends BaseMapper<CsEventPO> {
|
||||
List<CsWarnDescVO> getEventDesc(@Param("lineIdList")List<String> lineIdList, @Param("count")int count);
|
||||
}
|
||||
@@ -15,4 +15,26 @@
|
||||
<!--@mbg.generated-->
|
||||
id, line_id, device_id, start_time, tag, wave_id
|
||||
</sql>
|
||||
|
||||
|
||||
<select id="getEventDesc" resultType="com.njcn.csharmonic.pojo.vo.CsWarnDescVO">
|
||||
SELECT
|
||||
t1.line_id id,
|
||||
t2.NAME,
|
||||
t1.start_time timeId,
|
||||
t1.amplitude,
|
||||
t1.persist_time
|
||||
FROM
|
||||
cs_event t1,
|
||||
cs_line t2
|
||||
WHERE
|
||||
t1.line_id = t2.line_id
|
||||
and t1.line_id in
|
||||
<foreach collection="lineIdList" item="lineId" separator="," open="(" close=")">
|
||||
#{lineId}
|
||||
</foreach>
|
||||
and t1.type = 0
|
||||
LIMIT 60
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -10,6 +10,7 @@ import com.njcn.csharmonic.param.DataParam;
|
||||
import com.njcn.csharmonic.pojo.param.EventStatisticParam;
|
||||
import com.njcn.csharmonic.pojo.po.CsEventPO;
|
||||
import com.njcn.csharmonic.pojo.vo.CsEventVO;
|
||||
import com.njcn.csharmonic.pojo.vo.CsWarnDescVO;
|
||||
import com.njcn.csharmonic.pojo.vo.EventDetailVO;
|
||||
import com.njcn.csharmonic.pojo.vo.EventStatisticsVo;
|
||||
import com.njcn.event.file.pojo.dto.WaveDataDTO;
|
||||
@@ -69,4 +70,5 @@ public interface CsEventPOService extends IService<CsEventPO>{
|
||||
|
||||
List<EventStatisticsVo> getEventStatistics(CsEventUserQueryParam param);
|
||||
|
||||
List<CsWarnDescVO> getEventDesc(List<String> lineIdList);
|
||||
}
|
||||
|
||||
@@ -23,4 +23,9 @@ public interface ILineTargetService {
|
||||
*/
|
||||
List<CsRtDataVO> getLineData(String id);
|
||||
|
||||
/**
|
||||
* 获取绑定指标的数据
|
||||
* @param id
|
||||
*/
|
||||
List<CsRtDataVO> getLineDataNew(String id);
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import com.njcn.csharmonic.param.DataParam;
|
||||
import com.njcn.csharmonic.pojo.param.EventStatisticParam;
|
||||
import com.njcn.csharmonic.pojo.po.CsEventPO;
|
||||
import com.njcn.csharmonic.pojo.vo.CsEventVO;
|
||||
import com.njcn.csharmonic.pojo.vo.CsWarnDescVO;
|
||||
import com.njcn.csharmonic.pojo.vo.EventDetailVO;
|
||||
import com.njcn.csharmonic.pojo.vo.EventStatisticsVo;
|
||||
import com.njcn.csharmonic.service.CsEventPOService;
|
||||
@@ -401,6 +402,23 @@ public class CsEventPOServiceImpl extends ServiceImpl<CsEventPOMapper, CsEventPO
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CsWarnDescVO> getEventDesc(List<String> lineIdList) {
|
||||
List<CsWarnDescVO> csWarnDescVOList = new ArrayList<>();
|
||||
if(CollUtil.isEmpty(lineIdList)){
|
||||
return csWarnDescVOList;
|
||||
}
|
||||
/**
|
||||
* todo.. 目前且先查最近的60条
|
||||
*/
|
||||
csWarnDescVOList = this.baseMapper.getEventDesc(lineIdList,60);
|
||||
// 处理下描述
|
||||
for (CsWarnDescVO csWarnDescVO : csWarnDescVOList) {
|
||||
csWarnDescVO.setEventDesc("电压暂态事件,持续时间"+csWarnDescVO.getPersistTime()+"秒,电压降至"+csWarnDescVO.getAmplitude()+"%。");
|
||||
}
|
||||
return csWarnDescVOList;
|
||||
}
|
||||
|
||||
public String getTag(Integer type) {
|
||||
String tag;
|
||||
switch (type) {
|
||||
|
||||
@@ -2,6 +2,9 @@ package com.njcn.csharmonic.service.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.csdevice.api.*;
|
||||
@@ -12,10 +15,12 @@ import com.njcn.csdevice.pojo.vo.DataArrayTreeVO;
|
||||
import com.njcn.csdevice.pojo.vo.LineTargetVO;
|
||||
import com.njcn.csharmonic.enums.CsHarmonicResponseEnum;
|
||||
import com.njcn.csharmonic.pojo.dto.ZuTaiDTO;
|
||||
import com.njcn.csharmonic.pojo.dto.ZuTaiNewDTO;
|
||||
import com.njcn.csharmonic.pojo.vo.CsRtDataVO;
|
||||
import com.njcn.csharmonic.service.CsPagePOService;
|
||||
import com.njcn.csharmonic.service.ILineTargetService;
|
||||
import com.njcn.csharmonic.util.InfluxDbParamUtil;
|
||||
import com.njcn.cssystem.enums.CsSystemResponseEnum;
|
||||
import com.njcn.influx.pojo.dto.StatisticalDataDTO;
|
||||
import com.njcn.influx.service.CommonService;
|
||||
import com.njcn.oss.utils.FileStorageUtil;
|
||||
@@ -34,10 +39,7 @@ import java.io.InputStreamReader;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -137,6 +139,50 @@ public class LineTargetServiceImpl implements ILineTargetService {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<CsRtDataVO> getLineDataNew(String id) {
|
||||
List<CsRtDataVO> result = new ArrayList<>();
|
||||
String path = csPagePOService.queryById(id).getPath();
|
||||
InputStream inputStream = fileStorageUtil.getFileStream(path);
|
||||
ZuTaiNewDTO zuTaiDto = analysisJsonNew(inputStream);
|
||||
|
||||
zuTaiDto.getJson().forEach(item->{
|
||||
if (!CollectionUtils.isEmpty(item.getUidNames())){
|
||||
for (int i = 0; i < item.getUidNames().size(); i++) {
|
||||
String temp = item.getUidNames().get(i);
|
||||
String targetTag = null;
|
||||
String phasic = null;
|
||||
String dataType = null;
|
||||
// String[] tmepUidName = temp.split(" / ");
|
||||
// if(tmepUidName.length==2){
|
||||
// targetTag = tmepUidName[0];
|
||||
// phasic = "T";
|
||||
// dataType = tmepUidName[1];
|
||||
// }else if (tmepUidName.length==3){
|
||||
// targetTag = tmepUidName[0];
|
||||
// phasic = tmepUidName[1];
|
||||
// dataType = tmepUidName[2];
|
||||
// }
|
||||
|
||||
if (CollectionUtils.isEmpty(item.getUid()) || org.springframework.util.StringUtils.isEmpty(item.getLineId())){
|
||||
throw new BusinessException(CsSystemResponseEnum.BIND_TARGET_ERROR);
|
||||
}
|
||||
List<String> tempUid = item.getUid().get(i);
|
||||
String s = tempUid.get(tempUid.size() - 1);
|
||||
String[] tempTable = s.replace("$", "").split("#");
|
||||
result.add(getLineRtDataNew(item.getId(),item.getLineId(),tempTable[3],tempTable[0],tempTable[1],tempTable[2].toUpperCase(),temp,item.getUnit().get(i)));
|
||||
// result.add(getLineRtData(item.getId(),item.getLineId(),tempUid.get(3),tempUid.get(0),tempUid.get(1),tempUid.get(2).toUpperCase(),temp,"%"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 解析json文件
|
||||
*/
|
||||
@@ -149,6 +195,28 @@ public class LineTargetServiceImpl implements ILineTargetService {
|
||||
return gson.fromJson(text, new TypeToken<ZuTaiDTO>(){}.getType());
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析json文件
|
||||
*/
|
||||
public ZuTaiNewDTO analysisJsonNew(InputStream inputStream) {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
String text = new BufferedReader(
|
||||
new InputStreamReader(inputStream, StandardCharsets.UTF_8))
|
||||
.lines()
|
||||
.collect(Collectors.joining("\n"));
|
||||
|
||||
|
||||
ZuTaiNewDTO config = null;
|
||||
try {
|
||||
config = mapper.readValue(text, ZuTaiNewDTO.class);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过orm框架获取数据
|
||||
* @param id 图元Id
|
||||
@@ -179,4 +247,74 @@ public class LineTargetServiceImpl implements ILineTargetService {
|
||||
csRtDataVO.setId(id);
|
||||
return csRtDataVO;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 通过orm框架获取数据
|
||||
* @param id 图元Id
|
||||
* @param lineId 监测点Id
|
||||
* @param tableName 表名称
|
||||
* @param columnName 字段名称
|
||||
* @param phasic 相别
|
||||
* @param dataType 数据类型
|
||||
* @param target 数据名称
|
||||
* @return
|
||||
*/
|
||||
public CsRtDataVO getLineRtDataNew(String id,String lineId, String tableName, String columnName, String phasic, String dataType, String target,String uint) {
|
||||
CsRtDataVO csRtDataVO = new CsRtDataVO();
|
||||
StatisticalDataDTO statisticalDataDTO = commonService.getLineRtData(lineId,tableName,columnName,phasic,dataType,null);
|
||||
if(Objects.isNull(statisticalDataDTO)){
|
||||
statisticalDataDTO = new StatisticalDataDTO();
|
||||
statisticalDataDTO.setLineId(lineId);
|
||||
statisticalDataDTO.setPhaseType(phasic);
|
||||
statisticalDataDTO.setValueType(dataType);
|
||||
statisticalDataDTO.setValue(3.1415926);
|
||||
} else {
|
||||
statisticalDataDTO.setValue(BigDecimal.valueOf(statisticalDataDTO.getValue()).setScale(4, RoundingMode.HALF_UP).doubleValue());
|
||||
}
|
||||
String targetTag = null;
|
||||
String targetPhasic = null;
|
||||
String targetDataType = null;
|
||||
|
||||
String[] tmepUidName = target.split(" / ");
|
||||
if(tmepUidName.length==2){
|
||||
targetTag = tmepUidName[0];
|
||||
targetDataType = getDataType(tmepUidName[1]) ;
|
||||
}else if (tmepUidName.length==3){
|
||||
targetTag = tmepUidName[0];
|
||||
targetPhasic = tmepUidName[1];
|
||||
targetDataType =getDataType(tmepUidName[2]) ;
|
||||
} else if (tmepUidName.length==4) {
|
||||
targetTag = tmepUidName[1];
|
||||
targetPhasic = tmepUidName[2];
|
||||
targetDataType =getDataType(tmepUidName[3]) ;
|
||||
}
|
||||
statisticalDataDTO.setStatisticalName((Objects.isNull(targetPhasic)?"":targetPhasic+"相_")+targetTag+"_"+targetDataType);
|
||||
statisticalDataDTO.setTarget(columnName + "$" + phasic + "$" + dataType);
|
||||
BeanUtils.copyProperties(statisticalDataDTO,csRtDataVO);
|
||||
csRtDataVO.setId(id);
|
||||
csRtDataVO.setUnit(uint);
|
||||
return csRtDataVO;
|
||||
}
|
||||
|
||||
public String getDataType(String statItem){
|
||||
String valueTypeName = "";
|
||||
switch (statItem) {
|
||||
case "max":
|
||||
valueTypeName = "最大值";
|
||||
break;
|
||||
case "min":
|
||||
valueTypeName = "最小值";
|
||||
break;
|
||||
case "avg":
|
||||
valueTypeName = "平均值";
|
||||
break;
|
||||
case "cp95":
|
||||
valueTypeName = "cp95值";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return valueTypeName;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user