import React, { useState, useEffect, useRef } from "react"; import { connect } from "react-redux"; import { Button, Form, Modal, Skeleton, Pagination, Table, Tooltip, Toast, CheckboxGroup, Checkbox, } from "@douyinfe/semi-ui"; import { SkeletonScreen, } from "$components"; import moment from "moment"; const TableData = ({ alarmDataGroup, route, dispatch, actions, collectData, setSetup, exhibition, pepProjectId, selected, setSelected, setIfBulk, setConfirm, genre, setGenre, query, setQuery, tableData, setTableData, location, user, statusId, setStatusId }) => { const { problem } = actions const [count, setCount] = useState(0) // const [checkAll, setCheckAll] = useState(true) //查询 const api = useRef(); const search = useRef({ state: 'new', keywordTarget: '', keyword: '', kindId: '', groupUnitId: '', statusId: '', errType: '', confirmState: '', onlineState: '', sustainTimeStart: '', sustainTimeEnd: '' }) const kindName = useRef() const groupId = useRef() let title = { dataLnterrupt: "数据中断详情", dataAbnormal: "数据异常详情", strategyHit: "策略命中详情", videoAbnormal: "视频异常详情", useAbnormal: "应用异常详情", deviceAbnormal: "设备异常详情" } const [exportUrl, setExportUrl] = useState('') const [typeSet, setTypeSet] = useState(false) const [typeId, setTypeId] = useState([]) const [check, setCheck] = useState([]) useEffect(() => { switch (route) { case 'useAbnormal': dispatch(problem.getAlarmLnspectionApi({ ...search.current, pepProjectId: pepProjectId })).then((res) => { if (res.success) { let typeData = { element: "元素异常", apiError: "接口报错 ", timeout: "加载超时" } let tableDatas = res.payload.data?.rows.map(v => ({ key: v.id, id: v.id, projectName: v.app?.projectCorrelations?.map(r => (r.name ? { id: r.id, name: r.name, state: 'PMOS' } : { id: r.id, name: r.pepProject?.projectName, state: r.pepProject?.constructionStatus }))?.filter(c => c), appName: v.app?.name, url: v.app?.url, createTime: v.createTime ? moment(v.createTime).format("YYYY-MM-DD HH:mm:ss") : "", updateTime: v.updateTime ? moment(v.updateTime).format("YYYY-MM-DD HH:mm:ss") : "", confirmTime: v.confirmTime ? moment(v.confirmTime).format("YYYY-MM-DD HH:mm:ss") : "", alarmContent: v.alarmContent || '无', screenshot: v.screenshot, type: v.type ? typeData[v.type] : "", confirm: v.confirm, confirmAuto: v.confirmAuto, projectLocal: v.Project, })) setCount(tableDatas?.length || 0); setTableData(tableDatas) } }) break; case 'videoAbnormal': dispatch(problem.getAlarmVideoList({ ...search.current, pepProjectId: pepProjectId })).then((res) => { if (res.success) { let tableDatas = res.payload.data?.map(v => ({ key: v.alarmId, id: v.alarmId, StructureName: v.struc, projectName: v.pomsProject?.map(r => (r.name ? { id: r.id, name: r.name, state: 'PMOS' } : { id: r.id, name: r.pepProject?.projectName, state: r.pepProject?.constructionStatus }))?.filter(c => c), createTime: v.createTime ? moment(v.createTime).format("YYYY-MM-DD HH:mm:ss") : "", updateTime: v.updateTime ? moment(v.updateTime).format("YYYY-MM-DD HH:mm:ss") : "", confirmTime: v.confirmTime ? moment(v.confirmTime).format("YYYY-MM-DD HH:mm:ss") : "", SourceName: v.cameraName, yingshiToken: v.yingshiToken, AlarmContent: v.statusDescribe, station: v.station || [], resolve: v.resolve || [], cameraChannelNo: v.cameraChannelNo, cameraSerialNo: v.cameraSerialNo, cameraKindId: v.cameraKindId ? kindName.current?.find(u => u.value == v.cameraKindId)?.name : "", venderName: v.venderName, platform: v.platform, confirm: v.confirmContent, camerOnline: v.camerOnline, autoRestore: v.autoRestore, projectLocal: v.Project, })) setCount(tableDatas?.length || 0); setTableData(tableDatas) } }) break; default: if (genre?.length > 0 && (route === 'dataAbnormal' ? typeId?.length > 0 : true)) { dispatch(problem.getAlarmDataList({ ...(route === 'dataLnterrupt' ? { timestamps: true } : {}), ...(route === 'dataAbnormal' ? { groupUnitId: typeId?.length > 0 ? typeId?.join(',') : "", } : {}), ...query, ...(api.current?.getValues() || {}), groupId: groupId.current.map(v => v.id).join(), pepProjectId: pepProjectId, })).then((res) => { if (res.success) { setCount(res.payload.data?.count || 0) let tableDatas = res.payload.data?.rows?.map(v => ({ key: v.AlarmId, id: v.AlarmId, StructureName: v.StructureName, projectName: v.pomsProject?.map(r => (r.name ? { id: r.id, name: r.name, state: 'PMOS' } : { id: r.id, name: r.pepProject?.projectName, state: r.pepProject?.constructionStatus }))?.filter(c => c), createTime: v.StartTime ? moment(v.StartTime).format("YYYY-MM-DD HH:mm:ss") : "", updateTime: v.EndTime ? moment(v.EndTime).format("YYYY-MM-DD HH:mm:ss") : "", confirmTime: v.confirmedTime ? moment(v.confirmedTime).format("YYYY-MM-DD HH:mm:ss") : "", SourceName: v.SourceName, AlarmGroupUnit: v.AlarmGroupUnit ? genre?.find(r => r.value == v.AlarmGroupUnit)?.name : "无", Strategy: v.AlarmGroupUnit ? genre?.find(r => r.value == v.AlarmGroupUnit)?.name : "", type: (v.AlarmGroup == 4 || v.AlarmGroup == 5) ? v.DeviceStatus == 0 ? "离线" : '' : v.AlarmGroupUnit ? genre?.find(r => r.value == v.AlarmGroupUnit)?.name : "", cameraKindId: v.AlarmGroupUnit ? genre?.find(r => r.value == v.AlarmGroupUnit)?.name : "", AlarmCodeName: v.AlarmCodeName, CurrentLevel: v.CurrentLevel, detailCount: v.detailCount, AlarmContent: v.AlarmContent, State: v.State, alarmType: v.alarmType, confirm: v.confirmedContent, station: v.StructureLongitude && v.StructureLatitude ? v.StructureLongitude + ',' + v.StructureLatitude : "", projectLocal: v.Project, AlarmGroup: v.AlarmGroup, })) setTableData(tableDatas) } }) } break; } }, [query, genre, pepProjectId, typeId]) useEffect(() => { if (alarmDataGroup?.length > 0) { if (location) { search.current = { ...search.current, ...location, state: 'new' } api.current?.setValues({ ...location, state: 'new' }) } if (route !== 'videoAbnormal' && route !== 'useAbnormal') { let data if (route == 'dataLnterrupt') data = alarmDataGroup?.filter(v => (v.desc == '数据中断' || v.desc == '掉线' || v.desc == '不活跃')) if (route == 'dataAbnormal') data = alarmDataGroup?.filter(v => (v.desc == '数据异常' || v.desc == '策略命中')) // if (route == 'strategyHit') data = alarmDataGroup?.filter(v => v.desc == '策略命中') // if (route == 'deviceAbnormal') data = alarmDataGroup?.filter(v => v.desc == '掉线' || v.desc == '不活跃') groupId.current = data let genreData = [] data?.map(v => { v?.unit?.map(vv => { genreData.push({ name: vv.name, value: vv.id }) }) }) setGenre(genreData) if (route == 'dataAbnormal') { dispatch(problem.getExceptionTypeCheck({ userId: user?.id, })).then(res => { if (res.success) { setTypeId(res.payload.data?.typeId || [8, 40, 41, 48, 49]) } }) } } if (route == 'useAbnormal') { setGenre({ element: "元素异常", apiError: "接口报错 ", timeout: "加载超时" }) } if (route == 'videoAbnormal') { dispatch(problem.getAlarmVideoDeviceKind()).then((res) => { if (res.success) { kindName.current = res.payload.data.map(v => ({ name: v.kind, value: v.id })) setGenre(res.payload.data.map(v => ({ name: v.kind, value: v.id }))) } }) dispatch(problem.getAlarmVideoExceptionType()).then((res) => { if (res.success) { setStatusId(res.payload.data.map(v => ({ name: v.describe, value: v.statusId }))) } }) } } return () => { } }, [route, alarmDataGroup]) const handleExport = () => { let url = '' let { keywordTarget, keyword = '', errType = '', state = '', kindId = '', statusId = '', groupUnitId = '', confirmState = '', onlineState = '', sustainTimeStart = '', sustainTimeEnd = '' } = search.current if (sustainTimeStart && sustainTimeEnd) { let range = moment(sustainTimeEnd).diff(moment(sustainTimeStart), 'minutes') if (range > 24 * 60 * 7) { Toast.warning({ content: '导出自定义时间跨度不超过7天', duration: 3, }) return false; } } else { sustainTimeStart = moment().add(-7, 'day').format("YYYY-MM-DD HH:mm:ss") sustainTimeEnd = moment().format("YYYY-MM-DD HH:mm:ss") } switch (route) { case 'useAbnormal': dispatch(problem.getAlarmLnspectionApi({ ...search.current, sustainTimeStart, sustainTimeEnd, pepProjectId: pepProjectId })).then((res) => { if (res.success) { if (res.payload.data.count) { url = `alarm/application/api?token=${user.token}&toExport=1×tamp=${moment().valueOf()}&keyword=${keyword}&errType=${errType}` + `&state=${state}&sustainTimeStart=${sustainTimeStart}&sustainTimeEnd=${sustainTimeEnd}&pepProjectId=${pepProjectId || ''}` setExportUrl(url); } else { Toast.info({ content: '暂无可导出的数据', duration: 3, }) } } }) break; case 'videoAbnormal': dispatch(problem.getAlarmVideoList({ ...search.current, limit: 1, sustainTimeStart, sustainTimeEnd, pepProjectId: pepProjectId })).then((res) => { if (res.success) { if (res.payload.data.length) { url = `alarm/video/list?token=${user.token}&toExport=1×tamp=${moment().valueOf()}&keywordTarget=${keywordTarget}` + `&keyword=${keyword}&kindId=${kindId}&statusId=${statusId}&state=${state}&sustainTimeStart=${sustainTimeStart}&sustainTimeEnd=${sustainTimeEnd}` + `&pepProjectId=${pepProjectId || ''}` setExportUrl(url); } else { Toast.info({ content: '暂无可导出的数据', duration: 3, }) } } }) break; default: dispatch(problem.getAlarmDataList({ ...(route === 'dataLnterrupt' ? { timestamps: true } : {}), ...query, ...search.current, limit: 1, sustainTimeStart, sustainTimeEnd, groupId: groupId.current.map(v => v.id).join(), pepProjectId: pepProjectId })).then((res) => { if (res.success) { if (res.payload.data.count) { let groups = { "dataLnterrupt": "1,4,5", "dataAbnormal": "2,3", // "strategyHit": "3", // "deviceAbnormal": "4,5" } url = `alarm/data/list?token=${user.token}&toExport=1×tamp=${true}&state=${state}&keywordTarget=${keywordTarget}&keyword=${keyword}&kindId=${kindId}` + `&groupUnitId=${groupUnitId}&errType=${errType}&confirmState=${confirmState}&onlineState=${onlineState}&sustainTimeStart=${sustainTimeStart}` + `&sustainTimeEnd=${sustainTimeEnd}&pepProjectId=${pepProjectId || ''}&groupId=${groups[route]}` setExportUrl(url); } else { Toast.info({ content: '暂无可导出的数据', duration: 3, }) } } }) break; } } return ( <>
{title[route]} DETAILED INFORMATION
console.log(values)} getFormApi={(formApi) => (api.current = formApi)} layout="horizontal" allowEmpty={false} style={{ position: "relative", width: "100%", flex: 1, display: 'flex' }} > {(() => { let frame = [] collectData[route]?.map((v, index) => { if (index == 0) { if (route == 'useAbnormal') { frame.push() } else { frame.push( {[{ name: "告警源", value: "source" }, { name: "项目", value: "pepProject" }, { name: "结构物", value: "struc" },].map(vv => { return {vv.name} })} ) } } else { if (route == 'dataAbnormal' && v.special) { frame.push(
{v.data?.filter(d => typeId?.includes(d.value))?.map((item) => { return ( {item.name} ); })} { setCheck(typeId) setTypeSet(true) }} />
) } else { frame.push( {v.data?.map((item) => { return ( {item.name} ); })} ) } } }) frame.push( console.log(v)} />) return frame })()}
{ api.current.validate().then((v) => { search.current = { state: v.state, keywordTarget: v.keywordTarget, keyword: v.keyword, kindId: v.kindId, statusId: v.statusId, groupUnitId: v.groupUnitId, errType: v.errType, confirmState: v.confirmState, onlineState: v.onlineState, sustainTimeStart: v.time && v.time.length > 0 ? moment(v.time[0]).format("YYYY-MM-DD HH:mm:ss") : "", sustainTimeEnd: v.time && v.time.length > 0 ? moment(v.time[1]).format("YYYY-MM-DD HH:mm:ss") : "", } handleExport(); }); }} /> setSetup(true)} />
{(() => { return 暂无告警数据 } style={{}} pagination={false} onRow={(record, index) => { if (index % 1 === 0) { return { style: { background: '#FAFCFF' } } } }} rowSelection={{ selectedRowKeys: selected || [], getCheckboxProps: record => ({ disabled: (record.confirmTime || record.State > 2 || record.projectLocal) ? true : false, // name: record.name, }), onSelect: (record, selected) => { // console.log(`select row: ${selected}`, record); }, // onSelectAll: (selected, selectedRows) => { // console.log(`select all rows: ${selected}`, selectedRows); // }, onChange: (selectedRowKeys, selectedRows) => { // console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows); setSelected(selectedRows?.map(v => v.id)) }, }} /> })()}
勾选{selected.length}条问题
{count > 0 ?
共{count}个问题 { setQuery({ limit: pageSize, page: currentPage - 1 }); }} />
: ""} { exportUrl ?