Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add get rule, receiver by id endpoint #19

Merged
merged 4 commits into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.springframework.web.bind.annotation.RestController;
import javax.persistence.criteria.Predicate;
import javax.validation.Valid;
import java.util.HashSet;
import java.util.List;
import static com.zmops.open.common.util.CommonConstants.FAIL_CODE;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
Expand Down Expand Up @@ -85,6 +86,17 @@ public ResponseEntity<Message<Void>> deleteNoticeReceiver(
return ResponseEntity.ok(new Message<>("Delete success"));
}


@DeleteMapping(path = "/receivers")
@Operation(summary = "Delete existing recipient information", description = "删除已存在的接收人信息")
public ResponseEntity<Message<Void>> deleteNoticeReceivers(
@Parameter(description = "接收人IDS", example = "6565463543") @RequestParam(required = false) List<Long> ids) {
if (ids != null && !ids.isEmpty()) {
noticeConfigService.deleteReceivers(new HashSet<>(ids));
}
return ResponseEntity.ok(new Message<>("Delete success"));
}

@GetMapping(path = "/receiver/{id}")
@Operation(summary = "Get existing recipient information", description = "查询已存在的接收人信息")
public ResponseEntity<Message<NoticeReceiver>> getNoticeReceiver(
Expand Down Expand Up @@ -145,6 +157,16 @@ public ResponseEntity<Message<Void>> deleteNoticeRule(
return ResponseEntity.ok(new Message<>("Delete success"));
}


@DeleteMapping(path = "/rules")
@Operation(summary = "Delete existing notification policy information", description = "删除已存在的通知策略信息")
public ResponseEntity<Message<Void>> deleteNoticeRules(
@Parameter(description = "en: Notification Policy ID,zh: 通知策略ID", example = "6565463543") @RequestParam(required = false) List<Long> ids) {
noticeConfigService.deleteNoticeRules(new HashSet<>(ids));
return ResponseEntity.ok(new Message<>("Delete success"));
}


@GetMapping(path = "/rule/{id}")
@Operation(summary = "Get existing notification policy information", description = "查询已存在的通知策略信息")
public ResponseEntity<Message<NoticeRule>> getNoticeRule(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,18 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

import java.util.Set;

/**
* NoticeReceiver数据库操作
* @author tom from <a href="https://github.com/dromara/hertzbeat">hertzbeat</a>
* @date 2021/12/16 16:12
*/
public interface NoticeReceiverDao extends JpaRepository<NoticeReceiver, Long>, JpaSpecificationExecutor<NoticeReceiver> {

/**
* 根据IDS删除
* @param ids ids
*/
void deleteNoticeReceiversByIdIn(Set<Long> ids);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

import java.util.List;
import java.util.Set;

/**
* NoticeRule数据库操作
Expand All @@ -35,4 +36,10 @@ public interface NoticeRuleDao extends JpaRepository<NoticeRule, Long>, JpaSpeci
* @return 通知策略
*/
List<NoticeRule> findNoticeRulesByEnableTrue();

/**
* 根据IDS删除
* @param ids ids
*/
void deleteNoticeRulesByIdIn(Set<Long> ids);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.domain.Specification;

import java.util.HashSet;
import java.util.List;

/**
Expand Down Expand Up @@ -135,4 +136,16 @@ public interface NoticeConfigService {
* @return true send success | false send fail
*/
boolean sendTestMsg(NoticeReceiver noticeReceiver);

/**
* delete receivers
* @param longs ids
*/
void deleteReceivers(HashSet<Long> longs);

/**
* delete rules
* @param ids ids
*/
void deleteNoticeRules(HashSet<Long> ids);
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -166,4 +163,14 @@ public boolean sendTestMsg(NoticeReceiver noticeReceiver) {
alert.setPriority(CommonConstants.ALERT_PRIORITY_CODE_CRITICAL);
return dispatcherAlarm.sendNoticeMsg(noticeReceiver, alert);
}

@Override
public void deleteReceivers(HashSet<Long> longs) {
noticeReceiverDao.deleteNoticeReceiversByIdIn(longs);
}

@Override
public void deleteNoticeRules(HashSet<Long> ids) {
noticeRuleDao.deleteNoticeRulesByIdIn(ids);
}
}