|
@@ -0,0 +1,126 @@
|
|
|
|
+package com.gyee.impala.controller.diagnose;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
+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.ExecuteInfo;
|
|
|
|
+import com.gyee.impala.model.master.Casefault;
|
|
|
|
+import com.gyee.impala.model.master.diagnose.Diagnosepoint;
|
|
|
|
+import com.gyee.impala.service.custom.diagnose.DataPointService;
|
|
|
|
+import com.gyee.impala.service.custom.diagnose.TrainFaultDiagnoseService;;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
+
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
+import java.util.Calendar;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * 故障诊断
|
|
|
|
+ */
|
|
|
|
+@Slf4j
|
|
|
|
+@CrossOrigin
|
|
|
|
+@RestController
|
|
|
|
+@RequestMapping("/api/diagnose")
|
|
|
|
+public class TrainFaultDiagnoseController {
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private TrainFaultDiagnoseService trainFaultDiagnoseService;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private ExecuteInfo executeInfo;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private DataPointService dataService;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 线程池
|
|
|
|
+ */
|
|
|
|
+ @Resource
|
|
|
|
+ private ThreadPoolTaskExecutor taskExecutor;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private static final Object locker = new Object();
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /** 开始诊断 查询 golden 所有原始数据
|
|
|
|
+ * flag ture: 所有数据 ;false: 前10条数据
|
|
|
|
+ * **/
|
|
|
|
+ @PostMapping("/pointdata")
|
|
|
|
+ public JSONObject getPointData(@RequestBody JSONObject json){
|
|
|
|
+ if (json == null)
|
|
|
|
+ return JsonResult.error(ResultCode.PARAM_IS_BLANK);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ log.info("进入诊断程序");
|
|
|
|
+ boolean flag = json.getBooleanValue("flag");
|
|
|
|
+ List<Diagnosepoint> points = JSONObject.parseArray(json.getJSONArray("points").toString(), Diagnosepoint.class);
|
|
|
|
+ List<Casefault> faults = JSONObject.parseArray(json.getJSONArray("faults").toString(), Casefault.class);
|
|
|
|
+
|
|
|
|
+ /** 组装数据 删除添加的故障类型**/
|
|
|
|
+ dataService.formatUniformcode(points.stream().filter(a -> !a.getUniformcode().equals("faulttype")).collect(Collectors.toList()));
|
|
|
|
+ executeInfo = new ExecuteInfo();
|
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
|
+ DataInfo[] dataInfos = new DataInfo[faults.size()];
|
|
|
|
+ for (int i = 0; i < faults.size(); i++){
|
|
|
|
+ DataInfo data = new DataInfo();
|
|
|
|
+ data.setId(Long.valueOf(faults.get(i).getId()));
|
|
|
|
+ data.setStationId(faults.get(i).getStationen());
|
|
|
|
+ data.setThingId(faults.get(i).getWindturbineid());
|
|
|
|
+ data.setModelId(faults.get(i).getModel());
|
|
|
|
+ data.setTag(faults.get(i).getFaultcode());
|
|
|
|
+ data.setFaultTime(faults.get(i).getStarttime());
|
|
|
|
+
|
|
|
|
+ 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);
|
|
|
|
+ if (flag){
|
|
|
|
+ if (!trainFaultDiagnoseService.isComplete()) {
|
|
|
|
+ return JsonResult.error(4000, "已有正在诊断的故障模型...");
|
|
|
|
+ }
|
|
|
|
+ synchronized (locker) {
|
|
|
|
+ taskExecutor.submit(this::execute);
|
|
|
|
+ }
|
|
|
|
+ return JsonResult.success(ResultCode.SUCCESS);
|
|
|
|
+ }else {
|
|
|
|
+ Map<String, Object> mp = dataService.getFormData(executeInfo);
|
|
|
|
+ return JsonResult.successData(ResultCode.SUCCESS, mp);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 调用执行脚本
|
|
|
|
+ */
|
|
|
|
+ private void execute() {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|