fix🐛 :修复角色数据权限更新失(#380)
This commit is contained in:
1 parent
91c9a2c7f9
commit
86c7c64a32
5 files changed
+104
-96
No files matched your search
@@ -50,7 +50,7 @@ type SysRoleControl struct {
|
||||
Flag string `form:"flag" comment:"标记"` // 标记
|
||||
Remark string `form:"remark" comment:"备注"` // 备注
|
||||
Admin bool `form:"admin" comment:"是否管理员"`
|
||||
DataScope string `form:"dataScope" comment:"是否管理员"`
|
||||
DataScope string `form:"dataScope"`
|
||||
MenuIds []int `json:"menuIds"`
|
||||
}
|
||||
|
||||
@@ -123,4 +123,4 @@ type RoleDataScopeReq struct {
|
||||
|
||||
type DeptIdList struct {
|
||||
DeptId int `json:"DeptId"`
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package service
|
||||
|
||||
import (
|
||||
"errors"
|
||||
log "github.com/go-admin-team/go-admin-core/logger"
|
||||
"github.com/go-admin-team/go-admin-core/sdk/pkg"
|
||||
|
||||
"gorm.io/gorm"
|
||||
@@ -220,66 +221,66 @@ func (e *SysDept) deptPageCall(deptlist *[]system.SysDept, menu system.SysDept)
|
||||
return menu
|
||||
}
|
||||
|
||||
//// GetRoleDeptId 获取角色的部门ID集合
|
||||
//func (e *SysDept) GetRoleDeptId(roleId int) ([]int, error) {
|
||||
// deptIds := make([]int, 0)
|
||||
// deptList := make([]dto.DeptIdList, 0)
|
||||
// if err := e.Orm.Table("sys_role_dept").
|
||||
// Select("sys_role_dept.dept_id").
|
||||
// Joins("LEFT JOIN sys_dept on sys_dept.dept_id=sys_role_dept.dept_id").
|
||||
// Where("role_id = ? ", roleId).
|
||||
// Where(" sys_role_dept.dept_id not in(select sys_dept.parent_id from sys_role_dept LEFT JOIN sys_dept on sys_dept.dept_id=sys_role_dept.dept_id where role_id =? )", roleId).
|
||||
// Find(&deptList).Error; err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
//
|
||||
// for i := 0; i < len(deptList); i++ {
|
||||
// deptIds = append(deptIds, deptList[i].DeptId)
|
||||
// }
|
||||
//
|
||||
// return deptIds, nil
|
||||
//}
|
||||
//
|
||||
//func (e *SysDept) SetDeptLabel() (m []dto.DeptLabel, err error) {
|
||||
// list := make([]models.SysDept, 0)
|
||||
// err = e.Orm.Find(&list).Error
|
||||
// if err != nil {
|
||||
// log.Error("find dept list error, %s", e.err)
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// m = make([]dto.DeptLabel, 0)
|
||||
// var item dto.DeptLabel
|
||||
// for i := range list {
|
||||
// if list[i].ParentId != 0 {
|
||||
// continue
|
||||
// }
|
||||
// item = dto.DeptLabel{}
|
||||
// item.Id = list[i].DeptId
|
||||
// item.Label = list[i].DeptName
|
||||
// deptInfo := digitDeptLabel(&list, item)
|
||||
//
|
||||
// m = append(m, deptInfo)
|
||||
// }
|
||||
// return
|
||||
//}
|
||||
//
|
||||
//// digitDeptLabel
|
||||
//func digitDeptLabel(deptList *[]models.SysDept, dept dto.DeptLabel) dto.DeptLabel {
|
||||
// list := *deptList
|
||||
//
|
||||
// var mi dto.DeptLabel
|
||||
// min := make([]dto.DeptLabel, 0)
|
||||
// for j := 0; j < len(list); j++ {
|
||||
//
|
||||
// if dept.Id != list[j].ParentId {
|
||||
// continue
|
||||
// }
|
||||
// mi = dto.DeptLabel{Id: list[j].DeptId, Label: list[j].DeptName, Children: []dto.DeptLabel{}}
|
||||
// ms := digitDeptLabel(deptList, mi)
|
||||
// min = append(min, ms)
|
||||
//
|
||||
// }
|
||||
// dept.Children = min
|
||||
// return dept
|
||||
//}
|
||||
// GetRoleDeptId 获取角色的部门ID集合
|
||||
func (e *SysDept) GetRoleDeptId(roleId int) ([]int, error) {
|
||||
deptIds := make([]int, 0)
|
||||
deptList := make([]dto.DeptIdList, 0)
|
||||
if err := e.Orm.Table("sys_role_dept").
|
||||
Select("sys_role_dept.dept_id").
|
||||
Joins("LEFT JOIN sys_dept on sys_dept.dept_id=sys_role_dept.dept_id").
|
||||
Where("role_id = ? ", roleId).
|
||||
Where(" sys_role_dept.dept_id not in(select sys_dept.parent_id from sys_role_dept LEFT JOIN sys_dept on sys_dept.dept_id=sys_role_dept.dept_id where role_id =? )", roleId).
|
||||
Find(&deptList).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for i := 0; i < len(deptList); i++ {
|
||||
deptIds = append(deptIds, deptList[i].DeptId)
|
||||
}
|
||||
|
||||
return deptIds, nil
|
||||
}
|
||||
|
||||
func (e *SysDept) SetDeptLabel() (m []dto.DeptLabel, err error) {
|
||||
list := make([]system.SysDept, 0)
|
||||
err = e.Orm.Find(&list).Error
|
||||
if err != nil {
|
||||
log.Error("find dept list error, %s", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
m = make([]dto.DeptLabel, 0)
|
||||
var item dto.DeptLabel
|
||||
for i := range list {
|
||||
if list[i].ParentId != 0 {
|
||||
continue
|
||||
}
|
||||
item = dto.DeptLabel{}
|
||||
item.Id = list[i].DeptId
|
||||
item.Label = list[i].DeptName
|
||||
deptInfo := digitDeptLabel(&list, item)
|
||||
|
||||
m = append(m, deptInfo)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// digitDeptLabel
|
||||
func digitDeptLabel(deptList *[]system.SysDept, dept dto.DeptLabel) dto.DeptLabel {
|
||||
list := *deptList
|
||||
|
||||
var mi dto.DeptLabel
|
||||
min := make([]dto.DeptLabel, 0)
|
||||
for j := 0; j < len(list); j++ {
|
||||
|
||||
if dept.Id != list[j].ParentId {
|
||||
continue
|
||||
}
|
||||
mi = dto.DeptLabel{Id: list[j].DeptId, Label: list[j].DeptName, Children: []dto.DeptLabel{}}
|
||||
ms := digitDeptLabel(deptList, mi)
|
||||
min = append(min, ms)
|
||||
|
||||
}
|
||||
dept.Children = min
|
||||
return dept
|
||||
}
|
||||
@@ -197,7 +197,7 @@ func (e *SysRole) UpdateDataScope(c *system.SysRole) (err error) {
|
||||
tx.Commit()
|
||||
}
|
||||
}()
|
||||
err = tx.Model(&system.SysRole{}).Where("role_id = ?", c.RoleId).Select("data_scope, update_by").Updates(c).Error
|
||||
err = tx.Model(&system.SysRole{}).Where("role_id = ?", c.RoleId).Select("data_scope", "update_by").Updates(c).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -221,4 +221,4 @@ func (e *SysRole) UpdateDataScope(c *system.SysRole) (err error) {
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user