作者 郑周

Merge remote-tracking branch 'origin/test' into test

  1 +package command
  2 +
  3 +type BatchRemove struct {
  4 + CompanyId int64 `json:"company_id"`
  5 + UserIds []int64 `json:"user_ids"`
  6 + DepartmentIds []int `json:"department_ids"`
  7 +}
@@ -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(&param4) 64 err = srv.importUser(&param4)
  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 +}
@@ -92,7 +92,7 @@ func (repo *DepartmentRepository) FindOne(queryOptions map[string]interface{}) ( @@ -92,7 +92,7 @@ func (repo *DepartmentRepository) FindOne(queryOptions map[string]interface{}) (
92 func (repo *DepartmentRepository) Find(queryOptions map[string]interface{}) (int, []*domain.Department, error) { 92 func (repo *DepartmentRepository) Find(queryOptions map[string]interface{}) (int, []*domain.Department, error) {
93 tx := repo.transactionContext.PgTx 93 tx := repo.transactionContext.PgTx
94 dparmentModel := []models.Department{} 94 dparmentModel := []models.Department{}
95 - query := tx.Model(&dparmentModel).Where("delete_at isnull") 95 + query := tx.Model(&dparmentModel)
96 if v, ok := queryOptions["id"]; ok { 96 if v, ok := queryOptions["id"]; ok {
97 query.Where("id=?", v) 97 query.Where("id=?", v)
98 } 98 }
@@ -21,16 +21,18 @@ func NewUserRepository(tx *pgTransaction.TransactionContext) *UserRepository { @@ -21,16 +21,18 @@ func NewUserRepository(tx *pgTransaction.TransactionContext) *UserRepository {
21 21
22 func (repo *UserRepository) Insert(user *domain.User) (*domain.User, error) { 22 func (repo *UserRepository) Insert(user *domain.User) (*domain.User, error) {
23 userModel := models.User{ 23 userModel := models.User{
24 - Id: user.Id,  
25 - Account: user.Account,  
26 - AvatarUrl: user.AvatarUrl,  
27 - CompanyId: user.CompanyId,  
28 - AdminType: user.AdminType,  
29 - Name: user.Name,  
30 - Status: user.Status,  
31 - UpdatedAt: user.UpdatedAt,  
32 - CreatedAt: user.CreatedAt,  
33 - DeletedAt: user.DeletedAt, 24 + Id: user.Id,
  25 + Account: user.Account,
  26 + AvatarUrl: user.AvatarUrl,
  27 + CompanyId: user.CompanyId,
  28 + AdminType: user.AdminType,
  29 + DepartmentId: user.DepartmentId,
  30 + PositionId: user.PositionId,
  31 + Name: user.Name,
  32 + Status: user.Status,
  33 + UpdatedAt: user.UpdatedAt,
  34 + CreatedAt: user.CreatedAt,
  35 + DeletedAt: user.DeletedAt,
34 } 36 }
35 tx := repo.transactionContext.PgTx 37 tx := repo.transactionContext.PgTx
36 _, err := tx.Model(&userModel).Insert() 38 _, err := tx.Model(&userModel).Insert()
@@ -43,17 +45,19 @@ func (repo *UserRepository) Insert(user *domain.User) (*domain.User, error) { @@ -43,17 +45,19 @@ func (repo *UserRepository) Insert(user *domain.User) (*domain.User, error) {
43 45
44 func (repo *UserRepository) Update(user *domain.User) (*domain.User, error) { 46 func (repo *UserRepository) Update(user *domain.User) (*domain.User, error) {
45 userModel := models.User{ 47 userModel := models.User{
46 - Id: user.Id,  
47 - Account: user.Account,  
48 - AvatarUrl: user.AvatarUrl,  
49 - CompanyId: user.CompanyId,  
50 - AdminType: user.AdminType,  
51 - Name: user.Name,  
52 - Email: user.Email,  
53 - Status: user.Status,  
54 - UpdatedAt: user.UpdatedAt,  
55 - CreatedAt: user.CreatedAt,  
56 - DeletedAt: user.DeletedAt, 48 + Id: user.Id,
  49 + Account: user.Account,
  50 + AvatarUrl: user.AvatarUrl,
  51 + CompanyId: user.CompanyId,
  52 + AdminType: user.AdminType,
  53 + DepartmentId: user.DepartmentId,
  54 + PositionId: user.PositionId,
  55 + Name: user.Name,
  56 + Email: user.Email,
  57 + Status: user.Status,
  58 + UpdatedAt: user.UpdatedAt,
  59 + CreatedAt: user.CreatedAt,
  60 + DeletedAt: user.DeletedAt,
57 } 61 }
58 tx := repo.transactionContext.PgTx 62 tx := repo.transactionContext.PgTx
59 _, err := tx.Model(&userModel).WherePK().Update() 63 _, err := tx.Model(&userModel).WherePK().Update()