Skip to content

Commit 7473cdf

Browse files
author
piexlmax
committed
增加回滚不删表按钮防止误删数据库重要数据
1 parent 069478a commit 7473cdf

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

server/api/v1/system/sys_auto_code_history.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ func (a *AutoCodeHistoryApi) Delete(c *gin.Context) {
5858
// @Security ApiKeyAuth
5959
// @accept application/json
6060
// @Produce application/json
61-
// @Param data body request.GetById true "请求参数"
61+
// @Param data body systemReq.RollBack true "请求参数"
6262
// @Success 200 {object} response.Response{msg=string} "回滚自动生成代码"
6363
// @Router /autoCode/rollback [post]
6464
func (a *AutoCodeHistoryApi) RollBack(c *gin.Context) {
65-
var info request.GetById
65+
var info systemReq.RollBack
6666
_ = c.ShouldBindJSON(&info)
6767
if err := autoCodeHistoryService.RollBack(&info); err != nil {
6868
response.FailWithMessage(err.Error(), c)

server/model/system/request/sys_auto_history.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,9 @@ import "github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
55
type SysAutoHistory struct {
66
request.PageInfo
77
}
8+
9+
// GetById Find by id structure
10+
type RollBack struct {
11+
ID int `json:"id" form:"id"` // 主键ID
12+
DeleteTable bool `json:"deleteTable" form:"deleteTable"` // 是否删除表
13+
}

server/service/system/sys_autocode_history.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package system
33
import (
44
"errors"
55
"fmt"
6+
systemReq "github.com/flipped-aurora/gin-vue-admin/server/model/system/request"
67
"path/filepath"
78
"strings"
89
"time"
@@ -60,9 +61,9 @@ func (autoCodeHistoryService *AutoCodeHistoryService) Repeat(structName string,
6061
// RollBack 回滚
6162
// Author [SliverHorn](https://github.com/SliverHorn)
6263
// Author [songzhibin97](https://github.com/songzhibin97)
63-
func (autoCodeHistoryService *AutoCodeHistoryService) RollBack(info *request.GetById) error {
64+
func (autoCodeHistoryService *AutoCodeHistoryService) RollBack(info *systemReq.RollBack) error {
6465
md := system.SysAutoCodeHistory{}
65-
if err := global.GVA_DB.Where("id = ?", info.Uint()).First(&md).Error; err != nil {
66+
if err := global.GVA_DB.Where("id = ?", info.ID).First(&md).Error; err != nil {
6667
return err
6768
}
6869
// 清除API表
@@ -71,8 +72,10 @@ func (autoCodeHistoryService *AutoCodeHistoryService) RollBack(info *request.Get
7172
global.GVA_LOG.Error("ClearTag DeleteApiByIds:", zap.Error(err))
7273
}
7374
// 删除表
74-
if err = AutoCodeServiceApp.DropTable(md.TableName); err != nil {
75-
global.GVA_LOG.Error("ClearTag DropTable:", zap.Error(err))
75+
if info.DeleteTable {
76+
if err = AutoCodeServiceApp.DropTable(md.TableName); err != nil {
77+
global.GVA_LOG.Error("ClearTag DropTable:", zap.Error(err))
78+
}
7679
}
7780
// 删除文件
7881

web/src/view/systemTools/autoCodeAdmin/index.vue

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@
3636
</el-tag>
3737
</template>
3838
</el-table-column>
39-
<el-table-column align="left" label="操作" min-width="180">
39+
<el-table-column align="left" label="操作" min-width="240">
4040
<template #default="scope">
4141
<div>
42-
<el-button size="small" type="text" :disabled="scope.row.flag === 1" @click="rollbackFunc(scope.row)">回滚</el-button>
42+
<el-button size="small" type="text" :disabled="scope.row.flag === 1" @click="rollbackFunc(scope.row,true)">回滚(删表)</el-button>
43+
<el-button size="small" type="text" :disabled="scope.row.flag === 1" @click="rollbackFunc(scope.row,false)">回滚(不删表)</el-button>
4344
<el-button size="small" type="text" @click="goAutoCode(scope.row)">复用</el-button>
4445
<el-button size="small" type="text" @click="deleteRow(scope.row)">删除</el-button>
4546
</div>
@@ -120,13 +121,13 @@ const deleteRow = async(row) => {
120121
}
121122
})
122123
}
123-
const rollbackFunc = async(row) => {
124-
ElMessageBox.confirm('此操作将删除自动创建的文件和api, 是否继续?', '提示', {
124+
const rollbackFunc = async(row, flag) => {
125+
ElMessageBox.confirm(`此操作将删除自动创建的文件和api${flag ? '(包含数据库表!)' : ''}, 是否继续?`, '提示', {
125126
confirmButtonText: '确定',
126127
cancelButtonText: '取消',
127128
type: 'warning'
128129
}).then(async() => {
129-
const res = await rollback({ id: Number(row.ID) })
130+
const res = await rollback({ id: Number(row.ID), deleteTable: flag })
130131
if (res.code === 0) {
131132
ElMessage.success('回滚成功')
132133
getTableData()

0 commit comments

Comments
 (0)