From a37513def2af6903562df786a3f289e5bba1d957 Mon Sep 17 00:00:00 2001 From: songzhibin97 <718428482@qq.com> Date: Mon, 12 Jul 2021 14:53:25 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E5=AE=8C=E5=96=84=E5=9B=9E=E6=BB=9A?= =?UTF-8?q?=E9=80=BB=E8=BE=91,=E5=A6=82=E6=9E=9C=E5=8B=BE=E9=80=89api?= =?UTF-8?q?=E4=B9=9F=E4=BC=9A=E5=88=9B=E5=BB=BA=E5=AF=B9=E5=BA=94=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/service/sys_auto_code.go | 63 ++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/server/service/sys_auto_code.go b/server/service/sys_auto_code.go index 53175213..528c654c 100644 --- a/server/service/sys_auto_code.go +++ b/server/service/sys_auto_code.go @@ -127,6 +127,13 @@ func CreateTemp(autoCode model.AutoCodeStruct, ids ...uint) (err error) { return } }() + bf := strings.Builder{} + idBf := strings.Builder{} + injectionCodeMeta := strings.Builder{} + for _, id := range ids { + idBf.WriteString(strconv.Itoa(int(id))) + idBf.WriteString(";") + } if autoCode.AutoMoveFile { // 判断是否需要自动转移 for index, _ := range dataList { addAutoMoveFile(&dataList[index]) @@ -148,53 +155,51 @@ func CreateTemp(autoCode model.AutoCodeStruct, ids ...uint) (err error) { if err != nil { return err } - injectionCodeMeta := strings.Builder{} + injectionCodeMeta.WriteString(fmt.Sprintf("%s@%s@%s", initializeGormFilePath, "MysqlTables", "model."+autoCode.StructName+"{},")) injectionCodeMeta.WriteString(";") injectionCodeMeta.WriteString(fmt.Sprintf("%s@%s@%s", initializeRouterFilePath, "Routers", "router.Init"+autoCode.StructName+"Router(PrivateGroup)")) // 保存生成信息 - bf := strings.Builder{} for _, data := range dataList { if len(data.autoMoveFilePath) != 0 { bf.WriteString(data.autoMoveFilePath) bf.WriteString(";") } } - idBf := strings.Builder{} - for _, id := range ids { - idBf.WriteString(strconv.Itoa(int(id))) - idBf.WriteString(";") - } - if autoCode.TableName != "" { - err = CreateAutoCodeHistory(bf.String(), - injectionCodeMeta.String(), - autoCode.TableName, - idBf.String(), - ) - } else { - err = CreateAutoCodeHistory(bf.String(), - injectionCodeMeta.String(), - autoCode.StructName, - idBf.String(), - ) + if global.GVA_CONFIG.AutoCode.TransferRestart { + go func() { + _ = utils.Reload() + }() } - if err != nil { - return err - } - //if global.GVA_CONFIG.AutoCode.TransferRestart { - // go func() { - // _ = utils.Reload() - // }() - //} - return errors.New("创建代码成功并移动文件成功") + //return errors.New("创建代码成功并移动文件成功") } else { // 打包 - if err := utils.ZipFiles("./ginvueadmin.zip", fileList, ".", "."); err != nil { + if err = utils.ZipFiles("./ginvueadmin.zip", fileList, ".", "."); err != nil { return err } } + if autoCode.TableName != "" { + err = CreateAutoCodeHistory(bf.String(), + injectionCodeMeta.String(), + autoCode.TableName, + idBf.String(), + ) + } else { + err = CreateAutoCodeHistory(bf.String(), + injectionCodeMeta.String(), + autoCode.StructName, + idBf.String(), + ) + } + if err != nil { + return err + } + if autoCode.AutoMoveFile { + return errors.New("创建代码成功并移动文件成功") + } return nil + } //@author: [piexlmax](https://github.com/piexlmax)