From ebb257bbb63218a1ed3df0f523ad710c715cef66 Mon Sep 17 00:00:00 2001 From: tomsun28 Date: Tue, 14 Dec 2021 08:45:08 +0800 Subject: [PATCH] =?UTF-8?q?[monitor]=20=E5=91=8A=E8=AD=A6=E4=B8=AD?= =?UTF-8?q?=E5=BF=83-=E5=91=8A=E8=AD=A6=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../alert/service/impl/AlertServiceImpl.java | 4 ++ .../alert-center/alert-center.component.html | 7 --- .../alert-center/alert-center.component.ts | 53 +++++++++++++++---- web-app/src/app/service/alert.service.ts | 12 +++++ 4 files changed, 60 insertions(+), 16 deletions(-) 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 9f5cd80..4c96fa8 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 @@ -3,11 +3,13 @@ package com.usthe.alert.service.impl; import com.usthe.alert.dao.AlertDao; import com.usthe.alert.pojo.entity.Alert; import com.usthe.alert.service.AlertService; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.HashSet; @@ -17,6 +19,8 @@ import java.util.HashSet; * @date 2021/12/10 15:39 */ @Service +@Transactional(rollbackFor = Exception.class) +@Slf4j public class AlertServiceImpl implements AlertService { @Autowired diff --git a/web-app/src/app/routes/alert/alert-center/alert-center.component.html b/web-app/src/app/routes/alert/alert-center/alert-center.component.html index d103cb3..2b70a0e 100644 --- a/web-app/src/app/routes/alert/alert-center/alert-center.component.html +++ b/web-app/src/app/routes/alert/alert-center/alert-center.component.html @@ -13,10 +13,6 @@ - diff --git a/web-app/src/app/routes/alert/alert-center/alert-center.component.ts b/web-app/src/app/routes/alert/alert-center/alert-center.component.ts index 3adb5e3..dc67998 100644 --- a/web-app/src/app/routes/alert/alert-center/alert-center.component.ts +++ b/web-app/src/app/routes/alert/alert-center/alert-center.component.ts @@ -2,8 +2,8 @@ import { Component, OnInit } from '@angular/core'; import {NzTableQueryParams} from "ng-zorro-antd/table"; import {Alert} from "../../../pojo/Alert"; import {NzNotificationService} from "ng-zorro-antd/notification"; -import {NzMessageService} from "ng-zorro-antd/message"; import {AlertService} from "../../../service/alert.service"; +import {NzModalService} from "ng-zorro-antd/modal"; @Component({ selector: 'app-alert-center', @@ -14,7 +14,7 @@ import {AlertService} from "../../../service/alert.service"; export class AlertCenterComponent implements OnInit { constructor(private notifySvc: NzNotificationService, - private msg: NzMessageService, + private modal: NzModalService, private alertSvc: AlertService) { } pageIndex: number = 1; @@ -50,18 +50,53 @@ export class AlertCenterComponent implements OnInit { }); } - onRestoreAlerts() { - - } - onRestoreOneAlert(alertId: number) { - - } onDeleteAlerts() { - + if (this.checkedAlertIds == null || this.checkedAlertIds.size === 0) { + this.notifySvc.warning("未选中任何待删除项!",""); + return; + } + this.modal.confirm({ + nzTitle: '请确认是否批量删除!', + nzOkText: '确定', + nzCancelText: '取消', + nzOkDanger: true, + nzOkType: "primary", + nzOnOk: () => this.deleteAlerts(this.checkedAlertIds) + }); } onDeleteOneAlert(alertId: number) { + let alerts = new Set(); + alerts.add(alertId); + this.modal.confirm({ + nzTitle: '请确认是否删除!', + nzOkText: '确定', + nzCancelText: '取消', + nzOkDanger: true, + nzOkType: "primary", + nzOnOk: () => this.deleteAlerts(alerts) + }); + } + deleteAlerts(alertIds: Set) { + this.tableLoading = true; + const deleteAlerts$ = this.alertSvc.deleteAlerts(alertIds) + .subscribe(message => { + deleteAlerts$.unsubscribe(); + if (message.code === 0) { + this.notifySvc.success("删除成功!", ""); + this.loadAlertsTable(); + } else { + this.tableLoading = false; + this.notifySvc.error("删除失败!", message.msg); + } + }, + error => { + this.tableLoading = false; + deleteAlerts$.unsubscribe(); + this.notifySvc.error("删除失败!", error.msg) + } + ); } // begin: 列表多选分页逻辑 diff --git a/web-app/src/app/service/alert.service.ts b/web-app/src/app/service/alert.service.ts index 3411513..1ba2ac1 100644 --- a/web-app/src/app/service/alert.service.ts +++ b/web-app/src/app/service/alert.service.ts @@ -28,4 +28,16 @@ export class AlertService { const options = { params: httpParams }; return this.http.get>>(alerts_uri, options); } + + public deleteAlerts(alertIds: Set) : Observable> { + let httpParams = new HttpParams(); + alertIds.forEach(alertId => { + // 注意HttpParams是不可变对象 需要保存append后返回的对象为最新对象 + // append方法可以叠加同一key, set方法会把key之前的值覆盖只留一个key-value + httpParams = httpParams.append('ids', alertId); + }) + const options = { params: httpParams }; + return this.http.delete>(alerts_uri, options); + } + }