This is an automated email from the ASF dual-hosted git repository.

zhaoqingran pushed a commit to branch bulletin
in repository https://gitbox.apache.org/repos/asf/hertzbeat.git


The following commit(s) were added to refs/heads/bulletin by this push:
     new 84c010e4a [feat(bulletin)] add tags support for bulletin definitions
84c010e4a is described below

commit 84c010e4a189cec6321988c6a643fd5218b0b6f9
Author: zqr10159 <[email protected]>
AuthorDate: Thu Jul 11 17:33:42 2024 +0800

    [feat(bulletin)] add tags support for bulletin definitions
    
    Extend the BulletinDefine class to include a new 'tags' property, enabling
    the association of tags with bulletin definitions. This feature enhances
    the bulletin management system by allowing for improved categorization
    and filtering of bulletins based on tags.
---
 .../common/entity/manager/bulletin/Bulletin.java   |   3 +
 .../common/entity/manager/bulletin/BulletinVo.java |  39 ++++++
 .../manager/controller/BulletinController.java     |   6 +-
 .../hertzbeat/manager/service/BulletinService.java |   3 +-
 .../manager/service/impl/BulletinServiceImpl.java  |  39 +++++-
 web-app/src/app/pojo/BulletinDefine.ts             |   4 +-
 .../app/routes/bulletin/bulletin.component.html    | 137 +++++++++++----------
 .../src/app/routes/bulletin/bulletin.component.ts  |  17 ++-
 8 files changed, 165 insertions(+), 83 deletions(-)

diff --git 
a/common/src/main/java/org/apache/hertzbeat/common/entity/manager/bulletin/Bulletin.java
 
