Commit 0e110478 authored by wenmo's avatar wenmo

报警组下拉多选报警实例

parent d2dbb824
...@@ -8,6 +8,7 @@ import com.fasterxml.jackson.databind.JsonNode; ...@@ -8,6 +8,7 @@ import com.fasterxml.jackson.databind.JsonNode;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
...@@ -81,4 +82,12 @@ public class AlertInstanceController { ...@@ -81,4 +82,12 @@ public class AlertInstanceController {
alertInstance = alertInstanceService.getById(alertInstance.getId()); alertInstance = alertInstanceService.getById(alertInstance.getId());
return Result.succeed(alertInstance,"获取成功"); return Result.succeed(alertInstance,"获取成功");
} }
/**
* 获取可用的报警实例列表
*/
@GetMapping("/listEnabledAll")
public Result listEnabledAll() {
return Result.succeed(alertInstanceService.listEnabledAll(),"获取成功");
}
} }
...@@ -3,6 +3,8 @@ package com.dlink.service; ...@@ -3,6 +3,8 @@ package com.dlink.service;
import com.dlink.db.service.ISuperService; import com.dlink.db.service.ISuperService;
import com.dlink.model.AlertInstance; import com.dlink.model.AlertInstance;
import java.util.List;
/** /**
* AlertInstanceService * AlertInstanceService
* *
...@@ -10,4 +12,6 @@ import com.dlink.model.AlertInstance; ...@@ -10,4 +12,6 @@ import com.dlink.model.AlertInstance;
* @since 2022/2/24 19:52 * @since 2022/2/24 19:52
**/ **/
public interface AlertInstanceService extends ISuperService<AlertInstance> { public interface AlertInstanceService extends ISuperService<AlertInstance> {
List<AlertInstance> listEnabledAll();
} }
package com.dlink.service.impl; package com.dlink.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dlink.db.service.impl.SuperServiceImpl; import com.dlink.db.service.impl.SuperServiceImpl;
import com.dlink.mapper.AlertInstanceMapper; import com.dlink.mapper.AlertInstanceMapper;
import com.dlink.model.AlertInstance; import com.dlink.model.AlertInstance;
import com.dlink.service.AlertInstanceService; import com.dlink.service.AlertInstanceService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List;
/** /**
* AlertInstanceServiceImpl * AlertInstanceServiceImpl
* *
...@@ -14,4 +17,8 @@ import org.springframework.stereotype.Service; ...@@ -14,4 +17,8 @@ import org.springframework.stereotype.Service;
**/ **/
@Service @Service
public class AlertInstanceServiceImpl extends SuperServiceImpl<AlertInstanceMapper, AlertInstance> implements AlertInstanceService { public class AlertInstanceServiceImpl extends SuperServiceImpl<AlertInstanceMapper, AlertInstance> implements AlertInstanceService {
@Override
public List<AlertInstance> listEnabledAll() {
return list(new QueryWrapper<AlertInstance>().eq("enabled",1));
}
} }
...@@ -164,6 +164,16 @@ export function showJars(dispatch: any) { ...@@ -164,6 +164,16 @@ export function showJars(dispatch: any) {
}); });
}); });
} }
/*--- 刷新 报警实例 ---*/
export function showAlertInstance(dispatch: any) {
const res = getData('api/alertInstance/listEnabledAll');
res.then((result) => {
result.datas && dispatch && dispatch({
type: "Alert/saveInstance",
payload: result.datas,
});
});
}
/*--- 刷新 元数据表 ---*/ /*--- 刷新 元数据表 ---*/
export function showMetaDataTable(id:number) { export function showMetaDataTable(id:number) {
return getData('api/database/getSchemasAndTables',{id:id}); return getData('api/database/getSchemasAndTables',{id:id});
......
...@@ -12,7 +12,7 @@ import StudioLeftTool from "./StudioLeftTool"; ...@@ -12,7 +12,7 @@ import StudioLeftTool from "./StudioLeftTool";
import StudioRightTool from "./StudioRightTool"; import StudioRightTool from "./StudioRightTool";
import { import {
listSession, showCluster, showDataBase, getFillAllByVersion, listSession, showCluster, showDataBase, getFillAllByVersion,
showClusterConfiguration, showSessionCluster, showJars, showEnv showClusterConfiguration, showSessionCluster, showJars, showEnv,showAlertInstance
} from "@/components/Studio/StudioEvent/DDL"; } from "@/components/Studio/StudioEvent/DDL";
import {loadSettings} from "@/pages/Settings/function"; import {loadSettings} from "@/pages/Settings/function";
import DraggleLayout from "@/components/DraggleLayout"; import DraggleLayout from "@/components/DraggleLayout";
...@@ -59,6 +59,7 @@ const Studio = (props: any) => { ...@@ -59,6 +59,7 @@ const Studio = (props: any) => {
showDataBase(dispatch); showDataBase(dispatch);
listSession(dispatch); listSession(dispatch);
showJars(dispatch); showJars(dispatch);
showAlertInstance(dispatch);
showEnv(dispatch); showEnv(dispatch);
onResize(); onResize();
}, []); }, []);
......
import React, {useEffect, useState} from 'react'; import React, {useEffect, useState} from 'react';
import {Form, Button, Input, Modal, Select,Divider,Switch} from 'antd'; import {Form, Button, Input, Modal, Select,Tag,Switch} from 'antd';
import {AlertGroupTableListItem} from "@/pages/AlertGroup/data"; import {AlertGroupTableListItem} from "@/pages/AlertGroup/data";
import {JarStateType} from "@/pages/Jar/model";
import {connect} from "umi";
import {StateType} from "@/pages/FlinkSqlStudio/model";
import {AlertStateType} from "@/pages/AlertInstance/model";
import {AlertInstanceTableListItem} from "@/pages/AlertInstance/data";
import {buildFormData, getFormData} from "@/pages/AlertGroup/function";
export type AlertGroupFormProps = { export type AlertGroupFormProps = {
onCancel: (flag?: boolean) => void; onCancel: (flag?: boolean) => void;
onSubmit: (values: Partial<AlertGroupTableListItem>) => void; onSubmit: (values: Partial<AlertGroupTableListItem>) => void;
modalVisible: boolean; modalVisible: boolean;
values: Partial<AlertGroupTableListItem>; values: Partial<AlertGroupTableListItem>;
instance: AlertInstanceTableListItem[];
}; };
const Option = Select.Option; const Option = Select.Option;
...@@ -30,12 +37,24 @@ const AlertGroupForm: React.FC<AlertGroupFormProps> = (props) => { ...@@ -30,12 +37,24 @@ const AlertGroupForm: React.FC<AlertGroupFormProps> = (props) => {
onSubmit: handleSubmit, onSubmit: handleSubmit,
onCancel: handleModalVisible, onCancel: handleModalVisible,
modalVisible, modalVisible,
instance,
} = props; } = props;
const getAlertInstanceOptions = () => {
const itemList = [];
for (const item of instance) {
const tag = (<><Tag color="processing">{item.type}</Tag>{item.name}</>);
itemList.push(<Option key={item.id} value={item.id.toString()} label={tag}>
{tag}
</Option>)
}
return itemList;
};
const submitForm = async () => { const submitForm = async () => {
const fieldsValue = await form.validateFields(); const fieldsValue = await form.validateFields();
setFormVals({...formVals, ...fieldsValue}); setFormVals(buildFormData(formVals,fieldsValue));
handleSubmit({...formVals, ...fieldsValue}); handleSubmit(buildFormData(formVals,fieldsValue));
}; };
const renderContent = (formVals) => { const renderContent = (formVals) => {
...@@ -52,7 +71,14 @@ const AlertGroupForm: React.FC<AlertGroupFormProps> = (props) => { ...@@ -52,7 +71,14 @@ const AlertGroupForm: React.FC<AlertGroupFormProps> = (props) => {
label="报警实例" label="报警实例"
help="请选择报警组实例" help="请选择报警组实例"
> >
<Input placeholder="请选择报警实例"/> <Select
mode="multiple"
style={{width: '100%'}}
placeholder="请选择报警实例"
optionLabelProp="label"
>
{getAlertInstanceOptions()}
</Select>
</Form.Item> </Form.Item>
<Form.Item <Form.Item
name="note" name="note"
...@@ -95,12 +121,14 @@ const AlertGroupForm: React.FC<AlertGroupFormProps> = (props) => { ...@@ -95,12 +121,14 @@ const AlertGroupForm: React.FC<AlertGroupFormProps> = (props) => {
<Form <Form
{...formLayout} {...formLayout}
form={form} form={form}
initialValues={formVals} initialValues={getFormData(formVals)}
> >
{renderContent(formVals)} {renderContent(getFormData(formVals))}
</Form> </Form>
</Modal> </Modal>
); );
}; };
export default AlertGroupForm; export default connect(({Alert}: { Alert: AlertStateType }) => ({
instance: Alert.instance,
})) (AlertGroupForm);
import {AlertGroupTableListItem} from "@/pages/AlertGroup/data";
export const getFormData = (values: AlertGroupTableListItem) => {
let alertInstanceIds:string [] = [];
if(values&&values.alertInstanceIds&&values.alertInstanceIds!=''){
alertInstanceIds = values.alertInstanceIds.split(',');
}
return {...values,alertInstanceIds:alertInstanceIds};
}
export const buildFormData = (values: AlertGroupTableListItem,params: any) => {
let newValue = values;
if(params.alertInstanceIds){
newValue.alertInstanceIds = params.alertInstanceIds.join(',');
delete params.alertInstanceIds;
}
return {...newValue,...params};
}
...@@ -83,6 +83,9 @@ const AlertGroupTableList: React.FC<{}> = (props: any) => { ...@@ -83,6 +83,9 @@ const AlertGroupTableList: React.FC<{}> = (props: any) => {
title: '报警实例', title: '报警实例',
sorter: true, sorter: true,
dataIndex: 'alertInstanceIds', dataIndex: 'alertInstanceIds',
hideInTable: true,
hideInForm: true,
hideInSearch: true,
}, },
{ {
title: '注释', title: '注释',
...@@ -153,84 +156,102 @@ const AlertGroupTableList: React.FC<{}> = (props: any) => { ...@@ -153,84 +156,102 @@ const AlertGroupTableList: React.FC<{}> = (props: any) => {
actionRef={actionRef} actionRef={actionRef}
rowKey="id" rowKey="id"
search={{ search={{
labelWidth: 120, labelWidth: 120,
}} }}
toolBarRender={() => [ toolBarRender={() => [
<Button type="primary" onClick={() => handleModalVisible(true)}> <Button type="primary" onClick={() => handleModalVisible(true)}>
<PlusOutlined/> 新建 <PlusOutlined/> 新建
</Button>, </Button>,
]} ]}
request={(params, sorter, filter) => queryData(url, {...params, sorter, filter})} request={(params, sorter, filter) => queryData(url, {...params, sorter, filter})}
columns={columns} columns={columns}
rowSelection={{ rowSelection={{
onChange: (_, selectedRows) => setSelectedRows(selectedRows), onChange: (_, selectedRows) => setSelectedRows(selectedRows),
}} }}
/> />
{selectedRowsState?.length > 0 && ( {selectedRowsState?.length > 0 && (
<FooterToolbar <FooterToolbar
extra={ extra={
<div> <div>
已选择 <a style={{fontWeight: 600}}>{selectedRowsState.length}</a>&nbsp;&nbsp; 已选择 <a style={{fontWeight: 600}}>{selectedRowsState.length}</a>&nbsp;&nbsp;
<span> <span>
被禁用的集群配置共 {selectedRowsState.length - selectedRowsState.reduce((pre, item) => pre + (item.enabled ? 1 : 0), 0)} 被禁用的集群配置共 {selectedRowsState.length - selectedRowsState.reduce((pre, item) => pre + (item.enabled ? 1 : 0), 0)}
</span> </span>
</div> </div>
} }
>
<Button type="primary" danger
onClick={() => {
Modal.confirm({
title: '删除报警组',
content: '确定删除选中的报警组吗?',
okText: '确认',
cancelText: '取消',
onOk: async () => {
await handleRemove(url, selectedRowsState);
setSelectedRows([]);
actionRef.current?.reloadAndRest?.();
}
});
}}
> >
<Button type="primary" danger 批量删除
onClick={() => { </Button>
Modal.confirm({ <Button type="primary"
title: '删除报警组', onClick={() => {
content: '确定删除选中的报警组吗?', Modal.confirm({
okText: '确认', title: '启用报警组',
cancelText: '取消', content: '确定启用选中的报警组吗?',
onOk: async () => { okText: '确认',
await handleRemove(url, selectedRowsState); cancelText: '取消',
setSelectedRows([]); onOk: async () => {
actionRef.current?.reloadAndRest?.(); await updateEnabled(url, selectedRowsState, true);
} setSelectedRows([]);
}); actionRef.current?.reloadAndRest?.();
}} }
> });
批量删除 }}
</Button> >批量启用</Button>
<Button type="primary" <Button danger
onClick={() => { onClick={() => {
Modal.confirm({ Modal.confirm({
title: '启用报警组', title: '禁用报警组',
content: '确定启用选中的报警组吗?', content: '确定禁用选中的报警组吗?',
okText: '确认', okText: '确认',
cancelText: '取消', cancelText: '取消',
onOk: async () => { onOk: async () => {
await updateEnabled(url, selectedRowsState, true); await updateEnabled(url, selectedRowsState, false);
setSelectedRows([]); setSelectedRows([]);
actionRef.current?.reloadAndRest?.(); actionRef.current?.reloadAndRest?.();
} }
}); });
}} }}
>批量启用</Button> >批量禁用</Button>
<Button danger </FooterToolbar>
onClick={() => { )}
Modal.confirm({ <AlertGroupForm
title: '禁用报警组', onSubmit={async (value) => {
content: '确定禁用选中的报警组吗?', const success = await handleAddOrUpdate(url, value);
okText: '确认', if (success) {
cancelText: '取消', handleModalVisible(false);
onOk: async () => { setFormValues({});
await updateEnabled(url, selectedRowsState, false); if (actionRef.current) {
setSelectedRows([]); actionRef.current.reload();
actionRef.current?.reloadAndRest?.(); }
} }
}); }}
}} onCancel={() => {
>批量禁用</Button> handleModalVisible(false);
</FooterToolbar> }}
)} modalVisible={modalVisible}
values={{}}
/>
{formValues && Object.keys(formValues).length ? (
<AlertGroupForm <AlertGroupForm
onSubmit={async (value) => { onSubmit={async (value) => {
const success = await handleAddOrUpdate(url, value); const success = await handleAddOrUpdate(url, value);
if (success) { if (success) {
handleModalVisible(false); handleUpdateModalVisible(false);
setFormValues({}); setFormValues({});
if (actionRef.current) { if (actionRef.current) {
actionRef.current.reload(); actionRef.current.reload();
...@@ -238,55 +259,37 @@ const AlertGroupTableList: React.FC<{}> = (props: any) => { ...@@ -238,55 +259,37 @@ const AlertGroupTableList: React.FC<{}> = (props: any) => {
} }
}} }}
onCancel={() => { onCancel={() => {
handleModalVisible(false); handleUpdateModalVisible(false);
setFormValues({});
}} }}
modalVisible={modalVisible} modalVisible={updateModalVisible}
values={{}} values={formValues}
/> />
{formValues && Object.keys(formValues).length ? ( ): null}
<AlertGroupForm <Drawer
onSubmit={async (value) => { width={600}
const success = await handleAddOrUpdate(url, value); visible={!!row}
if (success) { onClose={() => {
handleUpdateModalVisible(false); setRow(undefined);
setFormValues({}); }}
if (actionRef.current) { closable={false}
actionRef.current.reload(); >
} {row?.name && (
} <ProDescriptions<AlertGroupTableListItem>
}} column={2}
onCancel={() => { title={row?.name}
handleUpdateModalVisible(false); request={async () => ({
setFormValues({});
}}
modalVisible={updateModalVisible}
values={formValues}
/>
): null}
<Drawer
width={600}
visible={!!row}
onClose={() => {
setRow(undefined);
}}
closable={false}
>
{row?.name && (
<ProDescriptions<AlertGroupTableListItem>
column={2}
title={row?.name}
request={async () => ({
data: row || {}, data: row || {},
})} })}
params={{ params={{
id: row?.name, id: row?.name,
}} }}
columns={columns} columns={columns}
/> />
)} )}
</Drawer> </Drawer>
</PageContainer> </PageContainer>
); );
}; };
export default AlertGroupTableList; export default AlertGroupTableList;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment