1 Star 0 Fork 0

iThings/core

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
userAreaApplyDealLogic.go 2.65 KB
一键复制 编辑 原始数据 按行查看 历史
杨磊 提交于 2024-08-21 11:34 . feat: 完善项目
package datamanagelogic
import (
"context"
"gitee.com/i-Things/core/service/syssvr/internal/repo/relationDB"
"gitee.com/i-Things/share/ctxs"
"gitee.com/i-Things/share/def"
"gitee.com/i-Things/share/errors"
"gitee.com/i-Things/share/stores"
"gorm.io/gorm"
"gitee.com/i-Things/core/service/syssvr/internal/svc"
"gitee.com/i-Things/core/service/syssvr/pb/sys"
"github.com/zeromicro/go-zero/core/logx"
)
type UserAreaApplyDealLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewUserAreaApplyDealLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserAreaApplyDealLogic {
return &UserAreaApplyDealLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *UserAreaApplyDealLogic) UserAreaApplyDeal(in *sys.UserAreaApplyDealReq) (*sys.Empty, error) {
if !in.IsApprove {
err := relationDB.NewUserAreaApplyRepo(l.ctx).DeleteByFilter(l.ctx, relationDB.UserAreaApplyFilter{IDs: in.Ids})
return &sys.Empty{}, err
}
uc := ctxs.GetUserCtx(l.ctx)
db := stores.GetTenantConn(l.ctx)
err := db.Transaction(func(tx *gorm.DB) error {
uaa := relationDB.NewUserAreaApplyRepo(tx)
ua := relationDB.NewDataAreaRepo(tx)
dp := relationDB.NewDataProjectRepo(tx)
uaas, err := uaa.FindByFilter(l.ctx, relationDB.UserAreaApplyFilter{IDs: in.Ids}, nil)
if err != nil {
return err
}
if len(uaas) == 0 {
return errors.Parameter.AddMsgf("未查询到授权的id")
}
var uas []*relationDB.SysDataArea
var authUserIDs []int64
for _, v := range uaas {
uas = append(uas, &relationDB.SysDataArea{
TargetType: def.TargetUser,
TargetID: v.UserID,
ProjectID: v.ProjectID,
AreaID: int64(v.AreaID),
AuthType: v.AuthType,
})
authUserIDs = append(authUserIDs, v.UserID)
}
authd, err := dp.FindByFilter(l.ctx, relationDB.DataProjectFilter{TargetType: def.TargetUser, TargetIDs: authUserIDs}, nil)
if err != nil {
return err
}
var authSet map[int64]struct{}
for _, v := range authd {
authSet[v.TargetID] = struct{}{}
}
var needAuthUser []*relationDB.SysDataProject
for _, v := range authUserIDs {
if _, ok := authSet[v]; !ok {
needAuthUser = append(needAuthUser, &relationDB.SysDataProject{
ProjectID: uc.ProjectID,
TargetType: def.TargetUser,
TargetID: v,
AuthType: def.AuthRead,
})
}
}
if len(needAuthUser) != 0 {
err = dp.MultiInsert(l.ctx, needAuthUser)
if err != nil {
return err
}
}
err = ua.MultiInsert(l.ctx, uas)
if err != nil {
return err
}
err = uaa.DeleteByFilter(l.ctx, relationDB.UserAreaApplyFilter{IDs: in.Ids})
if err != nil {
return err
}
return nil
})
return &sys.Empty{}, err
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/i-Things/core.git
git@gitee.com:i-Things/core.git
i-Things
core
core
v0.1.6

搜索帮助