Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 调整自动化代码逻辑,重复创建的菜单和api需要用户手动取消自动创建 #1798

Merged
merged 3 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions server/api/v1/system/sys_auto_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,20 @@ func (autoApi *AutoCodeApi) CreateTemp(c *gin.Context) {
var menuId uint
if a.AutoCreateApiToSql {
if ids, err := autoCodeService.AutoCreateApi(&a); err != nil {
global.GVA_LOG.Error("自动化创建失败!请自行清空垃圾数据!", zap.Error(err))
global.GVA_LOG.Error("自动化创建API失败!", zap.Error(err))
c.Writer.Header().Add("success", "false")
c.Writer.Header().Add("msg", url.QueryEscape("自动化创建失败!请自行清空垃圾数据!"))
c.Writer.Header().Add("msg", url.QueryEscape("自动化创建失败!请自行清空垃圾数据或取消自动创建API!"))
return
} else {
apiIds = ids
}
}
if a.AutoCreateMenuToSql {
if id, err := autoCodeService.AutoCreateMenu(&a); err != nil {
global.GVA_LOG.Error("自动化创建失败!请自行清空垃圾数据!", zap.Error(err))
global.GVA_LOG.Error("自动化创建菜单失败!", zap.Error(err))
c.Writer.Header().Add("success", "false")
c.Writer.Header().Add("msg", url.QueryEscape("自动化创建失败!请自行清空垃圾数据!"))
c.Writer.Header().Add("msg", url.QueryEscape("自动化创建失败!请自行清空垃圾数据或取消自动创建菜单!"))
return
} else {
menuId = id
}
Expand Down
9 changes: 7 additions & 2 deletions server/service/system/sys_auto_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/mholt/archiver/v4"
"io"
"mime/multipart"
"os"
Expand All @@ -14,6 +13,8 @@ import (
"strings"
"text/template"

"github.com/mholt/archiver/v4"

ast2 "github.com/flipped-aurora/gin-vue-admin/server/utils/ast"

"github.com/flipped-aurora/gin-vue-admin/server/resource/autocode_template/subcontract"
Expand Down Expand Up @@ -468,7 +469,11 @@ func (autoCodeService *AutoCodeService) AutoCreateApi(a *system.AutoCodeStruct)
err = global.GVA_DB.Transaction(func(tx *gorm.DB) error {
for _, v := range apiList {
var api system.SysApi
if errors.Is(tx.Where("path = ? AND method = ?", v.Path, v.Method).First(&api).Error, gorm.ErrRecordNotFound) {
findErr := tx.Where("path = ? AND method = ?", v.Path, v.Method).First(&api).Error
if findErr == nil {
return errors.New("存在相同的API,请关闭自动创建API功能")
}
if errors.Is(findErr, gorm.ErrRecordNotFound) {
if err = tx.Create(&v).Error; err != nil { // 遇到错误时回滚事务
return err
} else {
Expand Down
Loading