import React, { useState, useRef, useEffect } from "react"; import { connect } from "react-redux"; import { Modal, Form, Notification } from "@douyinfe/semi-ui"; import { IconAlertCircle } from '@douyinfe/semi-icons'; import './pushModal.less' function pushModal (props) { const { close, cancel, visible, dispatch, pepList, actions, pushEdit,//是否是编辑 editObj, user } = props; const { service } = actions; const form = useRef();//表单 const [abnormal, setAbnormal] = useState(false); //异常率推送机制disable const [usersList, setUsersList] = useState([]); //获取全部未删除用户 const [structure, setStructure] = useState(true); //结构物disable const [projectPoms, setProjectPoms] = useState([]); //获取已绑定项目 const [projectStructure, setProjectStructure] = useState([]); //获取绑定项目下结构物 const [timeTypeDis, setTimeTypeDis] = useState(true); //通知时效disable const [projectStatus, setProjectStatus] = useState([]); //获取项目状态列表 const timeTypePOMS = useRef([]);//表单 const [interval1, setInterval1] = useState(undefined); // const [interval2, setInterval2] = useState(undefined); // const [interval3, setInterval3] = useState(undefined); // const [deviceProportion, setDeviceProportion] = useState(undefined); // //初始化 useEffect(() => { getOrganizationUsersList()//获取全部未删除用户 getProjectPomsList()//获取已绑定项目 if (editObj.id) { getProjectStructureList(editObj.pomsProjectId) if (editObj.pomsProject?.pepProjectId) { getProjectStatusList()//获取项目状态列表 } else { setProjectStatus([{ construction_status: 'POMS', id: 'POMS' }]) timeTypePOMS.current = ['POMS'] } if (editObj.tactics == 'immediately') { setInterval1(editObj.tacticsParams?.interval) } else if (editObj.tactics == 'continue') { setInterval2(editObj.tacticsParams?.interval) } else if (editObj.tactics == 'abnormal_rate') { setInterval3(editObj.tacticsParams?.interval) setDeviceProportion(editObj.tacticsParams?.deviceProportion) } } }, []); function getOrganizationUsersList () {//获取全部未删除用户 dispatch(service.getOrganizationUsers()).then((res) => { if (res.success) { setUsersList(res.payload.data) } }) } function getProjectPomsList () {//获取已绑定项目 dispatch(service.getProjectPoms()).then((res) => { if (res.success) { setProjectPoms(res.payload?.data?.rows) } }) } function getProjectStructureList (value) {//获取绑定项目下结构物 dispatch(service.getProjectStructure({ pomsProjectId: value })).then((res) => { if (res.success) { let mylist = [] for (let i = 0; i < res.payload?.data.length; i++) { mylist.push(res.payload?.data[i].id) } setProjectStructure(res.payload?.data) form.current.setValue('strucId', mylist) form.current.validate(['strucId', 'timeType']) setStructure(false) setTimeTypeDis(false) } }) } function getProjectStatusList () {//获取项目状态列表 dispatch(service.getProjectStatus()).then((res) => { if (res.success) { setProjectStatus(res.payload?.data) let mylist = [] for (let i = 0; i < res.payload?.data.length; i++) { mylist.push(res.payload?.data[i].id) } form.current.setValue('timeType', mylist) form.current.validate(['strucId', 'timeType']) } }) } function handleOk () { //点击弹框确定 右边按钮 form.current .validate() .then((values) => { if (pushEdit) { let obj = JSON.parse(JSON.stringify(values)) if (obj.timeType[0] == 'POMS') { obj.timeType = [] } let regu = /^[0-9]*[1-9][0-9]*$/; if (obj.tactics == 'immediately') { if (obj.interval1) { if (regu.test(obj.interval1)) { if (obj.interval1 <= 1440) { obj.tacticsParams = { interval: obj.interval1 } delete obj.interval1 delete obj.interval2 delete obj.interval3 delete obj.deviceProportion } else { Notification.error({ content: '即时推送时间不能大于1440分钟', duration: 2, }) } } else { Notification.error({ content: '即时推送时间应为正整数', duration: 2, }) } } else { Notification.error({ content: '即时推送时间应为正整数', duration: 2, }) } } else if (obj.tactics == 'continue') { if (obj.interval2) { if (regu.test(obj.interval2)) { if (obj.interval2 <= 1440) { obj.tacticsParams = { interval: obj.interval2 } delete obj.interval1 delete obj.interval2 delete obj.interval3 delete obj.deviceProportion } else { Notification.error({ content: '持续时长推送时间不能大于1440分钟', duration: 2, }) } } else { Notification.error({ content: '持续时长推送时间应为正整数', duration: 2, }) } } else { Notification.error({ content: '持续时长推送时间应为正整数', duration: 2, }) } } else { if (regu.test(obj.interval3) && regu.test(obj.deviceProportion)) { if (obj.interval3 <= 720 && obj.deviceProportion <= 100) { obj.tacticsParams = { interval: obj.interval3, deviceProportion: obj.deviceProportion } delete obj.interval1 delete obj.interval2 delete obj.interval3 delete obj.deviceProportion } else if (obj.interval3 <= 720 && obj.deviceProportion > 100) { Notification.error({ content: '异常率推送异常率不能超过100%', duration: 2, }) } else if (obj.interval3 > 720 && obj.deviceProportion <= 100) { Notification.error({ content: '异常率推送时间不能超过720小时', duration: 2, }) } else { Notification.error({ content: '异常率推送时间不能超过720小时', duration: 2, }) Notification.error({ content: '异常率推送异常率不能超过100%', duration: 2, }) } } else if (regu.test(obj.interval3) && !regu.test(obj.deviceProportion)) { Notification.error({ content: '异常率推送异常率应为正整数', duration: 2, }) } else if (!regu.test(obj.interval3) && regu.test(obj.deviceProportion)) { Notification.error({ content: '异常率推送时间应为正整数', duration: 2, }) } else { Notification.error({ content: '异常率推送异常率应为正整数', duration: 2, }) Notification.error({ content: '异常率推送时间应为正整数', duration: 2, }) } } dispatch(service.postPush({ pushId: pushId, ...obj, msg: '编辑推送配置' })).then((res) => {//获取项企(PEP)全部部门及其下用户 if (res.success) { close(); } }) } else { let obj = JSON.parse(JSON.stringify(values)) if (obj.timeType[0] == 'POMS') { obj.timeType = [] } let regu = /^[0-9]*[1-9][0-9]*$/; if (obj.tactics == 'immediately') { if (obj.interval1) { if (regu.test(obj.interval1)) { if (obj.interval1 <= 1440) { obj.tacticsParams = { interval: obj.interval1 } delete obj.interval1 delete obj.interval2 delete obj.interval3 delete obj.deviceProportion } else { Notification.error({ content: '即时推送时间不能大于1440分钟', duration: 2, }) } } else { Notification.error({ content: '即时推送时间应为正整数', duration: 2, }) } } else { Notification.error({ content: '即时推送时间应为正整数', duration: 2, }) } } else if (obj.tactics == 'continue') { if (obj.interval2) { if (regu.test(obj.interval2)) { if (obj.interval2 <= 1440) { obj.tacticsParams = { interval: obj.interval2 } delete obj.interval1 delete obj.interval2 delete obj.interval3 delete obj.deviceProportion } else { Notification.error({ content: '持续时长推送时间不能大于1440分钟', duration: 2, }) } } else { Notification.error({ content: '持续时长推送时间应为正整数', duration: 2, }) } } else { Notification.error({ content: '持续时长推送时间应为正整数', duration: 2, }) } } else { if (regu.test(obj.interval3) && regu.test(obj.deviceProportion)) { if (obj.interval3 <= 720 && obj.deviceProportion <= 100) { obj.tacticsParams = { interval: obj.interval3, deviceProportion: obj.deviceProportion } delete obj.interval1 delete obj.interval2 delete obj.interval3 delete obj.deviceProportion } else if (obj.interval3 <= 720 && obj.deviceProportion > 100) { Notification.error({ content: '异常率推送异常率不能超过100%', duration: 2, }) } else if (obj.interval3 > 720 && obj.deviceProportion <= 100) { Notification.error({ content: '异常率推送时间不能超过720小时', duration: 2, }) } else { Notification.error({ content: '异常率推送时间不能超过720小时', duration: 2, }) Notification.error({ content: '异常率推送异常率不能超过100%', duration: 2, }) } } else if (regu.test(obj.interval3) && !regu.test(obj.deviceProportion)) { Notification.error({ content: '异常率推送异常率应为正整数', duration: 2, }) } else if (!regu.test(obj.interval3) && regu.test(obj.deviceProportion)) { Notification.error({ content: '异常率推送时间应为正整数', duration: 2, }) } else { Notification.error({ content: '异常率推送异常率应为正整数', duration: 2, }) Notification.error({ content: '异常率推送时间应为正整数', duration: 2, }) } } dispatch(service.postPush({ ...obj, msg: '新增推送配置' })).then((res) => {//获取项企(PEP)全部部门及其下用户 if (res.success) { close(); } }) } }) } function handleCancel () { cancel(); //点击弹框取消 左边按钮 } return ( <>
{ console.log('values', values); for (var key in field) { if (key == 'tactics') { if (values.tactics == 'abnormal_rate') { form.current.setValue('alarmType', undefined) setAbnormal(true) } else { setAbnormal(false) } } if (key == 'pomsProjectId') { getProjectStructureList(values.pomsProjectId)//获取绑定项目下结构物 for (let i = 0; i < projectPoms.length; i++) { if (values.pomsProjectId == projectPoms[i].id) { if (projectPoms[i].pepProjectId) { getProjectStatusList()//获取项目状态列表 } else { setProjectStatus([{ construction_status: 'POMS', id: 'POMS' }]) form.current.setValue('timeType', ['POMS']) form.current.validate() } } } } } }} getFormApi={(formApi) => (form.current = formApi)} >
项目信息配置
{ projectPoms.map((item, index) => { return ( {item.pepProjectName || item.name} ) }) }
{ projectStructure.map((item, index) => { return ( {item.name} ) }) }
发现在 分钟内,有告警源新增,则通过【信鸽服务】发送一条通知信息。 } style={{ width: 198 }}> 即时推送机制 告警源持续产生时间超过 分钟,则通过【信鸽服务】发送一条通知信息。 } style={{ width: 198 }}> 持续时长推送机制 异常设备数量达到项目或结构物内设备总数量的 %,且持续时长超过 小时,则通过【信鸽服务】发送一条通知信息。 } style={{ width: 260 }}> 异常率推送机制
数据中断 数据异常 策略命中 视频异常 应用异常 设备异常
接收信息配置
0 ? editObj?.timeType : timeTypePOMS.current} disabled={timeTypeDis} multiple maxTagCount={3} > { projectStatus.map((item, index) => { return ( {item.construction_status} ) }) } { usersList.map((item, index) => { return ( {item.name} ) }) }
不在项目节点的通知策略,会自动失效.
启用 禁用
); } function mapStateToProps (state) { const { auth, global, members } = state; return { // loading: members.isRequesting, user: auth.user, actions: global.actions, // members: members.data, }; } export default connect(mapStateToProps)(pushModal);