From a34731ae41fe351cdb3ac85b4d91589f81b973da Mon Sep 17 00:00:00 2001 From: "peng.peng" Date: Tue, 21 Mar 2023 13:56:45 +0800 Subject: [PATCH] =?UTF-8?q?(*)=E9=87=87=E9=9B=86=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=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 | 128 ++++++++++++++++++ .../lib/routes/metadataAcquisition/task.js | 22 +++ .../components/steps/postgre/stepThree.js | 2 + 3 files changed, 152 insertions(+) create mode 100644 api/app/lib/controllers/metadataAcquisition/task.js create mode 100644 api/app/lib/routes/metadataAcquisition/task.js diff --git a/api/app/lib/controllers/metadataAcquisition/task.js b/api/app/lib/controllers/metadataAcquisition/task.js new file mode 100644 index 0000000..282e843 --- /dev/null +++ b/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 +} \ No newline at end of file diff --git a/api/app/lib/routes/metadataAcquisition/task.js b/api/app/lib/routes/metadataAcquisition/task.js new file mode 100644 index 0000000..cb14543 --- /dev/null +++ b/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)) + +}; diff --git a/web/client/src/sections/metadataAcquisition/components/steps/postgre/stepThree.js b/web/client/src/sections/metadataAcquisition/components/steps/postgre/stepThree.js index e6722a2..431e750 100644 --- a/web/client/src/sections/metadataAcquisition/components/steps/postgre/stepThree.js +++ b/web/client/src/sections/metadataAcquisition/components/steps/postgre/stepThree.js @@ -42,6 +42,7 @@ function StepThree(props) { >