1、预警信息新增api预警的状态
This commit is contained in:
parent
f2a6a46d29
commit
827e8c521f
|
|
@ -4,24 +4,33 @@ import java.io.Serializable;
|
|||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* api记录实体类
|
||||
*
|
||||
* @author xiejs
|
||||
* @desc api记录实体类
|
||||
* @create 2021-12-31
|
||||
* @since 2021-12-31
|
||||
*/
|
||||
public class ApiRecord implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 主键id */
|
||||
/**
|
||||
* 主键id
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/** api名称 */
|
||||
/**
|
||||
* api名称
|
||||
*/
|
||||
private String apiName;
|
||||
|
||||
/** api地址 */
|
||||
/**
|
||||
* api地址
|
||||
*/
|
||||
private String apiUrl;
|
||||
|
||||
/** api每天请求次数 */
|
||||
/**
|
||||
* api每天请求次数
|
||||
*/
|
||||
private Long dayCount;
|
||||
|
||||
/**
|
||||
|
|
@ -29,16 +38,32 @@ public class ApiRecord implements Serializable {
|
|||
*/
|
||||
private Integer requestTime;
|
||||
|
||||
/** api总请求次数 */
|
||||
/**
|
||||
* api总请求次数
|
||||
*/
|
||||
private Long totalCount;
|
||||
|
||||
/** api限制请求次数每天 */
|
||||
private Integer status;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* api限制请求次数每天
|
||||
*/
|
||||
private Long limitCount;
|
||||
|
||||
private Date createTime;
|
||||
|
||||
private Date updateTime;
|
||||
|
||||
public Integer getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(Integer status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,23 @@
|
|||
:value="index"/>
|
||||
</el-select>
|
||||
</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-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>
|
||||
|
|
@ -55,14 +72,24 @@
|
|||
<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">
|
||||
<template slot-scope="scope">
|
||||
<span>{{scope.row.requestTime+"ms"}}</span>
|
||||
<span>{{ scope.row.requestTime + "ms" }}</span>
|
||||
</template>
|
||||
</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="调用时间" 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">
|
||||
<span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
|
||||
</template>
|
||||
|
|
@ -112,6 +139,9 @@ import {
|
|||
|
||||
export default {
|
||||
name: "Apiwarning",
|
||||
|
||||
dicts: ['request_status'],
|
||||
|
||||
data() {
|
||||
return {
|
||||
// 遮罩层
|
||||
|
|
@ -137,6 +167,7 @@ export default {
|
|||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
apiName: null,
|
||||
status: null
|
||||
},
|
||||
// 表单参数
|
||||
form: {},
|
||||
|
|
@ -144,7 +175,7 @@ export default {
|
|||
rules: {
|
||||
limitCount: [
|
||||
{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
|
||||
public void insertFill(MetaObject metaObject) {
|
||||
log.info("start insert fill ....");
|
||||
//log.info("start insert fill ....");
|
||||
//this.setFieldValByName("createTime", new Date(), metaObject);
|
||||
this.strictInsertFill(metaObject, "createTime", Date.class,new Date()); // 起始版本 3.3.3(推荐)
|
||||
this.strictInsertFill(metaObject, "updateTime", Date.class,new Date());
|
||||
|
|
|
|||
|
|
@ -28,12 +28,12 @@ import java.lang.annotation.Annotation;
|
|||
import java.lang.reflect.Method;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
|
||||
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||
import static com.xjs.consts.ApiWarnHandleConst.NO;
|
||||
import static com.xjs.consts.ReqConst.ERROR;
|
||||
import static com.xjs.consts.ReqConst.SUCCESS;
|
||||
|
||||
/**
|
||||
* api日志切面类
|
||||
|
|
@ -76,14 +76,19 @@ public class ApiLogAspect {
|
|||
//执行预警切入逻辑(降级不预警)
|
||||
if (obj instanceof JSONObject) {
|
||||
JSONObject jsonObject = (JSONObject) obj;
|
||||
|
||||
if (!jsonObject.containsKey(DEMOTE_ERROR)) {
|
||||
warning(between, joinPoint);
|
||||
this.warning(between, joinPoint);
|
||||
} else {
|
||||
//如果降级,接口状态修改为异常
|
||||
this.demoteHandle(joinPoint);
|
||||
}
|
||||
}
|
||||
|
||||
//返回值为String情况
|
||||
if (obj instanceof String) {
|
||||
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)) {
|
||||
entity.setIsSuccess(ReqConst.ERROR);
|
||||
} else {
|
||||
entity.setIsSuccess(ReqConst.SUCCESS);
|
||||
entity.setIsSuccess(SUCCESS);
|
||||
}
|
||||
remoteLogFeign.saveApiLog(entity);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 预警切入
|
||||
*
|
||||
|
|
@ -160,85 +167,145 @@ public class ApiLogAspect {
|
|||
* @param joinPoint aop连接对象
|
||||
*/
|
||||
private void warning(long between, ProceedingJoinPoint joinPoint) {
|
||||
|
||||
Map<String, String> annotationInfo = this.getAnnotationInfo(joinPoint);
|
||||
|
||||
if (CollUtil.isEmpty(annotationInfo)) {
|
||||
return;
|
||||
}
|
||||
|
||||
String name = annotationInfo.get("name");
|
||||
String url = annotationInfo.get("url");
|
||||
|
||||
//根据拿到的url和name查询数据库是否存在,存在则count+1,不存在则add
|
||||
ApiRecord apiRecord = new ApiRecord();
|
||||
apiRecord.setApiName(name);
|
||||
apiRecord.setApiUrl(url);
|
||||
apiRecord.setRequestTime((int) between);
|
||||
R<List<ApiRecord>> listR = remoteWarningCRUDFeign.selectApiRecordListForRPC(apiRecord);
|
||||
if (listR.getCode() == R.SUCCESS) {
|
||||
List<ApiRecord> data = listR.getData();
|
||||
if (CollUtil.isEmpty(data)) {
|
||||
//设置初始请求次数
|
||||
apiRecord.setTotalCount(1L);
|
||||
apiRecord.setDayCount(1L);
|
||||
apiRecord.setLimitCount(30L);
|
||||
apiRecord.setStatus(SUCCESS);
|
||||
remoteWarningCRUDFeign.saveApiRecordForRPC(apiRecord);
|
||||
} else {
|
||||
ApiRecord haveApiRecord = data.get(0);
|
||||
|
||||
haveApiRecord.setStatus(SUCCESS);
|
||||
haveApiRecord.setRequestTime((int) between);
|
||||
haveApiRecord.setTotalCount(haveApiRecord.getTotalCount() + 1L);
|
||||
//统计当前的请求次数,隔天清零
|
||||
haveApiRecord.setDayCount(haveApiRecord.getDayCount() + 1L);
|
||||
Date updateTime = haveApiRecord.getUpdateTime();
|
||||
String dateTime = DateUtil.formatDateTime(updateTime);
|
||||
Date date = DateUtil.parseDate(dateTime).toJdkDate();
|
||||
//当前时间和最后一次修改时间间隔天数(超过1 就清零)
|
||||
long compareTime = DateUtil.between(date, new Date(), DateUnit.DAY);
|
||||
if (compareTime > 0) {
|
||||
haveApiRecord.setDayCount(1L);
|
||||
}
|
||||
//置为空让mp自动填充
|
||||
haveApiRecord.setUpdateTime(null);
|
||||
remoteWarningCRUDFeign.updateApiRecordForRPC(haveApiRecord);
|
||||
//判断接口请求是否超过阈值
|
||||
if (Objects.nonNull(haveApiRecord.getLimitCount())) {
|
||||
if (haveApiRecord.getDayCount() > haveApiRecord.getLimitCount()) {
|
||||
//把记录添加到预警表中
|
||||
ApiWarning apiWarning = new ApiWarning();
|
||||
apiWarning.setLimitValue(String.valueOf(haveApiRecord.getLimitCount()));
|
||||
apiWarning.setRealValue(String.valueOf(haveApiRecord.getDayCount()));
|
||||
apiWarning.setApiName(haveApiRecord.getApiName());
|
||||
apiWarning.setHandle(NO);
|
||||
apiWarning.setWarningLevel(WarnLevelEnum.NOEMAL.getMessage());
|
||||
if (haveApiRecord.getDayCount() > haveApiRecord.getLimitCount() * 2 &&
|
||||
haveApiRecord.getDayCount() < haveApiRecord.getLimitCount() * 3) {
|
||||
apiWarning.setWarningLevel(WarnLevelEnum.WARNING.getMessage());
|
||||
} else if (haveApiRecord.getDayCount() > haveApiRecord.getLimitCount() * 3) {
|
||||
apiWarning.setWarningLevel(WarnLevelEnum.DANGER.getMessage());
|
||||
}
|
||||
apiWarning.setWarningType(WarnTypeEnum.API.getType());
|
||||
String message = String.format(WarnTypeEnum.API.getMessage(),
|
||||
haveApiRecord.getApiName(),
|
||||
haveApiRecord.getLimitCount(),
|
||||
haveApiRecord.getDayCount());
|
||||
apiWarning.setWarningMessage(message);
|
||||
remoteWarningCRUDFeign.saveApiWarningForRPC(apiWarning);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 接口降级修改状态异常
|
||||
* @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();
|
||||
//根据拿到的url和name查询数据库是否存在,存在则count+1,不存在则add
|
||||
ApiRecord apiRecord = new ApiRecord();
|
||||
apiRecord.setApiName(name);
|
||||
apiRecord.setApiUrl(url);
|
||||
apiRecord.setRequestTime((int) between);
|
||||
R<List<ApiRecord>> listR = remoteWarningCRUDFeign.selectApiRecordListForRPC(apiRecord);
|
||||
if (listR.getCode() == R.SUCCESS) {
|
||||
List<ApiRecord> data = listR.getData();
|
||||
if (CollUtil.isEmpty(data)) {
|
||||
//设置初始请求次数
|
||||
apiRecord.setTotalCount(1L);
|
||||
apiRecord.setDayCount(1L);
|
||||
apiRecord.setLimitCount(30L);
|
||||
remoteWarningCRUDFeign.saveApiRecordForRPC(apiRecord);
|
||||
} else {
|
||||
ApiRecord haveApiRecord = data.get(0);
|
||||
|
||||
haveApiRecord.setRequestTime((int) between);
|
||||
haveApiRecord.setTotalCount(haveApiRecord.getTotalCount() + 1L);
|
||||
//统计当前的请求次数,隔天清零
|
||||
haveApiRecord.setDayCount(haveApiRecord.getDayCount() + 1L);
|
||||
Date updateTime = haveApiRecord.getUpdateTime();
|
||||
String dateTime = DateUtil.formatDateTime(updateTime);
|
||||
Date date = DateUtil.parseDate(dateTime).toJdkDate();
|
||||
//当前时间和最后一次修改时间间隔天数(超过1 就清零)
|
||||
long compareTime = DateUtil.between(date, new Date(), DateUnit.DAY);
|
||||
if (compareTime > 0) {
|
||||
haveApiRecord.setDayCount(1L);
|
||||
}
|
||||
//置为空让mp自动填充
|
||||
haveApiRecord.setUpdateTime(null);
|
||||
remoteWarningCRUDFeign.updateApiRecordForRPC(haveApiRecord);
|
||||
//判断接口请求是否超过阈值
|
||||
if (Objects.nonNull(haveApiRecord.getLimitCount())) {
|
||||
if (haveApiRecord.getDayCount() > haveApiRecord.getLimitCount()) {
|
||||
//把记录添加到预警表中
|
||||
ApiWarning apiWarning = new ApiWarning();
|
||||
apiWarning.setLimitValue(String.valueOf(haveApiRecord.getLimitCount()));
|
||||
apiWarning.setRealValue(String.valueOf(haveApiRecord.getDayCount()));
|
||||
apiWarning.setApiName(haveApiRecord.getApiName());
|
||||
apiWarning.setHandle(NO);
|
||||
apiWarning.setWarningLevel(WarnLevelEnum.NOEMAL.getMessage());
|
||||
if (haveApiRecord.getDayCount() > haveApiRecord.getLimitCount() * 2 &&
|
||||
haveApiRecord.getDayCount() < haveApiRecord.getLimitCount() * 3) {
|
||||
apiWarning.setWarningLevel(WarnLevelEnum.WARNING.getMessage());
|
||||
} else if (haveApiRecord.getDayCount() > haveApiRecord.getLimitCount() * 3) {
|
||||
apiWarning.setWarningLevel(WarnLevelEnum.DANGER.getMessage());
|
||||
}
|
||||
apiWarning.setWarningType(WarnTypeEnum.API.getType());
|
||||
String message = String.format(WarnTypeEnum.API.getMessage(),
|
||||
haveApiRecord.getApiName(),
|
||||
haveApiRecord.getLimitCount(),
|
||||
haveApiRecord.getDayCount());
|
||||
apiWarning.setWarningMessage(message);
|
||||
remoteWarningCRUDFeign.saveApiWarningForRPC(apiWarning);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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
|
||||
* @return R
|
||||
*/
|
||||
|
|
@ -61,7 +62,7 @@ public class ApiWarningController extends BaseController {
|
|||
ApiWarning apiWarning = new ApiWarning();
|
||||
apiWarning.setId(id);
|
||||
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")
|
||||
@GetMapping("/apiwarnlist")
|
||||
@ApiOperation("查询api预警列表")
|
||||
public TableDataInfo list(ApiWarning apiWarning) {
|
||||
public TableDataInfo list(@Validated({SelectGroup.class}) ApiWarning apiWarning) {
|
||||
startPage();
|
||||
List<ApiWarning> list = apiWarningService.list(new QueryWrapper<ApiWarning>()
|
||||
.orderByDesc("create_time")
|
||||
.like(Objects.nonNull(apiWarning.getApiName()),"api_name", apiWarning.getApiName()));
|
||||
.like(Objects.nonNull(apiWarning.getApiName()), "api_name", apiWarning.getApiName()));
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
|
|
@ -87,7 +88,7 @@ public class ApiWarningController extends BaseController {
|
|||
@ApiOperation("导出api预警列表")
|
||||
public void export(HttpServletResponse response, ApiWarning 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);
|
||||
util.exportExcel(response, list, "api预警数据");
|
||||
}
|
||||
|
|
@ -113,6 +114,7 @@ public class ApiWarningController extends BaseController {
|
|||
|
||||
/**
|
||||
* 获取所有Api名称
|
||||
*
|
||||
* @return api名称
|
||||
*/
|
||||
@GetMapping("getApiName")
|
||||
|
|
@ -167,12 +169,13 @@ public class ApiWarningController extends BaseController {
|
|||
@ApiOperation("远程查询预警信息")
|
||||
public R<JSONArray> findRecordListForRPC() {
|
||||
List<ApiRecord> apiRecordList = apiWarningService.selectApiRecordList(new ApiRecord());
|
||||
JSONArray jo= (JSONArray) JSONArray.toJSON(apiRecordList);
|
||||
JSONArray jo = (JSONArray) JSONArray.toJSON(apiRecordList);
|
||||
return R.ok(jo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 远程获取所有Api名称
|
||||
*
|
||||
* @return api名称
|
||||
*/
|
||||
@GetMapping("getApiNameForRPC")
|
||||
|
|
@ -183,7 +186,6 @@ public class ApiWarningController extends BaseController {
|
|||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 远程保存api预警信息并websocket推送
|
||||
*
|
||||
|
|
@ -202,12 +204,12 @@ public class ApiWarningController extends BaseController {
|
|||
}
|
||||
|
||||
/**
|
||||
* websocket推送
|
||||
* websocket推送
|
||||
*/
|
||||
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);
|
||||
JSONObject jsonData =new JSONObject();
|
||||
JSONObject jsonData = new JSONObject();
|
||||
JSONObject jsonObject = (JSONObject) JSONObject.toJSON(apiWarning);
|
||||
//把id设置成字符串防止前端精度丢失
|
||||
jsonObject.put("id", apiWarning.getId().toString());
|
||||
|
|
@ -216,7 +218,7 @@ public class ApiWarningController extends BaseController {
|
|||
jsonData.put("socketType", "apiWarning");
|
||||
for (String userId : cacheSet) {
|
||||
try {
|
||||
WebSocketServer.sendInfo(jsonData.toString(),userId);
|
||||
WebSocketServer.sendInfo(jsonData.toString(), userId);
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage());
|
||||
}
|
||||
|
|
@ -224,8 +226,6 @@ public class ApiWarningController extends BaseController {
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//-------------------------代码生成------------------------------------
|
||||
|
||||
|
||||
|
|
@ -271,7 +271,7 @@ public class ApiWarningController extends BaseController {
|
|||
@Log(title = "API预警", businessType = BusinessType.UPDATE)
|
||||
@PutMapping("edit")
|
||||
@ApiOperation("修改API预警信息")
|
||||
public AjaxResult edit(@Validated({UpdateGroup.class}) @RequestBody ApiRecord apiRecord) {
|
||||
public AjaxResult edit(@Validated({UpdateGroup.class}) @RequestBody ApiRecord apiRecord) {
|
||||
return toAjax(apiWarningService.updateApiRecord(apiRecord));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.FieldFill;
|
|||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.ruoyi.common.core.annotation.Excel;
|
||||
import com.xjs.validation.annotation.CheckNumber;
|
||||
import com.xjs.validation.group.SelectGroup;
|
||||
import com.xjs.validation.group.UpdateGroup;
|
||||
import lombok.Data;
|
||||
|
|
@ -35,7 +36,7 @@ public class ApiRecord implements Serializable {
|
|||
* 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;
|
||||
|
||||
/**
|
||||
|
|
@ -56,13 +57,20 @@ public class ApiRecord implements Serializable {
|
|||
@Excel(name = "api总请求次数")
|
||||
private Long totalCount;
|
||||
|
||||
/**
|
||||
* 接口状态
|
||||
*/
|
||||
@Excel(name = "接口状态", readConverterExp = "1=正常,2=异常")
|
||||
@CheckNumber(num= {1, 2}, groups = { SelectGroup.class})
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* api限制请求次数每天
|
||||
*/
|
||||
@Excel(name = "api限制请求次数每天")
|
||||
@NotNull(message = "api每天限制请求次数不能为空",groups = UpdateGroup.class)
|
||||
@Max(value = 9999,message = "超过最大值!api每天限制请求次数最大为9999",groups = UpdateGroup.class)
|
||||
@Min(value = 0,message = "低于最小值!api每天限制请求次数最小为0",groups = UpdateGroup.class)
|
||||
@NotNull(message = "api每天限制请求次数不能为空", groups = UpdateGroup.class)
|
||||
@Max(value = 9999, message = "超过最大值!api每天限制请求次数最大为9999", groups = UpdateGroup.class)
|
||||
@Min(value = 0, message = "低于最小值!api每天限制请求次数最小为0", groups = UpdateGroup.class)
|
||||
private Long limitCount;
|
||||
|
||||
@Excel(name = "api每天请求次数")
|
||||
|
|
|
|||
|
|
@ -4,8 +4,10 @@ import com.baomidou.mybatisplus.annotation.FieldFill;
|
|||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.ruoyi.common.core.annotation.Excel;
|
||||
import com.xjs.validation.group.SelectGroup;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
|
|
@ -22,6 +24,7 @@ public class ApiWarning implements Serializable {
|
|||
|
||||
/** api名称 */
|
||||
@Excel(name = "api名称")
|
||||
@Size(max = 20, message = "请控制api名称长度在20字符", groups = {SelectGroup.class})
|
||||
private String apiName;
|
||||
|
||||
/** 预警类型 */
|
||||
|
|
|
|||
|
|
@ -14,10 +14,11 @@
|
|||
<result property="createTime" column="create_time" />
|
||||
<result property="dayCount" column="day_count" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
<result property="status" column="status" />
|
||||
</resultMap>
|
||||
|
||||
<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
|
||||
</sql>
|
||||
|
||||
|
|
@ -25,6 +26,7 @@
|
|||
<include refid="selectApiRecordVo"/>
|
||||
<where>
|
||||
<if test="apiName != null and apiName != ''"> and api_name like concat('%', #{apiName}, '%')</if>
|
||||
<if test="status != null">status = #{status}</if>
|
||||
</where>
|
||||
order by create_time desc
|
||||
</select>
|
||||
|
|
@ -44,6 +46,7 @@
|
|||
<if test="limitCount != null">limit_count = #{limitCount},</if>
|
||||
<if test="createTime != null">create_time = #{createTime},</if>
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
<if test="status != null">status = #{status},</if>
|
||||
</trim>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
|
|
|||
|
|
@ -106,18 +106,36 @@ public class _36wallpaperProcessor implements PageProcessor {
|
|||
private void initParameter() {
|
||||
//判断redis中是否存在
|
||||
Boolean hasKey = redisService.hasKey(REDIS_KEY);
|
||||
JSONObject json;
|
||||
String downloadImg = "downloadImg";
|
||||
String path = "path";
|
||||
String init = "init";
|
||||
if (hasKey) {
|
||||
String cacheObject = redisService.getCacheObject(REDIS_KEY);
|
||||
JSONObject json = JSONObject.parseObject(cacheObject);
|
||||
this.init = json.getBoolean("init");
|
||||
this.downloadImg = json.getBoolean("downloadImg");
|
||||
this.path = json.getString("path");
|
||||
try {
|
||||
json = JSONObject.parseObject(cacheObject);
|
||||
if(json.containsKey(init) && json.containsKey(downloadImg) && json.containsKey(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())) {
|
||||
String data = remoteConfigService.getConfigKeyForRPC(CONFIG_KEY).getData();
|
||||
JSONObject json = JSONObject.parseObject(data);
|
||||
this.init = json.getBoolean("init");
|
||||
this.downloadImg = json.getBoolean("downloadImg");
|
||||
this.path = json.getString("path");
|
||||
try {
|
||||
json = JSONObject.parseObject(data);
|
||||
if(json.containsKey(init) && json.containsKey(downloadImg) && json.containsKey(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