Ver código fonte

在线实时诊断脚本调用

chenminghua 2 anos atrás
pai
commit
18eed4f534

+ 1 - 0
gyee-sample-impala/src/main/java/com/gyee/impala/common/result/ResultCode.java

@@ -20,6 +20,7 @@ public enum ResultCode {
     ERROR_DATA(4006, "数据库操作失败"),
     ERROR_DATA_REPEAT(4007, "数据已存在"),
     ERROR_SQL(4008, "sql语法不正确"),
+    ERROR_MODEL(4006, "同场站不同机型至少启用一个模型"),
 
 
     /* 参数错误:1000~1999 */

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

@@ -147,7 +147,6 @@ public class InitialRunner implements CommandLineRunner {
         historyModelMap.clear();
         historyList.clear();
         List<Diagnosetrainhistory> historyList = diagnosetrainhistoryService.getListAll();
-        historyModelMap = historyList.stream().collect(Collectors.groupingBy(Diagnosetrainhistory::getModel));
-
+        historyModelMap = historyList.stream().filter(a -> a.isEnable()).collect(Collectors.groupingBy(Diagnosetrainhistory::getModel));
     }
 }

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

@@ -5,11 +5,14 @@ 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.spring.InitialRunner;
 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;
+import com.gyee.impala.model.master.diagnose.Diagnosepoint;
 import com.gyee.impala.model.master.diagnose.Diagnosereport;
+import com.gyee.impala.service.custom.diagnose.DataPointService;
 import com.gyee.impala.service.custom.diagnose.DataService;
 import com.gyee.impala.service.master.diagnose.DiagnosereportService;
 import org.springframework.web.bind.annotation.*;
