2021-12-12 10:33:27 +08:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
2021-12-23 15:59:49 +08:00
|
|
|
import { NzModalService } from 'ng-zorro-antd/modal';
|
|
|
|
|
import { NzNotificationService } from 'ng-zorro-antd/notification';
|
|
|
|
|
import { NzTableQueryParams } from 'ng-zorro-antd/table';
|
|
|
|
|
|
|
|
|
|
import { Alert } from '../../../pojo/Alert';
|
|
|
|
|
import { AlertService } from '../../../service/alert.service';
|
2021-12-12 10:33:27 +08:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-alert-center',
|
|
|
|
|
templateUrl: './alert-center.component.html',
|
2021-12-23 15:59:49 +08:00
|
|
|
styles: []
|
2021-12-12 10:33:27 +08:00
|
|
|
})
|
|
|
|
|
export class AlertCenterComponent implements OnInit {
|
2021-12-23 15:59:49 +08:00
|
|
|
constructor(private notifySvc: NzNotificationService, private modal: NzModalService, private alertSvc: AlertService) {}
|
2021-12-13 14:51:08 +08:00
|
|
|
|
|
|
|
|
pageIndex: number = 1;
|
|
|
|
|
pageSize: number = 8;
|
|
|
|
|
total: number = 0;
|
|
|
|
|
alerts!: Alert[];
|
|
|
|
|
tableLoading: boolean = false;
|
|
|
|
|
checkedAlertIds = new Set<number>();
|
2021-12-19 21:49:19 +08:00
|
|
|
// 搜索过滤相关属性
|
|
|
|
|
filterStatus: number | undefined;
|
|
|
|
|
filterPriority: number | undefined;
|
|
|
|
|
filterContent: string | undefined;
|
2021-12-12 10:33:27 +08:00
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
2021-12-13 14:51:08 +08:00
|
|
|
this.loadAlertsTable();
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-19 21:49:19 +08:00
|
|
|
onFilterSearchAlerts() {
|
|
|
|
|
this.tableLoading = true;
|
2021-12-23 15:59:49 +08:00
|
|
|
let filterAlerts$ = this.alertSvc
|
|
|
|
|
.searchAlerts(this.filterStatus, this.filterPriority, this.filterContent, this.pageIndex - 1, this.pageSize)
|
|
|
|
|
.subscribe(
|
|
|
|
|
message => {
|
|
|
|
|
filterAlerts$.unsubscribe();
|
|
|
|
|
this.tableLoading = false;
|
|
|
|
|
this.checkedAll = false;
|
|
|
|
|
this.checkedAlertIds.clear();
|
|
|
|
|
if (message.code === 0) {
|
|
|
|
|
let page = message.data;
|
|
|
|
|
this.alerts = page.content;
|
|
|
|
|
this.pageIndex = page.number + 1;
|
|
|
|
|
this.total = page.totalElements;
|
|
|
|
|
} else {
|
|
|
|
|
console.warn(message.msg);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
error => {
|
|
|
|
|
this.tableLoading = false;
|
|
|
|
|
filterAlerts$.unsubscribe();
|
|
|
|
|
console.error(error.msg);
|
2021-12-19 21:49:19 +08:00
|
|
|
}
|
2021-12-23 15:59:49 +08:00
|
|
|
);
|
2021-12-19 21:49:19 +08:00
|
|
|
}
|
|
|
|
|
|
2021-12-17 15:43:25 +08:00
|
|
|
sync() {
|
|
|
|
|
this.loadAlertsTable();
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-13 14:51:08 +08:00
|
|
|
loadAlertsTable() {
|
|
|
|
|
this.tableLoading = true;
|
2021-12-23 15:59:49 +08:00
|
|
|
let alertsInit$ = this.alertSvc.getAlerts(this.pageIndex - 1, this.pageSize).subscribe(
|
|
|
|
|
message => {
|
2021-12-13 14:51:08 +08:00
|
|
|
this.tableLoading = false;
|
|
|
|
|
this.checkedAll = false;
|
|
|
|
|
this.checkedAlertIds.clear();
|
|
|
|
|
if (message.code === 0) {
|
|
|
|
|
let page = message.data;
|
|
|
|
|
this.alerts = page.content;
|
|
|
|
|
this.pageIndex = page.number + 1;
|
|
|
|
|
this.total = page.totalElements;
|
|
|
|
|
} else {
|
|
|
|
|
console.warn(message.msg);
|
|
|
|
|
}
|
|
|
|
|
alertsInit$.unsubscribe();
|
2021-12-23 15:59:49 +08:00
|
|
|
},
|
|
|
|
|
error => {
|
2021-12-13 14:51:08 +08:00
|
|
|
this.tableLoading = false;
|
|
|
|
|
alertsInit$.unsubscribe();
|
2021-12-19 21:49:19 +08:00
|
|
|
console.error(error.msg);
|
2021-12-23 15:59:49 +08:00
|
|
|
}
|
|
|
|
|
);
|
2021-12-13 14:51:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onDeleteAlerts() {
|
2021-12-14 08:45:08 +08:00
|
|
|
if (this.checkedAlertIds == null || this.checkedAlertIds.size === 0) {
|
2021-12-23 15:59:49 +08:00
|
|
|
this.notifySvc.warning('未选中任何待删除项!', '');
|
2021-12-14 08:45:08 +08:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this.modal.confirm({
|
|
|
|
|
nzTitle: '请确认是否批量删除!',
|
|
|
|
|
nzOkText: '确定',
|
|
|
|
|
nzCancelText: '取消',
|
|
|
|
|
nzOkDanger: true,
|
2021-12-23 15:59:49 +08:00
|
|
|
nzOkType: 'primary',
|
2021-12-14 08:45:08 +08:00
|
|
|
nzOnOk: () => this.deleteAlerts(this.checkedAlertIds)
|
|
|
|
|
});
|
2021-12-12 10:33:27 +08:00
|
|
|
}
|
|
|
|
|
|
2021-12-19 21:49:19 +08:00
|
|
|
onMarkReadAlerts() {
|
|
|
|
|
if (this.checkedAlertIds == null || this.checkedAlertIds.size === 0) {
|
2021-12-23 15:59:49 +08:00
|
|
|
this.notifySvc.warning('未选中任何待标记项!', '');
|
2021-12-19 21:49:19 +08:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this.modal.confirm({
|
2022-01-30 12:39:23 +08:00
|
|
|
nzTitle: '请确认是否批量标记已处理!',
|
2021-12-19 21:49:19 +08:00
|
|
|
nzOkText: '确定',
|
|
|
|
|
nzCancelText: '取消',
|
|
|
|
|
nzOkDanger: true,
|
2021-12-23 15:59:49 +08:00
|
|
|
nzOkType: 'primary',
|
2021-12-19 21:49:19 +08:00
|
|
|
nzOnOk: () => this.updateAlertsStatus(this.checkedAlertIds, 3)
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
onMarkUnReadAlerts() {
|
|
|
|
|
if (this.checkedAlertIds == null || this.checkedAlertIds.size === 0) {
|
2021-12-23 15:59:49 +08:00
|
|
|
this.notifySvc.warning('未选中任何待标记项!', '');
|
2021-12-19 21:49:19 +08:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this.modal.confirm({
|
2022-01-30 12:39:23 +08:00
|
|
|
nzTitle: '请确认是否批量标记未处理!',
|
2021-12-19 21:49:19 +08:00
|
|
|
nzOkText: '确定',
|
|
|
|
|
nzCancelText: '取消',
|
|
|
|
|
nzOkDanger: true,
|
2021-12-23 15:59:49 +08:00
|
|
|
nzOkType: 'primary',
|
2021-12-19 21:49:19 +08:00
|
|
|
nzOnOk: () => this.updateAlertsStatus(this.checkedAlertIds, 0)
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-13 14:51:08 +08:00
|
|
|
onDeleteOneAlert(alertId: number) {
|
2021-12-14 08:45:08 +08:00
|
|
|
let alerts = new Set<number>();
|
|
|
|
|
alerts.add(alertId);
|
|
|
|
|
this.modal.confirm({
|
|
|
|
|
nzTitle: '请确认是否删除!',
|
|
|
|
|
nzOkText: '确定',
|
|
|
|
|
nzCancelText: '取消',
|
|
|
|
|
nzOkDanger: true,
|
2021-12-23 15:59:49 +08:00
|
|
|
nzOkType: 'primary',
|
2021-12-14 08:45:08 +08:00
|
|
|
nzOnOk: () => this.deleteAlerts(alerts)
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-12-13 14:51:08 +08:00
|
|
|
|
2021-12-19 21:49:19 +08:00
|
|
|
onMarkReadOneAlert(alertId: number) {
|
|
|
|
|
let alerts = new Set<number>();
|
|
|
|
|
alerts.add(alertId);
|
|
|
|
|
this.modal.confirm({
|
2022-01-30 12:39:23 +08:00
|
|
|
nzTitle: '请确认是否标记已处理!',
|
2021-12-19 21:49:19 +08:00
|
|
|
nzOkText: '确定',
|
|
|
|
|
nzCancelText: '取消',
|
|
|
|
|
nzOkDanger: true,
|
2021-12-23 15:59:49 +08:00
|
|
|
nzOkType: 'primary',
|
2021-12-19 21:49:19 +08:00
|
|
|
nzOnOk: () => this.updateAlertsStatus(alerts, 3)
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onMarkUnReadOneAlert(alertId: number) {
|
|
|
|
|
let alerts = new Set<number>();
|
|
|
|
|
alerts.add(alertId);
|
|
|
|
|
this.modal.confirm({
|
2022-01-30 12:39:23 +08:00
|
|
|
nzTitle: '请确认是否标记未处理!',
|
2021-12-19 21:49:19 +08:00
|
|
|
nzOkText: '确定',
|
|
|
|
|
nzCancelText: '取消',
|
|
|
|
|
nzOkDanger: true,
|
2021-12-23 15:59:49 +08:00
|
|
|
nzOkType: 'primary',
|
2021-12-19 21:49:19 +08:00
|
|
|
nzOnOk: () => this.updateAlertsStatus(alerts, 0)
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-14 08:45:08 +08:00
|
|
|
deleteAlerts(alertIds: Set<number>) {
|
|
|
|
|
this.tableLoading = true;
|
2021-12-23 15:59:49 +08:00
|
|
|
const deleteAlerts$ = this.alertSvc.deleteAlerts(alertIds).subscribe(
|
|
|
|
|
message => {
|
|
|
|
|
deleteAlerts$.unsubscribe();
|
|
|
|
|
if (message.code === 0) {
|
|
|
|
|
this.notifySvc.success('删除成功!', '');
|
|
|
|
|
this.loadAlertsTable();
|
|
|
|
|
} else {
|
2021-12-14 08:45:08 +08:00
|
|
|
this.tableLoading = false;
|
2021-12-23 15:59:49 +08:00
|
|
|
this.notifySvc.error('删除失败!', message.msg);
|
2021-12-14 08:45:08 +08:00
|
|
|
}
|
2021-12-23 15:59:49 +08:00
|
|
|
},
|
|
|
|
|
error => {
|
|
|
|
|
this.tableLoading = false;
|
|
|
|
|
deleteAlerts$.unsubscribe();
|
|
|
|
|
this.notifySvc.error('删除失败!', error.msg);
|
|
|
|
|
}
|
|
|
|
|
);
|
2021-12-13 14:51:08 +08:00
|
|
|
}
|
|
|
|
|
|
2021-12-19 21:49:19 +08:00
|
|
|
updateAlertsStatus(alertIds: Set<number>, status: number) {
|
|
|
|
|
this.tableLoading = true;
|
2021-12-23 15:59:49 +08:00
|
|
|
const markAlertsStatus$ = this.alertSvc.applyAlertsStatus(alertIds, status).subscribe(
|
|
|
|
|
message => {
|
|
|
|
|
markAlertsStatus$.unsubscribe();
|
|
|
|
|
if (message.code === 0) {
|
|
|
|
|
this.notifySvc.success('标记成功!', '');
|
|
|
|
|
this.loadAlertsTable();
|
|
|
|
|
} else {
|
2021-12-19 21:49:19 +08:00
|
|
|
this.tableLoading = false;
|
2021-12-23 15:59:49 +08:00
|
|
|
this.notifySvc.error('标记失败!', message.msg);
|
2021-12-19 21:49:19 +08:00
|
|
|
}
|
2021-12-23 15:59:49 +08:00
|
|
|
},
|
|
|
|
|
error => {
|
|
|
|
|
this.tableLoading = false;
|
|
|
|
|
markAlertsStatus$.unsubscribe();
|
|
|
|
|
this.notifySvc.error('标记失败!', error.msg);
|
|
|
|
|
}
|
|
|
|
|
);
|
2021-12-19 21:49:19 +08:00
|
|
|
}
|
|
|
|
|
|
2021-12-13 14:51:08 +08:00
|
|
|
// begin: 列表多选分页逻辑
|
|
|
|
|
checkedAll: boolean = false;
|
|
|
|
|
onAllChecked(checked: boolean) {
|
|
|
|
|
if (checked) {
|
|
|
|
|
this.alerts.forEach(monitor => this.checkedAlertIds.add(monitor.id));
|
|
|
|
|
} else {
|
|
|
|
|
this.checkedAlertIds.clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
onItemChecked(monitorId: number, checked: boolean) {
|
|
|
|
|
if (checked) {
|
|
|
|
|
this.checkedAlertIds.add(monitorId);
|
|
|
|
|
} else {
|
|
|
|
|
this.checkedAlertIds.delete(monitorId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
onTablePageChange(params: NzTableQueryParams) {
|
|
|
|
|
const { pageSize, pageIndex, sort, filter } = params;
|
|
|
|
|
this.pageIndex = pageIndex;
|
|
|
|
|
this.pageSize = pageSize;
|
|
|
|
|
this.loadAlertsTable();
|
|
|
|
|
}
|
|
|
|
|
// end: 列表多选分页逻辑
|
2021-12-12 10:33:27 +08:00
|
|
|
}
|