From dea0e78b4f3b35d258fe379ff21695219cdb1708 Mon Sep 17 00:00:00 2001 From: zhangminghua Date: Fri, 26 May 2023 15:13:30 +0800 Subject: [PATCH] =?UTF-8?q?(+)=E6=8E=A5=E5=8F=A3=E4=B8=9A=E5=8A=A1?= =?UTF-8?q?=E5=85=83=E6=95=B0=E6=8D=AE=E5=A2=9E=E5=88=A0=E6=94=B9=E6=9F=A5?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/controllers/businessMetadata/index.js | 127 ++++++++++++++++++ api/app/lib/routes/businessMetadata/index.js | 13 ++ 2 files changed, 140 insertions(+) diff --git a/api/app/lib/controllers/businessMetadata/index.js b/api/app/lib/controllers/businessMetadata/index.js index 182d03c..1c81a26 100644 --- a/api/app/lib/controllers/businessMetadata/index.js +++ b/api/app/lib/controllers/businessMetadata/index.js @@ -261,6 +261,128 @@ async function delBusinessMetadataFiles(ctx) { ctx.body = { message: '删除业务元数据失败' } } } + +//获取接口业务元数据列表 +async function getBusinessMetadataRestapis(ctx) { + try { + const models = ctx.fs.dc.models; + const { catalog, limit, offset, keywords, orderBy = 'updateAt', orderDirection = 'desc' } = ctx.query; + const where = {}; + if (catalog) { + where.catalog = catalog; + } + if (keywords) { + where.name = { $iLike: `%${keywords}%` }; + } + const findObj = { + include: [{ + model: models.BusinessMetadataRestapi, + include: [ + { + model: models.User, + attributes: ['id', 'name', 'username'], + }] + }], + attributes: { exclude: ['catalogKey', 'createAt', 'createBy', 'updateAt'] }, + where: where, + order: [[models.BusinessMetadataRestapi, orderBy, orderDirection + ' NULLS LAST']], + distinct: true + } + if (Number(limit) > 0 && Number(offset) >= 0) { + findObj.offset = Number(offset) * Number(limit); + findObj.limit = Number(limit); + } + const rslt = await models.MetadataRestapi.findAndCountAll(findObj); + ctx.status = 200; + ctx.body = rslt; + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = { + "message": "获取业务元数据列表失败" + } + } +} +//新建接口业务元数据 +async function postBusinessMetadataRestapis(ctx) { + try { + const { resourceName, resourceAbstract, resourceProvider, resourceCategory, resourceId, metadataId, + createBy, metadataRestapiId } = ctx.request.body; + const models = ctx.fs.dc.models; + if (!resourceName || !resourceAbstract || !resourceProvider || + !resourceCategory || !resourceId || !metadataId || + !createBy || !metadataRestapiId) { + ctx.body = { message: '参数不全,请重新配置' } + ctx.status = 400; + } else { + await models.BusinessMetadataRestapi.create({ createAt: moment(), updateAt: moment(), ...ctx.request.body }); + ctx.body = { message: '新建业务元数据成功' } + ctx.status = 200; + } + + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = { + "message": "新建业务元数据失败" + } + } +} +//修改接口业务元数据 +async function putBusinessMetadataRestapis(ctx) { + try { + const { id } = ctx.params; + const models = ctx.fs.dc.models; + let businessMetadataInfo = await models.BusinessMetadataRestapi.findOne({ where: { id } }); + if (businessMetadataInfo) { + const { resourceName, resourceAbstract, resourceProvider, resourceCategory, resourceId, metadataId } = ctx.request.body; + if (!resourceName || !resourceAbstract || !resourceProvider || + !resourceCategory || !resourceId || !metadataId) { + ctx.body = { message: '参数不全,请重新配置' } + ctx.status = 400; + } else { + await models.BusinessMetadataRestapi.update({ updateAt: moment(), ...ctx.request.body }, { where: { id: id } }); + ctx.status = 200; + ctx.body = { message: '修改业务元数据成功' } + } + } else { + ctx.status = 400; + ctx.body = { message: '该业务元数据不存在' } + } + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = { + "message": "修改业务元数据失败" + } + } +} +//删除接口业务元数据 +async function delBusinessMetadataRestapis(ctx) { + const transaction = await ctx.fs.dc.orm.transaction(); + try { + const models = ctx.fs.dc.models; + const { id } = ctx.params; + let businessMetadataInfo = await models.BusinessMetadataRestapi.findOne({ where: { id } }); + if (businessMetadataInfo) { + await models.BusinessMetadataRestapi.destroy({ + where: { id: id }, + transaction + }) + await transaction.commit(); + ctx.status = 200; + ctx.body = { message: '删除业务元数据成功' } + } else { + ctx.status = 400; + ctx.body = { message: '该业务元数据不存在' } + } + } catch (error) { + await transaction.rollback(); + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = { message: '删除业务元数据失败' } + } +} module.exports = { getBusinessMetadataDatabases, postBusinessMetadataDatabases, @@ -271,4 +393,9 @@ module.exports = { postBusinessMetadataFiles, putBusinessMetadataFiles, delBusinessMetadataFiles, + + getBusinessMetadataRestapis, + postBusinessMetadataRestapis, + putBusinessMetadataRestapis, + delBusinessMetadataRestapis, } \ No newline at end of file diff --git a/api/app/lib/routes/businessMetadata/index.js b/api/app/lib/routes/businessMetadata/index.js index 322fcb9..14d0b08 100644 --- a/api/app/lib/routes/businessMetadata/index.js +++ b/api/app/lib/routes/businessMetadata/index.js @@ -27,4 +27,17 @@ module.exports = function (app, router, opts) { app.fs.api.logAttr['DEL/business/metadata/files/:id'] = { content: '删除文件业务元数据', visible: true }; router.delete('/business/metadata/files/:id', businessMetadata.delBusinessMetadataFiles); + + + app.fs.api.logAttr['GET/business/metadata/restapis'] = { content: '获取接口业务元数据列表', visible: false }; + router.get('/business/metadata/restapis', businessMetadata.getBusinessMetadataRestapis); + + app.fs.api.logAttr['POST/business/metadata/restapis'] = { content: '新建接口业务元数据', visible: true }; + router.post('/business/metadata/restapis', businessMetadata.postBusinessMetadataRestapis); + + app.fs.api.logAttr['PUT/business/metadata/restapis/:id'] = { content: '修改接口业务元数据', visible: true }; + router.put('/business/metadata/restapis/:id', businessMetadata.putBusinessMetadataRestapis); + + app.fs.api.logAttr['DEL/business/metadata/restapis/:id'] = { content: '删除接口业务元数据', visible: true }; + router.delete('/business/metadata/restapis/:id', businessMetadata.delBusinessMetadataRestapis); }; \ No newline at end of file