组态图元入库、查询功能
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
package com.njcn.csharmonic.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.csharmonic.param.CsPageParm;
|
||||
import com.njcn.csharmonic.pojo.po.CsElement;
|
||||
import com.njcn.csharmonic.pojo.vo.ElementsVO;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 组态图元库 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author xuyang
|
||||
* @since 2023-06-14
|
||||
*/
|
||||
public interface ICsElementService extends IService<CsElement> {
|
||||
|
||||
/**
|
||||
* 新增组态图元
|
||||
* @param json 参数
|
||||
*/
|
||||
void addElement(String json);
|
||||
|
||||
/**
|
||||
* 组态图元数据查询
|
||||
*/
|
||||
ElementsVO findElement();
|
||||
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
package com.njcn.csharmonic.service;
|
||||
|
||||
import com.njcn.csdevice.pojo.vo.DataArrayTreeVO;
|
||||
import com.njcn.csdevice.pojo.vo.LineTargetVO;
|
||||
import com.njcn.csharmonic.pojo.vo.TargetDetailVO;
|
||||
import com.njcn.influx.pojo.dto.StatisticalDataDTO;
|
||||
|
||||
import java.util.List;
|
||||
@@ -19,14 +17,6 @@ public interface ILineTargetService {
|
||||
*/
|
||||
List<DataArrayTreeVO> getLineTarget(String lineId);
|
||||
|
||||
/**
|
||||
* 获取指标的数据类型和相别
|
||||
* @param pid
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
TargetDetailVO getTargetDetail(String pid, String name);
|
||||
|
||||
/**
|
||||
* 获取绑定指标的数据
|
||||
* @param id
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
package com.njcn.csharmonic.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.common.utils.FileUtil;
|
||||
import com.njcn.csharmonic.mapper.CsElementMapper;
|
||||
import com.njcn.csharmonic.pojo.po.CsElement;
|
||||
import com.njcn.csharmonic.pojo.vo.ElementsVO;
|
||||
import com.njcn.csharmonic.service.ICsElementService;
|
||||
import com.njcn.oss.constant.OssPath;
|
||||
import com.njcn.oss.utils.FileStorageUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 组态图元库 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author xuyang
|
||||
* @since 2023-06-14
|
||||
*/
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class CsElementServiceImpl extends ServiceImpl<CsElementMapper, CsElement> implements ICsElementService {
|
||||
|
||||
private final FileStorageUtil fileStorageUtil;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void addElement(String json) {
|
||||
CsElement csElement = new CsElement();
|
||||
if (Objects.isNull(json)){
|
||||
throw new BusinessException("组态图元json缺失");
|
||||
}
|
||||
LambdaQueryWrapper<CsElement> lambdaQueryWrapper = new LambdaQueryWrapper<CsElement>();
|
||||
csElement = this.baseMapper.selectOne(lambdaQueryWrapper);
|
||||
if (!Objects.isNull(csElement)){
|
||||
fileStorageUtil.deleteFile(csElement.getPath());
|
||||
} else {
|
||||
csElement = new CsElement();
|
||||
}
|
||||
InputStream inputStream = this.writeJsonStringToInputStream(json);
|
||||
String path = fileStorageUtil.uploadStream(inputStream, OssPath.ELEMENT, FileUtil.generateFileName("json"));
|
||||
csElement.setPath(path);
|
||||
this.saveOrUpdate(csElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ElementsVO findElement() {
|
||||
ElementsVO elementsVo = new ElementsVO();
|
||||
LambdaQueryWrapper<CsElement> lambdaQueryWrapper = new LambdaQueryWrapper<CsElement>();
|
||||
CsElement csElement = this.baseMapper.selectOne(lambdaQueryWrapper);
|
||||
if (!Objects.isNull(csElement)){
|
||||
InputStream inputStream = fileStorageUtil.getFileStream(csElement.getPath());
|
||||
String text = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8)).lines().collect(Collectors.joining("\n"));
|
||||
elementsVo.setId(csElement.getId());
|
||||
elementsVo.setJson(text);
|
||||
}
|
||||
return elementsVo;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将json转成流
|
||||
* @param jsonString
|
||||
* @return
|
||||
*/
|
||||
public InputStream writeJsonStringToInputStream(String jsonString) {
|
||||
return new ByteArrayInputStream(jsonString.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,16 +1,10 @@
|
||||
package com.njcn.csharmonic.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||
import com.njcn.csdevice.api.*;
|
||||
import com.njcn.csdevice.pojo.po.CsDataArray;
|
||||
import com.njcn.csdevice.pojo.po.CsDevModelPO;
|
||||
import com.njcn.csdevice.pojo.po.CsDevModelRelationPO;
|
||||
import com.njcn.csdevice.pojo.vo.DataArrayTreeVO;
|
||||
import com.njcn.csdevice.pojo.vo.LineTargetVO;
|
||||
import com.njcn.csharmonic.pojo.vo.ElementsVO;
|
||||
import com.njcn.csharmonic.pojo.vo.TargetDetailVO;
|
||||
import com.njcn.csharmonic.pojo.vo.ZuTaiVo;
|
||||
import com.njcn.csharmonic.service.CsPagePOService;
|
||||
import com.njcn.csharmonic.service.ILineTargetService;
|
||||
import com.njcn.influx.pojo.dto.StatisticalDataDTO;
|
||||
@@ -20,12 +14,9 @@ import com.njcn.system.api.EpdFeignClient;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
@@ -77,60 +68,15 @@ public class LineTargetServiceImpl implements ILineTargetService {
|
||||
return dataArrayList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TargetDetailVO getTargetDetail(String pid, String name) {
|
||||
TargetDetailVO vo = new TargetDetailVO();
|
||||
List<CsDataArray> dataArrayList = dataArrayFeignClient.getDataArrayById(pid,name).getData();
|
||||
List<String> dataType = dataArrayList.stream().map(CsDataArray::getStatMethod).distinct().collect(Collectors.toList());
|
||||
List<String> phasic = dataArrayList.stream().map(CsDataArray::getPhase).distinct().collect(Collectors.toList());
|
||||
vo.setDataTypeList(dataType);
|
||||
vo.setPhasicList(phasic);
|
||||
return vo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<StatisticalDataDTO> getLineData(String id) {
|
||||
List<StatisticalDataDTO> result = new ArrayList<>();
|
||||
String path = csPagePOService.queryById(id).getPath();
|
||||
InputStream inputStream = fileStorageUtil.getFileStream(path);
|
||||
List<ElementsVO> list = analysisJson(inputStream);
|
||||
if (CollectionUtil.isNotEmpty(list)){
|
||||
list.forEach(item->{
|
||||
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(getLineRtData(lineId,classId,targetTag,phasic,dataType,targetName));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取子节点
|
||||
*/
|
||||
public List<LineTargetVO> getChildren(LineTargetVO item, List<LineTargetVO> all) {
|
||||
return all.stream().filter(allItem -> allItem.getPid().equals(item.getId())).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析json文件
|
||||
*/
|
||||
public List<ElementsVO> analysisJson(InputStream inputStream) {
|
||||
Gson gson = new Gson();
|
||||
String text = new BufferedReader(
|
||||
new InputStreamReader(inputStream, StandardCharsets.UTF_8))
|
||||
.lines()
|
||||
.collect(Collectors.joining("\n"));
|
||||
ZuTaiVo zuTai = gson.fromJson(text, ZuTaiVo.class);
|
||||
return zuTai.getElements();
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过orm框架获取数据
|
||||
* @param lineId 监测点Id
|
||||
|
||||
Reference in New Issue
Block a user