From 02b4990a6f162513550020c51f310beea07d0596 Mon Sep 17 00:00:00 2001 From: xjs <1294405880@qq.com> Date: Sat, 15 Jan 2022 00:45:00 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E5=89=8D=E7=AB=AF=E9=A2=84=E8=AD=A6?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E5=86=85=E5=AE=B9=E4=BB=A5=E5=8F=8A=E5=8D=95?= =?UTF-8?q?=E4=B8=AA=E9=A2=84=E8=AD=A6=E5=A4=84=E7=90=86=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/api/business/warning/apiwarning.js | 8 +++ ruoyi-ui/src/layout/components/Navbar.vue | 55 ++++++++++++++++++- .../business/warning/apiwarning/index.vue | 2 +- .../xjs/controller/ApiWarningController.java | 20 ++++++- .../java/com/xjs/server/WebSocketServer.java | 5 +- 5 files changed, 85 insertions(+), 5 deletions(-) diff --git a/ruoyi-ui/src/api/business/warning/apiwarning.js b/ruoyi-ui/src/api/business/warning/apiwarning.js index 063e87ea..ec53fdfe 100644 --- a/ruoyi-ui/src/api/business/warning/apiwarning.js +++ b/ruoyi-ui/src/api/business/warning/apiwarning.js @@ -35,3 +35,11 @@ export function listApiwarning(query) { params: query }) } + +// 处理单个预警 +export function handleWarning(id) { + return request({ + url: '/warning/apiwarning/handle/'+id, + method: 'put', + }) +} diff --git a/ruoyi-ui/src/layout/components/Navbar.vue b/ruoyi-ui/src/layout/components/Navbar.vue index fe3b4651..c67b0abf 100644 --- a/ruoyi-ui/src/layout/components/Navbar.vue +++ b/ruoyi-ui/src/layout/components/Navbar.vue @@ -8,10 +8,26 @@
+ + -
@@ -56,6 +71,8 @@ import SizeSelect from '@/components/SizeSelect' import Search from '@/components/HeaderSearch' import RuoYiGit from '@/components/RuoYi/Git' import RuoYiDoc from '@/components/RuoYi/Doc' +import {handleWarning} from "@/api/business/warning/apiwarning"; + export default { components: { @@ -72,6 +89,8 @@ export default { data() { return { warnData: {}, + + visible: false, } }, @@ -108,6 +127,38 @@ export default { }, methods: { + + //已读操作 + haveRead() { + this.visible = false + if (this.warnData) { + let str = this.warnData.data; + if (str) { + var json = eval("(" + str + ")"); + if (json.id !== undefined) { + handleWarning(json.id).then(res => { + this.$modal.msgSuccess("处理成功"); + this.warnData.data= "{}" + }); + } + } + } + + + }, + + append() { + let str = this.warnData.data; + if (str != null) { + var json = eval("(" + str + ")"); + if (json.apiName !== undefined && json.warningMessage !== undefined) { + let data = json.apiName + "-" + json.warningMessage; + this.visible = true + return data + } + } + }, + getData(data) { if (data) { this.warnData = data diff --git a/ruoyi-ui/src/views/business/warning/apiwarning/index.vue b/ruoyi-ui/src/views/business/warning/apiwarning/index.vue index 8b25e49f..081d4c47 100644 --- a/ruoyi-ui/src/views/business/warning/apiwarning/index.vue +++ b/ruoyi-ui/src/views/business/warning/apiwarning/index.vue @@ -54,7 +54,7 @@ diff --git a/xjs-business/xjs-business-warning/src/main/java/com/xjs/controller/ApiWarningController.java b/xjs-business/xjs-business-warning/src/main/java/com/xjs/controller/ApiWarningController.java index 6c4ba9ab..8cf58d4f 100644 --- a/xjs-business/xjs-business-warning/src/main/java/com/xjs/controller/ApiWarningController.java +++ b/xjs-business/xjs-business-warning/src/main/java/com/xjs/controller/ApiWarningController.java @@ -25,6 +25,8 @@ import java.util.List; import java.util.Objects; import java.util.Set; +import static com.xjs.consts.ApiWarnHandleConst.NO; +import static com.xjs.consts.ApiWarnHandleConst.YES; import static com.xjs.consts.RedisConst.WEBSOCKET; /** @@ -75,6 +77,20 @@ public class ApiWarningController extends BaseController { return R.ok(apiRecords); } + /** + * 处理预警单个预警 + * @param id 预警id + * @return R + */ + @PutMapping("handle/{id}") + //@RequiresPermissions("warning:apiwarning:list") + public R handleWarning(@PathVariable("id") Long id) { + ApiWarning apiWarning = new ApiWarning(); + apiWarning.setId(id); + apiWarning.setHandle(YES); + return apiWarningService.updateById(apiWarning)?R.ok():R.fail(); + } + /** * 远程保存api预警信息并websocket推送 * @@ -95,10 +111,12 @@ public class ApiWarningController extends BaseController { * websocket推送 */ private void websocketPush(ApiWarning apiWarning) { - long count = apiWarningService.count(); + long count = apiWarningService.count(new QueryWrapper().eq("handle",NO)); Set cacheSet = redisService.getCacheSet(WEBSOCKET); JSONObject jsonData =new JSONObject(); JSONObject jsonObject = (JSONObject) JSONObject.toJSON(apiWarning); + //把id设置成字符串防止前端精度丢失 + jsonObject.put("id", apiWarning.getId().toString()); jsonData.put("count", count); jsonData.put("data", jsonObject.toJSONString()); jsonData.put("socketType", "apiWarning"); diff --git a/xjs-business/xjs-business-warning/src/main/java/com/xjs/server/WebSocketServer.java b/xjs-business/xjs-business-warning/src/main/java/com/xjs/server/WebSocketServer.java index 3506644c..efc47439 100644 --- a/xjs-business/xjs-business-warning/src/main/java/com/xjs/server/WebSocketServer.java +++ b/xjs-business/xjs-business-warning/src/main/java/com/xjs/server/WebSocketServer.java @@ -1,7 +1,9 @@ package com.xjs.server; import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.ruoyi.common.redis.service.RedisService; +import com.xjs.domain.ApiWarning; import com.xjs.service.ApiWarningService; import lombok.extern.log4j.Log4j2; import org.apache.commons.lang3.StringUtils; @@ -16,6 +18,7 @@ import java.util.HashSet; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import static com.xjs.consts.ApiWarnHandleConst.NO; import static com.xjs.consts.RedisConst.WEBSOCKET; /** @@ -84,7 +87,7 @@ public class WebSocketServer { set.add(userId); redisService.setCacheSet(WEBSOCKET, set); - long count = apiWarningService.count(); + long count = apiWarningService.count(new QueryWrapper().eq("handle",NO)); JSONObject jsonData =new JSONObject(); jsonData.put("count", count); jsonData.put("socketType", "apiWarning");