|
@@ -6,8 +6,10 @@ import com.gyee.impala.common.feign.RemoteServiceBuilder;
|
|
|
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.Casewarningcustom;
|
|
|
import com.gyee.impala.model.master.Casewarningscada;
|
|
|
import com.gyee.impala.model.master.diagnose.CustomDuration;
|
|
|
+import com.gyee.impala.service.master.CasewarningscadaService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -23,64 +25,45 @@ public class WarningService {
|
|
|
|
|
|
@Autowired
|
|
|
private RemoteServiceBuilder remoteService;
|
|
|
+ @Autowired
|
|
|
+ private CasewarningscadaService casewarningscadaService;
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * 通过sharding获取时间内的报警数据
|
|
|
+ * 通过sharding获取时间内的scada报警数据
|
|
|
+ *
|
|
|
* @param category 报警分类 DI scada:windturbine 自定义:custom
|
|
|
* @param station
|
|
|
* @param wtId
|
|
|
* @param time
|
|
|
* @return
|
|
|
*/
|
|
|
- public List<Object> resolveWarn(String category, String station, String wtId, List<String> time){
|
|
|
+ public List<Object> resolveWarn(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{
|
|
|
+ try {
|
|
|
map.forEach((k, v) -> {
|
|
|
- if (v.size() < 10 )
|
|
|
- return;
|
|
|
+ String min = v.stream().min(String::compareTo).get();
|
|
|
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().getAlertHistory(category, st, et, station, wtId, 1);
|
|
|
- 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);
|
|
|
- list.add(warn);
|
|
|
- }
|
|
|
- });
|
|
|
+ list.addAll(casewarningscadaService.getList(station, wtId, null, min, max));
|
|
|
});
|
|
|
- }catch (Exception e){
|
|
|
- e.getStackTrace();
|
|
|
+ } catch (Exception e) {
|
|
|
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));
|
|
|
+ Map<String, List<Casewarningscada>> collect = list.stream().collect(Collectors.groupingBy(Casewarningscada::getWarncode));
|
|
|
collect.forEach((k, v) -> {
|
|
|
Map<String, Object> mp = new HashMap<>();
|
|
|
- mp.put("label", InitialRunner.scadaWarnMap.containsKey(k.toUpperCase()) ? InitialRunner.scadaWarnMap.get(k.toUpperCase()) : "");
|
|
|
+ mp.put("warndes", InitialRunner.scadaWarnMap.containsKey(k.toUpperCase()) ? InitialRunner.scadaWarnMap.get(k.toUpperCase()) : "");
|
|
|
mp.put("value", k);
|
|
|
- mp.put("children", v);
|
|
|
+ if (v.size() > 0)
|
|
|
+ mp.put("children", v);
|
|
|
result.add(mp);
|
|
|
});
|
|
|
|
|
@@ -89,26 +72,57 @@ public class WarningService {
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * 通过sharding获取时间内的报警数据
|
|
|
+ * 通过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){
|
|
|
+ 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();
|
|
|
+ List<AlertHistory> list = getAlarmHistory(category, station, wtId, time);
|
|
|
|
|
|
+ /**按照报警类型分类**/
|
|
|
+ Map<String, List<AlertHistory>> collect = list.stream().sorted(Comparator.comparing(AlertHistory::getAlertTime))
|
|
|
+ .filter(obj -> StringUtils.isNotEmpty(obj.getCategory3()))
|
|
|
+ .collect(Collectors.groupingBy(AlertHistory::getCategory3));
|
|
|
+ collect.forEach((k, v) -> {
|
|
|
+ Map<String, Object> mp = new HashMap<>();
|
|
|
+ mp.put("alerttext", InitialRunner.customWarnMap.containsKey(k.toUpperCase()) ? InitialRunner.customWarnMap.get(k.toUpperCase()) : "");
|
|
|
+ mp.put("value", k);
|
|
|
+
|
|
|
+ Map<String, List<AlertHistory>> cwslmGbw = v.stream().collect(Collectors.groupingBy(AlertHistory::getAlertText));
|
|
|
+
|
|
|
+ mp.put("children", getCountAndTime(cwslmGbw));
|
|
|
+ result.add(mp);
|
|
|
+ });
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询所有区间内的自定义报警 将其转换为相应对象
|
|
|
+ *
|
|
|
+ * @param category
|
|
|
+ * @param station
|
|
|
+ * @param wtId
|
|
|
+ * @param time
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<AlertHistory> getAlarmHistory(String category, String station, String wtId, List<String> time) {
|
|
|
+ List<AlertHistory> 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{
|
|
|
+ try {
|
|
|
map.forEach((k, v) -> {
|
|
|
- //if (v.size() < 10 ) return;
|
|
|
+ if (v.size() < 5) return;
|
|
|
|
|
|
String max = v.stream().max(String::compareTo).get();
|
|
|
/**提前30分钟**/
|
|
@@ -117,83 +131,66 @@ public class WarningService {
|
|
|
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);
|
|
|
+ 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);
|
|
|
+ && obj.getAlertTime().compareTo(min) > 0 && obj.getAlertTime().compareTo(max) < 0) {
|
|
|
+ list.add(obj);
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
- }catch (Exception e){
|
|
|
- e.getStackTrace();
|
|
|
+ } catch (Exception e) {
|
|
|
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;
|
|
|
+ return list;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 计算故障时间次数
|
|
|
+ *
|
|
|
* @param cwslm 按故障描述分类的故障
|
|
|
* @return 故障描述、持续时间、机型、次数
|
|
|
*/
|
|
|
- private List<CustomDuration> getCountAndTime(Map<String, List<Casewarningscada>> cwslm){
|
|
|
+ private List<CustomDuration> getCountAndTime(Map<String, List<AlertHistory>> cwslm) {
|
|
|
|
|
|
- List<CustomDuration> customDurations=new ArrayList<>();
|
|
|
+ List<CustomDuration> customDurations = new ArrayList<>();
|
|
|
|
|
|
- for (Map.Entry<String, List<Casewarningscada>> cwslmentry : cwslm.entrySet()) {
|
|
|
+ for (Map.Entry<String, List<AlertHistory>> cwslmentry : cwslm.entrySet()) {
|
|
|
|
|
|
long duration = 0;
|
|
|
- String time1 = cwslmentry.getValue().get(0).getWarntime();//触发时间
|
|
|
- String time3 = "";//解除时间
|
|
|
+ String time1 = cwslmentry.getValue().get(0).getAlertTime();//触发时间
|
|
|
int count = 0;
|
|
|
|
|
|
CustomDuration customDuration = new CustomDuration();
|
|
|
|
|
|
- for (Casewarningscada casewarningscada : cwslmentry.getValue()) {
|
|
|
+ for (AlertHistory alert : cwslmentry.getValue()) {
|
|
|
|
|
|
long durationtemp = 0;
|
|
|
|
|
|
- if(casewarningscada.getWarntype().equals("1")){
|
|
|
- time1=casewarningscada.getWarntime();
|
|
|
+ if (alert.getMessageType() == 1) {
|
|
|
+ time1 = alert.getAlertTime();
|
|
|
count++;
|
|
|
- }else if(casewarningscada.getWarntype().equals("3")){
|
|
|
- durationtemp = DateUtil.covertDateTimestamp(casewarningscada.getWarntime()) - DateUtil.covertDateTimestamp(time1);
|
|
|
- time1=casewarningscada.getWarntime();
|
|
|
+ } else if (alert.getMessageType() == 3) {
|
|
|
+ durationtemp = DateUtil.covertDateTimestamp(alert.getAlertTime()) - DateUtil.covertDateTimestamp(time1);
|
|
|
+ time1 = alert.getAlertTime();
|
|
|
|
|
|
- if(durationtemp<86400000){
|
|
|
+ if (durationtemp < 86400000) {
|
|
|
duration += durationtemp;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
- customDuration.setAlerttext(cwslmentry.getValue().get(0).getWarndes());
|
|
|
+ customDuration.setAlerttext(cwslmentry.getValue().get(0).getAlertText());
|
|
|
long dr = TimeUnit.MILLISECONDS.toMinutes(duration);
|
|
|
- customDuration.setDuration(dr==0?1: dr);
|
|
|
+ customDuration.setDuration(dr == 0 ? 1 : dr);
|
|
|
customDuration.setCount(count);
|
|
|
- customDuration.setModel(cwslmentry.getValue().get(0).getModel());
|
|
|
+ customDuration.setModel(cwslmentry.getValue().get(0).getModelId());
|
|
|
|
|
|
customDurations.add(customDuration);
|
|
|
}
|