From e914fd69411629e86f2f1f5b90d5eac37dea57af Mon Sep 17 00:00:00 2001 From: tomsun28 Date: Sun, 30 Jan 2022 12:34:20 +0800 Subject: [PATCH] =?UTF-8?q?[alter,webapp]fix=20=E5=91=8A=E8=AD=A6=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E5=85=B3=E8=81=94=E7=9B=91=E6=8E=A7=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../alert/controller/AlertDefineController.java | 10 +++++----- .../com/usthe/alert/dao/AlertDefineBindDao.java | 6 +++--- .../java/com/usthe/alert/dao/AlertDefineDao.java | 2 +- .../usthe/alert/service/AlertDefineService.java | 6 +++--- .../alert/service/impl/AlertDefineServiceImpl.java | 6 +++--- ...DefineBind.java => AlertDefineMonitorBind.java} | 14 +++++++++++--- web-app/src/app/pojo/AlertDefineBind.ts | 4 +++- .../alert/alert-setting/alert-setting.component.ts | 3 +-- .../app/routes/passport/login/login.component.ts | 2 +- 9 files changed, 31 insertions(+), 22 deletions(-) rename common/src/main/java/com/usthe/common/entity/alerter/{AlertDefineBind.java => AlertDefineMonitorBind.java} (77%) diff --git a/alerter/src/main/java/com/usthe/alert/controller/AlertDefineController.java b/alerter/src/main/java/com/usthe/alert/controller/AlertDefineController.java index b2aebec..33a07bb 100644 --- a/alerter/src/main/java/com/usthe/alert/controller/AlertDefineController.java +++ b/alerter/src/main/java/com/usthe/alert/controller/AlertDefineController.java @@ -1,7 +1,7 @@ package com.usthe.alert.controller; import com.usthe.common.entity.alerter.AlertDefine; -import com.usthe.common.entity.alerter.AlertDefineBind; +import com.usthe.common.entity.alerter.AlertDefineMonitorBind; import com.usthe.alert.service.AlertDefineService; import com.usthe.common.entity.dto.Message; import io.swagger.annotations.Api; @@ -84,16 +84,16 @@ public class AlertDefineController { @ApiOperation(value = "应用告警定义与监控关联", notes = "应用指定告警定义与监控关联关系") public ResponseEntity> applyAlertDefineMonitorsBind( @ApiParam(value = "告警定义ID", example = "6565463543") @PathVariable("alertDefineId") long alertDefineId, - @RequestBody List alertDefineBinds) { - alertDefineService.applyBindAlertDefineMonitors(alertDefineId, alertDefineBinds); + @RequestBody List alertDefineMonitorBinds) { + alertDefineService.applyBindAlertDefineMonitors(alertDefineId, alertDefineMonitorBinds); return ResponseEntity.ok(new Message<>("Apply success")); } @GetMapping(path = "/{alertDefineId}/monitors") @ApiOperation(value = "应用告警定义与监控关联", notes = "应用指定告警定义与监控关联关系") - public ResponseEntity>> getAlertDefineMonitorsBind( + public ResponseEntity>> getAlertDefineMonitorsBind( @ApiParam(value = "告警定义ID", example = "6565463543") @PathVariable("alertDefineId") long alertDefineId) { - List defineBinds = alertDefineService.getBindAlertDefineMonitors(alertDefineId); + List defineBinds = alertDefineService.getBindAlertDefineMonitors(alertDefineId); return ResponseEntity.ok(new Message<>(defineBinds)); } diff --git a/alerter/src/main/java/com/usthe/alert/dao/AlertDefineBindDao.java b/alerter/src/main/java/com/usthe/alert/dao/AlertDefineBindDao.java index 6fc6e55..d515798 100644 --- a/alerter/src/main/java/com/usthe/alert/dao/AlertDefineBindDao.java +++ b/alerter/src/main/java/com/usthe/alert/dao/AlertDefineBindDao.java @@ -1,6 +1,6 @@ package com.usthe.alert.dao; -import com.usthe.common.entity.alerter.AlertDefineBind; +import com.usthe.common.entity.alerter.AlertDefineMonitorBind; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; @@ -11,7 +11,7 @@ import java.util.List; * @author tom * @date 2021/12/9 10:03 */ -public interface AlertDefineBindDao extends JpaRepository, JpaSpecificationExecutor { +public interface AlertDefineBindDao extends JpaRepository, JpaSpecificationExecutor { /** * 根据告警定义ID删除告警定义与监控关联 @@ -24,5 +24,5 @@ public interface AlertDefineBindDao extends JpaRepository * @param alertDefineId 告警定义ID * @return 关联监控信息 */ - List getAlertDefineBindsByAlertDefineIdEquals(Long alertDefineId); + List getAlertDefineBindsByAlertDefineIdEquals(Long alertDefineId); } 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 6a752a9..9f35dda 100644 --- a/alerter/src/main/java/com/usthe/alert/dao/AlertDefineDao.java +++ b/alerter/src/main/java/com/usthe/alert/dao/AlertDefineDao.java @@ -28,7 +28,7 @@ public interface AlertDefineDao extends JpaRepository, JpaSpe * @param metrics 指标组 * @return 告警定义列表 */ - @Query("select define from AlertDefine define join AlertDefineBind bind on bind.alertDefineId = define.id " + + @Query("select define from AlertDefine define join AlertDefineMonitorBind bind on bind.alertDefineId = define.id " + "where bind.monitorId = :monitorId and define.metric = :metrics and define.enable = true") List queryAlertDefinesByMonitor(@Param(value = "monitorId") Long monitorId, @Param(value = "metrics") String metrics); diff --git a/alerter/src/main/java/com/usthe/alert/service/AlertDefineService.java b/alerter/src/main/java/com/usthe/alert/service/AlertDefineService.java index 0f8b1b9..117c3ab 100644 --- a/alerter/src/main/java/com/usthe/alert/service/AlertDefineService.java +++ b/alerter/src/main/java/com/usthe/alert/service/AlertDefineService.java @@ -1,7 +1,7 @@ package com.usthe.alert.service; import com.usthe.common.entity.alerter.AlertDefine; -import com.usthe.common.entity.alerter.AlertDefineBind; +import com.usthe.common.entity.alerter.AlertDefineMonitorBind; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.jpa.domain.Specification; @@ -75,7 +75,7 @@ public interface AlertDefineService { * @param alertId 告警定义ID * @param alertDefineBinds 关联关系 */ - void applyBindAlertDefineMonitors(Long alertId, List alertDefineBinds); + void applyBindAlertDefineMonitors(Long alertId, List alertDefineBinds); /** * 查询与此监控ID关联的指定指标组匹配的告警定义 @@ -99,5 +99,5 @@ public interface AlertDefineService { * @param alertDefineId 告警定义ID * @return 监控列表关联信息 */ - List getBindAlertDefineMonitors(long alertDefineId); + List getBindAlertDefineMonitors(long alertDefineId); } 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 5df988c..7fe3f89 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 @@ -3,7 +3,7 @@ package com.usthe.alert.service.impl; import com.usthe.alert.dao.AlertDefineBindDao; import com.usthe.alert.dao.AlertDefineDao; import com.usthe.common.entity.alerter.AlertDefine; -import com.usthe.common.entity.alerter.AlertDefineBind; +import com.usthe.common.entity.alerter.AlertDefineMonitorBind; import com.usthe.alert.service.AlertDefineService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -73,7 +73,7 @@ public class AlertDefineServiceImpl implements AlertDefineService { } @Override - public void applyBindAlertDefineMonitors(Long alertId, List alertDefineBinds) { + public void applyBindAlertDefineMonitors(Long alertId, List alertDefineBinds) { // todo 校验此告警定义和监控是否存在 // 先删除此告警的所有关联 @@ -99,7 +99,7 @@ public class AlertDefineServiceImpl implements AlertDefineService { } @Override - public List getBindAlertDefineMonitors(long alertDefineId) { + public List getBindAlertDefineMonitors(long alertDefineId) { return alertDefineBindDao.getAlertDefineBindsByAlertDefineIdEquals(alertDefineId); } } diff --git a/common/src/main/java/com/usthe/common/entity/alerter/AlertDefineBind.java b/common/src/main/java/com/usthe/common/entity/alerter/AlertDefineMonitorBind.java similarity index 77% rename from common/src/main/java/com/usthe/common/entity/alerter/AlertDefineBind.java rename to common/src/main/java/com/usthe/common/entity/alerter/AlertDefineMonitorBind.java index e7e18c0..5ce8bd9 100644 --- a/common/src/main/java/com/usthe/common/entity/alerter/AlertDefineBind.java +++ b/common/src/main/java/com/usthe/common/entity/alerter/AlertDefineMonitorBind.java @@ -1,5 +1,6 @@ package com.usthe.common.entity.alerter; +import com.usthe.common.entity.manager.Monitor; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.AllArgsConstructor; @@ -9,9 +10,12 @@ import lombok.NoArgsConstructor; import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.OneToOne; import javax.persistence.Table; import java.time.LocalDateTime; @@ -30,7 +34,7 @@ import static io.swagger.annotations.ApiModelProperty.AccessMode.READ_WRITE; @AllArgsConstructor @NoArgsConstructor @ApiModel(description = "告警定义与监控关联实体") -public class AlertDefineBind { +public class AlertDefineMonitorBind { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -41,10 +45,11 @@ public class AlertDefineBind { private Long alertDefineId; @ApiModelProperty(value = "监控ID", example = "87432674336", accessMode = READ_WRITE, position = 2) + @Column(name = "monitor_id") private Long monitorId; - @ApiModelProperty(value = "监控名称", example = "Linux_192.123.23.1", accessMode = READ_WRITE, position = 3) - private String monitorName; + @ApiModelProperty(value = "租户ID", example = "42343", accessMode = READ_WRITE, position = 3) + private Long tenantId; @ApiModelProperty(value = "记录创建时间(毫秒时间戳)", example = "1612198922000", accessMode = READ_ONLY, position = 4) @Column(insertable = false, updatable = false) @@ -54,4 +59,7 @@ public class AlertDefineBind { @Column(insertable = false, updatable = false) private LocalDateTime gmtUpdate; + @OneToOne(fetch = FetchType.EAGER) + @JoinColumn(name = "monitor_id", referencedColumnName = "id", insertable = false, updatable = false) + private Monitor monitor; } diff --git a/web-app/src/app/pojo/AlertDefineBind.ts b/web-app/src/app/pojo/AlertDefineBind.ts index 09e0505..e9b684d 100644 --- a/web-app/src/app/pojo/AlertDefineBind.ts +++ b/web-app/src/app/pojo/AlertDefineBind.ts @@ -1,8 +1,10 @@ +import { Monitor } from './Monitor'; + export class AlertDefineBind { id!: number; alertDefineId!: number; monitorId!: number; - monitorName!: string; + monitor!: Monitor; gmtCreate!: number; gmtUpdate!: number; } diff --git a/web-app/src/app/routes/alert/alert-setting/alert-setting.component.ts b/web-app/src/app/routes/alert/alert-setting/alert-setting.component.ts index 2cf1d3c..349f131 100644 --- a/web-app/src/app/routes/alert/alert-setting/alert-setting.component.ts +++ b/web-app/src/app/routes/alert/alert-setting/alert-setting.component.ts @@ -307,7 +307,7 @@ export class AlertSettingComponent implements OnInit { let bindRecode: Record = {}; if (defineBindData.data != undefined) { defineBindData.data.forEach(bind => { - bindRecode[bind.monitorId] = bind.monitorName; + bindRecode[bind.monitorId] = bind.monitor.name; }); } let listTmp: any[] = []; @@ -337,7 +337,6 @@ export class AlertSettingComponent implements OnInit { let bind = new AlertDefineBind(); bind.alertDefineId = this.currentAlertDefineId; bind.monitorId = item.id; - bind.monitorName = item.name; defineBinds.push(bind); } }); diff --git a/web-app/src/app/routes/passport/login/login.component.ts b/web-app/src/app/routes/passport/login/login.component.ts index 5787ae3..9eb2efc 100644 --- a/web-app/src/app/routes/passport/login/login.component.ts +++ b/web-app/src/app/routes/passport/login/login.component.ts @@ -103,7 +103,7 @@ export class UserLoginComponent implements OnDestroy { .post>('/account/auth/form', { type: this.type, identifier: this.userName.value, - password: this.password.value + credential: this.password.value }) .pipe( finalize(() => {