fix 用户列表部门权限
This commit is contained in:
parent
cb8f67abc1
commit
9008192ef5
@ -66,6 +66,7 @@ type DeptDeleteRes struct {
|
|||||||
|
|
||||||
type DeptTreeSelectReq struct {
|
type DeptTreeSelectReq struct {
|
||||||
g.Meta `path:"/dept/treeSelect" tags:"系统后台/部门管理" method:"get" summary:"获取部门树形菜单"`
|
g.Meta `path:"/dept/treeSelect" tags:"系统后台/部门管理" method:"get" summary:"获取部门树形菜单"`
|
||||||
|
ShowOwner bool `p:"showOwner"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type DeptTreeSelectRes struct {
|
type DeptTreeSelectRes struct {
|
||||||
|
@ -50,14 +50,20 @@ func (c *sysDeptController) Delete(ctx context.Context, req *system.DeptDeleteRe
|
|||||||
// TreeSelect 获取部门数据结构数据
|
// TreeSelect 获取部门数据结构数据
|
||||||
func (c *sysDeptController) TreeSelect(ctx context.Context, req *system.DeptTreeSelectReq) (res *system.DeptTreeSelectRes, err error) {
|
func (c *sysDeptController) TreeSelect(ctx context.Context, req *system.DeptTreeSelectReq) (res *system.DeptTreeSelectRes, err error) {
|
||||||
var deptList []*entity.SysDept
|
var deptList []*entity.SysDept
|
||||||
|
currentUser := service.Context().GetLoginUser(ctx)
|
||||||
deptList, err = service.SysDept().GetList(ctx, &system.DeptSearchReq{
|
deptList, err = service.SysDept().GetList(ctx, &system.DeptSearchReq{
|
||||||
Status: "1", //正常状态数据
|
Status: "1", //正常状态数据
|
||||||
ShowAll: true,
|
ShowAll: !req.ShowOwner,
|
||||||
|
UserId: currentUser.Id,
|
||||||
|
UserDeptId: currentUser.DeptId,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
res = new(system.DeptTreeSelectRes)
|
res = new(system.DeptTreeSelectRes)
|
||||||
res.Deps = service.SysDept().GetListTree(0, deptList)
|
topIds := service.SysDept().GetTopIds(deptList)
|
||||||
|
for _, v := range topIds {
|
||||||
|
res.Deps = append(res.Deps, service.SysDept().GetListTree(v, deptList)...)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ package sysDept
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"github.com/gogf/gf/v2/container/garray"
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
"github.com/gogf/gf/v2/text/gstr"
|
"github.com/gogf/gf/v2/text/gstr"
|
||||||
"github.com/gogf/gf/v2/util/gconv"
|
"github.com/gogf/gf/v2/util/gconv"
|
||||||
@ -182,6 +183,24 @@ func (s *sSysDept) GetListTree(pid uint64, list []*entity.SysDept) (deptTree []*
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *sSysDept) GetTopIds(list []*entity.SysDept) (ids []uint64) {
|
||||||
|
arr := garray.NewArray()
|
||||||
|
for _, v1 := range list {
|
||||||
|
tag := true
|
||||||
|
for _, v2 := range list {
|
||||||
|
if v1.ParentId == v2.DeptId {
|
||||||
|
tag = false
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if tag {
|
||||||
|
arr.PushRight(v1.ParentId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ids = gconv.Uint64s(arr.Unique().Slice())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// GetByDeptId 通过部门id获取部门信息
|
// GetByDeptId 通过部门id获取部门信息
|
||||||
func (s *sSysDept) GetByDeptId(ctx context.Context, deptId uint64) (dept *entity.SysDept, err error) {
|
func (s *sSysDept) GetByDeptId(ctx context.Context, deptId uint64) (dept *entity.SysDept, err error) {
|
||||||
var depts []*entity.SysDept
|
var depts []*entity.SysDept
|
||||||
|
@ -958,7 +958,7 @@ func (s *sSysUser) GetDataWhere(ctx context.Context, userInfo *model.ContextUser
|
|||||||
deptIdArr.Add(gconv.Int64(userInfo.DeptId))
|
deptIdArr.Add(gconv.Int64(userInfo.DeptId))
|
||||||
//获取正常状态部门数据
|
//获取正常状态部门数据
|
||||||
deptList := ([]*entity.SysDept)(nil)
|
deptList := ([]*entity.SysDept)(nil)
|
||||||
deptList, err = service.SysDept().GetList(ctx, &system.DeptSearchReq{Status: "1"})
|
deptList, err = service.SysDept().GetList(ctx, &system.DeptSearchReq{Status: "1", ShowAll: true})
|
||||||
liberr.ErrIsNil(ctx, err)
|
liberr.ErrIsNil(ctx, err)
|
||||||
var dList g.List
|
var dList g.List
|
||||||
for _, d := range deptList {
|
for _, d := range deptList {
|
||||||
@ -1059,7 +1059,7 @@ func (s *sSysUser) GetAuthDataWhere(ctx context.Context, m *gdb.Model, userInfo
|
|||||||
deptIdArr.Add(gconv.Int64(userInfo.DeptId))
|
deptIdArr.Add(gconv.Int64(userInfo.DeptId))
|
||||||
//获取正常状态部门数据
|
//获取正常状态部门数据
|
||||||
deptList := ([]*entity.SysDept)(nil)
|
deptList := ([]*entity.SysDept)(nil)
|
||||||
deptList, err = service.SysDept().GetList(ctx, &system.DeptSearchReq{Status: "1"})
|
deptList, err = service.SysDept().GetList(ctx, &system.DeptSearchReq{Status: "1", ShowAll: true})
|
||||||
liberr.ErrIsNil(ctx, err)
|
liberr.ErrIsNil(ctx, err)
|
||||||
var dList g.List
|
var dList g.List
|
||||||
for _, d := range deptList {
|
for _, d := range deptList {
|
||||||
@ -1166,7 +1166,7 @@ func (s *sSysUser) GetAuthDeptDataWhere(ctx context.Context, m *gdb.Model, userI
|
|||||||
deptIdArr.Add(gconv.Int64(userInfo.DeptId))
|
deptIdArr.Add(gconv.Int64(userInfo.DeptId))
|
||||||
//获取正常状态部门数据
|
//获取正常状态部门数据
|
||||||
deptList := ([]*entity.SysDept)(nil)
|
deptList := ([]*entity.SysDept)(nil)
|
||||||
deptList, err = service.SysDept().GetList(ctx, &system.DeptSearchReq{Status: "1"})
|
deptList, err = service.SysDept().GetList(ctx, &system.DeptSearchReq{Status: "1", ShowAll: true})
|
||||||
liberr.ErrIsNil(ctx, err)
|
liberr.ErrIsNil(ctx, err)
|
||||||
var dList g.List
|
var dList g.List
|
||||||
for _, d := range deptList {
|
for _, d := range deptList {
|
||||||
|
@ -23,6 +23,7 @@ type ISysDept interface {
|
|||||||
GetListTree(pid uint64, list []*entity.SysDept) (deptTree []*model.SysDeptTreeRes)
|
GetListTree(pid uint64, list []*entity.SysDept) (deptTree []*model.SysDeptTreeRes)
|
||||||
GetByDeptId(ctx context.Context, deptId uint64) (dept *entity.SysDept, err error)
|
GetByDeptId(ctx context.Context, deptId uint64) (dept *entity.SysDept, err error)
|
||||||
GetByDept(ctx context.Context, deptId interface{}) (dept *model.LinkDeptRes)
|
GetByDept(ctx context.Context, deptId interface{}) (dept *model.LinkDeptRes)
|
||||||
|
GetTopIds(list []*entity.SysDept) (ids []uint64)
|
||||||
}
|
}
|
||||||
|
|
||||||
var localSysDept ISysDept
|
var localSysDept ISysDept
|
||||||
|
Loading…
x
Reference in New Issue
Block a user