Browse Source

故障损失电量LosePowerTest更新

gfhd 2 years ago
parent
commit
45548f2e20

+ 1 - 1
src/main/java/com/gyee/frame/common/feign/RemoteServiceBuilder.java

@@ -35,7 +35,7 @@ public class RemoteServiceBuilder {
                 .decoder(new JacksonDecoder())
                 .options(new Request.Options(5000, 600000))
                 .retryer(new Retryer.Default(10000, 10000, 3))
-                .target(IAdapterService.class, "http://192.168.1.18:8075");
+                .target(IAdapterService.class, "http://192.168.10.18:8075");
     }
 
 }

+ 11 - 0
src/main/java/com/gyee/frame/mapper/auto/AlarmsnapMapper.java

@@ -2,13 +2,24 @@ package com.gyee.frame.mapper.auto;
 
 import com.gyee.frame.model.auto.Alarmsnap;
 import com.gyee.frame.model.auto.AlarmsnapExample;
+import com.gyee.frame.model.auto.FaultInfo;
 import com.gyee.frame.model.custom.TotalNumVo;
 import com.gyee.frame.model.custom.TotalNumsVo;
 import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
 
+import java.util.Date;
 import java.util.List;
 
 public interface AlarmsnapMapper {
+    @Select("SELECT h.id,h.faultTime,h.messageType,h.snapID,s.stationId,s.projectId,s.lineId,s.windturbineId,s.alertValue,s.rank," +
+            "s.category1,s.category2,s.category3,s.isOpened,s.stationName,s.windturbineName,s.alertText,s.modelId" +
+            "FROM faulthistory h left join faultsnap s on h.snapid = s.id" +
+            "WHERE h.messageType = 1 and s.WINDTURBINEID=#{windturbineid}" +
+            "  AND h.faultTime > #{starttime} AND h.faultTime < #{endtime} AND ROWNUM<#{row}" +
+            "order by h.faultTime desc")
+    List<FaultInfo>  getRecentFault(@Param("windturbineid") String wt,@Param("starttime") Date st,@Param("endtime") Date et,@Param("row") int r);
+
     /**
      * This method was generated by MyBatis Generator.
      * This method corresponds to the database table ALARMSNAP

+ 62 - 70
src/test/java/test/LosePowerTest.java

@@ -1,8 +1,14 @@
 package test;
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.gyee.SpringbootStart;
+import com.gyee.frame.common.domain.AjaxResult;
 import com.gyee.frame.common.feign.RemoteServiceBuilder;
+import com.gyee.frame.mapper.auto.AlarmsnapMapper;
 import com.gyee.frame.mapper.auto.WindTurbineTestingPointAi2Mapper;
+import com.gyee.frame.model.auto.FaultInfo;
 import com.gyee.frame.model.auto.WindTurbineTestingPointAi2;
 import com.gyee.frame.model.auto.WindTurbineTestingPointAi2Example;
 import com.gyee.frame.model.config.FilePathConfig;
@@ -38,7 +44,8 @@ import java.util.stream.Collectors;
 public class LosePowerTest {
 
     @Resource
-    private WindTurbineTestingPointAi2Mapper windTurbineTestingPointAi2Mapper;
+    private WindTurbineTestingPointAi2Mapper windTurbineTestingPointAi2Mapper;@Resource
+    private AlarmsnapMapper alarmsnapMapper;
     @Resource
     private RemoteServiceBuilder remoteServiceBuilder;
 
@@ -75,6 +82,7 @@ public class LosePowerTest {
         row0.createCell(6).setCellValue("故障时间(分钟)");
         row0.createCell(7).setCellValue("损失电量(kWh)");
         row0.createCell(8).setCellValue("机型");
+        row0.createCell(9).setCellValue("当时故障");
 
         int i = 1;
         for (WindTurbineTestingPointAi2 wttpai2 : faultCodes) {
@@ -91,7 +99,7 @@ public class LosePowerTest {
             long faultTime = historyRaw.get(0).getTs();
             short gzcs = 0;//故障次数
 
-            short k = 0;//是否连续,如果点是连续的2,故障次数算1次
+            short k = 0;//是否连续故障,如果点是连续的2,故障次数算1次
 
             short 当前风机是否有故障 = 0;
             //测点列表
@@ -99,48 +107,62 @@ public class LosePowerTest {
                 //点值
                 int doubleValue = (int) tsPointData.getDoubleValue();
                 if (doubleValue == 4) {
-                    k = 0;
                     continue;
                 } else if (doubleValue == 2) {
-                    long ts = tsPointData.getTs();
-                    duration = faultTime - ts;
-                    //超过2小时,毫秒
-                    int 两小时 = 2 * 60 * 60 * 1000;
-                    int 一小时 = 1 * 60 * 60 * 1000;
-                    int 半小时 = 1 * 30 * 60 * 1000;
-                    if (duration > 一小时) {
-                        当前风机是否有故障 = 1;
-                        if (k == 0) gzcs++;
+                    if(k==0){
+                        faultTime = tsPointData.getTs();
                         k = 1;
-                        //一个故障一行excel
-                        XSSFRow row = sheet.createRow(i);
-                        i++;
-
-                        durationlj += duration;
-                        String s = llfdlMap.get(wttpai2.getWindturbineid());
-                        Map<String, TsPointData> h1 = remoteServiceBuilder.ShardingService().getHistorySection(s, ts);
-                        Map<String, TsPointData> h2 = remoteServiceBuilder.ShardingService().getHistorySection(s, faultTime);
-                        double doubleValue2 = h2.get(s).getDoubleValue();
-                        double doubleValue1 = h1.get(s).getDoubleValue();
-                        ssdl = doubleValue2 - doubleValue1;
-
-                        row.createCell(0).setCellValue(i - 1);
-                        row.createCell(1).setCellValue(wttpai2.getWindpowerstationid());
-                        row.createCell(2).setCellValue(wttpai2.getWindturbineid());
-                        row.createCell(3).setCellValue(DateFormatUtils.format(ts, "yyyy-MM-dd HH:mm:ss"));
-                        row.createCell(4).setCellValue(DateFormatUtils.format(faultTime, "yyyy-MM-dd HH:mm:ss"));
-                        row.createCell(5).setCellValue(1);
-                        row.createCell(6).setCellValue(duration / 60000);
-                        row.createCell(7).setCellValue(ssdl);
-                        row.createCell(8).setCellValue(wttpai2.getModelid());
-                    } else {
-                        k = 0;
+                    }else {
+                        continue;
                     }
-                    faultTime = ts;
                 } else {
-                    faultTime = tsPointData.getTs();
-                    k = 0;
-                    continue;
+                    if(k==1){
+                        long ts = tsPointData.getTs();
+                        duration = faultTime - ts;
+                        //超过2小时,毫秒
+                        int 两小时 = 2 * 60 * 60 * 1000;
+                        int 一小时 = 1 * 60 * 60 * 1000;
+                        int 半小时 = 1 * 30 * 60 * 1000;
+                        if (duration > 一小时) {
+                            当前风机是否有故障 = 1;
+                            gzcs++;
+                            //一个故障一行excel
+                            XSSFRow row = sheet.createRow(i);
+                            i++;
+
+                            durationlj += duration;
+                            String s = llfdlMap.get(wttpai2.getWindturbineid());
+                            Map<String, TsPointData> h1 = remoteServiceBuilder.ShardingService().getHistorySection(s, ts);
+                            Map<String, TsPointData> h2 = remoteServiceBuilder.ShardingService().getHistorySection(s, faultTime);
+                            double doubleValue2 = h2.get(s).getDoubleValue();
+                            double doubleValue1 = h1.get(s).getDoubleValue();
+                            ssdl = doubleValue2 - doubleValue1;
+
+                            row.createCell(0).setCellValue(i - 1);
+                            row.createCell(1).setCellValue(wttpai2.getWindpowerstationid());
+                            row.createCell(2).setCellValue(wttpai2.getWindturbineid());
+                            row.createCell(3).setCellValue(DateFormatUtils.format(ts, "yyyy-MM-dd HH:mm:ss"));
+                            row.createCell(4).setCellValue(DateFormatUtils.format(faultTime, "yyyy-MM-dd HH:mm:ss"));
+                            row.createCell(5).setCellValue(1);
+                            row.createCell(6).setCellValue(duration / 60000);
+                            row.createCell(7).setCellValue(ssdl);
+                            row.createCell(8).setCellValue(wttpai2.getModelid());
+
+                            List<FaultInfo> recentFault = alarmsnapMapper.getRecentFault(wttpai2.getWindturbineid(), new Date(ts-1*60*60*1000), new Date(ts), 4);
+                            if(recentFault.size()==0){
+                                recentFault = alarmsnapMapper.getRecentFault(wttpai2.getWindturbineid(), new Date(ts-8*60*60*1000), new Date(ts), 2);
+                            }
+                            String dsgz = "";
+                            for (FaultInfo faultInfo : recentFault) {
+                                dsgz = dsgz + DateFormatUtils.format(faultInfo.getFaultTime(), "yyyy-MM-dd HH:mm:ss") + ":" + faultInfo.getAlertText() + "\n";
+                            }
+                            row.createCell(9).setCellValue(dsgz);
+                        }
+                        k = 0;
+                    }else {
+                        continue;
+                    }
+
                 }
             }
 
@@ -161,7 +183,7 @@ public class LosePowerTest {
         //通过输出流将workbook对象下载到磁盘
         FileOutputStream out = null;
         try {
-            out = new FileOutputStream("D:\\计算\\麻黄山风电场202210-1小时.xlsx");
+            out = new FileOutputStream("D:\\计算\\风电场202210-1小时.xlsx");
             workbook.write(out);
             out.flush();
             out.close();
@@ -444,37 +466,7 @@ public class LosePowerTest {
         for (TsPointData tsPointData : historyRaw) {
             //点值
             int doubleValue = (int) tsPointData.getDoubleValue();
-            if (doubleValue == 4) {
-                k = 0;
-                continue;
-            } else if (doubleValue == 2) {
-                long ts = tsPointData.getTs();
-                duration = faultTime - ts;
-                //超过2小时,毫秒
-                int 两小时 = 2 * 60 * 60 * 1000;
-                int 一小时 = 1 * 60 * 60 * 1000;
-                int 半小时 = 1 * 30 * 60 * 1000;
-                if (duration > 一小时) {
-                    if (k == 0) gzcs++;
-                    k = 1;
-
-                    durationlj += duration;
-                    String s = llfdlMap.get(wttpai2.getWindturbineid());
-                    Map<String, TsPointData> h1 = remoteServiceBuilder.ShardingService().getHistorySection(s, ts);
-                    Map<String, TsPointData> h2 = remoteServiceBuilder.ShardingService().getHistorySection(s, faultTime);
-                    double doubleValue2 = h2.get(s).getDoubleValue();
-                    double doubleValue1 = h1.get(s).getDoubleValue();
-                    ssdl = doubleValue2 - doubleValue1;
 
-                } else {
-                    k = 0;
-                }
-                faultTime = ts;
-            } else {
-                faultTime = tsPointData.getTs();
-                k = 0;
-                continue;
-            }
         }
 
         return "";