📄 rolebean.java
字号:
/**
* @function 角色管理
* @date 2006/12/08
* @author Janet
*
*/
package com.ufmobile.common.role.bo.bean;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import javax.ejb.Stateless;
import com.ufmobile.common.BaseBean;
import com.ufmobile.common.exception.RoleException;
import com.ufmobile.common.login.entity.UserInfo;
import com.ufmobile.common.role.bo.Role;
import com.ufmobile.common.role.dao.MemberRoleDAO;
import com.ufmobile.common.role.dao.RoleDAO;
import com.ufmobile.common.role.entity.MemberroleEntity;
import com.ufmobile.common.role.entity.MenuEntity;
import com.ufmobile.common.role.entity.RoleEntity;
import com.ufmobile.common.role.entity.RolefuncEntity;
import com.ufmobile.platform.log.RunTimeLogger;
/**
* <p>
* <p>
* 创建日期:Dec 13, 2006
*
* @author msf
* @since v3.0
*/
public @Stateless
class RoleBean extends BaseBean implements Role {
/**
* 作者:msf <br>
* 日期:Dec 30, 2006
*
* @see com.ufmobile.common.role.bo.Role#addRole(com.ufmobile.common.role.entity.RoleEntity)
*/
public void addRole(RoleEntity roleEntity) throws RoleException {
RunTimeLogger.info(getClass(), "新建角色");
RoleDAO roleDao = new RoleDAO(getManager());
roleDao.addRole(roleEntity);
}
/**
* 作者:msf <br>
* 日期:Dec 30, 2006
*
* @see com.ufmobile.common.role.bo.Role#deleteRole(java.lang.Long)
*/
public void deleteRole(Long roleId) throws RoleException {
RunTimeLogger.info(getClass(), "删除角色");
RoleDAO roleDao = new RoleDAO(getManager());
roleDao.deleteRole(roleId);
}
/**
* 作者:msf <br>
* 日期:Dec 30, 2006
*
* @see com.ufmobile.common.role.bo.Role#updateRole(com.ufmobile.common.role.entity.RoleEntity)
*/
public void updateRole(RoleEntity roleEntity) throws RoleException {
RunTimeLogger.info(getClass(), "更新角色");
if (roleEntity.getId() == 0L)
throw new RoleException(getClass(), "预制系统管理员不能更新!");
RoleDAO roleDao = new RoleDAO(getManager());
roleDao.updateRole(roleEntity);
}
/**
* 作者:msf <br>
* 日期:Dec 30, 2006
*
* @see com.ufmobile.common.role.bo.Role#getRoleEntity(java.lang.Long)
*/
public RoleEntity getRoleEntity(Long roleId) throws RoleException {
RoleDAO roleDao = new RoleDAO(getManager());
return roleDao.getRoleEntity(roleId);
}
/**
* 作者:msf <br>
* 日期:Dec 30, 2006
*
* @see com.ufmobile.common.role.bo.Role#getAllRoles()
*/
public List<RoleEntity> getAllRoles() throws RoleException {
RoleDAO roleDao = new RoleDAO(getManager());
return roleDao.getAllRoles();
}
/**
* 作者:msf <br>
* 日期:Dec 30, 2006
*
* @see com.ufmobile.common.role.bo.Role#getRoleMenu()
*/
public List<MenuEntity> getRoleMenu() throws RoleException {
return null;
}
/**
* <p>
* 从缓存中读取根节点菜单
* <p>
* 作者:Janet Feng <br>
* 日期:Dec 22, 2006
*
* @param data
* @return
* @throws RoleException
*/
private List<MenuEntity> getRoleMenuRootFromCache(List<MenuEntity> data) throws RoleException {
if (data == null)
return null;
List list = new ArrayList();
for (int i = 0; i < data.size(); i++) {
MenuEntity item = data.get(i);
if (item.getCode() != null && item.getCode().length() == 3)
list.add(item);
}
return list;
}
/**
* 作者:msf <br>
* 日期:Dec 13, 2006
*
* @see com.ufmobile.common.role.bo.Role#assignRole(java.lang.Long,
* java.lang.Long, java.lang.Long, java.lang.Integer)
*/
public void assignRole(Long ursid, Long sysid, Long roleid, Integer itype) throws RoleException {
RoleDAO roleDAO = new RoleDAO(getManager());
roleDAO.revokeRole(ursid, sysid, itype);
roleDAO.assignRole(ursid, sysid, roleid, itype);
}
/**
* 作者:msf <br>
* 日期:Dec 13, 2006
*
* @see com.ufmobile.common.role.bo.Role#getRoles(java.lang.Integer)
*/
public List<RoleEntity> getRoles(Integer itype) throws RoleException {
return new RoleDAO(getManager()).getRoles(itype);
}
/**
* 作者:Janet Feng <br>
* 日期:Dec 18, 2006
*
* @see com.ufmobile.common.role.bo.Role#queryRoles(int, int)
*/
public List<RoleEntity> queryRoles(int beginIndex, int maxNumber) throws RoleException {
RoleDAO roleDao = new RoleDAO(getManager());
return roleDao.queryRoles(beginIndex, maxNumber);
}
/**
* 作者:msf <br>
* 日期:Dec 22, 2006
*
* @see com.ufmobile.common.role.bo.Role#assignRole(java.lang.Long,
* java.lang.Long, java.util.List, java.lang.Integer)
*/
public void assignRole(Long ursid, Long sysid, List lRoleid, Integer itype) throws RoleException {
if (lRoleid == null)
return;
RoleDAO roleDAO = new RoleDAO(getManager());
roleDAO.revokeRole(ursid, sysid, itype);
for (int i = 0; i < lRoleid.size(); i++) {
Long roleid = (Long) lRoleid.get(i);
roleDAO.assignRole(ursid, sysid, roleid, itype);
}
}
/**
* 作者:msf <br>
* 日期:Jan 24, 2007
*
* @see com.ufmobile.common.role.bo.Role#getRolesbyUsrID(java.lang.Integer,
* java.lang.Long, java.lang.Long)
*/
public List<List> getRolesbyUsrID(Integer itype, Long systemid, Long usrid) throws RoleException {
List<List> ret = new ArrayList<List>();
RoleDAO roleDao = new RoleDAO(getManager());
List lAll = roleDao.getRoles(itype);
List lAssing = roleDao.getAssignRoles(itype, systemid, usrid);
List lNotAssing = new ArrayList();
for (int i = 0; i < lAll.size(); i++) {
if (!lAssing.contains(lAll.get(i)))
lNotAssing.add(lAll.get(i));
}
ret.add(lAssing);
ret.add(lNotAssing);
return ret;
}
/**
* 作者:msf <br>
* 日期:Jan 24, 2007
*
* @see com.ufmobile.common.role.bo.Role#getRolesbyUsrID2(java.lang.Integer,
* java.lang.Long, java.lang.Long)
*/
public RoleEntity getRolesbyUsrID2(Integer itype, Long systemid, Long usrid) throws RoleException {
RoleDAO roleDao = new RoleDAO(getManager());
List<RoleEntity> lAssing = roleDao.getAssignRoles(itype, systemid, usrid);
if (lAssing != null && lAssing.size() > 0)
return lAssing.get(0);
else
return null;
}
/**
* 作者:msf <br>
* 日期:Dec 22, 2006
*
* @see com.ufmobile.common.role.bo.Role#getRoles(java.lang.Integer,
* java.lang.Long)
*/
public List<RoleEntity> getRoles(Integer itype, Long systemid) throws RoleException {
return null;
}
public void saveAssign(RoleEntity roleEntity, List<String> sMenuCode) throws RoleException {
RunTimeLogger.info(getClass(), "保存角色菜单");
if (roleEntity.getId() == Role.ADMIN || roleEntity.getId() == Role.OWNER || roleEntity.getId() == Role.AGENT)
throw new RoleException(getClass(), "预制系统管理员不能修改!");
if (roleEntity == null)
throw new RoleException(getClass(), "分配菜单的角色不存在!");
RoleDAO roleDao = new RoleDAO(getManager());
// 删除原表中角色的功能
roleDao.deleteAssign(roleEntity);
// 没有选中任何菜单
if (sMenuCode == null || sMenuCode.isEmpty())
return;
// 选中菜单保存
StringBuffer sCode = new StringBuffer("'");
for (int i = 0; i < sMenuCode.size(); i++) {
String menuCode = sMenuCode.get(i);
sCode.append(menuCode);
if (i < sMenuCode.size() - 1) {
sCode.append("','");
} else {
sCode.append("'");
}
}
// 获得保存菜单信息
List<MenuEntity> menuItems = roleDao.getRoleMenuItem(sCode.toString(), roleEntity.getSys());
// 将菜单功能保存到角色菜单表中
for (int i = 0; i < menuItems.size(); i++) {
// 根据编码获得菜单实体对象,注意!编码不是主键,需查询获得
MenuEntity menuItem = menuItems.get(i);
if (menuItem != null) {
menuItem = menuItem.clone();
menuItem.setRoleid(roleEntity.getId());
// 新建角色功能
roleDao.addMenu(menuItem);
}
}
}
/**
* 作者:msf <br>
* 日期:Dec 23, 2006
*
* @see com.ufmobile.common.role.bo.Role#getAssignFuncCode(java.lang.Long)
*/
public List<MenuEntity> getMenu(Long roleID) throws RoleException {
// 取数据
RoleDAO roleDao = new RoleDAO(getManager());
return roleDao.getAssignMenu(roleID);
// 取出一级菜单和二级菜单,并去掉重复 复用以前代码,不修改了
}
public List<RoleEntity> queryRolesBySysPage(int beginIndex, int maxNumber, int sys) throws RoleException {
RoleDAO roleDao = new RoleDAO(getManager());
return roleDao.queryRolesBySysPage(beginIndex, maxNumber, sys);
}
public Long queryRolesBySysTotal(int sys) throws RoleException {
RoleDAO roleDao = new RoleDAO(getManager());
return roleDao.queryRolesBySysTotal(sys);
}
public List<MenuEntity> getAllMenus() throws RoleException {
return new RoleDAO(getManager()).getAssignMenu(new StringBuffer("(").append(Role.ADMIN).append(",").append(Role.OWNER).append(",").append(Role.AGENT).append(")").toString());
}
public List<MenuEntity> getAllMenus(Integer iType) throws RoleException {
Long Roleid = null;
switch (iType.intValue()) {
case UserInfo.Member:
Roleid = Role.OWNER;
break;
case UserInfo.Operator:
Roleid = Role.ADMIN;
break;
case UserInfo.Agent:
Roleid = Role.AGENT;
break;
default:
return null;
}
return new RoleDAO(getManager()).getAssignMenu(Roleid);
}
public List<MemberroleEntity> findMemberRoleEntityByShopId(Long shopId) throws RoleException {
return new MemberRoleDAO(getManager()).findMemberRoleEntityByShopId(shopId);
}
/**
* 作者:msf <br>
* 日期:Jan 9, 2007
*
* @see com.ufmobile.common.role.bo.Role#revokeRole(java.lang.Long,
* java.lang.Long, java.lang.Integer)
*/
public void revokeRole(Long ursid, Long sysid, Integer itype) throws RoleException {
new RoleDAO(getManager()).revokeRole(ursid, sysid, itype);
}
public List<MemberroleEntity> getRolebyMemberID(Long memberid) throws RoleException {
return new RoleDAO(getManager()).getRolebyMemberID(memberid);
}
/**
* 作者:msf <br>
* 日期:Jan 26, 2007
*
* @see com.ufmobile.common.role.bo.Role#queryFunc()
*/
public List<RolefuncEntity> queryFunc() throws RoleException {
List<RolefuncEntity> ls = getManager().createQuery("from RolefuncEntity order by url").getResultList();
List<RolefuncEntity> lsRet = new ArrayList<RolefuncEntity>();
String beforURL = "";
List lsURL = new ArrayList();
int iIndex = 0;
for (RolefuncEntity c : ls) {
if (!beforURL.equalsIgnoreCase(c.getUrl())) {
beforURL = c.getUrl();
lsURL = new ArrayList();
c.setFuncodes(lsURL);
lsRet.add(iIndex++, c);
}
if (!lsURL.contains(c.getFuccode()))
lsURL.add(c.getFuccode());
}
return lsRet;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -