说明:1、实现api预警前端页面

pull/254/head
xjs 4 years ago
parent 093ca22344
commit 1ae208b8e1

@ -1,7 +1,7 @@
import request from '@/utils/request'
// 查询API预警列表
export function listApiwarning(query) {
// 查询API预警信息列表
export function listApiwarningInfo(query) {
return request({
url: '/warning/apiwarning/list',
method: 'get',
@ -9,16 +9,16 @@ export function listApiwarning(query) {
})
}
// 查询API预警详细
export function getApiwarning(id) {
// 查询API预警详细信息
export function getApiwarningInfo(id) {
return request({
url: '/warning/apiwarning/' + id,
method: 'get'
})
}
// 修改API预警
export function updateApiwarning(data) {
// 修改API预警信息
export function updateApiwarningInfo(data) {
return request({
url: '/warning/apiwarning/edit',
method: 'put',
@ -26,3 +26,12 @@ export function updateApiwarning(data) {
})
}
// 查询API预警列表
export function listApiwarning(query) {
return request({
url: '/warning/apiwarning/apiwarnlist',
method: 'get',
params: query
})
}

@ -17,18 +17,6 @@
</el-form>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button
type="success"
plain
icon="el-icon-edit"
size="mini"
:disabled="single"
@click="handleUpdate"
v-hasPermi="['warning:apiwarning:edit']"
>修改
</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="warning"
@ -36,40 +24,38 @@
icon="el-icon-download"
size="mini"
@click="handleExport"
v-hasPermi="['warning:apiwarning:export']"
v-hasPermi="['warning:warning:export']"
>导出
</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<el-table v-loading="loading" :data="apiwarningList" @selection-change="handleSelectionChange">
<el-table v-loading="loading" :data="warningList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center"/>
<el-table-column label="API名称" align="center" prop="apiName" :show-overflow-tooltip="true"/>
<el-table-column label="API地址" align="center" prop="apiUrl" :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="api名称" align="center" prop="apiName" width="200px"/>
<el-table-column label="预警类型" align="center" prop="warningType" width="100px"/>
<el-table-column label="预警等级" align="center" prop="warningLevel" width="130px">
<template slot-scope="scope">
<span>{{scope.row.requestTime+"ms"}}</span>
<el-tag type="info" v-if="scope.row.warningLevel==='普通'">
{{ scope.row.warningLevel }}
</el-tag>
<el-tag type="warning" v-if="scope.row.warningLevel==='警告'">
{{ scope.row.warningLevel }}
</el-tag>
<el-tag type="danger" v-if="scope.row.warningLevel==='严重'">
{{ scope.row.warningLevel }}
</el-tag>
</template>
</el-table-column>
<el-table-column label="API每天限制请求次数" 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">
<template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
</template>
</el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<el-table-column label="预警记录信息" align="center" prop="warningMessage" :show-overflow-tooltip="true"/>
<el-table-column label="限定值" align="center" prop="limitValue" width="100px"/>
<el-table-column label="实际值" align="center" prop="realValue" width="100px"/>
<el-table-column label="是否处理" align="center" prop="handle" width="100px">
<template slot-scope="scope">
<el-button circle
type="primary"
icon="el-icon-edit"
@click="handleUpdate(scope.row)"
v-hasPermi="['warning:apiwarning:edit']"
></el-button>
<el-tag :type="scope.row.handle==='1'?'success':'danger'" size="small">
{{ scope.row.handle === 1 ? '是' : '否' }}
</el-tag>
</template>
</el-table-column>
</el-table>
@ -82,26 +68,14 @@
@pagination="getList"
/>
<!-- 添加或修改API预警对话框 -->
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
<el-form-item label="请求次数" prop="limitCount">
<el-input v-model="form.limitCount" placeholder="请输入api限制请求次数每天"/>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm"> </el-button>
<el-button @click="cancel"> </el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import {listApiwarning, getApiwarning, updateApiwarning} from "@/api/business/warning/apiwarning";
import {listApiwarning} from "@/api/business/warning/apiwarning";
export default {
name: "Apiwarning",
name: "Warning",
data() {
return {
//
@ -116,8 +90,8 @@ export default {
showSearch: true,
//
total: 0,
// API
apiwarningList: [],
// api
warningList: [],
//
title: "",
//
@ -138,11 +112,11 @@ export default {
this.getList();
},
methods: {
/** 查询API预警列表 */
/** 查询api预警列表 */
getList() {
this.loading = true;
listApiwarning(this.queryParams).then(response => {
this.apiwarningList = response.rows;
this.warningList = response.rows;
this.total = response.total;
this.loading = false;
});
@ -157,13 +131,13 @@ export default {
this.form = {
id: null,
apiName: null,
apiUrl: null,
totalCount: null,
requestTime: null,
limitCount: null,
createTime: null,
dayCount: null,
updateTime: null
warningType: null,
warningLevel: null,
warningMessage: null,
limitValue: null,
realValue: null,
handle: null,
createTime: null
};
this.resetForm("form");
},
@ -183,36 +157,13 @@ export default {
this.single = selection.length !== 1
this.multiple = !selection.length
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const id = row.id || this.ids
getApiwarning(id).then(response => {
this.form = response.data;
this.open = true;
this.title = "修改API预警";
});
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate(valid => {
if (valid) {
if (this.form.id != null) {
updateApiwarning(this.form).then(response => {
this.$modal.msgSuccess("修改成功");
this.open = false;
this.getList();
});
}
}
});
},
/** 导出按钮操作 */
handleExport() {
this.download('warning/apiwarning/export', {
this.download('warning/apiwarning/apiwarnexport', {
...this.queryParams
}, `apiwarning_${new Date().getTime()}.xlsx`)
}, `warning_${new Date().getTime()}.xlsx`)
}
}
};

@ -0,0 +1,219 @@
<template>
<div class="app-container">
<el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
<el-form-item label="api名称" prop="apiName">
<el-input
v-model="queryParams.apiName"
placeholder="请输入api名称"
clearable
size="small"
@keyup.enter.native="handleQuery"
/>
</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>
</el-form-item>
</el-form>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button
type="success"
plain
icon="el-icon-edit"
size="mini"
:disabled="single"
@click="handleUpdate"
v-hasPermi="['warning:apiwarning:edit']"
>修改
</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="warning"
plain
icon="el-icon-download"
size="mini"
@click="handleExport"
v-hasPermi="['warning:apiwarning:export']"
>导出
</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<el-table v-loading="loading" :data="apiwarningList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center"/>
<el-table-column label="API名称" align="center" prop="apiName" :show-overflow-tooltip="true"/>
<el-table-column label="API地址" align="center" prop="apiUrl" :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">
<template slot-scope="scope">
<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="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">
<template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
</template>
</el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope">
<el-button circle
type="primary"
icon="el-icon-edit"
@click="handleUpdate(scope.row)"
v-hasPermi="['warning:apiwarning:edit']"
></el-button>
</template>
</el-table-column>
</el-table>
<pagination
v-show="total>0"
:total="total"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
<!-- 添加或修改API预警对话框 -->
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
<el-form-item label="请求次数" prop="limitCount">
<el-input v-model="form.limitCount" placeholder="请输入api限制请求次数每天"/>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm"> </el-button>
<el-button @click="cancel"> </el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import { getApiwarningInfo, updateApiwarningInfo,listApiwarningInfo} from "@/api/business/warning/apiwarning";
export default {
name: "Apiwarning",
data() {
return {
//
loading: true,
//
ids: [],
//
single: true,
//
multiple: true,
//
showSearch: true,
//
total: 0,
// API
apiwarningList: [],
//
title: "",
//
open: false,
//
queryParams: {
pageNum: 1,
pageSize: 10,
apiName: null,
},
//
form: {},
//
rules: {}
};
},
created() {
this.getList();
},
methods: {
/** 查询API预警列表 */
getList() {
this.loading = true;
listApiwarningInfo(this.queryParams).then(response => {
this.apiwarningList = response.rows;
this.total = response.total;
this.loading = false;
});
},
//
cancel() {
this.open = false;
this.reset();
},
//
reset() {
this.form = {
id: null,
apiName: null,
apiUrl: null,
totalCount: null,
requestTime: null,
limitCount: null,
createTime: null,
dayCount: null,
updateTime: null
};
this.resetForm("form");
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
//
handleSelectionChange(selection) {
this.ids = selection.map(item => item.id)
this.single = selection.length !== 1
this.multiple = !selection.length
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const id = row.id || this.ids
getApiwarningInfo(id).then(response => {
this.form = response.data;
this.open = true;
this.title = "修改API预警";
});
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate(valid => {
if (valid) {
if (this.form.id != null) {
updateApiwarningInfo(this.form).then(response => {
this.$modal.msgSuccess("修改成功");
this.open = false;
this.getList();
});
}
}
});
},
/** 导出按钮操作 */
handleExport() {
this.download('warning/apiwarning/export', {
...this.queryParams
}, `apiwarning_${new Date().getTime()}.xlsx`)
}
}
};
</script>

@ -11,7 +11,10 @@ import com.fasterxml.jackson.annotation.JsonValue;
public enum StatusEnum {
SUCCESS(1,"成功"),
ERROR(2,"失败");
ERROR(2,"失败"),
YES(1,"是"),
NO(2,"否");
private String desc;

@ -178,7 +178,8 @@ public class ApiLogAspect {
apiWarning.setApiName(haveApiRecord.getApiName());
apiWarning.setHandle(NO);
apiWarning.setWarningLevel(WarnLevelEnum.NOEMAL.getMessage());
if(haveApiRecord.getDayCount()>haveApiRecord.getLimitCount()*2){
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());
@ -188,6 +189,8 @@ public class ApiLogAspect {
haveApiRecord.getLimitCount(), haveApiRecord.getDayCount());
apiWarning.setWarningMessage(message);
remoteWarningCRUDFeign.saveApiWarningForRPC(apiWarning);
// todo websocket实现即时推送到客户端
}
}

@ -72,7 +72,7 @@
api_copywriting
WHERE
content IN ( SELECT t.content FROM ( SELECT content FROM api_copywriting GROUP BY content HAVING count( content ) > 1 ) t )
AND id NOT IN ( SELECT c.id FROM ( SELECT max( id ) id FROM api_copywriting GROUP BY content HAVING count( content )> 1 ) c )
AND id NOT IN ( SELECT c.id FROM ( SELECT min( id ) id FROM api_copywriting GROUP BY content HAVING count( content )> 1 ) c )
</delete>

@ -2,14 +2,18 @@ package com.xjs.oneenglish.factory;
import com.xjs.XjsOpenApiApp;
import com.xjs.config.TianXingProperties;
import com.xjs.copywriting.domain.CopyWriting;
import com.xjs.copywriting.mapper.CopyWritingMapper;
import com.xjs.copywriting.service.CopyWritingService;
import com.xjs.oneenglish.domain.ApiEnglish;
import com.xjs.oneenglish.domain.RequestBody;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import static org.junit.jupiter.api.Assertions.*;
/**
* @author xiejs
* @desc
@ -24,6 +28,11 @@ class TianXingOneEnglishFactoryTest {
@Autowired
TianXingProperties tianXingProperties;
@Autowired
private CopyWritingService copyWritingService;
@Autowired
private SqlSessionFactory sqlSessionFactory;
@Test
void getOneEnglish() {
RequestBody requestBody = new RequestBody();
@ -31,4 +40,46 @@ class TianXingOneEnglishFactoryTest {
ApiEnglish oneEnglish = tianXingOneEnglishFactory.getOneEnglish(requestBody);
System.out.println(oneEnglish);
}
@Test
void insert() {
/*CopyWriting copyWriting = new CopyWriting();
copyWriting.setSource("xx");
copyWriting.setContent("既然看不到早上的夕阳,那就追求傍晚到日落。");
copyWriting.setType(1);
for (int i = 0; i < 100000; i++) {
copyWritingService.save(copyWriting);
}*/
/*ArrayList<CopyWriting> copyWritings = new ArrayList<>();
for (int i = 0; i < 100000; i++) {
CopyWriting copyWriting = new CopyWriting();
copyWriting.setSource("xx");
copyWriting.setContent("既然看不到早上的夕阳,那就追求傍晚到日落。");
copyWriting.setType(1);
copyWritings.add(copyWriting);
}
copyWritingService.saveBatch(copyWritings,30000);*/
SqlSession sqlSession=null;
try {
sqlSession= sqlSessionFactory.openSession(ExecutorType.BATCH);
CopyWritingMapper mapper = sqlSession.getMapper(CopyWritingMapper.class);
CopyWriting copyWriting = new CopyWriting();
copyWriting.setSource("xx");
copyWriting.setContent("既然看不到早上的夕阳,那就追求傍晚到日落。");
copyWriting.setType(1);
for (int i = 0; i < 100000; i++) {
mapper.insert(copyWriting);
}
sqlSession.commit();
} finally {
sqlSession.close();
}
}
}

@ -1,5 +1,6 @@
package com.xjs.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
@ -16,6 +17,7 @@ import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Objects;
/**
* @author xiejs
@ -30,7 +32,7 @@ public class ApiWarningController extends BaseController {
private ApiWarningService apiWarningService;
/**
* apiRecord
* apiRecord
*
* @param apiRecord api
* @return apiRecord
@ -41,7 +43,7 @@ public class ApiWarningController extends BaseController {
}
/**
*
*
*
* @param apiRecord api
* @return ApiRecord
@ -53,6 +55,7 @@ public class ApiWarningController extends BaseController {
/**
* api
*
* @param apiRecord
* @return R<List < ApiRecord>>
*/
@ -64,6 +67,7 @@ public class ApiWarningController extends BaseController {
/**
* api
*
* @param apiWarning
* @return R
*/
@ -74,50 +78,74 @@ public class ApiWarningController extends BaseController {
}
/**
* api
*/
@RequiresPermissions("warning:warning:list")
@GetMapping("/apiwarnlist")
public TableDataInfo list(ApiWarning apiWarning) {
startPage();
List<ApiWarning> list = apiWarningService.list(new QueryWrapper<ApiWarning>()
.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")
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预警数据");
}
//-------------------------代码生成------------------------------------
/**
* API
* API
*/
@RequiresPermissions("warning:apiwarning:list")
@GetMapping("/list")
public TableDataInfo list(ApiRecord apiRecord)
{
public TableDataInfo list(ApiRecord apiRecord) {
startPage();
List<ApiRecord> list = apiWarningService.selectApiRecordList(apiRecord);
return getDataTable(list);
}
/**
* API
* API
*/
@RequiresPermissions("warning:apiwarning:export")
@Log(title = "API预警", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, ApiRecord apiRecord)
{
public void export(HttpServletResponse response, ApiRecord apiRecord) {
List<ApiRecord> list = apiWarningService.selectApiRecordList(apiRecord);
ExcelUtil<ApiRecord> util = new ExcelUtil<ApiRecord>(ApiRecord.class);
util.exportExcel(response, list, "API预警数据");
}
/**
* API
* API
*/
@RequiresPermissions("warning:apiwarning:query")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id)
{
public AjaxResult getInfo(@PathVariable("id") Long id) {
return AjaxResult.success(apiWarningService.selectApiRecordById(id));
}
/**
* API
* API
*/
@RequiresPermissions("warning:apiwarning:edit")
@Log(title = "API预警", businessType = BusinessType.UPDATE)
@PutMapping("edit")
public AjaxResult edit(@RequestBody ApiRecord apiRecord)
{
public AjaxResult edit(@RequestBody ApiRecord apiRecord) {
return toAjax(apiWarningService.updateApiRecord(apiRecord));
}

Loading…
Cancel
Save