修改鉴权接口
This commit is contained in:
parent
787f48fbdf
commit
9c3877e937
296
html/monitor.html
Normal file
296
html/monitor.html
Normal file
@ -0,0 +1,296 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.14/theme-chalk/index.min.css">
|
||||
<title>Interface Monitor</title>
|
||||
<script src="https://cdn.staticfile.org/vue/2.7.14/vue.min.js"></script>
|
||||
<script src="https://cdn.staticfile.org/blueimp-md5/2.19.0/js/md5.min.js"></script>
|
||||
<script src="https://cdn.staticfile.org/axios/1.6.5/axios.js"></script>
|
||||
<script src="https://cdn.staticfile.org/element-ui/2.15.14/index.js"></script>
|
||||
<script src="https://cdn.staticfile.net/dayjs/1.11.10/dayjs.min.js"></script>
|
||||
<script src="https://cdn.staticfile.net/echarts/5.4.3/echarts.min.js"></script>
|
||||
|
||||
<style>
|
||||
body {
|
||||
font-family: 'Arial', sans-serif;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.el-form-item {
|
||||
display: flex;
|
||||
height: 50px;
|
||||
width: 100%;
|
||||
align-items: center;
|
||||
justify-content: flex-start;
|
||||
}
|
||||
|
||||
.el-form-item__content {
|
||||
margin-left: 20px !important;
|
||||
}
|
||||
|
||||
.resu {
|
||||
margin-left: 30%;
|
||||
width: 70%;
|
||||
min-height: 1080px;
|
||||
}
|
||||
|
||||
.line {
|
||||
width: 1000px;
|
||||
height: 300px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="app">
|
||||
<div style="width:30%;position: fixed;padding: 20px 0 0 50px;">
|
||||
<el-form label-width="80px">
|
||||
<el-form-item label="Host:">
|
||||
<div style="width: 108%;">
|
||||
<el-select v-model="query.host" placeholder="请选择">
|
||||
<el-option v-for="item in data.host" :key="item" :label="item" :value="item"></el-option>
|
||||
</el-select>
|
||||
</div>
|
||||
</el-form-item>
|
||||
<el-form-item label="开始时间:">
|
||||
<el-date-picker v-model="query.startTime" type="datetime" placeholder="选择开始时间">
|
||||
</el-date-picker>
|
||||
</el-form-item>
|
||||
<el-form-item label="结束时间:">
|
||||
<el-date-picker v-model="query.endTime" type="datetime" placeholder="选择结束时间">
|
||||
</el-date-picker>
|
||||
</el-form-item>
|
||||
<el-form-item label="IP:">
|
||||
<el-select v-model="query.ip" placeholder="请选择">
|
||||
<el-option v-for="item in data.ip" :key="item" :label="item" :value="item">
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="接口:">
|
||||
<el-select v-model="query.name" placeholder="请选择">
|
||||
<el-option v-for="item in data.name" :key="item" :label="item" :value="item">
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="分组方式:">
|
||||
<el-radio v-for="item in data.groupBy" v-model="query.groupBy" :label="item">{{ item }}</el-radio>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<div style="margin-left: 20%; display: flex;">
|
||||
<el-button type="primary" @click="listData()">查询曲线</el-button>
|
||||
<el-button type="primary" @click="groupData()">查询分组</el-button>
|
||||
</div>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
<div class="resu">
|
||||
<div id="total" class="line"></div>
|
||||
<div id="average" class="line"></div>
|
||||
<div id="failure" class="line"></div>
|
||||
<div id="timeout" class="line"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const HttpReq = axios.create({
|
||||
// baseURL, // api的base_url
|
||||
timeout: 10000, // 请求超时时间,
|
||||
method: "post"
|
||||
});
|
||||
|
||||
HttpReq.interceptors.request.use(config => {
|
||||
config.data = config.data || {}
|
||||
config.data.ticket = md5(`hello_syzb_${dayjs().format('YYYYMMDD')}`)
|
||||
if(config.data.ip == '全部'){
|
||||
config.data.ip = ''
|
||||
}
|
||||
if(config.data.name == '全部'){
|
||||
config.data.name = ''
|
||||
}
|
||||
return config;
|
||||
}, error => {
|
||||
return Promise.reject(error);
|
||||
});
|
||||
|
||||
HttpReq.interceptors.response.use(resp => {
|
||||
if (resp.code) {
|
||||
console.log({
|
||||
title: "HttpRequestError-" + resp.code,
|
||||
content: resp.message,
|
||||
});
|
||||
}
|
||||
return resp.data.data;
|
||||
})
|
||||
|
||||
function post(host, url, data) {
|
||||
if (!host) {
|
||||
return;
|
||||
}
|
||||
const targetUrl = (host + url)
|
||||
return HttpReq({
|
||||
url: targetUrl,
|
||||
data,
|
||||
})
|
||||
}
|
||||
|
||||
function fillTimeData(startTime, endTime, data) {
|
||||
const result = [];
|
||||
const timeMap = new Map();
|
||||
|
||||
// 建立已有数据的映射,key 是时间字符串
|
||||
data.forEach(item => {
|
||||
timeMap.set(item.time, item);
|
||||
});
|
||||
|
||||
let current = dayjs(startTime).second(0);
|
||||
console.log(current.minute());
|
||||
while (current.minute() % 5 !== 0) {
|
||||
current = current.add(1, 'minute');
|
||||
}
|
||||
const end = dayjs(endTime);
|
||||
console.log(current.isSameOrBefore);
|
||||
|
||||
while (current.isBefore(end) || current.isSame(end)) {
|
||||
const timeStr = current.format('YYYY-MM-DD HH:mm:ss');
|
||||
|
||||
if (timeMap.has(timeStr)) {
|
||||
result.push(timeMap.get(timeStr));
|
||||
} else {
|
||||
result.push({
|
||||
averageTime: 0,
|
||||
failure: 0,
|
||||
interfaceName: null,
|
||||
ip: null,
|
||||
maxTime: 0,
|
||||
minTime: 0,
|
||||
over1000ms: 0,
|
||||
over100ms: 0,
|
||||
over10ms: 0,
|
||||
over5000ms: 0,
|
||||
over500ms: 0,
|
||||
over50ms: 0,
|
||||
time: timeStr,
|
||||
total: 0
|
||||
});
|
||||
}
|
||||
|
||||
current = current.add(5, 'minute');
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function drawLine(data, div, field, filter) {
|
||||
if (data && data.length) {
|
||||
const xyData = data.map(v => [v.time, v[field]]);
|
||||
const myChart = echarts.init(document.getElementById(div));
|
||||
myChart.setOption({
|
||||
title: {
|
||||
text: field
|
||||
},
|
||||
xAxis: {
|
||||
type: 'time',
|
||||
// data: xDate
|
||||
},
|
||||
yAxis: {
|
||||
type: 'value'
|
||||
},
|
||||
tooltip: {
|
||||
trigger: 'axis'
|
||||
},
|
||||
series: [
|
||||
{
|
||||
type: 'line',
|
||||
data: xyData,
|
||||
showSymbol: false,
|
||||
}
|
||||
]
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const API = {
|
||||
listIP: function (host, data) {
|
||||
return post(host, '/admin/monitor/listIP', data);
|
||||
},
|
||||
listInterface: function (host, data) {
|
||||
return post(host, '/admin/monitor/listInterface', data);
|
||||
},
|
||||
listData: function (host, data) {
|
||||
return post(host, '/admin/monitor/listData', data);
|
||||
},
|
||||
groupData: function (host, data) {
|
||||
return post(host, '/admin/monitor/groupData', data);
|
||||
},
|
||||
}
|
||||
|
||||
new Vue({
|
||||
el: '#app',
|
||||
data() {
|
||||
return {
|
||||
query: {
|
||||
host: "http://8.138.144.54:8080",
|
||||
// startTime: dayjs().format('YYYY-MM-DD 00:00:00'),
|
||||
// endTime: dayjs().add(1, 'day').format('YYYY-MM-DD 00:00:00'),
|
||||
startTime: dayjs().subtract(1, 'day').format('YYYY-MM-DD 00:00:00'),
|
||||
endTime: dayjs().format('YYYY-MM-DD 00:00:00'),
|
||||
ip: "",
|
||||
name: "",
|
||||
groupBy: "name",
|
||||
},
|
||||
data: {
|
||||
host: ["http://8.138.144.54:8080"],
|
||||
ip: [],
|
||||
name: [],
|
||||
groupBy: ["name", "ip"],
|
||||
},
|
||||
monitor: [],
|
||||
interval: null,
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
async init() {
|
||||
const ip = await API.listIP(this.query.host, this.query)
|
||||
if(ip){
|
||||
ip.unshift("全部")
|
||||
this.data.ip = ip;
|
||||
this.query.ip = ip[0];
|
||||
}
|
||||
const name = await API.listInterface(this.query.host, this.query)
|
||||
if(name){
|
||||
name.unshift("全部")
|
||||
this.data.name = name;
|
||||
this.query.name = name[0];
|
||||
}
|
||||
},
|
||||
async listData() {
|
||||
let data = await API.listData(this.query.host, this.query);
|
||||
// console.log('before', data);
|
||||
data = fillTimeData(this.query.startTime, this.query.endTime, data);
|
||||
// console.log('after', data);
|
||||
drawLine(data, 'total', 'total');
|
||||
drawLine(data, 'average', 'averageTime');
|
||||
drawLine(data, 'failure', 'failure');
|
||||
drawLine(data, 'timeout', 'over5000ms');
|
||||
},
|
||||
},
|
||||
async mounted() {
|
||||
this.init();
|
||||
},
|
||||
watch: {
|
||||
'query.host': async function (newVal) {
|
||||
if (this.interval) {
|
||||
clearTimeout(this.interval)
|
||||
}
|
||||
this.interval = setTimeout(async () => {
|
||||
this.init();
|
||||
}, 100);
|
||||
},
|
||||
},
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@ -1,16 +1,21 @@
|
||||
package com.syzb.app.controller;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.syzb.common.handler.BizException;
|
||||
import com.syzb.common.query.AppUserInfoQuery;
|
||||
import com.syzb.common.query.OnlyIdQuery;
|
||||
import com.syzb.common.query.CheckAuthQuery;
|
||||
import com.syzb.common.result.CommonResult;
|
||||
import com.syzb.common.result.ResponseStatus;
|
||||
import com.syzb.common.service.AppUserService;
|
||||
import com.syzb.common.util.JwtUtil;
|
||||
import com.syzb.common.util.logger.LoggerUtil;
|
||||
import com.syzb.common.vo.AppCUserInfoVO;
|
||||
import com.syzb.common.vo.AuthResultVO;
|
||||
import com.syzb.common.vo.FrontUserVO;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@ -21,6 +26,12 @@ import javax.annotation.Resource;
|
||||
@RequestMapping("/app/user/")
|
||||
public class AppUserController {
|
||||
|
||||
@Value("${jwt.key}")
|
||||
private String jwtKey;
|
||||
|
||||
@Value("${jwt.secret}")
|
||||
private String jwtSecret;
|
||||
|
||||
@Resource
|
||||
private AppUserService appUserService;
|
||||
|
||||
@ -35,12 +46,25 @@ public class AppUserController {
|
||||
@ApiOperation("C端用户鉴权")
|
||||
@PostMapping("checkAuth")
|
||||
@CrossOrigin(origins = "*", allowedHeaders = "*", maxAge = 3600)
|
||||
public CommonResult<AuthResultVO> checkAuth(@Validated @RequestBody OnlyIdQuery query,
|
||||
@RequestAttribute(value = "frontUser", required = false) FrontUserVO frontUserVO) {
|
||||
public CommonResult<AuthResultVO> checkAuth(@Validated @RequestBody CheckAuthQuery query) {
|
||||
String token = query.getToken();
|
||||
if (StrUtil.isBlank(token) || "undefined".equals(token)) {
|
||||
throw new BizException(ResponseStatus.SESSION_EXPIRY);
|
||||
}
|
||||
FrontUserVO frontUserVO = null;
|
||||
try {
|
||||
String decodeStr = JwtUtil.verify(jwtSecret, jwtKey, token);
|
||||
if (StrUtil.isNotBlank(decodeStr)) {
|
||||
frontUserVO = JSONObject.parseObject(decodeStr, FrontUserVO.class);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LoggerUtil.error(e);
|
||||
throw new BizException(ResponseStatus.SESSION_EXPIRY);
|
||||
}
|
||||
if (frontUserVO == null) {
|
||||
throw new BizException(ResponseStatus.SESSION_EXPIRY);
|
||||
}
|
||||
AuthResultVO vo = appUserService.checkAuth(query.getId().toString(), frontUserVO);
|
||||
AuthResultVO vo = appUserService.checkAuth(query.getAuth(), frontUserVO);
|
||||
return CommonResult.success(vo);
|
||||
}
|
||||
|
||||
|
||||
@ -169,6 +169,9 @@ public class TencentCloudConfig {
|
||||
// 实例化一个http选项,可选的,没有特殊需求可以跳过
|
||||
HttpProfile httpProfile = new HttpProfile();
|
||||
httpProfile.setEndpoint(this.vodEndpoint);
|
||||
httpProfile.setConnTimeout(60);
|
||||
httpProfile.setReadTimeout(60);
|
||||
httpProfile.setWriteTimeout(60);
|
||||
|
||||
// 实例化一个client选项,可选的,没有特殊需求可以跳过
|
||||
ClientProfile clientProfile = new ClientProfile();
|
||||
@ -186,6 +189,9 @@ public class TencentCloudConfig {
|
||||
// 实例化一个http选项,可选的,没有特殊需求可以跳过
|
||||
HttpProfile httpProfile = new HttpProfile();
|
||||
httpProfile.setEndpoint(this.liveEndpoint);
|
||||
httpProfile.setConnTimeout(60);
|
||||
httpProfile.setReadTimeout(60);
|
||||
httpProfile.setWriteTimeout(60);
|
||||
// 实例化一个client选项,可选的,没有特殊需求可以跳过
|
||||
ClientProfile clientProfile = new ClientProfile();
|
||||
clientProfile.setHttpProfile(httpProfile);
|
||||
|
||||
@ -67,6 +67,10 @@ public class CacheConfig {
|
||||
configMap.put(COURSE, new LocalMapConfig(10000, 300));
|
||||
configMap.put(GROUP, new LocalMapConfig(10000, 300));
|
||||
configMap.put(WX_USER, new LocalMapConfig(10000, 3600));
|
||||
|
||||
configMap.put(VIDEO_ONLINE_USER, new LocalMapConfig(1000000, 604800, InMemoryFormat.OBJECT));
|
||||
configMap.put(GROUP_ONLINE_USER, new LocalMapConfig(1000000, 604800, InMemoryFormat.OBJECT));
|
||||
|
||||
return configMap;
|
||||
}
|
||||
}
|
||||
|
||||
24
src/main/java/com/syzb/common/query/CheckAuthQuery.java
Normal file
24
src/main/java/com/syzb/common/query/CheckAuthQuery.java
Normal file
@ -0,0 +1,24 @@
|
||||
package com.syzb.common.query;
|
||||
|
||||
public class CheckAuthQuery {
|
||||
|
||||
private String auth;
|
||||
|
||||
private String token;
|
||||
|
||||
public String getAuth() {
|
||||
return auth;
|
||||
}
|
||||
|
||||
public void setAuth(String auth) {
|
||||
this.auth = auth;
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
return token;
|
||||
}
|
||||
|
||||
public void setToken(String token) {
|
||||
this.token = token;
|
||||
}
|
||||
}
|
||||
@ -17,34 +17,31 @@ import java.util.List;
|
||||
|
||||
@Api(tags = "monitor")
|
||||
@RestController
|
||||
@CrossOrigin(origins = "*", allowedHeaders = "*", maxAge = 3600)
|
||||
public class MonitorController {
|
||||
|
||||
@Resource
|
||||
private MonitorService monitorService;
|
||||
|
||||
@PostMapping("/admin/monitor/listIP")
|
||||
@CrossOrigin(origins = "*", allowedHeaders = "*", maxAge = 3600)
|
||||
public CommonResult<List<String>> listIP(@Validated @RequestBody @ApiParam(required = true) MonitorQuery query) {
|
||||
List<String> list = monitorService.listIP(query);
|
||||
return CommonResult.success(list);
|
||||
}
|
||||
|
||||
@PostMapping("/admin/monitor/listInterface")
|
||||
@CrossOrigin(origins = "*", allowedHeaders = "*", maxAge = 3600)
|
||||
public CommonResult<List<String>> listInterface(@Validated @RequestBody @ApiParam(required = true) MonitorQuery query) {
|
||||
List<String> list = monitorService.listInterface(query);
|
||||
return CommonResult.success(list);
|
||||
}
|
||||
|
||||
@PostMapping("/admin/monitor/listData")
|
||||
@CrossOrigin(origins = "*", allowedHeaders = "*", maxAge = 3600)
|
||||
public CommonResult<List<InterfaceMonitor>> listData(@Validated @RequestBody @ApiParam(required = true) MonitorQuery query) {
|
||||
List<InterfaceMonitor> list = monitorService.listData(query);
|
||||
return CommonResult.success(list);
|
||||
}
|
||||
|
||||
@PostMapping("/admin/monitor/groupData")
|
||||
@CrossOrigin(origins = "*", allowedHeaders = "*", maxAge = 3600)
|
||||
public CommonResult<List<InterfaceMonitor>> groupData(@Validated @RequestBody @ApiParam(required = true) MonitorQuery query) {
|
||||
List<InterfaceMonitor> list = monitorService.groupData(query);
|
||||
return CommonResult.success(list);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user