mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-04-23 02:48:34 +08:00
[优化] 将部分在services中抛出异常使用error返回
This commit is contained in:
@@ -4,7 +4,7 @@ import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"github.com/PandaXGO/PandaKit/biz"
|
||||
"errors"
|
||||
"github.com/google/uuid"
|
||||
"gorm.io/gorm"
|
||||
"math/rand"
|
||||
@@ -63,18 +63,24 @@ func (m *DeviceAuth) UnmarshalBinary(data []byte) error {
|
||||
return json.Unmarshal(data, m)
|
||||
}
|
||||
|
||||
func OrgAuthSet(tx *gorm.DB, roleId int64, owner string) {
|
||||
func OrgAuthSet(tx *gorm.DB, roleId int64, owner string) error {
|
||||
if roleId == 0 {
|
||||
return
|
||||
return errors.New("角色Id不能为空")
|
||||
}
|
||||
role, err := services.SysRoleModelDao.FindOrganizationsByRoleId(roleId)
|
||||
biz.ErrIsNil(err, "查询角色数据权限失败")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if role.DataScope != entity.SELFDATASCOPE {
|
||||
biz.IsTrue(len(role.Org) > 0, "该角色下未分配组织权限")
|
||||
if len(role.Org) <= 0 {
|
||||
return errors.New("该角色下未分配组织权限")
|
||||
}
|
||||
tx.Where("org_id in (?)", strings.Split(role.Org, ","))
|
||||
} else {
|
||||
tx.Where("owner = ?", owner)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
func GenerateID() string {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
|
||||
@@ -17,7 +17,7 @@ func InitEvents() {
|
||||
// 监听规则链改变 更新所有绑定改规则链的产品
|
||||
global.EventEmitter.On(events.ProductChainRuleEvent, func(ruleId, codeData string) {
|
||||
global.Log.Infof("规则链%s变更", ruleId)
|
||||
list := services.ProductModelDao.FindList(entity.Product{
|
||||
list, _ := services.ProductModelDao.FindList(entity.Product{
|
||||
RuleChainId: ruleId,
|
||||
})
|
||||
if list != nil {
|
||||
|
||||
@@ -13,7 +13,7 @@ func TestNewRuleChainInstance(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
instance, errs := NewRuleChainInstance(buf)
|
||||
instance, errs := NewRuleChainInstance("11", buf)
|
||||
if len(errs) > 0 {
|
||||
t.Error(errs[0])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user