Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
FLIPPED-AURORA
gin-vue-admin
提交
e1e3a31e
G
gin-vue-admin
项目概览
FLIPPED-AURORA
/
gin-vue-admin
大约 1 年 前同步成功
通知
333
Star
18155
Fork
5506
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gin-vue-admin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e1e3a31e
编写于
7月 10, 2021
作者:
S
songzhibin97
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat:回滚删除对应api
上级
dac4e733
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
39 addition
and
16 deletion
+39
-16
server/api/v1/sys_auto_code.go
server/api/v1/sys_auto_code.go
+5
-2
server/model/sys_autocode_history.go
server/model/sys_autocode_history.go
+1
-0
server/service/sys_api.go
server/service/sys_api.go
+4
-0
server/service/sys_auto_code.go
server/service/sys_auto_code.go
+20
-10
server/service/sys_autocode_history.go
server/service/sys_autocode_history.go
+9
-4
未找到文件。
server/api/v1/sys_auto_code.go
浏览文件 @
e1e3a31e
...
...
@@ -72,15 +72,18 @@ func CreateTemp(c *gin.Context) {
response
.
FailWithMessage
(
err
.
Error
(),
c
)
return
}
var
apiIds
[]
uint
if
a
.
AutoCreateApiToSql
{
if
err
:=
service
.
AutoCreateApi
(
&
a
);
err
!=
nil
{
if
ids
,
err
:=
service
.
AutoCreateApi
(
&
a
);
err
!=
nil
{
global
.
GVA_LOG
.
Error
(
"自动化创建失败!请自行清空垃圾数据!"
,
zap
.
Any
(
"err"
,
err
))
c
.
Writer
.
Header
()
.
Add
(
"success"
,
"false"
)
c
.
Writer
.
Header
()
.
Add
(
"msg"
,
url
.
QueryEscape
(
"自动化创建失败!请自行清空垃圾数据!"
))
return
}
else
{
apiIds
=
ids
}
}
err
:=
service
.
CreateTemp
(
a
)
err
:=
service
.
CreateTemp
(
a
,
apiIds
...
)
if
err
!=
nil
{
if
errors
.
Is
(
err
,
model
.
AutoMoveErr
)
{
c
.
Writer
.
Header
()
.
Add
(
"success"
,
"false"
)
...
...
server/model/sys_autocode_history.go
浏览文件 @
e1e3a31e
...
...
@@ -9,5 +9,6 @@ type SysAutoCodeHistory struct {
TableName
string
AutoCodeMeta
string
`gorm:"type:text"`
// 其他meta信息 path;path
InjectionMeta
string
`gorm:"type:text"`
// 注入的内容 RouterPath@functionName@RouterString;
ApiIDs
string
// api表注册内容
Flag
int
// 表示对应状态 0 代表创建, 1 代表回滚 ...
}
server/service/sys_api.go
浏览文件 @
e1e3a31e
...
...
@@ -141,3 +141,7 @@ func DeleteApisByIds(ids request.IdsReq) (err error) {
err
=
global
.
GVA_DB
.
Delete
(
&
[]
model
.
SysApi
{},
"id in ?"
,
ids
.
Ids
)
.
Error
return
err
}
func
DeleteApiByIds
(
ids
[]
string
)
(
err
error
)
{
return
global
.
GVA_DB
.
Delete
(
model
.
SysApi
{},
ids
)
.
Error
}
server/service/sys_auto_code.go
浏览文件 @
e1e3a31e
...
...
@@ -10,6 +10,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"strconv"
"strings"
"text/template"
...
...
@@ -99,7 +100,7 @@ func PreviewTemp(autoCode model.AutoCodeStruct) (map[string]string, error) {
//@param: model.AutoCodeStruct
//@return: err error
func
CreateTemp
(
autoCode
model
.
AutoCodeStruct
)
(
err
error
)
{
func
CreateTemp
(
autoCode
model
.
AutoCodeStruct
,
ids
...
uint
)
(
err
error
)
{
dataList
,
fileList
,
needMkdir
,
err
:=
getNeedList
(
&
autoCode
)
if
err
!=
nil
{
return
err
...
...
@@ -160,27 +161,33 @@ func CreateTemp(autoCode model.AutoCodeStruct) (err error) {
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
err
!=
nil
{
return
err
}
if
global
.
GVA_CONFIG
.
AutoCode
.
TransferRestart
{
go
func
()
{
_
=
utils
.
Reload
()
}()
}
//
if global.GVA_CONFIG.AutoCode.TransferRestart {
//
go func() {
//
_ = utils.Reload()
//
}()
//
}
return
errors
.
New
(
"创建代码成功并移动文件成功"
)
}
else
{
// 打包
if
err
:=
utils
.
ZipFiles
(
"./ginvueadmin.zip"
,
fileList
,
"."
,
"."
);
err
!=
nil
{
...
...
@@ -301,7 +308,7 @@ func addAutoMoveFile(data *tplData) {
//@param: a *model.AutoCodeStruct
//@return: err error
func
AutoCreateApi
(
a
*
model
.
AutoCodeStruct
)
(
err
error
)
{
func
AutoCreateApi
(
a
*
model
.
AutoCodeStruct
)
(
ids
[]
uint
,
err
error
)
{
var
apiList
=
[]
model
.
SysApi
{
{
Path
:
"/"
+
a
.
Abbreviation
+
"/"
+
"create"
+
a
.
StructName
,
...
...
@@ -341,17 +348,20 @@ func AutoCreateApi(a *model.AutoCodeStruct) (err error) {
},
}
err
=
global
.
GVA_DB
.
Transaction
(
func
(
tx
*
gorm
.
DB
)
error
{
for
_
,
v
:=
range
apiList
{
var
api
model
.
SysApi
if
errors
.
Is
(
tx
.
Where
(
"path = ? AND method = ?"
,
v
.
Path
,
v
.
Method
)
.
First
(
&
api
)
.
Error
,
gorm
.
ErrRecordNotFound
)
{
if
err
:
=
tx
.
Create
(
&
v
)
.
Error
;
err
!=
nil
{
// 遇到错误时回滚事务
if
err
=
tx
.
Create
(
&
v
)
.
Error
;
err
!=
nil
{
// 遇到错误时回滚事务
return
err
}
else
{
ids
=
append
(
ids
,
v
.
ID
)
}
}
}
return
nil
})
return
err
return
ids
,
err
}
func
getNeedList
(
autoCode
*
model
.
AutoCodeStruct
)
(
dataList
[]
tplData
,
fileList
[]
string
,
needMkdir
[]
string
,
err
error
)
{
...
...
server/service/sys_autocode_history.go
浏览文件 @
e1e3a31e
...
...
@@ -11,11 +11,12 @@ import (
)
// CreateAutoCodeHistory RouterPath : RouterPath@RouterString;RouterPath2@RouterString2
func
CreateAutoCodeHistory
(
autoCodeMeta
string
,
injectionMeta
string
,
tableName
string
)
error
{
func
CreateAutoCodeHistory
(
autoCodeMeta
string
,
injectionMeta
string
,
tableName
string
,
apiIds
string
)
error
{
return
global
.
GVA_DB
.
Create
(
&
model
.
SysAutoCodeHistory
{
AutoCodeMeta
:
autoCodeMeta
,
InjectionMeta
:
injectionMeta
,
TableName
:
tableName
,
ApiIDs
:
apiIds
,
})
.
Error
}
...
...
@@ -24,10 +25,15 @@ func RollBack(id uint) error {
if
err
:=
global
.
GVA_DB
.
First
(
&
md
,
id
)
.
Error
;
err
!=
nil
{
return
err
}
// 切分数据
// 清除API表
err
:=
DeleteApiByIds
(
strings
.
Split
(
md
.
ApiIDs
,
";"
))
if
err
!=
nil
{
global
.
GVA_LOG
.
Error
(
"ClearTag DeleteApiByIds:"
,
zap
.
Error
(
err
))
}
// 获取全部表名
err
,
dbNames
:=
GetTables
(
global
.
GVA_CONFIG
.
Mysql
.
Dbname
)
if
err
!=
nil
{
return
err
global
.
GVA_LOG
.
Error
(
"ClearTag GetTables:"
,
zap
.
Error
(
err
))
}
// 删除表
for
_
,
name
:=
range
dbNames
{
...
...
@@ -40,7 +46,6 @@ func RollBack(id uint) error {
}
}
// 删除文件
for
_
,
path
:=
range
strings
.
Split
(
md
.
AutoCodeMeta
,
";"
)
{
_
=
utils
.
DeLFile
(
path
)
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录