...
|
...
|
@@ -290,34 +290,17 @@ func (roleService *RoleService) RemoveRole(removeRoleCommand *command.RemoveRole |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
// TODO:数据权限
|
|
|
var roleRepository domain.RoleRepository
|
|
|
if value, err := factory.CreateRoleRepository(map[string]interface{}{
|
|
|
batchRemoveRoleService, _ := factory.CreatePgBatchRemoveRoleService(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
roleRepository = value
|
|
|
}
|
|
|
role, err := roleRepository.FindOne(map[string]interface{}{"roleId": removeRoleCommand.RoleId})
|
|
|
if err != nil {
|
|
|
})
|
|
|
|
|
|
if _, err := batchRemoveRoleService.BatchRemove(removeRoleCommand.OperateInfo, []int64{removeRoleCommand.RoleId}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if role == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeRoleCommand.RoleId)))
|
|
|
}
|
|
|
if role.RoleType == domain.RoleTypeAdmin {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, "主管理员角色不可删除")
|
|
|
}
|
|
|
role.DeletedAt = time.Now()
|
|
|
if role, err := roleRepository.Remove(role); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return role, nil
|
|
|
}
|
|
|
return struct{}{}, nil
|
|
|
}
|
|
|
|
|
|
// 批量移除角色
|
...
|
...
|
@@ -335,32 +318,14 @@ func (roleService *RoleService) BatchDeleteRole(removeRoleCommand *command.Batch |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
// TODO:数据权限
|
|
|
var roleRepository domain.RoleRepository
|
|
|
if value, err := factory.CreateRoleRepository(map[string]interface{}{
|
|
|
|
|
|
batchRemoveRoleService, _ := factory.CreatePgBatchRemoveRoleService(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
roleRepository = value
|
|
|
}
|
|
|
for i := range removeRoleCommand.RoleIds {
|
|
|
roleId := removeRoleCommand.RoleIds[i]
|
|
|
role, err := roleRepository.FindOne(map[string]interface{}{"roleId": roleId})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if role == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%v", roleId))
|
|
|
}
|
|
|
if role.RoleType == domain.RoleTypeAdmin {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, "主管理员角色不可删除")
|
|
|
}
|
|
|
role.DeletedAt = time.Now()
|
|
|
if _, err := roleRepository.Remove(role); err != nil {
|
|
|
})
|
|
|
|
|
|
if _, err := batchRemoveRoleService.BatchRemove(removeRoleCommand.OperateInfo, removeRoleCommand.RoleIds); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
...
|
...
|
@@ -423,7 +388,6 @@ func (roleService *RoleService) UpdateRole(updateRoleCommand *command.UpdateRole |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
// TODO:数据权限
|
|
|
roleRepository, role, err := factory.FastPgRole(transactionContext, updateRoleCommand.RoleId)
|
|
|
if err != nil {
|
|
|
return nil, err
|
...
|
...
|
|