mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-04-30 10:11:26 +08:00
【feature】添加组织数据读取权限
This commit is contained in:
@@ -1,203 +0,0 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/PandaXGO/PandaKit/biz"
|
||||
"github.com/kakuilan/kgo"
|
||||
"pandax/apps/system/entity"
|
||||
"pandax/pkg/global"
|
||||
)
|
||||
|
||||
type (
|
||||
SysDeptModel interface {
|
||||
Insert(data entity.SysDept) *entity.SysDept
|
||||
FindOne(deptId int64) *entity.SysDept
|
||||
FindListPage(page, pageSize int, data entity.SysDept) (*[]entity.SysDept, int64)
|
||||
FindList(data entity.SysDept) *[]entity.SysDept
|
||||
Update(data entity.SysDept) *entity.SysDept
|
||||
Delete(deptId []int64)
|
||||
SelectDept(data entity.SysDept) []entity.SysDept
|
||||
SelectDeptLable(data entity.SysDept) []entity.DeptLable
|
||||
}
|
||||
|
||||
sysDeptModelImpl struct {
|
||||
table string
|
||||
}
|
||||
)
|
||||
|
||||
var SysDeptModelDao SysDeptModel = &sysDeptModelImpl{
|
||||
table: `sys_depts`,
|
||||
}
|
||||
|
||||
func (m *sysDeptModelImpl) Insert(data entity.SysDept) *entity.SysDept {
|
||||
biz.ErrIsNil(global.Db.Table(m.table).Create(&data).Error, "新增部门信息失败")
|
||||
deptPath := "/" + kgo.KConv.Int2Str(data.DeptId)
|
||||
if int(data.ParentId) != 0 {
|
||||
deptP := m.FindOne(data.ParentId)
|
||||
deptPath = deptP.DeptPath + deptPath
|
||||
} else {
|
||||
deptPath = "/0" + deptPath
|
||||
}
|
||||
data.DeptPath = deptPath
|
||||
biz.ErrIsNil(global.Db.Table(m.table).Model(&data).Updates(&data).Error, "修改部门信息失败")
|
||||
return &data
|
||||
}
|
||||
|
||||
func (m *sysDeptModelImpl) FindOne(deptId int64) *entity.SysDept {
|
||||
resData := new(entity.SysDept)
|
||||
err := global.Db.Table(m.table).Where("dept_id = ?", deptId).First(resData).Error
|
||||
biz.ErrIsNil(err, "查询部门信息失败")
|
||||
return resData
|
||||
}
|
||||
|
||||
func (m *sysDeptModelImpl) FindListPage(page, pageSize int, data entity.SysDept) (*[]entity.SysDept, int64) {
|
||||
list := make([]entity.SysDept, 0)
|
||||
var total int64 = 0
|
||||
offset := pageSize * (page - 1)
|
||||
|
||||
db := global.Db.Table(m.table)
|
||||
// 此处填写 where参数判断
|
||||
if data.DeptId != 0 {
|
||||
db = db.Where("dept_id = ?", data.DeptId)
|
||||
}
|
||||
if data.DeptName != "" {
|
||||
db = db.Where("dept_name like ?", "%"+data.DeptName+"%")
|
||||
}
|
||||
if data.Status != "" {
|
||||
db = db.Where("status = ?", data.Status)
|
||||
}
|
||||
if data.DeptPath != "" {
|
||||
db = db.Where("deptPath like %?%", data.DeptPath)
|
||||
}
|
||||
db.Where("delete_time IS NULL")
|
||||
err := db.Count(&total).Error
|
||||
err = db.Limit(pageSize).Offset(offset).Find(&list).Error
|
||||
biz.ErrIsNil(err, "查询部门分页列表信息失败")
|
||||
return &list, total
|
||||
}
|
||||
|
||||
func (m *sysDeptModelImpl) FindList(data entity.SysDept) *[]entity.SysDept {
|
||||
list := make([]entity.SysDept, 0)
|
||||
|
||||
db := global.Db.Table(m.table)
|
||||
// 此处填写 where参数判断
|
||||
if data.DeptId != 0 {
|
||||
db = db.Where("dept_id = ?", data.DeptId)
|
||||
}
|
||||
if data.DeptName != "" {
|
||||
db = db.Where("dept_name like ?", "%"+data.DeptName+"%")
|
||||
}
|
||||
if data.Status != "" {
|
||||
db = db.Where("status = ?", data.Status)
|
||||
}
|
||||
db.Where("delete_time IS NULL")
|
||||
err := db.Order("sort").Find(&list).Error
|
||||
biz.ErrIsNil(err, "查询部门列表信息失败")
|
||||
return &list
|
||||
}
|
||||
|
||||
func (m *sysDeptModelImpl) Update(data entity.SysDept) *entity.SysDept {
|
||||
one := m.FindOne(data.DeptId)
|
||||
|
||||
deptPath := "/" + kgo.KConv.Int2Str(data.DeptId)
|
||||
if int(data.ParentId) != 0 {
|
||||
deptP := m.FindOne(data.ParentId)
|
||||
deptPath = deptP.DeptPath + deptPath
|
||||
} else {
|
||||
deptPath = "/0" + deptPath
|
||||
}
|
||||
data.DeptPath = deptPath
|
||||
|
||||
if data.DeptPath != "" && data.DeptPath != one.DeptPath {
|
||||
biz.ErrIsNil(errors.New("上级部门不允许修改!"), "上级部门不允许修改")
|
||||
}
|
||||
biz.ErrIsNil(global.Db.Table(m.table).Model(&data).Updates(&data).Error, "修改部门信息失败")
|
||||
return &data
|
||||
}
|
||||
|
||||
func (m *sysDeptModelImpl) Delete(deptIds []int64) {
|
||||
err := global.Db.Table(m.table).Delete(&entity.SysDept{}, "dept_id in (?)", deptIds).Error
|
||||
biz.ErrIsNil(err, "删除部门信息失败")
|
||||
return
|
||||
}
|
||||
|
||||
func (m *sysDeptModelImpl) SelectDept(data entity.SysDept) []entity.SysDept {
|
||||
list := m.FindList(data)
|
||||
|
||||
sd := make([]entity.SysDept, 0)
|
||||
li := *list
|
||||
for i := 0; i < len(li); i++ {
|
||||
if li[i].ParentId != 0 {
|
||||
continue
|
||||
}
|
||||
info := Digui(list, li[i])
|
||||
|
||||
sd = append(sd, info)
|
||||
}
|
||||
return sd
|
||||
}
|
||||
|
||||
func (m *sysDeptModelImpl) SelectDeptLable(data entity.SysDept) []entity.DeptLable {
|
||||
deptlist := m.FindList(data)
|
||||
|
||||
dl := make([]entity.DeptLable, 0)
|
||||
deptl := *deptlist
|
||||
for i := 0; i < len(deptl); i++ {
|
||||
if deptl[i].ParentId != 0 {
|
||||
continue
|
||||
}
|
||||
e := entity.DeptLable{}
|
||||
e.DeptId = deptl[i].DeptId
|
||||
e.DeptName = deptl[i].DeptName
|
||||
deptsInfo := DiguiDeptLable(deptlist, e)
|
||||
|
||||
dl = append(dl, deptsInfo)
|
||||
}
|
||||
return dl
|
||||
}
|
||||
|
||||
func Digui(deptlist *[]entity.SysDept, menu entity.SysDept) entity.SysDept {
|
||||
list := *deptlist
|
||||
|
||||
min := make([]entity.SysDept, 0)
|
||||
for j := 0; j < len(list); j++ {
|
||||
|
||||
if menu.DeptId != list[j].ParentId {
|
||||
continue
|
||||
}
|
||||
mi := entity.SysDept{}
|
||||
mi.DeptId = list[j].DeptId
|
||||
mi.ParentId = list[j].ParentId
|
||||
mi.DeptPath = list[j].DeptPath
|
||||
mi.DeptName = list[j].DeptName
|
||||
mi.Sort = list[j].Sort
|
||||
mi.Leader = list[j].Leader
|
||||
mi.Phone = list[j].Phone
|
||||
mi.Email = list[j].Email
|
||||
mi.Status = list[j].Status
|
||||
mi.CreatedAt = list[j].CreatedAt
|
||||
mi.UpdatedAt = list[j].UpdatedAt
|
||||
mi.Children = []entity.SysDept{}
|
||||
ms := Digui(deptlist, mi)
|
||||
min = append(min, ms)
|
||||
}
|
||||
menu.Children = min
|
||||
return menu
|
||||
}
|
||||
func DiguiDeptLable(deptlist *[]entity.SysDept, dept entity.DeptLable) entity.DeptLable {
|
||||
list := *deptlist
|
||||
|
||||
min := make([]entity.DeptLable, 0)
|
||||
for j := 0; j < len(list); j++ {
|
||||
|
||||
if dept.DeptId != list[j].ParentId {
|
||||
continue
|
||||
}
|
||||
mi := entity.DeptLable{list[j].DeptId, list[j].DeptName, []entity.DeptLable{}}
|
||||
ms := DiguiDeptLable(deptlist, mi)
|
||||
min = append(min, ms)
|
||||
|
||||
}
|
||||
dept.Children = min
|
||||
return dept
|
||||
}
|
||||
@@ -88,7 +88,7 @@ func (m *sysDictDataModelImpl) Update(data entity.SysDictData) *entity.SysDictDa
|
||||
}
|
||||
|
||||
func (m *sysDictDataModelImpl) Delete(codeIds []int64) {
|
||||
err := global.Db.Table(m.table).Delete(&entity.SysDept{}, "dict_code in (?)", codeIds).Error
|
||||
err := global.Db.Table(m.table).Delete(&entity.SysOrganization{}, "dict_code in (?)", codeIds).Error
|
||||
biz.ErrIsNil(err, "删除字典数据信息失败")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -9,11 +9,11 @@ import (
|
||||
type (
|
||||
SysDictTypeModel interface {
|
||||
Insert(data entity.SysDictType) *entity.SysDictType
|
||||
FindOne(deptId int64) *entity.SysDictType
|
||||
FindOne(organizationId int64) *entity.SysDictType
|
||||
FindListPage(page, pageSize int, data entity.SysDictType) (*[]entity.SysDictType, int64)
|
||||
FindList(data entity.SysDictType) *[]entity.SysDictType
|
||||
Update(data entity.SysDictType) *entity.SysDictType
|
||||
Delete(deptId []int64)
|
||||
Delete(organizationId []int64)
|
||||
}
|
||||
|
||||
sysDictTypeModelImpl struct {
|
||||
|
||||
@@ -49,8 +49,8 @@ func (m *sysNoticeModelImpl) FindListPage(page, pageSize int, data entity.SysNot
|
||||
if data.NoticeType != "" {
|
||||
db = db.Where("notice_type = ?", data.NoticeType)
|
||||
}
|
||||
if len(data.DeptIds) > 0 {
|
||||
db = db.Where("dept_id in (?)", data.DeptIds)
|
||||
if len(data.OrganizationIds) > 0 {
|
||||
db = db.Where("organization_id in (?)", data.OrganizationIds)
|
||||
}
|
||||
db.Where("delete_time IS NULL")
|
||||
err := db.Count(&total).Error
|
||||
|
||||
237
apps/system/services/organization.go
Normal file
237
apps/system/services/organization.go
Normal file
@@ -0,0 +1,237 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/PandaXGO/PandaKit/biz"
|
||||
"github.com/kakuilan/kgo"
|
||||
"pandax/apps/system/entity"
|
||||
"pandax/pkg/global"
|
||||
)
|
||||
|
||||
type (
|
||||
SysOrganizationModel interface {
|
||||
Insert(data entity.SysOrganization) *entity.SysOrganization
|
||||
FindOne(organizationId int64) *entity.SysOrganization
|
||||
FindListPage(page, pageSize int, data entity.SysOrganization) (*[]entity.SysOrganization, int64)
|
||||
FindList(data entity.SysOrganization) *[]entity.SysOrganization
|
||||
Update(data entity.SysOrganization) *entity.SysOrganization
|
||||
Delete(organizationId []int64)
|
||||
SelectOrganization(data entity.SysOrganization) []entity.SysOrganization
|
||||
SelectOrganizationLable(data entity.SysOrganization) []entity.OrganizationLable
|
||||
SelectOrganizationIds(data entity.SysOrganization) []int64
|
||||
}
|
||||
|
||||
sysOrganizationModelImpl struct {
|
||||
table string
|
||||
}
|
||||
)
|
||||
|
||||
var SysOrganizationModelDao SysOrganizationModel = &sysOrganizationModelImpl{
|
||||
table: `sys_organizations`,
|
||||
}
|
||||
|
||||
func (m *sysOrganizationModelImpl) Insert(data entity.SysOrganization) *entity.SysOrganization {
|
||||
biz.ErrIsNil(global.Db.Table(m.table).Create(&data).Error, "新增组织信息失败")
|
||||
organizationPath := "/" + kgo.KConv.Int2Str(data.OrganizationId)
|
||||
if int(data.ParentId) != 0 {
|
||||
organizationP := m.FindOne(data.ParentId)
|
||||
organizationPath = organizationP.OrganizationPath + organizationPath
|
||||
} else {
|
||||
organizationPath = "/0" + organizationPath
|
||||
}
|
||||
data.OrganizationPath = organizationPath
|
||||
biz.ErrIsNil(global.Db.Table(m.table).Model(&data).Updates(&data).Error, "修改组织信息失败")
|
||||
return &data
|
||||
}
|
||||
|
||||
func (m *sysOrganizationModelImpl) FindOne(organizationId int64) *entity.SysOrganization {
|
||||
resData := new(entity.SysOrganization)
|
||||
err := global.Db.Table(m.table).Where("organization_id = ?", organizationId).First(resData).Error
|
||||
biz.ErrIsNil(err, "查询组织信息失败")
|
||||
return resData
|
||||
}
|
||||
|
||||
func (m *sysOrganizationModelImpl) FindListPage(page, pageSize int, data entity.SysOrganization) (*[]entity.SysOrganization, int64) {
|
||||
list := make([]entity.SysOrganization, 0)
|
||||
var total int64 = 0
|
||||
offset := pageSize * (page - 1)
|
||||
|
||||
db := global.Db.Table(m.table)
|
||||
// 此处填写 where参数判断
|
||||
if data.OrganizationId != 0 {
|
||||
db = db.Where("organization_id = ?", data.OrganizationId)
|
||||
}
|
||||
if data.OrganizationName != "" {
|
||||
db = db.Where("organization_name like ?", "%"+data.OrganizationName+"%")
|
||||
}
|
||||
if data.Status != "" {
|
||||
db = db.Where("status = ?", data.Status)
|
||||
}
|
||||
if data.OrganizationPath != "" {
|
||||
db = db.Where("organizationPath like %?%", data.OrganizationPath)
|
||||
}
|
||||
db.Where("delete_time IS NULL")
|
||||
err := db.Count(&total).Error
|
||||
err = db.Limit(pageSize).Offset(offset).Find(&list).Error
|
||||
biz.ErrIsNil(err, "查询组织分页列表信息失败")
|
||||
return &list, total
|
||||
}
|
||||
|
||||
func (m *sysOrganizationModelImpl) FindList(data entity.SysOrganization) *[]entity.SysOrganization {
|
||||
list := make([]entity.SysOrganization, 0)
|
||||
|
||||
db := global.Db.Table(m.table)
|
||||
// 此处填写 where参数判断
|
||||
if data.OrganizationId != 0 {
|
||||
db = db.Where("organization_id = ?", data.OrganizationId)
|
||||
}
|
||||
if data.OrganizationName != "" {
|
||||
db = db.Where("organization_name like ?", "%"+data.OrganizationName+"%")
|
||||
}
|
||||
if data.Status != "" {
|
||||
db = db.Where("status = ?", data.Status)
|
||||
}
|
||||
db.Where("delete_time IS NULL")
|
||||
err := db.Order("sort").Find(&list).Error
|
||||
biz.ErrIsNil(err, "查询组织列表信息失败")
|
||||
return &list
|
||||
}
|
||||
|
||||
func (m *sysOrganizationModelImpl) Update(data entity.SysOrganization) *entity.SysOrganization {
|
||||
one := m.FindOne(data.OrganizationId)
|
||||
|
||||
organizationPath := "/" + kgo.KConv.Int2Str(data.OrganizationId)
|
||||
if int(data.ParentId) != 0 {
|
||||
organizationP := m.FindOne(data.ParentId)
|
||||
organizationPath = organizationP.OrganizationPath + organizationPath
|
||||
} else {
|
||||
organizationPath = "/0" + organizationPath
|
||||
}
|
||||
data.OrganizationPath = organizationPath
|
||||
|
||||
if data.OrganizationPath != "" && data.OrganizationPath != one.OrganizationPath {
|
||||
biz.ErrIsNil(errors.New("上级组织不允许修改!"), "上级组织不允许修改")
|
||||
}
|
||||
biz.ErrIsNil(global.Db.Table(m.table).Model(&data).Updates(&data).Error, "修改组织信息失败")
|
||||
return &data
|
||||
}
|
||||
|
||||
func (m *sysOrganizationModelImpl) Delete(organizationIds []int64) {
|
||||
err := global.Db.Table(m.table).Delete(&entity.SysOrganization{}, "organization_id in (?)", organizationIds).Error
|
||||
biz.ErrIsNil(err, "删除组织信息失败")
|
||||
return
|
||||
}
|
||||
|
||||
func (m *sysOrganizationModelImpl) SelectOrganization(data entity.SysOrganization) []entity.SysOrganization {
|
||||
list := m.FindList(data)
|
||||
|
||||
sd := make([]entity.SysOrganization, 0)
|
||||
li := *list
|
||||
for i := 0; i < len(li); i++ {
|
||||
if li[i].ParentId != 0 {
|
||||
continue
|
||||
}
|
||||
info := Digui(list, li[i])
|
||||
|
||||
sd = append(sd, info)
|
||||
}
|
||||
return sd
|
||||
}
|
||||
|
||||
func (m *sysOrganizationModelImpl) SelectOrganizationLable(data entity.SysOrganization) []entity.OrganizationLable {
|
||||
organizationlist := m.FindList(data)
|
||||
|
||||
dl := make([]entity.OrganizationLable, 0)
|
||||
organizationl := *organizationlist
|
||||
for i := 0; i < len(organizationl); i++ {
|
||||
if organizationl[i].ParentId != 0 {
|
||||
continue
|
||||
}
|
||||
e := entity.OrganizationLable{}
|
||||
e.OrganizationId = organizationl[i].OrganizationId
|
||||
e.OrganizationName = organizationl[i].OrganizationName
|
||||
organizationsInfo := DiguiOrganizationLable(organizationlist, e)
|
||||
|
||||
dl = append(dl, organizationsInfo)
|
||||
}
|
||||
return dl
|
||||
}
|
||||
|
||||
func (m *sysOrganizationModelImpl) SelectOrganizationIds(data entity.SysOrganization) []int64 {
|
||||
organizationlist := m.FindList(data)
|
||||
dl := make([]int64, 0)
|
||||
organizationl := *organizationlist
|
||||
for i := 0; i < len(organizationl); i++ {
|
||||
if organizationl[i].ParentId != 0 {
|
||||
continue
|
||||
}
|
||||
dl = append(dl, organizationl[i].OrganizationId)
|
||||
e := entity.OrganizationLable{}
|
||||
e.OrganizationId = organizationl[i].OrganizationId
|
||||
e.OrganizationName = organizationl[i].OrganizationName
|
||||
id := DiguiOrganizationId(organizationlist, e)
|
||||
dl = append(dl, id...)
|
||||
}
|
||||
return dl
|
||||
}
|
||||
|
||||
func Digui(organizationlist *[]entity.SysOrganization, menu entity.SysOrganization) entity.SysOrganization {
|
||||
list := *organizationlist
|
||||
|
||||
min := make([]entity.SysOrganization, 0)
|
||||
for j := 0; j < len(list); j++ {
|
||||
|
||||
if menu.OrganizationId != list[j].ParentId {
|
||||
continue
|
||||
}
|
||||
mi := entity.SysOrganization{}
|
||||
mi.OrganizationId = list[j].OrganizationId
|
||||
mi.ParentId = list[j].ParentId
|
||||
mi.OrganizationPath = list[j].OrganizationPath
|
||||
mi.OrganizationName = list[j].OrganizationName
|
||||
mi.Sort = list[j].Sort
|
||||
mi.Leader = list[j].Leader
|
||||
mi.Phone = list[j].Phone
|
||||
mi.Email = list[j].Email
|
||||
mi.Status = list[j].Status
|
||||
mi.CreatedAt = list[j].CreatedAt
|
||||
mi.UpdatedAt = list[j].UpdatedAt
|
||||
mi.Children = []entity.SysOrganization{}
|
||||
ms := Digui(organizationlist, mi)
|
||||
min = append(min, ms)
|
||||
}
|
||||
menu.Children = min
|
||||
return menu
|
||||
}
|
||||
func DiguiOrganizationLable(organizationlist *[]entity.SysOrganization, organization entity.OrganizationLable) entity.OrganizationLable {
|
||||
list := *organizationlist
|
||||
|
||||
min := make([]entity.OrganizationLable, 0)
|
||||
for j := 0; j < len(list); j++ {
|
||||
|
||||
if organization.OrganizationId != list[j].ParentId {
|
||||
continue
|
||||
}
|
||||
mi := entity.OrganizationLable{list[j].OrganizationId, list[j].OrganizationName, []entity.OrganizationLable{}}
|
||||
ms := DiguiOrganizationLable(organizationlist, mi)
|
||||
min = append(min, ms)
|
||||
|
||||
}
|
||||
organization.Children = min
|
||||
return organization
|
||||
}
|
||||
|
||||
func DiguiOrganizationId(organizationlist *[]entity.SysOrganization, organization entity.OrganizationLable) []int64 {
|
||||
list := *organizationlist
|
||||
min := make([]int64, 0)
|
||||
for j := 0; j < len(list); j++ {
|
||||
if organization.OrganizationId != list[j].ParentId {
|
||||
continue
|
||||
}
|
||||
min = append(min, list[j].OrganizationId)
|
||||
mi := entity.OrganizationLable{list[j].OrganizationId, list[j].OrganizationName, []entity.OrganizationLable{}}
|
||||
id := DiguiOrganizationId(organizationlist, mi)
|
||||
min = append(min, id...)
|
||||
}
|
||||
return min
|
||||
}
|
||||
@@ -16,7 +16,7 @@ type (
|
||||
Update(data entity.SysRole) *entity.SysRole
|
||||
Delete(roleId []int64)
|
||||
GetRoleMeunId(data entity.SysRole) []int64
|
||||
GetRoleDeptId(data entity.SysRole) []int64
|
||||
GetRoleOrganizationId(data entity.SysRole) []int64
|
||||
}
|
||||
|
||||
sysRoleModel struct {
|
||||
@@ -119,14 +119,14 @@ func (m *sysRoleModel) GetRoleMeunId(data entity.SysRole) []int64 {
|
||||
return menuIds
|
||||
}
|
||||
|
||||
func (m *sysRoleModel) GetRoleDeptId(data entity.SysRole) []int64 {
|
||||
deptIds := make([]int64, 0)
|
||||
deptList := make([]entity.DeptIdList, 0)
|
||||
err := global.Db.Table("sys_role_depts").Select("sys_role_depts.dept_id").Joins("LEFT JOIN sys_depts on sys_depts.dept_id=sys_role_depts.dept_id").Where("role_id = ? ", data.RoleId).Where(" sys_role_depts.dept_id not in(select sys_depts.parent_id from sys_role_depts LEFT JOIN sys_depts on sys_depts.dept_id=sys_role_depts.dept_id where role_id =? )", data.RoleId).Find(&deptList).Error
|
||||
biz.ErrIsNil(err, "查询角色部门列表失败")
|
||||
func (m *sysRoleModel) GetRoleOrganizationId(data entity.SysRole) []int64 {
|
||||
organizationIds := make([]int64, 0)
|
||||
organizationList := make([]entity.OrganizationIdList, 0)
|
||||
err := global.Db.Table("sys_role_organizations").Select("sys_role_organizations.organization_id").Joins("LEFT JOIN sys_organizations on sys_organizations.organization_id=sys_role_organizations.organization_id").Where("role_id = ? ", data.RoleId).Where(" sys_role_organizations.organization_id not in(select sys_organizations.parent_id from sys_role_organizations LEFT JOIN sys_organizations on sys_organizations.organization_id=sys_role_organizations.organization_id where role_id =? )", data.RoleId).Find(&organizationList).Error
|
||||
biz.ErrIsNil(err, "查询角色组织列表失败")
|
||||
|
||||
for i := 0; i < len(deptList); i++ {
|
||||
deptIds = append(deptIds, deptList[i].DeptId)
|
||||
for i := 0; i < len(organizationList); i++ {
|
||||
organizationIds = append(organizationIds, organizationList[i].OrganizationId)
|
||||
}
|
||||
return deptIds
|
||||
return organizationIds
|
||||
}
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/PandaXGO/PandaKit/biz"
|
||||
"pandax/apps/system/entity"
|
||||
"pandax/pkg/global"
|
||||
)
|
||||
|
||||
type (
|
||||
SysRoleDeptModel interface {
|
||||
Insert(roleId int64, deptIds []int64) bool
|
||||
Delete(rm entity.SysRoleDept)
|
||||
}
|
||||
|
||||
sysRoleDeptImpl struct {
|
||||
table string
|
||||
}
|
||||
)
|
||||
|
||||
var SysRoleDeptModelDao SysRoleDeptModel = &sysRoleDeptImpl{
|
||||
table: `sys_role_depts`,
|
||||
}
|
||||
|
||||
func (m *sysRoleDeptImpl) Insert(roleId int64, deptIds []int64) bool {
|
||||
sql := "INSERT INTO sys_role_depts (role_id, dept_id) VALUES "
|
||||
|
||||
for i := 0; i < len(deptIds); i++ {
|
||||
if len(deptIds)-1 == i {
|
||||
//最后一条数据 以分号结尾
|
||||
sql += fmt.Sprintf("(%d,%d);", roleId, deptIds[i])
|
||||
} else {
|
||||
sql += fmt.Sprintf("(%d,%d),", roleId, deptIds[i])
|
||||
}
|
||||
}
|
||||
global.Db.Exec(sql)
|
||||
return true
|
||||
}
|
||||
|
||||
func (m *sysRoleDeptImpl) Delete(rm entity.SysRoleDept) {
|
||||
biz.ErrIsNil(global.Db.Table(m.table).Where("role_id = ?", rm.RoleId).Delete(&rm).Error, "删除角色失败")
|
||||
return
|
||||
}
|
||||
50
apps/system/services/role_organization.go
Normal file
50
apps/system/services/role_organization.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/PandaXGO/PandaKit/biz"
|
||||
"pandax/apps/system/entity"
|
||||
"pandax/pkg/global"
|
||||
)
|
||||
|
||||
type (
|
||||
SysRoleOrganizationModel interface {
|
||||
Insert(roleId int64, organizationIds []int64) bool
|
||||
FindOrganizationsByRoleId(roleId int64) ([]int64, error)
|
||||
Delete(rm entity.SysRoleOrganization)
|
||||
}
|
||||
|
||||
sysRoleOrganizationImpl struct {
|
||||
table string
|
||||
}
|
||||
)
|
||||
|
||||
var SysRoleOrganizationModelDao SysRoleOrganizationModel = &sysRoleOrganizationImpl{
|
||||
table: `sys_role_organizations`,
|
||||
}
|
||||
|
||||
func (m *sysRoleOrganizationImpl) Insert(roleId int64, organizationIds []int64) bool {
|
||||
sql := "INSERT INTO sys_role_organizations (role_id, organization_id) VALUES "
|
||||
|
||||
for i := 0; i < len(organizationIds); i++ {
|
||||
if len(organizationIds)-1 == i {
|
||||
//最后一条数据 以分号结尾
|
||||
sql += fmt.Sprintf("(%d,%d);", roleId, organizationIds[i])
|
||||
} else {
|
||||
sql += fmt.Sprintf("(%d,%d),", roleId, organizationIds[i])
|
||||
}
|
||||
}
|
||||
global.Db.Exec(sql)
|
||||
return true
|
||||
}
|
||||
|
||||
func (m *sysRoleOrganizationImpl) FindOrganizationsByRoleId(roleId int64) ([]int64, error) {
|
||||
var result []int64
|
||||
err := global.Db.Table(m.table).Where("role_id = ?", roleId).Pluck("organization_id", &result).Error
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (m *sysRoleOrganizationImpl) Delete(rm entity.SysRoleOrganization) {
|
||||
biz.ErrIsNil(global.Db.Table(m.table).Where("role_id = ?", rm.RoleId).Delete(&rm).Error, "删除角色失败")
|
||||
return
|
||||
}
|
||||
@@ -72,8 +72,8 @@ func (m *sysUserModelImpl) FindOne(data entity.SysUser) *entity.SysUserView {
|
||||
if data.RoleId != 0 {
|
||||
db = db.Where("role_id = ?", data.RoleId)
|
||||
}
|
||||
if data.DeptId != 0 {
|
||||
db = db.Where("dept_id = ?", data.DeptId)
|
||||
if data.OrganizationId != 0 {
|
||||
db = db.Where("organization_id = ?", data.OrganizationId)
|
||||
}
|
||||
if data.PostId != 0 {
|
||||
db = db.Where("post_id = ?", data.PostId)
|
||||
@@ -87,8 +87,8 @@ func (m *sysUserModelImpl) FindListPage(page, pageSize int, data entity.SysUser)
|
||||
list := make([]entity.SysUserPage, 0)
|
||||
var total int64 = 0
|
||||
offset := pageSize * (page - 1)
|
||||
db := global.Db.Table(m.table).Select("sys_users.*,sys_depts.dept_name")
|
||||
db = db.Joins("left join sys_depts on sys_depts.dept_id = sys_users.dept_id")
|
||||
db := global.Db.Table(m.table).Select("sys_users.*,sys_organizations.organization_name")
|
||||
db = db.Joins("left join sys_organizations on sys_organizations.organization_id = sys_users.organization_id")
|
||||
// 此处填写 where参数判断
|
||||
if data.Username != "" {
|
||||
db = db.Where("sys_users.username = ?", data.Username)
|
||||
@@ -104,8 +104,8 @@ func (m *sysUserModelImpl) FindListPage(page, pageSize int, data entity.SysUser)
|
||||
if data.Phone != "" {
|
||||
db = db.Where("sys_users.phone like ?", "%"+data.Phone+"%")
|
||||
}
|
||||
if data.DeptId != 0 {
|
||||
db = db.Where("sys_users.dept_id = ?", data.DeptId)
|
||||
if data.OrganizationId != 0 {
|
||||
db = db.Where("sys_users.organization_id = ?", data.OrganizationId)
|
||||
}
|
||||
db.Where("sys_users.delete_time IS NULL")
|
||||
err := db.Count(&total).Error
|
||||
@@ -131,21 +131,22 @@ func (m *sysUserModelImpl) FindList(data entity.SysUser) *[]entity.SysUserView {
|
||||
}
|
||||
|
||||
if data.RoleId != 0 {
|
||||
db = db.Where("role_id = ?", data.RoleId)
|
||||
db = db.Where("sys_users.role_id = ?", data.RoleId)
|
||||
}
|
||||
|
||||
if data.DeptId != 0 {
|
||||
db = db.Where("dept_id = ?", data.DeptId)
|
||||
if data.OrganizationId != 0 {
|
||||
db = db.Where("sys_users.organization_id = ?", data.OrganizationId)
|
||||
}
|
||||
|
||||
if data.PostId != 0 {
|
||||
db = db.Where("post_id = ?", data.PostId)
|
||||
db = db.Where("sys_users.post_id = ?", data.PostId)
|
||||
}
|
||||
if data.Status != "" {
|
||||
db = db.Where("status = ?", data.Status)
|
||||
db = db.Where("sys_users.status = ?", data.Status)
|
||||
}
|
||||
db.Where("sys_users.delete_time IS NULL")
|
||||
biz.ErrIsNil(db.Find(&list).Error, "查询用户列表失败")
|
||||
|
||||
biz.ErrIsNilAppendErr(db.Find(&list).Error, "查询用户列表失败")
|
||||
|
||||
return &list
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user