AlertDao.java 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package com.usthe.alert.dao;
  2. import com.usthe.alert.dto.AlertPriorityNum;
  3. import com.usthe.common.entity.alerter.Alert;
  4. import org.springframework.data.jpa.repository.JpaRepository;
  5. import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
  6. import org.springframework.data.jpa.repository.Modifying;
  7. import org.springframework.data.jpa.repository.Query;
  8. import org.springframework.data.repository.query.Param;
  9. import java.util.List;
  10. import java.util.Set;
  11. /**
  12. * Alert Database Operations Alert数据库表操作
  13. *
  14. * @author tom
  15. * @date 2021/12/9 10:03
  16. */
  17. public interface AlertDao extends JpaRepository<Alert, Long>, JpaSpecificationExecutor<Alert> {
  18. /**
  19. * Delete alerts based on ID list 根据ID列表删除告警
  20. *
  21. * @param alertIds Alert ID List 告警ID列表
  22. */
  23. void deleteAlertsByIdIn(Set<Long> alertIds);
  24. /**
  25. * 根据告警ID-状态值 更新告警状态
  26. *
  27. * @param status 状态值
  28. * @param ids 告警ID列表
  29. */
  30. @Modifying
  31. @Query("update Alert set status = :status where id in :ids")
  32. void updateAlertsStatus(@Param(value = "status") Byte status, @Param(value = "ids") List<Long> ids);
  33. /**
  34. * Query the number of unhandled alarms of each alarm severity
  35. * 查询各个告警级别的未处理告警数量
  36. *
  37. * @return Number of alerts 告警数量
  38. */
  39. @Query("select new com.usthe.alert.dto.AlertPriorityNum(mo.priority, count(mo.id)) from Alert mo where mo.status = 0 group by mo.priority")
  40. List<AlertPriorityNum> findAlertPriorityNum();
  41. }