From 5c3199daf5655b224456fe286b6abdacb31f112a Mon Sep 17 00:00:00 2001 From: wall-js Date: Thu, 20 Jun 2024 14:24:33 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fixed:=20=E4=BF=AE=E5=A4=8D=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=8C=96=E4=BB=A3=E7=A0=81form=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=EF=BC=8Cfind=E6=8E=A5=E5=8F=A3=E8=B0=83=E6=95=B4=E6=9C=AA?= =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=AE=8C=E5=85=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/resource/autocode_template/web/form.vue.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/resource/autocode_template/web/form.vue.tpl b/server/resource/autocode_template/web/form.vue.tpl index 14df8d3504..9e7c0f9ab7 100644 --- a/server/resource/autocode_template/web/form.vue.tpl +++ b/server/resource/autocode_template/web/form.vue.tpl @@ -176,7 +176,7 @@ const init = async () => { if (route.query.id) { const res = await find{{.StructName}}({ ID: route.query.id }) if (res.code === 0) { - formData.value = res.data.re{{.Abbreviation}} + formData.value = res.data type.value = 'update' } } else { From 898eca818477e375749b2191437a96a9771843f2 Mon Sep 17 00:00:00 2001 From: wall-js Date: Wed, 26 Jun 2024 11:07:00 +0800 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20=E8=B0=83=E6=95=B4=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=8C=96=E4=BB=A3=E7=A0=81=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E5=88=9B=E5=BB=BA=E7=9A=84=E8=8F=9C=E5=8D=95?= =?UTF-8?q?=E5=92=8Capi=E9=9C=80=E8=A6=81=E7=94=A8=E6=88=B7=E6=89=8B?= =?UTF-8?q?=E5=8A=A8=E5=8F=96=E6=B6=88=E8=87=AA=E5=8A=A8=E5=88=9B=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/api/v1/system/sys_auto_code.go | 9 +++++---- server/service/system/sys_auto_code.go | 9 +++++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/server/api/v1/system/sys_auto_code.go b/server/api/v1/system/sys_auto_code.go index 7f2d365e0c..eee191c82c 100644 --- a/server/api/v1/system/sys_auto_code.go +++ b/server/api/v1/system/sys_auto_code.go @@ -64,9 +64,9 @@ 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 @@ -74,9 +74,10 @@ func (autoApi *AutoCodeApi) CreateTemp(c *gin.Context) { } 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 } diff --git a/server/service/system/sys_auto_code.go b/server/service/system/sys_auto_code.go index d526200a34..d616cbe9cb 100644 --- a/server/service/system/sys_auto_code.go +++ b/server/service/system/sys_auto_code.go @@ -5,7 +5,6 @@ import ( "encoding/json" "errors" "fmt" - "github.com/mholt/archiver/v4" "io" "mime/multipart" "os" @@ -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" @@ -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 { From 65e4b178628992b8f02070877392699fb2145150 Mon Sep 17 00:00:00 2001 From: wall-js Date: Fri, 28 Jun 2024 09:21:43 +0800 Subject: [PATCH 3/3] =?UTF-8?q?feat:=20=E8=B0=83=E6=95=B4=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E6=97=A0=E8=AE=BA=E6=98=AF=E5=90=A6=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E8=8F=9C=E5=8D=95=E6=88=96API=E9=83=BD=E6=B3=A8=E5=86=8C?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=8C=96=E4=BB=A3=E7=A0=81=E5=8E=86=E5=8F=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/service/system/sys_auto_code.go | 54 +++++++++++++------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/server/service/system/sys_auto_code.go b/server/service/system/sys_auto_code.go index d616cbe9cb..3de3e54471 100644 --- a/server/service/system/sys_auto_code.go +++ b/server/service/system/sys_auto_code.go @@ -303,34 +303,32 @@ func (autoCodeService *AutoCodeService) CreateTemp(autoCode system.AutoCodeStruc bf.WriteString(";") } } - if autoCode.AutoCreateApiToSql || autoCode.AutoCreateMenuToSql { - if autoCode.TableName != "" { - err = AutoCodeHistoryServiceApp.CreateAutoCodeHistory( - string(meta), - autoCode.StructName, - autoCode.Description, - bf.String(), - injectionCodeMeta.String(), - autoCode.TableName, - idBf.String(), - autoCode.Package, - autoCode.BusinessDB, - menuID, - ) - } else { - err = AutoCodeHistoryServiceApp.CreateAutoCodeHistory( - string(meta), - autoCode.StructName, - autoCode.Description, - bf.String(), - injectionCodeMeta.String(), - autoCode.StructName, - idBf.String(), - autoCode.Package, - autoCode.BusinessDB, - menuID, - ) - } + if autoCode.TableName != "" { + err = AutoCodeHistoryServiceApp.CreateAutoCodeHistory( + string(meta), + autoCode.StructName, + autoCode.Description, + bf.String(), + injectionCodeMeta.String(), + autoCode.TableName, + idBf.String(), + autoCode.Package, + autoCode.BusinessDB, + menuID, + ) + } else { + err = AutoCodeHistoryServiceApp.CreateAutoCodeHistory( + string(meta), + autoCode.StructName, + autoCode.Description, + bf.String(), + injectionCodeMeta.String(), + autoCode.StructName, + idBf.String(), + autoCode.Package, + autoCode.BusinessDB, + menuID, + ) } if err != nil { return err