修复指针问题,提取by_id到公共结构体
This commit is contained in:
1 parent
3bd3656d15
commit
0c64d8b927
5 files changed
+43
-26
No files matched your search
@@ -5,11 +5,10 @@ import (
|
|||||||
"go-admin/app/admin/models"
|
"go-admin/app/admin/models"
|
||||||
"go-admin/common/dto"
|
"go-admin/common/dto"
|
||||||
models2 "go-admin/common/models"
|
models2 "go-admin/common/models"
|
||||||
"net/http"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type SysJobSearch struct {
|
type SysJobSearch struct {
|
||||||
Pagination `search:"-"`
|
dto.Pagination `search:"-"`
|
||||||
JobId int `form:"jobId" search:"type:exact;column:job_id;table:sys_job"`
|
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"`
|
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"`
|
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 {
|
type SysJobById struct {
|
||||||
Id int `uri:"id" validate:"required"`
|
dto.ObjectById
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SysJobById) Generate() dto.Control {
|
func (s *SysJobById) Generate() dto.Control {
|
||||||
@@ -108,10 +93,3 @@ func (s *SysJobById) Generate() dto.Control {
|
|||||||
func (s *SysJobById) GenerateM() (models2.ActiveRecord, error) {
|
func (s *SysJobById) GenerateM() (models2.ActiveRecord, error) {
|
||||||
return &models.SysJob{}, nil
|
return &models.SysJob{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SysJobById) GetId() interface{} {
|
|
||||||
if len(s.Ids) > 0 {
|
|
||||||
return s.Ids
|
|
||||||
}
|
|
||||||
return s.Id
|
|
||||||
}
|
|
||||||
@@ -5,7 +5,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"go-admin/tools/config"
|
"go-admin/tools/config"
|
||||||
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
|
||||||
"go-admin/tools"
|
"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").
|
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").
|
Joins("left join sys_role on sys_role.role_id = sys_user.role_id").
|
||||||
Where("sys_user.user_id = ?", userId).
|
Where("sys_user.user_id = ?", userId).
|
||||||
Scan(&p).Error
|
Scan(p).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.New("获取用户数据出错 msg:" + err.Error())
|
err = errors.New("获取用户数据出错 msg:" + err.Error())
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
dto2 "go-admin/common/dto"
|
dto2 "go-admin/common/dto"
|
||||||
"go-admin/common/models"
|
"go-admin/common/models"
|
||||||
"go-admin/tools/app"
|
"go-admin/tools/app"
|
||||||
|
"gopkg.in/ffmt.v1"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
@@ -35,6 +36,7 @@ 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
|
||||||
|
|||||||
@@ -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.
Reference in new issue
Block a user