From 4dc95a8a9eb4d47533450af30e4cddd6cc8fffe5 Mon Sep 17 00:00:00 2001 From: zhangminghua Date: Tue, 21 Mar 2023 15:13:32 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=85=83=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=9F=A5=E8=AF=A2=E5=88=97=E8=A1=A8=E8=B7=AF=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/client/src/utils/webapi.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/web/client/src/utils/webapi.js b/web/client/src/utils/webapi.js index 1c17926..dcc6c0b 100644 --- a/web/client/src/utils/webapi.js +++ b/web/client/src/utils/webapi.js @@ -22,6 +22,10 @@ export const ApiTable = { postResourceCatalog: 'resource-catalog', putResourceCatalog: 'resource-catalog/{id}', delResourceCatalog: 'resource-catalog/{id}', + //最新元数据-元数据列表查询 + getMeatadataDatabases: 'metadata/databases', + getMeatadataFiles: 'metadata/files', + getMeatadataRestapis: 'metadata/restapis', //元数据采集-数据源管理 pgCheckConnect: 'adapter/check/connect', From a0de61b70a905e02ee8ee5466acd0d783c8aeb08 Mon Sep 17 00:00:00 2001 From: zhangminghua Date: Tue, 21 Mar 2023 15:18:43 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=85=83=E6=95=B0=E6=8D=AE=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E8=B7=AF=E7=94=B1=E5=90=8D=E7=A7=B0=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/client/src/utils/webapi.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/web/client/src/utils/webapi.js b/web/client/src/utils/webapi.js index dcc6c0b..c4e9dae 100644 --- a/web/client/src/utils/webapi.js +++ b/web/client/src/utils/webapi.js @@ -23,9 +23,9 @@ export const ApiTable = { putResourceCatalog: 'resource-catalog/{id}', delResourceCatalog: 'resource-catalog/{id}', //最新元数据-元数据列表查询 - getMeatadataDatabases: 'metadata/databases', - getMeatadataFiles: 'metadata/files', - getMeatadataRestapis: 'metadata/restapis', + getMetadataDatabases: 'metadata/databases', + getMetadataFiles: 'metadata/files', + getMetadataRestapis: 'metadata/restapis', //元数据采集-数据源管理 pgCheckConnect: 'adapter/check/connect', From f855c48282f920f8f3c5e299cb00cd81c43842b6 Mon Sep 17 00:00:00 2001 From: zhangminghua Date: Tue, 21 Mar 2023 16:16:30 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=BA=93=E8=A1=A8?= =?UTF-8?q?=E3=80=81=E6=96=87=E4=BB=B6=E3=80=81=E6=8E=A5=E5=8F=A3=E5=85=83?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=9F=A5=E8=AF=A2api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/controllers/latestMetadata/index.js | 118 +++++++++++++++++- api/app/lib/index.js | 73 ++++++----- api/app/lib/models/tag_database.js | 11 +- api/app/lib/models/tag_file.js | 11 +- api/app/lib/models/tag_restapi.js | 11 +- api/app/lib/routes/latestMetadata/index.js | 9 ++ 6 files changed, 194 insertions(+), 39 deletions(-) diff --git a/api/app/lib/controllers/latestMetadata/index.js b/api/app/lib/controllers/latestMetadata/index.js index 87a881a..705a249 100644 --- a/api/app/lib/controllers/latestMetadata/index.js +++ b/api/app/lib/controllers/latestMetadata/index.js @@ -1,5 +1,5 @@ 'use strict'; -//获取资源目录列表 +//获取资源目录 async function getResourceCatalog(ctx) { try { const models = ctx.fs.dc.models; @@ -107,9 +107,123 @@ async function delResourceCatalog(ctx) { ctx.body = { message: '删除资源目录失败' } } } +//获取库表元数据列表 +async function getMetadataDatabases(ctx) { + try { + const models = ctx.fs.dc.models; + const { catalog, limit, offset, keywords, orderBy = 'createAt', orderDirection = 'desc' } = ctx.query; + const where = { catalog: catalog }; + if (keywords) { + where[$or] = [{ name: { $like: keywords } }, { code: { $like: keywords } }, { type: { $like: keywords } }] + } + const rslt = await models.MetadataDatabase.findAll({ + include: [ + { + model: models.User, + attributes: ['id', 'name'], + }, + { + model: models.TagDatabase, + include: [{ + model: models.Tag, + }] + }], + where: where, + order: [[orderBy, orderDirection]], + offset: Number(offset) * Number(limit), + limit: Number(limit), + distinct: true + }); + 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 getMetadataFiles(ctx) { + try { + const models = ctx.fs.dc.models; + const { catalog, limit, offset, keywords, orderBy = 'createAt', orderDirection = 'desc' } = ctx.query; + const where = { catalog: catalog }; + if (keywords) { + where[$or] = [{ name: { $like: keywords } }, { type: { $like: keywords } }] + } + const rslt = await models.MetadataFile.findAll({ + include: [ + { + model: models.User, + attributes: ['id', 'name'], + }, + { + model: models.TagFile, + include: [{ + model: models.Tag, + }] + }], + where: where, + order: [[orderBy, orderDirection]], + offset: Number(offset) * Number(limit), + limit: Number(limit), + distinct: true + }); + 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 getMetadataRestapis(ctx) { + try { + const models = ctx.fs.dc.models; + const { catalog, limit, offset, keywords, orderBy = 'createAt', orderDirection = 'desc' } = ctx.query; + const where = { catalog: catalog }; + if (keywords) { + where.name = { $like: keywords }; + } + const rslt = await models.MetadataRestapi.findAll({ + include: [ + { + model: models.User, + attributes: ['id', 'name'], + }, + { + model: models.TagRestapi, + include: [{ + model: models.Tag, + }] + }], + where: where, + order: [[orderBy, orderDirection]], + offset: Number(offset) * Number(limit), + limit: Number(limit), + distinct: true + }); + 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, putResourceCatalog, - delResourceCatalog + delResourceCatalog, + getMetadataDatabases, + getMetadataFiles, + getMetadataRestapis } \ No newline at end of file diff --git a/api/app/lib/index.js b/api/app/lib/index.js index 493d17a..c6e05d8 100644 --- a/api/app/lib/index.js +++ b/api/app/lib/index.js @@ -13,56 +13,61 @@ const schedule = require('./schedule') // const apiLog = require('./middlewares/api-log'); module.exports.entry = function (app, router, opts) { - app.fs.logger.log('info', '[FS-AUTH]', 'Inject auth and api mv into router.'); + app.fs.logger.log('info', '[FS-AUTH]', 'Inject auth and api mv into router.'); - app.fs.api = app.fs.api || {}; - app.fs.opts = opts || {}; - app.fs.utils = app.fs.utils || {}; - app.fs.api.authAttr = app.fs.api.authAttr || {}; - app.fs.api.logAttr = app.fs.api.logAttr || {}; + app.fs.api = app.fs.api || {}; + app.fs.opts = opts || {}; + app.fs.utils = app.fs.utils || {}; + app.fs.api.authAttr = app.fs.api.authAttr || {}; + app.fs.api.logAttr = app.fs.api.logAttr || {}; - // 顺序固定 ↓ - //redisConnect(app, opts) - socketConect(app, opts) + // 顺序固定 ↓ + //redisConnect(app, opts) + socketConect(app, opts) - // 实例其他平台请求方法 - paasRequest(app, opts) + // 实例其他平台请求方法 + paasRequest(app, opts) - // clickHouse 数据库 client - // clickHouseClient(app, opts) + // clickHouse 数据库 client + // clickHouseClient(app, opts) - // 工具类函数 - utils(app, opts) + // 工具类函数 + utils(app, opts) - // 定时任务 - schedule(app, opts) + // 定时任务 + schedule(app, opts) - //鉴权中间件 - router.use(authenticator(app, opts)); + //鉴权中间件 + router.use(authenticator(app, opts)); - // 日志记录 - // router.use(apiLog(app, opts)); + // 日志记录 + // router.use(apiLog(app, opts)); - router = routes(app, router, opts); + router = routes(app, router, opts); }; module.exports.models = function (dc) { - // dc = { orm: Sequelize对象, ORM: Sequelize, models: {} } + // dc = { orm: Sequelize对象, ORM: Sequelize, models: {} } - // 模型关系摘出来 初始化之后再定义关系才行 - fs.readdirSync(path.join(__dirname, '/models')).forEach((filename) => { - require(`./models/${filename}`)(dc) - }); + // 模型关系摘出来 初始化之后再定义关系才行 + fs.readdirSync(path.join(__dirname, '/models')).forEach((filename) => { + require(`./models/${filename}`)(dc) + }); - const { - DataSource, AcquisitionTask, Adapter - } = dc.models; + const { + DataSource, AcquisitionTask, Adapter, User, MetadataDatabase, MetadataFile, MetadataRestapi + } = dc.models; - AcquisitionTask.belongsTo(DataSource, { foreignKey: 'dataSourceId', targetKey: 'id' }); - DataSource.hasMany(AcquisitionTask, { foreignKey: 'dataSourceId', sourceKey: 'id' }); + AcquisitionTask.belongsTo(DataSource, { foreignKey: 'dataSourceId', targetKey: 'id' }); + DataSource.hasMany(AcquisitionTask, { foreignKey: 'dataSourceId', sourceKey: 'id' }); + + DataSource.belongsTo(Adapter, { foreignKey: 'adapterId', targetKey: 'id' }); + Adapter.hasMany(DataSource, { foreignKey: 'adapterId', sourceKey: 'id' }); + + MetadataDatabase.belongsTo(User, { foreignKey: 'createBy', targetKey: 'id' }); + MetadataFile.belongsTo(User, { foreignKey: 'createBy', targetKey: 'id' }); + MetadataRestapi.belongsTo(User, { foreignKey: 'createBy', targetKey: 'id' }); - DataSource.belongsTo(Adapter, { foreignKey: 'adapterId', targetKey: 'id' }); - Adapter.hasMany(DataSource, { foreignKey: 'adapterId', sourceKey: 'id' }); }; diff --git a/api/app/lib/models/tag_database.js b/api/app/lib/models/tag_database.js index 6ac90c7..8c2d682 100644 --- a/api/app/lib/models/tag_database.js +++ b/api/app/lib/models/tag_database.js @@ -16,7 +16,7 @@ module.exports = dc => { autoIncrement: true, unique: "t_tag_database_id_uindex" }, - tag: { + tagId: { type: DataTypes.INTEGER, allowNull: false, defaultValue: null, @@ -48,5 +48,14 @@ module.exports = dc => { indexes: [] }); dc.models.TagDatabase = TagDatabase; + + const { MetadataDatabase } = dc.models; + TagDatabase.belongsTo(MetadataDatabase, { foreignKey: 'database', targetKey: 'id' }); + MetadataDatabase.hasMany(TagDatabase, { foreignKey: 'database', sourceKey: 'id' }); + + const { Tag } = dc.models; + TagDatabase.belongsTo(Tag, { foreignKey: 'tagId', targetKey: 'id' }); + Tag.hasMany(TagDatabase, { foreignKey: 'tagId', sourceKey: 'id' }); + return TagDatabase; }; \ No newline at end of file diff --git a/api/app/lib/models/tag_file.js b/api/app/lib/models/tag_file.js index 5cf4453..c7ff7eb 100644 --- a/api/app/lib/models/tag_file.js +++ b/api/app/lib/models/tag_file.js @@ -16,7 +16,7 @@ module.exports = dc => { autoIncrement: true, unique: "t_tag_file_id_uindex" }, - tag: { + tagId: { type: DataTypes.INTEGER, allowNull: false, defaultValue: null, @@ -48,5 +48,14 @@ module.exports = dc => { indexes: [] }); dc.models.TagFile = TagFile; + + const { MetadataFile } = dc.models; + TagFile.belongsTo(MetadataFile, { foreignKey: 'file', targetKey: 'id' }); + MetadataFile.hasMany(TagFile, { foreignKey: 'file', sourceKey: 'id' }); + + const { Tag } = dc.models; + TagFile.belongsTo(Tag, { foreignKey: 'tagId', targetKey: 'id' }); + Tag.hasMany(TagFile, { foreignKey: 'tagId', sourceKey: 'id' }); + return TagFile; }; \ No newline at end of file diff --git a/api/app/lib/models/tag_restapi.js b/api/app/lib/models/tag_restapi.js index 461d44b..fc70bf8 100644 --- a/api/app/lib/models/tag_restapi.js +++ b/api/app/lib/models/tag_restapi.js @@ -16,7 +16,7 @@ module.exports = dc => { autoIncrement: true, unique: "t_tag_restapi_id_uindex" }, - tag: { + tagId: { type: DataTypes.INTEGER, allowNull: false, defaultValue: null, @@ -48,5 +48,14 @@ module.exports = dc => { indexes: [] }); dc.models.TagRestapi = TagRestapi; + + const { MetadataRestapi } = dc.models; + TagRestapi.belongsTo(MetadataRestapi, { foreignKey: 'restapi', targetKey: 'id' }); + MetadataRestapi.hasMany(TagRestapi, { foreignKey: 'restapi', sourceKey: 'id' }); + + const { Tag } = dc.models; + TagRestapi.belongsTo(Tag, { foreignKey: 'tagId', targetKey: 'id' }); + Tag.hasMany(TagRestapi, { foreignKey: 'tagId', sourceKey: 'id' }); + return TagRestapi; }; \ 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 8f3a33f..8cfc11e 100644 --- a/api/app/lib/routes/latestMetadata/index.js +++ b/api/app/lib/routes/latestMetadata/index.js @@ -15,4 +15,13 @@ module.exports = function (app, router, opts) { 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 }; + router.get('/metadata/databases', latestMetadata.getMetadataDatabases); + + app.fs.api.logAttr['GET/metadata/files'] = { content: '获取文件元数据列表', visible: false }; + router.get('/metadata/files', latestMetadata.getMetadataFiles); + + app.fs.api.logAttr['GET/metadata/restapis'] = { content: '获取接口元数据列表', visible: false }; + router.get('/metadata/restapis', latestMetadata.getMetadataRestapis); + }; \ No newline at end of file