代码调整
This commit is contained in:
parent
853c41e999
commit
8ffbb32188
@ -2,6 +2,8 @@ package club.joylink.xiannccda.alert.core.relieve;
|
||||
|
||||
import club.joylink.xiannccda.alert.core.AlertDeviceType;
|
||||
import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
public interface RelieveFilter {
|
||||
|
||||
@ -9,15 +11,31 @@ public interface RelieveFilter {
|
||||
|
||||
int filterIndex();
|
||||
|
||||
boolean hasNextFilter();
|
||||
|
||||
/**
|
||||
* @param deviceType 设备类型
|
||||
* @param alertType 告警类型
|
||||
* @param deviceLayoutId 设备地图id
|
||||
* @return
|
||||
*/
|
||||
boolean isMatch(Integer lineId, AlertDeviceType deviceType, AlertType alertType, String deviceLayoutId);
|
||||
MatcherResult isMatch(Integer lineId, AlertDeviceType deviceType, AlertType alertType, String deviceLayoutId);
|
||||
|
||||
enum FilterType {
|
||||
TIME_TYPE, DEVICE_TYPE
|
||||
}
|
||||
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
class MatcherResult {
|
||||
|
||||
boolean result;
|
||||
//是否需要下个过滤器
|
||||
boolean nextFilter;
|
||||
|
||||
public MatcherResult(boolean result, boolean nextFilter) {
|
||||
this.result = result;
|
||||
this.nextFilter = nextFilter;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package club.joylink.xiannccda.alert.core.relieve;
|
||||
|
||||
import club.joylink.xiannccda.alert.core.AlertDeviceType;
|
||||
import club.joylink.xiannccda.alert.core.relieve.RelieveFilter.MatcherResult;
|
||||
import club.joylink.xiannccda.constants.SystemContext;
|
||||
import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType;
|
||||
import com.google.common.collect.Lists;
|
||||
@ -30,8 +31,13 @@ public class RelieveFilterManager implements ApplicationRunner {
|
||||
*/
|
||||
public boolean relieveAlertMatch(Integer lineId, AlertDeviceType deviceType, AlertType alertType, String deviceLayoutId) {
|
||||
for (RelieveFilter filter : RELIEVE_FILTER_LIST) {
|
||||
if (Objects.equals(false, filter.isMatch(lineId, deviceType, alertType, deviceLayoutId))) {
|
||||
return false;
|
||||
MatcherResult result = filter.isMatch(lineId, deviceType, alertType, deviceLayoutId);
|
||||
if (result.nextFilter) {
|
||||
if (Objects.equals(false, result.result)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return result.result;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
@ -32,12 +32,18 @@ public class DeviceFilter implements RelieveFilter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMatch(Integer lineId, AlertDeviceType deviceType, AlertType alertType, String deviceLayoutId) {
|
||||
public boolean hasNextFilter() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MatcherResult isMatch(Integer lineId, AlertDeviceType deviceType, AlertType alertType, String deviceLayoutId) {
|
||||
DataService dataService = this.dataManager.getDataSourceService(this.filterType());
|
||||
List<RelieveDeviceVO> timeVOList = dataService.query(lineId, deviceType, alertType, RelieveDeviceVO.class);
|
||||
if (CollectionUtils.isEmpty(timeVOList)) {
|
||||
return false;
|
||||
return new MatcherResult(false, this.hasNextFilter());
|
||||
}
|
||||
return timeVOList.stream().anyMatch(d -> d.isExist(deviceLayoutId));
|
||||
boolean b = timeVOList.stream().anyMatch(d -> d.isExist(deviceLayoutId));
|
||||
return new MatcherResult(b, this.hasNextFilter());
|
||||
}
|
||||
}
|
||||
|
@ -33,14 +33,20 @@ public class TimeFilter implements RelieveFilter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMatch(Integer lineId, AlertDeviceType deviceType, AlertType alertType, String deviceLayoutId) {
|
||||
public boolean hasNextFilter() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MatcherResult isMatch(Integer lineId, AlertDeviceType deviceType, AlertType alertType, String deviceLayoutId) {
|
||||
LocalDateTime localDateTime = LocalDateTime.now();
|
||||
Integer currentHour = localDateTime.getHour();
|
||||
DataService dataService = this.dataManager.getDataSourceService(this.filterType());
|
||||
List<RelieveTimeVO> timeVOList = dataService.query(lineId, deviceType, alertType, RelieveTimeVO.class);
|
||||
if (CollectionUtils.isEmpty(timeVOList)) {
|
||||
return false;
|
||||
return new MatcherResult(false, false);
|
||||
}
|
||||
return timeVOList.stream().anyMatch(d -> currentHour >= d.getStartHour() && currentHour <= d.getEndHour());
|
||||
boolean b = timeVOList.stream().anyMatch(d -> currentHour >= d.getStartHour() && currentHour <= d.getEndHour());
|
||||
return new MatcherResult(b, this.hasNextFilter());
|
||||
}
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit a9017ecfb22febc327a7b761a269c4a06749925b
|
||||
Subproject commit 226023c351e10e7e07cc7c48e1dbde661091b6b5
|
Loading…
Reference in New Issue
Block a user