|
@@ -290,34 +290,17 @@ func (roleService *RoleService) RemoveRole(removeRoleCommand *command.RemoveRole |
|
@@ -290,34 +290,17 @@ func (roleService *RoleService) RemoveRole(removeRoleCommand *command.RemoveRole |
|
290
|
defer func() {
|
290
|
defer func() {
|
|
291
|
transactionContext.RollbackTransaction()
|
291
|
transactionContext.RollbackTransaction()
|
|
292
|
}()
|
292
|
}()
|
|
293
|
- // TODO:数据权限
|
|
|
|
294
|
- var roleRepository domain.RoleRepository
|
|
|
|
295
|
- if value, err := factory.CreateRoleRepository(map[string]interface{}{
|
293
|
+ batchRemoveRoleService, _ := factory.CreatePgBatchRemoveRoleService(map[string]interface{}{
|
|
296
|
"transactionContext": transactionContext,
|
294
|
"transactionContext": transactionContext,
|
|
297
|
- }); err != nil {
|
|
|
|
298
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
|
299
|
- } else {
|
|
|
|
300
|
- roleRepository = value
|
|
|
|
301
|
- }
|
|
|
|
302
|
- role, err := roleRepository.FindOne(map[string]interface{}{"roleId": removeRoleCommand.RoleId})
|
|
|
|
303
|
- if err != nil {
|
295
|
+ })
|
|
|
|
296
|
+
|
|
|
|
297
|
+ if _, err := batchRemoveRoleService.BatchRemove(removeRoleCommand.OperateInfo, []int64{removeRoleCommand.RoleId}); err != nil {
|
|
304
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
298
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
305
|
}
|
299
|
}
|
|
306
|
- if role == nil {
|
|
|
|
307
|
- return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeRoleCommand.RoleId)))
|
|
|
|
308
|
- }
|
|
|
|
309
|
- if role.RoleType == domain.RoleTypeAdmin {
|
|
|
|
310
|
- return nil, application.ThrowError(application.BUSINESS_ERROR, "主管理员角色不可删除")
|
|
|
|
311
|
- }
|
|
|
|
312
|
- role.DeletedAt = time.Now()
|
|
|
|
313
|
- if role, err := roleRepository.Remove(role); err != nil {
|
|
|
|
314
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
|
315
|
- } else {
|
|
|
|
316
|
if err := transactionContext.CommitTransaction(); err != nil {
|
300
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
317
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
301
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
318
|
}
|
302
|
}
|
|
319
|
- return role, nil
|
|
|
|
320
|
- }
|
303
|
+ return struct{}{}, nil
|
|
321
|
}
|
304
|
}
|
|
322
|
|
305
|
|
|
323
|
// 批量移除角色
|
306
|
// 批量移除角色
|
|
@@ -335,32 +318,14 @@ func (roleService *RoleService) BatchDeleteRole(removeRoleCommand *command.Batch |
|
@@ -335,32 +318,14 @@ func (roleService *RoleService) BatchDeleteRole(removeRoleCommand *command.Batch |
|
335
|
defer func() {
|
318
|
defer func() {
|
|
336
|
transactionContext.RollbackTransaction()
|
319
|
transactionContext.RollbackTransaction()
|
|
337
|
}()
|
320
|
}()
|
|
338
|
- // TODO:数据权限
|
|
|
|
339
|
- var roleRepository domain.RoleRepository
|
|
|
|
340
|
- if value, err := factory.CreateRoleRepository(map[string]interface{}{
|
321
|
+
|
|
|
|
322
|
+ batchRemoveRoleService, _ := factory.CreatePgBatchRemoveRoleService(map[string]interface{}{
|
|
341
|
"transactionContext": transactionContext,
|
323
|
"transactionContext": transactionContext,
|
|
342
|
- }); err != nil {
|
|
|
|
343
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
|
344
|
- } else {
|
|
|
|
345
|
- roleRepository = value
|
|
|
|
346
|
- }
|
|
|
|
347
|
- for i := range removeRoleCommand.RoleIds {
|
|
|
|
348
|
- roleId := removeRoleCommand.RoleIds[i]
|
|
|
|
349
|
- role, err := roleRepository.FindOne(map[string]interface{}{"roleId": roleId})
|
|
|
|
350
|
- if err != nil {
|
|
|
|
351
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
|
352
|
- }
|
|
|
|
353
|
- if role == nil {
|
|
|
|
354
|
- return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%v", roleId))
|
|
|
|
355
|
- }
|
|
|
|
356
|
- if role.RoleType == domain.RoleTypeAdmin {
|
|
|
|
357
|
- return nil, application.ThrowError(application.BUSINESS_ERROR, "主管理员角色不可删除")
|
|
|
|
358
|
- }
|
|
|
|
359
|
- role.DeletedAt = time.Now()
|
|
|
|
360
|
- if _, err := roleRepository.Remove(role); err != nil {
|
324
|
+ })
|
|
|
|
325
|
+
|
|
|
|
326
|
+ if _, err := batchRemoveRoleService.BatchRemove(removeRoleCommand.OperateInfo, removeRoleCommand.RoleIds); err != nil {
|
|
361
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
327
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
362
|
}
|
328
|
}
|
|
363
|
- }
|
|
|
|
364
|
|
329
|
|
|
365
|
if err := transactionContext.CommitTransaction(); err != nil {
|
330
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
366
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
331
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
@@ -423,7 +388,6 @@ func (roleService *RoleService) UpdateRole(updateRoleCommand *command.UpdateRole |
|
@@ -423,7 +388,6 @@ func (roleService *RoleService) UpdateRole(updateRoleCommand *command.UpdateRole |
|
423
|
defer func() {
|
388
|
defer func() {
|
|
424
|
transactionContext.RollbackTransaction()
|
389
|
transactionContext.RollbackTransaction()
|
|
425
|
}()
|
390
|
}()
|
|
426
|
- // TODO:数据权限
|
|
|
|
427
|
roleRepository, role, err := factory.FastPgRole(transactionContext, updateRoleCommand.RoleId)
|
391
|
roleRepository, role, err := factory.FastPgRole(transactionContext, updateRoleCommand.RoleId)
|
|
428
|
if err != nil {
|
392
|
if err != nil {
|
|
429
|
return nil, err
|
393
|
return nil, err
|