45 lines
1.4 KiB
JavaScript
45 lines
1.4 KiB
JavaScript
const stats = require("../service/biz_api_stats_service");
|
|
const baseModel = require("../../middleware/baseModel");
|
|
const { find_page } = require("../service/biz_query_helpers");
|
|
|
|
module.exports = {
|
|
/** 按用户查询调用统计 */
|
|
"POST /biz_api_stats/by_user": async (ctx) => {
|
|
const body = ctx.getBody();
|
|
const { user_id, start_date, end_date } = body;
|
|
if (!user_id) {
|
|
ctx.fail("缺少 user_id");
|
|
return;
|
|
}
|
|
const data = await stats.getStatsByUser(user_id, start_date, end_date);
|
|
ctx.success(data);
|
|
},
|
|
|
|
/** 按接口路径查询调用统计 */
|
|
"POST /biz_api_stats/by_api": async (ctx) => {
|
|
const body = ctx.getBody();
|
|
const { api_path, start_date, end_date } = body;
|
|
if (!api_path) {
|
|
ctx.fail("缺少 api_path");
|
|
return;
|
|
}
|
|
const data = await stats.getStatsByApi(api_path, start_date, end_date);
|
|
ctx.success(data);
|
|
},
|
|
|
|
/** 综合统计面板 */
|
|
"POST /biz_api_stats/summary": async (ctx) => {
|
|
const body = ctx.getBody();
|
|
const { start_date, end_date, top_limit } = body;
|
|
const data = await stats.getSummary(start_date, end_date, top_limit || 10);
|
|
ctx.success(data);
|
|
},
|
|
|
|
/** 调用日志分页列表 */
|
|
"POST /biz_api_call_log/page": async (ctx) => {
|
|
const body = ctx.getBody();
|
|
const { count, rows } = await find_page(baseModel.biz_api_call_log, "biz_api_call_log", body);
|
|
ctx.success({ rows, count });
|
|
},
|
|
};
|