正在显示
1 个修改的文件
包含
23 行增加
和
2 行删除
| @@ -32,7 +32,7 @@ func (l *SystemAddLogic) SystemAdd(req *types.DepartmentAddRequest) (resp *types | @@ -32,7 +32,7 @@ func (l *SystemAddLogic) SystemAdd(req *types.DepartmentAddRequest) (resp *types | ||
| 32 | var conn = l.svcCtx.DefaultDBConn() | 32 | var conn = l.svcCtx.DefaultDBConn() |
| 33 | 33 | ||
| 34 | _, list, err := l.svcCtx.DepartmentRepository.Find(l.ctx, conn, domain.NewQueryOptions(). | 34 | _, list, err := l.svcCtx.DepartmentRepository.Find(l.ctx, conn, domain.NewQueryOptions(). |
| 35 | - WithOffsetLimit(1, 1).WithCountOnly(). | 35 | + WithOffsetLimit(1, 1).WithFindOnly(). |
| 36 | WithKV("companyId", userToken.CompanyId). | 36 | WithKV("companyId", userToken.CompanyId). |
| 37 | WithKV("name", req.Name)) | 37 | WithKV("name", req.Name)) |
| 38 | if err != nil { | 38 | if err != nil { |
| @@ -50,7 +50,28 @@ func (l *SystemAddLogic) SystemAdd(req *types.DepartmentAddRequest) (resp *types | @@ -50,7 +50,28 @@ func (l *SystemAddLogic) SystemAdd(req *types.DepartmentAddRequest) (resp *types | ||
| 50 | } | 50 | } |
| 51 | err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error { | 51 | err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error { |
| 52 | _, err = l.svcCtx.DepartmentRepository.Insert(l.ctx, conn, insert) | 52 | _, err = l.svcCtx.DepartmentRepository.Insert(l.ctx, conn, insert) |
| 53 | - return err | 53 | + if err != nil { |
| 54 | + return err | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + // 用户添加到分组下 | ||
| 58 | + if len(req.Ids) > 0 { | ||
| 59 | + _, users, err := l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions(). | ||
| 60 | + WithOffsetLimit(1, len(req.Ids)).WithFindOnly(). | ||
| 61 | + WithKV("companyId", userToken.CompanyId)) | ||
| 62 | + if err != nil { | ||
| 63 | + return err | ||
| 64 | + } | ||
| 65 | + for i := range users { | ||
| 66 | + user := users[i] | ||
| 67 | + user.Departments = append(user.Departments, insert.Id) | ||
| 68 | + _, err := l.svcCtx.UserRepository.UpdateWithVersion(l.ctx, conn, user) | ||
| 69 | + if err != nil { | ||
| 70 | + return err | ||
| 71 | + } | ||
| 72 | + } | ||
| 73 | + } | ||
| 74 | + return nil | ||
| 54 | }, true) | 75 | }, true) |
| 55 | if err != nil { | 76 | if err != nil { |
| 56 | return nil, xerr.NewErrMsgErr("新增分组失败", err) | 77 | return nil, xerr.NewErrMsgErr("新增分组失败", err) |
-
请 注册 或 登录 后发表评论