From 253e8d85e53a58f67298c5455d8d3e54ff0dcd28 Mon Sep 17 00:00:00 2001 From: tomsun28 Date: Mon, 13 Dec 2021 14:50:23 +0800 Subject: [PATCH] =?UTF-8?q?[alerter]=20=E5=91=8A=E8=AD=A6=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E6=89=B9=E9=87=8F=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../alert/controller/AlertDefinesController.java | 2 +- .../usthe/alert/controller/AlertsController.java | 15 +++++++++++++++ .../main/java/com/usthe/alert/dao/AlertDao.java | 8 ++++++++ .../java/com/usthe/alert/dao/AlertDefineDao.java | 2 +- .../com/usthe/alert/service/AlertService.java | 8 ++++++++ .../service/impl/AlertDefineServiceImpl.java | 2 +- .../alert/service/impl/AlertServiceImpl.java | 7 +++++++ 7 files changed, 41 insertions(+), 3 deletions(-) diff --git a/alerter/src/main/java/com/usthe/alert/controller/AlertDefinesController.java b/alerter/src/main/java/com/usthe/alert/controller/AlertDefinesController.java index 0d79fe5..fe0a1a2 100644 --- a/alerter/src/main/java/com/usthe/alert/controller/AlertDefinesController.java +++ b/alerter/src/main/java/com/usthe/alert/controller/AlertDefinesController.java @@ -72,7 +72,7 @@ public class AlertDefinesController { } @DeleteMapping - @ApiOperation(value = "批量删除告警定义", notes = "根据告警定义ID列表批量删除监控项") + @ApiOperation(value = "批量删除告警定义", notes = "根据告警定义ID列表批量删除告警定义") public ResponseEntity> deleteAlertDefines( @ApiParam(value = "告警定义IDs", example = "6565463543") @RequestParam(required = false) List ids ) { diff --git a/alerter/src/main/java/com/usthe/alert/controller/AlertsController.java b/alerter/src/main/java/com/usthe/alert/controller/AlertsController.java index 8a0ff82..46930f8 100644 --- a/alerter/src/main/java/com/usthe/alert/controller/AlertsController.java +++ b/alerter/src/main/java/com/usthe/alert/controller/AlertsController.java @@ -12,13 +12,16 @@ import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Sort; import org.springframework.data.jpa.domain.Specification; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import javax.persistence.Id; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.Predicate; +import java.util.HashSet; import java.util.List; import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; @@ -83,4 +86,16 @@ public class AlertsController { return ResponseEntity.ok(message); } + @DeleteMapping + @ApiOperation(value = "批量删除告警", notes = "根据告警ID列表批量删除告警") + public ResponseEntity> deleteAlertDefines( + @ApiParam(value = "告警IDs", example = "6565463543") @RequestParam(required = false) List ids + ) { + if (ids != null && !ids.isEmpty()) { + alertService.deleteAlerts(new HashSet<>(ids)); + } + Message message = new Message<>(); + return ResponseEntity.ok(message); + } + } diff --git a/alerter/src/main/java/com/usthe/alert/dao/AlertDao.java b/alerter/src/main/java/com/usthe/alert/dao/AlertDao.java index 3a80e99..d17f055 100644 --- a/alerter/src/main/java/com/usthe/alert/dao/AlertDao.java +++ b/alerter/src/main/java/com/usthe/alert/dao/AlertDao.java @@ -4,6 +4,8 @@ import com.usthe.alert.pojo.entity.Alert; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import java.util.Set; + /** * Alert 数据库操作 * @author tom @@ -11,4 +13,10 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor; */ public interface AlertDao extends JpaRepository, JpaSpecificationExecutor { + /** + * 根据ID列表删除告警 + * @param alertIds 告警ID列表 + */ + void deleteAlertsByIdIn(Set alertIds); + } diff --git a/alerter/src/main/java/com/usthe/alert/dao/AlertDefineDao.java b/alerter/src/main/java/com/usthe/alert/dao/AlertDefineDao.java index e755bb6..e2cd779 100644 --- a/alerter/src/main/java/com/usthe/alert/dao/AlertDefineDao.java +++ b/alerter/src/main/java/com/usthe/alert/dao/AlertDefineDao.java @@ -20,7 +20,7 @@ public interface AlertDefineDao extends JpaRepository, JpaSpe * 根据ID列表删除告警定义 * @param alertDefineIds 告警定义ID列表 */ - void deleteAllByIdIn(Set alertDefineIds); + void deleteAlertDefinesByIdIn(Set alertDefineIds); /** * 根据监控ID查询与之关联的告警定义列表 diff --git a/alerter/src/main/java/com/usthe/alert/service/AlertService.java b/alerter/src/main/java/com/usthe/alert/service/AlertService.java index 23a1040..aa2e9bb 100644 --- a/alerter/src/main/java/com/usthe/alert/service/AlertService.java +++ b/alerter/src/main/java/com/usthe/alert/service/AlertService.java @@ -5,6 +5,8 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.jpa.domain.Specification; +import java.util.HashSet; + /** * 告警信息管理接口 * @author tom @@ -26,4 +28,10 @@ public interface AlertService { * @return 查询结果 */ Page getAlerts(Specification specification, PageRequest pageRequest); + + /** + * 根据告警ID列表批量删除告警 + * @param ids 告警IDs + */ + void deleteAlerts(HashSet ids); } diff --git a/alerter/src/main/java/com/usthe/alert/service/impl/AlertDefineServiceImpl.java b/alerter/src/main/java/com/usthe/alert/service/impl/AlertDefineServiceImpl.java index a819e56..11ec856 100644 --- a/alerter/src/main/java/com/usthe/alert/service/impl/AlertDefineServiceImpl.java +++ b/alerter/src/main/java/com/usthe/alert/service/impl/AlertDefineServiceImpl.java @@ -64,7 +64,7 @@ public class AlertDefineServiceImpl implements AlertDefineService { @Override public void deleteAlertDefines(Set alertIds) throws RuntimeException { - alertDefineDao.deleteAllByIdIn(alertIds); + alertDefineDao.deleteAlertDefinesByIdIn(alertIds); } @Override diff --git a/alerter/src/main/java/com/usthe/alert/service/impl/AlertServiceImpl.java b/alerter/src/main/java/com/usthe/alert/service/impl/AlertServiceImpl.java index 472ca57..9f5cd80 100644 --- a/alerter/src/main/java/com/usthe/alert/service/impl/AlertServiceImpl.java +++ b/alerter/src/main/java/com/usthe/alert/service/impl/AlertServiceImpl.java @@ -9,6 +9,8 @@ import org.springframework.data.domain.PageRequest; import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Service; +import java.util.HashSet; + /** * 告警信息服务实现 * @author tom @@ -29,4 +31,9 @@ public class AlertServiceImpl implements AlertService { public Page getAlerts(Specification specification, PageRequest pageRequest) { return alertDao.findAll(specification, pageRequest); } + + @Override + public void deleteAlerts(HashSet ids) { + alertDao.deleteAlertsByIdIn(ids); + } }