1、预警信息新增api预警的状态
This commit is contained in:
parent
f2a6a46d29
commit
827e8c521f
|
|
@ -4,24 +4,33 @@ import java.io.Serializable;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* api记录实体类
|
||||||
|
*
|
||||||
* @author xiejs
|
* @author xiejs
|
||||||
* @desc api记录实体类
|
* @since 2021-12-31
|
||||||
* @create 2021-12-31
|
|
||||||
*/
|
*/
|
||||||
public class ApiRecord implements Serializable {
|
public class ApiRecord implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
/** 主键id */
|
/**
|
||||||
|
* 主键id
|
||||||
|
*/
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
/** api名称 */
|
/**
|
||||||
|
* api名称
|
||||||
|
*/
|
||||||
private String apiName;
|
private String apiName;
|
||||||
|
|
||||||
/** api地址 */
|
/**
|
||||||
|
* api地址
|
||||||
|
*/
|
||||||
private String apiUrl;
|
private String apiUrl;
|
||||||
|
|
||||||
/** api每天请求次数 */
|
/**
|
||||||
|
* api每天请求次数
|
||||||
|
*/
|
||||||
private Long dayCount;
|
private Long dayCount;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -29,16 +38,32 @@ public class ApiRecord implements Serializable {
|
||||||
*/
|
*/
|
||||||
private Integer requestTime;
|
private Integer requestTime;
|
||||||
|
|
||||||
/** api总请求次数 */
|
/**
|
||||||
|
* api总请求次数
|
||||||
|
*/
|
||||||
private Long totalCount;
|
private Long totalCount;
|
||||||
|
|
||||||
/** api限制请求次数每天 */
|
private Integer status;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* api限制请求次数每天
|
||||||
|
*/
|
||||||
private Long limitCount;
|
private Long limitCount;
|
||||||
|
|
||||||
private Date createTime;
|
private Date createTime;
|
||||||
|
|
||||||
private Date updateTime;
|
private Date updateTime;
|
||||||
|
|
||||||
|
public Integer getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(Integer status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,23 @@
|
||||||
:value="index"/>
|
:value="index"/>
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="状态" prop="status">
|
||||||
|
<el-select
|
||||||
|
v-model="queryParams.status"
|
||||||
|
placeholder="请输入"
|
||||||
|
clearable
|
||||||
|
size="small"
|
||||||
|
@change="handleQuery"
|
||||||
|
style="width: 150px">
|
||||||
|
<el-option
|
||||||
|
v-for="dict in dict.type.request_status"
|
||||||
|
:key="dict.value"
|
||||||
|
:label="dict.label"
|
||||||
|
:value="dict.value"/>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
<el-form-item>
|
<el-form-item>
|
||||||
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
|
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
|
||||||
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
|
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
|
||||||
|
|
@ -55,14 +72,24 @@
|
||||||
<el-table-column label="API总请求次数" align="center" prop="totalCount" :show-overflow-tooltip="true"/>
|
<el-table-column label="API总请求次数" align="center" prop="totalCount" :show-overflow-tooltip="true"/>
|
||||||
<el-table-column label="请求耗费时间" align="center" prop="requestTime" :show-overflow-tooltip="true">
|
<el-table-column label="请求耗费时间" align="center" prop="requestTime" :show-overflow-tooltip="true">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<span>{{scope.row.requestTime+"ms"}}</span>
|
<span>{{ scope.row.requestTime + "ms" }}</span>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="API每天限制请求次数" align="center" prop="limitCount" :show-overflow-tooltip="true"/>
|
<el-table-column label="每天限制次数" align="center" prop="limitCount" :show-overflow-tooltip="true"/>
|
||||||
|
|
||||||
<el-table-column label="API每天请求次数" align="center" prop="dayCount"/>
|
<el-table-column label="API每天请求次数" align="center" prop="dayCount"/>
|
||||||
<el-table-column label="调用时间" align="center" prop="updateTime" width="180"/>
|
<el-table-column label="调用时间" align="center" prop="updateTime" width="180"/>
|
||||||
<el-table-column label="创建时间" align="center" prop="createTime" width="180" :show-overflow-tooltip="true">
|
|
||||||
|
<el-table-column label="API状态" align="center" prop="status" width="100">
|
||||||
|
<template slot-scope="scope">
|
||||||
|
<el-tag :type="scope.row.status===1?'success':'danger'">
|
||||||
|
{{ scope.row.status === 1 ? '正常' : '异常' }}
|
||||||
|
</el-tag>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
|
||||||
|
|
||||||
|
<el-table-column label="创建时间" align="center" prop="createTime" width="150" :show-overflow-tooltip="true">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
|
<span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
|
||||||
</template>
|
</template>
|
||||||
|
|
@ -112,6 +139,9 @@ import {
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "Apiwarning",
|
name: "Apiwarning",
|
||||||
|
|
||||||
|
dicts: ['request_status'],
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
// 遮罩层
|
// 遮罩层
|
||||||
|
|
@ -137,6 +167,7 @@ export default {
|
||||||
pageNum: 1,
|
pageNum: 1,
|
||||||
pageSize: 10,
|
pageSize: 10,
|
||||||
apiName: null,
|
apiName: null,
|
||||||
|
status: null
|
||||||
},
|
},
|
||||||
// 表单参数
|
// 表单参数
|
||||||
form: {},
|
form: {},
|
||||||
|
|
@ -144,7 +175,7 @@ export default {
|
||||||
rules: {
|
rules: {
|
||||||
limitCount: [
|
limitCount: [
|
||||||
{required: true, message: "请求次数", trigger: "blur"},
|
{required: true, message: "请求次数", trigger: "blur"},
|
||||||
{type: 'number',min: 0, max: 9999, message: '必须数字!且数字在 0 到 9999 之间!', trigger: 'blur'}
|
{type: 'number', min: 0, max: 9999, message: '必须数字!且数字在 0 到 9999 之间!', trigger: 'blur'}
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ public class MyMetaObjectHandler implements MetaObjectHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void insertFill(MetaObject metaObject) {
|
public void insertFill(MetaObject metaObject) {
|
||||||
log.info("start insert fill ....");
|
//log.info("start insert fill ....");
|
||||||
//this.setFieldValByName("createTime", new Date(), metaObject);
|
//this.setFieldValByName("createTime", new Date(), metaObject);
|
||||||
this.strictInsertFill(metaObject, "createTime", Date.class,new Date()); // 起始版本 3.3.3(推荐)
|
this.strictInsertFill(metaObject, "createTime", Date.class,new Date()); // 起始版本 3.3.3(推荐)
|
||||||
this.strictInsertFill(metaObject, "updateTime", Date.class,new Date());
|
this.strictInsertFill(metaObject, "updateTime", Date.class,new Date());
|
||||||
|
|
|
||||||
|
|
@ -28,12 +28,12 @@ import java.lang.annotation.Annotation;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
import java.util.Date;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||||
import static com.xjs.consts.ApiWarnHandleConst.NO;
|
import static com.xjs.consts.ApiWarnHandleConst.NO;
|
||||||
|
import static com.xjs.consts.ReqConst.ERROR;
|
||||||
|
import static com.xjs.consts.ReqConst.SUCCESS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* api日志切面类
|
* api日志切面类
|
||||||
|
|
@ -76,14 +76,19 @@ public class ApiLogAspect {
|
||||||
//执行预警切入逻辑(降级不预警)
|
//执行预警切入逻辑(降级不预警)
|
||||||
if (obj instanceof JSONObject) {
|
if (obj instanceof JSONObject) {
|
||||||
JSONObject jsonObject = (JSONObject) obj;
|
JSONObject jsonObject = (JSONObject) obj;
|
||||||
|
|
||||||
if (!jsonObject.containsKey(DEMOTE_ERROR)) {
|
if (!jsonObject.containsKey(DEMOTE_ERROR)) {
|
||||||
warning(between, joinPoint);
|
this.warning(between, joinPoint);
|
||||||
|
} else {
|
||||||
|
//如果降级,接口状态修改为异常
|
||||||
|
this.demoteHandle(joinPoint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//返回值为String情况
|
//返回值为String情况
|
||||||
if (obj instanceof String) {
|
if (obj instanceof String) {
|
||||||
if (StringUtils.isNotEmpty(String.valueOf(obj))) {
|
if (StringUtils.isNotEmpty(String.valueOf(obj))) {
|
||||||
warning(between, joinPoint);
|
this.warning(between, joinPoint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -94,6 +99,7 @@ public class ApiLogAspect {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理完请求后执行
|
* 处理完请求后执行
|
||||||
*
|
*
|
||||||
|
|
@ -148,11 +154,12 @@ public class ApiLogAspect {
|
||||||
if (e != null || StringUtils.isEmpty(response)) {
|
if (e != null || StringUtils.isEmpty(response)) {
|
||||||
entity.setIsSuccess(ReqConst.ERROR);
|
entity.setIsSuccess(ReqConst.ERROR);
|
||||||
} else {
|
} else {
|
||||||
entity.setIsSuccess(ReqConst.SUCCESS);
|
entity.setIsSuccess(SUCCESS);
|
||||||
}
|
}
|
||||||
remoteLogFeign.saveApiLog(entity);
|
remoteLogFeign.saveApiLog(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 预警切入
|
* 预警切入
|
||||||
*
|
*
|
||||||
|
|
@ -160,20 +167,16 @@ public class ApiLogAspect {
|
||||||
* @param joinPoint aop连接对象
|
* @param joinPoint aop连接对象
|
||||||
*/
|
*/
|
||||||
private void warning(long between, ProceedingJoinPoint joinPoint) {
|
private void warning(long between, ProceedingJoinPoint joinPoint) {
|
||||||
//获取目标类名及方法名
|
|
||||||
Signature signature = joinPoint.getSignature();
|
Map<String, String> annotationInfo = this.getAnnotationInfo(joinPoint);
|
||||||
String method = signature.getName();
|
|
||||||
Class aclass = signature.getDeclaringType();
|
if (CollUtil.isEmpty(annotationInfo)) {
|
||||||
Method[] methods = aclass.getMethods();
|
return;
|
||||||
//根据目标的方法名判断当前方法
|
}
|
||||||
for (Method thisMethod : methods) {
|
|
||||||
if (method.equals(thisMethod.getName())) {
|
String name = annotationInfo.get("name");
|
||||||
//拿到当前方法的注解判断是否为apiLog注解
|
String url = annotationInfo.get("url");
|
||||||
Annotation[] declaredAnnotations = thisMethod.getDeclaredAnnotations();
|
|
||||||
for (Annotation annotation : declaredAnnotations) {
|
|
||||||
if (annotation instanceof ApiLog) {
|
|
||||||
String name = ((ApiLog) annotation).name();
|
|
||||||
String url = ((ApiLog) annotation).url();
|
|
||||||
//根据拿到的url和name查询数据库是否存在,存在则count+1,不存在则add
|
//根据拿到的url和name查询数据库是否存在,存在则count+1,不存在则add
|
||||||
ApiRecord apiRecord = new ApiRecord();
|
ApiRecord apiRecord = new ApiRecord();
|
||||||
apiRecord.setApiName(name);
|
apiRecord.setApiName(name);
|
||||||
|
|
@ -187,10 +190,12 @@ public class ApiLogAspect {
|
||||||
apiRecord.setTotalCount(1L);
|
apiRecord.setTotalCount(1L);
|
||||||
apiRecord.setDayCount(1L);
|
apiRecord.setDayCount(1L);
|
||||||
apiRecord.setLimitCount(30L);
|
apiRecord.setLimitCount(30L);
|
||||||
|
apiRecord.setStatus(SUCCESS);
|
||||||
remoteWarningCRUDFeign.saveApiRecordForRPC(apiRecord);
|
remoteWarningCRUDFeign.saveApiRecordForRPC(apiRecord);
|
||||||
} else {
|
} else {
|
||||||
ApiRecord haveApiRecord = data.get(0);
|
ApiRecord haveApiRecord = data.get(0);
|
||||||
|
|
||||||
|
haveApiRecord.setStatus(SUCCESS);
|
||||||
haveApiRecord.setRequestTime((int) between);
|
haveApiRecord.setRequestTime((int) between);
|
||||||
haveApiRecord.setTotalCount(haveApiRecord.getTotalCount() + 1L);
|
haveApiRecord.setTotalCount(haveApiRecord.getTotalCount() + 1L);
|
||||||
//统计当前的请求次数,隔天清零
|
//统计当前的请求次数,隔天清零
|
||||||
|
|
@ -234,11 +239,73 @@ public class ApiLogAspect {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 接口降级修改状态异常
|
||||||
|
* @param joinPoint 切入点
|
||||||
|
*/
|
||||||
|
private void demoteHandle(ProceedingJoinPoint joinPoint) {
|
||||||
|
|
||||||
|
Map<String, String> map = this.getAnnotationInfo(joinPoint);
|
||||||
|
|
||||||
|
if (CollUtil.isEmpty(map)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String name = map.get("name");
|
||||||
|
String url = map.get("url");
|
||||||
|
ApiRecord apiRecord = new ApiRecord();
|
||||||
|
apiRecord.setApiName(name);
|
||||||
|
apiRecord.setApiUrl(url);
|
||||||
|
|
||||||
|
R<List<ApiRecord>> listR = remoteWarningCRUDFeign.selectApiRecordListForRPC(apiRecord);
|
||||||
|
if (listR.getCode() == R.SUCCESS) {
|
||||||
|
List<ApiRecord> data = listR.getData();
|
||||||
|
if (CollUtil.isNotEmpty(data)) {
|
||||||
|
ApiRecord haveApiRecord = data.get(0);
|
||||||
|
//置为空让mp自动填充
|
||||||
|
haveApiRecord.setUpdateTime(null);
|
||||||
|
haveApiRecord.setStatus(ERROR);
|
||||||
|
remoteWarningCRUDFeign.updateApiRecordForRPC(haveApiRecord);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过反射获取注解信息
|
||||||
|
*
|
||||||
|
* @param joinPoint 切入点
|
||||||
|
* @return 注解信息map
|
||||||
|
*/
|
||||||
|
private Map<String, String> getAnnotationInfo(ProceedingJoinPoint joinPoint) {
|
||||||
|
//获取目标类名及方法名
|
||||||
|
Signature signature = joinPoint.getSignature();
|
||||||
|
String method = signature.getName();
|
||||||
|
Class aclass = signature.getDeclaringType();
|
||||||
|
Method[] methods = aclass.getMethods();
|
||||||
|
|
||||||
|
//根据目标的方法名判断当前方法
|
||||||
|
for (Method thisMethod : methods) {
|
||||||
|
if (method.equals(thisMethod.getName())) {
|
||||||
|
|
||||||
|
//拿到当前方法的注解判断是否为apiLog注解
|
||||||
|
Annotation[] declaredAnnotations = thisMethod.getDeclaredAnnotations();
|
||||||
|
|
||||||
|
for (Annotation annotation : declaredAnnotations) {
|
||||||
|
if (annotation instanceof ApiLog) {
|
||||||
|
String name = ((ApiLog) annotation).name();
|
||||||
|
String url = ((ApiLog) annotation).url();
|
||||||
|
|
||||||
|
Map<String, String> hashMap = new HashMap<>();
|
||||||
|
hashMap.put("name", name);
|
||||||
|
hashMap.put("url", url);
|
||||||
|
return hashMap;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,7 @@ public class ApiWarningController extends BaseController {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理预警单个预警
|
* 处理预警单个预警
|
||||||
|
*
|
||||||
* @param id 预警id
|
* @param id 预警id
|
||||||
* @return R
|
* @return R
|
||||||
*/
|
*/
|
||||||
|
|
@ -61,7 +62,7 @@ public class ApiWarningController extends BaseController {
|
||||||
ApiWarning apiWarning = new ApiWarning();
|
ApiWarning apiWarning = new ApiWarning();
|
||||||
apiWarning.setId(id);
|
apiWarning.setId(id);
|
||||||
apiWarning.setHandle(YES);
|
apiWarning.setHandle(YES);
|
||||||
return apiWarningService.updateById(apiWarning)?R.ok():R.fail();
|
return apiWarningService.updateById(apiWarning) ? R.ok() : R.fail();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -70,11 +71,11 @@ public class ApiWarningController extends BaseController {
|
||||||
@RequiresPermissions("warning:warning:list")
|
@RequiresPermissions("warning:warning:list")
|
||||||
@GetMapping("/apiwarnlist")
|
@GetMapping("/apiwarnlist")
|
||||||
@ApiOperation("查询api预警列表")
|
@ApiOperation("查询api预警列表")
|
||||||
public TableDataInfo list(ApiWarning apiWarning) {
|
public TableDataInfo list(@Validated({SelectGroup.class}) ApiWarning apiWarning) {
|
||||||
startPage();
|
startPage();
|
||||||
List<ApiWarning> list = apiWarningService.list(new QueryWrapper<ApiWarning>()
|
List<ApiWarning> list = apiWarningService.list(new QueryWrapper<ApiWarning>()
|
||||||
.orderByDesc("create_time")
|
.orderByDesc("create_time")
|
||||||
.like(Objects.nonNull(apiWarning.getApiName()),"api_name", apiWarning.getApiName()));
|
.like(Objects.nonNull(apiWarning.getApiName()), "api_name", apiWarning.getApiName()));
|
||||||
return getDataTable(list);
|
return getDataTable(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -87,7 +88,7 @@ public class ApiWarningController extends BaseController {
|
||||||
@ApiOperation("导出api预警列表")
|
@ApiOperation("导出api预警列表")
|
||||||
public void export(HttpServletResponse response, ApiWarning apiWarning) {
|
public void export(HttpServletResponse response, ApiWarning apiWarning) {
|
||||||
List<ApiWarning> list = apiWarningService.list(new QueryWrapper<ApiWarning>()
|
List<ApiWarning> list = apiWarningService.list(new QueryWrapper<ApiWarning>()
|
||||||
.like(Objects.nonNull(apiWarning.getApiName()),"api_name", apiWarning.getApiName()));
|
.like(Objects.nonNull(apiWarning.getApiName()), "api_name", apiWarning.getApiName()));
|
||||||
ExcelUtil<ApiWarning> util = new ExcelUtil<ApiWarning>(ApiWarning.class);
|
ExcelUtil<ApiWarning> util = new ExcelUtil<ApiWarning>(ApiWarning.class);
|
||||||
util.exportExcel(response, list, "api预警数据");
|
util.exportExcel(response, list, "api预警数据");
|
||||||
}
|
}
|
||||||
|
|
@ -113,6 +114,7 @@ public class ApiWarningController extends BaseController {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取所有Api名称
|
* 获取所有Api名称
|
||||||
|
*
|
||||||
* @return api名称
|
* @return api名称
|
||||||
*/
|
*/
|
||||||
@GetMapping("getApiName")
|
@GetMapping("getApiName")
|
||||||
|
|
@ -167,12 +169,13 @@ public class ApiWarningController extends BaseController {
|
||||||
@ApiOperation("远程查询预警信息")
|
@ApiOperation("远程查询预警信息")
|
||||||
public R<JSONArray> findRecordListForRPC() {
|
public R<JSONArray> findRecordListForRPC() {
|
||||||
List<ApiRecord> apiRecordList = apiWarningService.selectApiRecordList(new ApiRecord());
|
List<ApiRecord> apiRecordList = apiWarningService.selectApiRecordList(new ApiRecord());
|
||||||
JSONArray jo= (JSONArray) JSONArray.toJSON(apiRecordList);
|
JSONArray jo = (JSONArray) JSONArray.toJSON(apiRecordList);
|
||||||
return R.ok(jo);
|
return R.ok(jo);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 远程获取所有Api名称
|
* 远程获取所有Api名称
|
||||||
|
*
|
||||||
* @return api名称
|
* @return api名称
|
||||||
*/
|
*/
|
||||||
@GetMapping("getApiNameForRPC")
|
@GetMapping("getApiNameForRPC")
|
||||||
|
|
@ -183,7 +186,6 @@ public class ApiWarningController extends BaseController {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 远程保存api预警信息并websocket推送
|
* 远程保存api预警信息并websocket推送
|
||||||
*
|
*
|
||||||
|
|
@ -205,9 +207,9 @@ public class ApiWarningController extends BaseController {
|
||||||
* websocket推送
|
* websocket推送
|
||||||
*/
|
*/
|
||||||
private void websocketPush(ApiWarning apiWarning) {
|
private void websocketPush(ApiWarning apiWarning) {
|
||||||
long count = apiWarningService.count(new QueryWrapper<ApiWarning>().eq("handle",NO));
|
long count = apiWarningService.count(new QueryWrapper<ApiWarning>().eq("handle", NO));
|
||||||
Set<String> cacheSet = redisService.getCacheSet(WEBSOCKET);
|
Set<String> cacheSet = redisService.getCacheSet(WEBSOCKET);
|
||||||
JSONObject jsonData =new JSONObject();
|
JSONObject jsonData = new JSONObject();
|
||||||
JSONObject jsonObject = (JSONObject) JSONObject.toJSON(apiWarning);
|
JSONObject jsonObject = (JSONObject) JSONObject.toJSON(apiWarning);
|
||||||
//把id设置成字符串防止前端精度丢失
|
//把id设置成字符串防止前端精度丢失
|
||||||
jsonObject.put("id", apiWarning.getId().toString());
|
jsonObject.put("id", apiWarning.getId().toString());
|
||||||
|
|
@ -216,7 +218,7 @@ public class ApiWarningController extends BaseController {
|
||||||
jsonData.put("socketType", "apiWarning");
|
jsonData.put("socketType", "apiWarning");
|
||||||
for (String userId : cacheSet) {
|
for (String userId : cacheSet) {
|
||||||
try {
|
try {
|
||||||
WebSocketServer.sendInfo(jsonData.toString(),userId);
|
WebSocketServer.sendInfo(jsonData.toString(), userId);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.error(e.getMessage());
|
logger.error(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
@ -224,8 +226,6 @@ public class ApiWarningController extends BaseController {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//-------------------------代码生成------------------------------------
|
//-------------------------代码生成------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.ruoyi.common.core.annotation.Excel;
|
import com.ruoyi.common.core.annotation.Excel;
|
||||||
|
import com.xjs.validation.annotation.CheckNumber;
|
||||||
import com.xjs.validation.group.SelectGroup;
|
import com.xjs.validation.group.SelectGroup;
|
||||||
import com.xjs.validation.group.UpdateGroup;
|
import com.xjs.validation.group.UpdateGroup;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
@ -35,7 +36,7 @@ public class ApiRecord implements Serializable {
|
||||||
* api名称
|
* api名称
|
||||||
*/
|
*/
|
||||||
@Excel(name = "api名称")
|
@Excel(name = "api名称")
|
||||||
@Size(max = 20, message = "请控制api名称长度在20字符", groups = { SelectGroup.class})
|
@Size(max = 20, message = "请控制api名称长度在20字符", groups = {SelectGroup.class})
|
||||||
private String apiName;
|
private String apiName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -56,13 +57,20 @@ public class ApiRecord implements Serializable {
|
||||||
@Excel(name = "api总请求次数")
|
@Excel(name = "api总请求次数")
|
||||||
private Long totalCount;
|
private Long totalCount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 接口状态
|
||||||
|
*/
|
||||||
|
@Excel(name = "接口状态", readConverterExp = "1=正常,2=异常")
|
||||||
|
@CheckNumber(num= {1, 2}, groups = { SelectGroup.class})
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* api限制请求次数每天
|
* api限制请求次数每天
|
||||||
*/
|
*/
|
||||||
@Excel(name = "api限制请求次数每天")
|
@Excel(name = "api限制请求次数每天")
|
||||||
@NotNull(message = "api每天限制请求次数不能为空",groups = UpdateGroup.class)
|
@NotNull(message = "api每天限制请求次数不能为空", groups = UpdateGroup.class)
|
||||||
@Max(value = 9999,message = "超过最大值!api每天限制请求次数最大为9999",groups = UpdateGroup.class)
|
@Max(value = 9999, message = "超过最大值!api每天限制请求次数最大为9999", groups = UpdateGroup.class)
|
||||||
@Min(value = 0,message = "低于最小值!api每天限制请求次数最小为0",groups = UpdateGroup.class)
|
@Min(value = 0, message = "低于最小值!api每天限制请求次数最小为0", groups = UpdateGroup.class)
|
||||||
private Long limitCount;
|
private Long limitCount;
|
||||||
|
|
||||||
@Excel(name = "api每天请求次数")
|
@Excel(name = "api每天请求次数")
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,10 @@ import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.ruoyi.common.core.annotation.Excel;
|
import com.ruoyi.common.core.annotation.Excel;
|
||||||
|
import com.xjs.validation.group.SelectGroup;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.Size;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
|
@ -22,6 +24,7 @@ public class ApiWarning implements Serializable {
|
||||||
|
|
||||||
/** api名称 */
|
/** api名称 */
|
||||||
@Excel(name = "api名称")
|
@Excel(name = "api名称")
|
||||||
|
@Size(max = 20, message = "请控制api名称长度在20字符", groups = {SelectGroup.class})
|
||||||
private String apiName;
|
private String apiName;
|
||||||
|
|
||||||
/** 预警类型 */
|
/** 预警类型 */
|
||||||
|
|
|
||||||
|
|
@ -14,10 +14,11 @@
|
||||||
<result property="createTime" column="create_time" />
|
<result property="createTime" column="create_time" />
|
||||||
<result property="dayCount" column="day_count" />
|
<result property="dayCount" column="day_count" />
|
||||||
<result property="updateTime" column="update_time" />
|
<result property="updateTime" column="update_time" />
|
||||||
|
<result property="status" column="status" />
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<sql id="selectApiRecordVo">
|
<sql id="selectApiRecordVo">
|
||||||
select id, api_name, api_url, total_count, limit_count, create_time, update_time,day_count,request_time
|
select id, api_name, api_url, total_count, limit_count, create_time, update_time,day_count,request_time,status
|
||||||
from api_record
|
from api_record
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
|
|
@ -25,6 +26,7 @@
|
||||||
<include refid="selectApiRecordVo"/>
|
<include refid="selectApiRecordVo"/>
|
||||||
<where>
|
<where>
|
||||||
<if test="apiName != null and apiName != ''"> and api_name like concat('%', #{apiName}, '%')</if>
|
<if test="apiName != null and apiName != ''"> and api_name like concat('%', #{apiName}, '%')</if>
|
||||||
|
<if test="status != null">status = #{status}</if>
|
||||||
</where>
|
</where>
|
||||||
order by create_time desc
|
order by create_time desc
|
||||||
</select>
|
</select>
|
||||||
|
|
@ -44,6 +46,7 @@
|
||||||
<if test="limitCount != null">limit_count = #{limitCount},</if>
|
<if test="limitCount != null">limit_count = #{limitCount},</if>
|
||||||
<if test="createTime != null">create_time = #{createTime},</if>
|
<if test="createTime != null">create_time = #{createTime},</if>
|
||||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||||
|
<if test="status != null">status = #{status},</if>
|
||||||
</trim>
|
</trim>
|
||||||
where id = #{id}
|
where id = #{id}
|
||||||
</update>
|
</update>
|
||||||
|
|
|
||||||
|
|
@ -106,18 +106,36 @@ public class _36wallpaperProcessor implements PageProcessor {
|
||||||
private void initParameter() {
|
private void initParameter() {
|
||||||
//判断redis中是否存在
|
//判断redis中是否存在
|
||||||
Boolean hasKey = redisService.hasKey(REDIS_KEY);
|
Boolean hasKey = redisService.hasKey(REDIS_KEY);
|
||||||
|
JSONObject json;
|
||||||
|
String downloadImg = "downloadImg";
|
||||||
|
String path = "path";
|
||||||
|
String init = "init";
|
||||||
if (hasKey) {
|
if (hasKey) {
|
||||||
String cacheObject = redisService.getCacheObject(REDIS_KEY);
|
String cacheObject = redisService.getCacheObject(REDIS_KEY);
|
||||||
JSONObject json = JSONObject.parseObject(cacheObject);
|
try {
|
||||||
this.init = json.getBoolean("init");
|
json = JSONObject.parseObject(cacheObject);
|
||||||
this.downloadImg = json.getBoolean("downloadImg");
|
if(json.containsKey(init) && json.containsKey(downloadImg) && json.containsKey(path)){
|
||||||
this.path = json.getString("path");
|
this.init = json.getBoolean(init);
|
||||||
|
this.downloadImg = json.getBoolean(downloadImg);
|
||||||
|
this.path = json.getString(path);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("JSON转换异常:"+e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
} else if (StringUtils.isNotEmpty(remoteConfigService.getConfigKeyForRPC(CONFIG_KEY).getData())) {
|
} else if (StringUtils.isNotEmpty(remoteConfigService.getConfigKeyForRPC(CONFIG_KEY).getData())) {
|
||||||
String data = remoteConfigService.getConfigKeyForRPC(CONFIG_KEY).getData();
|
String data = remoteConfigService.getConfigKeyForRPC(CONFIG_KEY).getData();
|
||||||
JSONObject json = JSONObject.parseObject(data);
|
try {
|
||||||
this.init = json.getBoolean("init");
|
json = JSONObject.parseObject(data);
|
||||||
this.downloadImg = json.getBoolean("downloadImg");
|
if(json.containsKey(init) && json.containsKey(downloadImg) && json.containsKey(path)){
|
||||||
this.path = json.getString("path");
|
this.init = json.getBoolean(init);
|
||||||
|
this.downloadImg = json.getBoolean(downloadImg);
|
||||||
|
this.path = json.getString(path);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("JSON转换异常:"+e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue