From f3e0e4dbc67f9820fdadbebbf6493f26721c4b6f Mon Sep 17 00:00:00 2001 From: linwenxiang <991154416@qq.com> Date: Tue, 22 Sep 2020 20:39:11 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=80=E5=8C=96=E4=BB=A3=E7=A0=81=E7=94=9F?= =?UTF-8?q?=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/actions/index.go | 2 -- common/actions/view.go | 10 ++++------ common/dto/pagination.go | 14 ++++++++++++++ common/models/by.go | 8 ++++++++ template/v2/dto.go.template | 8 -------- template/v2/model.go.template | 8 -------- 6 files changed, 26 insertions(+), 24 deletions(-) diff --git a/common/actions/index.go b/common/actions/index.go index a58911d3..a7febf7c 100644 --- a/common/actions/index.go +++ b/common/actions/index.go @@ -29,8 +29,6 @@ func IndexAction(m models.ActiveRecord, d dto2.Index, f func() interface{}) gin. case *gorm.DB: //查询列表 db := idb.(*gorm.DB) - err = c.Bind(req) - tools.HasError(err, "参数验证失败", 422) err = req.Bind(c) tools.HasError(err, "参数验证失败", 422) diff --git a/common/actions/view.go b/common/actions/view.go index 01458057..3eb5408b 100644 --- a/common/actions/view.go +++ b/common/actions/view.go @@ -2,19 +2,18 @@ package actions import ( "errors" - dto2 "go-admin/common/dto" - "go-admin/common/models" - "go-admin/tools/app" - "gopkg.in/ffmt.v1" "github.com/gin-gonic/gin" "gorm.io/gorm" + "go-admin/common/dto" + "go-admin/common/models" "go-admin/tools" + "go-admin/tools/app" ) // ViewAction 通用详情动作 -func ViewAction(control dto2.Control) gin.HandlerFunc { +func ViewAction(control dto.Control) gin.HandlerFunc { return func(c *gin.Context) { var err error idb, exist := c.Get("db") @@ -36,7 +35,6 @@ func ViewAction(control dto2.Control) gin.HandlerFunc { //数据权限检查 p := getPermissionFromContext(c) - ffmt.P(object) err = db.WithContext(c).Scopes( Permission(object.TableName(), p), ).Where(req.GetId()).First(object).Error diff --git a/common/dto/pagination.go b/common/dto/pagination.go index 37c2bc01..ee438e58 100644 --- a/common/dto/pagination.go +++ b/common/dto/pagination.go @@ -4,3 +4,17 @@ type Pagination struct { PageIndex int `form:"pageIndex"` PageSize int `form:"pageSize"` } + +func (m *Pagination) GetPageIndex() int { + if m.PageIndex <= 0 { + m.PageIndex = 1 + } + return m.PageIndex +} + +func (m *Pagination) GetPageSize() int { + if m.PageSize <= 0 { + m.PageSize = 10 + } + return m.PageSize +} diff --git a/common/models/by.go b/common/models/by.go index afe259eb..1bf7de87 100644 --- a/common/models/by.go +++ b/common/models/by.go @@ -4,3 +4,11 @@ type ControlBy struct { CreateBy uint `gorm:"index;comment:'创建者'"` UpdateBy uint `gorm:"index;comment:'更新者'"` } + +func (e *ControlBy) SetCreateBy(createBy uint) { + e.CreateBy = createBy +} + +func (e *ControlBy) SetUpdateBy(updateBy uint) { + e.UpdateBy = updateBy +} diff --git a/template/v2/dto.go.template b/template/v2/dto.go.template index b0169b3b..81974bf0 100644 --- a/template/v2/dto.go.template +++ b/template/v2/dto.go.template @@ -34,14 +34,6 @@ func (m *{{.ClassName}}Search) Generate() dto.Index { return &o } -func (m *{{.ClassName}}Search) GetPageIndex() int { - return m.PageIndex -} - -func (m *{{.ClassName}}Search) GetPageSize() int { - return m.PageSize -} - type {{.ClassName}}Control struct { {{ range .Columns -}} {{$x := .Pk}} diff --git a/template/v2/model.go.template b/template/v2/model.go.template index 4183a0ec..ecbebbe8 100644 --- a/template/v2/model.go.template +++ b/template/v2/model.go.template @@ -41,11 +41,3 @@ func (e *{{.ClassName}}) Generate() models.ActiveRecord { func (e *{{.ClassName}}) GetId() interface{} { return e.{{.PkGoField}} } - -func (e *{{.ClassName}}) SetCreateBy(createBy uint) { - e.CreateBy = createBy -} - -func (e *{{.ClassName}}) SetUpdateBy(updateBy uint) { - e.UpdateBy = updateBy -}