[优化] 将部分在services中抛出异常使用error返回

This commit is contained in:
PandaX
2023-12-29 11:19:17 +08:00
parent 7669cc208a
commit 7abc0a6840
24 changed files with 534 additions and 440 deletions

View File

@@ -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())

View File

@@ -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 {

View File

@@ -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])
}