@@ -30,6 +33,8 @@ public class AutoFaultController {
     @Resource
     private DataService dataService;
     @Resource
+    private DataPointService dataPointService;
+    @Resource
     private DiagnosereportService reportService;
     @Resource
     private RemoteServiceBuilder shardingBuilder;
@@ -46,7 +51,7 @@ public class AutoFaultController {
     }
 
     /**
-     * 获取故障原始数据
+     * 获取故障原始数据(is页面)
      * @param faultid
      * @return
      */
@@ -86,6 +91,39 @@ public class AutoFaultController {
     }
 
 
+    /**
+     * 获取故障原始数据(集成在报警配置系统里的)
+     * @param faultid
+     * @return
+     */
+    @GetMapping("/faultdata/{faultid}")
+    public JSONObject getFaultData(@PathVariable long faultid) {
+        List<FaultInfo> fis = shardingBuilder.sharding().getFaultHistoryById(faultid + "");
+        if (fis == null || fis.size() <= 0) {
+            return JsonResult.error(ResultCode.ERROR_DATA);
+        }
+
+        FaultInfo fi = fis.get(0);
+        String faultTime = fi.getFaultTime();
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(DateUtil.parseStrtoDate(faultTime));
+        DataInfo dataInfo = new DataInfo();
+        dataInfo.setId(fi.getId());
+        dataInfo.setFaultTime(String.valueOf(calendar.getTime().getTime()));
+        dataInfo.setEndTs(String.valueOf(calendar.getTime().getTime()));
+        calendar.add(Calendar.MINUTE, -2);
+        dataInfo.setStartTs(String.valueOf(calendar.getTime().getTime()));
+        dataInfo.setThingId(fi.getWindturbineId());
+        dataInfo.setModelId(fi.getModelId());
+        dataInfo.setStationId(fi.getStationId());
+
+        List<Diagnosepoint> uniforms = InitialRunner.mapPoint.get(fi.getStationId()).get(fi.getModelId());
+        dataPointService.formatUniformcode(uniforms);
+        Map<String, List<PointData>> data = dataPointService.getData(dataInfo);
+        return JsonResult.successData(ResultCode.SUCCESS, data);
+    }
+
+
     @PostMapping("/report/add")
     public JSONObject getHistory(@RequestBody Diagnosereport obj) {
         reportService.insertItem(obj);

+ 9 - 9
gyee-sample-impala/src/main/java/com/gyee/impala/controller/diagnose/DiagnoseFaultController.java

@@ -16,6 +16,9 @@ import java.util.List;
 import java.util.Optional;
 import java.util.stream.Collectors;
 
+/**
+ * 离线故障诊断
+ */
 @CrossOrigin
 @RestController
 @RequestMapping("/api/diagnosefault")
@@ -31,7 +34,7 @@ public class DiagnoseFaultController {
 
     @GetMapping("/offline")
     public JSONObject offline(@RequestParam(value = "station", required = false) String station,
-                              @RequestParam(value = "windturbindid", required = false) String wtId,
+                              @RequestParam(value = "windturbineid", required = false) String wtId,
                               @RequestParam(value = "id", required = false) String[] id,
                               @RequestParam(value = "faultid", required = false) Long[] faultid,
                               @RequestParam(value = "model", required = false) String[] model,
@@ -48,14 +51,11 @@ public class DiagnoseFaultController {
             List<Casefaultalg> array = new ArrayList<>();
             List<Casefaultalg> list = casefaultalgService.getAll(station, wtId, id, faultid, model, faultcode, st, et, algcode, false);
             List<FaultInfo> faults = remoteServiceBuilder.sharding().getFaultRecent(et);
-            List<FaultInfo> collect;
-            if (!StringUtils.isEmpty(wtId))
-                collect = faults.stream().filter(f -> f.getCategory1().equals("FJ")
-                        && f.getCategory2().equals("GZ")&& f.getWindturbineId().equals(wtId)).collect(Collectors.toList());
-            else
-                collect = faults.stream().filter(f -> f.getCategory1().equals("FJ")
-                        && f.getCategory2().equals("GZ")).collect(Collectors.toList());
-
+            List<FaultInfo> collect = faults.stream()
+                    .filter(f -> f.getCategory1().equals("FJ") && f.getCategory2().equals("GZ"))
+                    .filter(a -> StringUtils.isEmpty(station) || a.getStationId().equals(station))
+                    .filter(a -> StringUtils.isEmpty(wtId) || a.getWindturbineId().equals(wtId))
+                    .collect(Collectors.toList());
             for (int i = 0; i < collect.size(); i++){
                 FaultInfo info = collect.get(i);
                 if (list == null || list.size() == 0){

+ 3 - 7
gyee-sample-impala/src/main/java/com/gyee/impala/controller/diagnose/DiagnosetrainhistoryController.java

@@ -60,12 +60,8 @@ public class DiagnosetrainhistoryController {
      */
     @PostMapping("/editHistory")
     public JSONObject editDiagnosetrainhistory(@RequestBody String history) {
-        try {
-            Diagnosetrainhistory update = JSONObject.parseObject(history, Diagnosetrainhistory.class);
-            diagnosetrainhistoryService.editDiagnosetrainhistory(update);
-            return JsonResult.success(ResultCode.SUCCESS);
-        } catch (Exception e) {
-            return JsonResult.error(ResultCode.ERROR_DATA);
-        }
+        Diagnosetrainhistory update = JSONObject.parseObject(history, Diagnosetrainhistory.class);
+        diagnosetrainhistoryService.editDiagnosetrainhistory(update);
+        return JsonResult.success(ResultCode.SUCCESS);
     }
 }

+ 7 - 10
gyee-sample-impala/src/main/java/com/gyee/impala/controller/diagnose/TrainFileModeController.java

@@ -29,7 +29,7 @@ import java.util.stream.Collectors;
 
 
 /**
- * 文件方式训练模型
+ * 模型训练
  */
 @Slf4j
 @CrossOrigin
@@ -183,15 +183,12 @@ public class TrainFileModeController {
             data.setModelId(faults.get(i).getModel());
             data.setTag(faults.get(i).getFaultcode());
             data.setFaultTime(faults.get(i).getStarttime());
-            data.setStartTs(DateUtil.covertDateTimestamp(faults.get(i).getStarttime()).toString());
-            if (flag){
-                data.setEndTs(DateUtil.covertDateTimestamp(faults.get(i).getEndtime()).toString());
-            }else{
-                //查看前10条数据时结束时间往后推10s
-                cal.setTime(DateUtil.parseStrtoDate(faults.get(i).getStarttime(), DateUtil.DATE_TIME_PATTERN));
-                cal.add(Calendar.SECOND, 10);
-                data.setEndTs(cal.getTimeInMillis() + "");
-            }
+
+            cal.setTime(DateUtil.parseStrtoDate(faults.get(i).getStarttime(), DateUtil.YYYY_MM_DD_HH_MM_SS));
+            cal.add(Calendar.MINUTE, -30);
+            data.setStartTs(cal.getTimeInMillis() + "");
+            cal.add(Calendar.MINUTE, 30);
+            data.setEndTs(cal.getTimeInMillis() + "");
             dataInfos[i] = data;
         }
         executeInfo.setDataInfos(dataInfos);

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

@@ -1,7 +1,9 @@
 package com.gyee.impala.service.custom.diagnose;
 
 import com.gyee.impala.common.config.GyeeConfig;
+import com.gyee.impala.common.spring.InitialRunner;
 import com.gyee.impala.model.custom.diagnose.FaultInfo;
+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;
@@ -9,6 +11,7 @@ import org.springframework.stereotype.Component;
 import java.io.BufferedReader;
 import java.io.InputStreamReader;
 import java.util.Date;
+import java.util.List;
 
 @Slf4j
 @Component
@@ -30,10 +33,11 @@ public class AutoCmdService {
         System.out.println(new Date() + "开始执行脚本...");
         Process p;
         String cmdPath = gyeeConfig.getDiagnosePath();
+        List<Diagnosetrainhistory> ls = InitialRunner.historyModelMap.get(fi.getStationId() + "_" + fi.getModelId());
         try {
-            String[] cmd = {"/bin/sh", "-c", "python " + cmdPath + "ANNs_predict" + fi.getStationId() + "_" + fi.getModelId() + ".py " + fi.getId()};
-            //String order = "cmd /c python " + cmdPath + "ANNs_predict" + fi.getStationId() + "_" + fi.getModelId() + ".py " + fi.getId();
-            System.out.println(cmd[0] + " " + cmd[1] + " " + cmd[2]);
+            Diagnosetrainhistory history = ls.get(0);
+            String[] cmd = {"/bin/sh", "-c", "python " + cmdPath + "predict_route.py " + history.getCode() + " " + fi.getId()};
+            //String[] cmd = {"/bin/sh", "-c", "python " + cmdPath + "ANNs_predict" + fi.getStationId() + "_" + fi.getModelId() + ".py " + fi.getId()};
             p = Runtime.getRuntime().exec(cmd);
             BufferedReader bri = new BufferedReader(new InputStreamReader(p.getInputStream()));
             BufferedReader bre = new BufferedReader(new InputStreamReader(p.getErrorStream()));

Diferenças do arquivo suprimidas por serem muito extensas
+ 14 - 5
gyee-sample-impala/src/main/java/com/gyee/impala/service/custom/diagnose/DataPointService.java


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

@@ -100,7 +100,7 @@ public class CasefaultServiceImpl extends ServiceImpl<CasefaultMapper, Casefault
         try{
             return baseMapper.executeQuery(sql);
         } catch (Exception e){
-            throw new CustomException(e);
+            throw new CustomException(ResultCode.ERROR_SQL);
         }
     }
 

+ 8 - 10
gyee-sample-impala/src/main/java/com/gyee/impala/service/impl/master/diagnose/DiagnosetrainhistoryServiceImpl.java

@@ -90,18 +90,16 @@ public class DiagnosetrainhistoryServiceImpl extends ServiceImpl<Diagnosetrainhi
     @Override
     public void editDiagnosetrainhistory(Diagnosetrainhistory history) {
         try {
-            List<Diagnosetrainhistory> historyByModel = getHistoryByModel("", history.getModel());
-            if (1 == historyByModel.size() && historyByModel.get(0).getId().equals(history.getId()) && !history.isEnable()) {
-                throw new CustomException(ResultCode.ERROR_DATA);
+            List<Diagnosetrainhistory> list = getList(true,"","", history.getModel());
+            if (list.size() <= 1 && !history.isEnable()) {
+                throw new CustomException(ResultCode.ERROR_MODEL);
             }
-            if (null != historyByModel && historyByModel.size() > 0 && history.isEnable()) {
-                for (Diagnosetrainhistory h : historyByModel) {
-                    if (h.getId().equals(history.getId())) {
-                        continue;
-                    }
-                    h.setEnable(false);
-                    baseMapper.updateById(h);
+            for (Diagnosetrainhistory h : list) {
+                if (h.getId().equals(history.getId())) {
+                    continue;
                 }
+                h.setEnable(false);
+                baseMapper.updateById(h);
             }
             baseMapper.updateById(history);
             initialRunner.cacheHistory();