mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-09-21 10:13:01 +00:00
修复指针问题,提取by_id到公共结构体
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package dto
|
||||
|
||||
type Pagination struct {
|
||||
PageIndex int `form:"pageIndex"`
|
||||
PageSize int `form:"pageSize"`
|
||||
}
|
||||
Reference in New Issue
Block a user