From fc4c02e9a7016660d6fc71e7818bfe8a14f8ad53 Mon Sep 17 00:00:00 2001 From: zhangminghua Date: Wed, 29 Mar 2023 14:51:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=93=E8=A1=A8=E5=85=83=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BF=AE=E6=94=B9=E3=80=81=E5=88=A0=E9=99=A4?= =?UTF-8?q?=EF=BC=8C=E6=9F=A5=E7=9C=8B=E8=AF=A6=E6=83=85=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/controllers/latestMetadata/index.js | 97 +++++++++++++++++-- api/app/lib/routes/latestMetadata/index.js | 8 +- ...tadata_database&t_resource_consumption.sql | 6 ++ .../metadataManagement/actions/metadata.js | 8 +- .../components/metadataDatabModal.js | 14 ++- .../containers/databasesTable.js | 20 ++-- .../containers/metadataDetails.js | 4 +- 7 files changed, 130 insertions(+), 27 deletions(-) diff --git a/api/app/lib/controllers/latestMetadata/index.js b/api/app/lib/controllers/latestMetadata/index.js index 5c929ec..eb7ade1 100644 --- a/api/app/lib/controllers/latestMetadata/index.js +++ b/api/app/lib/controllers/latestMetadata/index.js @@ -265,25 +265,108 @@ async function postMeatadataDatabases(ctx) { const { name, code, catalog } = ctx.request.body; const models = ctx.fs.dc.models; const postOne = await models.MetadataDatabase.findOne({ - where: { $or: [{ name: name }, { code: code, catalog: catalog }] } + where: { $or: [{ name: name }, { code: code }], catalog: catalog } }); if (postOne) { ctx.status = 400; - ctx.body = { message: '该资源目录下库表元数据名称或代码已存在' } + ctx.body = { message: '该资源目录下元数据名称或代码已存在' } } else { await models.MetadataDatabase.create({ createAt: moment(), ...ctx.request.body }); - ctx.body = { message: '新建库表元数据成功' } + ctx.body = { message: '新建元数据成功' } ctx.status = 200; } } catch (error) { ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.status = 400; ctx.body = { - "message": "新建库表元数据失败" + "message": "新建元数据失败" } } } +//修改库表元数据 +async function putMeatadataDatabases(ctx) { + try { + const { id } = ctx.params; + const { catalog, name, code } = ctx.request.body; + const models = ctx.fs.dc.models; + let metadataDatabaseInfo = await models.MetadataDatabase.findOne({ where: { id } }); + if (metadataDatabaseInfo) { + const putOne = await models.MetadataDatabase.findOne({ where: { id: { $not: id }, catalog: catalog, $or: [{ name: name }, { code: code }] } }); + if (putOne) { + ctx.status = 400; + ctx.body = { message: '该元数据名称或代码已存在' } + } else { + await models.MetadataDatabase.update(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 delMeatadataDatabases(ctx) { + const transaction = await ctx.fs.dc.orm.transaction(); + try { + const models = ctx.fs.dc.models; + const { id } = ctx.params; + let metadataDatabaseInfo = await models.MetadataDatabase.findOne({ where: { id } }); + if (metadataDatabaseInfo) { + let deletable = true; + let childMetadataDatabaseInfo = await models.MetadataDatabase.findOne({ where: { parent: id } }); + if (childMetadataDatabaseInfo) { + ctx.status = 400; + ctx.body = { message: '存在关联子类元数据,请删除相关数据,再删除该元数据' } + deletable = false; + } else { + let tagDatabaseInfo = await models.TagDatabase.findOne({ where: { database: id } }); + if (tagDatabaseInfo) { + ctx.status = 400; + ctx.body = { message: '该元数据已被打标' } + deletable = false; + } else { + let resourceConsumptionInfo = await models.ResourceConsumption.findOne({ + where: { + resourceName: metadataDatabaseInfo.name, + resourceType: '库表' + } + }); + if (resourceConsumptionInfo) { + ctx.status = 400; + ctx.body = { message: '该元数据存在资源申请' } + deletable = false; + } + } + } + if (deletable) { + await models.MetadataDatabase.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: '删除元数据失败' } + } +} //获取库表元数据基本信息 async function getMetadataDatabasesById(ctx) { try { @@ -310,7 +393,7 @@ async function getMetadataDatabasesById(ctx) { ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.status = 400; ctx.body = { - "message": "获取库表元数据基本信息失败" + "message": "获取元数据基本信息失败" } } } @@ -324,7 +407,7 @@ module.exports = { getMetadataRestapis, getMetadataModels, postMeatadataDatabases, - // putMeatadataDatabases, - // delMeatadataDatabases, + putMeatadataDatabases, + delMeatadataDatabases, getMetadataDatabasesById } \ 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 0caa457..6f089c9 100644 --- a/api/app/lib/routes/latestMetadata/index.js +++ b/api/app/lib/routes/latestMetadata/index.js @@ -30,11 +30,11 @@ module.exports = function (app, router, opts) { app.fs.api.logAttr['POST /meatadata/databases'] = { content: '新建库表元数据', visible: true }; router.post('/meatadata/databases', latestMetadata.postMeatadataDatabases); - // app.fs.api.logAttr['PUT /meatadata/databases/:id'] = { content: '修改库表元数据', visible: true }; - // router.put('/meatadata/databases/:id', latestMetadata.putMeatadataDatabases); + app.fs.api.logAttr['PUT /meatadata/databases/:id'] = { content: '修改库表元数据', visible: true }; + router.put('/meatadata/databases/:id', latestMetadata.putMeatadataDatabases); - // app.fs.api.logAttr['DEL /meatadata/databases/:id'] = { content: '删除库表元数据', visible: true }; - // router.delete('/meatadata/databases/:id', latestMetadata.delMeatadataDatabases); + app.fs.api.logAttr['DEL /meatadata/databases/:id'] = { content: '删除库表元数据', visible: true }; + router.delete('/meatadata/databases/:id', latestMetadata.delMeatadataDatabases); app.fs.api.logAttr['GET/metadata/databases/:id'] = { content: '获取库表元数据基本信息', visible: false }; router.get('/metadata/databases/:id', latestMetadata.getMetadataDatabasesById); diff --git a/scripts/0.0.4/01_alter_t_metadata_database&t_resource_consumption.sql b/scripts/0.0.4/01_alter_t_metadata_database&t_resource_consumption.sql index f066a78..c7d49be 100644 --- a/scripts/0.0.4/01_alter_t_metadata_database&t_resource_consumption.sql +++ b/scripts/0.0.4/01_alter_t_metadata_database&t_resource_consumption.sql @@ -1,10 +1,16 @@ alter table t_metadata_database alter column type type varchar(255) using type::varchar(255); alter table t_resource_consumption alter column approve_state type varchar(20) using approve_state::varchar(20); + DROP TYPE "public"."enum_metadata_type"; DROP TYPE "public"."enum_approve_state"; + alter table t_metadata_database add "catalogKey" varchar(255) not null; alter table t_metadata_file add "catalogKey" varchar(255) not null; alter table t_metadata_restapi add "catalogKey" varchar(255) not null; + +-- update_at integer型需先转为varchar再转timestamp,不可直接由integer型转为timestamp +alter table t_metadata_database alter column update_at type varchar(255) using update_at::varchar(255); +alter table t_metadata_database alter column update_at type timestamp with time zone using update_at::timestamp with time zone; diff --git a/web/client/src/sections/metadataManagement/actions/metadata.js b/web/client/src/sections/metadataManagement/actions/metadata.js index c307abf..c4f1ae0 100644 --- a/web/client/src/sections/metadataManagement/actions/metadata.js +++ b/web/client/src/sections/metadataManagement/actions/metadata.js @@ -107,7 +107,7 @@ export function postMeatadataDatabases(data) { dispatch: dispatch, actionType: 'POST_METADATA_DATABASES', url: ApiTable.postMeatadataDatabases, - msg: { option: '新建库表元数据' }, + msg: { option: '新建元数据' }, reducer: {} }); } @@ -120,7 +120,7 @@ export function putMeatadataDatabases(id, data) { actionType: 'PUT_METADATA_DATABASES', url: ApiTable.putMeatadataDatabases.replace('{id}', id), msg: { - option: '修改库表元数据', + option: '修改元数据', } }); } @@ -132,7 +132,7 @@ export function delMeatadataDatabases(id) { actionType: 'DELETE_METADATA_DATABASES', url: ApiTable.delMeatadataDatabases.replace('{id}', id), msg: { - option: '删除库表元数据', + option: '删除元数据', } }); } @@ -143,7 +143,7 @@ export function getMetadataDatabasesById(id) { dispatch: dispatch, actionType: 'GET_METADATA_DATABASES_Info', url: ApiTable.getMetadataDatabasesById.replace('{id}', id), - msg: { error: '获取库表元数据基本信息失败' }, + msg: { error: '获取元数据基本信息失败' }, reducer: { name: 'metadataDatabasesInfo' } }); } \ No newline at end of file diff --git a/web/client/src/sections/metadataManagement/components/metadataDatabModal.js b/web/client/src/sections/metadataManagement/components/metadataDatabModal.js index 5f70132..e6dcad4 100644 --- a/web/client/src/sections/metadataManagement/components/metadataDatabModal.js +++ b/web/client/src/sections/metadataManagement/components/metadataDatabModal.js @@ -1,5 +1,5 @@ import React, { useEffect, useState } from 'react'; -import { Modal, Input, Form, Select, InputNumber } from 'antd'; +import { Modal, Input, Form, Select, InputNumber, Tooltip } from 'antd'; const { TextArea } = Input; const MetadataDatabaseModal = (props) => { const { onConfirm, onCancel, editData, metadataModels, modelTypes } = props; @@ -37,7 +37,9 @@ const MetadataDatabaseModal = (props) => { rules.push({ max: m.length, message: `${m.attributeName}不超过${m.length}个字符` }) } return 10 ? + {m.attributeName.substring(0, 10) + '...'} + : m.attributeName} name={m.attributeCode} rules={rules}> @@ -52,14 +54,18 @@ const MetadataDatabaseModal = (props) => { } } return 10 ? + {m.attributeName.substring(0, 10) + '...'} + : m.attributeName} name={m.attributeCode} rules={rules}> } else { return 10 ? + {m.attributeName.substring(0, 10) + '...'} + : m.attributeName} name={m.attributeCode} rules={[{ required: !m.nullable, message: `${m.attributeName}不可空` }]}>