|
|
@ -1,23 +1,37 @@ |
|
|
|
import React, { useEffect, useState } from 'react' |
|
|
|
import { Spin, Popconfirm, Tree, Row, Col, Button, Input, Table } from 'antd'; |
|
|
|
import { Spin, Popconfirm, Tree, Row, Col, Button, Input, Table, Select } from 'antd'; |
|
|
|
import { connect } from 'react-redux'; |
|
|
|
import ProTable from '@ant-design/pro-table'; |
|
|
|
import moment from 'moment'; |
|
|
|
import { useFsRequest, ApiTable } from '$utils'; |
|
|
|
|
|
|
|
const { Option } = Select; |
|
|
|
import xlsx from 'xlsx'; |
|
|
|
import './style.less'; |
|
|
|
function AcquisitionLog(props) { |
|
|
|
const { loading, clientHeight, actions, dispatch, acqlogs } = props; |
|
|
|
const [pageSize, setPageSize] = useState(10); |
|
|
|
const [currentPage, setCurrentPage] = useState(1); |
|
|
|
const [searchValue, setSearchValue] = useState('') |
|
|
|
const [logState, setLogState] = useState('全部') |
|
|
|
|
|
|
|
const queryData = (search) => { |
|
|
|
const query = { |
|
|
|
limit: search ? 10 : pageSize || 10, |
|
|
|
page: search ? 1 : currentPage || 1, |
|
|
|
logState: logState, |
|
|
|
taskName: searchValue |
|
|
|
} |
|
|
|
dispatch(actions.metadataAcquisition.getLogs(query)); |
|
|
|
} |
|
|
|
const { data: allLogs = {} } = useFsRequest({ |
|
|
|
url: ApiTable.getLogs, |
|
|
|
query: { |
|
|
|
logState: logState, |
|
|
|
taskName: searchValue |
|
|
|
}, |
|
|
|
refreshDeps: [logState, searchValue] |
|
|
|
}); |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
queryData(); |
|
|
@ -31,6 +45,13 @@ function AcquisitionLog(props) { |
|
|
|
return record?.acquisitionTask?.taskName; |
|
|
|
} |
|
|
|
}, |
|
|
|
// {
|
|
|
|
// title: '任务描述',
|
|
|
|
// dataIndex: 'taskDescription',
|
|
|
|
// render: (text, record) => {
|
|
|
|
// return record?.acquisitionTask?.description;
|
|
|
|
// }
|
|
|
|
// },
|
|
|
|
{ |
|
|
|
title: '数据源名称', |
|
|
|
dataIndex: 'dataSourceName', |
|
|
@ -39,36 +60,111 @@ function AcquisitionLog(props) { |
|
|
|
} |
|
|
|
}, |
|
|
|
{ |
|
|
|
title: '适配器类型', |
|
|
|
dataIndex: 'adapter', |
|
|
|
}, |
|
|
|
{ |
|
|
|
title: '采集方式', |
|
|
|
dataIndex: 'control', |
|
|
|
title: '任务状态', |
|
|
|
dataIndex: 'success', |
|
|
|
render: (text, record) => { |
|
|
|
return record?.success ? '采集成功' : "采集失败"; |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
title: '执行周期', |
|
|
|
dataIndex: 'cron', |
|
|
|
// render: (text, record) => {
|
|
|
|
// return transCron(record?.cron);
|
|
|
|
// }
|
|
|
|
title: '开始时间', |
|
|
|
dataIndex: 'startTime', |
|
|
|
render: (text, record) => { |
|
|
|
return moment(record?.startTime).format('YYYY-MM-DD HH:mm:ss'); |
|
|
|
}, |
|
|
|
sorter: { |
|
|
|
compare: (a, b) => moment(b?.startTime).valueOf() - moment(a?.startTime).valueOf(), |
|
|
|
multiple: 2, |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
title: '重复次数', |
|
|
|
dataIndex: 'retryCount', |
|
|
|
title: '耗时', |
|
|
|
dataIndex: 'endTime', |
|
|
|
render: (text, record) => { |
|
|
|
return moment(record?.endTime).valueOf() - moment(record?.startTime).valueOf() + '毫秒'; |
|
|
|
}, |
|
|
|
sorter: { |
|
|
|
compare: (a, b) => (moment(b?.endTime).valueOf() - moment(b?.startTime).valueOf()) - (moment(a?.endTime).valueOf() - moment(a?.startTime).valueOf()), |
|
|
|
multiple: 2, |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
title: '时间间隔(分钟)', |
|
|
|
dataIndex: 'retryTime', |
|
|
|
title: '详情', |
|
|
|
dataIndex: 'details', |
|
|
|
ellipsis: true, |
|
|
|
}, |
|
|
|
]; |
|
|
|
|
|
|
|
const handleTableExport = () => { |
|
|
|
let rows = allLogs?.rows; |
|
|
|
if (rows.length == 0) { |
|
|
|
message.info('当前无采集日志信息!') |
|
|
|
} |
|
|
|
let excelTitle = columns.map(s => { |
|
|
|
return { k: s.dataIndex, v: s.title } |
|
|
|
}); |
|
|
|
|
|
|
|
let workBook = { |
|
|
|
SheetNames: [], //sheet名称
|
|
|
|
Sheets: {} //根据SheetNames名称顺序依次添加每个sheet数据
|
|
|
|
}; |
|
|
|
if (rows && rows.length > 0) { |
|
|
|
let sheetName = '日志信息'; |
|
|
|
let sheetDataMap = new Map(); |
|
|
|
let sheetData = [excelTitle]; |
|
|
|
let index = 1; |
|
|
|
rows.map(record => { |
|
|
|
sheetData.push([ |
|
|
|
{ k: 'taskName', v: record?.acquisitionTask?.taskName }, |
|
|
|
// { k: 'taskDescription', v: record?.acquisitionTask?.description || '' },
|
|
|
|
{ k: 'dataSourceName', v: record?.acquisitionTask?.dataSource?.name }, |
|
|
|
{ k: 'success', v: record?.success ? '采集成功' : "采集失败" }, |
|
|
|
{ k: 'startTime', v: moment(record?.startTime).format('YYYY-MM-DD HH:mm:ss') }, |
|
|
|
{ k: 'endTime', v: moment(record?.endTime).valueOf() - moment(record?.startTime).valueOf() + '毫秒' }, |
|
|
|
{ k: 'details', v: record?.details }, |
|
|
|
]); |
|
|
|
index = index + 1; |
|
|
|
}) |
|
|
|
|
|
|
|
sheetDataMap.set(sheetName, sheetData); |
|
|
|
sheetDataMap.forEach((values, key) => { |
|
|
|
// 写入excel
|
|
|
|
workBook.Sheets[key] = xlsx.utils.aoa_to_sheet(values); |
|
|
|
workBook.Sheets[key]['!cols'] = [{ wpx: 50 }, { wpx: 150 }, { wpx: 180 }, { wpx: 230 }, { wpx: 230 }, { wpx: 230 }] |
|
|
|
}) |
|
|
|
workBook.SheetNames = [sheetName]; |
|
|
|
} |
|
|
|
// 将workBook写入文件
|
|
|
|
xlsx.writeFile(workBook, `采集日志-${moment().format('YYYY-MM-DD HH:mm:ss')}.xlsx`); |
|
|
|
} |
|
|
|
|
|
|
|
return <Spin spinning={loading}> |
|
|
|
<Row className='protable-title'> |
|
|
|
<Row className='protable-title' style={{ alignItems: 'center' }}> |
|
|
|
<span style={{ marginRight: 8 }}>关键字搜索:</span> |
|
|
|
<Input |
|
|
|
value={searchValue} onChange={e => { setSearchValue(e.target.value) }} |
|
|
|
style={{ width: 220, marginRight: 15 }} placeholder="数据源或任务名称" /> |
|
|
|
<Button onClick={() => { queryData() }} type='primary'>查询</Button> |
|
|
|
style={{ width: 220, marginRight: 15 }} placeholder="任务名称或数据源" /> |
|
|
|
<span style={{ marginRight: 8 }}> 任务状态:</span> |
|
|
|
<Select |
|
|
|
style={{ width: 160, marginRight: 15 }} |
|
|
|
defaultValue='全部' |
|
|
|
onChange={(e) => { |
|
|
|
setLogState(e) |
|
|
|
}} |
|
|
|
> |
|
|
|
<Option value={'全部'} key={'全部'}>全部</Option> |
|
|
|
<Option value={true} key={'采集成功'}>采集成功</Option> |
|
|
|
<Option value={false} key={'采集失败'}>采集失败</Option> |
|
|
|
</Select> |
|
|
|
|
|
|
|
<Button |
|
|
|
onClick={() => { |
|
|
|
setCurrentPage(1); |
|
|
|
setPageSize(10); |
|
|
|
queryData() |
|
|
|
}} type='primary'>查询</Button> |
|
|
|
|
|
|
|
<Button style={{ marginLeft: 15 }} onClick={() => { handleTableExport() }} type='primary'>导出</Button> |
|
|
|
</Row> |
|
|
|
|
|
|
|
<ProTable |
|
|
|