代码拉取完成,页面将自动刷新
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
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。