Browse Source

(*)restful 服务接口提交

master
peng.peng 1 year ago
parent
commit
23f6f2df7f
  1. 2
      api/app/lib/controllers/backups/index.js
  2. 22
      api/app/lib/controllers/homepage/index.js
  3. 94
      api/app/lib/models/restful_api_record.js
  4. 5
      api/app/lib/routes/homepage/index.js
  5. 2
      api/sequelize-automate.config.js

2
api/app/lib/controllers/backups/index.js

@ -6,7 +6,7 @@ function getBackupsList(opts) {
const models = ctx.fs.dc.models;
const { page, limit, name } = ctx.query;
const Op = ctx.fs.dc.ORM.Op;
let errMsg = { message: '获取数据备份失败' }
try {
let searchWhere = {

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

@ -160,24 +160,24 @@ function getRestfulInfo(opts) {
return async function (ctx, next) {
const models = ctx.fs.dc.models;
try {
let todayTotal = await models.RestfulApiRecord.Count({
const Op = ctx.fs.dc.ORM.Op;
let allApis = await models.RestfulApiRecord.findAndCount({
order: [["id", "desc"]],
where: {
visitTime: { [Op.between]: [moment().startOf('day'), moment().endOf('day')] }
}
})
let total = await models.RestfulApiRecord.Count({
where: {
id: { [$.gt]: 0 }
}
id: { [Op.gt]: 0 }
},
include: [
{
model: models.RestfulApi,
}]
})
ctx.status = 200;
ctx.body = { total, todayTotal };
ctx.body = { allApis };
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = { message: '查询后端同步数据库数据量总量和top5' }
ctx.body = { message: '获取restful统计信息失败' }
}
}
}

94
api/app/lib/models/restful_api_record.js

@ -3,51 +3,51 @@
'use strict';
module.exports = dc => {
const DataTypes = dc.ORM;
const sequelize = dc.orm;
const RestfulApiRecord = sequelize.define("restfulApiRecord", {
id: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: null,
comment: "唯一标识",
primaryKey: true,
field: "id",
autoIncrement: true,
unique: "t_restful_api_record_id_uindex"
},
name: {
type: DataTypes.STRING,
allowNull: false,
defaultValue: null,
comment: "接口名称",
primaryKey: false,
field: "name",
autoIncrement: false
},
visitTime: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: null,
comment: "访问时间",
primaryKey: false,
field: "visit_time",
autoIncrement: false
},
token: {
type: DataTypes.STRING,
allowNull: false,
defaultValue: null,
comment: "令牌",
primaryKey: false,
field: "token",
autoIncrement: false
},
}, {
tableName: "t_restful_api_record",
comment: "",
indexes: []
});
dc.models.RestfulApiRecord = RestfulApiRecord;
return RestfulApiRecord;
const DataTypes = dc.ORM;
const sequelize = dc.orm;
const RestfulApiRecord = sequelize.define("restfulApiRecord", {
id: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: null,
comment: null,
primaryKey: true,
field: "id",
autoIncrement: true,
unique: "t_resful_api_record_id_uindex"
},
restServiceId: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: null,
comment: "rest服务id",
primaryKey: false,
field: "rest_service_id",
autoIncrement: false
},
visitTime: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: null,
comment: "访问时间",
primaryKey: false,
field: "visit_time",
autoIncrement: false
},
token: {
type: DataTypes.STRING,
allowNull: false,
defaultValue: null,
comment: "令牌",
primaryKey: false,
field: "token",
autoIncrement: false
}
}, {
tableName: "t_restful_api_record",
comment: "",
indexes: []
});
dc.models.RestfulApiRecord = RestfulApiRecord;
return RestfulApiRecord;
};

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

@ -10,8 +10,9 @@ module.exports = function (app, router, opts, AuthCode) {
app.fs.api.logAttr['GET/homepage/datatotal/top5'] = { content: '获取数据总量和top5', visible: true };
router.get('/homepage/datatotal/top5', backups.getDataTotalTop5(opts))
app.fs.api.logAttr['GET/homepage/cluters'] = { content: '获取集群资源节点信息', visible: true };
app.fs.api.logAttr['GET/homepage/datatotal/cluters'] = { content: '获取集群资源节点信息', visible: true };
router.get('/homepage/datatotal/cluters', backups.getClusterInfo(opts))
app.fs.api.logAttr['GET/homepage/restful/info'] = { content: '获取restful统计信息', visible: true };
router.get('/homepage/restful/info', backups.getRestfulInfo(opts))
};

2
api/sequelize-automate.config.js

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

Loading…
Cancel
Save