mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-04-29 13:31:26 +08:00
【feature】添加组织数据读取权限
This commit is contained in:
@@ -36,6 +36,7 @@ func (m *deviceModelImpl) Insert(data entity.Device) *entity.Device {
|
||||
biz.IsTrue(list != nil && len(*list) == 0, "设备名称已经存在")
|
||||
//2 创建认证TOKEN IOTHUB使用
|
||||
etoken := getDeviceToken(&data)
|
||||
// 子网关不需要设置token
|
||||
if data.DeviceType != global.GATEWAYS {
|
||||
data.Token = etoken.Token
|
||||
}
|
||||
@@ -56,6 +57,7 @@ func getDeviceToken(data *entity.Device) *tool.DeviceAuth {
|
||||
now := time.Now()
|
||||
etoken := &tool.DeviceAuth{
|
||||
DeviceId: data.Id,
|
||||
OrgId: data.OrgId,
|
||||
User: data.Owner,
|
||||
Name: data.Name,
|
||||
DeviceType: data.DeviceType,
|
||||
@@ -93,9 +95,6 @@ func (m *deviceModelImpl) FindListPage(page, pageSize int, data entity.Device) (
|
||||
if data.Gid != "" {
|
||||
db = db.Where("gid = ?", data.Gid)
|
||||
}
|
||||
if data.OrgId != "" {
|
||||
db = db.Where("org_id = ?", data.OrgId)
|
||||
}
|
||||
if data.Name != "" {
|
||||
db = db.Where("name like ?", "%"+data.Name+"%")
|
||||
}
|
||||
@@ -114,6 +113,9 @@ func (m *deviceModelImpl) FindListPage(page, pageSize int, data entity.Device) (
|
||||
if data.ParentId != "" {
|
||||
db = db.Where("parent_id = ?", data.ParentId)
|
||||
}
|
||||
// 组织数据访问权限
|
||||
tool.OrgAuthSet(db, data.RoleId)
|
||||
|
||||
err := db.Count(&total).Error
|
||||
err = db.Order("create_time").Preload("Product").Preload("DeviceGroup").Limit(pageSize).Offset(offset).Find(&list).Error
|
||||
biz.ErrIsNil(err, "查询设备分页列表失败")
|
||||
@@ -130,9 +132,6 @@ func (m *deviceModelImpl) FindList(data entity.Device) *[]entity.DeviceRes {
|
||||
if data.Gid != "" {
|
||||
db = db.Where("gid = ?", data.Gid)
|
||||
}
|
||||
if data.OrgId != "" {
|
||||
db = db.Where("org_id = ?", data.OrgId)
|
||||
}
|
||||
if data.Name != "" {
|
||||
db = db.Where("name like ?", "%"+data.Name+"%")
|
||||
}
|
||||
@@ -154,6 +153,7 @@ func (m *deviceModelImpl) FindList(data entity.Device) *[]entity.DeviceRes {
|
||||
if data.ParentId != "" {
|
||||
db = db.Where("parent_id = ?", data.ParentId)
|
||||
}
|
||||
tool.OrgAuthSet(db, data.RoleId)
|
||||
db.Preload("Product").Preload("DeviceGroup")
|
||||
biz.ErrIsNil(db.Order("create_time").Find(&list).Error, "查询设备列表失败")
|
||||
return &list
|
||||
|
||||
@@ -129,20 +129,20 @@ func (m *deviceGroupModelImpl) SelectDeviceGroup(data entity.DeviceGroup) []enti
|
||||
}
|
||||
|
||||
func (m *deviceGroupModelImpl) SelectDeviceGroupLabel(data entity.DeviceGroup) []entity.DeviceGroupLabel {
|
||||
deptlist := m.FindList(data)
|
||||
organizationlist := m.FindList(data)
|
||||
|
||||
dl := make([]entity.DeviceGroupLabel, 0)
|
||||
deptl := *deptlist
|
||||
for i := 0; i < len(deptl); i++ {
|
||||
if deptl[i].Pid != "0" {
|
||||
organizationl := *organizationlist
|
||||
for i := 0; i < len(organizationl); i++ {
|
||||
if organizationl[i].Pid != "0" {
|
||||
continue
|
||||
}
|
||||
e := entity.DeviceGroupLabel{}
|
||||
e.Id = deptl[i].Id
|
||||
e.Name = deptl[i].Name
|
||||
deptsInfo := DiGuiDeviceGroupLabel(deptlist, e)
|
||||
e.Id = organizationl[i].Id
|
||||
e.Name = organizationl[i].Name
|
||||
organizationsInfo := DiGuiDeviceGroupLabel(organizationlist, e)
|
||||
|
||||
dl = append(dl, deptsInfo)
|
||||
dl = append(dl, organizationsInfo)
|
||||
}
|
||||
return dl
|
||||
}
|
||||
@@ -170,12 +170,12 @@ func DiGuiDeviceGroup(sglist *[]entity.DeviceGroup, menu entity.DeviceGroup) ent
|
||||
menu.Children = min
|
||||
return menu
|
||||
}
|
||||
func DiGuiDeviceGroupLabel(sglist *[]entity.DeviceGroup, dept entity.DeviceGroupLabel) entity.DeviceGroupLabel {
|
||||
func DiGuiDeviceGroupLabel(sglist *[]entity.DeviceGroup, organization entity.DeviceGroupLabel) entity.DeviceGroupLabel {
|
||||
list := *sglist
|
||||
|
||||
min := make([]entity.DeviceGroupLabel, 0)
|
||||
for j := 0; j < len(list); j++ {
|
||||
if dept.Id != list[j].Pid {
|
||||
if organization.Id != list[j].Pid {
|
||||
continue
|
||||
}
|
||||
sg := entity.DeviceGroupLabel{list[j].Id, list[j].Name, []entity.DeviceGroupLabel{}}
|
||||
@@ -183,6 +183,6 @@ func DiGuiDeviceGroupLabel(sglist *[]entity.DeviceGroup, dept entity.DeviceGroup
|
||||
min = append(min, ms)
|
||||
|
||||
}
|
||||
dept.Children = min
|
||||
return dept
|
||||
organization.Children = min
|
||||
return organization
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ func (m *productModelImpl) FindListPage(page, pageSize int, data entity.Product)
|
||||
if data.Name != "" {
|
||||
db = db.Where("name like ?", "%"+data.Name+"%")
|
||||
}
|
||||
if data.OrgId != "" {
|
||||
if data.OrgId != 0 {
|
||||
db = db.Where("org_id = ?", data.OrgId)
|
||||
}
|
||||
if data.RuleChainId != "" {
|
||||
@@ -114,7 +114,7 @@ func (m *productModelImpl) FindList(data entity.Product) *[]entity.ProductRes {
|
||||
if data.Name != "" {
|
||||
db = db.Where("name like ?", "%"+data.Name+"%")
|
||||
}
|
||||
if data.OrgId != "" {
|
||||
if data.OrgId != 0 {
|
||||
db = db.Where("org_id = ?", data.OrgId)
|
||||
}
|
||||
if data.RuleChainId != "" {
|
||||
|
||||
@@ -132,17 +132,17 @@ func (m *productCategoryModelImpl) SelectProductCategoryLabel(data entity.Produc
|
||||
list := m.FindList(data)
|
||||
|
||||
dl := make([]entity.ProductCategoryLabel, 0)
|
||||
deptl := *list
|
||||
for i := 0; i < len(deptl); i++ {
|
||||
if deptl[i].Pid != "0" {
|
||||
organizationl := *list
|
||||
for i := 0; i < len(organizationl); i++ {
|
||||
if organizationl[i].Pid != "0" {
|
||||
continue
|
||||
}
|
||||
e := entity.ProductCategoryLabel{}
|
||||
e.Id = deptl[i].Id
|
||||
e.Name = deptl[i].Name
|
||||
deptsInfo := DiGuiProductCategoryLabel(list, e)
|
||||
e.Id = organizationl[i].Id
|
||||
e.Name = organizationl[i].Name
|
||||
organizationsInfo := DiGuiProductCategoryLabel(list, e)
|
||||
|
||||
dl = append(dl, deptsInfo)
|
||||
dl = append(dl, organizationsInfo)
|
||||
}
|
||||
return dl
|
||||
}
|
||||
@@ -170,12 +170,12 @@ func DiGuiProductCategory(sglist *[]entity.ProductCategory, menu entity.ProductC
|
||||
menu.Children = min
|
||||
return menu
|
||||
}
|
||||
func DiGuiProductCategoryLabel(sglist *[]entity.ProductCategory, dept entity.ProductCategoryLabel) entity.ProductCategoryLabel {
|
||||
func DiGuiProductCategoryLabel(sglist *[]entity.ProductCategory, organization entity.ProductCategoryLabel) entity.ProductCategoryLabel {
|
||||
list := *sglist
|
||||
|
||||
min := make([]entity.ProductCategoryLabel, 0)
|
||||
for j := 0; j < len(list); j++ {
|
||||
if dept.Id != list[j].Pid {
|
||||
if organization.Id != list[j].Pid {
|
||||
continue
|
||||
}
|
||||
sg := entity.ProductCategoryLabel{}
|
||||
@@ -185,6 +185,6 @@ func DiGuiProductCategoryLabel(sglist *[]entity.ProductCategory, dept entity.Pro
|
||||
min = append(min, ms)
|
||||
|
||||
}
|
||||
dept.Children = min
|
||||
return dept
|
||||
organization.Children = min
|
||||
return organization
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user