1、统计模块api统计实现
This commit is contained in:
parent
2c6d0fe295
commit
465b67df50
|
|
@ -25,11 +25,11 @@ import java.util.List;
|
|||
public interface RemoteWarningCRUDFeign {
|
||||
|
||||
@PostMapping("apiwarning")
|
||||
public R<ApiRecord> saveApiRecordForRPC(@RequestBody ApiRecord apiRecord);
|
||||
R<ApiRecord> saveApiRecordForRPC(@RequestBody ApiRecord apiRecord);
|
||||
|
||||
|
||||
@PutMapping("apiwarning")
|
||||
public R<ApiRecord> updateApiRecordForRPC(@RequestBody ApiRecord apiRecord);
|
||||
R<ApiRecord> updateApiRecordForRPC(@RequestBody ApiRecord apiRecord);
|
||||
|
||||
@GetMapping("apiwarning")
|
||||
R<List<ApiRecord>> selectApiRecordListForRPC(@SpringQueryMap ApiRecord apiRecord);
|
||||
|
|
@ -38,6 +38,9 @@ public interface RemoteWarningCRUDFeign {
|
|||
R<ApiWarning> saveApiWarningForRPC(@RequestBody ApiWarning apiWarning);
|
||||
|
||||
@GetMapping("apiwarning/getApiNameForRPC")
|
||||
public R<List<String>> getApiName();
|
||||
R<List<String>> getApiName();
|
||||
|
||||
@GetMapping("apistatistics")
|
||||
R<List<ApiRecord>> selectApiRecordListForRPC();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,6 +53,12 @@ public class RemoteWarningCRUDFactory implements FallbackFactory<RemoteWarningCR
|
|||
log.error("调用预警服务api预警查询所有api名称接口失败,执行降级处理----");
|
||||
return R.fail();
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<List<ApiRecord>> selectApiRecordListForRPC() {
|
||||
log.error("调用预警服务api统计查询所有api接口失败,执行降级处理----");
|
||||
return R.fail();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import com.ruoyi.file.utils.FileUploadUtils;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
|
@ -17,12 +18,13 @@ import java.util.Date;
|
|||
|
||||
/**
|
||||
* 阿里云oss文件上传实现
|
||||
*
|
||||
* @author xiejs
|
||||
* @since 2022-01-25
|
||||
*/
|
||||
@Service
|
||||
@Primary
|
||||
public class AliyunOssFileServiceImpl implements ISysFileService{
|
||||
public class AliyunOssFileServiceImpl implements ISysFileService {
|
||||
|
||||
|
||||
@Autowired
|
||||
|
|
@ -30,6 +32,7 @@ public class AliyunOssFileServiceImpl implements ISysFileService{
|
|||
|
||||
@Override
|
||||
public String uploadFile(MultipartFile file) throws Exception {
|
||||
Assert.notNull(file, "file is null");
|
||||
try {
|
||||
String endpoint = aliyunOssProperties.getEndpoint();
|
||||
String keyId = aliyunOssProperties.getKeyId();
|
||||
|
|
@ -42,13 +45,13 @@ public class AliyunOssFileServiceImpl implements ISysFileService{
|
|||
//获取文件后缀
|
||||
String extension = FileUploadUtils.getExtension(file);
|
||||
//获取文件名称
|
||||
String fileName = getDataTime()+"."+extension;
|
||||
String fileName = getDataTime() + "." + extension;
|
||||
//执行文件上传 bucket名称 文件名称 文件流
|
||||
ossClient.putObject(bucketName,fileName,is);
|
||||
ossClient.putObject(bucketName, fileName, is);
|
||||
//关闭ossClient
|
||||
ossClient.shutdown();
|
||||
//拼接文件地址
|
||||
return "https://"+bucketName+"."+endpoint+"/"+fileName;
|
||||
return "https://" + bucketName + "." + endpoint + "/" + fileName;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
|
|
@ -57,13 +60,14 @@ public class AliyunOssFileServiceImpl implements ISysFileService{
|
|||
|
||||
/**
|
||||
* 生成一个当前日期文件名
|
||||
* @return
|
||||
*
|
||||
* @return 文件名
|
||||
*/
|
||||
private String getDataTime(){
|
||||
private String getDataTime() {
|
||||
String today = DateUtil.format(new Date(), "yyyy-MM");
|
||||
String time = DateUtil.formatDateTime(new Date());
|
||||
int random = RandomUtil.randomInt(1000, 10000);
|
||||
int random = RandomUtil.randomInt(100, 10000);
|
||||
//防止同一时间生成文件名重复
|
||||
return today+"/"+time+"-"+random;
|
||||
return today + "/" + time + "-" + random;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
@ -59,8 +59,12 @@
|
|||
</el-image>
|
||||
<el-button @click="close" icon="el-icon-close" circle plain size="mini"
|
||||
style="float: right"></el-button>
|
||||
<el-button v-loading="loading2" type="primary" icon="el-icon-search" size="mini"
|
||||
<el-button v-loading="loading2"
|
||||
type="primary"
|
||||
icon="el-icon-search"
|
||||
size="mini"
|
||||
@click="getBeautyPicture()"
|
||||
v-hasPermi="['open:apitools:beautypicture']"
|
||||
slot="reference">搜索
|
||||
</el-button>
|
||||
</el-popover>
|
||||
|
|
@ -91,8 +95,12 @@
|
|||
</div>
|
||||
<el-button @click="close" icon="el-icon-close" circle plain size="mini"
|
||||
style="float: right"></el-button>
|
||||
<el-button v-loading="loading3" type="primary" icon="el-icon-search" @click="getHistoryToday()"
|
||||
<el-button v-loading="loading3"
|
||||
type="primary"
|
||||
icon="el-icon-search"
|
||||
@click="getHistoryToday()"
|
||||
size="mini"
|
||||
v-hasPermi="['open:apitools:historytoday']"
|
||||
slot="reference">搜索
|
||||
</el-button>
|
||||
|
||||
|
|
@ -132,7 +140,10 @@
|
|||
</el-card>
|
||||
<el-button @click="close" icon="el-icon-close" circle plain size="mini"
|
||||
style="float: right"></el-button>
|
||||
<el-button v-loading="loading4" type="primary" @click="getIdCardQuery('idCardForm')" slot="reference">
|
||||
<el-button v-loading="loading4" type="primary"
|
||||
@click="getIdCardQuery('idCardForm')"
|
||||
v-hasPermi="['open:apitools:idcardquery']"
|
||||
slot="reference">
|
||||
搜索
|
||||
</el-button>
|
||||
</el-popover>
|
||||
|
|
@ -170,7 +181,11 @@
|
|||
</div>
|
||||
<el-button @click="close" icon="el-icon-close" circle plain size="mini"
|
||||
style="float: right"></el-button>
|
||||
<el-button type="primary" slot="reference" @click="getMobileBelong('mobileBelongForm')">搜索</el-button>
|
||||
<el-button type="primary"
|
||||
slot="reference"
|
||||
v-hasPermi="['open:apitools:mobilebelong']"
|
||||
@click="getMobileBelong('mobileBelongForm')">搜索
|
||||
</el-button>
|
||||
</el-popover>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
|
@ -202,7 +217,10 @@
|
|||
</div>
|
||||
<el-button @click="close" icon="el-icon-close" circle plain size="mini"
|
||||
style="float: right"></el-button>
|
||||
<el-button v-loading="loading6" type="primary" slot="reference"
|
||||
<el-button v-loading="loading6"
|
||||
type="primary"
|
||||
slot="reference"
|
||||
v-hasPermi="['open:apitools:nowweather']"
|
||||
@click="getNowWeather('nowWeatherForm')">搜索
|
||||
</el-button>
|
||||
</el-popover>
|
||||
|
|
@ -256,7 +274,10 @@
|
|||
</div>
|
||||
<el-button @click="close" icon="el-icon-close" circle plain size="mini"
|
||||
style="float: right"></el-button>
|
||||
<el-button v-loading="loading7" type="primary" slot="reference"
|
||||
<el-button v-loading="loading7"
|
||||
type="primary"
|
||||
slot="reference"
|
||||
v-hasPermi="['open:apitools:forecastweather']"
|
||||
@click="getForecastWeather('forecastWeatherForm')">搜索
|
||||
</el-button>
|
||||
</el-popover>
|
||||
|
|
@ -290,7 +311,10 @@
|
|||
</div>
|
||||
<el-button @click="close" icon="el-icon-close" circle plain size="mini"
|
||||
style="float: right"></el-button>
|
||||
<el-button v-loading="loading8" type="primary" slot="reference"
|
||||
<el-button v-loading="loading8"
|
||||
type="primary"
|
||||
slot="reference"
|
||||
v-hasPermi="['open:apitools:garbagesorting']"
|
||||
@click="getGarbageSorting('garbageSortingForm')">搜索
|
||||
</el-button>
|
||||
</el-popover>
|
||||
|
|
@ -319,7 +343,10 @@
|
|||
</div>
|
||||
<el-button @click="close" icon="el-icon-close" circle plain size="mini"
|
||||
style="float: right"></el-button>
|
||||
<el-button v-loading="loading9" type="primary" slot="reference"
|
||||
<el-button v-loading="loading9"
|
||||
type="primary"
|
||||
slot="reference"
|
||||
v-hasPermi="['open:apitools:simplecomplex']"
|
||||
@click="getSimpleComplex('simpleComplexForm')">搜索
|
||||
</el-button>
|
||||
</el-popover>
|
||||
|
|
@ -361,7 +388,10 @@
|
|||
|
||||
<el-button @click="close" icon="el-icon-close" circle plain size="mini"
|
||||
style="float: right"></el-button>
|
||||
<el-button v-loading="loading10" type="primary" slot="reference"
|
||||
<el-button v-loading="loading10"
|
||||
type="primary"
|
||||
slot="reference"
|
||||
v-hasPermi="['open:apitools:chinesedict']"
|
||||
@click="getChineseDict('chineseDictForm')">搜索
|
||||
</el-button>
|
||||
</el-popover>
|
||||
|
|
@ -399,7 +429,10 @@
|
|||
</div>
|
||||
<el-button @click="close" icon="el-icon-close" circle plain size="mini"
|
||||
style="float: right"></el-button>
|
||||
<el-button v-loading="loading11" type="primary" slot="reference"
|
||||
<el-button v-loading="loading11"
|
||||
type="primary"
|
||||
slot="reference"
|
||||
v-hasPermi="['open:apitools:ipinfo']"
|
||||
@click="getIpInfo('ipInfoForm')">搜索
|
||||
</el-button>
|
||||
</el-popover>
|
||||
|
|
|
|||
|
|
@ -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