wjx 2 anos atrás
pai
commit
ad6ecae0d0

+ 19 - 12
src/components/EarlyWarning/addEdit.tsx

@@ -1,7 +1,7 @@
-import { DeleteOutlined, PlusOutlined, QuestionCircleOutlined } from "@ant-design/icons"
-import { Button, DatePicker, Form, Input, InputNumber, message, Modal, Popconfirm, Select, Space, Switch, TimePicker, Tooltip } from "antd"
-import { RuleObject } from "antd/es/form"
-import { StoreValue } from "antd/es/form/interface"
+import { useAjax } from "@/Hook/useAjax"
+import { addSysWarningRuleApi } from "@/services/adMonitor/earlyWarning"
+import { DeleteOutlined, PlusOutlined } from "@ant-design/icons"
+import { Button, Form, Input, InputNumber, message, Modal, Popconfirm, Select, Space, Switch } from "antd"
 import React from "react"
 import { MonitorFieldEnum, WarningTypeEnum } from "./config"
 import './index.less'
@@ -16,19 +16,21 @@ interface Props {
 const AddEdit: React.FC<Props> = (props) => {
 
     /******************************/
-    const { visible, onClose } = props
+    const { visible, onClose, onChange } = props
     const [form] = Form.useForm();
     const rules = Form.useWatch('rules', form);
+
+    const addSysWarningRule = useAjax((params) => addSysWarningRuleApi(params))
     /******************************/
 
 
     const handleOk = () => {
         console.log(JSON.stringify(rules));
         form.validateFields().then(values => {
-            console.log(values);
             if (values?.rules) {
                 let newValues = JSON.parse(JSON.stringify(values))
-                let params = newValues?.rules?.map((item: any) => {
+                let { rules, defaultRule, enable, notifyFrequency, ruleName, warningType } = newValues
+                let params = rules?.map((item: any) => {
                     const { field, ...newItem } = item
                     return {
                         rule: Object.keys(newItem).map((item: any) => {
@@ -39,8 +41,11 @@ const AddEdit: React.FC<Props> = (props) => {
                         })
                     }
                 })
-                console.log('params--->', params);
-
+                console.log('params--->', { rules: params, notifyFrequency, ruleName, warningType, defaultRule: defaultRule ? 1 : 0, enable: enable ? 1 : 0 });
+                addSysWarningRule.run({ rules: params, notifyFrequency, ruleName, warningType, defaultRule: defaultRule ? 1 : 0, enable: enable ? 1 : 0 }).then(res => {
+                    message.success('新增成功')
+                    onChange?.()
+                })
             } else {
                 message.error('请添加最少一项规则')
             }
@@ -55,6 +60,7 @@ const AddEdit: React.FC<Props> = (props) => {
         visible={visible}
         onOk={handleOk}
         width={750}
+        confirmLoading={addSysWarningRule.loading}
         onCancel={() => onClose?.()}
     >
         <Form
@@ -66,6 +72,7 @@ const AddEdit: React.FC<Props> = (props) => {
             initialValues={{
                 enable: true,
                 notifyFrequency: 5,
+                defaultRule: false,
                 rules: [{
                     field: [],
                 }]
@@ -88,15 +95,15 @@ const AddEdit: React.FC<Props> = (props) => {
                         {Object.keys(WarningTypeEnum).map((item, index) => <Select.Option value={item} key={index}>{WarningTypeEnum[item]}</Select.Option>)}
                     </Select>
                 </Form.Item>
-                <Form.Item name="ruleName" label={<strong>规则名称</strong>} rules={[{ required: true, message: '请输入规则名称' }]}>
-                    <Input placeholder="规则名称" />
-                </Form.Item>
                 <Form.Item name="notifyFrequency" label={<strong>通知频率</strong>} rules={[{ required: true, message: '请选择通知频率' }]}>
                     <InputNumber min={5} addonAfter="分钟" />
                 </Form.Item>
                 <Form.Item name="enable" label={<strong>Enable?</strong>} valuePropName="checked" rules={[{ required: true }]}>
                     <Switch />
                 </Form.Item>
+                <Form.Item name="defaultRule" label={<strong>是否默认规则</strong>} rules={[{ required: true }]}>
+                    <Switch />
+                </Form.Item>
             </div>
             <Form.List name="rules">
                 {(fields, { add, remove }) => <>

+ 38 - 5
src/components/EarlyWarning/index.tsx

@@ -1,6 +1,10 @@
-import { Button, Drawer, Form, Modal, Space } from "antd"
-import React, { useState } from "react"
+import { useAjax } from "@/Hook/useAjax"
+import TableData from "@/pages/launchSystemNew/components/TableData"
+import { getSysWarningRuleListApi } from "@/services/adMonitor/earlyWarning"
+import { Button, Drawer, Form, Input, Modal, Space } from "antd"
+import React, { useEffect, useState } from "react"
 import AddEdit from "./addEdit"
+import tableConfig from "./tableConfig"
 
 
 
@@ -11,10 +15,21 @@ import AddEdit from "./addEdit"
 const EarlyWarning: React.FC = () => {
 
     /**************************/
-    const [visible, setVisible] = useState<boolean>(false)
-    const [addVisible, setAddVisible] = useState<boolean>(true)
+    const [visible, setVisible] = useState<boolean>(true)
+    const [addVisible, setAddVisible] = useState<boolean>(false)
+    const [queryParams, setQueryParams] = useState<{ ruleName?: string }>({})
+
+    const getSysWarningRuleList = useAjax((params) => getSysWarningRuleListApi(params))
     /**************************/
 
+    // 获取列表
+    useEffect(() => {
+        getList()
+    }, [])
+
+    const getList = () => {
+        getSysWarningRuleList.run(queryParams)
+    }
 
     return <>
         <Button type="primary" onClick={() => setVisible(true)}>监控预警</Button>
@@ -28,7 +43,25 @@ const EarlyWarning: React.FC = () => {
             width='800px'
         >
             <Space direction="vertical">
-                <Button type="primary" onClick={() => setAddVisible(true)}>设置预警</Button>
+                <Space>
+                    <Input placeholder="请输入规则名字" value={queryParams?.ruleName} onChange={(e) => setQueryParams({ ...queryParams, ruleName: e.target.value })} />
+                    <Button type="primary" onClick={getList}>搜索</Button>
+                    <Button type="primary" onClick={() => setAddVisible(true)}>设置预警</Button>
+                </Space>
+
+                <TableData
+                    isCard={false}
+                    columns={() => tableConfig()}
+                    ajax={getSysWarningRuleList}
+                    dataSource={getSysWarningRuleList?.data}
+                    loading={getSysWarningRuleList?.loading}
+                    scroll={{ y: 560 }}
+                    total={getSysWarningRuleList?.data?.length}
+                    gutter={[0, 10]}
+                    leftChild={<Space direction='vertical'>
+
+                    </Space>}
+                />
             </Space>
         </Drawer>}
 

+ 52 - 0
src/components/EarlyWarning/tableConfig.tsx

@@ -0,0 +1,52 @@
+import { Badge, Tag } from 'antd'
+import React from 'react'
+import { WarningTypeEnum } from './config'
+function tableConfig(): any {
+    return [
+        {
+            title: 'ID',
+            dataIndex: 'id',
+            key: 'id',
+            align: 'center',
+            width: 55,
+        },
+        {
+            title: '规则名称',
+            dataIndex: 'ruleName',
+            key: 'ruleName',
+            width: 120,
+            ellipsis: true,
+        },
+        {
+            title: '通知频率',
+            dataIndex: 'notifyFrequency',
+            key: 'notifyFrequency',
+            align: 'center',
+            width: 70,
+            render: (a: string, b: any) => {
+                return <span>{a}分钟</span>
+            }
+        },
+        {
+            title: '告警方式',
+            dataIndex: 'warningType',
+            key: 'warningType',
+            align: 'center',
+            width: 90,
+            render: (a: string[], b: any) => {
+                return a?.map((item, index) => <Tag color={['#f50', '#2db7f5'][index]} key={index}>{WarningTypeEnum[item]}</Tag>)
+            }
+        },
+        {
+            title: '是否默认规则',
+            dataIndex: 'defaultRule',
+            key: 'defaultRule',
+            align: 'center',
+            width: 70,
+            render: (a: 0 | 1, b: any) => {
+                return <Badge status={{'0' : 'error', '1': 'success'}[a] as any} text={{'0': '否', '1': '是'}[a]}/>
+            }
+        },
+    ]
+}
+export default tableConfig

+ 75 - 0
src/services/adMonitor/earlyWarning.ts

@@ -0,0 +1,75 @@
+import { api } from '../api'
+import { request } from 'umi'
+/***********告警接口**************/
+
+export interface AddSysWarningRuleProps {
+    // 1:默认规则;0:非默认规则;默认规则仅能创建一条
+    defaultRule: 0 | 1,
+    // 1:规则启用;0:规则禁用
+    enable: 0 | 1,
+    // 通知频率(分钟),最少五分钟
+    notifyFrequency: number,
+    // 修改ID 
+    ruleId: number,
+    // 规则名称
+    ruleName: string,
+    // 规则列表
+    rules: {
+        rule: {
+            field: string,
+            condition: '>' | '>=' | '<' | '<=' | '=',
+            value: string
+        }
+    }[],
+    warningType: Array<'SMS' | 'DING_TALK'>
+}
+/** 设置预警 */
+export async function addSysWarningRuleApi(data: AddSysWarningRuleProps) {
+    return request(`${api}/adq/sysWarningRule/add`, {
+        method: 'POST',
+        data
+    })
+}
+
+
+/**
+ * 告警规则下的广告列表
+ * @param ruleId 
+ * @returns 
+ */
+export async function getSysWarningRuleApi(ruleId: number) {
+    return request(`${api}/adq/sysWarningRule/adList`, {
+        method: 'GET',
+        params: { ruleId }
+    })
+}
+
+/**
+ * 删除告警规则
+ * @param ruleIds 
+ * @returns 
+ */
+export async function delSysWarningRuleApi(ruleIds: string) {
+    return request(`${api}/adq/sysWarningRule/delete/${ruleIds}`, {
+        method: 'POST'
+    })
+}
+
+/** */
+// export async function delAdSysWarningRuleApi(ruleIds: string) {
+//     return request(`${api}/adq/sysWarningRule/delete/${ruleIds}`, {
+//         method: 'POST'
+//     })
+// }
+
+/**
+ * 告警规则列表
+ * @param params 
+ * @returns 
+ */
+export async function getSysWarningRuleListApi(params: { ruleName?: string }) {
+    return request(`${api}/adq/sysWarningRule/list`, {
+        method: 'GET',
+        params
+    })
+}