|
|
@@ -7,8 +7,6 @@ import com.energy.manage.common.util.HttpUtils;
|
|
|
import com.energy.manage.service.constant.analysis.AnalysisConstants;
|
|
|
import com.energy.manage.service.domain.dto.analysis.AnalysisDto;
|
|
|
import com.energy.manage.service.domain.dto.analysis.AnalysisResultDto;
|
|
|
-import com.energy.manage.service.domain.dto.analysisalgorithm.DataContractDto;
|
|
|
-import com.energy.manage.service.domain.dto.analysisalgorithm.DataContractTypeDto;
|
|
|
import com.energy.manage.service.domain.vo.analysis.*;
|
|
|
import com.energy.manage.service.domain.vo.windenginegroup.WindEngineGroupVo;
|
|
|
import com.energy.manage.service.mappers.analysis.*;
|
|
|
@@ -16,7 +14,6 @@ import com.energy.manage.service.mappers.windenginegroup.WindEngineGroupMapper;
|
|
|
import com.energy.manage.service.property.analysis.AlgorithmProperties;
|
|
|
import com.energy.manage.service.service.analysis.AnalysisService;
|
|
|
import com.energy.manage.service.util.BeanMapUtils;
|
|
|
-import com.energy.manage.service.util.TreeUtil;
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
@@ -29,6 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.stream.Collectors;
|
|
|
@@ -65,6 +63,8 @@ public class AnalysisServiceImpl implements AnalysisService {
|
|
|
@Autowired
|
|
|
private AnalysisGeneralFileMapper generalFileMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private WindEngineGroupMapper windEngineGroupMapper;
|
|
|
|
|
|
private static ObjectMapper mapper = new ObjectMapper();
|
|
|
|
|
|
@@ -86,14 +86,16 @@ public class AnalysisServiceImpl implements AnalysisService {
|
|
|
@Override
|
|
|
public ResultResp analysis(AnalysisDto analysisDto) {
|
|
|
try {
|
|
|
- String batchCode = analysisDto.getDataBatchNum();
|
|
|
- if(checkAnalysising(batchCode)){
|
|
|
+ if(checkAnalysising()){
|
|
|
return ResultResp.FAIL(ConstVar.ANALYSISING);
|
|
|
}
|
|
|
+ //分析类型code转换为flag(便于json分析类型赋值)
|
|
|
+ transferAnalysisFlagByCode(analysisDto);
|
|
|
//将配置文件中的算法json转换为对象
|
|
|
JsonNode rootNode = mapper.readTree(AlgorithmProperties.analysisJson);
|
|
|
- //将前端入参转换为算法标准json
|
|
|
+ //将入参analysisDto转换为算法标准json
|
|
|
dataProccess(analysisDto,rootNode);
|
|
|
+ log.info("调用分析算法之前,将入参analysisDto转换为算法标准json = {}" + rootNode.toString());
|
|
|
//调用算法
|
|
|
JSONObject jsonObject = HttpUtils.doPost(AlgorithmProperties.analysisUrl,mapper.convertValue(rootNode, Map.class));
|
|
|
log.info("调用算法分析返回结果:{}",jsonObject);
|
|
|
@@ -134,11 +136,8 @@ public class AnalysisServiceImpl implements AnalysisService {
|
|
|
}
|
|
|
//最新总文件
|
|
|
List<AnalysisGeneralFileVo> newGeneralFileVos = new ArrayList<>();
|
|
|
- //如果风机编号为空的话 则需要查总文件
|
|
|
- if(StringUtils.isBlank(fieldEngineCode)){
|
|
|
- //获取最新总文件列表
|
|
|
- newGeneralFileVos = getNewGeneralFiles(batchCode,analysisTypeCode);
|
|
|
- }
|
|
|
+ //获取最新总文件列表
|
|
|
+ newGeneralFileVos = getNewGeneralFiles(batchCode,analysisTypeCode);
|
|
|
//获取最新分文件
|
|
|
List<AnalysisDiagramRelationVo> newDiagramRelationVos = getNewDiagramRelations(batchCode, analysisTypeCode, fieldEngineCode);
|
|
|
//查询评论
|
|
|
@@ -161,6 +160,16 @@ public class AnalysisServiceImpl implements AnalysisService {
|
|
|
|
|
|
|
|
|
/**
|
|
|
+ * 分析中检查
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public boolean checkAnalysising(){
|
|
|
+ return analysisResultMapper.selectAlasisingCount() > AnalysisConstants.SERVER_MERCHINE_COUNT;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
* 获取分析类型
|
|
|
*/
|
|
|
private List<Map<String,Object>> getAnalysisType(){
|
|
|
@@ -169,8 +178,10 @@ public class AnalysisServiceImpl implements AnalysisService {
|
|
|
if(CollectionUtils.isEmpty(analysisTypeVos)){
|
|
|
return resultList;
|
|
|
}
|
|
|
+ analysisTypeVos = analysisTypeVos.stream().filter(item->StringUtils.isNotBlank(item.getTypeCode())).sorted(Comparator.comparing(AnalysisTypeVo::getParentId)).collect(Collectors.toList());
|
|
|
analysisTypeVos.forEach(analysisTypeVo -> resultList.add(BeanMapUtils.beanToMap(analysisTypeVo)));
|
|
|
- return TreeUtil.getJava8ResultTree(resultList, AnalysisConstants.ANALYSIS_TYPE_PARRENT_KEY);
|
|
|
+ return resultList;
|
|
|
+// return TreeUtil.getJava8ResultTree(resultList, AnalysisConstants.ANALYSIS_TYPE_PARRENT_KEY,AnalysisConstants.ANALYSIS_TYPE_KEY);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -258,13 +269,15 @@ public class AnalysisServiceImpl implements AnalysisService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 分析中检查
|
|
|
- * @param batchCode
|
|
|
- * @return
|
|
|
+ * 根据分析类型code转换分析flag
|
|
|
+ * @param analysisDto
|
|
|
*/
|
|
|
- private boolean checkAnalysising(String batchCode){
|
|
|
- int analysisingCount = analysisResultMapper.selectAlasisingCountByBatchCode(batchCode);
|
|
|
- return analysisingCount > AnalysisConstants.SERVER_MERCHINE_COUNT;
|
|
|
+ private void transferAnalysisFlagByCode(AnalysisDto analysisDto){
|
|
|
+ List<String> configAnalysisCodes = analysisDto.getConfigAnalysis();
|
|
|
+ if(CollectionUtils.isEmpty(configAnalysisCodes)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ analysisDto.setConfigAnalysis(analysisTypeMapper.selecFlagtByCode(configAnalysisCodes));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -275,16 +288,24 @@ public class AnalysisServiceImpl implements AnalysisService {
|
|
|
private void dataProccess(AnalysisDto analysisDto,JsonNode rootNode){
|
|
|
//前端入参类
|
|
|
Field[] analysisFields = analysisDto.getClass().getDeclaredFields();
|
|
|
+// List<String> propertyNames = new ArrayList<>();
|
|
|
+ String scada = analysisDto.getScada();
|
|
|
Arrays.asList(analysisFields).stream().forEach(field -> {
|
|
|
field.setAccessible(true);
|
|
|
try {
|
|
|
if(field.get(analysisDto) != null){
|
|
|
- updateNodesByPropertyName(rootNode, field.getName(), field.get(analysisDto));
|
|
|
+ //放置值不为空的属性
|
|
|
+// propertyNames.add(field.getName());
|
|
|
+ updateNodesByPropertyName(rootNode, field.getName(), field.get(analysisDto),scada);
|
|
|
}
|
|
|
} catch (IllegalAccessException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
});
|
|
|
+ //如果不包含该属性则设置默认值
|
|
|
+// if(!propertyNames.contains("activePower")){
|
|
|
+//
|
|
|
+// }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -319,20 +340,20 @@ public class AnalysisServiceImpl implements AnalysisService {
|
|
|
* @param propertyName 属性名称
|
|
|
* @param newValue 新值
|
|
|
*/
|
|
|
- private void updateNodesByPropertyName(JsonNode parentNode, String propertyName, Object newValue) {
|
|
|
+ private void updateNodesByPropertyName(JsonNode parentNode, String propertyName, Object newValue,String scada) {
|
|
|
if (parentNode.isObject()) {
|
|
|
parentNode.fields().forEachRemaining(entry -> {
|
|
|
// 匹配到属性名称,进行值的修改
|
|
|
- if (entry.getKey().equals(propertyName)) {
|
|
|
+ if (entry.getKey().equalsIgnoreCase(propertyName)) {
|
|
|
//判断当前节点有没有子节点
|
|
|
- if(parentNode.isContainerNode()){
|
|
|
- assignmentByPropertyName(entry.getValue(), propertyName, newValue);
|
|
|
- }else{
|
|
|
+ if(!entry.getValue().fields().hasNext() && !propertyName.equalsIgnoreCase(AlgorithmProperties.configAnalysisProperties)){
|
|
|
((ObjectNode) parentNode).put(propertyName, newValue.toString());
|
|
|
+ }else{
|
|
|
+ assignmentByPropertyName(entry.getValue(), propertyName, newValue,scada);
|
|
|
}
|
|
|
}
|
|
|
// 递归搜索子节点
|
|
|
- updateNodesByPropertyName(entry.getValue(), propertyName, newValue);
|
|
|
+ updateNodesByPropertyName(entry.getValue(), propertyName, newValue,scada);
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
@@ -343,7 +364,7 @@ public class AnalysisServiceImpl implements AnalysisService {
|
|
|
* @param propertyName
|
|
|
* @param newValue
|
|
|
*/
|
|
|
- private void assignmentByPropertyName(JsonNode subNode, String propertyName, Object newValue){
|
|
|
+ private void assignmentByPropertyName(JsonNode subNode, String propertyName, Object newValue,String scada){
|
|
|
//scada数据筛选过滤 、图像设置特殊处理
|
|
|
if(AlgorithmProperties.graphSetsProperties.contains(propertyName)
|
|
|
|| AlgorithmProperties.customFilterProperties.contains(propertyName)){
|
|
|
@@ -352,7 +373,7 @@ public class AnalysisServiceImpl implements AnalysisService {
|
|
|
}
|
|
|
//分析类型特殊处理
|
|
|
if(AlgorithmProperties.configAnalysisProperties.equals(propertyName)){
|
|
|
- dealConfigAnalysis(subNode, newValue);
|
|
|
+ dealConfigAnalysis(subNode, newValue,scada);
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
@@ -364,6 +385,9 @@ public class AnalysisServiceImpl implements AnalysisService {
|
|
|
*/
|
|
|
private void dealGraphSetsAndCustomFilter(JsonNode subNode, Object newValue){
|
|
|
List<Integer> list = (List) newValue;
|
|
|
+ if(list.size() == 0){
|
|
|
+ return;
|
|
|
+ }
|
|
|
AtomicInteger index = new AtomicInteger(0);
|
|
|
subNode.fields().forEachRemaining(entry -> {
|
|
|
((ObjectNode) subNode).put(entry.getKey(), list.get(index.get()));
|
|
|
@@ -376,7 +400,7 @@ public class AnalysisServiceImpl implements AnalysisService {
|
|
|
* @param subNode
|
|
|
* @param newValue
|
|
|
*/
|
|
|
- private void dealConfigAnalysis(JsonNode subNode, Object newValue){
|
|
|
+ private void dealConfigAnalysis(JsonNode subNode, Object newValue,String scada){
|
|
|
try{
|
|
|
ArrayNode arrayNode = (ArrayNode) subNode;
|
|
|
List<String> analysisTypes = (List) newValue;
|
|
|
@@ -386,7 +410,11 @@ public class AnalysisServiceImpl implements AnalysisService {
|
|
|
String[] types = analysisTypes.get(i).split("\\|");
|
|
|
AtomicInteger index = new AtomicInteger(0);
|
|
|
childNode.fields().forEachRemaining(entry-> {
|
|
|
- ((ObjectNode)childNode).put(entry.getKey(), types[index.get()]);
|
|
|
+ if(StringUtils.isNotBlank(scada) && entry.getKey().equals(AnalysisConstants.SCADA)){
|
|
|
+ ((ObjectNode)childNode).put(entry.getKey(), scada);
|
|
|
+ }else{
|
|
|
+ ((ObjectNode)childNode).put(entry.getKey(), types[index.get()]);
|
|
|
+ }
|
|
|
index.incrementAndGet();
|
|
|
});
|
|
|
arrayNode.add(childNode);
|
|
|
@@ -396,4 +424,22 @@ public class AnalysisServiceImpl implements AnalysisService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取 ratedCapacity 风机额定功率*1.2
|
|
|
+ * @param analysisDto
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String getRatedCapacity(AnalysisDto analysisDto){
|
|
|
+ //获取风机机组
|
|
|
+ List<String> engineCodes = analysisDto.getTurbines();
|
|
|
+ //获取风场编号
|
|
|
+ String fieldCode = analysisDto.getPowerFarmID();
|
|
|
+ //查询最大功率
|
|
|
+ BigDecimal ratedCapacity = windEngineGroupMapper.selectMaxRatedCapacity(fieldCode,engineCodes);
|
|
|
+ //功率因数 1.2
|
|
|
+ BigDecimal powerFactorRated = new BigDecimal(AlgorithmProperties.powerFactorRated);
|
|
|
+ //返回功率
|
|
|
+ return ratedCapacity == null ? "0" : ratedCapacity.multiply(powerFactorRated).toString();
|
|
|
+ }
|
|
|
+
|
|
|
}
|