Browse Source

(*)告警导出限制7天

dev
wuqun 3 years ago
parent
commit
302a24780c
  1. 124
      web/client/src/sections/problem/components/tableData.jsx

124
web/client/src/sections/problem/components/tableData.jsx

@ -1,6 +1,6 @@
import React, { useState, useEffect, useRef } from "react"; import React, { useState, useEffect, useRef } from "react";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { Button, Form, Modal, Skeleton, Pagination, Table } from "@douyinfe/semi-ui"; import { Button, Form, Modal, Skeleton, Pagination, Table, Tooltip, Toast } from "@douyinfe/semi-ui";
import { SkeletonScreen, } from "$components"; import { SkeletonScreen, } from "$components";
import moment from "moment"; import moment from "moment";
import { validate } from "schema-utils"; import { validate } from "schema-utils";
@ -122,7 +122,7 @@ const TableData = ({ route, dispatch, actions, collectData, setSetup, exhibition
useEffect(() => { useEffect(() => {
if (location) { if (location) {
search.current = { ...search.current, ...location, state: 'new' } search.current = { ...search.current, ...location, state: 'new' }
api.current?.setValues({...location, state: 'new'}) api.current?.setValues({ ...location, state: 'new' })
} }
if (route !== 'videoAbnormal' && route !== 'useAbnormal') { if (route !== 'videoAbnormal' && route !== 'useAbnormal') {
dispatch(problem.getAlarmDataGroup()).then((res) => { dispatch(problem.getAlarmDataGroup()).then((res) => {
@ -159,29 +159,77 @@ const TableData = ({ route, dispatch, actions, collectData, setSetup, exhibition
const handleExport = () => { const handleExport = () => {
let url = '' let url = ''
let { keywordTarget, keyword = '', errType = '', state = '', kindId = '', groupUnitId = '', confirmState = '', onlineState = '', sustainTimeStart = '', sustainTimeEnd = '' } = search.current let { keywordTarget, keyword = '', errType = '', state = '', kindId = '', 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) { switch (route) {
case 'useAbnormal': case 'useAbnormal':
url = `alarm/application/api?token=${user.token}&toExport=1&timestamp=${moment().valueOf()}&keyword=${keyword}&errType=${errType} dispatch(problem.getAlarmLnspectionApi({ ...search.current, limit: 1, sustainTimeStart, sustainTimeEnd, pepProjectId: pepProjectId })).then((res) => {
&state=${state}stainTimeStart=${sustainTimeStart}&sustainTimeEnd=${sustainTimeEnd}&pepProjectId=${pepProjectId || ''}` if (res.success) {
if (res.payload.data.count) {
url = `alarm/application/api?token=${user.token}&toExport=1&timestamp=${moment().valueOf()}&keyword=${keyword}&errType=${errType}
&state=${state}stainTimeStart=${sustainTimeStart}&sustainTimeEnd=${sustainTimeEnd}&pepProjectId=${pepProjectId || ''}`
setExportUrl(url);
} else {
Toast.info({
content: '暂无可导出的数据',
duration: 3,
})
}
}
})
break; break;
case 'videoAbnormal': case 'videoAbnormal':
url = `alarm/video/list?token=${user.token}&toExport=1&timestamp=${moment().valueOf()}&keywordTarget=${keywordTarget} dispatch(problem.getAlarmVideoList({ ...search.current, limit: 1, sustainTimeStart, sustainTimeEnd, pepProjectId: pepProjectId })).then((res) => {
&keyword=${keyword}&kindId=${kindId}&state=${state}&sustainTimeStart=${sustainTimeStart}&sustainTimeEnd=${sustainTimeEnd} if (res.success) {
&pepProjectId=${pepProjectId || ''}` if (res.payload.data.count) {
url = `alarm/video/list?token=${user.token}&toExport=1&timestamp=${moment().valueOf()}&keywordTarget=${keywordTarget}
&keyword=${keyword}&kindId=${kindId}&state=${state}&sustainTimeStart=${sustainTimeStart}&sustainTimeEnd=${sustainTimeEnd}
&pepProjectId=${pepProjectId || ''}`
setExportUrl(url);
} else {
Toast.info({
content: '暂无可导出的数据',
duration: 3,
})
}
}
})
break; break;
default: default:
let groups = { dispatch(problem.getAlarmDataList({ ...query, ...search.current, limit: 1, sustainTimeStart, sustainTimeEnd, groupId: groupId.current.map(v => v.id).join(), pepProjectId: pepProjectId })).then((res) => {
"dataLnterrupt": "1", if (res.success) {
"dataAbnormal": "2", if (res.payload.data.count) {
"strategyHit": "3", let groups = {
"deviceAbnormal": "4,5" "dataLnterrupt": "1",
} "dataAbnormal": "2",
url = `alarm/data/list?token=${user.token}&toExport=1&timestamp=${moment().valueOf()}&state=${state}&keywordTarget=${keywordTarget}&keyword=${keyword}&kindId=${kindId} "strategyHit": "3",
&groupUnitId=${groupUnitId}&errType=${errType}&confirmState=${confirmState}&onlineState=${onlineState}&sustainTimeStart=${sustainTimeStart} "deviceAbnormal": "4,5"
&sustainTimeEnd=${sustainTimeEnd}&pepProjectId=${pepProjectId || ''}&groupId=${groups[route]}` }
url = `alarm/data/list?token=${user.token}&toExport=1&timestamp=${moment().valueOf()}&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; break;
} }
setExportUrl(url);
} }
return ( return (
@ -269,25 +317,27 @@ const TableData = ({ route, dispatch, actions, collectData, setSetup, exhibition
marginBottom: 16 marginBottom: 16
}} }}
> >
<img title='导出' src="/assets/images/problem/export.png" style={{ width: 20 }} <Tooltip content={'默认导出最近7天的数据,自定义时间跨度不超过7天'}>
onClick={() => { <img title='导出' src="/assets/images/problem/export.png" style={{ width: 20, cursor: 'pointer' }}
api.current.validate().then((v) => { onClick={() => {
search.current = { api.current.validate().then((v) => {
state: v.state, search.current = {
keywordTarget: v.keywordTarget, state: v.state,
keyword: v.keyword, keywordTarget: v.keywordTarget,
kindId: v.kindId, keyword: v.keyword,
groupUnitId: v.groupUnitId, kindId: v.kindId,
errType: v.errType, groupUnitId: v.groupUnitId,
confirmState: v.confirmState, errType: v.errType,
onlineState: v.onlineState, confirmState: v.confirmState,
sustainTimeStart: v.time && v.time.length > 0 ? moment(v.time[0]).format("YYYY-MM-DD HH:mm:ss") : "", onlineState: v.onlineState,
sustainTimeEnd: v.time && v.time.length > 0 ? moment(v.time[1]).format("YYYY-MM-DD HH:mm:ss") : "", 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(); }
}); handleExport();
}} /> });
<img title='设置' src="/assets/images/problem/setup.png" style={{ width: 20 }} onClick={() => setSetup(true)} /> }} />
</Tooltip>
<img title='设置' src="/assets/images/problem/setup.png" style={{ width: 20, cursor: 'pointer' }} onClick={() => setSetup(true)} />
<Button <Button
theme="solid" theme="solid"
type="primary" type="primary"
@ -415,7 +465,7 @@ const TableData = ({ route, dispatch, actions, collectData, setSetup, exhibition
} }
function mapStateToProps (state) { function mapStateToProps(state) {
const { auth, global, members } = state; const { auth, global, members } = state;
// console.log(global); // console.log(global);
return { return {

Loading…
Cancel
Save