wenlele 1 year ago
parent
commit
deadb48359
  1. 49
      api/app/lib/controllers/dataService/index.js
  2. 3
      api/app/lib/routes/dataService/index.js
  3. 14
      web/client/src/sections/homePage/components/hotspotData.js

49
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
}

3
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));
};

14
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 <Box title={"热点数据"} bodyPaddingTop={25} >
{top3?.length > 0 ?
<div className='hotspot_data_container'>
<div className='_img'></div>
<div className='_top1'>
<span className='hotspot_title' title={top3[0].name}>{top3[0].name?.length > 8 ? top3[0].name.substring(0, 8) + '...' : top3[0].name}</span>
<span className='hotspot_title' title={top3[0].name}>{top3[0].name?.length > 6 ? top3[0].name.substring(0, 6) + '...' : top3[0].name}</span>
<div className='hotspot_data_number'>{top3[0].count}</div>
</div>
<div className='_top2'>
{top3?.length > 2 && <>
<span className='hotspot_title' title={top3[2].name}>{top3[2].name?.length > 8 ? top3[2].name.substring(0, 8) + '...' : top3[2].name}</span>
<span className='hotspot_title' title={top3[2].name}>{top3[2].name?.length > 6 ? top3[2].name.substring(0, 6) + '...' : top3[2].name}</span>
<div className='hotspot_data_number'>{top3[2].count}</div>
</>}
</div>
<div className='_top3'>
{top3?.length > 1 && <>
<span className='hotspot_title' title={top3[1].name}>{top3[1].name?.length > 8 ? top3[1].name.substring(0, 8) + '...' : top3[1].name}</span>
<span className='hotspot_title' title={top3[1].name}>{top3[1].name?.length > 6 ? top3[1].name.substring(0, 6) + '...' : top3[1].name}</span>
<div className='hotspot_data_number'>{top3[1].count}</div>
</>}
</div>

Loading…
Cancel
Save