From 85736afa060f5b213f36a7dc398c78e46fde3def Mon Sep 17 00:00:00 2001 From: "peng.peng" Date: Wed, 29 Mar 2023 13:46:18 +0800 Subject: [PATCH] =?UTF-8?q?=EF=BC=88*=EF=BC=89=E9=87=87=E9=9B=86=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E7=AB=8B=E5=8D=B3=E6=89=A7=E8=A1=8C=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/metadataAcquisition/task.js | 10 +- .../lib/routes/metadataAcquisition/task.js | 4 +- .../metadataAcquisition/actions/task.js | 15 +- .../containers/acquisitionLog.js | 184 +++++++++++++++++- .../containers/acquisitionTask.js | 12 +- web/client/src/utils/webapi.js | 2 +- 6 files changed, 213 insertions(+), 14 deletions(-) diff --git a/api/app/lib/controllers/metadataAcquisition/task.js b/api/app/lib/controllers/metadataAcquisition/task.js index f82aabb..72b0c05 100644 --- a/api/app/lib/controllers/metadataAcquisition/task.js +++ b/api/app/lib/controllers/metadataAcquisition/task.js @@ -133,6 +133,12 @@ function deleteAcquisitionTask(app) { try { const models = ctx.fs.dc.models; const { id } = ctx.params; + + await models.AcquisitionLog.destroy({ + where: { + task: id + } + }) const task = await models.AcquisitionTask.destroy({ where: { id: id @@ -156,13 +162,13 @@ function deleteAcquisitionTask(app) { } // 采集任务立即执行一次 -function addAcquisitionTask(app) { +function runAcqTask(app) { return async function (ctx, next) { const models = ctx.fs.dc.models; try { const { id } = ctx.request.body - const task = await models.AcquisitionTask.findOne({ where: { id, id } }); + const task = await models.AcquisitionTask.findOne({ where: { id: id } }); if (task) { await handleTask(app, task); ctx.status = 204; diff --git a/api/app/lib/routes/metadataAcquisition/task.js b/api/app/lib/routes/metadataAcquisition/task.js index ce1e0f5..56cbad1 100644 --- a/api/app/lib/routes/metadataAcquisition/task.js +++ b/api/app/lib/routes/metadataAcquisition/task.js @@ -20,7 +20,7 @@ module.exports = function (app, router, opts, AuthCode) { router.del('acq/task/:id', task.deleteAcquisitionTask(app)) //任务立即执行 - app.fs.api.logAttr['POST/acq/task/run'] = { content: '任务立即执行', visible: true }; - router.put('/acq/task/run', task.runAcqTask(app)) + app.fs.api.logAttr['POST/run/acq/task'] = { content: '任务立即执行', visible: true }; + router.post('/run/acq/task', task.runAcqTask(app)) }; diff --git a/web/client/src/sections/metadataAcquisition/actions/task.js b/web/client/src/sections/metadataAcquisition/actions/task.js index d940619..11d8ce3 100644 --- a/web/client/src/sections/metadataAcquisition/actions/task.js +++ b/web/client/src/sections/metadataAcquisition/actions/task.js @@ -8,7 +8,7 @@ export function addTask(params, msg) { type: 'post', data: params, dispatch, - actionType: 'ADD_DATSOURCE', + actionType: 'ADD_ACQ_TASK', url: ApiTable.addTask, msg: { option: msg || '新增采集任务', @@ -53,4 +53,17 @@ export function modifyTask(id, params, msg) { }); } +export function runTask(params, msg) { + return (dispatch) => basicAction({ + type: 'post', + data: params, + dispatch, + actionType: 'RUN_ACQ_TASK', + url: ApiTable.runTask, + msg: { + option: msg || '任务执行', + }, + }); +} + diff --git a/web/client/src/sections/metadataAcquisition/containers/acquisitionLog.js b/web/client/src/sections/metadataAcquisition/containers/acquisitionLog.js index f792f7e..a9ddc89 100644 --- a/web/client/src/sections/metadataAcquisition/containers/acquisitionLog.js +++ b/web/client/src/sections/metadataAcquisition/containers/acquisitionLog.js @@ -1,7 +1,185 @@ import React, { useEffect, useState } from 'react' +import { Spin, Popconfirm, Tree, Row, Col, Button, Input, Table } from 'antd'; +import { connect } from 'react-redux'; +import ProTable from '@ant-design/pro-table'; +import moment from 'moment'; -function AcquisitionLog (props) { - return <>采集日志 +import './style.less'; +function AcquisitionLog(props) { + const { loading, clientHeight, actions, dispatch, dataSources, adapters, tasks } = props; + const [pageSize, setPageSize] = useState(10); + const [currentPage, setCurrentPage] = useState(1); + const [searchValue, setSearchValue] = useState('') + const queryData = (search) => { + const query = { + // limit: search ? 10 : pageSize || 10, + // page: search ? 1 : currentPage || 1, + taskName: searchValue + } + dispatch(actions.metadataAcquisition.getTasks(query)); + } + + useEffect(() => { + dispatch(actions.metadataAcquisition.getDataSources()); + dispatch(actions.metadataAcquisition.getAdapters()) + queryData(); + }, [pageSize, currentPage]); + + const columns = [ + { + title: '任务名称', + dataIndex: 'taskName', + }, + { + title: '数据源名称', + dataIndex: 'dataSourceName', + render: (text, record) => { + return record?.dataSource?.name + } + }, + { + title: '适配器类型', + dataIndex: 'adapter', + render: (text, record) => { + const adapterInfo = record?.dataSource?.adapter + return adapterInfo?.adapterName + } + }, + { + title: '采集方式', + dataIndex: 'control', + render: (text, record) => { + const adapterInfo = record?.dataSource?.adapter + return adapterInfo?.mode + } + }, + { + title: '执行周期', + dataIndex: 'cron', + // render: (text, record) => { + // return transCron(record?.cron); + // } + }, + { + title: '重复次数', + dataIndex: 'retryCount', + }, + { + title: '时间间隔(分钟)', + dataIndex: 'retryTime', + }, + + { + title: '操作', + width: 300, + key: 'option', + valueType: 'option', + render: (text, record) => { + const options = []; + options.push( { + const param = { id: record.id } + dispatch(actions.metadataAcquisition.runTask(param)) + }} style={{ marginRight: 8 }}>立即执行) + + const enabledText = record?.enabled ? '禁用' : '启用'; + options.push( { + dispatch(actions.metadataAcquisition.modifyTask(record?.id, { enabled: !record?.enabled }, '采集任务' + enabledText)).then(res => { + if (res.success) { + queryData(); + } + }) + }} style={{ marginRight: 8 }}>{enabledText}) + + options.push( { + const adapterInfo = adapters?.find(x => x.id == record?.adapter) + setVisible(true) + record.adapterInfo = adapterInfo + setEditData(record) + }} style={{ marginRight: 8 }}>编辑) + //判断数据源下是否有任务 有任务提示需要先删除任务再删除数据源 + options.push( +
是否确认删除该采集任务?
+
(将同步删除该任务采集日志)
} + onConfirm={() => handleDelete(record.id)} + okText="是" + cancelText="否" + > + 删除 +
) + + return options; + + }, + }, + ]; + + return + + { setSearchValue(e.target.value) }} + style={{ width: 220, marginRight: 15 }} placeholder="数据源或任务名称" /> + + + + { + // return {`共${Math.ceil(total / pageSize)}页,${total}项`} + // }, + // onShowSizeChange: (currentPage, pageSize) => { + // setCurrentPage(currentPage); + // setPageSize(pageSize); + + // }, + // onChange: (page, pageSize) => { + // setCurrentPage(page); + // setPageSize(pageSize); + + // } + }} + dataSource={tasks?.rows || []} + options={false} + /> + + +} + +function mapStateToProps(state) { + const { + auth, global, datasources, adapters, tasks + } = state; + return { + loading: datasources.isRequesting || adapters?.isRequesting, + clientHeight: global.clientHeight, + actions: global.actions, + dataSources: datasources?.data || {}, + adapters: adapters?.data || [], + tasks: tasks?.data || [], + }; } -export default AcquisitionLog \ No newline at end of file +export default connect(mapStateToProps)(AcquisitionLog); + + + + diff --git a/web/client/src/sections/metadataAcquisition/containers/acquisitionTask.js b/web/client/src/sections/metadataAcquisition/containers/acquisitionTask.js index 53b9f38..a9ffac3 100644 --- a/web/client/src/sections/metadataAcquisition/containers/acquisitionTask.js +++ b/web/client/src/sections/metadataAcquisition/containers/acquisitionTask.js @@ -122,9 +122,9 @@ function AcquisitionTask(props) { { title: '执行周期', dataIndex: 'cron', - render: (text, record) => { - return transCron(record?.cron); - } + // render: (text, record) => { + // return transCron(record?.cron); + // } }, { title: '重复次数', @@ -143,7 +143,8 @@ function AcquisitionTask(props) { render: (text, record) => { const options = []; options.push( { - + const param = { id: record.id } + dispatch(actions.metadataAcquisition.runTask(param)) }} style={{ marginRight: 8 }}>立即执行) const enabledText = record?.enabled ? '禁用' : '启用'; @@ -166,7 +167,8 @@ function AcquisitionTask(props) {
是否确认删除该采集任务?
+
(将同步删除该任务采集日志)
} onConfirm={() => handleDelete(record.id)} okText="是" cancelText="否" diff --git a/web/client/src/utils/webapi.js b/web/client/src/utils/webapi.js index 337871c..dc0bee9 100644 --- a/web/client/src/utils/webapi.js +++ b/web/client/src/utils/webapi.js @@ -44,7 +44,7 @@ export const ApiTable = { addTask: 'meta/acq/task', getTasks: 'meta/acq/tasks', modifyTask: 'acq/task/{id}', - + runTask: 'run/acq/task' };