From 343ea5dab99cf9f81e5abc6ebf21ac9b73bb2446 Mon Sep 17 00:00:00 2001 From: zhangminghua Date: Fri, 31 Mar 2023 15:10:16 +0800 Subject: [PATCH 01/10] =?UTF-8?q?=E5=BA=93=E8=A1=A8=E5=85=83=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=20=E6=89=93=E6=A0=87=E6=96=B0=E5=A2=9E=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E3=80=81=E8=B5=84=E6=BA=90=E7=94=B3=E8=AF=B7=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/controllers/latestMetadata/index.js | 174 ++++++++++++++++-- api/app/lib/routes/latestMetadata/index.js | 30 ++- .../metadataManagement/actions/metadata.js | 47 ++++- .../components/metadataDatabaseModal.js | 4 +- .../components/metadataResourceModal.js | 53 ++++++ .../components/metadataTagModal.js | 79 ++++++++ .../containers/databasesTable.js | 87 ++++++++- .../containers/metadataDetails.js | 2 +- web/client/src/utils/webapi.js | 16 +- 9 files changed, 445 insertions(+), 47 deletions(-) create mode 100644 web/client/src/sections/metadataManagement/components/metadataResourceModal.js create mode 100644 web/client/src/sections/metadataManagement/components/metadataTagModal.js diff --git a/api/app/lib/controllers/latestMetadata/index.js b/api/app/lib/controllers/latestMetadata/index.js index eb7ade1..1fa043e 100644 --- a/api/app/lib/controllers/latestMetadata/index.js +++ b/api/app/lib/controllers/latestMetadata/index.js @@ -31,9 +31,14 @@ async function postResourceCatalog(ctx) { ctx.status = 400; ctx.body = { message: '该资源目录名称或代码已存在' } } else { - await models.ResourceCatalog.create(ctx.request.body); - ctx.body = { message: '新建资源目录成功' } - ctx.status = 200; + if (!name || !code) { + ctx.body = { message: '参数不全,请重新配置' } + ctx.status = 400; + } else { + await models.ResourceCatalog.create(ctx.request.body); + ctx.body = { message: '新建资源目录成功' } + ctx.status = 200; + } } } catch (error) { ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); @@ -260,7 +265,7 @@ async function getMetadataModels(ctx) { } //新建库表元数据 -async function postMeatadataDatabases(ctx) { +async function postMetadataDatabases(ctx) { try { const { name, code, catalog } = ctx.request.body; const models = ctx.fs.dc.models; @@ -271,9 +276,14 @@ async function postMeatadataDatabases(ctx) { ctx.status = 400; ctx.body = { message: '该资源目录下元数据名称或代码已存在' } } else { - await models.MetadataDatabase.create({ createAt: moment(), ...ctx.request.body }); - ctx.body = { message: '新建元数据成功' } - ctx.status = 200; + if (!name || !code || !catalog) { + ctx.body = { message: '参数不全,请重新配置' } + ctx.status = 400; + } else { + await models.MetadataDatabase.create({ createAt: moment(), ...ctx.request.body }); + ctx.body = { message: '新建元数据成功' } + ctx.status = 200; + } } } catch (error) { ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); @@ -285,7 +295,7 @@ async function postMeatadataDatabases(ctx) { } //修改库表元数据 -async function putMeatadataDatabases(ctx) { +async function putMetadataDatabases(ctx) { try { const { id } = ctx.params; const { catalog, name, code } = ctx.request.body; @@ -314,7 +324,7 @@ async function putMeatadataDatabases(ctx) { } } //删除库表元数据 -async function delMeatadataDatabases(ctx) { +async function delMetadataDatabases(ctx) { const transaction = await ctx.fs.dc.orm.transaction(); try { const models = ctx.fs.dc.models; @@ -397,6 +407,140 @@ async function getMetadataDatabasesById(ctx) { } } } + +//打标元数据 +async function postTagMetadata(ctx) { + const transaction = await ctx.fs.dc.orm.transaction(); + try { + const { tags, database, file, restapi } = ctx.request.body; + const models = ctx.fs.dc.models; + if (tags.length && (database || file || restapi)) { + if (database) { + await models.TagDatabase.destroy({ where: { database: database }, transaction }); + const data = tags.map(tag => { return { tagId: tag, database: database } }); + if (data.length) + await models.TagDatabase.bulkCreate(data, { transaction }); + } + if (file) { + await models.TagFile.destroy({ where: { file: file }, transaction }); + const data = tags.map(tag => { return { tagId: tag, file: file } }); + if (data.length) + await models.TagFile.bulkCreate(data, { transaction }); + } + if (restapi) { + await models.TagRestapi.destroy({ where: { restapi: restapi }, transaction }); + const data = tags.map(tag => { return { tagId: tag, restapi: restapi } }); + if (data.length) + await models.TagRestapi.bulkCreate(data, { transaction }); + } + await transaction.commit(); + ctx.status = 204; + } else { + ctx.body = { message: '参数不全,请重新配置' } + ctx.status = 400; + } + } catch (error) { + await transaction.rollback(); + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = { + "message": "打标元数据失败" + } + } +} + +//获取元数据已打标数据 +async function getTagMetadata(ctx) { + try { + const models = ctx.fs.dc.models; + const { id } = ctx.params; + const { type } = ctx.query; + let rslt = []; + if (type === 'database') { + rslt = await models.Tag.findAll({ + where: { '$tagDatabases.database$': id }, + include: [{ + model: models.TagDatabase, + }], + order: [['id', 'asc']], + }); + } + if (type === 'file') { + rslt = await models.Tag.findAll({ + where: { '$tagFiles.file$': id }, + include: [{ + model: models.TagFile, + }], + order: [['id', 'asc']], + }); + } + if (type === 'restapi') { + rslt = await models.Tag.findAll({ + where: { '$tagRestapis.restapi$': id }, + include: [{ + model: models.TagRestapi, + }], + order: [['id', 'asc']], + }); + } + 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 postMetadataResourceApplications(ctx) { + try { + const { resourceName, applyBy } = ctx.request.body; + if (!resourceName || !applyBy) { + ctx.status = 400; + ctx.body = { message: '参数不全,请重新申请资源' } + } else { + const models = ctx.fs.dc.models; + const postOne = await models.ResourceConsumption.findOne({ + where: { applyBy: applyBy, resourceName: resourceName } + }); + if (postOne) { + ctx.status = 400; + ctx.body = { message: '该用户已申请过该元数据资源' } + } else { + await models.ResourceConsumption.create({ applyAt: moment(), approveState: '审批中', ...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 getMetadataResourceApplications(ctx) { + try { + const models = ctx.fs.dc.models; + const { resourceNames, type } = ctx.query; + const rslt = await models.ResourceConsumption.findAll({ + where: { resourceName: { $in: resourceNames.split(',') }, resourceType: type } + }); + ctx.status = 200; + ctx.body = rslt; + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = { + "message": "获取元数据资源申请记录失败" + } + } +} module.exports = { getResourceCatalog, postResourceCatalog, @@ -406,8 +550,12 @@ module.exports = { getMetadataFiles, getMetadataRestapis, getMetadataModels, - postMeatadataDatabases, - putMeatadataDatabases, - delMeatadataDatabases, - getMetadataDatabasesById + postMetadataDatabases, + putMetadataDatabases, + delMetadataDatabases, + getMetadataDatabasesById, + postTagMetadata, + getTagMetadata, + postMetadataResourceApplications, + getMetadataResourceApplications } \ No newline at end of file diff --git a/api/app/lib/routes/latestMetadata/index.js b/api/app/lib/routes/latestMetadata/index.js index 6f089c9..af86797 100644 --- a/api/app/lib/routes/latestMetadata/index.js +++ b/api/app/lib/routes/latestMetadata/index.js @@ -6,13 +6,13 @@ module.exports = function (app, router, opts) { app.fs.api.logAttr['GET/resource-catalog'] = { content: '获取资源目录', visible: false }; router.get('/resource-catalog', latestMetadata.getResourceCatalog); - app.fs.api.logAttr['POST /resource-catalog'] = { content: '新建资源目录', visible: true }; + app.fs.api.logAttr['POST/resource-catalog'] = { content: '新建资源目录', visible: true }; router.post('/resource-catalog', latestMetadata.postResourceCatalog); - app.fs.api.logAttr['PUT /resource-catalog/:id'] = { content: '修改资源目录', visible: true }; + app.fs.api.logAttr['PUT/resource-catalog/:id'] = { content: '修改资源目录', visible: true }; router.put('/resource-catalog/:id', latestMetadata.putResourceCatalog); - app.fs.api.logAttr['DEL /resource-catalog/:id'] = { content: '删除资源目录', visible: true }; + app.fs.api.logAttr['DEL/resource-catalog/:id'] = { content: '删除资源目录', visible: true }; router.delete('/resource-catalog/:id', latestMetadata.delResourceCatalog); app.fs.api.logAttr['GET/metadata/databases'] = { content: '获取库表元数据列表', visible: false }; @@ -27,15 +27,27 @@ module.exports = function (app, router, opts) { app.fs.api.logAttr['GET/metadata/models'] = { content: '获取元数据模型', visible: false }; router.get('/metadata/models', latestMetadata.getMetadataModels); - app.fs.api.logAttr['POST /meatadata/databases'] = { content: '新建库表元数据', visible: true }; - router.post('/meatadata/databases', latestMetadata.postMeatadataDatabases); + app.fs.api.logAttr['POST/metadata/databases'] = { content: '新建库表元数据', visible: true }; + router.post('/metadata/databases', latestMetadata.postMetadataDatabases); - app.fs.api.logAttr['PUT /meatadata/databases/:id'] = { content: '修改库表元数据', visible: true }; - router.put('/meatadata/databases/:id', latestMetadata.putMeatadataDatabases); + app.fs.api.logAttr['PUT/metadata/databases/:id'] = { content: '修改库表元数据', visible: true }; + router.put('/metadata/databases/:id', latestMetadata.putMetadataDatabases); - app.fs.api.logAttr['DEL /meatadata/databases/:id'] = { content: '删除库表元数据', visible: true }; - router.delete('/meatadata/databases/:id', latestMetadata.delMeatadataDatabases); + app.fs.api.logAttr['DEL/metadata/databases/:id'] = { content: '删除库表元数据', visible: true }; + router.delete('/metadata/databases/:id', latestMetadata.delMetadataDatabases); app.fs.api.logAttr['GET/metadata/databases/:id'] = { content: '获取库表元数据基本信息', visible: false }; router.get('/metadata/databases/:id', latestMetadata.getMetadataDatabasesById); + + app.fs.api.logAttr['POST/tag/metadata'] = { content: '打标元数据', visible: true }; + router.post('/tag/metadata', latestMetadata.postTagMetadata); + + app.fs.api.logAttr['GET/tag/metadata/:id'] = { content: '获取元数据已打标数据', visible: true }; + router.get('/tag/metadata/:id', latestMetadata.getTagMetadata); + + app.fs.api.logAttr['POST/resource-consumption/applications'] = { content: '申请资源', visible: true }; + router.post('/resource-consumption/applications', latestMetadata.postMetadataResourceApplications); + + app.fs.api.logAttr['GET/resource-consumption/applications'] = { content: '获取元数据资源申请记录', visible: true }; + router.get('/resource-consumption/applications', latestMetadata.getMetadataResourceApplications); }; \ No newline at end of file diff --git a/web/client/src/sections/metadataManagement/actions/metadata.js b/web/client/src/sections/metadataManagement/actions/metadata.js index c4f1ae0..d30d5c9 100644 --- a/web/client/src/sections/metadataManagement/actions/metadata.js +++ b/web/client/src/sections/metadataManagement/actions/metadata.js @@ -100,37 +100,37 @@ export function getMetadataModels(params) { }); } -export function postMeatadataDatabases(data) { +export function postMetadataDatabases(data) { return dispatch => basicAction({ type: 'post', data: data, dispatch: dispatch, actionType: 'POST_METADATA_DATABASES', - url: ApiTable.postMeatadataDatabases, + url: ApiTable.postMetadataDatabases, msg: { option: '新建元数据' }, reducer: {} }); } -export function putMeatadataDatabases(id, data) { +export function putMetadataDatabases(id, data) { return dispatch => basicAction({ type: 'put', data: data, dispatch, actionType: 'PUT_METADATA_DATABASES', - url: ApiTable.putMeatadataDatabases.replace('{id}', id), + url: ApiTable.putMetadataDatabases.replace('{id}', id), msg: { option: '修改元数据', } }); } -export function delMeatadataDatabases(id) { +export function delMetadataDatabases(id) { return dispatch => basicAction({ type: 'del', dispatch, actionType: 'DELETE_METADATA_DATABASES', - url: ApiTable.delMeatadataDatabases.replace('{id}', id), + url: ApiTable.delMetadataDatabases.replace('{id}', id), msg: { option: '删除元数据', } @@ -146,4 +146,39 @@ export function getMetadataDatabasesById(id) { msg: { error: '获取元数据基本信息失败' }, reducer: { name: 'metadataDatabasesInfo' } }); +} + +export function getTagMetadata(id, type) { + return dispatch => basicAction({ + type: 'get', + dispatch: dispatch, + actionType: 'GET_TAG_METADATA', + url: ApiTable.getTagMetadata.replace('{id}', id) + `?type=${type}`, + msg: { error: '获取元数据已打标数据失败' }, + reducer: { name: 'tagMetadata' } + }); +} + +export function postMetadataResourceApplications(data) { + return dispatch => basicAction({ + type: 'post', + data: data, + dispatch: dispatch, + actionType: 'POST_METADATA_RESOURCE_APPLICATIONS', + url: ApiTable.postMetadataResourceApplications, + msg: { option: '申请资源' }, + reducer: {} + }); +} + +export function getMetadataResourceApplications(params) { + return dispatch => basicAction({ + type: 'get', + dispatch: dispatch, + query: params, + actionType: 'GET_TAG_METADATA', + url: ApiTable.getMetadataResourceApplications, + msg: { error: '获取元数据资源申请记录失败' }, + reducer: { name: 'metadataResourceApplications' } + }); } \ No newline at end of file diff --git a/web/client/src/sections/metadataManagement/components/metadataDatabaseModal.js b/web/client/src/sections/metadataManagement/components/metadataDatabaseModal.js index e6dcad4..d005501 100644 --- a/web/client/src/sections/metadataManagement/components/metadataDatabaseModal.js +++ b/web/client/src/sections/metadataManagement/components/metadataDatabaseModal.js @@ -137,8 +137,8 @@ const MetadataDatabaseModal = (props) => { -