增加回滚不删表按钮防止误删数据库重要数据

This commit is contained in:
piexlmax
2022-03-30 22:48:43 +08:00
parent 08c2b02be9
commit 13b12d80da
4 changed files with 21 additions and 11 deletions
@@ -58,11 +58,11 @@ func (a *AutoCodeHistoryApi) Delete(c *gin.Context) {
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.GetById true "请求参数"
// @Param data body systemReq.RollBack true "请求参数"
// @Success 200 {object} response.Response{msg=string} "回滚自动生成代码"
// @Router /autoCode/rollback [post]
func (a *AutoCodeHistoryApi) RollBack(c *gin.Context) {
var info request.GetById
var info systemReq.RollBack
_ = c.ShouldBindJSON(&info)
if err := autoCodeHistoryService.RollBack(&info); err != nil {
response.FailWithMessage(err.Error(), c)
@@ -5,3 +5,9 @@ import "github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
type SysAutoHistory struct {
request.PageInfo
}
// GetById Find by id structure
type RollBack struct {
ID int `json:"id" form:"id"` // 主键ID
DeleteTable bool `json:"deleteTable" form:"deleteTable"` // 是否删除表
}
@@ -3,6 +3,7 @@ package system
import (
"errors"
"fmt"
systemReq "github.com/flipped-aurora/gin-vue-admin/server/model/system/request"
"path/filepath"
"strings"
"time"
@@ -60,9 +61,9 @@ func (autoCodeHistoryService *AutoCodeHistoryService) Repeat(structName string,
// RollBack 回滚
// Author [SliverHorn](https://github.com/SliverHorn)
// Author [songzhibin97](https://github.com/songzhibin97)
func (autoCodeHistoryService *AutoCodeHistoryService) RollBack(info *request.GetById) error {
func (autoCodeHistoryService *AutoCodeHistoryService) RollBack(info *systemReq.RollBack) error {
md := system.SysAutoCodeHistory{}
if err := global.GVA_DB.Where("id = ?", info.Uint()).First(&md).Error; err != nil {
if err := global.GVA_DB.Where("id = ?", info.ID).First(&md).Error; err != nil {
return err
}
// 清除API表
@@ -71,8 +72,10 @@ func (autoCodeHistoryService *AutoCodeHistoryService) RollBack(info *request.Get
global.GVA_LOG.Error("ClearTag DeleteApiByIds:", zap.Error(err))
}
// 删除表
if err = AutoCodeServiceApp.DropTable(md.TableName); err != nil {
global.GVA_LOG.Error("ClearTag DropTable:", zap.Error(err))
if info.DeleteTable {
if err = AutoCodeServiceApp.DropTable(md.TableName); err != nil {
global.GVA_LOG.Error("ClearTag DropTable:", zap.Error(err))
}
}
// 删除文件