diff --git a/app/admin/service/dto/sysjob.go b/app/admin/service/dto/sysjob.go index c291bd5..0ba54f9 100644 --- a/app/admin/service/dto/sysjob.go +++ b/app/admin/service/dto/sysjob.go @@ -5,11 +5,10 @@ import ( "go-admin/app/admin/models" "go-admin/common/dto" models2 "go-admin/common/models" - "net/http" ) type SysJobSearch struct { - Pagination `search:"-"` + dto.Pagination `search:"-"` JobId int `form:"jobId" search:"type:exact;column:job_id;table:sys_job"` JobName string `form:"jobName" search:"type:icontains;column:job_name;table:sys_job"` JobGroup string `form:"jobGroup" search:"type:exact;column:job_group;table:sys_job"` @@ -83,21 +82,7 @@ func (s *SysJobControl) GetId() interface{} { } type SysJobById struct { - Id int `uri:"id" validate:"required"` - Ids []int `json:"ids"` -} - -func (s *SysJobById) Bind(ctx *gin.Context) error { - if ctx.Request.Method == http.MethodDelete { - err := ctx.Bind(s) - if err != nil { - return err - } - if len(s.Ids) > 0 { - return nil - } - } - return ctx.BindUri(s) + dto.ObjectById } func (s *SysJobById) Generate() dto.Control { @@ -108,10 +93,3 @@ func (s *SysJobById) Generate() dto.Control { func (s *SysJobById) GenerateM() (models2.ActiveRecord, error) { return &models.SysJob{}, nil } - -func (s *SysJobById) GetId() interface{} { - if len(s.Ids) > 0 { - return s.Ids - } - return s.Id -} diff --git a/common/actions/permission.go b/common/actions/permission.go index 1cefe7b..24747a7 100644 --- a/common/actions/permission.go +++ b/common/actions/permission.go @@ -5,7 +5,6 @@ import ( "fmt" "github.com/gin-gonic/gin" "go-admin/tools/config" - "gorm.io/gorm" "go-admin/tools" @@ -62,7 +61,7 @@ func newDataPermission(tx *gorm.DB, userId interface{}) (*dataPermission, error) Select("sys_user.user_id", "sys_role.role_id", "sys_user.dept_id", "sys_role.data_scope"). Joins("left join sys_role on sys_role.role_id = sys_user.role_id"). Where("sys_user.user_id = ?", userId). - Scan(&p).Error + Scan(p).Error if err != nil { err = errors.New("获取用户数据出错 msg:" + err.Error()) return nil, err diff --git a/common/actions/view.go b/common/actions/view.go index 20d4692..0145805 100644 --- a/common/actions/view.go +++ b/common/actions/view.go @@ -5,6 +5,7 @@ import ( 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" @@ -35,6 +36,7 @@ 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/generate.go b/common/dto/generate.go new file mode 100644 index 0000000..8193059 --- /dev/null +++ b/common/dto/generate.go @@ -0,0 +1,38 @@ +package dto + +import ( + "encoding/json" + "github.com/gin-gonic/gin" + "net/http" +) + +type ObjectById struct { + Id int `uri:"id" validate:"required"` + Ids []json.Number `json:"ids"` +} + +func (s *ObjectById) Bind(ctx *gin.Context) error { + if ctx.Request.Method == http.MethodDelete { + err := ctx.Bind(s) + if err != nil { + return err + } + if len(s.Ids) > 0 { + return nil + } + } + return ctx.BindUri(s) +} + +func (s *ObjectById) GetId() interface{} { + if len(s.Ids) > 0 { + ids := make([]int64, 0) + var i int64 + for _, id := range s.Ids { + i, _ = id.Int64() + ids = append(ids, i) + } + return ids + } + return s.Id +} diff --git a/app/admin/service/dto/pagination.go b/common/dto/pagination.go similarity index 100% rename from app/admin/service/dto/pagination.go rename to common/dto/pagination.go