自动化代码可分包 (#982)

* [style] 修改右上角图标,选择统一风格的iconfont

* 增加路由排错处理

* 未输入tablename时前端自动生成下划线表名方式回滚误删表

* 支持自动化生成package功能

Co-authored-by: bypanghu <bypanghu@163.com>
Co-authored-by: songzhibin97 <718428482@qq.com>
This commit is contained in:
奇淼(piexlmax
2022-03-26 14:13:26 +08:00
committed by GitHub
parent 8003603ffd
commit 429353fa54
47 changed files with 1069 additions and 699 deletions

View File

@@ -1,120 +0,0 @@
package autocode
import (
"github.com/flipped-aurora/gin-vue-admin/server/global"
"github.com/flipped-aurora/gin-vue-admin/server/model/autocode"
autocodeReq "github.com/flipped-aurora/gin-vue-admin/server/model/autocode/request"
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
"github.com/flipped-aurora/gin-vue-admin/server/service"
"github.com/flipped-aurora/gin-vue-admin/server/utils"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
type AutoCodeExampleApi struct{}
var autoCodeExampleService = service.ServiceGroupApp.AutoCodeServiceGroup.AutoCodeExampleService
// @Tags AutoCodeExample
// @Summary 创建AutoCodeExample
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body autocode.AutoCodeExample true "AutoCodeExample模型"
// @Success 200 {object} response.Response{msg=string} "创建AutoCodeExample"
// @Router /autoCodeExample/createAutoCodeExample [post]
func (autoCodeExampleApi *AutoCodeExampleApi) CreateAutoCodeExample(c *gin.Context) {
var autoCodeExample autocode.AutoCodeExample
_ = c.ShouldBindJSON(&autoCodeExample)
if err := autoCodeExampleService.CreateAutoCodeExample(autoCodeExample); err != nil {
global.GVA_LOG.Error("创建失败!", zap.Error(err))
response.FailWithMessage("创建失败", c)
} else {
response.OkWithMessage("创建成功", c)
}
}
// @Tags AutoCodeExample
// @Summary 删除AutoCodeExample
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body autocode.AutoCodeExample true "AutoCodeExample模型"
// @Success 200 {object} response.Response{msg=string} "删除AutoCodeExample"
// @Router /autoCodeExample/deleteAutoCodeExample [delete]
func (autoCodeExampleApi *AutoCodeExampleApi) DeleteAutoCodeExample(c *gin.Context) {
var autoCodeExample autocode.AutoCodeExample
_ = c.ShouldBindJSON(&autoCodeExample)
if err := autoCodeExampleService.DeleteAutoCodeExample(autoCodeExample); err != nil {
global.GVA_LOG.Error("删除失败!", zap.Error(err))
response.FailWithMessage("删除失败", c)
} else {
response.OkWithMessage("删除成功", c)
}
}
// @Tags AutoCodeExample
// @Summary 更新AutoCodeExample
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body autocode.AutoCodeExample true "更新AutoCodeExample"
// @Success 200 {object} response.Response{msg=string} "更新AutoCodeExample"
// @Router /autoCodeExample/updateAutoCodeExample [put]
func (autoCodeExampleApi *AutoCodeExampleApi) UpdateAutoCodeExample(c *gin.Context) {
var autoCodeExample autocode.AutoCodeExample
_ = c.ShouldBindJSON(&autoCodeExample)
if err := autoCodeExampleService.UpdateAutoCodeExample(&autoCodeExample); err != nil {
global.GVA_LOG.Error("更新失败!", zap.Error(err))
response.FailWithMessage("更新失败", c)
} else {
response.OkWithMessage("更新成功", c)
}
}
// @Tags AutoCodeExample
// @Summary 用id查询AutoCodeExample
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query autocode.AutoCodeExample true "用id查询AutoCodeExample"
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "用id查询AutoCodeExample"
// @Router /autoCodeExample/findAutoCodeExample [get]
func (autoCodeExampleApi *AutoCodeExampleApi) FindAutoCodeExample(c *gin.Context) {
var autoCodeExample autocode.AutoCodeExample
_ = c.ShouldBindQuery(&autoCodeExample)
if err := utils.Verify(autoCodeExample, utils.IdVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if err, reAutoCodeExample := autoCodeExampleService.GetAutoCodeExample(autoCodeExample.ID); err != nil {
global.GVA_LOG.Error("查询失败!", zap.Error(err))
response.FailWithMessage("查询失败", c)
} else {
response.OkWithDetailed(gin.H{"reAutoCodeExample": reAutoCodeExample}, "查询成功", c)
}
}
// @Tags AutoCodeExample
// @Summary 分页获取AutoCodeExample列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query autocodeReq.AutoCodeExampleSearch true "页码, 每页大小, 搜索条件"
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "分页获取AutoCodeExample列表,返回包括列表,总数,页码,每页数量"
// @Router /autoCodeExample/getAutoCodeExampleList [get]
func (autoCodeExampleApi *AutoCodeExampleApi) GetAutoCodeExampleList(c *gin.Context) {
var pageInfo autocodeReq.AutoCodeExampleSearch
_ = c.ShouldBindQuery(&pageInfo)
if err, list, total := autoCodeExampleService.GetAutoCodeExampleInfoList(pageInfo); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Error(err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithDetailed(response.PageResult{
List: list,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, "获取成功", c)
}
}

View File

@@ -1,7 +0,0 @@
package autocode
type ApiGroup struct {
// Code generated by github.com/flipped-aurora/gin-vue-admin/server Begin; DO NOT EDIT.
AutoCodeExampleApi
// Code generated by github.com/flipped-aurora/gin-vue-admin/server End; DO NOT EDIT.
}

View File

@@ -1,7 +1,6 @@
package v1
import (
"github.com/flipped-aurora/gin-vue-admin/server/api/v1/autocode"
"github.com/flipped-aurora/gin-vue-admin/server/api/v1/example"
"github.com/flipped-aurora/gin-vue-admin/server/api/v1/system"
)
@@ -9,7 +8,6 @@ import (
type ApiGroup struct {
SystemApiGroup system.ApiGroup
ExampleApiGroup example.ApiGroup
AutoCodeApiGroup autocode.ApiGroup
}
var ApiGroupApp = new(ApiGroup)

View File

@@ -5,6 +5,7 @@ import (
"fmt"
"net/url"
"os"
"strings"
"github.com/flipped-aurora/gin-vue-admin/server/global"
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
@@ -33,6 +34,7 @@ func (autoApi *AutoCodeApi) PreviewTemp(c *gin.Context) {
response.FailWithMessage(err.Error(), c)
return
}
a.PackageT = strings.Title(a.Package)
autoCode, err := autoCodeService.PreviewTemp(a)
if err != nil {
global.GVA_LOG.Error("预览失败!", zap.Error(err))
@@ -69,6 +71,7 @@ func (autoApi *AutoCodeApi) CreateTemp(c *gin.Context) {
apiIds = ids
}
}
a.PackageT = strings.Title(a.Package)
err := autoCodeService.CreateTemp(a, apiIds...)
if err != nil {
if errors.Is(err, system.AutoMoveErr) {
@@ -142,3 +145,71 @@ func (autoApi *AutoCodeApi) GetColumn(c *gin.Context) {
}
response.OkWithDetailed(gin.H{"columns": columns}, "获取成功", c)
}
// CreatePackage
// @Tags AutoCode
// @Summary 创建package
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body system.SysAutoCode true "创建package"
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "创建package成功"
// @Router /autoCode/createPackage [post]
func (autoApi *AutoCodeApi) CreatePackage(c *gin.Context) {
var a system.SysAutoCode
_ = c.ShouldBindJSON(&a)
if err := utils.Verify(a, utils.AutoPackageVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err := autoCodeService.CreateAutoCode(&a)
if err != nil {
global.GVA_LOG.Error("创建成功!", zap.Error(err))
response.FailWithMessage("创建失败", c)
} else {
response.OkWithMessage("创建成功", c)
}
}
// GetPackage
// @Tags AutoCode
// @Summary 获取package
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "创建package成功"
// @Router /autoCode/getPackage [post]
func (autoApi *AutoCodeApi) GetPackage(c *gin.Context) {
pkgs,err := autoCodeService.GetPackage()
if err != nil {
global.GVA_LOG.Error("获取失败!", zap.Error(err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithDetailed(gin.H{"pkgs": pkgs},"获取成功", c)
}
}
// DelPackage
// @Tags AutoCode
// @Summary 删除package
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body system.SysAutoCode true "创建package"
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "删除package成功"
// @Router /autoCode/delPackage [post]
func (autoApi *AutoCodeApi) DelPackage(c *gin.Context) {
var a system.SysAutoCode
_ = c.ShouldBindJSON(&a)
err := autoCodeService.DelPackage(a)
if err != nil {
global.GVA_LOG.Error("删除失败!", zap.Error(err))
response.FailWithMessage("删除失败", c)
} else {
response.OkWithMessage("删除成功", c)
}
}