Browse Source

(+)获取数据总量和top5

master
peng.peng 2 years ago
parent
commit
33a9470df5
  1. 30
      api/app/lib/controllers/homepage/index.js
  2. 8
      api/app/lib/index.js
  3. 70
      api/app/lib/models/dbStatistics.js
  4. 3
      api/app/lib/routes/homepage/index.js
  5. 2
      api/sequelize-automate.config.js

30
api/app/lib/controllers/homepage/index.js

@ -60,8 +60,38 @@ async function getCPUUsage() {
}); });
} }
//查询后端同步数据库数据量总量和top5
function getDataTotalTop5(opts) {
return async function (ctx, next) {
const models = ctx.fs.dc.models;
try {
let total = await models.DbStatistics.sum('dbRecordCount')
let top5 = await models.DbStatistics.findAll({
order: [["dbRecordCount", "desc"]],
limit: 5,
offset: 0,
include: [{
model: models.DataSource,
include: [
{
model: models.ResourceCatalog,
attributes: ['id', 'name'],
}]
}],
})
ctx.status = 200;
ctx.body = { total, top5 };
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = { message: '查询后端同步数据库数据量总量和top5' }
}
}
}
module.exports = { module.exports = {
getNodeResources, getNodeResources,
getDataTotalTop5
} }

8
api/app/lib/index.js

@ -56,7 +56,7 @@ module.exports.models = function (dc) {
const { const {
DataSource, AcquisitionTask, Adapter, User, MetadataDatabase, MetadataFile, MetadataRestapi, AcquisitionLog, ResourceCatalog, DataSource, AcquisitionTask, Adapter, User, MetadataDatabase, MetadataFile, MetadataRestapi, AcquisitionLog, ResourceCatalog,
BusinessMetadataDatabase, BusinessMetadataFile, BusinessMetadataRestapi,ResourceConsumption,BusinessRule,StandardDoc BusinessMetadataDatabase, BusinessMetadataFile, BusinessMetadataRestapi, ResourceConsumption, BusinessRule, StandardDoc, DbStatistics
} = dc.models; } = dc.models;
AcquisitionTask.belongsTo(DataSource, { foreignKey: 'dataSourceId', targetKey: 'id' }); AcquisitionTask.belongsTo(DataSource, { foreignKey: 'dataSourceId', targetKey: 'id' });
@ -86,10 +86,12 @@ module.exports.models = function (dc) {
BusinessMetadataFile.belongsTo(User, { foreignKey: 'createBy', targetKey: 'id' }); BusinessMetadataFile.belongsTo(User, { foreignKey: 'createBy', targetKey: 'id' });
BusinessMetadataRestapi.belongsTo(User, { foreignKey: 'createBy', targetKey: 'id' }); BusinessMetadataRestapi.belongsTo(User, { foreignKey: 'createBy', targetKey: 'id' });
ResourceConsumption.belongsTo(User, { foreignKey: 'applyBy', targetKey: 'id' ,as:"applyUser"}); ResourceConsumption.belongsTo(User, { foreignKey: 'applyBy', targetKey: 'id', as: "applyUser" });
ResourceConsumption.belongsTo(User, { foreignKey: 'approveBy', targetKey: 'id',as:'approveUser' }); ResourceConsumption.belongsTo(User, { foreignKey: 'approveBy', targetKey: 'id', as: 'approveUser' });
BusinessRule.belongsTo(StandardDoc, { foreignKey: 'ruleBasis', targetKey: 'id' }); BusinessRule.belongsTo(StandardDoc, { foreignKey: 'ruleBasis', targetKey: 'id' });
StandardDoc.hasMany(BusinessRule, { foreignKey: 'ruleBasis', targetKey: 'id' }); StandardDoc.hasMany(BusinessRule, { foreignKey: 'ruleBasis', targetKey: 'id' });
DbStatistics.belongsTo(DataSource, { foreignKey: 'sourceId', targetKey: 'id' });
DataSource.hasMany(DbStatistics, { foreignKey: 'sourceId', sourceKey: 'id' });
}; };

