Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
FLIPPED-AURORA
gin-vue-admin
提交
70b2ee3f
G
gin-vue-admin
项目概览
FLIPPED-AURORA
/
gin-vue-admin
10 个月 前同步成功
通知
324
Star
18154
Fork
5505
代码
文件
提交
分支
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,体验更适合开发者的 AI 搜索 >>
提交
70b2ee3f
编写于
11月 14, 2020
作者:
S
SliverHorn
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
更新自动化代码api层代码混入service层代码
上级
67790541
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
68 addition
and
67 deletion
+68
-67
server/api/v1/sys_auto_code.go
server/api/v1/sys_auto_code.go
+5
-45
server/service/sys_api.go
server/service/sys_api.go
+0
-22
server/service/sys_auto_code.go
server/service/sys_auto_code.go
+63
-0
未找到文件。
server/api/v1/sys_auto_code.go
浏览文件 @
70b2ee3f
...
...
@@ -30,51 +30,11 @@ func CreateTemp(c *gin.Context) {
return
}
if
a
.
AutoCreateApiToSql
{
apiList
:=
[
6
]
model
.
SysApi
{
{
Path
:
"/"
+
a
.
Abbreviation
+
"/"
+
"create"
+
a
.
StructName
,
Description
:
"新增"
+
a
.
Description
,
ApiGroup
:
a
.
Abbreviation
,
Method
:
"POST"
,
},
{
Path
:
"/"
+
a
.
Abbreviation
+
"/"
+
"delete"
+
a
.
StructName
,
Description
:
"删除"
+
a
.
Description
,
ApiGroup
:
a
.
Abbreviation
,
Method
:
"DELETE"
,
},
{
Path
:
"/"
+
a
.
Abbreviation
+
"/"
+
"delete"
+
a
.
StructName
+
"ByIds"
,
Description
:
"批量删除"
+
a
.
Description
,
ApiGroup
:
a
.
Abbreviation
,
Method
:
"DELETE"
,
},
{
Path
:
"/"
+
a
.
Abbreviation
+
"/"
+
"update"
+
a
.
StructName
,
Description
:
"更新"
+
a
.
Description
,
ApiGroup
:
a
.
Abbreviation
,
Method
:
"PUT"
,
},
{
Path
:
"/"
+
a
.
Abbreviation
+
"/"
+
"find"
+
a
.
StructName
,
Description
:
"根据ID获取"
+
a
.
Description
,
ApiGroup
:
a
.
Abbreviation
,
Method
:
"GET"
,
},
{
Path
:
"/"
+
a
.
Abbreviation
+
"/"
+
"get"
+
a
.
StructName
+
"List"
,
Description
:
"获取"
+
a
.
Description
+
"列表"
,
ApiGroup
:
a
.
Abbreviation
,
Method
:
"GET"
,
},
}
for
_
,
v
:=
range
apiList
{
if
err
:=
service
.
AutoCreateApi
(
v
);
err
!=
nil
{
global
.
GVA_LOG
.
Error
(
"自动化创建失败!请自行清空垃圾数据!"
,
zap
.
Any
(
"err"
,
err
))
c
.
Writer
.
Header
()
.
Add
(
"success"
,
"false"
)
c
.
Writer
.
Header
()
.
Add
(
"msg"
,
url
.
QueryEscape
(
"自动化创建失败!请自行清空垃圾数据!"
))
return
}
if
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
}
}
err
:=
service
.
CreateTemp
(
a
)
...
...
server/service/sys_api.go
浏览文件 @
70b2ee3f
...
...
@@ -33,28 +33,6 @@ func DeleteApi(api model.SysApi) (err error) {
return
err
}
//@author: [piexlmax](https://github.com/piexlmax)
//@function: CreateApi
//@description: 自动创建api数据,
//@param: api model.SysApi
//@return: err error
func
AutoCreateApi
(
api
model
.
SysApi
)
(
err
error
)
{
err
=
global
.
GVA_DB
.
Transaction
(
func
(
tx
*
gorm
.
DB
)
error
{
var
fApi
model
.
SysApi
var
txErr
error
fxErr
:=
tx
.
Where
(
"path = ? AND method = ?"
,
api
.
Path
,
api
.
Method
)
.
First
(
&
fApi
)
.
Error
if
errors
.
Is
(
fxErr
,
gorm
.
ErrRecordNotFound
)
{
txErr
=
tx
.
Create
(
&
api
)
.
Error
if
txErr
!=
nil
{
return
txErr
}
}
return
nil
})
return
err
}
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetAPIInfoList
//@description: 分页获取数据,
...
...
server/service/sys_auto_code.go
浏览文件 @
70b2ee3f
...
...
@@ -7,6 +7,7 @@ import (
"gin-vue-admin/model"
"gin-vue-admin/model/request"
"gin-vue-admin/utils"
"gorm.io/gorm"
"io/ioutil"
"os"
"path/filepath"
...
...
@@ -207,3 +208,65 @@ func addAutoMoveFile(data *tplData) {
}
}
}
//@author: [piexlmax](https://github.com/piexlmax)
//@author: [SliverHorn](https://github.com/SliverHorn)
//@function: CreateApi
//@description: 自动创建api数据,
//@param: a *model.AutoCodeStruct
//@return: error
func
AutoCreateApi
(
a
*
model
.
AutoCodeStruct
)
(
err
error
)
{
var
apiList
=
[]
model
.
SysApi
{
{
Path
:
"/"
+
a
.
Abbreviation
+
"/"
+
"create"
+
a
.
StructName
,
Description
:
"新增"
+
a
.
Description
,
ApiGroup
:
a
.
Abbreviation
,
Method
:
"POST"
,
},
{
Path
:
"/"
+
a
.
Abbreviation
+
"/"
+
"delete"
+
a
.
StructName
,
Description
:
"删除"
+
a
.
Description
,
ApiGroup
:
a
.
Abbreviation
,
Method
:
"DELETE"
,
},
{
Path
:
"/"
+
a
.
Abbreviation
+
"/"
+
"delete"
+
a
.
StructName
+
"ByIds"
,
Description
:
"批量删除"
+
a
.
Description
,
ApiGroup
:
a
.
Abbreviation
,
Method
:
"DELETE"
,
},
{
Path
:
"/"
+
a
.
Abbreviation
+
"/"
+
"update"
+
a
.
StructName
,
Description
:
"更新"
+
a
.
Description
,
ApiGroup
:
a
.
Abbreviation
,
Method
:
"PUT"
,
},
{
Path
:
"/"
+
a
.
Abbreviation
+
"/"
+
"find"
+
a
.
StructName
,
Description
:
"根据ID获取"
+
a
.
Description
,
ApiGroup
:
a
.
Abbreviation
,
Method
:
"GET"
,
},
{
Path
:
"/"
+
a
.
Abbreviation
+
"/"
+
"get"
+
a
.
StructName
+
"List"
,
Description
:
"获取"
+
a
.
Description
+
"列表"
,
ApiGroup
:
a
.
Abbreviation
,
Method
:
"GET"
,
},
}
err
=
global
.
GVA_DB
.
Transaction
(
func
(
tx
*
gorm
.
DB
)
error
{
for
_
,
v
:=
range
apiList
{
var
api
model
.
SysApi
if
err
:=
tx
.
Where
(
"path = ? AND method = ?"
,
v
.
Path
,
v
.
Method
)
.
First
(
&
api
)
.
Error
;
err
!=
nil
{
return
err
}
if
err
:=
tx
.
Create
(
&
v
)
.
Error
;
err
!=
nil
{
// 遇到错误时回滚事务
return
err
}
}
return
nil
})
return
err
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录