[alerter] 告警信息批量接口
This commit is contained in:
@@ -72,7 +72,7 @@ public class AlertDefinesController {
|
||||
}
|
||||
|
||||
@DeleteMapping
|
||||
@ApiOperation(value = "批量删除告警定义", notes = "根据告警定义ID列表批量删除监控项")
|
||||
@ApiOperation(value = "批量删除告警定义", notes = "根据告警定义ID列表批量删除告警定义")
|
||||
public ResponseEntity<Message<Void>> deleteAlertDefines(
|
||||
@ApiParam(value = "告警定义IDs", example = "6565463543") @RequestParam(required = false) List<Long> ids
|
||||
) {
|
||||
|
||||
@@ -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<Message<Void>> deleteAlertDefines(
|
||||
@ApiParam(value = "告警IDs", example = "6565463543") @RequestParam(required = false) List<Long> ids
|
||||
) {
|
||||
if (ids != null && !ids.isEmpty()) {
|
||||
alertService.deleteAlerts(new HashSet<>(ids));
|
||||
}
|
||||
Message<Void> message = new Message<>();
|
||||
return ResponseEntity.ok(message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<Alert, Long>, JpaSpecificationExecutor<Alert> {
|
||||
|
||||
/**
|
||||
* 根据ID列表删除告警
|
||||
* @param alertIds 告警ID列表
|
||||
*/
|
||||
void deleteAlertsByIdIn(Set<Long> alertIds);
|
||||
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ public interface AlertDefineDao extends JpaRepository<AlertDefine, Long>, JpaSpe
|
||||
* 根据ID列表删除告警定义
|
||||
* @param alertDefineIds 告警定义ID列表
|
||||
*/
|
||||
void deleteAllByIdIn(Set<Long> alertDefineIds);
|
||||
void deleteAlertDefinesByIdIn(Set<Long> alertDefineIds);
|
||||
|
||||
/**
|
||||
* 根据监控ID查询与之关联的告警定义列表
|
||||
|
||||
@@ -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<Alert> getAlerts(Specification<Alert> specification, PageRequest pageRequest);
|
||||
|
||||
/**
|
||||
* 根据告警ID列表批量删除告警
|
||||
* @param ids 告警IDs
|
||||
*/
|
||||
void deleteAlerts(HashSet<Long> ids);
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ public class AlertDefineServiceImpl implements AlertDefineService {
|
||||
|
||||
@Override
|
||||
public void deleteAlertDefines(Set<Long> alertIds) throws RuntimeException {
|
||||
alertDefineDao.deleteAllByIdIn(alertIds);
|
||||
alertDefineDao.deleteAlertDefinesByIdIn(alertIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -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<Alert> getAlerts(Specification<Alert> specification, PageRequest pageRequest) {
|
||||
return alertDao.findAll(specification, pageRequest);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAlerts(HashSet<Long> ids) {
|
||||
alertDao.deleteAlertsByIdIn(ids);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user