代码调整

This commit is contained in:
tiger_zhou 2023-10-30 14:25:57 +08:00
parent 853c41e999
commit 8ffbb32188
5 changed files with 46 additions and 10 deletions

View File

@ -2,6 +2,8 @@ package club.joylink.xiannccda.alert.core.relieve;
import club.joylink.xiannccda.alert.core.AlertDeviceType; import club.joylink.xiannccda.alert.core.AlertDeviceType;
import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType; import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType;
import lombok.Getter;
import lombok.NoArgsConstructor;
public interface RelieveFilter { public interface RelieveFilter {
@ -9,15 +11,31 @@ public interface RelieveFilter {
int filterIndex(); int filterIndex();
boolean hasNextFilter();
/** /**
* @param deviceType 设备类型 * @param deviceType 设备类型
* @param alertType 告警类型 * @param alertType 告警类型
* @param deviceLayoutId 设备地图id * @param deviceLayoutId 设备地图id
* @return * @return
*/ */
boolean isMatch(Integer lineId, AlertDeviceType deviceType, AlertType alertType, String deviceLayoutId); MatcherResult isMatch(Integer lineId, AlertDeviceType deviceType, AlertType alertType, String deviceLayoutId);
enum FilterType { enum FilterType {
TIME_TYPE, DEVICE_TYPE TIME_TYPE, DEVICE_TYPE
} }
@Getter
@NoArgsConstructor
class MatcherResult {
boolean result;
//是否需要下个过滤器
boolean nextFilter;
public MatcherResult(boolean result, boolean nextFilter) {
this.result = result;
this.nextFilter = nextFilter;
}
}
} }

View File

@ -1,6 +1,7 @@
package club.joylink.xiannccda.alert.core.relieve; package club.joylink.xiannccda.alert.core.relieve;
import club.joylink.xiannccda.alert.core.AlertDeviceType; 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.constants.SystemContext;
import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType; import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType;
import com.google.common.collect.Lists; 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) { public boolean relieveAlertMatch(Integer lineId, AlertDeviceType deviceType, AlertType alertType, String deviceLayoutId) {
for (RelieveFilter filter : RELIEVE_FILTER_LIST) { for (RelieveFilter filter : RELIEVE_FILTER_LIST) {
if (Objects.equals(false, filter.isMatch(lineId, deviceType, alertType, deviceLayoutId))) { MatcherResult result = filter.isMatch(lineId, deviceType, alertType, deviceLayoutId);
return false; if (result.nextFilter) {
if (Objects.equals(false, result.result)) {
return false;
}
} else {
return result.result;
} }
} }
return true; return true;

View File

@ -32,12 +32,18 @@ public class DeviceFilter implements RelieveFilter {
} }
@Override @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()); DataService dataService = this.dataManager.getDataSourceService(this.filterType());
List<RelieveDeviceVO> timeVOList = dataService.query(lineId, deviceType, alertType, RelieveDeviceVO.class); List<RelieveDeviceVO> timeVOList = dataService.query(lineId, deviceType, alertType, RelieveDeviceVO.class);
if (CollectionUtils.isEmpty(timeVOList)) { 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());
} }
} }

View File

@ -33,14 +33,20 @@ public class TimeFilter implements RelieveFilter {
} }
@Override @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(); LocalDateTime localDateTime = LocalDateTime.now();
Integer currentHour = localDateTime.getHour(); Integer currentHour = localDateTime.getHour();
DataService dataService = this.dataManager.getDataSourceService(this.filterType()); DataService dataService = this.dataManager.getDataSourceService(this.filterType());
List<RelieveTimeVO> timeVOList = dataService.query(lineId, deviceType, alertType, RelieveTimeVO.class); List<RelieveTimeVO> timeVOList = dataService.query(lineId, deviceType, alertType, RelieveTimeVO.class);
if (CollectionUtils.isEmpty(timeVOList)) { 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