Commit fe5436ea by zhaochengxiang

采集

parent 0ccc9d0f
...@@ -19,10 +19,9 @@ function compare(val1, val2) { ...@@ -19,10 +19,9 @@ function compare(val1, val2) {
} }
const reportStates = [ const reportStates = [
{ title: '完成', key: '' }, { title: '完成', key: 'ENDED' },
{ title: '失败', key: '' }, { title: '失败', key: 'FAILED' },
{ title: '执行中', key: '' }, { title: '执行中', key: 'STARTED' },
{ title: '已取消', key: '' },
] ]
const FC = (props) => { const FC = (props) => {
...@@ -33,10 +32,14 @@ const FC = (props) => { ...@@ -33,10 +32,14 @@ const FC = (props) => {
const [tracerData, setTracerData] = useState(undefined); const [tracerData, setTracerData] = useState(undefined);
const [loadingReport, setLoadingReport] = useState(false); const [loadingReport, setLoadingReport] = useState(false);
const [pagination, setPagination] = useState({pageNum: 1, pageSize: 20}); const [pagination, setPagination] = useState({pageNum: 1, pageSize: 20});
const [taskCode, setTaskCode] = useState(undefined);
const [datasourceName, setDatasourceName] = useState(undefined);
const [reportState, setReportState] = useState(undefined);
const [keyword, setKeyword] = useState(undefined); const [keyword, setKeyword] = useState(undefined);
const [datasourceId, setDatasourceId] = useState(undefined);
const [reportState, setReportState] = useState('');
const [loadingTasks, setLoadingTasks] = useState(false);
const [tasks, setTasks] = useState(undefined);
const [loadingDatasources, setLoadingDatasources] = useState(false); const [loadingDatasources, setLoadingDatasources] = useState(false);
const [datasources, setDatasources] = useState([]); const [datasources, setDatasources] = useState([]);
...@@ -68,27 +71,92 @@ const FC = (props) => { ...@@ -68,27 +71,92 @@ const FC = (props) => {
return []; return [];
}, [reportData]) }, [reportData])
const taskCodes = useMemo(() => {
return tasks?.filter(item => item.taskCode).map(item => item.taskCode)
}, [tasks])
useEffect(() => {
getAllTasks();
getDatasources();
}, [env])
useEffect(() => {
getTaskReportDetail();
}, [env, rangeValue])
useMemo(() => {
let newTasks = reportData?.datas?.filter(item => {
return (taskCode===undefined || item.taskCode === taskCode)
&& (datasourceName===undefined || item.databaseName === datasourceName)
&& (reportState===undefined || item.state === reportState)
&& (!keyword || item.taskCode?.indexOf(keyword)!==-1 || item.databaseName?.indexOf(keyword)!==-1)
});
setSummaryData([
{ cnName: '采集总数', value: (newTasks||[]).length },
{ cnName: '成功次数', value: (newTasks||[]).filter(item => item.state==='ENDED').length },
{ cnName: '失败次数', value: (newTasks||[]).filter(item => item.state==='FAILED').length },
{ cnName: '采集时长', value: parseInt((newTasks||[]).reduce((preVal, item) => item.costTime + preVal, 0)), unit: '分钟' },
])
}, [reportData, taskCode, datasourceName, reportState, keyword, pagination])
const tableData = useMemo(() => { const tableData = useMemo(() => {
if (reportData) { let newTasks = reportData?.datas?.filter(item => {
return paginate(reportData.datas, pageNum, pageSize); return (taskCode===undefined || item.taskCode === taskCode)
} && (datasourceName===undefined || item.databaseName === datasourceName)
&& (reportState===undefined || item.state === reportState)
&& (!keyword || item.taskCode?.indexOf(keyword)!==-1 || item.databaseName?.indexOf(keyword)!==-1)
});
return []; return paginate(newTasks||[], pagination.pageNum, pagination.pageSize);
}, [reportData, datasources, pageNum, pageSize]) }, [reportData, taskCode, datasourceName, reportState, keyword, pagination])
const total = useMemo(() => { const total = useMemo(() => {
if (reportData) { let newTasks = reportData?.datas?.filter(item => {
return (reportData.datas||[]).length; return (taskCode===undefined || item.taskCode === taskCode)
} && (datasourceName===undefined || item.databaseName === datasourceName)
&& (reportState===undefined || item.state === reportState)
&& (!keyword || item.taskCode?.indexOf(keyword)!==-1 || item.databaseName?.indexOf(keyword)!==-1)
});
return 0; return (newTasks||[]).length;
}, [reportData]) }, [reportData, taskCode, datasourceName, reportState, keyword, pagination])
useEffect(() => { const getAllTasks = () => {
getTaskReportSummary(); setLoadingTasks(true);
getTaskReportDetail(); dispatch({
getDatasources(); type: 'datasource.getAllTasks',
}, [env]) callback: data => {
setLoadingTasks(false);
const newData = [...(data||[])];
newData.forEach(item => {
item.type = item.target?.type;
item.target?.targetParameters?.forEach(param => {
if (param.name === 'name') {
item.name = param.value;
} else if (param.name === 'cnName') {
item.cnName = param.value;
}
});
item.targetConfParameters?.forEach(param => {
if (param.name === 'schema') {
item.schema = param.value;
} else if (item.param === 'tableFilterParam') {
item.tableWhiteList = param.value;
} else if (item.param === 'tableBlacklist') {
item.tableBlackList = param.value;
}
});
});
console.log('new data', newData);
setTasks(newData||[]);
},
error: () => {
setLoadingTasks(false);
}
})
}
const getDatasources = () => { const getDatasources = () => {
setLoadingDatasources(true); setLoadingDatasources(true);
...@@ -107,21 +175,6 @@ const FC = (props) => { ...@@ -107,21 +175,6 @@ const FC = (props) => {
}) })
} }
const getTaskReportSummary = () => {
dispatch({
type: 'datasource.getTaskReportSummary',
payload: {
namespace: env?.domainId,
startTime: (rangeValue||[]).length>0 ? rangeValue[0] : null,
endTime: (rangeValue||[]).length>1 ? rangeValue[1] : null
},
callback: data => {
data?.sort(compare);
setSummaryData(data);
}
})
}
const getTaskReportDetail = () => { const getTaskReportDetail = () => {
setLoadingReport(true); setLoadingReport(true);
dispatch({ dispatch({
...@@ -171,8 +224,16 @@ const FC = (props) => { ...@@ -171,8 +224,16 @@ const FC = (props) => {
setRangeValue(value?.map(item => item.valueOf())); setRangeValue(value?.map(item => item.valueOf()));
} }
const onTaskCodeChange = (value) => {
setTaskCode(value);
}
const onDatasourceChange = (value) => { const onDatasourceChange = (value) => {
setDatasourceId(value); setDatasourceName(value);
}
const onReportStateChange = (value) => {
setReportState(value);
} }
const onSearchInputChange = (e) => { const onSearchInputChange = (e) => {
...@@ -196,8 +257,24 @@ const FC = (props) => { ...@@ -196,8 +257,24 @@ const FC = (props) => {
/> />
<Select <Select
allowClear allowClear
loading={loadingTasks}
value={taskCode}
placeholder='请选择任务编号'
style={{ width: 200 }}
onChange={onTaskCodeChange}
>
{
taskCodes?.map((item, index) => {
return (
<Select.Option key={index} value={item}>{item}</Select.Option>
);
})
}
</Select>
<Select
allowClear
loading={loadingDatasources} loading={loadingDatasources}
value={datasourceId} value={datasourceName}
placeholder='请选择数据库' placeholder='请选择数据库'
style={{ width: 170 }} style={{ width: 170 }}
onChange={onDatasourceChange} onChange={onDatasourceChange}
...@@ -211,7 +288,22 @@ const FC = (props) => { ...@@ -211,7 +288,22 @@ const FC = (props) => {
} }
return ( return (
<Select.Option key={index} value={item.id}>{name}</Select.Option> <Select.Option key={index} value={name}>{name}</Select.Option>
);
})
}
</Select>
<Select
allowClear
value={reportState}
placeholder='请选择执行状态'
style={{ width: 170 }}
onChange={onReportStateChange}
>
{
reportStates?.map((item, index) => {
return (
<Select.Option key={index} value={item.key}>{item.title}</Select.Option>
); );
}) })
} }
...@@ -308,10 +400,12 @@ const Summary = ({ data }) => { ...@@ -308,10 +400,12 @@ const Summary = ({ data }) => {
<Card> <Card>
<Meta <Meta
title={ title={
<div> <div className='flex' style={{ justifyContent: 'space-between' }}>
<span>{item.cnName}</span> <span style={{ color: '#aaa' }}>{item.cnName}</span>
<span>{item.value||0}</span> <div>
<span>{item.unit?`(${item.unit})`:''}</span> <span>{item.value||0}</span>
<span style={{ color: '#aaa' }}>{item.unit?` (${item.unit})`:''}</span>
</div>
</div> </div>
} }
/> />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment