Browse Source

feat:完善回滚逻辑,如果勾选api也会创建对应信息

main
songzhibin97 3 years ago
parent
commit
a37513def2
  1. 37
      server/service/sys_auto_code.go

37
server/service/sys_auto_code.go

@ -127,6 +127,13 @@ func CreateTemp(autoCode model.AutoCodeStruct, ids ...uint) (err error) {
return 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 { // 判断是否需要自动转移 if autoCode.AutoMoveFile { // 判断是否需要自动转移
for index, _ := range dataList { for index, _ := range dataList {
addAutoMoveFile(&dataList[index]) addAutoMoveFile(&dataList[index])
@ -148,25 +155,30 @@ func CreateTemp(autoCode model.AutoCodeStruct, ids ...uint) (err error) {
if err != nil { if err != nil {
return err return err
} }
injectionCodeMeta := strings.Builder{}
injectionCodeMeta.WriteString(fmt.Sprintf("%s@%s@%s", initializeGormFilePath, "MysqlTables", "model."+autoCode.StructName+"{},")) injectionCodeMeta.WriteString(fmt.Sprintf("%s@%s@%s", initializeGormFilePath, "MysqlTables", "model."+autoCode.StructName+"{},"))
injectionCodeMeta.WriteString(";") injectionCodeMeta.WriteString(";")
injectionCodeMeta.WriteString(fmt.Sprintf("%s@%s@%s", initializeRouterFilePath, "Routers", "router.Init"+autoCode.StructName+"Router(PrivateGroup)")) injectionCodeMeta.WriteString(fmt.Sprintf("%s@%s@%s", initializeRouterFilePath, "Routers", "router.Init"+autoCode.StructName+"Router(PrivateGroup)"))
// 保存生成信息 // 保存生成信息
bf := strings.Builder{}
for _, data := range dataList { for _, data := range dataList {
if len(data.autoMoveFilePath) != 0 { if len(data.autoMoveFilePath) != 0 {
bf.WriteString(data.autoMoveFilePath) bf.WriteString(data.autoMoveFilePath)
bf.WriteString(";") bf.WriteString(";")
} }
} }
idBf := strings.Builder{}
for _, id := range ids {
idBf.WriteString(strconv.Itoa(int(id)))
idBf.WriteString(";")
}
if global.GVA_CONFIG.AutoCode.TransferRestart {
go func() {
_ = utils.Reload()
}()
}
//return errors.New("创建代码成功并移动文件成功")
} else { // 打包
if err = utils.ZipFiles("./ginvueadmin.zip", fileList, ".", "."); err != nil {
return err
}
}
if autoCode.TableName != "" { if autoCode.TableName != "" {
err = CreateAutoCodeHistory(bf.String(), err = CreateAutoCodeHistory(bf.String(),
injectionCodeMeta.String(), injectionCodeMeta.String(),
@ -183,18 +195,11 @@ func CreateTemp(autoCode model.AutoCodeStruct, ids ...uint) (err error) {
if err != nil { if err != nil {
return err return err
} }
//if global.GVA_CONFIG.AutoCode.TransferRestart {
// go func() {
// _ = utils.Reload()
// }()
//}
if autoCode.AutoMoveFile {
return errors.New("创建代码成功并移动文件成功") return errors.New("创建代码成功并移动文件成功")
} else { // 打包
if err := utils.ZipFiles("./ginvueadmin.zip", fileList, ".", "."); err != nil {
return err
}
} }
return nil return nil
} }
//@author: [piexlmax](https://github.com/piexlmax) //@author: [piexlmax](https://github.com/piexlmax)

Loading…
Cancel
Save