From e952b3cbb1a4dd25cc97c14f6d42c53cd22472ce Mon Sep 17 00:00:00 2001 From: "peng.peng" Date: Wed, 30 Aug 2023 17:40:17 +0800 Subject: [PATCH] =?UTF-8?q?=EF=BC=88*=EF=BC=89=E7=83=AD=E7=82=B9=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=8A=9F=E8=83=BD=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/controllers/dataService/index.js | 49 +++++++++++++++++-- api/app/lib/routes/dataService/index.js | 3 +- .../homePage/components/hotspotData.js | 14 +++--- 3 files changed, 53 insertions(+), 13 deletions(-) diff --git a/api/app/lib/controllers/dataService/index.js b/api/app/lib/controllers/dataService/index.js index a3c01c5..f1d3215 100644 --- a/api/app/lib/controllers/dataService/index.js +++ b/api/app/lib/controllers/dataService/index.js @@ -3,7 +3,7 @@ const moment = require('moment') //获取REST服务失败 -function getServiceManagement (opts) { +function getServiceManagement(opts) { return async function (ctx, next) { const models = ctx.fs.dc.models; @@ -44,7 +44,7 @@ function getServiceManagement (opts) { } //编辑REST服务 -function postServiceManagement (opts) { +function postServiceManagement(opts) { return async function (ctx, next) { try { @@ -63,7 +63,7 @@ function postServiceManagement (opts) { } //编辑REST服务 -function delServiceManagement (opts) { +function delServiceManagement(opts) { return async function (ctx, next) { try { const models = ctx.fs.dc.models; @@ -86,7 +86,7 @@ function delServiceManagement (opts) { //获取表字段 -function getLookField (opts) { +function getLookField(opts) { return async function (ctx, next) { const models = ctx.fs.dc.models; @@ -128,10 +128,49 @@ function getLookField (opts) { } } +//获取rest服务申请次数 +function getResourceConsumptionCount(opts) { + return async function (ctx, next) { + const models = ctx.fs.dc.models; + let errMsg = { message: '获取接口资源申请次数失败' } + try { + const rslt = await models.ResourceConsumption.count({ + attributes: [ + 'rest_service_id', // 分组的字段 + ], + group: ['rest_service_id'], // 分组的字段 + where: { + resourceType: '数据服务' + } + }); + + const rests = await models.RestfulApi.findAll() + let arr = [] + rslt.map(s => { + let rest = rests.find(x => x.id == s.rest_service_id) + if (rest) { + arr.push({ + count: s.count, + name: rest.name + }) + } + }) + ctx.status = 200; + ctx.body = arr; + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = errMsg + } + } +} + + module.exports = { getServiceManagement, postServiceManagement, delServiceManagement, - getLookField + getLookField, + getResourceConsumptionCount } \ No newline at end of file diff --git a/api/app/lib/routes/dataService/index.js b/api/app/lib/routes/dataService/index.js index a63906a..8ea5bbc 100644 --- a/api/app/lib/routes/dataService/index.js +++ b/api/app/lib/routes/dataService/index.js @@ -18,7 +18,8 @@ module.exports = function (app, router, opts, AuthCode) { app.fs.api.logAttr['GET/lookField'] = { content: '获取表字段', visible: true }; router.get('/lookField', model.getLookField(opts)); - + app.fs.api.logAttr['GET/resource/count'] = { content: '获取资源申请次数', visible: true }; + router.get('/resource/count', model.getResourceConsumptionCount(opts)); }; diff --git a/web/client/src/sections/homePage/components/hotspotData.js b/web/client/src/sections/homePage/components/hotspotData.js index f8a7240..2e7203e 100644 --- a/web/client/src/sections/homePage/components/hotspotData.js +++ b/web/client/src/sections/homePage/components/hotspotData.js @@ -5,30 +5,30 @@ import './style.less'; import { ApiTable, useFsRequest } from '$utils'; function HotspotData(props) { - const { data: restfulInfo = {} } = useFsRequest({ - url: 'homepage/restful/info', + const { data: restfulInfo = [] } = useFsRequest({ + url: 'resource/count', pollingInterval: 1000 * 60, - cacheKey: 'restfulInfo', + // cacheKey: 'restfulInfo', }); - const top3 = restfulInfo?.top3 + const top3 = restfulInfo?.sort((a, b) => b.count - a.count)?.slice(0, 3) return {top3?.length > 0 ?
- {top3[0].name?.length > 8 ? top3[0].name.substring(0, 8) + '...' : top3[0].name} + {top3[0].name?.length > 6 ? top3[0].name.substring(0, 6) + '...' : top3[0].name}
{top3[0].count}
{top3?.length > 2 && <> - {top3[2].name?.length > 8 ? top3[2].name.substring(0, 8) + '...' : top3[2].name} + {top3[2].name?.length > 6 ? top3[2].name.substring(0, 6) + '...' : top3[2].name}
{top3[2].count}
}
{top3?.length > 1 && <> - {top3[1].name?.length > 8 ? top3[1].name.substring(0, 8) + '...' : top3[1].name} + {top3[1].name?.length > 6 ? top3[1].name.substring(0, 6) + '...' : top3[1].name}
{top3[1].count}
}