Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
FLIPPED-AURORA
gin-vue-admin
提交
5c7ba88b
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,发现更多精彩内容 >>
提交
5c7ba88b
编写于
7月 13, 2021
作者:
S
songzhibin97
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat:新存储了meta信息,完善了记录逻辑
上级
fb2199c9
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
59 addition
and
24 deletion
+59
-24
server/api/v1/sys_auto_code.go
server/api/v1/sys_auto_code.go
+22
-2
server/model/sys_autocode_history.go
server/model/sys_autocode_history.go
+4
-2
server/router/sys_auto_code.go
server/router/sys_auto_code.go
+1
-0
server/service/sys_auto_code.go
server/service/sys_auto_code.go
+20
-12
server/service/sys_autocode_history.go
server/service/sys_autocode_history.go
+12
-8
未找到文件。
server/api/v1/sys_auto_code.go
浏览文件 @
5c7ba88b
...
...
@@ -23,7 +23,7 @@ import (
// @Produce application/json
// @Param data body request.SysAutoHistory true "查询回滚记录"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /autoCode/
preview
[post]
// @Router /autoCode/
getSysHistory
[post]
func
GetSysHistory
(
c
*
gin
.
Context
)
{
var
search
request
.
SysAutoHistory
_
=
c
.
ShouldBindJSON
(
&
search
)
...
...
@@ -48,7 +48,7 @@ func GetSysHistory(c *gin.Context) {
// @Produce application/json
// @Param data body request.AutoHistoryByID true "回滚自动生成代码"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"回滚成功"}"
// @Router /autoCode/
preview
[post]
// @Router /autoCode/
rollback
[post]
func
RollBack
(
c
*
gin
.
Context
)
{
var
id
request
.
AutoHistoryByID
_
=
c
.
ShouldBindJSON
(
&
id
)
...
...
@@ -59,6 +59,26 @@ func RollBack(c *gin.Context) {
response
.
OkWithMessage
(
"回滚成功"
,
c
)
}
// @Tags AutoCode
// @Summary 回滚
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.AutoHistoryByID true "获取meta信息"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /autoCode/getMeta [post]
func
GetMeta
(
c
*
gin
.
Context
)
{
var
id
request
.
AutoHistoryByID
_
=
c
.
ShouldBindJSON
(
&
id
)
if
v
,
err
:=
service
.
GetMeta
(
id
.
ID
);
err
!=
nil
{
response
.
FailWithMessage
(
err
.
Error
(),
c
)
return
}
else
{
response
.
OkWithDetailed
(
gin
.
H
{
"meta"
:
v
},
"获取成功"
,
c
)
}
}
// @Tags AutoCode
// @Summary 预览创建后的代码
// @Security ApiKeyAuth
...
...
server/model/sys_autocode_history.go
浏览文件 @
5c7ba88b
...
...
@@ -7,8 +7,10 @@ import "gin-vue-admin/global"
type
SysAutoCodeHistory
struct
{
global
.
GVA_MODEL
TableName
string
AutoCodeMeta
string
`gorm:"type:text"`
// 其他meta信息 path;path
InjectionMeta
string
`gorm:"type:text"`
// 注入的内容 RouterPath@functionName@RouterString;
RequestMeta
string
`gorm:"type:text" json:"request_meta,omitempty"`
// 前端传入的结构化信息
AutoCodePath
string
`gorm:"type:text"`
// 其他meta信息 path;path
InjectionMeta
string
`gorm:"type:text"`
// 注入的内容 RouterPath@functionName@RouterString;
ApiIDs
string
// api表注册内容
Flag
int
// 表示对应状态 0 代表创建, 1 代表回滚 ...
}
server/router/sys_auto_code.go
浏览文件 @
5c7ba88b
...
...
@@ -8,6 +8,7 @@ import (
func
InitAutoCodeRouter
(
Router
*
gin
.
RouterGroup
)
{
AutoCodeRouter
:=
Router
.
Group
(
"autoCode"
)
{
AutoCodeRouter
.
POST
(
"getMeta"
,
v1
.
GetMeta
)
// 根据id获取meta信息
AutoCodeRouter
.
POST
(
"getSysHistory"
,
v1
.
GetSysHistory
)
// 获取回滚记录分页
AutoCodeRouter
.
POST
(
"rollback"
,
v1
.
RollBack
)
// 回滚
AutoCodeRouter
.
POST
(
"preview"
,
v1
.
PreviewTemp
)
// 获取自动创建代码预览
...
...
server/service/sys_auto_code.go
浏览文件 @
5c7ba88b
package
service
import
(
"encoding/json"
"errors"
"fmt"
"gin-vue-admin/global"
...
...
@@ -105,6 +106,7 @@ func CreateTemp(autoCode model.AutoCodeStruct, ids ...uint) (err error) {
if
err
!=
nil
{
return
err
}
meta
,
_
:=
json
.
Marshal
(
autoCode
)
// 写入文件前,先创建文件夹
if
err
=
utils
.
CreateDir
(
needMkdir
...
);
err
!=
nil
{
return
err
...
...
@@ -179,18 +181,24 @@ func CreateTemp(autoCode model.AutoCodeStruct, ids ...uint) (err error) {
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
autoCode
.
AutoMoveFile
||
autoCode
.
AutoCreateApiToSql
{
if
autoCode
.
TableName
!=
""
{
err
=
CreateAutoCodeHistory
(
string
(
meta
),
bf
.
String
(),
injectionCodeMeta
.
String
(),
autoCode
.
TableName
,
idBf
.
String
(),
)
}
else
{
err
=
CreateAutoCodeHistory
(
string
(
meta
),
bf
.
String
(),
injectionCodeMeta
.
String
(),
autoCode
.
StructName
,
idBf
.
String
(),
)
}
}
if
err
!=
nil
{
return
err
...
...
server/service/sys_autocode_history.go
浏览文件 @
5c7ba88b
package
service
import
(
"errors"
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
...
...
@@ -12,9 +11,10 @@ import (
)
// CreateAutoCodeHistory RouterPath : RouterPath@RouterString;RouterPath2@RouterString2
func
CreateAutoCodeHistory
(
autoCodeMeta
string
,
injectionMeta
string
,
tableName
string
,
apiIds
string
)
error
{
func
CreateAutoCodeHistory
(
meta
,
autoCodePath
string
,
injectionMeta
string
,
tableName
string
,
apiIds
string
)
error
{
return
global
.
GVA_DB
.
Create
(
&
model
.
SysAutoCodeHistory
{
AutoCodeMeta
:
autoCodeMeta
,
RequestMeta
:
meta
,
AutoCodePath
:
autoCodePath
,
InjectionMeta
:
injectionMeta
,
TableName
:
tableName
,
ApiIDs
:
apiIds
,
...
...
@@ -48,28 +48,32 @@ func RollBack(id uint) error {
}
}
// 删除文件
for
_
,
path
:=
range
strings
.
Split
(
md
.
AutoCode
Meta
,
";"
)
{
for
_
,
path
:=
range
strings
.
Split
(
md
.
AutoCode
Path
,
";"
)
{
_
=
utils
.
DeLFile
(
path
)
}
// 清除注入
for
_
,
v
:=
range
strings
.
Split
(
md
.
InjectionMeta
,
";"
)
{
// RouterPath@functionName@RouterString
meta
:=
strings
.
Split
(
v
,
"@"
)
if
len
(
meta
)
!
=
3
{
return
errors
.
New
(
"split InjectionMeta Err"
)
if
len
(
meta
)
=
=
3
{
_
=
utils
.
AutoClearCode
(
meta
[
0
],
meta
[
2
]
)
}
_
=
utils
.
AutoClearCode
(
meta
[
0
],
meta
[
2
])
}
md
.
Flag
=
1
return
global
.
GVA_DB
.
Save
(
&
md
)
.
Error
}
func
GetMeta
(
id
uint
)
(
string
,
error
)
{
var
meta
string
return
meta
,
global
.
GVA_DB
.
Model
(
model
.
SysAutoCodeHistory
{})
.
Select
(
"request_meta"
)
.
First
(
&
meta
,
id
)
.
Error
}
func
GetSysHistoryPage
(
info
request
.
PageInfo
)
(
err
error
,
list
interface
{},
total
int64
)
{
limit
:=
info
.
PageSize
offset
:=
info
.
PageSize
*
(
info
.
Page
-
1
)
db
:=
global
.
GVA_DB
var
fileLists
[]
model
.
SysAutoCodeHistory
err
=
db
.
Find
(
&
fileLists
)
.
Count
(
&
total
)
.
Error
err
=
db
.
Limit
(
limit
)
.
Offset
(
offset
)
.
Order
(
"updated_at desc"
)
.
Find
(
&
fileLists
)
.
Error
err
=
db
.
Limit
(
limit
)
.
Offset
(
offset
)
.
Order
(
"updated_at desc"
)
.
Select
(
"id,created_at,updated_at,table_name,auto_code_path,injection_meta,api_ids,flag"
)
.
Find
(
&
fileLists
)
.
Error
return
err
,
fileLists
,
total
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录