70
api/app/lib/models/dbStatistics.js

@ -0,0 +1,70 @@
/* eslint-disable*/
'use strict';
module.exports = dc => {
const DataTypes = dc.ORM;
const sequelize = dc.orm;
const DbStatistics = sequelize.define("dbStatistics", {
id: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: "nextval(\"dbStatistics_id_seq\"::regclass)",
comment: null,
primaryKey: true,
field: "id",
autoIncrement: false
},
dbName: {
type: DataTypes.STRING,
allowNull: false,
defaultValue: null,
comment: null,
primaryKey: false,
field: "dbName",
autoIncrement: false
},
sourceId: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: null,
comment: null,
primaryKey: false,
field: "sourceId",
autoIncrement: false
},
dbRecordCount: {
type: DataTypes.BIGINT,
allowNull: false,
defaultValue: null,
comment: null,
primaryKey: false,
field: "dbRecordCount",
autoIncrement: false
},
time: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: null,
comment: null,
primaryKey: false,
field: "time",
autoIncrement: false
},
description: {
type: DataTypes.STRING,
allowNull: true,
defaultValue: null,
comment: null,
primaryKey: false,
field: "description",
autoIncrement: false
}
}, {
tableName: "dbStatistics",
comment: "",
indexes: []
});
dc.models.DbStatistics = DbStatistics;
return DbStatistics;
};

3
api/app/lib/routes/homepage/index.js

@ -7,4 +7,7 @@ module.exports = function (app, router, opts, AuthCode) {
app.fs.api.logAttr['GET/homepage/node/resources'] = { content: '获取节点资源信息', visible: true }; app.fs.api.logAttr['GET/homepage/node/resources'] = { content: '获取节点资源信息', visible: true };
router.get('/homepage/node/resources', backups.getNodeResources(opts)) router.get('/homepage/node/resources', backups.getNodeResources(opts))
app.fs.api.logAttr['GET/homepage/datatotal/top5'] = { content: '获取数据总量和top5', visible: true };
router.get('/homepage/datatotal/top5', backups.getDataTotalTop5(opts))
}; };

2
api/sequelize-automate.config.js

@ -26,7 +26,7 @@ module.exports = {
dir: './app/lib/models', // 指定输出 models 文件的目录 dir: './app/lib/models', // 指定输出 models 文件的目录
typesDir: 'models', // 指定输出 TypeScript 类型定义的文件目录,只有 TypeScript / Midway 等会有类型定义 typesDir: 'models', // 指定输出 TypeScript 类型定义的文件目录,只有 TypeScript / Midway 等会有类型定义
emptyDir: false, // !!! 谨慎操作 生成 models 之前是否清空 `dir` 以及 `typesDir` emptyDir: false, // !!! 谨慎操作 生成 models 之前是否清空 `dir` 以及 `typesDir`
// tables: ['safety_cultivate'], // 指定生成哪些表的 models,如 ['user', 'user_post'];如果为 null,则忽略改属性 tables: ['dbStatistics'], // 指定生成哪些表的 models,如 ['user', 'user_post'];如果为 null,则忽略改属性
skipTables: [], // 指定跳过哪些表的 models,如 ['user'];如果为 null,则忽略改属性 skipTables: [], // 指定跳过哪些表的 models,如 ['user'];如果为 null,则忽略改属性
tsNoCheck: false, // 是否添加 `@ts-nocheck` 注释到 models 文件中 tsNoCheck: false, // 是否添加 `@ts-nocheck` 注释到 models 文件中
ignorePrefix: ['t_',], // 生成的模型名称忽略的前缀,因为 项目中有以下表名是以 t_ 开头的,在实际模型中不需要, 可以添加多个 [ 't_data_', 't_',] ,长度较长的 前缀放前面 ignorePrefix: ['t_',], // 生成的模型名称忽略的前缀,因为 项目中有以下表名是以 t_ 开头的,在实际模型中不需要, 可以添加多个 [ 't_data_', 't_',] ,长度较长的 前缀放前面

Loading…
Cancel
Save