peng.peng
2 years ago
3 changed files with 152 additions and 0 deletions
@ -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 |
||||
|
} |
@ -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)) |
||||
|
|
||||
|
}; |
Loading…
Reference in new issue