Ver código fonte

1.修改分析类型json默认额定功率

chenhongyan1989 1 ano atrás
pai
commit
c7594a755d

+ 0 - 1
energy-manage-common/src/main/java/com/energy/manage/common/constant/redis/ManagerRedisKeyConstant.java

@@ -1,7 +1,6 @@
 package com.energy.manage.common.constant.redis;
 
 import com.energy.manage.common.enums.IdPrefixEnum;
-import com.energy.manage.common.util.IdGeneratorUtil;
 
 import java.io.Serializable;
 import java.util.Arrays;

+ 8 - 0
energy-manage-service/src/main/java/com/energy/manage/service/constant/analysis/AnalysisConstants.java

@@ -1,5 +1,8 @@
 package com.energy.manage.service.constant.analysis;
 
+import java.util.Arrays;
+import java.util.List;
+
 /**
  * @author chy
  * @date 2024/5/31 09:46
@@ -37,4 +40,9 @@ public interface AnalysisConstants {
      */
     String SCADA = "scada";
 
+    /**
+     * 有功功率轴系设置
+     */
+    List<Double> ACTIVITY_POWER = Arrays.asList(250.0, 0.0,2000.0);
+
 }

+ 72 - 21
energy-manage-service/src/main/java/com/energy/manage/service/service/analysis/impl/AnalysisServiceImpl.java

@@ -124,6 +124,8 @@ public class AnalysisServiceImpl implements AnalysisService {
             if(analysisDto.getAutoOrManual().equalsIgnoreCase(AnalysisConstants.MANUAL_ANALYSIS)){
                 transferAnalysisFlagByCode(analysisDto);
             }
+            //当有功功率没有设置的话 设置默认值 整个风场最大额定功率*1.2
+            setActivePower(analysisDto);
             //将配置文件中的算法json转换为对象
             JsonNode rootNode = mapper.readTree(algorithmProperties.getAnalysisAlgorithmJson());
             //将入参analysisDto转换为算法标准json
@@ -406,13 +408,15 @@ public class AnalysisServiceImpl implements AnalysisService {
      * @param newValue
      */
     private void dealGraphSetsAndCustomFilter(JsonNode subNode, Object newValue){
-        List<Integer> list = (List) newValue;
+        List<Double> 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()));
+            if(index.get() <= list.size() -1 && list.get(index.get()) != null){
+                ((ObjectNode) subNode).put(entry.getKey(), list.get(index.get()));
+            }
             index.incrementAndGet();
         });
     }
@@ -470,6 +474,46 @@ public class AnalysisServiceImpl implements AnalysisService {
     }
 
     /**
+     * 设置额定功率
+     * @param analysisDto
+     * @return
+     */
+    public void setActivePower(AnalysisDto analysisDto){
+        List<Double> targetList = AnalysisConstants.ACTIVITY_POWER;
+        List<Double> sourceList = analysisDto.getActivePower();
+        //替换值为空的元素
+        replaceNullForList(sourceList,targetList);
+        //当源列表长度与指定列表长度一样的话 源列表最后一个元素一定不是空,不需要替换值为最大功率*1.2
+        if(sourceList != null && sourceList.size() == targetList.size()){
+            analysisDto.setActivePower(targetList);
+            return;
+        }
+        String rateCapacity = getRatedCapacity(analysisDto);
+        if(StringUtils.isNotBlank(rateCapacity)){
+            //设置额定功率(风场所有风机中最大功率*1.2)
+            targetList.set(targetList.size() -1 ,new Double(rateCapacity));
+        }
+        analysisDto.setActivePower(targetList);
+    }
+
+    /**
+     * 将源列表中非空元素替换到目标列表中且下标不变
+     * @param sourcelist
+     * @param targetList
+     * @return
+     */
+    private <T> void replaceNullForList(List<T> sourcelist ,List<T> targetList){
+        if(CollectionUtils.isEmpty(sourcelist)){
+            return;
+        }
+        sourcelist.stream().forEachOrdered(element -> {
+            if(element != null){
+                targetList.set(sourcelist.indexOf(element),element);
+            }
+        });
+    }
+
+    /**
      * 获取 ratedCapacity 风机额定功率*1.2
      * @param analysisDto
      * @return
@@ -479,12 +523,15 @@ public class AnalysisServiceImpl implements AnalysisService {
         List<String> engineCodes = analysisDto.getTurbines();
         //获取风场编号
         String fieldCode = analysisDto.getPowerFarmID();
+        if(StringUtils.isBlank(fieldCode)){
+            return null;
+        }
         //查询最大功率
        BigDecimal ratedCapacity = windEngineGroupMapper.selectMaxRatedCapacity(fieldCode,engineCodes);
        //功率因数 1.2
        BigDecimal powerFactorRated = new BigDecimal(algorithmProperties.getPowerFactorRated());
        //返回功率
-       return ratedCapacity == null ? "0" : ratedCapacity.multiply(powerFactorRated).toString();
+       return ratedCapacity == null ? null : ratedCapacity.multiply(powerFactorRated).toString();
     }
 
     @Autowired
@@ -518,24 +565,28 @@ public class AnalysisServiceImpl implements AnalysisService {
      * @throws InterruptedException
      */
     public static void main(String[] args) throws InterruptedException, URISyntaxException {
-        List<AnalysisGeneralFileVo> generalFileVos = new ArrayList<>();
-        AnalysisGeneralFileVo a1 = new AnalysisGeneralFileVo();
-        a1.setFileAddr("http://123/412/89.html");
-        a1.setCreateTime(new Date());
-        a1.setBatchCode("123");
-        generalFileVos.add(a1);
-        Thread.sleep(1000);
-        AnalysisGeneralFileVo a2 = new AnalysisGeneralFileVo();
-        a2.setFileAddr("http://123/412/89.html");
-        a2.setCreateTime(new Date());
-        generalFileVos.add(a2);
-        a2.setBatchCode("453");
-        generalFileVos.sort(Comparator.comparing(AnalysisGeneralFileVo::getCreateTime,Comparator.reverseOrder()));
-        //删除地址相同的文件
-        List<AnalysisGeneralFileVo> returnList =  generalFileVos.stream().collect(Collectors.collectingAndThen(
-                Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(AnalysisGeneralFileVo::getFileAddr))),
-                ArrayList :: new));
-        returnList.forEach(System.out::println);
+//        List<AnalysisGeneralFileVo> generalFileVos = new ArrayList<>();
+//        AnalysisGeneralFileVo a1 = new AnalysisGeneralFileVo();
+//        a1.setFileAddr("http://123/412/89.html");
+//        a1.setCreateTime(new Date());
+//        a1.setBatchCode("123");
+//        generalFileVos.add(a1);
+//        Thread.sleep(1000);
+//        AnalysisGeneralFileVo a2 = new AnalysisGeneralFileVo();
+//        a2.setFileAddr("http://123/412/89.html");
+//        a2.setCreateTime(new Date());
+//        generalFileVos.add(a2);
+//        a2.setBatchCode("453");
+//        generalFileVos.sort(Comparator.comparing(AnalysisGeneralFileVo::getCreateTime,Comparator.reverseOrder()));
+//        //删除地址相同的文件
+//        List<AnalysisGeneralFileVo> returnList =  generalFileVos.stream().collect(Collectors.collectingAndThen(
+//                Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(AnalysisGeneralFileVo::getFileAddr))),
+//                ArrayList :: new));
+//        returnList.forEach(System.out::println);
+        List<String> list = new ArrayList<>();
+        list.add("1");
+        list.add(0,"2");
+        System.out.println(list);
     }
 
 }