作者 庄敏学

增加调整部门

package command
type BatchRemove struct {
CompanyId int64 `json:"company_id"`
UserIds []int64 `json:"user_ids"`
DepartmentIds []int `json:"department_ids"`
}
... ...
... ... @@ -62,6 +62,13 @@ func (srv SyncDataUserService) FromBusinessAdmin(param *domain.MessageBody) erro
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
err = srv.importUser(&param4)
case "employee/batchRemove":
batchRemove := &command.BatchRemove{}
err = json.Unmarshal(param.Data, batchRemove)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
err = srv.BatchRemove(batchRemove)
default:
log.Logger.Error("action err:" + action)
}
... ... @@ -320,3 +327,38 @@ func (srv SyncDataUserService) importUser(param *command.ImportUserCommand) erro
return nil
}
// BatchRemove 调整部门
func (srv SyncDataUserService) BatchRemove(batchRemove *command.BatchRemove) error {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
userRepo := factory.CreateUserRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
if len(batchRemove.UserIds) > 0 {
for _, item := range batchRemove.UserIds {
user, err := userRepo.FindOne(map[string]interface{}{"id": item, "companyId": batchRemove.CompanyId})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
user.DepartmentId = batchRemove.DepartmentIds
user.UpdatedAt = time.Now()
_, err = userRepo.Update(user)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return nil
}
... ...
... ... @@ -26,6 +26,8 @@ func (repo *UserRepository) Insert(user *domain.User) (*domain.User, error) {
AvatarUrl: user.AvatarUrl,
CompanyId: user.CompanyId,
AdminType: user.AdminType,
DepartmentId: user.DepartmentId,
PositionId: user.PositionId,
Name: user.Name,
Status: user.Status,
UpdatedAt: user.UpdatedAt,
... ... @@ -48,6 +50,8 @@ func (repo *UserRepository) Update(user *domain.User) (*domain.User, error) {
AvatarUrl: user.AvatarUrl,
CompanyId: user.CompanyId,
AdminType: user.AdminType,
DepartmentId: user.DepartmentId,
PositionId: user.PositionId,
Name: user.Name,
Email: user.Email,
Status: user.Status,
... ...