Browse Source

(*)采集任务接口提交

master
peng.peng 2 years ago
parent
commit
a34731ae41
  1. 128
      api/app/lib/controllers/metadataAcquisition/task.js
  2. 22
      api/app/lib/routes/metadataAcquisition/task.js
  3. 2
      web/client/src/sections/metadataAcquisition/components/steps/postgre/stepThree.js

128
api/app/lib/controllers/metadataAcquisition/task.js

@ -0,0 +1,128 @@
'use strict';
// 新增采集任务
function addAcquisitionTask(opts) {
return async function (ctx, next) {
const models = ctx.fs.dc.models;
try {
const { taskName } = ctx.request.body
const checkName = await models.AcquisitionTask.findOne({ where: { taskName, taskName } });
if (checkName) {
ctx.status = 400;
ctx.body = { message: '该采集任务名称已存在' }
} else {
let rslt = ctx.request.body;
await models.AcquisitionTask.create(Object.assign({}, rslt))
let datasource = await models.AcquisitionTask.findOne({ where: { taskName } })
ctx.status = 200;
ctx.body = { message: '新建采集任务成功', id: datasource.id }
}
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = { message: '新建采集任务失败' }
}
}
}
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"]],
}
if (taskName) {
searchWhere.taskName = {
// 模糊查询
[Op.like]: '%' + 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.AcquisitionTask.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
}
}
}
// 修改采集任务
function editAcquisitionTask(opts) {
return async function (ctx, next) {
try {
const models = ctx.fs.dc.models;
const { id } = ctx.params;
const body = ctx.request.body;
const { taskName } = ctx.request.body
const checkName = await models.AcquisitionTask.findOne({ where: { id: { $not: id }, taskName, taskName } });
if (checkName) {
ctx.status = 400;
ctx.body = { message: '该采集任务名称已存在' }
} else {
await models.AcquisitionTask.update(
body,
{ where: { id: id, } }
)
ctx.status = 204;
ctx.body = { message: '修改采集任务成功' }
}
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = { message: '修改采集任务失败' }
}
}
}
// 删除采集任务
function deleteAcquisitionTask(opts) {
return async function (ctx, next) {
try {
const models = ctx.fs.dc.models;
const { id } = ctx.params;
await models.AcquisitionTask.destroy({
where: {
id: id
}
})
ctx.status = 204;
ctx.body = { message: '删除采集任务成功' }
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = { message: '删除采集任务失败' }
}
}
}
module.exports = {
addAcquisitionTask,
getAcquisitionTask,
editAcquisitionTask,
deleteAcquisitionTask
}

22
api/app/lib/routes/metadataAcquisition/task.js

@ -0,0 +1,22 @@
'use strict';
const task = require('../../controllers/metadataAcquisition/task');
module.exports = function (app, router, opts, AuthCode) {
app.fs.api.logAttr['POST/meta/acq/task'] = { content: '增加采集任务信息', visible: true };
router.post('/meta/acq/task', task.addAcquisitionTask(opts))
//获取采集任务列表
app.fs.api.logAttr['GET/meta/acq/tasks'] = { content: '获取采集任务列表', visible: true };
router.get('/meta/acq/tasks', task.getAcquisitionTask(opts));
// 修改采集任务信息
app.fs.api.logAttr['PUT/acq/task/:id'] = { content: '修改采集任务信息', visible: true };
router.put('/acq/task/:id', task.editAcquisitionTask(opts))
// 删除采集任务信息
app.fs.api.logAttr['DEL/acq/task/:id'] = { content: '删除采集任务信息', visible: true };
router.del('acq/task/:id', task.deleteAcquisitionTask(opts))
};

2
web/client/src/sections/metadataAcquisition/components/steps/postgre/stepThree.js

@ -42,6 +42,7 @@ function StepThree(props) {
> >
<ProForm.Group title="请输入该计划任务执行时间"> <ProForm.Group title="请输入该计划任务执行时间">
<ProFormText <ProFormText
width="md"
rules={[{ required: true, message: '请输入数据源名称' }, rules={[{ required: true, message: '请输入数据源名称' },
{ max: 255, message: '数据源名称长度不能大于255个字符' }, { max: 255, message: '数据源名称长度不能大于255个字符' },
]} ]}
@ -83,6 +84,7 @@ function StepThree(props) {
name="retryCount" name="retryCount"
label="重试次数" label="重试次数"
fieldProps={{ precision: 0, max: 10, }} fieldProps={{ precision: 0, max: 10, }}
addonAfter={' '}
/> />
<ProFormDigit <ProFormDigit

Loading…
Cancel
Save