Skip to content

Commit

Permalink
[feature] add threshold rule query condition. (#1237)
Browse files Browse the repository at this point in the history
  • Loading branch information
zqr10159 authored Sep 9, 2023
1 parent d486f19 commit d285d6f
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,40 @@ public ResponseEntity<Message<Void>> deleteAlertDefines(
return ResponseEntity.ok(message);
}

@GetMapping("/app")
@Operation(summary = "Example Query the alarm definition list by app| 根据名称查询告警定义列表",
description = "You can obtain the list of alarm definitions by querying filter items | 根据查询过滤项获取告警定义信息列表")
public ResponseEntity<Message<Page<AlertDefine>>> getAlertDefinesByName(
@Parameter(description = "Alarm Definition app | 告警定义名称", example = "6565463543") @RequestParam(required = false) String app,
@Parameter(description = "Sort field, default id | 排序字段,默认id", example = "id") @RequestParam(defaultValue = "id") String sort,
@Parameter(description = "Sort mode: asc: ascending, desc: descending | 排序方式,asc:升序,desc:降序", example = "desc") @RequestParam(defaultValue = "desc") String order,
@Parameter(description = "List current page | 列表当前分页", example = "0") @RequestParam(defaultValue = "0") int pageIndex,
@Parameter(description = "Number of list pages | 列表分页数量", example = "8") @RequestParam(defaultValue = "8") int pageSize) {

Specification<AlertDefine> specification = (root, query, criteriaBuilder) -> {
List<Predicate> andList = new ArrayList<>();
if (app != null) {
Predicate predicate = criteriaBuilder.or(
criteriaBuilder.like(
criteriaBuilder.lower(root.get("app")),
"%" + app.toLowerCase() + "%"
),
criteriaBuilder.like(
criteriaBuilder.lower(root.get("app")),
"%" + app.toUpperCase() + "%"
)
);
andList.add(predicate);
}
Predicate[] predicates = new Predicate[andList.size()];
return criteriaBuilder.and(andList.toArray(predicates));
};
// 分页是必须的
Sort sortExp = Sort.by(new Sort.Order(Sort.Direction.fromString(order), sort));
PageRequest pageRequest = PageRequest.of(pageIndex, pageSize, sortExp);
Page<AlertDefine> alertDefinePage = alertDefineService.getAlertDefines(specification,pageRequest);
Message<Page<AlertDefine>> message = new Message<>(alertDefinePage);
return ResponseEntity.ok(message);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,20 @@
<i nz-icon nzType="delete" nzTheme="outline"></i>
{{ 'common.button.delete' | i18n }}
</button>
<button style="margin-right: 25px; float: right" nz-button nzType="primary" (click)="onFilterSearchAlertDefinesByName()">
{{ 'common.search' | i18n }}
</button>
<input
style="margin-right: 5px; float: right; width: 200px; border-radius: 9px; text-align: center; margin-right: 0"
nz-input
type="text"
[placeholder]="'alert.setting.target' | i18n"
nzSize="default"
(keyup.enter)="onFilterSearchAlertDefinesByName()"
[(ngModel)]="app"
/>
</div>
<div nz-col [nzXs]="{ span: 24 }" class="mobile-hide"> </div>

<nz-table
#fixedTable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class AlertSettingComponent implements OnInit {
private tagSvc: TagService,
@Inject(ALAIN_I18N_TOKEN) private i18nSvc: I18NService
) {}

app!: string;
pageIndex: number = 1;
pageSize: number = 8;
total: number = 0;
Expand All @@ -46,7 +46,6 @@ export class AlertSettingComponent implements OnInit {
checkedDefineIds = new Set<number>();

appHierarchies!: any[];

ngOnInit(): void {
this.loadAlertDefineTable();
// 查询监控层级
Expand Down Expand Up @@ -667,4 +666,29 @@ export class AlertSettingComponent implements OnInit {
});
}
// end 告警定义与监控关联model
//查询告警阈值
onFilterSearchAlertDefinesByName() {
this.tableLoading = true;
let filter$ = this.alertDefineSvc.getAlertDefinesByName(this.pageIndex - 1, this.pageSize, this.app).subscribe(
message => {
filter$.unsubscribe();
this.tableLoading = false;
this.checkedAll = false;
this.checkedDefineIds.clear();
if (message.code === 0) {
let page = message.data;
this.defines = page.content;
this.pageIndex = page.number + 1;
this.total = page.totalElements;
} else {
console.warn(message.msg);
}
},
error => {
this.tableLoading = false;
filter$.unsubscribe();
console.error(error.msg);
}
);
}
}
17 changes: 17 additions & 0 deletions web-app/src/app/service/alert-define.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,21 @@ export class AlertDefineService {
const options = { params: httpParams };
return this.http.get<Message<Page<AlertDefine>>>(alert_defines_uri, options);
}

public getAlertDefinesByName(pageIndex: number, pageSize: number, app: string): Observable<Message<Page<AlertDefine>>> {
pageIndex = pageIndex ? pageIndex : 0;
pageSize = pageSize ? pageSize : 8;

// 注意HttpParams是不可变对象 需要保存set后返回的对象为最新对象
let httpParams = new HttpParams();
httpParams = httpParams.appendAll({
sort: 'id',
order: 'desc',
pageIndex: pageIndex,
pageSize: pageSize,
app: app
});
const options = { params: httpParams };
return this.http.get<Message<Page<AlertDefine>>>(`${alert_defines_uri}/app`, options);
}
}

0 comments on commit d285d6f

Please sign in to comment.