Package com.lgx8.right.service.impl

Source Code of com.lgx8.right.service.impl.RoleService

package com.lgx8.right.service.impl;

import java.util.List;
import java.util.Set;

import org.springframework.transaction.annotation.Transactional;

import com.lgx8.common.PageArgument;
import com.lgx8.common.PageList;
import com.lgx8.right.dao.IRoleDao;
import com.lgx8.right.dao.IUserDao;
import com.lgx8.right.entities.Role;
import com.lgx8.right.entities.User;
import com.lgx8.right.service.IRoleService;

/**
*
* @author chenbutao
*/
public class RoleService implements IRoleService {

  private IRoleDao roleDao;
 
  private IUserDao userDao;
 
  public IRoleDao getRoleDao() {
    return roleDao;
  }


  public void setRoleDao(IRoleDao roleDao) {
    this.roleDao = roleDao;
  }


  public IUserDao getUserDao() {
    return userDao;
  }


  public void setUserDao(IUserDao userDao) {
    this.userDao = userDao;
  }
 
  /**
   * 强制删除角色
   */
  @Transactional
  public void ForceDelRole(Integer rid) {
    Role role = roleDao.findRole("id", rid);
    Set<User> users = role.getUsers();
    if (users.size() > 0) {
      for (User user : users) {
        user.getRoles().remove(role);
        userDao.updateUser(user);
      }
      roleDao.deleteRole(role);
     
    } else {
      roleDao.deleteRole(role);
    }
  }
 
  /**
   * 删除角色时返回该角色已授权的用户集合
   */
  @Transactional
  public Set<User> delRole(Integer rid) {
    Role role = roleDao.findRole("id", rid);
    Set<User> users = role.getUsers();
    if (users.size() > 0) {
      return users;
    } else {
      return null;
    }
  }
 
  @Transactional
  public void addRole(Role role) {
    roleDao.createRole(role);
   
  }
 
  @Transactional
  public void updateRole(Role role) {
    roleDao.updateRole(role);
  }
 
  public List<Role> queryAllRoleByUser(Long uid) {
    return roleDao.findRoles("uid", uid);
  }


  public PageList queryRolesByPage(PageArgument pageArgment, String hql,
      Object[] values) {
    int pageNum = pageArgment.getCurPage();
    int pageSize = pageArgment.getPageSize();
    PageList pageList = roleDao.findByPage4Report(hql, values, pageNum, pageSize);
    return pageList;
  }


  public List<Role> queryAllRole() {
   
    return null;
  }

}
TOP

Related Classes of com.lgx8.right.service.impl.RoleService

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.