From 0ae41f247c2ffc2ea8cc265281558efc21fb1157 Mon Sep 17 00:00:00 2001 From: linwenxiang <991154416@qq.com> Date: Thu, 3 Sep 2020 21:04:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=BC=E5=AE=B9=E6=89=B9=E9=87=8F=E5=88=A0?= =?UTF-8?q?=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apis/actions/delete.go | 2 +- apis/actions/update.go | 2 +- apis/actions/view.go | 2 +- service/dto/sysjob.go | 28 ++++++++++++++++++++++++---- service/dto/type.go | 1 + 5 files changed, 28 insertions(+), 7 deletions(-) diff --git a/apis/actions/delete.go b/apis/actions/delete.go index bd2f91d..b753a65 100644 --- a/apis/actions/delete.go +++ b/apis/actions/delete.go @@ -39,7 +39,7 @@ func DeleteAction(control dto.Control) gin.HandlerFunc { db = db.WithContext(c).Scopes( Permission(object.TableName(), p), - ).Delete(object) + ).Where(req.GetId()).Delete(object) tools.HasError(db.Error, "删除失败", 500) if db.RowsAffected == 0 { err = errors.New("无权删除该数据") diff --git a/apis/actions/update.go b/apis/actions/update.go index 356c402..fe4dd55 100644 --- a/apis/actions/update.go +++ b/apis/actions/update.go @@ -38,7 +38,7 @@ func UpdateAction(control dto.Control) gin.HandlerFunc { db = db.WithContext(c).Scopes( Permission(object.TableName(), p), - ).Updates(object) + ).Where(req.GetId()).Updates(object) tools.HasError(db.Error, "更新失败", 500) if db.RowsAffected == 0 { err = errors.New("无权更新该数据") diff --git a/apis/actions/view.go b/apis/actions/view.go index 9f291de..695c6cb 100644 --- a/apis/actions/view.go +++ b/apis/actions/view.go @@ -37,7 +37,7 @@ func ViewAction(control dto.Control) gin.HandlerFunc { err = db.WithContext(c).Scopes( Permission(object.TableName(), p), - ).First(object).Error + ).Where(req.GetId()).First(object).Error if errors.Is(err, gorm.ErrRecordNotFound) { tools.HasError(err, "查看失败", 404) } diff --git a/service/dto/sysjob.go b/service/dto/sysjob.go index 4fd62f7..f12b283 100644 --- a/service/dto/sysjob.go +++ b/service/dto/sysjob.go @@ -4,6 +4,7 @@ import ( "github.com/gin-gonic/gin" "go-admin/models" "go-admin/tools/model" + "net/http" ) type SysJobSearch struct { @@ -76,11 +77,25 @@ func (s *SysJobControl) GenerateM() (model.ActiveRecord, error) { }, nil } +func (s *SysJobControl) GetId() interface{} { + return s.JobId +} + type SysJobById struct { - Id int `uri:"id" validate:"required"` + 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) } @@ -90,7 +105,12 @@ func (s *SysJobById) Generate() Control { } func (s *SysJobById) GenerateM() (model.ActiveRecord, error) { - return &models.SysJob{ - JobId: s.Id, - }, nil + return &models.SysJob{}, nil +} + +func (s *SysJobById) GetId() interface{} { + if len(s.Ids) > 0 { + return s.Ids + } + return s.Id } diff --git a/service/dto/type.go b/service/dto/type.go index cb73d76..1083a4f 100644 --- a/service/dto/type.go +++ b/service/dto/type.go @@ -17,4 +17,5 @@ type Control interface { Generate() Control Bind(ctx *gin.Context) error GenerateM() (model.ActiveRecord, error) + GetId() interface{} }