简化代码生成
This commit is contained in:
1 parent
72a876f37a
commit
f3e0e4dbc6
6 files changed
+26
-24
No files matched your search
@@ -29,8 +29,6 @@ func IndexAction(m models.ActiveRecord, d dto2.Index, f func() interface{}) gin.
|
|||||||
case *gorm.DB:
|
case *gorm.DB:
|
||||||
//查询列表
|
//查询列表
|
||||||
db := idb.(*gorm.DB)
|
db := idb.(*gorm.DB)
|
||||||
err = c.Bind(req)
|
|
||||||
tools.HasError(err, "参数验证失败", 422)
|
|
||||||
err = req.Bind(c)
|
err = req.Bind(c)
|
||||||
tools.HasError(err, "参数验证失败", 422)
|
tools.HasError(err, "参数验证失败", 422)
|
||||||
|
|
||||||
|
|||||||
@@ -2,19 +2,18 @@ package actions
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
dto2 "go-admin/common/dto"
|
|
||||||
"go-admin/common/models"
|
|
||||||
"go-admin/tools/app"
|
|
||||||
"gopkg.in/ffmt.v1"
|
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
|
||||||
|
"go-admin/common/dto"
|
||||||
|
"go-admin/common/models"
|
||||||
"go-admin/tools"
|
"go-admin/tools"
|
||||||
|
"go-admin/tools/app"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ViewAction 通用详情动作
|
// ViewAction 通用详情动作
|
||||||
func ViewAction(control dto2.Control) gin.HandlerFunc {
|
func ViewAction(control dto.Control) gin.HandlerFunc {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
var err error
|
var err error
|
||||||
idb, exist := c.Get("db")
|
idb, exist := c.Get("db")
|
||||||
@@ -36,7 +35,6 @@ func ViewAction(control dto2.Control) gin.HandlerFunc {
|
|||||||
//数据权限检查
|
//数据权限检查
|
||||||
p := getPermissionFromContext(c)
|
p := getPermissionFromContext(c)
|
||||||
|
|
||||||
ffmt.P(object)
|
|
||||||
err = db.WithContext(c).Scopes(
|
err = db.WithContext(c).Scopes(
|
||||||
Permission(object.TableName(), p),
|
Permission(object.TableName(), p),
|
||||||
).Where(req.GetId()).First(object).Error
|
).Where(req.GetId()).First(object).Error
|
||||||
|
|||||||
@@ -4,3 +4,17 @@ type Pagination struct {
|
|||||||
PageIndex int `form:"pageIndex"`
|
PageIndex int `form:"pageIndex"`
|
||||||
PageSize int `form:"pageSize"`
|
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
|
||||||
|
}
|
||||||
@@ -4,3 +4,11 @@ type ControlBy struct {
|
|||||||
CreateBy uint `gorm:"index;comment:'创建者'"`
|
CreateBy uint `gorm:"index;comment:'创建者'"`
|
||||||
UpdateBy 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
|
||||||
|
}
|
||||||
@@ -34,14 +34,6 @@ func (m *{{.ClassName}}Search) Generate() dto.Index {
|
|||||||
return &o
|
return &o
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *{{.ClassName}}Search) GetPageIndex() int {
|
|
||||||
return m.PageIndex
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *{{.ClassName}}Search) GetPageSize() int {
|
|
||||||
return m.PageSize
|
|
||||||
}
|
|
||||||
|
|
||||||
type {{.ClassName}}Control struct {
|
type {{.ClassName}}Control struct {
|
||||||
{{ range .Columns -}}
|
{{ range .Columns -}}
|
||||||
{{$x := .Pk}}
|
{{$x := .Pk}}
|
||||||
|
|||||||
@@ -41,11 +41,3 @@ func (e *{{.ClassName}}) Generate() models.ActiveRecord {
|
|||||||
func (e *{{.ClassName}}) GetId() interface{} {
|
func (e *{{.ClassName}}) GetId() interface{} {
|
||||||
return e.{{.PkGoField}}
|
return e.{{.PkGoField}}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *{{.ClassName}}) SetCreateBy(createBy uint) {
|
|
||||||
e.CreateBy = createBy
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *{{.ClassName}}) SetUpdateBy(updateBy uint) {
|
|
||||||
e.UpdateBy = updateBy
|
|
||||||
}
|
|
||||||
Reference in new issue
Block a user