[优化]base模块提出

This commit is contained in:
PandaGoAdmin
2022-08-02 22:37:37 +08:00
parent 0555922a90
commit 2cb23c0ecf
151 changed files with 550 additions and 5255 deletions

View File

@@ -7,9 +7,9 @@ package api
import (
"pandax/apps/{{.PackageName}}/entity"
"pandax/apps/{{.PackageName}}/services"
"pandax/base/ginx"
"pandax/base/ginx"
"pandax/base/utils"
"github.com/XM-GO/PandaKit/restfulx"
"github.com/XM-GO/PandaKit/restfulx"
"github.com/XM-GO/PandaKit/utils"
)
type {{.ClassName}}Api struct {
@@ -23,16 +23,16 @@ type {{.ClassName}}Api struct {
// @Success 200 {string} string "{"code": 200, "data": [...]}"
// @Router /{{.PackageName}}/{{.BusinessName}}/list [get]
// @Security
func (p *{{.ClassName}}Api) Get{{.ClassName}}List(rc *ginx.ReqCtx) {
func (p *{{.ClassName}}Api) Get{{.ClassName}}List(rc *restfulx.ReqCtx) {
data := entity.{{.ClassName}}{}
pageNum := ginx.QueryInt(rc.GinCtx, "pageNum", 1)
pageSize := ginx.QueryInt(rc.GinCtx, "pageSize", 10)
pageNum := restfulx.QueryInt(rc.GinCtx, "pageNum", 1)
pageSize := restfulx.QueryInt(rc.GinCtx, "pageSize", 10)
{{- range $index, $column := .Columns -}}
{{- if eq $column.IsRequired "1" -}}
{{- if eq $column.GoType "string" }}
data.{{$column.GoField}} = rc.GinCtx.Query("{{$column.JsonField}}")
{{- else if or (eq $column.GoType "int") (eq $column.GoType "int64") (eq $column.GoType "uint") (eq $column.GoType "uint64") -}}
data.{{$column.GoField}} = ginx.QueryInt(rc.GinCtx, "{{$column.JsonField}}", 0)
data.{{$column.GoField}} = restfulx.QueryInt(rc.GinCtx, "{{$column.JsonField}}", 0)
{{- end -}}
{{- end -}}
{{- end }}
@@ -54,8 +54,8 @@ func (p *{{.ClassName}}Api) Get{{.ClassName}}List(rc *ginx.ReqCtx) {
// @Success 200 {string} string "{"code": 200, "data": [...]}"
// @Router /{{.PackageName}}/{{.BusinessName}}/{{"{"}}{{.PkJsonField}}{{"}"}} [get]
// @Security
func (p *{{.ClassName}}Api) Get{{.ClassName}}(rc *ginx.ReqCtx) {
{{.PkJsonField}} := ginx.PathParamInt(rc.GinCtx, "{{.PkJsonField}}")
func (p *{{.ClassName}}Api) Get{{.ClassName}}(rc *restfulx.ReqCtx) {
{{.PkJsonField}} := restfulx.PathParamInt(rc.GinCtx, "{{.PkJsonField}}")
p.{{.ClassName}}App.FindOne(int64({{.PkJsonField}}))
}
@@ -69,9 +69,9 @@ func (p *{{.ClassName}}Api) Get{{.ClassName}}(rc *ginx.ReqCtx) {
// @Success 200 {string} string "{"code": 400, "message": "添加失败"}"
// @Router /{{.PackageName}}/{{.BusinessName}} [post]
// @Security X-TOKEN
func (p *{{.ClassName}}Api) Insert{{.ClassName}}(rc *ginx.ReqCtx) {
func (p *{{.ClassName}}Api) Insert{{.ClassName}}(rc *restfulx.ReqCtx) {
var data entity.{{.ClassName}}
ginx.BindJsonAndValid(rc.GinCtx, &data)
restfulx.BindJsonAndValid(rc.GinCtx, &data)
p.{{.ClassName}}App.Insert(data)
}
@@ -86,9 +86,9 @@ func (p *{{.ClassName}}Api) Insert{{.ClassName}}(rc *ginx.ReqCtx) {
// @Success 200 {string} string "{"code": 400, "message": "添加失败"}"
// @Router /{{.PackageName}}/{{.BusinessName}} [put]
// @Security X-TOKEN
func (p *{{.ClassName}}Api) Update{{.ClassName}}(rc *ginx.ReqCtx) {
func (p *{{.ClassName}}Api) Update{{.ClassName}}(rc *restfulx.ReqCtx) {
var data entity.{{.ClassName}}
ginx.BindJsonAndValid(rc.GinCtx, &data)
restfulx.BindJsonAndValid(rc.GinCtx, &data)
p.{{.ClassName}}App.Update(data)
}
@@ -100,7 +100,7 @@ func (p *{{.ClassName}}Api) Update{{.ClassName}}(rc *ginx.ReqCtx) {
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
// @Success 200 {string} string "{"code": 400, "message": "删除失败"}"
// @Router /{{.PackageName}}/{{.BusinessName}}/{{"{"}}{{.PkJsonField}}{{"}"}} [delete]
func (p *{{.ClassName}}Api) Delete{{.ClassName}}(rc *ginx.ReqCtx) {
func (p *{{.ClassName}}Api) Delete{{.ClassName}}(rc *restfulx.ReqCtx) {
{{.PkJsonField}} := rc.GinCtx.Param("{{.PkJsonField}}")
{{.PkJsonField}}s := utils.IdsStrToIdsIntGroup({{.PkJsonField}})

View File

@@ -9,7 +9,7 @@ import (
"github.com/gin-gonic/gin"
"pandax/apps/{{.PackageName}}/api"
"pandax/apps/{{.PackageName}}/services"
"pandax/base/ginx"
"github.com/XM-GO/PandaKit/restfulx"
)
func Init{{.ClassName}}Router(router *gin.RouterGroup) {
@@ -18,29 +18,29 @@ func Init{{.ClassName}}Router(router *gin.RouterGroup) {
}
routerGroup := router.Group("{{.BusinessName}}")
{{.ClassName}}ListLog := ginx.NewLogInfo("获取{{.FunctionName}}分页列表")
{{.ClassName}}ListLog := restfulx.NewLogInfo("获取{{.FunctionName}}分页列表")
routerGroup.GET("list", func(c *gin.Context) {
ginx.NewReqCtx(c).WithLog({{.ClassName}}ListLog).Handle(s.Get{{.ClassName}}List)
restfulx.NewReqCtx(c).WithLog({{.ClassName}}ListLog).Handle(s.Get{{.ClassName}}List)
})
{{.ClassName}}Log := ginx.NewLogInfo("获取{{.FunctionName}}信息")
{{.ClassName}}Log := restfulx.NewLogInfo("获取{{.FunctionName}}信息")
routerGroup.GET(":{{.PkJsonField}}", func(c *gin.Context) {
ginx.NewReqCtx(c).WithLog({{.ClassName}}Log).Handle(s.Get{{.ClassName}})
restfulx.NewReqCtx(c).WithLog({{.ClassName}}Log).Handle(s.Get{{.ClassName}})
})
insert{{.ClassName}}Log := ginx.NewLogInfo("添加{{.FunctionName}}信息")
insert{{.ClassName}}Log := restfulx.NewLogInfo("添加{{.FunctionName}}信息")
routerGroup.POST("", func(c *gin.Context) {
ginx.NewReqCtx(c).WithLog(insert{{.ClassName}}Log).Handle(s.Insert{{.ClassName}})
restfulx.NewReqCtx(c).WithLog(insert{{.ClassName}}Log).Handle(s.Insert{{.ClassName}})
})
update{{.ClassName}}Log := ginx.NewLogInfo("修改{{.FunctionName}}信息")
update{{.ClassName}}Log := restfulx.NewLogInfo("修改{{.FunctionName}}信息")
routerGroup.PUT("", func(c *gin.Context) {
ginx.NewReqCtx(c).WithLog(update{{.ClassName}}Log).Handle(s.Update{{.ClassName}})
restfulx.NewReqCtx(c).WithLog(update{{.ClassName}}Log).Handle(s.Update{{.ClassName}})
})
delete{{.ClassName}}Log := ginx.NewLogInfo("删除{{.FunctionName}}信息")
delete{{.ClassName}}Log := restfulx.NewLogInfo("删除{{.FunctionName}}信息")
routerGroup.DELETE(":{{.PkJsonField}}", func(c *gin.Context) {
ginx.NewReqCtx(c).WithLog(delete{{.ClassName}}Log).Handle(s.Delete{{.ClassName}})
restfulx.NewReqCtx(c).WithLog(delete{{.ClassName}}Log).Handle(s.Delete{{.ClassName}})
})
}

View File

@@ -8,8 +8,8 @@ package services
import (
"pandax/apps/{{.PackageName}}/entity"
"pandax/base/biz"
"pandax/base/global"
"github.com/XM-GO/PandaKit/biz"
"github.com/XM-GO/PandaKit/global"
)
type (