Bläddra i källkod

计算方法null问题

hlf 3 månader sedan
förälder
incheckning
8df7b9d0d2

+ 5 - 0
generationXK-service/pom.xml

@@ -141,6 +141,11 @@
             <artifactId>spring-test</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-test</artifactId>
+            <scope>test</scope>
+        </dependency>
 
         <!--        <dependency>-->
         <!--            <groupId>com.gyee</groupId>-->

+ 46 - 34
generationXK-service/src/main/java/com/gyee/generation/service/realtimelibrary/StatusService.java

@@ -58,24 +58,32 @@ public class StatusService {
             //算调度场站自算功率
             Map<String, ProBasicPowerstationPoint> stringProBasicPowerstationPointMap = subwppointmap.get(sub.getId());
 
-            ProBasicPowerstationPoint zsglPoint = stringProBasicPowerstationPointMap.get(ContantXk.TPOINT_WP_ZSGL);
+            ProBasicPowerstationPoint zsglPoint = null;
+            if (null != stringProBasicPowerstationPointMap){
+                zsglPoint = stringProBasicPowerstationPointMap.get(ContantXk.TPOINT_WP_ZSGL);
+            }
             AtomicReference<Double> zsgl = new AtomicReference<>((double) 0);
             List<ProBasicProject> basicProjects = pjls.stream().filter(p -> p.getWindsubStationId().equals(sub.getId())).collect(Collectors.toList());
             basicProjects.stream().forEach(p -> {
                 Map<String, ProBasicPowerstationPoint> powerstationPointMap = propointmap.get(p.getId());
-                ProBasicPowerstationPoint powerstationPoint = powerstationPointMap.get(ContantXk.SSZNHGLZS);
-
-                zsgl.updateAndGet(v -> {
-                    try {
-                        return new Double((double) (v + edosUtil.getSectionData(powerstationPoint, currentDate.getTime()).getPointValueInDouble()));
-                    } catch (Exception e) {
-                        e.printStackTrace();
+                if (null != powerstationPointMap){
+                    ProBasicPowerstationPoint powerstationPoint = powerstationPointMap.get(ContantXk.SSZNHGLZS);
+                    if (null != powerstationPoint){
+                        zsgl.updateAndGet(v -> {
+                            try {
+                                return new Double((double) (v + edosUtil.getSectionData(powerstationPoint, currentDate.getTime()).getPointValueInDouble()));
+                            } catch (Exception e) {
+                                e.printStackTrace();
+                            }
+                            return v;
+                        });
                     }
-                    return v;
-                });
+                }
             });
             try {
-                edosUtil.sendSinglePoint(PointUtil.createPointData(currentDate, zsgl.get(), zsglPoint.getNemCode(), zsglPoint.getName()));
+                if (null != zsglPoint){
+                    edosUtil.sendSinglePoint(PointUtil.createPointData(currentDate, zsgl.get(), zsglPoint.getNemCode(), zsglPoint.getName()));
+                }
             } catch (Exception e) {
                 e.printStackTrace();
             }
@@ -333,7 +341,7 @@ public class StatusService {
                         }
                     }
                     //判定是否所有中断盘点点的取值时间,距离当前时间相差大于指定值,就统计到新的集合里,如果结果集数量等于中断点数量,说明设备通信中断
-                    List<PointData> collect = interruptionRealData.stream().filter(i -> (currentDate.getTime() - i.getPointTime()) / 1000 > Integer.parseInt(second)).collect(Collectors.toList());
+                    List<PointData> collect = interruptionRealData.stream().filter(i -> i.getPointTime() != null && (currentDate.getTime() - i.getPointTime()) / 1000 > Integer.parseInt(second)).collect(Collectors.toList());
 
                     if (state == interruptionList.size() || collect.size() == interruptionRealData.size()) {
                         //离线
@@ -373,21 +381,23 @@ public class StatusService {
         String aiordi = modelMap.get(wt.getModelId()).getDescription();
         if (aiordi.equals("AI")) {
             Map<Integer, Integer> stateMap = aistateMap.get(wt.getModelId());
-            Optional<ProBasicStatusPoint> first = statusMap.get(wt.getId()).stream().filter(w -> w.getUniformCode().equals(Contant.AI422)).findFirst();
-            if (first.isPresent()) {
-                ProBasicStatusPoint windturbinestatusdi = first.get();
-                int pointValueInDouble = (int) edosUtil.getRealData(windturbinestatusdi.getNemCode()).getPointValueInDouble();
+            if (null != stateMap){
+                Optional<ProBasicStatusPoint> first = statusMap.get(wt.getId()).stream().filter(w -> w.getUniformCode().equals(Contant.AI422)).findFirst();
+                if (first.isPresent()) {
+                    ProBasicStatusPoint windturbinestatusdi = first.get();
+                    int pointValueInDouble = (int) edosUtil.getRealData(windturbinestatusdi.getNemCode()).getPointValueInDouble();
 
-                if (stateMap.containsKey(pointValueInDouble)) {
-                    double temp = (double) stateMap.get(pointValueInDouble);
+                    if (stateMap.containsKey(pointValueInDouble)) {
+                        double temp = (double) stateMap.get(pointValueInDouble);
 
-                    if (temp == 3) {
-                        status = 2;
-                    } else if (temp == 8 || temp == 9) {
-                        status = 3;
+                        if (temp == 3) {
+                            status = 2;
+                        } else if (temp == 8 || temp == 9) {
+                            status = 3;
+                        }
                     }
-                }
 
+                }
             }
         } else {
             //每个状态一个状态点
@@ -553,18 +563,20 @@ public class StatusService {
             String aiordi = modelMap.get(wt.getModelId()).getDescription();
             if (aiordi.equals("AI")) {
 
-                Optional<ProBasicStatusPoint> first = statusMap.get(wt.getId()).stream().filter(w -> w.getUniformCode().equals(Contant.AI422)).findFirst();
-                if (first.isPresent()) {
-                    ProBasicStatusPoint windturbinestatusdi = first.get();
-                    aipointls.add(windturbinestatusdi.getNemCode());
-                }
+                if (statusMap.size() > 0){
+                    Optional<ProBasicStatusPoint> first = statusMap.get(wt.getId()).stream().filter(w -> w.getUniformCode().equals(Contant.AI422)).findFirst();
+                    if (first.isPresent()) {
+                        ProBasicStatusPoint windturbinestatusdi = first.get();
+                        aipointls.add(windturbinestatusdi.getNemCode());
+                    }
 
-                if (wt.getModelId().contains("HW")) {
-                    Optional<ProBasicStatusPoint> gzzt = statusMap.get(wt.getId()).stream().filter(w -> w.getUniformCode().equals(Contant.MX004)).findFirst();
-                    if (gzzt.isPresent()) {
-                        ProBasicStatusPoint windturbinestatusdi = gzzt.get();
-                        PointData po = edosUtil.getRealData(windturbinestatusdi.getNemCode());
-                        gzztMap.put(wt.getId(), po.getPointValueInDouble());
+                    if (wt.getModelId().contains("HW")) {
+                        Optional<ProBasicStatusPoint> gzzt = statusMap.get(wt.getId()).stream().filter(w -> w.getUniformCode().equals(Contant.MX004)).findFirst();
+                        if (gzzt.isPresent()) {
+                            ProBasicStatusPoint windturbinestatusdi = gzzt.get();
+                            PointData po = edosUtil.getRealData(windturbinestatusdi.getNemCode());
+                            gzztMap.put(wt.getId(), po.getPointValueInDouble());
+                        }
                     }
                 }