[alerter,common]fixbug告警定义关联监控不存在时异常
This commit is contained in:
@@ -21,6 +21,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static com.usthe.common.util.CommonConstants.MONITOR_NOT_EXIST_CODE;
|
import static com.usthe.common.util.CommonConstants.MONITOR_NOT_EXIST_CODE;
|
||||||
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
|
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
|
||||||
@@ -94,6 +95,7 @@ public class AlertDefineController {
|
|||||||
public ResponseEntity<Message<List<AlertDefineMonitorBind>>> getAlertDefineMonitorsBind(
|
public ResponseEntity<Message<List<AlertDefineMonitorBind>>> getAlertDefineMonitorsBind(
|
||||||
@ApiParam(value = "告警定义ID", example = "6565463543") @PathVariable("alertDefineId") long alertDefineId) {
|
@ApiParam(value = "告警定义ID", example = "6565463543") @PathVariable("alertDefineId") long alertDefineId) {
|
||||||
List<AlertDefineMonitorBind> defineBinds = alertDefineService.getBindAlertDefineMonitors(alertDefineId);
|
List<AlertDefineMonitorBind> defineBinds = alertDefineService.getBindAlertDefineMonitors(alertDefineId);
|
||||||
|
defineBinds = defineBinds.stream().filter(item -> item.getMonitor() != null).collect(Collectors.toList());
|
||||||
return ResponseEntity.ok(new Message<>(defineBinds));
|
return ResponseEntity.ok(new Message<>(defineBinds));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import lombok.AllArgsConstructor;
|
|||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.hibernate.annotations.NotFound;
|
||||||
|
import org.hibernate.annotations.NotFoundAction;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
@@ -58,5 +60,6 @@ public class AlertDefineMonitorBind {
|
|||||||
|
|
||||||
@OneToOne(fetch = FetchType.EAGER)
|
@OneToOne(fetch = FetchType.EAGER)
|
||||||
@JoinColumn(name = "monitor_id", referencedColumnName = "id", insertable = false, updatable = false)
|
@JoinColumn(name = "monitor_id", referencedColumnName = "id", insertable = false, updatable = false)
|
||||||
|
@NotFound(action = NotFoundAction.IGNORE)
|
||||||
private Monitor monitor;
|
private Monitor monitor;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user