添加安全组页面和安全规则页面

This commit is contained in:
=
2023-12-06 17:22:14 +08:00
parent 90623b9146
commit 781b14861c
8 changed files with 787 additions and 6 deletions
@@ -0,0 +1,97 @@
import request from '@/utils/request'
const baseUri = '/security';
export function fetchGroupList() {
return request({
url: `${baseUri}/group/s`,
method: 'get'
})
}
export function fetchGroupOne(groupId) {
return request({
url: `${baseUri}/group/getOne?groupId=${groupId}`,
method: 'get'
})
}
export function createGroup(data) {
return request({
url: `${baseUri}/group/create`,
method: 'post',
data
})
}
export function updateGroup(data) {
return request({
url: `${baseUri}/group/update`,
method: 'post',
data
})
}
export function deleteGroup(groupId) {
return request({
url: `${baseUri}/group/delete?groupId=${groupId}`,
method: 'post'
})
}
export function enableGroup(groupId) {
return request({
url: `${baseUri}/group/enable?groupId=${groupId}`,
method: 'post'
})
}
export function disableGroup(groupId) {
return request({
url: `${baseUri}/group/disable?groupId=${groupId}`,
method: 'post'
})
}
export function fetchRuleList(groupId) {
return request({
url: `${baseUri}/rule/s?groupId=${groupId}`,
method: 'get'
})
}
export function createRule(data) {
return request({
url: `${baseUri}/rule/create`,
method: 'post',
data
})
}
export function updateRule(data) {
return request({
url: `${baseUri}/rule/update`,
method: 'post',
data
})
}
export function deleteRule(ruleId) {
return request({
url: `${baseUri}/rule/delete?ruleId=${ruleId}`,
method: 'post'
})
}
export function enableRule(ruleId) {
return request({
url: `${baseUri}/rule/enable?ruleId=${ruleId}`,
method: 'post'
})
}
export function disableRule(ruleId) {
return request({
url: `${baseUri}/rule/disable?ruleId=${ruleId}`,
method: 'post'
})
}
+14 -1
View File
@@ -48,6 +48,8 @@ export default {
user: '用户管理',
system: '系统管理',
portPool: '端口池管理',
securityGroup: '安全组管理',
securityRule: '安全规则管理',
portGroup: '端口分组管理',
protocal: '协议管理',
proxy: '代理配置',
@@ -128,6 +130,7 @@ export default {
confirm: '确 定',
userId: '用户ID',
userName: '用户名',
name: '名称',
group: '分组',
groupName: '分组名称',
groupPossessor: '分组所属',
@@ -169,7 +172,17 @@ export default {
totalFlow: '总流量',
protocalName: '协议',
supportStatus: '支持状态',
domainName: '域名'
domainName: '域名',
defaultPassType: '默认放行类型',
ruleName: '规则名称',
rule: '规则内容',
passType: '放行类型',
priority: '优先级',
ruleConfig: '规则配置',
portMappingBindSecurityGroup: '绑定安全组',
securityGroupBindPortMapping: '绑定端口映射',
bind: '绑定',
unbind: '解绑'
},
button: {
lookOver: '查看'
+2
View File
@@ -77,6 +77,8 @@ export const asyncRouterMap = [
{ path: 'user', component: _import('system/user'), name: 'user', meta: { title: 'user' }},
{ path: 'portGroup', component: _import('system/portGroup'), name: 'portGroup', meta: { title: 'portGroup' }},
{ path: 'portPool', component: _import('system/portPool'), name: 'portPool', meta: { title: 'portPool' }},
{ path: 'securityGroup', component: _import('system/securityGroup'), name: 'securityGroup', meta: { title: 'securityGroup' }},
{ path: 'securityRule', component: _import('system/securityRule'), name: 'securityRule', meta: { title: 'securityRule' }, hidden: true},
{ path: 'protocal', component: _import('system/protocal'), name: 'protocal', meta: { title: 'protocal' }},
{ path: 'jobManager', component: _import('system/jobManager'), name: 'jobManager', meta: { title: 'jobManager' }}
]
@@ -0,0 +1,310 @@
<template>
<div class="app-container calendar-list-container">
<div class="filter-container">
<el-button class="filter-item" style="margin-left: 10px;" @click="handleCreate" type="primary" icon="el-icon-edit">{{$t('table.add')}}</el-button>
</div>
<el-table :key='tableKey' :data="list" v-loading="listLoading" element-loading-text="给我一点时间" border fit highlight-current-row
style="width: 100%">
<!-- <el-table-column align="center" width="40" type="selection" /> -->
<el-table-column align="center" :label="$t('table.id')" width="60">
<template slot-scope="scope">
<span>{{scope.row.id}}</span>
</template>
</el-table-column>
<el-table-column align="center" :label="$t('table.name')">
<template slot-scope="scope">
<span>{{scope.row.name}}</span>
</template>
</el-table-column>
<el-table-column align="center" :label="$t('table.desc')">
<template slot-scope="scope">
<span>{{scope.row.description}}</span>
</template>
</el-table-column>
<el-table-column align="center" :label="$t('table.defaultPassType')">
<template slot-scope="scope">
<span>{{scope.row.defaultPassType}}</span>
</template>
</el-table-column>
<el-table-column align="center" :label="$t('table.createTime')">
<template slot-scope="scope">
<span>{{scope.row.createTime}}</span>
</template>
</el-table-column>
<el-table-column align="center" :label="$t('table.updateTime')">
<template slot-scope="scope">
<span>{{scope.row.updateTime}}</span>
</template>
</el-table-column>
<el-table-column class-name="status-col" :label="$t('table.enableStatus')" width="150">
<template slot-scope="scope">
<el-tag :type="scope.row.enable" v-if="scope.row.enable == '启用'">{{scope.row.enable}}</el-tag>
<el-tag :type="scope.row.disable" v-if="scope.row.enable == '禁用'">{{scope.row.enable}}</el-tag>
</template>
</el-table-column>
<el-table-column align="center" :label="$t('table.actions')" width="400" class-name="small-padding fixed-width">
<template slot-scope="scope">
<el-button type="primary" size="mini" @click="handleUpdate(scope.row)">{{$t('table.edit')}}</el-button>
<el-button v-if="scope.row.enable =='启用'" size="mini" type="warning" @click="handleDisableStatus(scope.row)">{{$t('table.disable')}}</el-button>
<el-button v-if="scope.row.enable =='禁用'" size="mini" type="success" @click="handleEnableStatus(scope.row)">{{$t('table.enable')}}</el-button>
<!-- <el-button v-if="scope.row.status!='deleted'" size="mini" type="danger" @click="handleDelete(scope.row,'deleted')">{{$t('table.delete')}}</el-button>-->
<ButtonPopover @handleCommitClick="handleDelete(scope.row)" style="margin-left: 10px"/>
<el-button type="primary" size="mini" @click="handleGoRulePage(scope.row)">{{$t('table.ruleConfig')}}</el-button>
<el-button type="primary" size="mini" @click="handlePortMapping(scope.row)">{{$t('table.securityGroupBindPortMapping')}}</el-button>
</template>
</el-table-column>
</el-table>
<el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible">
<el-form :rules="rules" ref="dataForm" :model="temp" label-position="right" label-width="200px" style='width: 500px; margin-left:50px;'>
<el-form-item :label="$t('table.name')" prop="name">
<el-input :placeholder="$t('table.name')" v-model="temp.name"></el-input>
</el-form-item>
<el-form-item :label="$t('table.desc')" prop="desc">
<el-input type="textarea" :autosize="{ minRows: 2, maxRows: 4}" :placeholder="$t('table.desc')" v-model="temp.description"></el-input>
</el-form-item>
<el-form-item :label="$t('table.defaultPassType')" prop="defaultPassType">
<el-select style="width: 300px" class="filter-item" v-model="temp.defaultPassType">
<el-option v-for="item in passTypeList" :key="item.key" :label="item.key" :value="item.value">
</el-option>
</el-select>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="dialogFormVisible = false">{{$t('table.cancel')}}</el-button>
<el-button v-if="dialogStatus=='create'" type="primary" @click="createData">{{$t('table.confirm')}}</el-button>
<el-button v-else type="primary" @click="updateData">{{$t('table.confirm')}}</el-button>
</div>
</el-dialog>
<el-dialog title="Reading statistics" :visible.sync="dialogPvVisible">
<el-table :data="pvData" border fit highlight-current-row style="width: 100%">
<el-table-column prop="key" label="Channel"> </el-table-column>
<el-table-column prop="pv" label="Pv"> </el-table-column>
</el-table>
<span slot="footer" class="dialog-footer">
<el-button type="primary" @click="dialogPvVisible = false">{{$t('table.confirm')}}</el-button>
</span>
</el-dialog>
<el-dialog :title="$t('table.securityGroupBindPortMapping')" :visible.sync="dialogBindPortMappingVisible">
<el-table :key='tableKey' :data="list" v-loading="listLoading" element-loading-text="给我一点时间" border fit highlight-current-row
style="width: 100%">
<el-table-column align="center" :label="$t('table.id')" width="60">
<template slot-scope="scope">
<span>{{scope.row.id}}</span>
</template>
</el-table-column>
<el-table-column align="center" :label="$t('table.name')">
<template slot-scope="scope">
<span>{{scope.row.name}}</span>
</template>
</el-table-column>
<el-table-column align="center" :label="$t('table.desc')">
<template slot-scope="scope">
<span>{{scope.row.description}}</span>
</template>
</el-table-column>
<el-table-column align="center" :label="$t('table.defaultPassType')">
<template slot-scope="scope">
<span>{{scope.row.defaultPassType}}</span>
</template>
</el-table-column>
<el-table-column align="center" :label="$t('table.actions')" width="200" class-name="small-padding fixed-width">
<template slot-scope="scope">
<el-button type="primary" size="mini" @click="handleBind(scope.row)">{{$t('table.bind')}}</el-button>
<el-button type="danger" size="mini" @click="handleUnbind(scope.row)">{{$t('table.unbind')}}</el-button>
</template>
</el-table-column>
</el-table>
</el-dialog>
</div>
</template>
<script>
import {fetchGroupList, createGroup, updateGroup, deleteGroup, enableGroup, disableGroup} from '@/api/securityGroup'
import waves from '@/directive/waves' // 水波纹指令
import { parseTime } from '@/utils'
import ButtonPopover from '../../components/Button/buttonPopover'
export default {
name: 'complexTable',
directives: {
waves
},
components: {
ButtonPopover
},
data() {
return {
tableKey: 0,
list: [],
listLoading: true,
temp: {
id: undefined,
name: '',
description: '',
defaultPassType: undefined
},
dialogFormVisible: false,
dialogStatus: '',
textMap: {
update: '编辑',
create: '新建'
},
passTypeList: [{key: 'allow', value: 1}, {key: 'deny', value: -1}],
dialogPvVisible: false,
pvData: [],
rules: {
name: [{ required: true, message: '安全组名称必填', trigger: 'blur' }],
defaultPassType: [{ required: true, message: '默认放行类型必选', trigger: 'blur' }]
},
downloadLoading: false,
checkBoxData:[], //表单勾选的行
dialogBindPortMappingVisible: false,
bindProtMappingSecurityGroup: {}
}
},
filters: {
statusName(status) {
const statusMap = {
1: '启用',
2: '禁用'
}
return statusMap[status]
},
statusFilter(status) {
const statusMap = {
1: 'success',
2: 'danger'
}
return statusMap[status]
},
typeFilter(type) {
return calendarTypeKeyValue[type]
}
},
created() {
// eslint-disable-next-line no-sequences
this.getList()
},
methods: {
getList() {
this.listLoading = true
fetchGroupList().then(response => {
this.list = response.data.data
this.listLoading = false
})
},
handleEnableStatus(row) {
enableGroup(row.id).then(response => {
if (response.data.code === 0) {
this.$message({
message: '操作成功',
type: 'success'
})
this.getList()
}
})
},
handleDisableStatus(row) {
disableGroup(row.id).then(response => {
if (response.data.code === 0) {
this.$message({
message: '操作成功',
type: 'success'
})
this.getList()
}
})
},
resetTemp() {
this.temp = {
id: undefined,
name: '',
description: '',
defaultPassType: undefined
}
},
handleCreate() {
this.resetTemp()
this.dialogStatus = 'create'
this.dialogFormVisible = true
this.$nextTick(() => {
this.$refs['dataForm'].clearValidate()
})
},
createData() {
this.$refs['dataForm'].validate((valid) => {
if (valid) {
createGroup(this.temp).then(response => {
if (response.data.code === 0) {
this.dialogFormVisible = false
this.$notify({
title: '成功',
message: '创建成功',
type: 'success',
duration: 2000
})
this.getList()
}
})
}
})
},
handleUpdate(row) {
this.temp = Object.assign({}, row) // copy obj
this.temp.timestamp = new Date(this.temp.timestamp)
this.dialogStatus = 'update'
this.dialogFormVisible = true
this.$nextTick(() => {
this.$refs['dataForm'].clearValidate()
})
},
updateData() {
this.$refs['dataForm'].validate((valid) => {
if (valid) {
const tempData = Object.assign({}, this.temp)
updateGroup(tempData).then(response => {
if (response.data.code === 0) {
this.$notify({
title: '成功',
message: '更新成功',
type: 'success',
duration: 2000
})
this.dialogFormVisible = false
this.getList()
}
})
}
})
},
handleDelete(row) {
deleteGroup(row.id).then(response => {
if (response.data.code === 0) {
this.$notify({
title: '成功',
message: '删除成功',
type: 'success',
duration: 2000
})
this.getList()
}
})
},
handleGoRulePage (row) {
this.$router.push(`/system/securityRule?groupId=${row.id}`)
},
handlePortMapping(row) {
this.dialogBindPortMappingVisible = true
this.bindProtMappingSecurityGroup = row
}
}
}
</script>
@@ -0,0 +1,349 @@
<template>
<div class="app-container calendar-list-container">
<div>
<div style="text-align: center;line-height:48px;font-size:24px">{{group.name}}安全组</div>
<div style="text-align: center;font-size:14px; color: #606266">{{group.description}}</div>
</div>
<div class="filter-container" align="right">
<el-button class="filter-item" @click="handleCreate" type="primary" icon="el-icon-edit">{{$t('table.add')}}</el-button>
</div>
<el-table :key='tableKey' :data="list" v-loading="listLoading" element-loading-text="给我一点时间" border fit highlight-current-row
style="width: 100%">
<!-- <el-table-column align="center" width="40" type="selection" /> -->
<el-table-column align="center" :label="$t('table.id')" width="60">
<template slot-scope="scope">
<span>{{scope.row.id}}</span>
</template>
</el-table-column>
<el-table-column align="center" :label="$t('table.ruleName')">
<template slot-scope="scope">
<span>{{scope.row.name}}</span>
</template>
</el-table-column>
<el-table-column align="center" :label="$t('table.desc')">
<template slot-scope="scope">
<span>{{scope.row.description}}</span>
</template>
</el-table-column>
<el-table-column align="center" :label="$t('table.rule')">
<template slot-scope="scope">
<span>{{scope.row.rule}}</span>
</template>
</el-table-column>
<el-table-column align="center" :label="$t('table.passType')">
<template slot-scope="scope">
<el-tag type="success" v-if="scope.row.passType == 'allow'" effect="dark">{{scope.row.passType}}</el-tag>
<el-tag type="info" v-if="scope.row.passType == 'deny'" effect="dark">{{scope.row.passType}}</el-tag>
</template>
</el-table-column>
<el-table-column align="center" :label="$t('table.priority')">
<template slot-scope="scope">
<span>{{scope.row.priority}}</span>
</template>
</el-table-column>
<el-table-column align="center" :label="$t('table.createTime')">
<template slot-scope="scope">
<span>{{scope.row.createTime}}</span>
</template>
</el-table-column>
<el-table-column align="center" :label="$t('table.updateTime')">
<template slot-scope="scope">
<span>{{scope.row.updateTime}}</span>
</template>
</el-table-column>
<el-table-column class-name="status-col" :label="$t('table.enableStatus')" width="150">
<template slot-scope="scope">
<el-tag type="success" v-if="scope.row.enable == '启用'">{{scope.row.enable}}</el-tag>
<el-tag type="warning" v-if="scope.row.enable == '禁用'">{{scope.row.enable}}</el-tag>
</template>
</el-table-column>
<el-table-column align="center" :label="$t('table.actions')" width="250" class-name="small-padding fixed-width">
<template slot-scope="scope">
<el-button type="primary" size="mini" @click="handleUpdate(scope.row)">{{$t('table.edit')}}</el-button>
<el-button v-if="scope.row.enable =='启用'" size="mini" type="warning" @click="handleDisableStatus(scope.row)">{{$t('table.disable')}}</el-button>
<el-button v-if="scope.row.enable =='禁用'" size="mini" type="success" @click="handleEnableStatus(scope.row)">{{$t('table.enable')}}</el-button>
<!-- <el-button v-if="scope.row.status!='deleted'" size="mini" type="danger" @click="handleDelete(scope.row,'deleted')">{{$t('table.delete')}}</el-button>-->
<ButtonPopover @handleCommitClick="handleDelete(scope.row)" style="margin-left: 10px"/>
</template>
</el-table-column>
</el-table>
<el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" top="4vh">
<el-form :rules="rules" ref="dataForm" :model="temp" label-position="right" label-width="100px" style='margin-left:50px;margin-right: 150px'>
<el-form-item :label="$t('table.name')" prop="name">
<el-input :placeholder="$t('table.name')" v-model="temp.name"></el-input>
</el-form-item>
<el-form-item :label="$t('table.desc')" prop="desc">
<el-input type="textarea" :autosize="{ minRows: 2, maxRows: 4}" :placeholder="$t('table.desc')" v-model="temp.description"></el-input>
</el-form-item>
<el-form-item :label="$t('table.rule')" prop="rule">
<el-input type="textarea" :autosize="{ minRows: 4, maxRows: 10}" :placeholder="$t('table.rule')" v-model="temp.rule"></el-input>
</el-form-item>
<el-form-item>
<div style="line-height: 28px; color: cornflowerblue">
<div>规则描述:</div>
<div>单个ip192.168.1.1,0:0:0:0:0:0:10.0.0.1, ipv6只支持单个ip判断</div>
<div>范围类型192.168.1.0-192.168.1.255</div>
<div>掩码类型192.168.1.0/24</div>
<div>泛型0.0.0.0/ALL</div>
<div>每个类型中间以英文逗号分隔,形如 192.168.1.1,192.168.3.0/24 是正确的 </div>
</div>
</el-form-item>
<el-form-item :label="$t('table.passType')" prop="passType">
<el-select class="filter-item" v-model="temp.passType">
<el-option v-for="item in passTypeList" :key="item.key" :label="item.key" :value="item.value">
</el-option>
</el-select>
</el-form-item>
<el-form-item :label="$t('table.priority')" prop="priority">
<el-input-number v-model="temp.priority" :min="1" :max="1000" :placeholder="$t('table.priority')"></el-input-number>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="dialogFormVisible = false">{{$t('table.cancel')}}</el-button>
<el-button v-if="dialogStatus=='create'" type="primary" @click="createData">{{$t('table.confirm')}}</el-button>
<el-button v-else type="primary" @click="updateData">{{$t('table.confirm')}}</el-button>
</div>
</el-dialog>
<el-dialog title="Reading statistics" :visible.sync="dialogPvVisible">
<el-table :data="pvData" border fit highlight-current-row style="width: 100%">
<el-table-column prop="key" label="Channel"> </el-table-column>
<el-table-column prop="pv" label="Pv"> </el-table-column>
</el-table>
<span slot="footer" class="dialog-footer">
<el-button type="primary" @click="dialogPvVisible = false">{{$t('table.confirm')}}</el-button>
</span>
</el-dialog>
</div>
</template>
<script>
import {fetchGroupOne, fetchRuleList, createRule, updateRule, deleteRule, enableRule, disableRule} from '@/api/securityGroup'
import waves from '@/directive/waves' // 水波纹指令
import { parseTime } from '@/utils'
import ButtonPopover from '../../components/Button/buttonPopover'
export default {
name: 'complexTable',
directives: {
waves
},
components: {
ButtonPopover
},
data() {
return {
groupId: 1,
group: {},
tableKey: 0,
list: [],
listLoading: true,
temp: {
id: undefined,
groupId: undefined,
name: '',
description: '',
rule: '',
passType: undefined,
priority: 1
},
dialogFormVisible: false,
dialogStatus: '',
textMap: {
update: '编辑',
create: '新建'
},
passTypeList: [{key: 'allow', value: 1}, {key: 'deny', value: 0}],
dialogPvVisible: false,
pvData: [],
rules: {
name: [{ required: true, message: '安全组名称必填', trigger: 'blur' }],
rule: [{ required: true, message: '规则内容必填', trigger: 'blur' }],
passType: [{ required: true, message: '放行类型必选', trigger: 'blur' }],
priority: [{ required: true, message: '优先级必填', trigger: 'blur' }]
},
downloadLoading: false,
checkBoxData:[], //表单勾选的行
}
},
filters: {
statusName(status) {
const statusMap = {
1: '启用',
2: '禁用'
}
return statusMap[status]
},
statusFilter(status) {
const statusMap = {
1: 'success',
2: 'danger'
}
return statusMap[status]
},
typeFilter(type) {
return calendarTypeKeyValue[type]
}
},
created() {
// eslint-disable-next-line no-sequences
const queryParam = this.$route.query
if (queryParam && typeof queryParam === 'object' && queryParam.groupId) {
this.groupId = queryParam.groupId
localStorage.setItem('groupId', this.groupId)
this.getGroupOne()
this.getList()
return
}
const groupId = localStorage.getItem('groupId')
if (groupId) {
this.groupId = parseInt(groupId)
this.getGroupOne()
this.getList()
return
}
this.$notify({
title: '错误',
message: '没有获取到安全组信息',
type: 'error',
duration: 3000
})
this.$router.push(`/system/securityGroup`)
},
methods: {
getGroupOne () {
fetchGroupOne(this.groupId).then(response => {
this.group = response.data.data
})
},
getList() {
if (!this.groupId) {
this.$notify({
title: '错误',
message: '没有获取到安全组信息',
type: 'error',
duration: 3000
})
return
}
this.listLoading = true
fetchRuleList(this.groupId).then(response => {
this.list = response.data.data
this.listLoading = false
})
},
handleEnableStatus(row) {
enableRule(row.id).then(response => {
if (response.data.code === 0) {
this.$message({
message: '操作成功',
type: 'success'
})
this.getList()
}
})
},
handleDisableStatus(row) {
disableRule(row.id).then(response => {
if (response.data.code === 0) {
this.$message({
message: '操作成功',
type: 'success'
})
this.getList()
}
})
},
resetTemp() {
this.temp = {
id: undefined,
name: '',
description: '',
defaultPassType: undefined
}
},
handleCreate() {
this.resetTemp()
this.dialogStatus = 'create'
this.dialogFormVisible = true
this.$nextTick(() => {
this.$refs['dataForm'].clearValidate()
})
},
createData() {
this.$refs['dataForm'].validate((valid) => {
if (valid) {
this.temp.groupId = this.groupId
createRule(this.temp).then(response => {
if (response.data.code === 0) {
this.dialogFormVisible = false
this.$notify({
title: '成功',
message: '创建成功',
type: 'success',
duration: 2000
})
this.getList()
}
})
}
})
},
handleUpdate(row) {
this.temp = Object.assign({}, row) // copy obj
this.temp.timestamp = new Date(this.temp.timestamp)
this.dialogStatus = 'update'
this.dialogFormVisible = true
this.$nextTick(() => {
this.$refs['dataForm'].clearValidate()
})
},
updateData() {
this.$refs['dataForm'].validate((valid) => {
if (valid) {
const tempData = Object.assign({}, this.temp)
tempData.groupId = this.groupId
updateRule(tempData).then(response => {
if (response.data.code === 0) {
this.$notify({
title: '成功',
message: '更新成功',
type: 'success',
duration: 2000
})
this.dialogFormVisible = false
this.getList()
}
})
}
})
},
handleDelete(row) {
deleteRule(row.id).then(response => {
if (response.data.code === 0) {
this.$notify({
title: '成功',
message: '删除成功',
type: 'success',
duration: 2000
})
this.getList()
}
})
}
}
}
</script>
@@ -6,9 +6,9 @@ import lombok.Getter;
@AllArgsConstructor
@Getter
public enum SecurityRulePassTypeEnum {
DENY(-1, "DENY"),
DENY(0, "deny"),
ALLOW(1, "allow"),
NONE(0, "none")
NONE(-1, "none")
;
private final Integer code;
@@ -36,6 +36,12 @@ public class SecurityController {
return groupDOList.stream().map(SecurityGroupDO::toRes).collect(Collectors.toList());
}
@Get
@Mapping("/group/getOne")
public SecurityGroupRes getGroupOne(Integer groupId) {
return groupService.queryGroupOne(groupId).toRes();
}
@Post
@Mapping("/group/create")
public void createGroup(SecurityGroupCreateReq req) {
@@ -50,7 +56,7 @@ public class SecurityController {
/**
* 将级联删除对应规则,并更新缓存
* @param groupId
* @param groupId 安全组Id
*/
@Post
@Mapping("/group/delete")
@@ -61,6 +61,10 @@ public class SecurityGroupService {
.eq(SecurityGroupDO::getUserId, SystemContextHolder.getUserId()));
}
public SecurityGroupDO queryGroupOne(Integer groupId) {
return securityGroupMapper.selectById(groupId);
}
public void createGroup(SecurityGroupCreateReq req) {
SecurityGroupDO groupDO = new SecurityGroupDO();
BeanUtil.copyProperties(req, groupDO);
@@ -80,8 +84,8 @@ public class SecurityGroupService {
}
public void setGroupStatus(Integer groupId, EnableStatusEnum statusEnum) {
SecurityGroupDO groupDO = securityGroupMap.get(groupId);
if (groupDO == null || groupDO.getEnable() == EnableStatusEnum.DISABLE) {
SecurityGroupDO groupDO = securityGroupMapper.selectById(groupId);
if (groupDO == null) {
throw new RuntimeException("指定的安全组不存在");
}
groupDO.setEnable(statusEnum);