Explorar el Código

优化后台计算算法

shilin hace 1 año
padre
commit
2bd7ba2fb2

+ 3 - 0
realtime/generationXK-service/src/main/java/com/gyee/generation/GenerationMain.java

@@ -16,6 +16,9 @@ public class GenerationMain {
     public static void main(String[] args) throws Exception {
         SpringApplication.run(GenerationMain.class, args);
 
+//        InputOrOutPutService inputOrOutPutService= SpringUtils.getBean("inputOrOutPutService");
+//
+//        inputOrOutPutService.initialInputOrOutputSpeed();
 
 
 //        CacheService cacheService= SpringUtils.getBean("cacheService");

+ 4 - 1
realtime/generationXK-service/src/main/java/com/gyee/generation/init/CacheContext.java

@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.TypeReference;
 import com.gyee.common.model.StringUtils;
 import com.gyee.generation.model.auto.*;
+import com.gyee.generation.service.InputOrOutPutService;
 import com.gyee.generation.service.auto.*;
 import com.gyee.generation.service.realtimelibrary.TheoreticalPowerService;
 import com.gyee.generation.util.redis.RedisService;
@@ -72,6 +73,8 @@ public class CacheContext implements CommandLineRunner {
     private IProBasicEnergyGroupService proBasicEnergyGroupService;
     @Resource
     private IProEconStateAiService proEconStateAiService;
+    @Resource
+    private InputOrOutPutService inputOrOutPutService;
 
     @Value("${runWindpowerstation}")
     private String runWindpowerstation;
@@ -544,7 +547,7 @@ public class CacheContext implements CommandLineRunner {
         }
 
 
-
+        inputOrOutPutService.initialInputOrOutputSpeed();
         logger.info("缓存结束------------------------------------------------------------");
     }
 }

+ 132 - 68
realtime/generationXK-service/src/main/java/com/gyee/generation/service/InputOrOutPutService.java

@@ -40,44 +40,93 @@ public class InputOrOutPutService {
     @Value("${frequency.cutinandout}")
     private Integer frequency;
 
+    private static  Map<String, Double> statusRanngMap;
 
 
-    public void inputOrOutputSpeed(Date recordDate) throws Exception {
 
-//        Date begin = DateUtils.addSeconds(recordDate, -60);
-//
-        Date begin = DateUtils.addSeconds(recordDate, -frequency);
-        Date end = recordDate;
-        Map<String, ProEconInputOrOutputSpeed> wtTimeStatusMap=new HashMap<>();
-        Map<String,Double> wtLastStatusMap=new HashMap<>();
+    public void initialInputOrOutputSpeed()
+    {
+        statusRanngMap=new HashMap<>();
+        List<ProBasicEquipment> wtls= new ArrayList<>();
+        for(ProBasicPowerstation wp: CacheContext.wpls)
+        {
+            if(wp.getId().contains("FDC") )
+            {
+                wtls.addAll(CacheContext.wpwtmap.get(wp.getId()));
+            }
+        }
 
-        QueryWrapper<ProEconInputOrOutputSpeed> queryWrapper = new QueryWrapper<>();
-        queryWrapper.ge("record_date",begin).le("record_date",end);
-        queryWrapper.orderByAsc("record_date");
-        List<ProEconInputOrOutputSpeed> recordList = proEconInputOrOutputSpeedService.list(queryWrapper);
+        List<ProEconInputOrOutputSpeed> ls=new ArrayList<>();
 
-        Map<String, Map<String,ProEconInputOrOutputSpeed>> statusMap=new HashMap<>();
-        if(!recordList.isEmpty())
+
+        List<String> mxztls=new ArrayList<>();
+        List<String> ssfsls=new ArrayList<>();
+        for (ProBasicEquipment wt: wtls)
         {
-            for(ProEconInputOrOutputSpeed po:recordList)
+
+            Map<String, ProBasicEquipmentPoint> pointmap= CacheContext.wtpAimap.get(wt.getId());
+
+            ProBasicEquipmentPoint mxzt= pointmap.get(ContantXk.SBZT);
+            mxztls.add(mxzt.getNemCode());
+            ProBasicEquipmentPoint ssfs= pointmap.get(ContantXk.CJ_SSFS);
+            ssfsls.add(ssfs.getNemCode());
+        }
+
+
+        try {
+            List<PointData> mxztvaluels = edosUtil.getRealData(mxztls);
+
+            if(!mxztvaluels.isEmpty() && mxztvaluels.size()==wtls.size())
             {
-                if(statusMap.containsKey(po.getWindturbineId()))
+                for (int i=0;i<wtls.size();i++)
                 {
-                    Map<String, ProEconInputOrOutputSpeed> map= statusMap.get(po.getWindturbineId());
-                    map.put(String.valueOf(po.getRecordDate().getTime()),po);
-                }else
-                {
-                    Map<String, ProEconInputOrOutputSpeed> map= new HashMap<>();
-                    map.put(String.valueOf(po.getRecordDate().getTime()),po);
-                    statusMap.put(po.getWindturbineId(),map);
-                }
 
+                    ProBasicEquipment wt=wtls.get(i);
+                    statusRanngMap.put(wt.getId(),mxztvaluels.get(i).getPointValueInDouble());
+                }
             }
+
+        } catch (Exception e) {
+            throw new RuntimeException(e);
         }
+    }
+
+    public void inputOrOutputSpeed(Date recordDate) throws Exception {
+
+//        Date begin = DateUtils.addSeconds(recordDate, -60);
+//
+//        Date begin = DateUtils.addHours(recordDate, -frequency);
+//        Date end = recordDate;
+//        Map<String, ProEconInputOrOutputSpeed> wtTimeStatusMap=new HashMap<>();
+//        Map<String,Double> wtLastStatusMap=new HashMap<>();
+//
+//        QueryWrapper<ProEconInputOrOutputSpeed> queryWrapper = new QueryWrapper<>();
+//        queryWrapper.ge("record_date",begin).le("record_date",end);
+//        queryWrapper.orderByAsc("record_date");
+//        List<ProEconInputOrOutputSpeed> recordList = proEconInputOrOutputSpeedService.list(queryWrapper);
+//
+//        Map<String, Map<String,ProEconInputOrOutputSpeed>> statusMap=new HashMap<>();
+//        if(!recordList.isEmpty())
+//        {
+//            for(ProEconInputOrOutputSpeed po:recordList)
+//            {
+//                if(statusMap.containsKey(po.getWindturbineId()))
+//                {
+//                    Map<String, ProEconInputOrOutputSpeed> map= statusMap.get(po.getWindturbineId());
+//                    map.put(String.valueOf(po.getRecordDate().getTime()),po);
+//                }else
+//                {
+//                    Map<String, ProEconInputOrOutputSpeed> map= new HashMap<>();
+//                    map.put(String.valueOf(po.getRecordDate().getTime()),po);
+//                    statusMap.put(po.getWindturbineId(),map);
+//                }
+//
+//            }
+//        }
         List<ProBasicEquipment> wtls= new ArrayList<>();
         for(ProBasicPowerstation wp: CacheContext.wpls)
         {
-            if(wp.getId().contains("FDC") && !wp.getId().contains("MLJ") )
+            if(wp.getId().contains("FDC") )
             {
                 wtls.addAll(CacheContext.wpwtmap.get(wp.getId()));
             }
@@ -99,72 +148,87 @@ public class InputOrOutPutService {
             ssfsls.add(ssfs.getNemCode());
         }
 
-        Calendar c=Calendar.getInstance();
-        c.setTime(recordDate);
-        c.add(Calendar.SECOND,-1);
 
-        List<PointData> mxztlastvaluels = edosUtil.getHistMatrix(mxztls,c.getTime().getTime()/1000);
+
+
         List<PointData> mxztvaluels = edosUtil.getRealData(mxztls);
         List<PointData> ssfsvaluels = edosUtil.getRealData(ssfsls);
 
-        if(ssfsvaluels.size() == mxztlastvaluels.size() && ssfsvaluels.size() == mxztvaluels.size() && ssfsvaluels.size()==wtls.size())
+        if(ssfsvaluels.size() == mxztvaluels.size() && ssfsvaluels.size()==wtls.size())
         {
             for (int i=0;i<wtls.size();i++)
             {
-                ProBasicEquipment wt=wtls.get(i);
 
-                double lastStatus=StringUtils.round(mxztlastvaluels.get(i).getPointValueInDouble(),0);
+
+                ProBasicEquipment wt=wtls.get(i);
                 double status=StringUtils.round(mxztvaluels.get(i).getPointValueInDouble(),0);
-                PointData ssfspo=ssfsvaluels.get(i);
-                //     切入切出风速
-                if (lastStatus == StatusValue.DJ.getCode() && status == StatusValue.YX.getCode())
+                if(null !=statusRanngMap)
                 {
-                    ProEconInputOrOutputSpeed input = new ProEconInputOrOutputSpeed();
-
-                    input.setWindturbineId(wt.getId());
-                    input.setWindpowerstationId(wt.getWindpowerstationId());
-                    input.setProjectId(wt.getProjectId());
-                    input.setLineId(wt.getLineId());
-                    input.setRecordDate(new Date());
-                    input.setInputOrOutput(1);
+                    double lastStatus=StringUtils.round( statusRanngMap.get(wt.getId()),0);
 
+                    PointData ssfspo=ssfsvaluels.get(i);
+                    //     切入切出风速
+                    if (lastStatus == StatusValue.DJ.getCode() && status == StatusValue.YX.getCode())
+                    {
+                        ProEconInputOrOutputSpeed input = new ProEconInputOrOutputSpeed();
 
-                    input.setSpeed(StringUtils.round(ssfspo.getPointValueInDouble(),2));
+                        input.setWindturbineId(wt.getId());
+                        input.setWindpowerstationId(wt.getWindpowerstationId());
+                        input.setProjectId(wt.getProjectId());
+                        input.setLineId(wt.getLineId());
+                        input.setRecordDate(DateUtils.truncate(new Date()));
+                        input.setInputOrOutput(1);
 
 
-                    if(statusMap.containsKey(wt.getId()))
-                    {
-                        Map<String, ProEconInputOrOutputSpeed> map= statusMap.get(wt.getId());
+                        input.setSpeed(StringUtils.round(ssfspo.getPointValueInDouble(),2));
 
-                        if(!map.containsKey(String.valueOf(ssfspo.getPointTime())) )
-                        {
-                            ls.add(input);
-                        }
-                    }
 
-                }
-                else if (lastStatus == StatusValue.YX.getCode() && status== StatusValue.DJ.getCode())
-                {
-                    ProEconInputOrOutputSpeed input = new ProEconInputOrOutputSpeed();
-                    input.setWindturbineId(wt.getId());
-                    input.setWindpowerstationId(wt.getWindpowerstationId());
-                    input.setProjectId(wt.getProjectId());
-                    input.setLineId(wt.getLineId());
-                    input.setRecordDate(new Date());
-                    input.setInputOrOutput(0);
+//                    if(statusMap.containsKey(wt.getId()))
+//                    {
+//                        Map<String, ProEconInputOrOutputSpeed> map= statusMap.get(wt.getId());
+//
+//                        if(!map.containsKey(String.valueOf(ssfspo.getPointTime())) )
+//                        {
+//                            ls.add(input);
+//                        }
+//                    }else {
+//                        ls.add(input);
+//                    }
 
-                    input.setSpeed(StringUtils.round(ssfspo.getPointValueInDouble(),2));
+                        ls.add(input);
 
-                    if(statusMap.containsKey(wt.getId()))
+                    }
+                    else if (lastStatus == StatusValue.YX.getCode() && status== StatusValue.DJ.getCode())
                     {
-                        Map<String, ProEconInputOrOutputSpeed> map= statusMap.get(wt.getId());
+                        ProEconInputOrOutputSpeed input = new ProEconInputOrOutputSpeed();
+                        input.setWindturbineId(wt.getId());
+                        input.setWindpowerstationId(wt.getWindpowerstationId());
+                        input.setProjectId(wt.getProjectId());
+                        input.setLineId(wt.getLineId());
+                        input.setRecordDate(DateUtils.truncate(new Date()));
+                        input.setInputOrOutput(0);
+
+                        input.setSpeed(StringUtils.round(ssfspo.getPointValueInDouble(),2));
 
-                        if(!map.containsKey(String.valueOf(ssfspo.getPointTime())) )
-                        {
-                            ls.add(input);
-                        }
+//                    if(statusMap.containsKey(wt.getId()))
+//                    {
+//                        Map<String, ProEconInputOrOutputSpeed> map= statusMap.get(wt.getId());
+//
+//                        if(!map.containsKey(String.valueOf(ssfspo.getPointTime())) )
+//                        {
+//                            ls.add(input);
+//                        }
+//                    }else
+//                    {
+//                        ls.add(input);
+//                    }
+
+                        ls.add(input);
                     }
                 }
+
+
+                statusRanngMap.put(wt.getId(),status);
             }
         }
 //        for (ProBasicEquipment wt: wtls) {

+ 3 - 3
realtime/generationXK-service/src/main/java/com/gyee/generation/service/ShutdownnewService.java

@@ -176,7 +176,7 @@ public class ShutdownnewService {
             }
 
             if (wtStatusMap.containsKey(wtId)) {
-                if(wtId.equals("SXJ_KGDL_PTZ_F_WT_0022_EQ"))
+                if(wtId.equals("SXJ_KGDL_YF_F_WT_0043_EQ"))
                 {
                     System.out.println("");
                 }
@@ -216,7 +216,7 @@ public class ShutdownnewService {
                     {
                         finishShutdownEvent(updateProEconShutdownEventls, wtId, wtStatusMap, currentTime, shutdwonEvent);
                     }
-                    if (StringUtils.notEmp(shutdwonEvent2)  && shutdwonEvent.getStatusCode()!=wtPoint.getPointValueInDouble())
+                    if (StringUtils.notEmp(shutdwonEvent2)  && shutdwonEvent2.getStatusCode()!=wtPoint.getPointValueInDouble())
                     {
                         finishShutdownEvent2(updateProEconShutdownEvent2ls, wtId, wtStatusMap, currentTime, shutdwonEvent2);
                     }
@@ -237,7 +237,7 @@ public class ShutdownnewService {
                     {
                         finishShutdownEvent(updateProEconShutdownEventls, wtId, wtStatusMap, currentTime, shutdwonEvent);
                     }
-                    if (StringUtils.notEmp(shutdwonEvent2)  && shutdwonEvent.getStatusCode()!=wtPoint.getPointValueInDouble())
+                    if (StringUtils.notEmp(shutdwonEvent2)  && shutdwonEvent2.getStatusCode()!=wtPoint.getPointValueInDouble())
                     {
                         finishShutdownEvent2(updateProEconShutdownEvent2ls, wtId, wtStatusMap, currentTime, shutdwonEvent2);
                     }

+ 28 - 24
realtime/generationXK-service/src/test/java/com/gyee/generation/HealthTest.java

@@ -1,21 +1,25 @@
 package com.gyee.generation;
 
+import com.gyee.generation.model.auto.ProBasicPowerstation;
 import com.gyee.generation.service.InputOrOutPutService;
-import com.gyee.generation.service.ShutdownnewService;
+import com.gyee.generation.service.LimitEventnewService;
 import com.gyee.generation.util.DateUtils;
 import com.gyee.generation.util.SpringUtils;
 import org.springframework.boot.SpringApplication;
 
+import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Date;
+import java.util.List;
 
 public class HealthTest {
 
 
     public static void main(String[] args) throws Exception {
         SpringApplication.run(GenerationMain.class, args);
-
         InputOrOutPutService inputOrOutPutService= SpringUtils.getBean("inputOrOutPutService");
+
+        inputOrOutPutService.initialInputOrOutputSpeed();
         Calendar c = Calendar.getInstance();
         Date begin=null;
         Date end=null;
@@ -76,35 +80,35 @@ public class HealthTest {
 //
 //
 //
-        begin=new Date();
-        System.out.println("停机记录调度程序执行开始!。。。。。。");
-        ShutdownnewService shutdownnewService= SpringUtils.getBean("shutdownnewService");
-//       List<ProBasicPowerstation> wpls=new ArrayList<>();
-//
-//        ProBasicPowerstation wp=  CacheContext.wpmap.get("SXJ_KGDL_GJY_FDC_STA");
-//       wpls.add(wp);
-//        List<ProBasicEquipment> wtls=CacheContext.wpwtmap.get("SXJ_KGDL_GJY_FDC_STA");
-        shutdownnewService.execShutdown(c.getTime());
-        end=new Date();
-        System.out.println("执行用时"+ DateUtils.secondsDiff(begin,end) +"秒");
-        System.out.println("停机记录调度程序执行结束!。。。。。。");
-//
-//
 //        begin=new Date();
-//        System.out.println("限电停机记录调度程序执行开始!。。。。。。");
-//        LimitEventnewService limitEventnewService= SpringUtils.getBean("limitEventnewService");
-//
-//
-//       List<ProBasicPowerstation> wpls=new ArrayList<>();
-//
+//        System.out.println("停机记录调度程序执行开始!。。。。。。");
+//        ShutdownnewService shutdownnewService= SpringUtils.getBean("shutdownnewService");
+////       List<ProBasicPowerstation> wpls=new ArrayList<>();
+////
 ////        ProBasicPowerstation wp=  CacheContext.wpmap.get("SXJ_KGDL_GJY_FDC_STA");
 ////       wpls.add(wp);
 ////        List<ProBasicEquipment> wtls=CacheContext.wpwtmap.get("SXJ_KGDL_GJY_FDC_STA");
-//        limitEventnewService.execBrownouts(c.getTime());
+//        shutdownnewService.execShutdown(c.getTime());
 //        end=new Date();
 //        System.out.println("执行用时"+ DateUtils.secondsDiff(begin,end) +"秒");
-//        System.out.println("限电停机记录调度程序执行结束!。。。。。。");
+//        System.out.println("停机记录调度程序执行结束!。。。。。。");
+//
+//
+        begin=new Date();
+        System.out.println("限电停机记录调度程序执行开始!。。。。。。");
+        LimitEventnewService limitEventnewService= SpringUtils.getBean("limitEventnewService");
 //
+
+       List<ProBasicPowerstation> wpls=new ArrayList<>();
+
+//        ProBasicPowerstation wp=  CacheContext.wpmap.get("SXJ_KGDL_GJY_FDC_STA");
+//       wpls.add(wp);
+//        List<ProBasicEquipment> wtls=CacheContext.wpwtmap.get("SXJ_KGDL_GJY_FDC_STA");
+        limitEventnewService.execBrownouts(c.getTime());
+        end=new Date();
+        System.out.println("执行用时"+ DateUtils.secondsDiff(begin,end) +"秒");
+        System.out.println("限电停机记录调度程序执行结束!。。。。。。");
+
 //
 //        begin=new Date();
 //        System.out.println("曲线拟合调度程序执行开始!。。。。。。");