b/common/src/main/java/org/apache/hertzbeat/common/entity/manager/bulletin/Bulletin.java
index d1e4c3283..69f418d1e 100644
--- 
a/common/src/main/java/org/apache/hertzbeat/common/entity/manager/bulletin/Bulletin.java
+++ 
b/common/src/main/java/org/apache/hertzbeat/common/entity/manager/bulletin/Bulletin.java
@@ -64,6 +64,9 @@ public class Bulletin {
     @Column(name = "monitor_id")
     private Long monitorId;
 
+    @Schema(description = "Monitor Type eg: jvm, tomcat", example = "jvm", 
accessMode = READ_WRITE)
+    private String app;
+
     @Schema(description = "Monitor Metrics", example = "[\"cpu\", \"memory\"]")
     @Convert(converter = JsonStringListAttributeConverter.class)
     private List<String> metrics;
diff --git 
a/common/src/main/java/org/apache/hertzbeat/common/entity/manager/bulletin/BulletinVo.java
 
b/common/src/main/java/org/apache/hertzbeat/common/entity/manager/bulletin/BulletinVo.java
index 040001895..c84a11b6e 100644
--- 
a/common/src/main/java/org/apache/hertzbeat/common/entity/manager/bulletin/BulletinVo.java
+++ 
b/common/src/main/java/org/apache/hertzbeat/common/entity/manager/bulletin/BulletinVo.java
@@ -17,5 +17,44 @@
 
 package org.apache.hertzbeat.common.entity.manager.bulletin;
 
+import java.util.List;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.apache.hertzbeat.common.entity.manager.TagItem;
+
+/**
+ * Bulletin Vo
+ */
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
 public class BulletinVo {
+
+    /**
+     * Bulletin ID
+     */
+    private Long id;
+
+    /**
+     * Bulletin metrics
+     */
+    private List<String> metrics;
+
+    /**
+     * Bulletin tags
+     */
+    private List<TagItem> tags;
+
+    /**
+     * Bulletin monitor ID
+     */
+    private Long monitorId;
+
+    /**
+     * Bulletin monitor name
+     */
+    private String app;
+
 }
diff --git 
a/manager/src/main/java/org/apache/hertzbeat/manager/controller/BulletinController.java
 
b/manager/src/main/java/org/apache/hertzbeat/manager/controller/BulletinController.java
index 5660bfe32..16da51d01 100644
--- 
a/manager/src/main/java/org/apache/hertzbeat/manager/controller/BulletinController.java
+++ 
b/manager/src/main/java/org/apache/hertzbeat/manager/controller/BulletinController.java
@@ -28,6 +28,7 @@ import java.util.List;
 import org.apache.hertzbeat.common.entity.dto.Message;
 import org.apache.hertzbeat.common.entity.manager.bulletin.Bulletin;
 import org.apache.hertzbeat.common.entity.manager.bulletin.BulletinDto;
+import org.apache.hertzbeat.common.entity.manager.bulletin.BulletinVo;
 import org.apache.hertzbeat.manager.service.BulletinService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
@@ -70,7 +71,7 @@ public class BulletinController {
      * page query bulletin
      */
     @GetMapping
-    public ResponseEntity<Message<Page<Bulletin>>> pageQueryBulletin(
+    public ResponseEntity<Message<Page<BulletinVo>>> pageQueryBulletin(
             @Parameter(description = "Bulletin Definition ID", example = 
"6565463543") @RequestParam(required = false) List<Long> ids,
             @Parameter(description = "Search-Target Expr Template", example = 
"x") @RequestParam(required = false) String search,
             @Parameter(description = "Sort field, default id", example = "id") 
@RequestParam(defaultValue = "id") String sort,
@@ -118,7 +119,8 @@ public class BulletinController {
          };
          Sort sortExp = Sort.by(new 
Sort.Order(Sort.Direction.fromString(order), sort));
          PageRequest pageRequest = PageRequest.of(pageIndex, pageSize, 
sortExp);
-         Page<Bulletin> bulletinsPage = 
bulletinService.getBulletins(specification, pageRequest);
+         Page<BulletinVo> bulletinsPage = 
bulletinService.getBulletins(specification, pageRequest);
+
          return ResponseEntity.ok(Message.success(bulletinsPage));
     }
 
diff --git 
a/manager/src/main/java/org/apache/hertzbeat/manager/service/BulletinService.java
 
b/manager/src/main/java/org/apache/hertzbeat/manager/service/BulletinService.java
index 345247aa1..ac2308620 100644
--- 
a/manager/src/main/java/org/apache/hertzbeat/manager/service/BulletinService.java
+++ 
b/manager/src/main/java/org/apache/hertzbeat/manager/service/BulletinService.java
@@ -20,6 +20,7 @@ package org.apache.hertzbeat.manager.service;
 import java.util.List;
 import org.apache.hertzbeat.common.entity.manager.bulletin.Bulletin;
 import org.apache.hertzbeat.common.entity.manager.bulletin.BulletinDto;
+import org.apache.hertzbeat.common.entity.manager.bulletin.BulletinVo;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.PageRequest;
 import org.springframework.data.jpa.domain.Specification;
@@ -55,6 +56,6 @@ public interface BulletinService {
      * @param pageRequest Paging parameters
      * @return The query results
      */
-    Page<Bulletin> getBulletins(Specification<Bulletin> specification, 
PageRequest pageRequest);
+    Page<BulletinVo> getBulletins(Specification<Bulletin> specification, 
PageRequest pageRequest);
 
 }
diff --git 
a/manager/src/main/java/org/apache/hertzbeat/manager/service/impl/BulletinServiceImpl.java
 
b/manager/src/main/java/org/apache/hertzbeat/manager/service/impl/BulletinServiceImpl.java
index b13cdf173..cd5878fd5 100644
--- 
a/manager/src/main/java/org/apache/hertzbeat/manager/service/impl/BulletinServiceImpl.java
+++ 
b/manager/src/main/java/org/apache/hertzbeat/manager/service/impl/BulletinServiceImpl.java
@@ -21,16 +21,22 @@
 package org.apache.hertzbeat.manager.service.impl;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
+import java.util.stream.Collectors;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.hertzbeat.common.entity.manager.bulletin.BulletinDto;
+import org.apache.hertzbeat.common.entity.manager.bulletin.BulletinVo;
 import org.apache.hertzbeat.common.util.SnowFlakeIdGenerator;
 import org.apache.hertzbeat.manager.dao.BulletinDao;
 import org.apache.hertzbeat.common.entity.manager.bulletin.Bulletin;
+import org.apache.hertzbeat.manager.dao.MonitorDao;
 import org.apache.hertzbeat.manager.service.BulletinService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageImpl;
 import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Pageable;
 import org.springframework.data.jpa.domain.Specification;
 import org.springframework.stereotype.Service;
 
@@ -45,6 +51,7 @@ public class BulletinServiceImpl implements BulletinService {
     @Autowired
     private BulletinDao bulletinDao;
 
+
     /**
      * validate Bulletin
      *
@@ -83,14 +90,14 @@ public class BulletinServiceImpl implements BulletinService 
{
     @Override
     public boolean addBulletin(BulletinDto bulletinDto) {
         try {
-            List<Bulletin> bulletins = new ArrayList<>();
-            for (Long monitorId : bulletinDto.getMonitorIds()) {
+            List<Bulletin> bulletins = 
bulletinDto.getMonitorIds().stream().map(monitorId -> {
                 Bulletin bulletin = new Bulletin();
                 bulletin.setId(SnowFlakeIdGenerator.generateId());
                 bulletin.setMetrics(bulletinDto.getMetrics());
                 bulletin.setMonitorId(monitorId);
-                bulletins.add(bulletin);
-            }
+                bulletin.setApp(bulletinDto.getApp());
+                return bulletin;
+            }).collect(Collectors.toList());
             bulletinDao.saveAll(bulletins);
             return true;
         } catch (Exception e) {
@@ -106,7 +113,27 @@ public class BulletinServiceImpl implements 
BulletinService {
      * @return The query results
      */
     @Override
-    public Page<Bulletin> getBulletins(Specification<Bulletin> specification, 
PageRequest pageRequest) {
-       return bulletinDao.findAll(specification, pageRequest);
+    public Page<BulletinVo> getBulletins(Specification<Bulletin> 
specification, PageRequest pageRequest) {
+        List<BulletinVo> voList = new ArrayList<>();
+        Page<Bulletin> bulletinPage = Page.empty(pageRequest);
+
+        try {
+            bulletinPage = bulletinDao.findAll(specification, pageRequest);
+            voList = bulletinPage.stream().map(bulletin -> {
+                BulletinVo vo = new BulletinVo();
+                vo.setId(bulletin.getId());
+                vo.setTags(bulletin.getTags());
+                vo.setMetrics(bulletin.getMetrics());
+                vo.setMonitorId(bulletin.getMonitorId());
+                vo.setApp(bulletin.getApp());
+                return vo;
+            }).collect(Collectors.toList());
+        } catch (Exception e) {
+            log.error("Failed to query bulletin: {}", e.getLocalizedMessage(), 
e);
+        }
+        long total = bulletinPage.getTotalElements();
+        return new PageImpl<>(voList, pageRequest, total);
     }
+
+
 }
diff --git a/web-app/src/app/pojo/BulletinDefine.ts 
b/web-app/src/app/pojo/BulletinDefine.ts
index 400afd042..16a2396c7 100644
--- a/web-app/src/app/pojo/BulletinDefine.ts
+++ b/web-app/src/app/pojo/BulletinDefine.ts
@@ -18,10 +18,12 @@
  */
 
 
+import {TagItem} from "./NoticeRule";
+
 export class BulletinDefine {
   id!: number;
   monitorIds!: number[];
   app!: string;
   metrics!: string[];
-
+  tags!: TagItem[];
 }
diff --git a/web-app/src/app/routes/bulletin/bulletin.component.html 
b/web-app/src/app/routes/bulletin/bulletin.component.html
index 3fbd5b141..6bdc05b9f 100644
--- a/web-app/src/app/routes/bulletin/bulletin.component.html
+++ b/web-app/src/app/routes/bulletin/bulletin.component.html
@@ -56,73 +56,76 @@
   </ng-template>
 </app-toolbar>
 
-<nz-table
-  #fixedTable
-  [nzData]="defines"
-  [nzPageIndex]="pageIndex"
-  [nzPageSize]="pageSize"
-  [nzTotal]="total"
-  nzFrontPagination="false"
-  [nzLoading]="tableLoading"
-  nzShowSizeChanger
-  [nzShowTotal]="rangeTemplate"
-  [nzPageSizeOptions]="[8, 15, 25]"
-  (nzQueryParams)="onTablePageChange($event)"
-  nzShowPagination="true"
-  [nzScroll]="{ x: '1240px' }"
->
-  <thead>
-    <tr>
-      <th nzAlign="center" nzLeft nzWidth="3%" [(nzChecked)]="checkedAll" 
(nzCheckedChange)="onAllChecked($event)"></th>
-      <th nzAlign="center" nzWidth="16%">目标Host</th>
-      <th nzAlign="center" nzWidth="14%">{{ 'alert.setting.expr' | i18n }}</th>
-      <th nzAlign="center" nzWidth="8%">{{ 'alert.priority' | i18n }}</th>
-      <th nzAlign="center" nzWidth="8%">{{ 'alert.setting.times' | i18n }}</th>
-      <th nzAlign="center" nzWidth="20%">{{ 'alert.setting.template' | i18n 
}}</th>
-      <th nzAlign="center" nzWidth="8%">{{ 'alert.setting.default' | i18n 
}}</th>
-      <th nzAlign="center" nzWidth="8%">{{ 'alert.setting.enable' | i18n 
}}</th>
-      <th nzAlign="center" nzWidth="15%">{{ 'common.edit' | i18n }}</th>
-    </tr>
-  </thead>
-  <tbody>
-    <tr *ngFor="let data of fixedTable.data">
-      <td nzAlign="center" nzLeft [nzChecked]="checkedDefineIds.has(data.id)" 
(nzCheckedChange)="onItemChecked(data.id, $event)"></td>
-      <td nzAlign="center">
-        <button
-          nz-button
-          nzType="primary"
-          (click)="onOpenConnectModal(data.id, data.app)"
-          nz-tooltip
-          [disabled]="data.app"
-          [nzTooltipTitle]="'alert.setting.connect' | i18n"
-        >
-          <i nz-icon nzType="link" nzTheme="outline"></i>
-        </button>
-        <button
-          nz-button
-          nzType="primary"
-          (click)="onEditOneBulletinDefine(data.id)"
-          nz-tooltip
-          [nzTooltipTitle]="'alert.setting.edit' | i18n"
-        >
-          <i nz-icon nzType="edit" nzTheme="outline"></i>
-        </button>
-        <button
-          nz-button
-          nzDanger
-          nzType="primary"
-          (click)="onDeleteOneBulletinDefine(data.id)"
-          nz-tooltip
-          [nzTooltipTitle]="'alert.setting.delete' | i18n"
-        >
-          <i nz-icon nzType="delete" nzTheme="outline"></i>
-        </button>
-      </td>
-    </tr>
-  </tbody>
-</nz-table>
-
-<ng-template #rangeTemplate> {{ 'common.total' | i18n }} {{ total }} 
</ng-template>
+<nz-tabset nzType="card">
+  <nz-tab *ngFor="let d of defines1" [nzTitle]="d.app">
+    <nz-table
+      #fixedTable
+      [nzData]="defines"
+      [nzPageIndex]="pageIndex"
+      [nzPageSize]="pageSize"
+      [nzTotal]="total"
+      nzFrontPagination="false"
+      [nzLoading]="tableLoading"
+      nzShowSizeChanger
+      [nzShowTotal]="rangeTemplate"
+      [nzPageSizeOptions]="[8, 15, 25]"
+      (nzQueryParams)="onTablePageChange($event)"
+      nzShowPagination="true"
+      [nzScroll]="{ x: '1240px' }"
+    >
+      <thead>
+        <tr>
+          <th nzAlign="center" nzLeft nzWidth="3%" [(nzChecked)]="checkedAll" 
(nzCheckedChange)="onAllChecked($event)"></th>
+          <th nzAlign="center" nzWidth="16%">目标Host</th>
+          <ng-container *ngFor="let metric of d.metrics">
+            <th nzAlign="center">{{ metric }}</th>
+          </ng-container>
+          <th nzAlign="center" nzWidth="15%">{{ 'common.edit' | i18n }}</th>
+        </tr>
+      </thead>
+      <tbody>
+        <tr *ngFor="let data of fixedTable.data">
+          <td nzAlign="center" nzLeft 
[nzChecked]="checkedDefineIds.has(data.id)" 
(nzCheckedChange)="onItemChecked(data.id, $event)"></td>
+          <td nzAlign="center">
+            <button
+              nz-button
+              nzType="primary"
+              (click)="onOpenConnectModal(data.id, data.app)"
+              nz-tooltip
+              [disabled]="data.app"
+              [nzTooltipTitle]="'alert.setting.connect' | i18n"
+            >
+              <i nz-icon nzType="link" nzTheme="outline"></i>
+            </button>
+            <button
+              nz-button
+              nzType="primary"
+              (click)="onEditOneBulletinDefine(data.id)"
+              nz-tooltip
+              [nzTooltipTitle]="'alert.setting.edit' | i18n"
+            >
+              <i nz-icon nzType="edit" nzTheme="outline"></i>
+            </button>
+            <button
+              nz-button
+              nzDanger
+              nzType="primary"
+              (click)="onDeleteOneBulletinDefine(data.id)"
+              nz-tooltip
+              [nzTooltipTitle]="'alert.setting.delete' | i18n"
+            >
+              <i nz-icon nzType="delete" nzTheme="outline"></i>
+            </button>
+          </td>
+          <ng-container *ngFor="let metric of d.metrics">
+            <td nzAlign="center"></td>
+          </ng-container>
+        </tr>
+      </tbody>
+    </nz-table>
+    <ng-template #rangeTemplate> {{ 'common.total' | i18n }} {{ total }} 
</ng-template>
+  </nz-tab>
+</nz-tabset>
 
 <!-- new bulletin modal -->
 <nz-modal
diff --git a/web-app/src/app/routes/bulletin/bulletin.component.ts 
b/web-app/src/app/routes/bulletin/bulletin.component.ts
index b2343a016..59029a364 100644
--- a/web-app/src/app/routes/bulletin/bulletin.component.ts
+++ b/web-app/src/app/routes/bulletin/bulletin.component.ts
@@ -74,9 +74,14 @@ export class BulletinComponent implements OnInit {
   appEntries: Array<{ value: any; key: string }> = [];
   checkedNodeList: NzTreeNode[] = [];
   monitors: Monitor[] = [];
-  switchExportTypeModalFooter: ModalButtonOptions[] = [
-    { label: this.i18nSvc.fanyi('common.button.cancel'), type: 'default', 
onClick: () => (this.isSwitchExportTypeModalVisible = false) }
+  defines1 = [
+    {
+      id: 1,
+      app: 'App1',
+      metrics: ['Metric1', 'Metric2']
+    }
   ];
+
   ngOnInit(): void {
     this.loadBulletinDefineTable();
   }
@@ -521,7 +526,6 @@ export class BulletinComponent implements OnInit {
             if (this.monitors != null) {
               this.isMonitorListLoading = true;
             }
-            console.log(this.monitors);
           } else {
             console.warn(message.msg);
           }
@@ -532,9 +536,10 @@ export class BulletinComponent implements OnInit {
       );
   }
 
-  onAppChange(appKey: string): void {
-    if (appKey) {
-      this.onSearchTreeNodes(appKey);
+  onAppChange(app: string): void {
+    if (app) {
+      this.onSearchMonitorsByApp(app);
+      this.onSearchTreeNodes(app);
     } else {
       this.hierarchies = [];
       this.treeNodes = [];


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to