peng.peng 2 years ago
parent
commit
6fe5aa8dc7
  1. 118
      api/app/lib/controllers/latestMetadata/index.js
  2. 73
      api/app/lib/index.js
  3. 11
      api/app/lib/models/tag_database.js
  4. 11
      api/app/lib/models/tag_file.js
  5. 11
      api/app/lib/models/tag_restapi.js
  6. 9
      api/app/lib/routes/latestMetadata/index.js
  7. 4
      web/client/src/utils/webapi.js

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

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

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

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

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

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

4
web/client/src/utils/webapi.js

@ -22,6 +22,10 @@ export const ApiTable = {
postResourceCatalog: 'resource-catalog',
putResourceCatalog: 'resource-catalog/{id}',
delResourceCatalog: 'resource-catalog/{id}',
//最新元数据-元数据列表查询
getMetadataDatabases: 'metadata/databases',
getMetadataFiles: 'metadata/files',
getMetadataRestapis: 'metadata/restapis',
//元数据采集-数据源管理
pgCheckConnect: 'adapter/check/connect',

Loading…
Cancel
Save