...
|
...
|
@@ -32,7 +32,7 @@ func (l *SystemAddLogic) SystemAdd(req *types.DepartmentAddRequest) (resp *types |
|
|
var conn = l.svcCtx.DefaultDBConn()
|
|
|
|
|
|
_, list, err := l.svcCtx.DepartmentRepository.Find(l.ctx, conn, domain.NewQueryOptions().
|
|
|
WithOffsetLimit(1, 1).WithCountOnly().
|
|
|
WithOffsetLimit(1, 1).WithFindOnly().
|
|
|
WithKV("companyId", userToken.CompanyId).
|
|
|
WithKV("name", req.Name))
|
|
|
if err != nil {
|
...
|
...
|
@@ -50,7 +50,28 @@ func (l *SystemAddLogic) SystemAdd(req *types.DepartmentAddRequest) (resp *types |
|
|
}
|
|
|
err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error {
|
|
|
_, err = l.svcCtx.DepartmentRepository.Insert(l.ctx, conn, insert)
|
|
|
return err
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
// 用户添加到分组下
|
|
|
if len(req.Ids) > 0 {
|
|
|
_, users, err := l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions().
|
|
|
WithOffsetLimit(1, len(req.Ids)).WithFindOnly().
|
|
|
WithKV("companyId", userToken.CompanyId))
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
for i := range users {
|
|
|
user := users[i]
|
|
|
user.Departments = append(user.Departments, insert.Id)
|
|
|
_, err := l.svcCtx.UserRepository.UpdateWithVersion(l.ctx, conn, user)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return nil
|
|
|
}, true)
|
|
|
if err != nil {
|
|
|
return nil, xerr.NewErrMsgErr("新增分组失败", err)
|
...
|
...
|
|