修复指针问题,提取by_id到公共结构体

This commit is contained in:
linwenxiang committed 2020-09-08 20:28:31 +08:00
1 parent 3bd3656d15
commit 0c64d8b927
5 files changed
+43 -26

No files matched your search

+2 -24
View File
@@ -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
}
+1 -2
View File
@@ -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
+2
View File
@@ -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
+38
View File
@@ -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
}
File renamed without changes.