|
|
@ -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 |
|
|
|
} |