From fa2053a7138326a204105ca1915b7017baa873e1 Mon Sep 17 00:00:00 2001 From: "peng.peng" Date: Thu, 15 Jun 2023 17:12:13 +0800 Subject: [PATCH] =?UTF-8?q?(*)=E5=85=83=E6=95=B0=E6=8D=AE=E9=87=87?= =?UTF-8?q?=E9=9B=86=20=E5=85=83=E6=95=B0=E6=8D=AE=E8=A1=A8=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=95=B0=E6=8D=AE=E6=BA=90=E8=BF=94=E5=9B=9E=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/controllers/auth/index.js | 4 +- .../metadataAcquisition/taskHandle.js | 3 ++ .../lib/controllers/metadataSearch/index.js | 37 ++++++++++++++++++- api/app/lib/models/data_source.js | 2 +- api/app/lib/models/metadata_database.js | 9 +++++ api/app/lib/routes/metadataSearch/index.js | 7 +++- 6 files changed, 55 insertions(+), 7 deletions(-) diff --git a/api/app/lib/controllers/auth/index.js b/api/app/lib/controllers/auth/index.js index eb7d901..c8959a3 100644 --- a/api/app/lib/controllers/auth/index.js +++ b/api/app/lib/controllers/auth/index.js @@ -19,12 +19,12 @@ async function login (ctx, next) { attributes: { exclude: ['password'] }, where: { username: params.username, - password: password + password: password, }, }); } if (userRes) { - if (userRes.forbidden) { + if (!userRes.enabled) { throw '用户已禁用' } else { const token = uuid.v4(); diff --git a/api/app/lib/controllers/metadataAcquisition/taskHandle.js b/api/app/lib/controllers/metadataAcquisition/taskHandle.js index 89709ef..1670aba 100644 --- a/api/app/lib/controllers/metadataAcquisition/taskHandle.js +++ b/api/app/lib/controllers/metadataAcquisition/taskHandle.js @@ -75,6 +75,8 @@ async function handleTask(app, task) { dataToSave.name = table; dataToSave.code = table; dataToSave.type = '表'; + dataToSave.datasourceConfig = dataSource.config; + const tableObj = { ...dataToSave } tableBodys.push(tableObj) } @@ -93,6 +95,7 @@ async function handleTask(app, task) { dataToSave.name = table; dataToSave.code = table; dataToSave.type = '表'; + dataToSave.datasourceConfig = dataSource.config; const tableObj = { ...dataToSave } tableBodys.push(tableObj) }); diff --git a/api/app/lib/controllers/metadataSearch/index.js b/api/app/lib/controllers/metadataSearch/index.js index 79c9f0e..9b2b205 100644 --- a/api/app/lib/controllers/metadataSearch/index.js +++ b/api/app/lib/controllers/metadataSearch/index.js @@ -1,4 +1,5 @@ 'use strict'; +const { Pool } = require('pg'); function searchMeta(opts) { return async function (ctx, next) { @@ -52,7 +53,7 @@ function searchMeta(opts) { const rslt2 = await models.MetadataFile.findAndCountAll(findObj2); const rslt3 = await models.MetadataRestapi.findAndCountAll(findObj3); const fileRslt = rslt2.rows.map(s => { return { ...s.dataValues, type: '文件', tagDatabases: s.tagFiles } }) - const restapiRslt = rslt3.rows.map(s => { return { ...s.dataValues, type: '接口', tagDatabases: s.tagRestapis } }) + const restapiRslt = rslt3.rows.map(s => { return { ...s.dataValues, type: '接口', tagDatabases: s.tagRestapis } }) ctx.status = 200; ctx.body = { count: rslt1.count + rslt2.count + rslt3.count, @@ -66,6 +67,38 @@ function searchMeta(opts) { } } +// 新增模型 +function getTableData(opts) { + return async function (ctx, next) { + + const models = ctx.fs.dc.models; + try { + const { id } = ctx.query; + let { user, host, database, password, port } = ctx.request.body; + const pool = new Pool({ + user: user, + host: host, + database: database, + password: password, + port: port, + }) + const client = await pool.connect() + + const tableName = "user" + const ress = await client.query(`SELECT * from "${tableName}"`, []) + console.log(ress.rows) + + ctx.status = 200; + ctx.body = { rslt: ress.rows } + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 200; + ctx.body = { message: '连接失败' } + } + } +} + module.exports = { - searchMeta + searchMeta, + getTableData } \ No newline at end of file diff --git a/api/app/lib/models/data_source.js b/api/app/lib/models/data_source.js index 37eabf7..b64a441 100644 --- a/api/app/lib/models/data_source.js +++ b/api/app/lib/models/data_source.js @@ -98,7 +98,7 @@ module.exports = dc => { }, type: { type: DataTypes.STRING, - allowNull: false, + allowNull: true, defaultValue: null, comment: "元数据类型", primaryKey: false, diff --git a/api/app/lib/models/metadata_database.js b/api/app/lib/models/metadata_database.js index 2d7ddf3..17b4b0c 100644 --- a/api/app/lib/models/metadata_database.js +++ b/api/app/lib/models/metadata_database.js @@ -122,6 +122,15 @@ module.exports = dc => { primaryKey: false, field: "catalogKey", autoIncrement: false + }, + datasourceConfig: { + type: DataTypes.JSONB, + allowNull: true, + defaultValue: null, + comment: null, + primaryKey: false, + field: "datasource_config", + autoIncrement: false } }, { tableName: "t_metadata_database", diff --git a/api/app/lib/routes/metadataSearch/index.js b/api/app/lib/routes/metadataSearch/index.js index 53d0f65..5f09f35 100644 --- a/api/app/lib/routes/metadataSearch/index.js +++ b/api/app/lib/routes/metadataSearch/index.js @@ -3,7 +3,10 @@ const search = require('../../controllers/metadataSearch/index'); module.exports = function (app, router, opts, AuthCode) { - //获取适配器列表 - app.fs.api.logAttr['GET/meta/data/search'] = { content: '获取适配器列表', visible: true }; + //元数据资源检索 + app.fs.api.logAttr['GET/meta/data/search'] = { content: '元数据资源检索', visible: true }; router.get('/meta/data/search', search.searchMeta(opts)); + + app.fs.api.logAttr['GET/meta/table/data'] = { content: '查询元数据表数据', visible: true }; + router.get('/meta/table/data', search.getTableData(opts)) };