|
|
|
|
@@ -2,18 +2,15 @@ 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.*;
|
|
|
|
|
import com.njcn.csdevice.pojo.po.CsDataArray;
|
|
|
|
|
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
|
|
|
|
import com.njcn.csdevice.pojo.po.CsLinePO;
|
|
|
|
|
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;
|
|
|
|
|
@@ -28,7 +25,7 @@ import com.njcn.system.api.DicDataFeignClient;
|
|
|
|
|
import com.njcn.system.api.EpdFeignClient;
|
|
|
|
|
import com.njcn.system.enums.DicDataEnum;
|
|
|
|
|
import lombok.AllArgsConstructor;
|
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
@@ -39,7 +36,10 @@ import java.io.InputStreamReader;
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.math.RoundingMode;
|
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@@ -51,6 +51,7 @@ import java.util.stream.Collectors;
|
|
|
|
|
*/
|
|
|
|
|
@Service
|
|
|
|
|
@AllArgsConstructor
|
|
|
|
|
@Slf4j
|
|
|
|
|
public class LineTargetServiceImpl implements ILineTargetService {
|
|
|
|
|
|
|
|
|
|
private final CsLedgerFeignClient csLedgerFeignClient;
|
|
|
|
|
@@ -109,6 +110,36 @@ public class LineTargetServiceImpl implements ILineTargetService {
|
|
|
|
|
return dataArrayFeignClient.getDataArray(setList).getData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @Override
|
|
|
|
|
// public List<CsRtDataVO> getLineData(String id) {
|
|
|
|
|
// List<CsRtDataVO> result = new ArrayList<>();
|
|
|
|
|
// String path = csPagePOService.queryById(id).getPath();
|
|
|
|
|
// InputStream inputStream = fileStorageUtil.getFileStream(path);
|
|
|
|
|
// ZuTaiDTO zuTaiDto = analysisJson(inputStream);
|
|
|
|
|
// zuTaiDto.getJson().forEach(item->{
|
|
|
|
|
// if (!Objects.isNull(item.getTarget()) && StringUtils.isNotBlank(item.getTarget())){
|
|
|
|
|
// String targetTag = item.getTarget().split("\\$")[0];
|
|
|
|
|
// String phasic = item.getTarget().split("\\$")[1];
|
|
|
|
|
// String dataType = item.getTarget().split("\\$")[2];
|
|
|
|
|
// if (CollectionUtils.isEmpty(item.getUId()) || ObjectUtil.isNull(item.getLineId())){
|
|
|
|
|
// throw new BusinessException(CsHarmonicResponseEnum.BIND_TARGET_ERROR);
|
|
|
|
|
// }
|
|
|
|
|
// CsDataArray dataArray = dataArrayFeignClient.getDataArrayById(String.valueOf(item.getUId().get(0)),targetTag).getData().get(0);
|
|
|
|
|
// String targetName = dataArray.getAnotherName();
|
|
|
|
|
// String dataId = dataArray.getDataId();
|
|
|
|
|
// String classId = epdFeignClient.selectById(dataId).getData().getClassId();
|
|
|
|
|
// String clDid = influxDbParamUtil.getClDidByLineId(item.getLineId());
|
|
|
|
|
// //基础信息
|
|
|
|
|
// CsRtDataVO vo = getLineRtData(item.getId(),item.getLineId(),influxDbParamUtil.getTableNameByClassId(classId),targetTag,phasic,dataType,targetName,clDid);
|
|
|
|
|
// //设备状态信息
|
|
|
|
|
// CsEquipmentDeliveryPO po = equipmentFeignClient.getDevByLineId(item.getLineId()).getData();
|
|
|
|
|
// vo.setDevStatus(po.getRunStatus());
|
|
|
|
|
// result.add(vo);
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
// return result;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<CsRtDataVO> getLineData(String id) {
|
|
|
|
|
List<CsRtDataVO> result = new ArrayList<>();
|
|
|
|
|
@@ -116,20 +147,25 @@ public class LineTargetServiceImpl implements ILineTargetService {
|
|
|
|
|
InputStream inputStream = fileStorageUtil.getFileStream(path);
|
|
|
|
|
ZuTaiDTO zuTaiDto = analysisJson(inputStream);
|
|
|
|
|
zuTaiDto.getJson().forEach(item->{
|
|
|
|
|
if (!Objects.isNull(item.getTarget()) && StringUtils.isNotBlank(item.getTarget())){
|
|
|
|
|
String targetTag = item.getTarget().split("\\$")[0];
|
|
|
|
|
String phasic = item.getTarget().split("\\$")[1];
|
|
|
|
|
String dataType = item.getTarget().split("\\$")[2];
|
|
|
|
|
if (CollectionUtils.isEmpty(item.getUId()) || ObjectUtil.isNull(item.getLineId())){
|
|
|
|
|
throw new BusinessException(CsHarmonicResponseEnum.BIND_TARGET_ERROR);
|
|
|
|
|
if (ObjectUtil.isNotNull(item.getUIdType()) && item.getUIdType()) {
|
|
|
|
|
Object lastElement = item.getUId().get(item.getUId().size() - 1);
|
|
|
|
|
String data = String.valueOf(lastElement);
|
|
|
|
|
//分解出来五个参数 第一个 指标字段 第二个 相别 第三个 数据类型 第四个 influxdb表名 第五个 限值名称
|
|
|
|
|
String[] tempTable = data.replace("$", "").split("#");
|
|
|
|
|
//解析指标名称
|
|
|
|
|
String targetName = "指标名称获取失败";
|
|
|
|
|
String[] tmepUidName = item.getTarget().split(" / ");
|
|
|
|
|
if(tmepUidName.length==2) {
|
|
|
|
|
targetName = tmepUidName[0];
|
|
|
|
|
}else if (tmepUidName.length==3) {
|
|
|
|
|
targetName = tmepUidName[0];
|
|
|
|
|
} else if (tmepUidName.length==4) {
|
|
|
|
|
targetName = tmepUidName[1];
|
|
|
|
|
}
|
|
|
|
|
CsDataArray dataArray = dataArrayFeignClient.getDataArrayById(item.getUId().get(0),targetTag).getData().get(0);
|
|
|
|
|
String targetName = dataArray.getAnotherName();
|
|
|
|
|
String dataId = dataArray.getDataId();
|
|
|
|
|
String classId = epdFeignClient.selectById(dataId).getData().getClassId();
|
|
|
|
|
String clDid = influxDbParamUtil.getClDidByLineId(item.getLineId());
|
|
|
|
|
//基础信息
|
|
|
|
|
CsRtDataVO vo = getLineRtData(item.getId(),item.getLineId(),influxDbParamUtil.getTableNameByClassId(classId),targetTag,phasic,dataType,targetName,clDid);
|
|
|
|
|
System.out.println(item.getLineId());
|
|
|
|
|
CsRtDataVO vo = getLineRtData(item.getId(),item.getLineId(),tempTable[3],tempTable[0],Objects.equals(tempTable[1],"T")?"M":tempTable[1],tempTable[2],targetName,clDid);
|
|
|
|
|
//设备状态信息
|
|
|
|
|
CsEquipmentDeliveryPO po = equipmentFeignClient.getDevByLineId(item.getLineId()).getData();
|
|
|
|
|
vo.setDevStatus(po.getRunStatus());
|
|
|
|
|
@@ -148,7 +184,7 @@ public class LineTargetServiceImpl implements ILineTargetService {
|
|
|
|
|
ZuTaiNewDTO zuTaiDto = analysisJsonNew(inputStream);
|
|
|
|
|
|
|
|
|
|
zuTaiDto.getJson().forEach(item->{
|
|
|
|
|
if (!CollectionUtils.isEmpty(item.getUidNames())){
|
|
|
|
|
if (!CollectionUtils.isEmpty(item.getUidNames()) && Objects.isNull(item.getUidType())){
|
|
|
|
|
for (int i = 0; i < item.getUidNames().size(); i++) {
|
|
|
|
|
String temp = item.getUidNames().get(i);
|
|
|
|
|
String targetTag = null;
|
|
|
|
|
@@ -168,16 +204,21 @@ public class LineTargetServiceImpl implements ILineTargetService {
|
|
|
|
|
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)));
|
|
|
|
|
// List<String> tempUid = (List<String>) item.getUid().get(i);
|
|
|
|
|
|
|
|
|
|
if (item.getUid().get(i) instanceof List) {
|
|
|
|
|
List<?> rawList = (List<?>) item.getUid().get(i);
|
|
|
|
|
List<String> tempUid = rawList.stream()
|
|
|
|
|
.filter(item2 -> item2 instanceof String)
|
|
|
|
|
.map(item2 -> (String) item2)
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
String s = tempUid.get(tempUid.size() - 1);
|
|
|
|
|
String[] tempTable = s.replace("$", "").split("#");
|
|
|
|
|
result.add(getLineRtDataNew(item.getId(),item.getLineId(),tempTable[3],tempTable[0],Objects.equals(tempTable[1],"T")?"M":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;
|
|
|
|
|
}
|
|
|
|
|
@@ -231,6 +272,13 @@ public class LineTargetServiceImpl implements ILineTargetService {
|
|
|
|
|
*/
|
|
|
|
|
public CsRtDataVO getLineRtData(String id,String lineId, String tableName, String columnName, String phasic, String dataType, String target, String cldId) {
|
|
|
|
|
CsRtDataVO csRtDataVO = new CsRtDataVO();
|
|
|
|
|
log.info("---------------------------------------------------------------------------------------------------------------");
|
|
|
|
|
log.info(lineId);
|
|
|
|
|
log.info(tableName);
|
|
|
|
|
log.info(columnName);
|
|
|
|
|
log.info(phasic);
|
|
|
|
|
log.info(dataType);
|
|
|
|
|
log.info(cldId);
|
|
|
|
|
StatisticalDataDTO statisticalDataDTO = commonService.getLineRtData(lineId,tableName,columnName,phasic,dataType,cldId);
|
|
|
|
|
if(Objects.isNull(statisticalDataDTO)){
|
|
|
|
|
statisticalDataDTO = new StatisticalDataDTO();
|
|
|
|
|
|