Merge remote-tracking branch 'origin/main'
This commit is contained in:
@@ -76,13 +76,16 @@ func (s *SystemApiApi) SyncApi(c *gin.Context) {
|
||||
// @Success 200 {object} response.Response{msg=string} "获取API分组"
|
||||
// @Router /api/getApiGroups [post]
|
||||
func (s *SystemApiApi) GetApiGroups(c *gin.Context) {
|
||||
groups, err := apiService.GetApiGroups()
|
||||
groups, apiGroupMap, err := apiService.GetApiGroups()
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Error(err))
|
||||
response.FailWithMessage("获取失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(groups, c)
|
||||
response.OkWithData(gin.H{
|
||||
"groups": groups,
|
||||
"apiGroupMap": apiGroupMap,
|
||||
}, c)
|
||||
}
|
||||
|
||||
// IgnoreApi
|
||||
|
@@ -229,6 +229,7 @@ type AutoCodeField struct {
|
||||
type AutoFunc struct {
|
||||
Package string `json:"package"`
|
||||
FuncName string `json:"funcName"` // 方法名称
|
||||
Router string `json:"router"` // 路由名称
|
||||
BusinessDB string `json:"businessDB"` // 业务库
|
||||
StructName string `json:"structName"` // Struct名称
|
||||
PackageName string `json:"packageName"` // 文件名称
|
||||
|
@@ -7,7 +7,7 @@
|
||||
// @Param data query request.{{.StructName}}Search true "分页获取{{.Description}}列表"
|
||||
// @Success 200 {object} response.Response{data=object,msg=string} "获取成功"
|
||||
// @Router /{{.Abbreviation}}/{{.FuncName}} [{{.Method}}]
|
||||
func (a *{{.Abbreviation}}) {{.FuncName}}(c *gin.Context) {
|
||||
func (a *{{.Abbreviation}}) {{.Router}}(c *gin.Context) {
|
||||
// 请添加自己的业务逻辑
|
||||
err := service{{ .StructName }}.{{.FuncName}}()
|
||||
if err != nil {
|
||||
@@ -27,14 +27,15 @@ func (a *{{.Abbreviation}}) {{.FuncName}}(c *gin.Context) {
|
||||
// @Produce application/json
|
||||
// @Param data query {{.Package}}Req.{{.StructName}}Search true "成功"
|
||||
// @Success 200 {object} response.Response{data=object,msg=string} "成功"
|
||||
// @Router /{{.Abbreviation}}/{{.FuncName}} [{{.Method}}]
|
||||
// @Router /{{.Abbreviation}}/{{.Router}} [{{.Method}}]
|
||||
func ({{.Abbreviation}}Api *{{.StructName}}Api){{.FuncName}}(c *gin.Context) {
|
||||
// 请添加自己的业务逻辑
|
||||
if err := {{.Abbreviation}}Service.{{.FuncName}}(); err != nil {
|
||||
// 请添加自己的业务逻辑
|
||||
if err := {{.Abbreviation}}Service.{{.FuncName}}()
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("失败!", zap.Error(err))
|
||||
response.FailWithMessage("失败", c)
|
||||
} else {
|
||||
response.OkWithData("返回数据",c)
|
||||
return
|
||||
}
|
||||
response.OkWithData("返回数据",c)
|
||||
}
|
||||
{{end}}
|
@@ -33,12 +33,13 @@ func ({{.Abbreviation}}Api *{{.StructName}}Api) Create{{.StructName}}(c *gin.Con
|
||||
{{- if .AutoCreateResource }}
|
||||
{{.Abbreviation}}.CreatedBy = utils.GetUserID(c)
|
||||
{{- end }}
|
||||
if err := {{.Abbreviation}}Service.Create{{.StructName}}(&{{.Abbreviation}}); err != nil {
|
||||
err = {{.Abbreviation}}Service.Create{{.StructName}}(&{{.Abbreviation}})
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("创建失败!", zap.Error(err))
|
||||
response.FailWithMessage("创建失败", c)
|
||||
} else {
|
||||
response.OkWithMessage("创建成功", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("创建成功", c)
|
||||
}
|
||||
|
||||
// Delete{{.StructName}} 删除{{.Description}}
|
||||
@@ -53,14 +54,15 @@ func ({{.Abbreviation}}Api *{{.StructName}}Api) Create{{.StructName}}(c *gin.Con
|
||||
func ({{.Abbreviation}}Api *{{.StructName}}Api) Delete{{.StructName}}(c *gin.Context) {
|
||||
{{.PrimaryField.FieldJson}} := c.Query("{{.PrimaryField.FieldJson}}")
|
||||
{{- if .AutoCreateResource }}
|
||||
userID := utils.GetUserID(c)
|
||||
userID := utils.GetUserID(c)
|
||||
{{- end }}
|
||||
if err := {{.Abbreviation}}Service.Delete{{.StructName}}({{.PrimaryField.FieldJson}} {{- if .AutoCreateResource -}},userID{{- end -}}); err != nil {
|
||||
err := {{.Abbreviation}}Service.Delete{{.StructName}}({{.PrimaryField.FieldJson}} {{- if .AutoCreateResource -}},userID{{- end -}})
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("删除失败!", zap.Error(err))
|
||||
response.FailWithMessage("删除失败", c)
|
||||
} else {
|
||||
response.OkWithMessage("删除成功", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("删除成功", c)
|
||||
}
|
||||
|
||||
// Delete{{.StructName}}ByIds 批量删除{{.Description}}
|
||||
@@ -76,12 +78,13 @@ func ({{.Abbreviation}}Api *{{.StructName}}Api) Delete{{.StructName}}ByIds(c *gi
|
||||
{{- if .AutoCreateResource }}
|
||||
userID := utils.GetUserID(c)
|
||||
{{- end }}
|
||||
if err := {{.Abbreviation}}Service.Delete{{.StructName}}ByIds({{.PrimaryField.FieldJson}}s{{- if .AutoCreateResource }},userID{{- end }}); err != nil {
|
||||
err := {{.Abbreviation}}Service.Delete{{.StructName}}ByIds({{.PrimaryField.FieldJson}}s{{- if .AutoCreateResource }},userID{{- end }})
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
|
||||
response.FailWithMessage("批量删除失败", c)
|
||||
} else {
|
||||
response.OkWithMessage("批量删除成功", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("批量删除成功", c)
|
||||
}
|
||||
|
||||
// Update{{.StructName}} 更新{{.Description}}
|
||||
@@ -103,13 +106,13 @@ func ({{.Abbreviation}}Api *{{.StructName}}Api) Update{{.StructName}}(c *gin.Con
|
||||
{{- if .AutoCreateResource }}
|
||||
{{.Abbreviation}}.UpdatedBy = utils.GetUserID(c)
|
||||
{{- end }}
|
||||
|
||||
if err := {{.Abbreviation}}Service.Update{{.StructName}}({{.Abbreviation}}); err != nil {
|
||||
err = {{.Abbreviation}}Service.Update{{.StructName}}({{.Abbreviation}})
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("更新失败!", zap.Error(err))
|
||||
response.FailWithMessage("更新失败", c)
|
||||
} else {
|
||||
response.OkWithMessage("更新成功", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("更新成功", c)
|
||||
}
|
||||
|
||||
// Find{{.StructName}} 用id查询{{.Description}}
|
||||
@@ -123,12 +126,13 @@ func ({{.Abbreviation}}Api *{{.StructName}}Api) Update{{.StructName}}(c *gin.Con
|
||||
// @Router /{{.Abbreviation}}/find{{.StructName}} [get]
|
||||
func ({{.Abbreviation}}Api *{{.StructName}}Api) Find{{.StructName}}(c *gin.Context) {
|
||||
{{.PrimaryField.FieldJson}} := c.Query("{{.PrimaryField.FieldJson}}")
|
||||
if re{{.Abbreviation}}, err := {{.Abbreviation}}Service.Get{{.StructName}}({{.PrimaryField.FieldJson}}); err != nil {
|
||||
re{{.Abbreviation}}, err := {{.Abbreviation}}Service.Get{{.StructName}}({{.PrimaryField.FieldJson}})
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("查询失败!", zap.Error(err))
|
||||
response.FailWithMessage("查询失败", c)
|
||||
} else {
|
||||
response.OkWithData(re{{.Abbreviation}}, c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(re{{.Abbreviation}}, c)
|
||||
}
|
||||
|
||||
// Get{{.StructName}}List 分页获取{{.Description}}列表
|
||||
@@ -147,17 +151,18 @@ func ({{.Abbreviation}}Api *{{.StructName}}Api) Get{{.StructName}}List(c *gin.Co
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
if list, total, err := {{.Abbreviation}}Service.Get{{.StructName}}InfoList(pageInfo); err != nil {
|
||||
list, total, err := {{.Abbreviation}}Service.Get{{.StructName}}InfoList(pageInfo)
|
||||
if 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)
|
||||
return
|
||||
}
|
||||
response.OkWithDetailed(response.PageResult{
|
||||
List: list,
|
||||
Total: total,
|
||||
Page: pageInfo.Page,
|
||||
PageSize: pageInfo.PageSize,
|
||||
}, "获取成功", c)
|
||||
}
|
||||
|
||||
{{- if .HasDataSource }}
|
||||
@@ -170,12 +175,13 @@ func ({{.Abbreviation}}Api *{{.StructName}}Api) Get{{.StructName}}List(c *gin.Co
|
||||
// @Router /{{.Abbreviation}}/get{{.StructName}}DataSource [get]
|
||||
func ({{.Abbreviation}}Api *{{.StructName}}Api) Get{{.StructName}}DataSource(c *gin.Context) {
|
||||
// 此接口为获取数据源定义的数据
|
||||
if dataSource, err := {{.Abbreviation}}Service.Get{{.StructName}}DataSource(); err != nil {
|
||||
dataSource, err := {{.Abbreviation}}Service.Get{{.StructName}}DataSource()
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("查询失败!", zap.Error(err))
|
||||
response.FailWithMessage("查询失败", c)
|
||||
} else {
|
||||
response.OkWithData(dataSource, c)
|
||||
}
|
||||
return
|
||||
}
|
||||
response.OkWithData(dataSource, c)
|
||||
}
|
||||
{{- end }}
|
||||
|
||||
|
@@ -80,7 +80,8 @@ func (a *{{.Abbreviation}}) Delete{{.StructName}}ByIds(c *gin.Context) {
|
||||
{{- if .AutoCreateResource }}
|
||||
userID := utils.GetUserID(c)
|
||||
{{- end }}
|
||||
if err := service{{ .StructName }}.Delete{{.StructName}}ByIds({{.PrimaryField.FieldJson}}s{{- if .AutoCreateResource }},userID{{- end }}); err != nil {
|
||||
err := service{{ .StructName }}.Delete{{.StructName}}ByIds({{.PrimaryField.FieldJson}}s{{- if .AutoCreateResource }},userID{{- end }})
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
|
||||
response.FailWithMessage("批量删除失败", c)
|
||||
return
|
||||
@@ -105,7 +106,7 @@ func (a *{{.Abbreviation}}) Update{{.StructName}}(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
{{- if .AutoCreateResource }}
|
||||
{{.Abbreviation}}.UpdatedBy = utils.GetUserID(c)
|
||||
info.UpdatedBy = utils.GetUserID(c)
|
||||
{{- end }}
|
||||
err = service{{ .StructName }}.Update{{.StructName}}(info)
|
||||
if err != nil {
|
||||
|
@@ -220,10 +220,10 @@ func (s *autoCodeTemplate) getTemplateStr(t string, info request.AutoFunc) (stri
|
||||
func (s *autoCodeTemplate) addTemplateToAst(t string, info request.AutoFunc) error {
|
||||
tPath := filepath.Join(global.GVA_CONFIG.AutoCode.Root, global.GVA_CONFIG.AutoCode.Server, "router", info.Package, info.HumpPackageName+".go")
|
||||
funcName := fmt.Sprintf("Init%sRouter", info.StructName)
|
||||
stmtStr := fmt.Sprintf("%sRouterWithoutAuth.%s(\"%s\", %sApi.%s)", info.Abbreviation, info.Method, info.FuncName, info.Abbreviation, info.FuncName)
|
||||
stmtStr := fmt.Sprintf("%sRouterWithoutAuth.%s(\"%s\", %sApi.%s)", info.Abbreviation, info.Method, info.Router, info.Abbreviation, info.FuncName)
|
||||
if info.IsPlugin {
|
||||
tPath = filepath.Join(global.GVA_CONFIG.AutoCode.Root, global.GVA_CONFIG.AutoCode.Server, "plugin", info.Package, "router", info.HumpPackageName+".go")
|
||||
stmtStr = fmt.Sprintf("group.%s(\"%s\", api%s.%s)", info.Method, info.FuncName, info.StructName, info.FuncName)
|
||||
stmtStr = fmt.Sprintf("group.%s(\"%s\", api%s.%s)", info.Method, info.Router, info.StructName, info.FuncName)
|
||||
funcName = "Init"
|
||||
}
|
||||
|
||||
|
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/system"
|
||||
systemRes "github.com/flipped-aurora/gin-vue-admin/server/model/system/response"
|
||||
"gorm.io/gorm"
|
||||
"strings"
|
||||
)
|
||||
|
||||
//@author: [piexlmax](https://github.com/piexlmax)
|
||||
@@ -27,8 +28,26 @@ func (apiService *ApiService) CreateApi(api system.SysApi) (err error) {
|
||||
return global.GVA_DB.Create(&api).Error
|
||||
}
|
||||
|
||||
func (apiService *ApiService) GetApiGroups() (groups []string, err error) {
|
||||
err = global.GVA_DB.Model(&system.SysApi{}).Select("DISTINCT api_group").Pluck("api_group", &groups).Error
|
||||
func (apiService *ApiService) GetApiGroups() (groups []string, groupApiMap map[string]string, err error) {
|
||||
var apis []system.SysApi
|
||||
err = global.GVA_DB.Find(&apis).Error
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
groupApiMap = make(map[string]string, 0)
|
||||
for i := range apis {
|
||||
pathArr := strings.Split(apis[i].Path, "/")
|
||||
newGroup := true
|
||||
for i2 := range groups {
|
||||
if groups[i2] == apis[i].ApiGroup {
|
||||
newGroup = false
|
||||
}
|
||||
}
|
||||
if newGroup {
|
||||
groups = append(groups, apis[i].ApiGroup)
|
||||
}
|
||||
groupApiMap[pathArr[1]] = apis[i].ApiGroup
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
@@ -125,6 +125,7 @@ func (i *initApi) InitializeData(ctx context.Context) (context.Context, error) {
|
||||
{ApiGroup: "代码生成器历史", Method: "POST", Path: "/autoCode/rollback", Description: "回滚自动生成代码"},
|
||||
{ApiGroup: "代码生成器历史", Method: "POST", Path: "/autoCode/getSysHistory", Description: "查询回滚记录"},
|
||||
{ApiGroup: "代码生成器历史", Method: "POST", Path: "/autoCode/delSysHistory", Description: "删除回滚记录"},
|
||||
{ApiGroup: "代码生成器历史", Method: "POST", Path: "/autoCode/addFunc", Description: "增加模板方法"},
|
||||
|
||||
{ApiGroup: "系统字典详情", Method: "PUT", Path: "/sysDictionaryDetail/updateSysDictionaryDetail", Description: "更新字典内容"},
|
||||
{ApiGroup: "系统字典详情", Method: "POST", Path: "/sysDictionaryDetail/createSysDictionaryDetail", Description: "新增字典内容"},
|
||||
|
@@ -127,6 +127,7 @@ func (i *initCasbin) InitializeData(ctx context.Context) (context.Context, error
|
||||
{Ptype: "p", V0: "888", V1: "/autoCode/createPlug", V2: "POST"},
|
||||
{Ptype: "p", V0: "888", V1: "/autoCode/installPlugin", V2: "POST"},
|
||||
{Ptype: "p", V0: "888", V1: "/autoCode/pubPlug", V2: "POST"},
|
||||
{Ptype: "p", V0: "888", V1: "/autoCode/addFunc", V2: "POST"},
|
||||
|
||||
{Ptype: "p", V0: "888", V1: "/sysDictionaryDetail/findSysDictionaryDetail", V2: "GET"},
|
||||
{Ptype: "p", V0: "888", V1: "/sysDictionaryDetail/updateSysDictionaryDetail", V2: "PUT"},
|
||||
|
Reference in New Issue
Block a user