parent
2c6d0fe295
commit
465b67df50
@ -0,0 +1,18 @@
|
||||
import request from '@/utils/request'
|
||||
|
||||
|
||||
//查询API历史记录统计
|
||||
export function getStatisticsHistoryApi() {
|
||||
return request({
|
||||
url: '/statistics/apistatistics/history',
|
||||
method: 'get',
|
||||
})
|
||||
}
|
||||
|
||||
//查询API当天记录统计
|
||||
export function getStatisticsTodayApi() {
|
||||
return request({
|
||||
url: '/statistics/apistatistics/today',
|
||||
method: 'get',
|
||||
})
|
||||
}
|
@ -0,0 +1,130 @@
|
||||
<template>
|
||||
<div>
|
||||
|
||||
<div ref="historyChart" style="height: 400px;width: 100%;margin-top: 25px">
|
||||
|
||||
</div>
|
||||
<div ref="todayChart" style="height: 400px;width: 100%">
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
||||
import {getStatisticsHistoryApi, getStatisticsTodayApi} from "@/api/business/statistics/apistatistics";
|
||||
|
||||
// 引入 ECharts 主模块
|
||||
var echarts = require('echarts/lib/echarts');
|
||||
// 引入柱状图
|
||||
require('echarts/lib/chart/bar');
|
||||
// 引入提示框和标题组件
|
||||
require('echarts/lib/component/tooltip');
|
||||
require('echarts/lib/component/title');
|
||||
|
||||
export default {
|
||||
name: "ApiStatistics",
|
||||
|
||||
|
||||
data() {
|
||||
return {
|
||||
historyApiData: {},
|
||||
todayApiData: {},
|
||||
}
|
||||
},
|
||||
|
||||
created() {
|
||||
this.getStatisticsHistoryApi()
|
||||
this.getStatisticsTodayApi()
|
||||
},
|
||||
|
||||
mounted() {
|
||||
},
|
||||
|
||||
methods: {
|
||||
initHistory() {
|
||||
let historyChart = echarts.init(this.$refs.historyChart)
|
||||
// 绘制图表
|
||||
historyChart.setOption({
|
||||
title: {
|
||||
text: '总计API调用次数',
|
||||
textStyle:{
|
||||
color: '#541264',
|
||||
fontWeight:'1000',
|
||||
align:'center',
|
||||
},
|
||||
left:"center",
|
||||
},
|
||||
tooltip: {},
|
||||
xAxis: {
|
||||
data: this.historyApiData.apiNames
|
||||
},
|
||||
yAxis: {
|
||||
splitNumber: 10,
|
||||
max:2000,
|
||||
},
|
||||
series: [{
|
||||
name: '次数',
|
||||
type: 'bar',
|
||||
data: this.historyApiData.count
|
||||
}]
|
||||
});
|
||||
},
|
||||
|
||||
initToday() {
|
||||
let todayChart = echarts.init(this.$refs.todayChart)
|
||||
// 绘制图表
|
||||
todayChart.setOption({
|
||||
title: {
|
||||
text: '今日API调用次数',
|
||||
textStyle:{
|
||||
color: '#541264',
|
||||
fontWeight:'1000',
|
||||
align:'center',
|
||||
},
|
||||
left:"center",
|
||||
},
|
||||
tooltip: {},
|
||||
xAxis: {
|
||||
data: this.todayApiData.apiNames
|
||||
},
|
||||
yAxis: {
|
||||
splitNumber: 10,
|
||||
max:80,
|
||||
},
|
||||
series: [{
|
||||
name: '次数',
|
||||
type: 'bar',
|
||||
data: this.todayApiData.count
|
||||
}]
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
//查询API历史记录统计
|
||||
getStatisticsHistoryApi() {
|
||||
getStatisticsHistoryApi().then(res => {
|
||||
this.historyApiData = res.data
|
||||
this.initHistory()
|
||||
})
|
||||
},
|
||||
|
||||
//查询API当天记录统计
|
||||
getStatisticsTodayApi() {
|
||||
getStatisticsTodayApi().then(res => {
|
||||
this.todayApiData = res.data
|
||||
this.initToday()
|
||||
})
|
||||
},
|
||||
|
||||
},
|
||||
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
@ -0,0 +1,45 @@
|
||||
package com.xjs.controller;
|
||||
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.common.security.annotation.RequiresPermissions;
|
||||
import com.xjs.service.ApiStatisticsService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* api记录统计控制器
|
||||
* @author xiejs
|
||||
* @since 2022-01-25
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("apistatistics")
|
||||
@Api(tags = "业务模块-API记录统计")
|
||||
public class ApiStatisticsController {
|
||||
|
||||
@Autowired
|
||||
private ApiStatisticsService apiStatisticsService;
|
||||
|
||||
@GetMapping("history")
|
||||
@ApiOperation("查询API历史记录统计")
|
||||
@RequiresPermissions("statistics:apistatistics:list")
|
||||
public R<Map<String, List>> statisticsHistoryApi() {
|
||||
Map<String, List> map = apiStatisticsService.statisticsHistoryApi();
|
||||
return R.ok(map);
|
||||
}
|
||||
|
||||
@GetMapping("today")
|
||||
@ApiOperation("查询API当天记录统计")
|
||||
@RequiresPermissions("statistics:apistatistics:list")
|
||||
public R<Map<String, List>> statisticsTodayApi() {
|
||||
Map<String, List> map = apiStatisticsService.statisticsTodayApi();
|
||||
return R.ok(map);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package com.xjs.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* api统计服务接口
|
||||
* @author xiejs
|
||||
* @since 2022-01-25
|
||||
*/
|
||||
public interface ApiStatisticsService {
|
||||
|
||||
|
||||
/**
|
||||
* 统计历史api次数
|
||||
* @return map
|
||||
*/
|
||||
Map<String, List> statisticsHistoryApi();
|
||||
|
||||
|
||||
/**
|
||||
* 统计当天api次数
|
||||
* @return map
|
||||
*/
|
||||
Map<String, List> statisticsTodayApi();
|
||||
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package com.xjs.service.impl;
|
||||
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.xjs.business.warning.RemoteWarningCRUDFeign;
|
||||
import com.xjs.business.warning.domain.ApiRecord;
|
||||
import com.xjs.service.ApiStatisticsService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* api统计服务接口实现
|
||||
* @author xiejs
|
||||
* @since 2022-01-25
|
||||
*/
|
||||
@Service
|
||||
public class ApiStatisticsServiceImpl implements ApiStatisticsService {
|
||||
|
||||
@Autowired
|
||||
private RemoteWarningCRUDFeign remoteWarningCRUDFeign;
|
||||
|
||||
@Override
|
||||
public Map<String, List> statisticsHistoryApi() {
|
||||
List<ApiRecord> recordList = getData();
|
||||
Map<String, List> map = new HashMap<>();
|
||||
List<String> apiNames = new ArrayList<>();
|
||||
List<Long> count = new ArrayList<>();
|
||||
recordList.forEach(record ->{
|
||||
apiNames.add(record.getApiName());
|
||||
count.add(record.getTotalCount());
|
||||
});
|
||||
map.put("apiNames", apiNames);
|
||||
map.put("count", count);
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, List> statisticsTodayApi() {
|
||||
List<ApiRecord> recordList = getData();
|
||||
Map<String, List> map = new HashMap<>();
|
||||
List<String> apiNames = new ArrayList<>();
|
||||
List<Long> count = new ArrayList<>();
|
||||
recordList.forEach(record ->{
|
||||
apiNames.add(record.getApiName());
|
||||
count.add(record.getDayCount());
|
||||
});
|
||||
map.put("apiNames", apiNames);
|
||||
map.put("count", count);
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取R中的data
|
||||
* @return List
|
||||
*/
|
||||
private List<ApiRecord> getData() {
|
||||
R<List<ApiRecord>> listR = remoteWarningCRUDFeign.selectApiRecordListForRPC();
|
||||
return listR.getData();
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package com.xjs.controller;
|
||||
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.xjs.domain.ApiRecord;
|
||||
import com.xjs.service.ApiWarningService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* api记录统计控制器
|
||||
* @author xiejs
|
||||
* @since 2022-01-25
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("apistatistics")
|
||||
@Api(tags = "业务模块-API记录统计")
|
||||
public class ApiStatisticsController {
|
||||
|
||||
@Autowired
|
||||
private ApiWarningService apiWarningService;
|
||||
|
||||
@GetMapping
|
||||
@ApiOperation("远程查询API记录统计")
|
||||
public R<List<ApiRecord>> selectApiRecordListForRPC() {
|
||||
List<ApiRecord> apiRecords = apiWarningService.selectApiRecordList(new ApiRecord());
|
||||
return R.ok(apiRecords);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue