[monitor] 通知策略支持启用关闭

This commit is contained in:
tomsun28
2021-12-17 22:00:14 +08:00
parent d8150e93bc
commit 657b81f612
3 changed files with 15 additions and 3 deletions

View File

@@ -4,6 +4,8 @@ import com.usthe.manager.pojo.entity.NoticeRule;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import java.util.List;
/**
* NoticeRule数据库操作
* @author tom
@@ -11,4 +13,9 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
*/
public interface NoticeRuleDao extends JpaRepository<NoticeRule, Long>, JpaSpecificationExecutor<NoticeRule> {
/**
* 查询所有已启用的通知策略
* @return 通知策略
*/
List<NoticeRule> findNoticeRulesByEnableTrue();
}

View File

@@ -12,7 +12,6 @@ import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@@ -76,10 +75,10 @@ public class NoticeConfigServiceImpl implements NoticeConfigService {
@Override
public List<NoticeReceiver> getReceiverFilterRule(Alert alert) {
// todo 使用缓存
List<NoticeRule> rules = noticeRuleDao.findAll();
List<NoticeRule> rules = noticeRuleDao.findNoticeRulesByEnableTrue();
// todo 暂时规则是全部转发 后面实现更多匹配规则:告警状态选择 监控类型选择等
Set<Long> receiverIds = rules.stream()
.filter(item -> item.isFilterAll() && item.isEnable())
.filter(NoticeRule::isFilterAll)
.map(NoticeRule::getReceiverId)
.collect(Collectors.toSet());
return noticeReceiverDao.findAllById(receiverIds);

View File

@@ -234,6 +234,12 @@
</nz-select>
</nz-form-control>
</nz-form-item >
<nz-form-item>
<nz-form-label nzSpan="7" nzRequired="true" nzFor= "enable">是否启用</nz-form-label>
<nz-form-control nzSpan="8">
<nz-switch [(ngModel)]="rule.enable" name="enable" id="enable"></nz-switch>
</nz-form-control>
</nz-form-item >
</form>
</div>
</nz-modal>