1 Star 0 Fork 0

iThings/core

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
dataProjectCreateLogic.go 1.71 KB
一键复制 编辑 原始数据 按行查看 历史
杨磊 提交于 2024-07-20 00:54 . feat: 完善项目
package datamanagelogic
import (
"context"
"gitee.com/i-Things/core/service/syssvr/internal/repo/cache"
"gitee.com/i-Things/core/service/syssvr/internal/repo/relationDB"
"gitee.com/i-Things/core/service/syssvr/internal/svc"
"gitee.com/i-Things/core/service/syssvr/pb/sys"
"gitee.com/i-Things/share/ctxs"
"gitee.com/i-Things/share/def"
"gitee.com/i-Things/share/errors"
"github.com/zeromicro/go-zero/core/logx"
)
type DataProjectCreateLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewDataProjectCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DataProjectCreateLogic {
return &DataProjectCreateLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *DataProjectCreateLogic) DataProjectCreate(in *sys.DataProjectSaveReq) (*sys.Empty, error) {
if in.TargetID == 0 {
return nil, errors.Parameter.AddDetail(in.TargetID).WithMsg("TargetID参数必填")
}
uc := ctxs.GetUserCtx(l.ctx)
if in.ProjectID != 0 {
uc.ProjectID = in.ProjectID
} else {
in.ProjectID = uc.ProjectID
}
project, err := relationDB.NewProjectInfoRepo(l.ctx).FindOne(l.ctx, in.ProjectID)
if err != nil {
return nil, err
}
if !(uc.IsAdmin || uc.UserID == project.AdminUserID && in.TargetType != def.TargetRole) {
return nil, errors.Permissions.WithMsg("只有管理员才有权限授权")
}
err = relationDB.NewDataProjectRepo(l.ctx).Insert(l.ctx, &relationDB.SysDataProject{
ProjectID: in.ProjectID,
TargetType: in.TargetType,
TargetID: in.TargetID,
AuthType: in.AuthType,
})
if err != nil && errors.Cmp(err, errors.Duplicate) {
return nil, err
}
if in.TargetType == def.TargetUser {
cache.ClearProjectAuth(in.TargetID)
}
return &sys.Empty{}, nil
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/i-Things/core.git
git@gitee.com:i-Things/core.git
i-Things
core
core
v0.1.6

搜索帮助