Jelajahi Sumber

增加故障诊断模块

chenminghua 3 tahun lalu
induk
melakukan
3ba38259c9

+ 6 - 0
gyee-sample-impala/src/main/java/com/gyee/impala/common/cache/InfoCache.java

@@ -8,6 +8,7 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
 
 import java.io.IOException;
+import java.util.HashMap;
 import java.util.Map;
 
 /**
@@ -24,6 +25,11 @@ public class InfoCache {
     private org.springframework.core.io.Resource algorithmIni;
 
     /**
+     * 故障报警缓存
+     */
+    public Map<String, FaultInfo> faultMap = new HashMap<>();
+
+    /**
      * 坐标信息
      */
     private String coordinates;

+ 6 - 4
gyee-sample-impala/src/main/java/com/gyee/impala/common/config/GyeeConfig.java

@@ -1,10 +1,11 @@
 package com.gyee.impala.common.config;
 
 import com.gyee.impala.common.util.JudeSystem;
+import lombok.Data;
 import org.springframework.boot.context.properties.ConfigurationProperties;
 import org.springframework.stereotype.Component;
 
-
+@Data
 @Component
 @ConfigurationProperties(prefix = "gyee")
 public class GyeeConfig {
@@ -37,6 +38,7 @@ public class GyeeConfig {
     private String diagnoseFileLinux;
 
 
+
     private String templatePath;
     private String diagnosePath;
     private String diagnoseFile;
@@ -66,7 +68,7 @@ public class GyeeConfig {
     }
 
     public String getTemplatePath() {
-        return templatePath = JudeSystem.isWindows() ? templatePathWindow : JudeSystem.isLinux() ? templatePathLinux : "";
+        return templatePath = JudeSystem.isWindows() ? getTemplatePathWindow() : JudeSystem.isLinux() ? getTemplatePathLinux() : "";
     }
 
     public void setTemplatePath(String templatePath) {
@@ -74,7 +76,7 @@ public class GyeeConfig {
     }
 
     public String getDiagnosePath() {
-        return JudeSystem.isWindows() ? diagnosePathWindow : JudeSystem.isLinux() ? diagnosePathWindow : "";
+        return JudeSystem.isWindows() ? getDiagnosePathWindow() : JudeSystem.isLinux() ? getDiagnosePathLinux() : "";
     }
 
     public void setDiagnosePath(String diagnosePath) {
@@ -82,7 +84,7 @@ public class GyeeConfig {
     }
 
     public String getDiagnoseFile() {
-        return diagnoseFile = JudeSystem.isWindows() ? diagnoseFileWindow : JudeSystem.isLinux() ? diagnoseFileLinux : "";
+        return diagnoseFile = JudeSystem.isWindows() ? getDiagnoseFileWindow() : JudeSystem.isLinux() ? getDiagnoseFileLinux() : "";
     }
 
     public void setDiagnoseFile(String diagnoseFile) {

+ 2 - 0
gyee-sample-impala/src/main/java/com/gyee/impala/common/spring/InitialRunner.java

@@ -5,6 +5,7 @@ import com.gyee.impala.model.master.*;
 import com.gyee.impala.service.master.*;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.CommandLineRunner;
+import org.springframework.core.annotation.Order;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
@@ -14,6 +15,7 @@ import java.util.*;
  * 服务启动前执行,进行全局变量初始化
  */
 @Component
+@Order(2)
 public class InitialRunner implements CommandLineRunner {
 
     @Resource

+ 12 - 1
gyee-sample-impala/src/main/java/com/gyee/impala/controller/diagnose/AutoFaultController.java

@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.gyee.impala.common.feign.RemoteServiceBuilder;
 import com.gyee.impala.common.result.JsonResult;
 import com.gyee.impala.common.result.ResultCode;
+import com.gyee.impala.common.util.DateUtil;
 import com.gyee.impala.model.custom.diagnose.DataInfo;
 import com.gyee.impala.model.custom.diagnose.FaultInfo;
 import com.gyee.impala.model.custom.diagnose.PointData;
@@ -73,7 +74,7 @@ public class AutoFaultController {
         calendar.add(Calendar.MINUTE, -1);
         dataInfo.setEndTs(String.valueOf(calendar.getTime().getTime()));
 
-        calendar.add(Calendar.HOUR_OF_DAY, -1);
+        calendar.add(Calendar.MINUTE, -2);
         dataInfo.setStartTs(String.valueOf(calendar.getTime().getTime()));
 
         dataInfo.setThingId(fi.getWindturbineId());
@@ -97,4 +98,14 @@ public class AutoFaultController {
         List<Diagnosereport> list = reportService.getAll(wtId, model, modelName, trainingTimes);
         return JsonResult.successData(ResultCode.SUCCESS, list);
     }
+
+    public static void main(String[] args){
+        Calendar calendar = Calendar.getInstance();
+        System.out.println(DateUtil.format(calendar.getTime(), DateUtil.YYYY_MM_DD_HH_MM_SS));
+
+        calendar.add(Calendar.MINUTE, -1);
+        System.out.println(DateUtil.format(calendar.getTime(), DateUtil.YYYY_MM_DD_HH_MM_SS));
+        calendar.add(Calendar.MINUTE, -10);
+        System.out.println(DateUtil.format(calendar.getTime(), DateUtil.YYYY_MM_DD_HH_MM_SS));
+    }
 }

+ 31 - 0
gyee-sample-impala/src/main/java/com/gyee/impala/model/custom/diagnose/FaultInfo.java

@@ -253,4 +253,35 @@ public class FaultInfo {
     public void setModelId(String modelId) {
         this.modelId = modelId;
     }
+
+    @Override
+    public String toString() {
+        return "FaultInfo{" +
+                "id=" + id +
+                ", faultTime='" + faultTime + '\'' +
+                ", messageType=" + messageType +
+                ", snapID=" + snapID +
+                ", confirmType=" + confirmType +
+                ", confirmTime='" + confirmTime + '\'' +
+                ", confirmPerson='" + confirmPerson + '\'' +
+                ", stationId='" + stationId + '\'' +
+                ", projectId='" + projectId + '\'' +
+                ", lineId='" + lineId + '\'' +
+                ", windturbineId='" + windturbineId + '\'' +
+                ", alertValue=" + alertValue +
+                ", rank='" + rank + '\'' +
+                ", category1='" + category1 + '\'' +
+                ", category2='" + category2 + '\'' +
+                ", category3='" + category3 + '\'' +
+                ", isOpened=" + isOpened +
+                ", lastUpdateTime='" + lastUpdateTime + '\'' +
+                ", lastUpdatePerson='" + lastUpdatePerson + '\'' +
+                ", stationName='" + stationName + '\'' +
+                ", projectName='" + projectName + '\'' +
+                ", lineName='" + lineName + '\'' +
+                ", windturbineName='" + windturbineName + '\'' +
+                ", alertText='" + alertText + '\'' +
+                ", modelId='" + modelId + '\'' +
+                '}';
+    }
 }

+ 4 - 0
gyee-sample-impala/src/main/java/com/gyee/impala/model/master/Casefaultalg.java

@@ -31,6 +31,10 @@ public class Casefaultalg extends Model<Casefaultalg> {
 
     private String windturbineid;
 
+    private String diagnosetype;
+
+    private String diagnosecode;
+
     private String faulttype;
 
     private String faultcode;

+ 3 - 0
gyee-sample-impala/src/main/java/com/gyee/impala/service/custom/diagnose/AutoCmdService.java

@@ -2,6 +2,7 @@ package com.gyee.impala.service.custom.diagnose;
 
 import com.gyee.impala.common.config.GyeeConfig;
 import com.gyee.impala.model.custom.diagnose.FaultInfo;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
@@ -9,6 +10,7 @@ import java.io.BufferedReader;
 import java.io.InputStreamReader;
 import java.util.Date;
 
+@Slf4j
 @Component
 public class AutoCmdService {
     /**
@@ -47,6 +49,7 @@ public class AutoCmdService {
             p.waitFor();
         } catch (Exception e) {
             e.printStackTrace();
+            log.error(e.getMessage());
         } finally {
             isComplete = true;
         }

+ 3 - 0
gyee-sample-impala/src/main/java/com/gyee/impala/service/custom/diagnose/CmdService.java

@@ -6,6 +6,7 @@ import com.gyee.impala.common.util.DateUtil;
 import com.gyee.impala.model.custom.diagnose.ExecuteInfo;
 import com.gyee.impala.model.master.diagnose.AlgorithmType;
 import com.gyee.impala.model.master.diagnose.Diagnosetrainhistory;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
@@ -19,6 +20,7 @@ import java.util.stream.Collectors;
  *
  * @author xysn
  */
+@Slf4j
 @Component
 public class CmdService {
     /**
@@ -76,6 +78,7 @@ public class CmdService {
             p.waitFor();
         } catch (Exception e) {
             e.printStackTrace();
+            log.error(e.getMessage());
         } finally {
             isComplete = true;
         }

+ 21 - 32
gyee-sample-impala/src/main/java/com/gyee/impala/service/custom/diagnose/FaultRefreshService.java

@@ -3,7 +3,9 @@ package com.gyee.impala.service.custom.diagnose;
 
 import com.gyee.impala.common.cache.InfoCache;
 import com.gyee.impala.common.feign.RemoteServiceBuilder;
+import com.gyee.impala.common.util.DateUtil;
 import com.gyee.impala.model.custom.diagnose.FaultInfo;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.boot.ApplicationArguments;
 import org.springframework.boot.ApplicationRunner;
 import org.springframework.core.annotation.Order;
@@ -23,6 +25,7 @@ import java.util.stream.Collectors;
  *
  * @author xysn
  */
+@Slf4j
 @Component
 @Order(1)
 public class FaultRefreshService implements ApplicationRunner {
@@ -32,22 +35,6 @@ public class FaultRefreshService implements ApplicationRunner {
 
     private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
     private Calendar calendar;
-    /**
-     * FaultInfo上次缓存
-     */
-    private List<FaultInfo> faultRecentold;
-    /**
-     * FaultInfo当前值
-     */
-    private List<FaultInfo> faultRecent;
-    /**
-     * FaultInfo当前值
-     */
-    private Map<Long, FaultInfo> faultRecentMap;
-    /**
-     * FaultInfo上次缓存
-     */
-    private Map<Long, FaultInfo> faultRecentMapold;
 
     @Resource
     private RemoteServiceBuilder shardingBuilder;
@@ -72,7 +59,7 @@ public class FaultRefreshService implements ApplicationRunner {
                 ex.printStackTrace();
             }
             try {
-                Thread.sleep(5000);
+                Thread.sleep(10 * 1000);
             } catch (Exception e) {
             }
         }
@@ -83,24 +70,26 @@ public class FaultRefreshService implements ApplicationRunner {
      */
     private void toRefresh() {
         calendar = Calendar.getInstance();
-        calendar.add(Calendar.HOUR_OF_DAY, -2);
+        calendar.add(Calendar.MINUTE, -10);
         String s = dateFormat.format(calendar.getTime());
-        if (faultRecentold == null || faultRecent == null) {
-            faultRecentold = shardingBuilder.sharding().getFaultRecent(s);
-            faultRecentold = faultRecentold.stream().filter(f -> f.getCategory1().equals("FJ")).collect(Collectors.toList());
-            faultRecentMapold = faultRecentold.stream().collect(Collectors.toMap(FaultInfo::getId, Function.identity(), (key1, key2) -> key2));
-            infoCache.setFaultRecent(faultRecentMapold);
-        } else {
-            faultRecentMapold = faultRecentMap;
-            infoCache.setFaultRecent(faultRecentMap);
-        }
-        faultRecent = shardingBuilder.sharding().getFaultRecent(s);
-        faultRecent = faultRecent.stream().filter(f -> f.getCategory1().equals("FJ")).collect(Collectors.toList());
-        faultRecentMap = faultRecent.stream().collect(Collectors.toMap(FaultInfo::getId, Function.identity(), (key1, key2) -> key2));
-        for (FaultInfo fi : faultRecentMap.values()) {
-            if (!faultRecentMapold.containsKey(fi.getId())) {
+
+        List<FaultInfo> faultRecent = shardingBuilder.sharding().getFaultRecent(s);
+        List<FaultInfo> collect = faultRecent.stream().filter(f -> f.getCategory1().equals("FJ") && f.getCategory2().equals("GZ")).collect(Collectors.toList());
+        Map<Long, FaultInfo> map = collect.stream().collect(Collectors.toMap(FaultInfo::getId, Function.identity(), (key1, key2) -> key2));
+        for (FaultInfo fi : map.values()) {
+            if (!infoCache.faultMap.containsKey(fi.getId()+fi.getFaultTime()+fi.getSnapID())) {
                 autoCmdService.exec(fi);
+                infoCache.faultMap.put(fi.getId()+fi.getFaultTime()+fi.getSnapID(), fi);
+                log.info(fi.toString());
             }
         }
     }
+
+    public static void main(String[] args){
+        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        Calendar calendar = Calendar.getInstance();
+        System.out.println(dateFormat.format(calendar.getTime()));
+        calendar.add(Calendar.MINUTE, -5);
+        System.out.println(dateFormat.format(calendar.getTime()));
+    }
 }

+ 4 - 1
gyee-sample-impala/src/main/java/com/gyee/impala/service/impl/master/CasefaultalgServiceImpl.java

@@ -63,7 +63,8 @@ public class CasefaultalgServiceImpl extends ServiceImpl<CasefaultalgMapper, Cas
                 .ge("starttime", st)
                 .le("endtime", et)
                 .eq("algcode", algcode)
-                .eq("confirm", confirm);
+                .eq("confirm", confirm)
+                .orderByDesc("starttime");
         try {
             return baseMapper.selectList(wrapper);
         } catch (Exception e) {
@@ -141,6 +142,8 @@ public class CasefaultalgServiceImpl extends ServiceImpl<CasefaultalgMapper, Cas
             row.addObject("faultid", obj.getFaultid());
             row.addObject("stationcn", obj.getStationcn());
             row.addObject("windturbineid", obj.getWindturbineid());
+            row.addObject("diagnosetype", obj.getDiagnosetype());
+            row.addObject("diagnosecode", obj.getDiagnosecode());
             row.addObject("faulttype", obj.getFaulttype());
             row.addObject("faultcode", obj.getFaultcode());
             row.addObject("algname", obj.getAlgname());

+ 4 - 1
gyee-sample-impala/src/main/resources/application.yaml

@@ -9,7 +9,7 @@ gyee:
   kudu-host: 192.168.1.65
   # 故障诊断脚本路径
   diagnose-path-window: d:/
-  diagnose-path-linux: /home/gyee/fault_dignosis/scripts/
+  diagnose-path-linux: /home/gyee/fault_digonsis/scripts/
   # 故障诊断保存数据文件的位置
   diagnose-file-window: D://diagnose//data
   diagnose-file-linux:  /diagnose/file/
@@ -93,3 +93,6 @@ logging:
   file:
     path: ./logs
 
+
+## 故障诊断部署  运行  source activate tensorflow-gpu   ##
+

+ 3 - 1
gyee-sample-impala/src/main/resources/mapper/master/CasefaultalgMapper.xml

@@ -9,6 +9,8 @@
         <result column="faultid" property="faultid" />
         <result column="stationcn" property="stationcn" />
         <result column="windturbineid" property="windturbineid" />
+        <result column="diagnosetype" property="diagnosetype" />
+        <result column="diagnosecode" property="diagnosecode" />
         <result column="faulttype" property="faulttype" />
         <result column="faultcode" property="faultcode" />
         <result column="algname" property="algname" />
@@ -28,7 +30,7 @@
 
     <!-- 通用查询结果列 -->
     <sql id="Base_Column_List">
-        id, tag, faultid, stationcn, windturbineid, faulttype, faultcode, algname, algcode, symptom, symptomcode, starttime, endtime, model, manufacturer, stationen, confirm, remark, category, createtime
+        id, tag, faultid, stationcn, windturbineid, diagnosetype, diagnosecode, faulttype, faultcode, algname, algcode, symptom, symptomcode, starttime, endtime, model, manufacturer, stationen, confirm, remark, category, createtime
     </sql>
 
 </mapper>