...
|
...
|
@@ -314,6 +314,53 @@ func (roleService *RoleService) RemoveRole(removeRoleCommand *command.RemoveRole |
|
|
}
|
|
|
}
|
|
|
|
|
|
// 批量移除角色
|
|
|
func (roleService *RoleService) BatchDeleteRole(removeRoleCommand *command.BatchDeleteRoleCommand) (interface{}, error) {
|
|
|
if err := removeRoleCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
if err := transactionContext.StartTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
var roleRepository domain.RoleRepository
|
|
|
if value, err := factory.CreateRoleRepository(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 {
|
|
|
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())
|
|
|
}
|
|
|
return struct{}{}, nil
|
|
|
}
|
|
|
|
|
|
// 取消用户分配的角色
|
|
|
func (roleService *RoleService) UnAssginRoleToUsers(unAssignRoleToUsersCommand *command.UnAssginRoleToUsersCommand) (interface{}, error) {
|
|
|
if err := unAssignRoleToUsersCommand.ValidateCommand(); err != nil {
|
...
|
...
|
@@ -409,10 +456,20 @@ func (roleService *RoleService) UpdateRoleAccessMenus(updateRoleAccessMenusComma |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
roleRepository, role, err := factory.FastPgRole(transactionContext, updateRoleAccessMenusCommand.RoleId)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
role.AccessMenus = updateRoleAccessMenusCommand.AccessMenus
|
|
|
if role, err = roleRepository.Save(role); 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())
|
|
|
}
|
|
|
return nil, nil
|
|
|
return role, nil
|
|
|
}
|
|
|
|
|
|
func NewRoleService(options map[string]interface{}) *RoleService {
|
...
|
...
|
|