...
|
...
|
@@ -62,6 +62,13 @@ func (srv SyncDataUserService) FromBusinessAdmin(param *domain.MessageBody) erro |
|
|
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
err = srv.importUser(¶m4)
|
|
|
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
|
|
|
} |
...
|
...
|
|