|
@@ -7,12 +7,14 @@ import com.gyee.impala.common.spring.InitialRunner;
|
|
|
import com.gyee.impala.common.util.DateUtil;
|
|
|
import com.gyee.impala.model.custom.AlertHistory;
|
|
|
import com.gyee.impala.model.master.Casewarningscada;
|
|
|
+import com.gyee.impala.model.master.diagnose.CustomDuration;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Slf4j
|
|
@@ -43,7 +45,7 @@ public class WarningService {
|
|
|
Map<String, List<String>> map = time.stream().collect(Collectors.groupingBy(item -> DateUtil.format(item, DateUtil.YYYY_MM_DD)));
|
|
|
try{
|
|
|
map.forEach((k, v) -> {
|
|
|
- if (v.size() < 10)
|
|
|
+ if (v.size() < 10 )
|
|
|
return;
|
|
|
String max = v.stream().max(String::compareTo).get();
|
|
|
/**提前30分钟**/
|
|
@@ -84,4 +86,118 @@ public class WarningService {
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过sharding获取时间内的报警数据
|
|
|
+ * @param category 报警分类 DI scada:windturbine 自定义:custom
|
|
|
+ * @param station
|
|
|
+ * @param wtId
|
|
|
+ * @param time
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<Object> resolveWarnc(String category, String station, String wtId, List<String> time){
|
|
|
+ if (StringUtils.isEmpty(station) || StringUtils.isEmpty(wtId) || time.size() == 0)
|
|
|
+ return null;
|
|
|
+
|
|
|
+ List<Object> result = new ArrayList<>();
|
|
|
+ List<Casewarningscada> list = new ArrayList<>();
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
+
|
|
|
+ /**将时间按照天分开**/
|
|
|
+ Map<String, List<String>> map = time.stream().collect(Collectors.groupingBy(item -> DateUtil.format(item, DateUtil.YYYY_MM_DD)));
|
|
|
+ try{
|
|
|
+ map.forEach((k, v) -> {
|
|
|
+ //if (v.size() < 10 ) return;
|
|
|
+
|
|
|
+ String max = v.stream().max(String::compareTo).get();
|
|
|
+ /**提前30分钟**/
|
|
|
+ String min = DateUtil.format(DateUtil.covertDateTimestamp(v.stream().min(String::compareTo).get()) - 30000, DateUtil.YYYY_MM_DD_HH_MM_SS);
|
|
|
+
|
|
|
+ cal.setTime(DateUtil.parseStrtoDate(k));
|
|
|
+ cal.set(Calendar.HOUR_OF_DAY, cal.getActualMinimum(Calendar.HOUR_OF_DAY));
|
|
|
+ String st = DateUtil.format(cal.getTime(), DateUtil.YYYY_MM_DD);
|
|
|
+ cal.add(cal.DATE,1);
|
|
|
+ String et = DateUtil.format(cal.getTime(), DateUtil.YYYY_MM_DD);
|
|
|
+ JSONObject data = remoteService.sharding().getAlertHistoryAll(category, st, et, station, wtId);
|
|
|
+ JSONArray records = data.getJSONArray("records");
|
|
|
+ List<AlertHistory> array = JSONArray.parseArray(records.toString(), AlertHistory.class);
|
|
|
+ array.stream().forEach(obj -> {
|
|
|
+ if (StringUtils.isNotEmpty(obj.getCategory1()) && StringUtils.isNotEmpty(obj.getCategory2())
|
|
|
+ && obj.getAlertTime().compareTo(min) > 0 && obj.getAlertTime().compareTo(max) < 0){
|
|
|
+ Casewarningscada warn = (Casewarningscada) new Casewarningscada().toData(obj);
|
|
|
+ warn.setWarntype(String.valueOf(obj.getMessageType()));
|
|
|
+ list.add(warn);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }catch (Exception e){
|
|
|
+ e.getStackTrace();
|
|
|
+ log.error(e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**按照报警类型分类**/
|
|
|
+ Map<String, List<Casewarningscada>> collect = list.stream().sorted(Comparator.comparing(Casewarningscada::getWarntime))
|
|
|
+ .filter(obj -> StringUtils.isNotEmpty(obj.getWarncode()))
|
|
|
+ .collect(Collectors.groupingBy(Casewarningscada::getWarncode));
|
|
|
+ collect.forEach((k, v) -> {
|
|
|
+ Map<String, Object> mp = new HashMap<>();
|
|
|
+ mp.put("label", InitialRunner.customWarnMap.containsKey(k.toUpperCase()) ? InitialRunner.customWarnMap.get(k.toUpperCase()) : "");
|
|
|
+ mp.put("value", k);
|
|
|
+
|
|
|
+ Map<String, List<Casewarningscada>> cwslmGbw = v.stream().collect(Collectors.groupingBy(Casewarningscada::getWarndes));
|
|
|
+
|
|
|
+ mp.put("children", getCountAndTime(cwslmGbw));
|
|
|
+ result.add(mp);
|
|
|
+ });
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算故障时间次数
|
|
|
+ * @param cwslm 按故障描述分类的故障
|
|
|
+ * @return 故障描述、持续时间、机型、次数
|
|
|
+ */
|
|
|
+ private List<CustomDuration> getCountAndTime(Map<String, List<Casewarningscada>> cwslm){
|
|
|
+
|
|
|
+ List<CustomDuration> customDurations=new ArrayList<>();
|
|
|
+
|
|
|
+ for (Map.Entry<String, List<Casewarningscada>> cwslmentry : cwslm.entrySet()) {
|
|
|
+
|
|
|
+ long duration = 0;
|
|
|
+ String time1 = cwslmentry.getValue().get(0).getWarntime();//触发时间
|
|
|
+ String time3 = "";//解除时间
|
|
|
+ int count = 0;
|
|
|
+
|
|
|
+ CustomDuration customDuration = new CustomDuration();
|
|
|
+
|
|
|
+ for (Casewarningscada casewarningscada : cwslmentry.getValue()) {
|
|
|
+
|
|
|
+ long durationtemp = 0;
|
|
|
+
|
|
|
+ if(casewarningscada.getWarntype().equals("1")){
|
|
|
+ time1=casewarningscada.getWarntime();
|
|
|
+ count++;
|
|
|
+ }else if(casewarningscada.getWarntype().equals("3")){
|
|
|
+ durationtemp = DateUtil.covertDateTimestamp(casewarningscada.getWarntime()) - DateUtil.covertDateTimestamp(time1);
|
|
|
+ time1=casewarningscada.getWarntime();
|
|
|
+
|
|
|
+ if(durationtemp<86400000){
|
|
|
+ duration += durationtemp;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ customDuration.setAlerttext(cwslmentry.getValue().get(0).getWarndes());
|
|
|
+ long dr = TimeUnit.MILLISECONDS.toMinutes(duration);
|
|
|
+ customDuration.setDuration(dr==0?1: dr);
|
|
|
+ customDuration.setCount(count);
|
|
|
+ customDuration.setModel(cwslmentry.getValue().get(0).getModel());
|
|
|
+
|
|
|
+ customDurations.add(customDuration);
|
|
|
+ }
|
|
|
+
|
|
|
+ return customDurations;
|
|
|
+ }
|
|
|
}
|