2021-12-31 22:58:34 +08:00
|
|
|
package com.xjs.controller;
|
|
|
|
|
|
2022-01-14 22:48:40 +08:00
|
|
|
import com.alibaba.fastjson.JSONObject;
|
2022-01-07 17:17:59 +08:00
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
2021-12-31 22:58:34 +08:00
|
|
|
import com.ruoyi.common.core.domain.R;
|
2022-01-01 22:31:22 +08:00
|
|
|
import com.ruoyi.common.core.utils.poi.ExcelUtil;
|
2021-12-31 22:58:34 +08:00
|
|
|
import com.ruoyi.common.core.web.controller.BaseController;
|
2022-01-01 22:31:22 +08:00
|
|
|
import com.ruoyi.common.core.web.domain.AjaxResult;
|
|
|
|
|
import com.ruoyi.common.core.web.page.TableDataInfo;
|
|
|
|
|
import com.ruoyi.common.log.annotation.Log;
|
|
|
|
|
import com.ruoyi.common.log.enums.BusinessType;
|
2022-01-14 22:48:40 +08:00
|
|
|
import com.ruoyi.common.redis.service.RedisService;
|
2022-01-01 22:31:22 +08:00
|
|
|
import com.ruoyi.common.security.annotation.RequiresPermissions;
|
2021-12-31 22:58:34 +08:00
|
|
|
import com.xjs.domain.ApiRecord;
|
2022-01-07 11:04:20 +08:00
|
|
|
import com.xjs.domain.ApiWarning;
|
2022-01-14 22:48:40 +08:00
|
|
|
import com.xjs.server.WebSocketServer;
|
2021-12-31 22:58:34 +08:00
|
|
|
import com.xjs.service.ApiWarningService;
|
2022-01-15 11:03:29 +08:00
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
2021-12-31 22:58:34 +08:00
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2022-01-14 22:48:40 +08:00
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
2021-12-31 22:58:34 +08:00
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
2022-01-01 22:31:22 +08:00
|
|
|
import javax.servlet.http.HttpServletResponse;
|
2022-01-14 22:48:40 +08:00
|
|
|
import java.io.IOException;
|
2022-01-15 14:24:02 +08:00
|
|
|
import java.util.*;
|
2022-01-14 22:48:40 +08:00
|
|
|
|
2022-01-15 00:45:00 +08:00
|
|
|
import static com.xjs.consts.ApiWarnHandleConst.NO;
|
|
|
|
|
import static com.xjs.consts.ApiWarnHandleConst.YES;
|
2022-01-14 22:48:40 +08:00
|
|
|
import static com.xjs.consts.RedisConst.WEBSOCKET;
|
2022-01-01 17:15:13 +08:00
|
|
|
|
2021-12-31 22:58:34 +08:00
|
|
|
/**
|
|
|
|
|
* @author xiejs
|
2022-01-01 17:15:13 +08:00
|
|
|
* @desc api预警控制器
|
2021-12-31 22:58:34 +08:00
|
|
|
* @create 2021-12-31
|
|
|
|
|
*/
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("apiwarning")
|
2022-01-15 11:03:29 +08:00
|
|
|
@Api(tags = "业务模块-预警管理")
|
2021-12-31 22:58:34 +08:00
|
|
|
public class ApiWarningController extends BaseController {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ApiWarningService apiWarningService;
|
2022-01-14 22:48:40 +08:00
|
|
|
@Autowired
|
|
|
|
|
private RedisService redisService;
|
2021-12-31 22:58:34 +08:00
|
|
|
|
|
|
|
|
/**
|
2022-01-07 17:17:59 +08:00
|
|
|
* 远程保存 apiRecord
|
2022-01-01 17:15:13 +08:00
|
|
|
*
|
2021-12-31 22:58:34 +08:00
|
|
|
* @param apiRecord api记录
|
|
|
|
|
* @return apiRecord
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping
|
2022-01-15 11:03:29 +08:00
|
|
|
@ApiOperation("远程保存预警信息")
|
2022-01-01 18:43:24 +08:00
|
|
|
public R<ApiRecord> saveApiRecordForRPC(@RequestBody ApiRecord apiRecord) {
|
2021-12-31 22:58:34 +08:00
|
|
|
return apiWarningService.saveApiRecord(apiRecord) ? R.ok() : R.fail();
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-01 17:15:13 +08:00
|
|
|
/**
|
2022-01-07 17:17:59 +08:00
|
|
|
* 远程修改
|
2022-01-01 17:15:13 +08:00
|
|
|
*
|
|
|
|
|
* @param apiRecord api记录
|
|
|
|
|
* @return ApiRecord
|
|
|
|
|
*/
|
2021-12-31 22:58:34 +08:00
|
|
|
@PutMapping
|
2022-01-15 11:03:29 +08:00
|
|
|
@ApiOperation("远程修改预警信息")
|
2022-01-01 18:43:24 +08:00
|
|
|
public R<ApiRecord> updateApiRecordForRPC(@RequestBody ApiRecord apiRecord) {
|
2022-01-01 22:31:22 +08:00
|
|
|
return apiWarningService.updateApiRecordByUrl(apiRecord) ? R.ok() : R.fail();
|
2022-01-01 17:15:13 +08:00
|
|
|
}
|
|
|
|
|
|
2022-01-07 11:04:20 +08:00
|
|
|
/**
|
|
|
|
|
* 远程查询api记录信息
|
2022-01-07 17:17:59 +08:00
|
|
|
*
|
2022-01-07 11:04:20 +08:00
|
|
|
* @param apiRecord
|
2022-01-07 17:17:59 +08:00
|
|
|
* @return R<List < ApiRecord>>
|
2022-01-07 11:04:20 +08:00
|
|
|
*/
|
2022-01-01 17:15:13 +08:00
|
|
|
@GetMapping
|
2022-01-15 11:03:29 +08:00
|
|
|
@ApiOperation("远程查询预警信息")
|
2022-01-01 18:43:24 +08:00
|
|
|
public R<List<ApiRecord>> selectApiRecordListForRPC(ApiRecord apiRecord) {
|
2022-01-01 22:31:22 +08:00
|
|
|
List<ApiRecord> apiRecords = apiWarningService.selectApiRecordListByUrl(apiRecord);
|
2022-01-01 17:15:13 +08:00
|
|
|
return R.ok(apiRecords);
|
2021-12-31 22:58:34 +08:00
|
|
|
}
|
|
|
|
|
|
2022-01-15 00:45:00 +08:00
|
|
|
/**
|
|
|
|
|
* 处理预警单个预警
|
|
|
|
|
* @param id 预警id
|
|
|
|
|
* @return R
|
|
|
|
|
*/
|
|
|
|
|
@PutMapping("handle/{id}")
|
2022-01-15 11:03:29 +08:00
|
|
|
@RequiresPermissions("warning:warning:handle")
|
|
|
|
|
@ApiOperation("处理预警单个预警")
|
|
|
|
|
@Log(title = "处理单个预警")
|
2022-01-15 00:45:00 +08:00
|
|
|
public R<Object> handleWarning(@PathVariable("id") Long id) {
|
|
|
|
|
ApiWarning apiWarning = new ApiWarning();
|
|
|
|
|
apiWarning.setId(id);
|
|
|
|
|
apiWarning.setHandle(YES);
|
|
|
|
|
return apiWarningService.updateById(apiWarning)?R.ok():R.fail();
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-07 11:04:20 +08:00
|
|
|
/**
|
2022-01-14 22:48:40 +08:00
|
|
|
* 远程保存api预警信息并websocket推送
|
2022-01-07 17:17:59 +08:00
|
|
|
*
|
2022-01-07 11:04:20 +08:00
|
|
|
* @param apiWarning 预警实体类
|
2022-01-07 17:17:59 +08:00
|
|
|
* @return R
|
2022-01-07 11:04:20 +08:00
|
|
|
*/
|
|
|
|
|
@PostMapping("saveApiwarningForRPC")
|
2022-01-14 22:48:40 +08:00
|
|
|
@Transactional
|
2022-01-15 11:03:29 +08:00
|
|
|
@ApiOperation("远程保存api预警信息并websocket推送")
|
2022-01-07 11:04:20 +08:00
|
|
|
public R<ApiWarning> saveApiWarningForRPC(@RequestBody ApiWarning apiWarning) {
|
|
|
|
|
boolean save = apiWarningService.save(apiWarning);
|
2022-01-14 22:48:40 +08:00
|
|
|
|
|
|
|
|
this.websocketPush(apiWarning);
|
|
|
|
|
|
2022-01-07 17:17:59 +08:00
|
|
|
return save ? R.ok() : R.fail();
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-14 22:48:40 +08:00
|
|
|
/**
|
|
|
|
|
* websocket推送
|
|
|
|
|
*/
|
|
|
|
|
private void websocketPush(ApiWarning apiWarning) {
|
2022-01-15 00:45:00 +08:00
|
|
|
long count = apiWarningService.count(new QueryWrapper<ApiWarning>().eq("handle",NO));
|
2022-01-14 22:48:40 +08:00
|
|
|
Set<String> cacheSet = redisService.getCacheSet(WEBSOCKET);
|
|
|
|
|
JSONObject jsonData =new JSONObject();
|
|
|
|
|
JSONObject jsonObject = (JSONObject) JSONObject.toJSON(apiWarning);
|
2022-01-15 00:45:00 +08:00
|
|
|
//把id设置成字符串防止前端精度丢失
|
|
|
|
|
jsonObject.put("id", apiWarning.getId().toString());
|
2022-01-14 22:48:40 +08:00
|
|
|
jsonData.put("count", count);
|
|
|
|
|
jsonData.put("data", jsonObject.toJSONString());
|
|
|
|
|
jsonData.put("socketType", "apiWarning");
|
|
|
|
|
for (String userId : cacheSet) {
|
|
|
|
|
try {
|
|
|
|
|
WebSocketServer.sendInfo(jsonData.toString(),userId);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
logger.error(e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-07 17:17:59 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询api预警列表
|
|
|
|
|
*/
|
|
|
|
|
@RequiresPermissions("warning:warning:list")
|
|
|
|
|
@GetMapping("/apiwarnlist")
|
2022-01-15 11:03:29 +08:00
|
|
|
@ApiOperation("查询api预警列表")
|
2022-01-07 17:17:59 +08:00
|
|
|
public TableDataInfo list(ApiWarning apiWarning) {
|
|
|
|
|
startPage();
|
|
|
|
|
List<ApiWarning> list = apiWarningService.list(new QueryWrapper<ApiWarning>()
|
2022-01-08 00:22:51 +08:00
|
|
|
.orderByDesc("create_time")
|
2022-01-07 17:17:59 +08:00
|
|
|
.like(Objects.nonNull(apiWarning.getApiName()),"api_name", apiWarning.getApiName()));
|
|
|
|
|
return getDataTable(list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 导出api预警列表
|
|
|
|
|
*/
|
|
|
|
|
@RequiresPermissions("warning:warning:export")
|
|
|
|
|
@Log(title = "api预警", businessType = BusinessType.EXPORT)
|
|
|
|
|
@PostMapping("/apiwarnexport")
|
2022-01-15 11:03:29 +08:00
|
|
|
@ApiOperation("导出api预警列表")
|
2022-01-07 17:17:59 +08:00
|
|
|
public void export(HttpServletResponse response, ApiWarning apiWarning) {
|
|
|
|
|
List<ApiWarning> list = apiWarningService.list(new QueryWrapper<ApiWarning>()
|
|
|
|
|
.like(Objects.nonNull(apiWarning.getApiName()),"api_name", apiWarning.getApiName()));
|
|
|
|
|
ExcelUtil<ApiWarning> util = new ExcelUtil<ApiWarning>(ApiWarning.class);
|
|
|
|
|
util.exportExcel(response, list, "api预警数据");
|
2022-01-07 11:04:20 +08:00
|
|
|
}
|
|
|
|
|
|
2022-01-15 11:51:37 +08:00
|
|
|
@RequiresPermissions("warning:warning:remove")
|
|
|
|
|
@Log(title = "api预警", businessType = BusinessType.DELETE)
|
|
|
|
|
@DeleteMapping("all")
|
|
|
|
|
@ApiOperation("清空已处理api预警列表")
|
|
|
|
|
public R<Object> clearAll() {
|
|
|
|
|
Integer integer = apiWarningService.clearAll();
|
|
|
|
|
return integer > 0 ? R.ok(integer) : R.fail();
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-15 14:24:02 +08:00
|
|
|
@RequiresPermissions("warning:warning:handleAll")
|
|
|
|
|
@PutMapping("handleAll")
|
|
|
|
|
@ApiOperation("全部标记已读")
|
|
|
|
|
@Log(title = "全部标记已读")
|
|
|
|
|
public R<Object> AllHaveRead() {
|
|
|
|
|
Integer integer = apiWarningService.AllHaveRead();
|
|
|
|
|
return integer > 0 ? R.ok(integer) : R.fail();
|
|
|
|
|
}
|
2022-01-15 11:51:37 +08:00
|
|
|
|
2022-01-01 22:31:22 +08:00
|
|
|
|
|
|
|
|
//-------------------------代码生成------------------------------------
|
2022-01-07 17:17:59 +08:00
|
|
|
|
|
|
|
|
|
2022-01-01 22:31:22 +08:00
|
|
|
/**
|
2022-01-07 17:17:59 +08:00
|
|
|
* 查询API预警信息列表
|
2022-01-01 22:31:22 +08:00
|
|
|
*/
|
|
|
|
|
@RequiresPermissions("warning:apiwarning:list")
|
|
|
|
|
@GetMapping("/list")
|
2022-01-15 11:03:29 +08:00
|
|
|
@ApiOperation("查询API预警信息列表")
|
2022-01-07 17:17:59 +08:00
|
|
|
public TableDataInfo list(ApiRecord apiRecord) {
|
2022-01-01 22:31:22 +08:00
|
|
|
startPage();
|
|
|
|
|
List<ApiRecord> list = apiWarningService.selectApiRecordList(apiRecord);
|
|
|
|
|
return getDataTable(list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2022-01-07 17:17:59 +08:00
|
|
|
* 导出API预警信息列表
|
2022-01-01 22:31:22 +08:00
|
|
|
*/
|
|
|
|
|
@RequiresPermissions("warning:apiwarning:export")
|
|
|
|
|
@Log(title = "API预警", businessType = BusinessType.EXPORT)
|
|
|
|
|
@PostMapping("/export")
|
2022-01-15 11:03:29 +08:00
|
|
|
@ApiOperation("导出API预警信息列表")
|
2022-01-07 17:17:59 +08:00
|
|
|
public void export(HttpServletResponse response, ApiRecord apiRecord) {
|
2022-01-01 22:31:22 +08:00
|
|
|
List<ApiRecord> list = apiWarningService.selectApiRecordList(apiRecord);
|
|
|
|
|
ExcelUtil<ApiRecord> util = new ExcelUtil<ApiRecord>(ApiRecord.class);
|
|
|
|
|
util.exportExcel(response, list, "API预警数据");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2022-01-07 17:17:59 +08:00
|
|
|
* 获取API预警详细信息信息
|
2022-01-01 22:31:22 +08:00
|
|
|
*/
|
|
|
|
|
@RequiresPermissions("warning:apiwarning:query")
|
|
|
|
|
@GetMapping(value = "/{id}")
|
2022-01-15 11:03:29 +08:00
|
|
|
@ApiOperation("获取API预警详细信息信息")
|
2022-01-07 17:17:59 +08:00
|
|
|
public AjaxResult getInfo(@PathVariable("id") Long id) {
|
2022-01-01 22:31:22 +08:00
|
|
|
return AjaxResult.success(apiWarningService.selectApiRecordById(id));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2022-01-07 17:17:59 +08:00
|
|
|
* 修改API预警信息
|
2022-01-01 22:31:22 +08:00
|
|
|
*/
|
|
|
|
|
@RequiresPermissions("warning:apiwarning:edit")
|
|
|
|
|
@Log(title = "API预警", businessType = BusinessType.UPDATE)
|
|
|
|
|
@PutMapping("edit")
|
2022-01-15 11:03:29 +08:00
|
|
|
@ApiOperation("修改API预警信息")
|
2022-01-07 17:17:59 +08:00
|
|
|
public AjaxResult edit(@RequestBody ApiRecord apiRecord) {
|
2022-01-01 22:31:22 +08:00
|
|
|
return toAjax(apiWarningService.updateApiRecord(apiRecord));
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-31 22:58:34 +08:00
|
|
|
}
|