📄 usersrightmanager.java
字号:
package com.sure.oa.system.permission;
import com.sure.businessmodel.Page;
import com.sure.businessmodel.UpdateException;
import com.sure.businesslogic.AlreadyExistsException;
import com.sure.businesslogic.NotFoundException;
import com.sure.dataabstraction.DBManager;
import com.sure.dataabstraction.DBPoolException;
import com.sure.util.StringUtils;
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.util.Vector;
import java.util.NoSuchElementException;
import com.sure.oa.orgnization.*;
import com.sure.oa.role.*;
/**
* <p>Title: OA</p>
* <p>Description: 国办项目</p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: sure</p>
* @author mengzy
* @version 1.0
*/
public class usersRightManager {
public usersRightManager() {
}
/**
* 根据Id获得权限详情
* @param Id
*/
public usersRight getRight(int Id) throws SQLException,DBPoolException, NotFoundException {
Connection cn = DBManager.getConnection();
try {
String where = "Where Id = " + Id;
Vector beans = usersRightPersistent.load(cn, where);
usersRight bean = (usersRight)beans.firstElement();
return bean;
}catch (SQLException sqle) {
throw new NotFoundException();
} finally {
cn.close();
}
}
/**
* 根据Id获得权限详情
* @param Id
*/
public usersRight getRight(String Id) throws SQLException,
DBPoolException, NotFoundException{
return getRight(Integer.parseInt(Id));
}
/**
* 根据userId获得某个人的权限详情
* @param Id
*/
public String getRoleId(int userId) throws SQLException,DBPoolException, NotFoundException {
String retValue="0";
Connection cn = DBManager.getConnection();
try {
String where = "Where userId = '"+userId+"'" ;
Vector beans = usersRightPersistent.load(cn, where);
if (beans.size()>0){
retValue = ( (usersRight) beans.firstElement()).getRoleId();
}
}catch (SQLException sqle) {
throw new NotFoundException();
} finally {
cn.close();
return retValue;
}
}
/**
* 保存权限信息
*/
public int saveRight(usersRight d) throws SQLException, DBPoolException, UpdateException, NotFoundException {
Connection cn = DBManager.getConnection();
int Id = d.getId().intValue();
String roleId=d.getRoleId();
String userId=d.getUserId();
int retval = 0;
try{
//String where="where roleId='"+roleId+"' and userId='"+userId+"'";
String where="where userId='"+userId+"'";
Vector beans = usersRightPersistent.load(cn, where);
usersRightPersistent right;
if (beans.size()==0){
right = new usersRightPersistent(d);
}
else {
usersRight dd=(usersRight)beans.firstElement();
dd.setRoleId(roleId);
right=new usersRightPersistent(dd);
right.setRecordExists(true);
}
right.persist(cn);
}finally {
cn.close();
}
return retval;
}
/**
* 删除权限
*/
public void delRight(int Id) throws SQLException,DBPoolException, NotFoundException {
Connection cn = DBManager.getConnection();
try {
String where = "Where Id = " + Id;
usersRightPersistent.delete(cn, where);
}catch (SQLException sqle) {
throw new NotFoundException();
} finally {
cn.close();
}
}
/**
* 根据用户userId返回用户所具有的权限
* @param userId
* @return vector(用户权限)
* @throws SQLException
* @throws DBPoolException
* @throws NotFoundException
*/
public Vector getPermissionIDsByUserId(int userId) throws SQLException, DBPoolException,NotFoundException{
int i;
Vector v=new Vector();
Connection cn = DBManager.getConnection();
Statement s = cn.createStatement();
String sql="select content from role where roleid in (select roleid from usersright where userid='"+userId+"')";
ResultSet rs = s.executeQuery(sql);
try{
while(rs.next()){
String strIds[] = StringUtils.split(rs.getString("content"),",");
for(i = 0; i < strIds.length; i++){
v.add(strIds[i]);
}
}
return v;
}
catch(Exception e){
e.printStackTrace();
}
finally{
rs.close();
s.close();
cn.close();
}
return v;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -