Browse Source

(*)元数据采集 元数据表增加数据源返回信息

master
peng.peng 2 years ago
parent
commit
fa2053a713
  1. 4
      api/app/lib/controllers/auth/index.js
  2. 3
      api/app/lib/controllers/metadataAcquisition/taskHandle.js
  3. 37
      api/app/lib/controllers/metadataSearch/index.js
  4. 2
      api/app/lib/models/data_source.js
  5. 9
      api/app/lib/models/metadata_database.js
  6. 7
      api/app/lib/routes/metadataSearch/index.js

4
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();

3
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)
});

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

2
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,

9
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",

7
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))
};

Loading…
Cancel
Save