Ver código fonte

修改算法json数组属性修改

chenhongyan1989 11 meses atrás
pai
commit
f8fdb9de95

+ 10 - 0
energy-manage-service/src/main/java/com/energy/manage/service/property/analysis/AlgorithmProperties.java

@@ -50,6 +50,12 @@ public class AlgorithmProperties {
     public static String powerFactorRated;
 
 
+    /**
+     * 算法json中无子节点数组
+     */
+    public static List<String> arrayProperties;
+
+
     @Value("${analysis.url}")
     public void setAnalysisUrl(String analysisUrl){
         AlgorithmProperties.analysisUrl = analysisUrl;
@@ -84,4 +90,8 @@ public class AlgorithmProperties {
     public void setPowerFactorRated(String powerFactorRated){
         AlgorithmProperties.powerFactorRated = powerFactorRated;
     }
+    @Value("${analysis.array.properties}")
+    public void setArrayProperties(List<String> arrayProperties){
+        AlgorithmProperties.arrayProperties = arrayProperties;
+    }
 }

+ 11 - 4
energy-manage-service/src/main/java/com/energy/manage/service/service/analysis/impl/AnalysisServiceImpl.java

@@ -116,8 +116,8 @@ public class AnalysisServiceImpl implements AnalysisService {
             log.info("调用分析算法之前,将入参analysisDto转换为算法标准json = {}" , mapper.writeValueAsString(rootNode));
             System.out.println("json入参:" + rootNode.toString());
             //调用算法
-//            String result = HttpUtils.doPost(AlgorithmProperties.analysisUrl,mapper.writeValueAsString(rootNode));
-//            log.info("调用算法分析返回结果:{}",result);
+            String result = HttpUtils.doPost(AlgorithmProperties.analysisUrl,mapper.writeValueAsString(rootNode));
+            log.info("调用算法分析返回结果:{}",result);
             //手动操作进行操作记录添加
             if(analysisDto.getAutoOrManual().equals(AnalysisConstants.MANUAL_ANALYSIS)){
                 addOptionRecords(analysisDto.getPowerFarmID(),null,OPTION_CONTENT);
@@ -363,9 +363,16 @@ public class AnalysisServiceImpl implements AnalysisService {
             Map.Entry<String, JsonNode> entry = it.next();
             // 匹配到属性名称,进行值的修改
             if (entry.getKey().equalsIgnoreCase(propertyName)) {
-                //判断当前节点有没有子节点
+                //判断当前节点有没有子节点 排除分析节点
                 if(!entry.getValue().fields().hasNext() && !propertyName.equalsIgnoreCase(AlgorithmProperties.configAnalysisProperties)){
-                    ((ObjectNode) parentNode).put(propertyName, newValue.toString());
+                    //数组属性得特殊处理
+                    if(AlgorithmProperties.arrayProperties.contains(propertyName)){
+                        ArrayNode arrayNode = mapper.createArrayNode();
+                        ((List<String>)newValue).stream().forEach(item-> arrayNode.add(item));
+                        ((ObjectNode) parentNode).set(propertyName,arrayNode);
+                    }else{
+                        ((ObjectNode) parentNode).put(propertyName, newValue.toString());
+                    }
                 }else{
                     assignmentByPropertyName(entry.getValue(), propertyName, newValue,scada);
                 }

+ 28 - 3
energy-manage-service/src/main/java/com/energy/manage/service/test/TestJson.java

@@ -8,6 +8,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.node.ArrayNode;
 import com.fasterxml.jackson.databind.node.IntNode;
 import com.fasterxml.jackson.databind.node.ObjectNode;
+import io.swagger.util.Json;
 import org.apache.commons.lang3.StringUtils;
 
 import java.lang.reflect.Field;
@@ -119,8 +120,8 @@ public class TestJson {
         dto.setScada("all");
         dto.setAutoOrManual("manual");
         dto.setBeginTime("1234-12-12 00:00:12");
-//        dto.setExcludingMonths(Arrays.asList("1","2","3"));
-//        dto.setTurbines(Arrays.asList("456","789"));
+        dto.setExcludingMonths(Arrays.asList("1","2","3"));
+        dto.setTurbines(Arrays.asList("456","789"));
         dto.setValueActivePower(Arrays.asList(1,2));
         dto.setConfigAnalysis(Arrays.asList("algorithm.powerOscillationAnalyst|PowerOscillationAnalyst|executeAnalysis|minute","algorithm.pitchTSRCpAnalyst|PitchTSRCpAnalyst|executeAnalysis|second"));
         setValue(dto,rootNode);
@@ -156,7 +157,13 @@ public class TestJson {
                 if (entry.getKey().equals(propertyName)) {
                     //如果当前节点没有子节点直接复制
                     if(!entry.getValue().fields().hasNext() && !propertyName.equals("configAnalysis")){
-                        ((ObjectNode) rootNode).put(propertyName, value.toString());
+                        if(StringUtils.endsWithAny(propertyName,"turbines","excludingMonths")){
+                            ArrayNode arrayNode = mapper.createArrayNode();
+                            ((List<String>)value).stream().forEach(item-> arrayNode.add(item));
+                            ((ObjectNode) rootNode).set(propertyName,arrayNode);
+                        }else{
+                            ((ObjectNode) rootNode).put(propertyName, value.toString());
+                        }
                     }else {
                         try {
                             assignmentByPropertyName(entry.getValue(), propertyName, value,scada);
@@ -206,6 +213,11 @@ public class TestJson {
             return ;
         }
         //分析类型特殊处理
+//        if("turbines".equals(propertyName)){
+//            dealArrayNode(subNode, newValue);
+//            return;
+//        }
+        //分析类型特殊处理
         if("configAnalysis".equals(propertyName)){
             dealConfigAnalysis(subNode, newValue,scada);
             return;
@@ -221,6 +233,19 @@ public class TestJson {
             "    \"scada\": \"\"\n" +
             "}";
 
+
+
+    /**
+     * 数组类型处理
+     * @param subNode
+     * @param newValue
+     */
+    private static void dealArrayNode(JsonNode subNode, Object newValue) throws JsonProcessingException {
+        ArrayNode arrayNode = (ArrayNode) subNode;
+        List<String> tu = (List) newValue;
+        tu.stream().forEach(item -> arrayNode.add(item));
+    }
+
     /**
      * 分析类型处理
      * @param subNode

+ 0 - 14
energy-manage-service/src/main/resources/bootstrap.properties

@@ -65,20 +65,6 @@ template.draught = http://192.168.50.234:6900/bucket-zhzn/template/%E9%A3%8E%E6%
 #xxl.job.executor.logpath = /usr/local/logs/xxl
 #xxl.job.executor.logretentiondays = 30
 
-
-#分析算法入参json格式
-analysis.algorithm.json={"dataContractType": {"type": "analysisExecuteOrder","version": "1.2.0"},"dataContract": {"autoOrManual": null,"dataFilter": {"powerFarmID": null,"turbines": null,"dataBatchNum": null,"beginTime": null,"endTime": null,"excludingMonths": null,"customFilter": {"valueWindSpeed": {"min": null,"max": null},"valuePitchAngle": {"min":null,"max": null},"valueActivePower": {"min": null,"max": null},"valueGeneratorSpeed": {"min": null,"max": null}}},"configAnalysis": [],"graphSets": {"DgeneratorSpeed": {"step": 5,"min": 0,"max": 30},"DgeneratorTorque": {"step": 10000,"min": 0,"max": 10000},"IgeneratorSpeed": {"step": 200,"min": 1000,"max": 2000},"IgeneratorTorque": {"step": 2000,"min": 0,"max": 12000},"cp": {"step": 0.5,"min": 0,"max": 2},"tsr": {"step": 5,"min": 0,"max": 30},"pitchAngle": {"step": 1,"min": -1,"max": 20},"activePower": {"step": 250,"min": 0,"max": 2000}}}}
-#需要特殊处理的图像设置属性
-graphSets.properties=dGeneratorSpeed,iGeneratorSpeed,dGeneratorTorque,iGeneratorTorque,cp,tsr,pitchAngle,activePower
-#scada数据筛选
-customFilter.properties=valueWindSpeed,valuePitchAngle,valueActivePower,valueGeneratorSpeed
-#需要特设处理分析类型属性
-analysis.properties.name=configAnalysis
-#分析类型json格式
-analysis.type.json={"package":"","className":"","methodName":"","scada":""}
-#额定功率因数
-power.factor.rated=1.2
-
 #拦截器是否生效
 energy.login.enabled=true