peng.peng 2 years ago
parent
commit
6fe5aa8dc7
  1. 118
      api/app/lib/controllers/latestMetadata/index.js
  2. 7
      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
}

7
api/app/lib/index.js

@ -55,7 +55,7 @@ module.exports.models = function (dc) {
});
const {
DataSource, AcquisitionTask, Adapter
DataSource, AcquisitionTask, Adapter, User, MetadataDatabase, MetadataFile, MetadataRestapi
} = dc.models;
AcquisitionTask.belongsTo(DataSource, { foreignKey: 'dataSourceId', targetKey: 'id' });
@ -64,6 +64,11 @@ module.exports.models = function (dc) {
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' });
};

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