正在显示
3 个修改的文件
包含
53 行增加
和
0 行删除
pkg/application/user/command/batch_remove.go
0 → 100644
@@ -62,6 +62,13 @@ func (srv SyncDataUserService) FromBusinessAdmin(param *domain.MessageBody) erro | @@ -62,6 +62,13 @@ func (srv SyncDataUserService) FromBusinessAdmin(param *domain.MessageBody) erro | ||
62 | return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 62 | return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
63 | } | 63 | } |
64 | err = srv.importUser(¶m4) | 64 | err = srv.importUser(¶m4) |
65 | + case "employee/batchRemove": | ||
66 | + batchRemove := &command.BatchRemove{} | ||
67 | + err = json.Unmarshal(param.Data, batchRemove) | ||
68 | + if err != nil { | ||
69 | + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
70 | + } | ||
71 | + err = srv.BatchRemove(batchRemove) | ||
65 | default: | 72 | default: |
66 | log.Logger.Error("action err:" + action) | 73 | log.Logger.Error("action err:" + action) |
67 | } | 74 | } |
@@ -320,3 +327,38 @@ func (srv SyncDataUserService) importUser(param *command.ImportUserCommand) erro | @@ -320,3 +327,38 @@ func (srv SyncDataUserService) importUser(param *command.ImportUserCommand) erro | ||
320 | 327 | ||
321 | return nil | 328 | return nil |
322 | } | 329 | } |
330 | + | ||
331 | +// BatchRemove 调整部门 | ||
332 | +func (srv SyncDataUserService) BatchRemove(batchRemove *command.BatchRemove) error { | ||
333 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
334 | + if err != nil { | ||
335 | + return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
336 | + } | ||
337 | + if err := transactionContext.StartTransaction(); err != nil { | ||
338 | + return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
339 | + } | ||
340 | + defer func() { | ||
341 | + _ = transactionContext.RollbackTransaction() | ||
342 | + }() | ||
343 | + userRepo := factory.CreateUserRepository(map[string]interface{}{ | ||
344 | + "transactionContext": transactionContext, | ||
345 | + }) | ||
346 | + if len(batchRemove.UserIds) > 0 { | ||
347 | + for _, item := range batchRemove.UserIds { | ||
348 | + user, err := userRepo.FindOne(map[string]interface{}{"id": item, "companyId": batchRemove.CompanyId}) | ||
349 | + if err != nil { | ||
350 | + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
351 | + } | ||
352 | + user.DepartmentId = batchRemove.DepartmentIds | ||
353 | + user.UpdatedAt = time.Now() | ||
354 | + _, err = userRepo.Update(user) | ||
355 | + if err != nil { | ||
356 | + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
357 | + } | ||
358 | + } | ||
359 | + } | ||
360 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
361 | + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
362 | + } | ||
363 | + return nil | ||
364 | +} |
@@ -26,6 +26,8 @@ func (repo *UserRepository) Insert(user *domain.User) (*domain.User, error) { | @@ -26,6 +26,8 @@ func (repo *UserRepository) Insert(user *domain.User) (*domain.User, error) { | ||
26 | AvatarUrl: user.AvatarUrl, | 26 | AvatarUrl: user.AvatarUrl, |
27 | CompanyId: user.CompanyId, | 27 | CompanyId: user.CompanyId, |
28 | AdminType: user.AdminType, | 28 | AdminType: user.AdminType, |
29 | + DepartmentId: user.DepartmentId, | ||
30 | + PositionId: user.PositionId, | ||
29 | Name: user.Name, | 31 | Name: user.Name, |
30 | Status: user.Status, | 32 | Status: user.Status, |
31 | UpdatedAt: user.UpdatedAt, | 33 | UpdatedAt: user.UpdatedAt, |
@@ -48,6 +50,8 @@ func (repo *UserRepository) Update(user *domain.User) (*domain.User, error) { | @@ -48,6 +50,8 @@ func (repo *UserRepository) Update(user *domain.User) (*domain.User, error) { | ||
48 | AvatarUrl: user.AvatarUrl, | 50 | AvatarUrl: user.AvatarUrl, |
49 | CompanyId: user.CompanyId, | 51 | CompanyId: user.CompanyId, |
50 | AdminType: user.AdminType, | 52 | AdminType: user.AdminType, |
53 | + DepartmentId: user.DepartmentId, | ||
54 | + PositionId: user.PositionId, | ||
51 | Name: user.Name, | 55 | Name: user.Name, |
52 | Email: user.Email, | 56 | Email: user.Email, |
53 | Status: user.Status, | 57 | Status: user.Status, |
-
请 注册 或 登录 后发表评论