package com.sp2p.service.admin;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.shove.base.BaseService;
import com.shove.data.DataException;
import com.sp2p.dao.admin.RoleRightsDao;
public class RoleRightsService extends BaseService {
public static Log log = LogFactory.getLog(RoleRightsService.class);
private RoleRightsDao roleRightsDao;
/**
* 根据角色编号查询角色权限信息
*
* @param roleId
* 角色编号
* @return
* @throws DataException
* @throws SQLException
*/
public List<Map<String, Object>> queryRoleRightByRoleId(long roleId) throws DataException, SQLException {
Connection conn = connectionManager.getConnection();
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
try {
list = roleRightsDao.queryRoleRightByRoleId(conn, roleId);
} catch (SQLException e) {
log.error(e);
e.printStackTrace();
throw e;
} catch (DataException e) {
log.error(e);
e.printStackTrace();
throw e;
} finally {
conn.close();
}
return list;
}
/**
* 根据角色编号查询角色权限信息
*
* @param roleId
* 角色编号
* @return
* @throws DataException
* @throws SQLException
*/
public String queryRoleRightsIdByRoleId(long roleId) throws DataException, SQLException {
Connection conn = connectionManager.getConnection();
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
try {
list = roleRightsDao.queryRoleRightsIdByRoleId(conn, roleId);
} catch (SQLException e) {
log.error(e);
e.printStackTrace();
throw e;
} catch (DataException e) {
log.error(e);
e.printStackTrace();
throw e;
} finally {
conn.close();
}
String[] rightIds = new String[list.size()];
int i = 0;
for (Map<String, Object> map : list) {
rightIds[i] = map.get("rightsId").toString();
i++;
}
return StringUtils.join(rightIds, ",");
}
/**
* 根据角色编号查询管理员角色权限信息
*
* @param roleId
* 角色编号
* @return
* @throws SQLException
* @throws DataException
*/
public List<Map<String, Object>> queryAdminRoleRightMenu(long roleId) throws SQLException, DataException {
Connection conn = connectionManager.getConnection();
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
try {
list = roleRightsDao.queryAdminRoleRightMenu(conn, roleId);
} catch (SQLException e) {
log.error(e);
e.printStackTrace();
throw e;
} catch (DataException e) {
log.error(e);
e.printStackTrace();
throw e;
} finally {
conn.close();
}
return list;
}
/**
* 根据角色编号、搜索关键字查询管理员角色权限信息
*
* @param roleId
* 角色编号
* @return
* @throws SQLException
* @throws DataException
*/
public List<Map<String, Object>> queryAdminRoleRightMenuSearch(long roleId, String searchCode) throws Exception {
Connection conn = connectionManager.getConnection();
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
try {
list = roleRightsDao.queryAdminRoleRightMenuSearch(conn, roleId, searchCode);
} catch (Exception e) {
log.error(e);
e.printStackTrace();
throw e;
} finally {
conn.close();
}
return list;
}
/**
* 查询角色是否有权限操作该路径
*
* @param roleId
* 角色编号
* @return 返回ture表示有权限,否则没有权限
* @throws SQLException
* @throws DataException
*/
public boolean queryAdminRoleIsHaveRights(long roleId, String url) throws SQLException, DataException {
Connection conn = connectionManager.getConnection();
boolean reslut = false;
try {
reslut = roleRightsDao.queryAdminRoleIsHaveRights(conn, roleId, url);
} catch (SQLException e) {
log.error(e);
e.printStackTrace();
throw e;
} catch (DataException e) {
log.error(e);
e.printStackTrace();
throw e;
} finally {
conn.close();
}
return reslut;
}
public void setRoleRightsDao(RoleRightsDao roleRightsDao) {
this.roleRightsDao = roleRightsDao;
}
}