diff --git a/api/app/lib/controllers/metadataAcquisition/log.js b/api/app/lib/controllers/metadataAcquisition/log.js
index e69de29..70fcfd3 100644
--- a/api/app/lib/controllers/metadataAcquisition/log.js
+++ b/api/app/lib/controllers/metadataAcquisition/log.js
@@ -0,0 +1,56 @@
+'use strict';
+
+function getAcquisitionTask(opts) {
+ return async function (ctx, next) {
+
+ const models = ctx.fs.dc.models;
+ const { page, limit, taskName } = ctx.query;
+ let errMsg = { message: '获取采集任务失败' }
+ const Op = ctx.fs.dc.ORM.Op;
+ try {
+ let searchWhere = {}
+ let option = {
+ where: searchWhere,
+ order: [["id", "desc"]],
+ include: [{
+ model: models.AcquisitionTask,
+ as: 'acquisitionTask',
+ include: [{
+ model: models.DataSource,
+ }]
+ }]
+ }
+
+ if (taskName) {
+ searchWhere.$or = [
+ { '$acquisitionTask.task_name$': { $iLike: `%${taskName}%` } },
+ { '$acquisitionTask.dataSource.name$': { $iLike: `%${taskName}%` } },
+ ]
+ }
+
+ option.where = searchWhere
+
+ let limit_ = limit || 10;
+ let page_ = page || 1;
+ let offset = (page_ - 1) * limit_;
+ if (limit && page) {
+ option.limit = limit_
+ option.offset = offset
+ }
+
+ const res = await models.AcquisitionLog.findAndCount(option);
+ ctx.status = 200;
+ ctx.body = res;
+ } catch (error) {
+ ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
+ ctx.status = 400;
+ ctx.body = errMsg
+ }
+ }
+}
+
+module.exports = {
+
+ getAcquisitionTask,
+
+}
diff --git a/api/app/lib/index.js b/api/app/lib/index.js
index b170bc5..4ff9474 100644
--- a/api/app/lib/index.js
+++ b/api/app/lib/index.js
@@ -55,11 +55,13 @@ module.exports.models = function (dc) {
});
const {
- DataSource, AcquisitionTask, Adapter, User, MetadataDatabase, MetadataFile, MetadataRestapi
+ DataSource, AcquisitionTask, Adapter, User, MetadataDatabase, MetadataFile, MetadataRestapi, AcquisitionLog
} = dc.models;
AcquisitionTask.belongsTo(DataSource, { foreignKey: 'dataSourceId', targetKey: 'id' });
DataSource.hasMany(AcquisitionTask, { foreignKey: 'dataSourceId', sourceKey: 'id' });
+ AcquisitionLog.belongsTo(AcquisitionTask, { foreignKey: 'task', targetKey: 'id' });
+ AcquisitionTask.hasMany(AcquisitionLog, { foreignKey: 'task', sourceKey: 'id' });
DataSource.belongsTo(Adapter, { foreignKey: 'adapterId', targetKey: 'id' });
Adapter.hasMany(DataSource, { foreignKey: 'adapterId', sourceKey: 'id' });
@@ -69,6 +71,6 @@ module.exports.models = function (dc) {
MetadataRestapi.belongsTo(User, { foreignKey: 'createBy', targetKey: 'id' });
-
+
};
diff --git a/api/app/lib/routes/metadataAcquisition/log.js b/api/app/lib/routes/metadataAcquisition/log.js
new file mode 100644
index 0000000..76f2367
--- /dev/null
+++ b/api/app/lib/routes/metadataAcquisition/log.js
@@ -0,0 +1,11 @@
+'use strict';
+
+const log = require('../../controllers/metadataAcquisition/log');
+
+module.exports = function (app, router, opts, AuthCode) {
+
+ //获取采集任务列表
+ app.fs.api.logAttr['GET/meta/acq/logs'] = { content: '获取采集任务列表', visible: true };
+ router.get('/meta/acq/logs', log.getAcquisitionTask(opts));
+
+};
diff --git a/web/client/src/sections/metadataAcquisition/actions/index.js b/web/client/src/sections/metadataAcquisition/actions/index.js
index 115de9b..c419cad 100644
--- a/web/client/src/sections/metadataAcquisition/actions/index.js
+++ b/web/client/src/sections/metadataAcquisition/actions/index.js
@@ -4,9 +4,11 @@ import * as example from './example'
import * as adapter from './adapter'
import * as dataSource from './dataSource'
import * as task from './task';
+import * as log from './log';
export default {
...example,
...adapter,
...dataSource,
- ...task
+ ...task,
+ ...log
}
\ No newline at end of file
diff --git a/web/client/src/sections/metadataAcquisition/actions/log.js b/web/client/src/sections/metadataAcquisition/actions/log.js
new file mode 100644
index 0000000..0fba54a
--- /dev/null
+++ b/web/client/src/sections/metadataAcquisition/actions/log.js
@@ -0,0 +1,16 @@
+'use strict';
+
+import { basicAction } from '@peace/utils'
+import { ApiTable } from '$utils'
+
+export function getLogs(query) {
+ return dispatch => basicAction({
+ type: 'get',
+ dispatch: dispatch,
+ query: query || {},
+ actionType: 'GET_ACQ_LOGS',
+ url: `${ApiTable.getLogs}`,
+ msg: { error: '获取采集日志失败' },
+ reducer: { name: 'acqlogs' }
+ });
+}
\ No newline at end of file
diff --git a/web/client/src/sections/metadataAcquisition/containers/acquisitionLog.js b/web/client/src/sections/metadataAcquisition/containers/acquisitionLog.js
index a9ddc89..5c36487 100644
--- a/web/client/src/sections/metadataAcquisition/containers/acquisitionLog.js
+++ b/web/client/src/sections/metadataAcquisition/containers/acquisitionLog.js
@@ -6,22 +6,20 @@ import moment from 'moment';
import './style.less';
function AcquisitionLog(props) {
- const { loading, clientHeight, actions, dispatch, dataSources, adapters, tasks } = props;
+ const { loading, clientHeight, actions, dispatch, acqlogs } = 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,
+ limit: search ? 10 : pageSize || 10,
+ page: search ? 1 : currentPage || 1,
taskName: searchValue
}
- dispatch(actions.metadataAcquisition.getTasks(query));
+ dispatch(actions.metadataAcquisition.getLogs(query));
}
useEffect(() => {
- dispatch(actions.metadataAcquisition.getDataSources());
- dispatch(actions.metadataAcquisition.getAdapters())
queryData();
}, [pageSize, currentPage]);
@@ -29,29 +27,24 @@ function AcquisitionLog(props) {
{
title: '任务名称',
dataIndex: 'taskName',
+ render: (text, record) => {
+ return record?.acquisitionTask?.taskName;
+ }
},
{
title: '数据源名称',
dataIndex: 'dataSourceName',
render: (text, record) => {
- return record?.dataSource?.name
+ return record?.acquisitionTask?.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: '执行周期',
@@ -68,52 +61,6 @@ function AcquisitionLog(props) {
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
@@ -136,28 +83,28 @@ function AcquisitionLog(props) {
}
pagination={{
size: 'large',
- total: tasks?.count,
+ total: acqlogs?.count,
showSizeChanger: true,
- // showQuickJumper: true,
- // current: currentPage,
- // pageSize: pageSize || 10,
+ showQuickJumper: true,
+ current: currentPage,
+ pageSize: pageSize || 10,
defaultPageSize: 10,
pageSizeOptions: [10, 20, 50],
- // showTotal: (total) => {
- // return {`共${Math.ceil(total / pageSize)}页,${total}项`}
- // },
- // onShowSizeChange: (currentPage, pageSize) => {
- // setCurrentPage(currentPage);
- // setPageSize(pageSize);
-
- // },
- // onChange: (page, pageSize) => {
- // setCurrentPage(page);
- // setPageSize(pageSize);
+ showTotal: (total) => {
+ return {`共${Math.ceil(total / pageSize)}页,${total}项`}
+ },
+ onShowSizeChange: (currentPage, pageSize) => {
+ setCurrentPage(currentPage);
+ setPageSize(pageSize);
+
+ },
+ onChange: (page, pageSize) => {
+ setCurrentPage(page);
+ setPageSize(pageSize);
- // }
+ }
}}
- dataSource={tasks?.rows || []}
+ dataSource={acqlogs?.rows || []}
options={false}
/>
@@ -166,15 +113,14 @@ function AcquisitionLog(props) {
function mapStateToProps(state) {
const {
- auth, global, datasources, adapters, tasks
+ global, acqlogs
} = state;
return {
- loading: datasources.isRequesting || adapters?.isRequesting,
+ loading: acqlogs.isRequesting,
clientHeight: global.clientHeight,
actions: global.actions,
- dataSources: datasources?.data || {},
- adapters: adapters?.data || [],
- tasks: tasks?.data || [],
+ acqlogs: acqlogs?.data || {},
+
};
}
diff --git a/web/client/src/utils/webapi.js b/web/client/src/utils/webapi.js
index dc0bee9..4239b66 100644
--- a/web/client/src/utils/webapi.js
+++ b/web/client/src/utils/webapi.js
@@ -44,8 +44,10 @@ export const ApiTable = {
addTask: 'meta/acq/task',
getTasks: 'meta/acq/tasks',
modifyTask: 'acq/task/{id}',
- runTask: 'run/acq/task'
-
+ runTask: 'run/acq/task',
+
+ //采集日志
+ getLogs:"meta/acq/logs"
};
export const RouteTable = {