?? rolemenu.java
字號:
package com.saas.biz.roleMgr;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.StringTokenizer;
import net.sf.json.JSONArray;
import com.saas.biz.JavaScriptObject.CheckTreeObject;
import com.saas.biz.JavaScriptObject.TreeNode;
import com.saas.biz.commen.commMethodMgr;
import com.saas.biz.dao.rightsDAO.MenuinfoExt;
import com.saas.biz.dao.rightsDAO.RightinfoExt;
import com.saas.biz.dao.rolerightDAO.RoleRightDAO;
import com.saas.biz.dao.rolerightDAO.RoleRightExt;
import com.saas.biz.rolerightMgr.RolerightInfo;
import com.saas.sys.buffer.Buffers;
import com.saas.sys.dbm.Dbtable;
import com.saas.sys.exp.SaasApplicationException;
import com.saas.sys.log.Logger;
/**
* @author:LiuYang
* @desc:用戶角色菜單權限管理
* @2008-7-3
*/
public class RoleMenu {
Dbtable tradeQuery;
commMethodMgr comm;
Logger log;
Buffers inBuffer;
Buffers outBuffer;
ArrayList queryResult = new ArrayList();
public RoleMenu() {
log = new Logger(this);
tradeQuery = new Dbtable();
comm = new commMethodMgr();
}
public void setTradeQuery(Dbtable tradeQuery) {
this.tradeQuery = tradeQuery;
}
public Dbtable getTradeQuery() {
return this.tradeQuery;
}
public void setOutBuffer(Buffers outBuffer) {
this.outBuffer = outBuffer;
}
public Buffers getOutBuffer() {
return this.outBuffer;
}
public ArrayList getQueryResult() {
return this.queryResult;
}
public void setQueryResult(ArrayList queryResult) {
this.queryResult = queryResult;
}
/**
* @param cust_id
* @param up_org_id
* @param iconImg
* @return 生成多選權限樹
* @throws SaasApplicationException
*/
public String getJSONCheckBoxTreeData(String cust_id, String cust_class, String sys_code, String role_code, String iconImg) throws SaasApplicationException {
log.LOG_INFO("進入getJSONCheckBoxTreeData方法");
JSONArray array = new JSONArray();
String json = "";
ArrayList list = getMenuRightInfoByClass(cust_class, sys_code, "1");
if (list != null && list.size() > 0) {
for (int i = 0; i < list.size(); i++) {
HashMap map = (HashMap) list.get(i);
String text = map.get("menu_name").toString();
String id = map.get("menu_id").toString();
CheckTreeObject tree = new CheckTreeObject();
tree.setText(text);
tree.setId(id);
tree.setChecked(checkSendMenu(cust_id, role_code, id));
TreeNode node = isLeaf(cust_id, cust_class, role_code, sys_code, 0, id);
tree.setDepth(0);
tree.setIconCls(iconImg);
tree.setLeaf(node.isLeaf());
tree.setChildren(node.getChildren());
array.add(tree);
}
json = array.toString();
}
return json;
}
/**
* @param role_code
* @param menu_id
* @return 檢測菜單是否分配
* @throws SaasApplicationException
*/
public boolean checkSendMenu(String cust_id, String role_code, String menu_id) throws SaasApplicationException {
log.LOG_INFO("進入checkSendMenu方法...");
boolean check = false;
RolerightInfo role = new RolerightInfo();
ArrayList list = role.getRoleRightByMenuId(cust_id, role_code, menu_id);
if (list != null && list.size() > 0) {
check = true;
}
return check;
}
/**
* @param cust_id
* @param up_org_id
* @return 取出一級權限菜單
* @throws SaasApplicationException
*/
public ArrayList getMenuRightInfoByClass(String cust_class, String sys_code, String menu_class) throws SaasApplicationException {
log.LOG_INFO("進入getMenuInfoByClass方法");
ArrayList list = new ArrayList();
MenuinfoExt menuext = new MenuinfoExt();
menuext.setParam(":VSUBSYS_CODE", sys_code);
menuext.setParam(":VMENU_CLASS", menu_class);
menuext.setParam(":VCUST_CLASS", cust_class);
list = menuext.selByList("SEL_BY_RIGHT_JSON");
return list;
}
/**
* @param cust_id
* @param root_id
* @param nextList
* @return children
* @throws SaasApplicationException
*/
public JSONArray getChildrenNodes(String cust_id, String cust_class, String role_code, String sys_code, int depth, ArrayList nextList) throws SaasApplicationException {
log.LOG_INFO("進入getChildrenNodes方法");
JSONArray children = new JSONArray();
if (nextList != null && nextList.size() > 0) {
for (int i = 0; i < nextList.size(); i++) {
HashMap map = (HashMap) nextList.get(i);
CheckTreeObject tree = new CheckTreeObject();
String text = map.get("menu_name").toString();
String id = map.get("menu_id").toString();
log.LOG_INFO("id====" + id);
tree.setId(id);
tree.setText(text);
tree.setChecked(checkSendMenu(cust_id, role_code, id));
tree.setDepth(depth);
TreeNode node = isLeaf(cust_id, cust_class, role_code, sys_code, depth, id);
tree.setChildren(node.getChildren());
tree.setLeaf(node.isLeaf());
children.add(tree);
}
}
return children;
}
/**
* @param cust_id
* @param up_id
* @return TreeNode
* @throws SaasApplicationException
*/
public TreeNode isLeaf(String cust_id, String cust_class, String role_code, String sys_code, int depth, String up_id) throws SaasApplicationException {
log.LOG_INFO("進入isLeaf方法");
depth = depth + 1;
ArrayList nextList = getDownMenuByUpMenuId(cust_id, cust_class, role_code, sys_code, up_id);
TreeNode node = new TreeNode();
if (nextList != null && nextList.size() > 0) {
node.setLeaf(false);
JSONArray children = getChildrenNodes(cust_id, cust_class, role_code, sys_code, depth, nextList);
node.setChildren(children);
}
return node;
}
/**
* @param sys_code
* @param menu_class
* @return 取出下級菜單
* @throws SaasApplicationException
*/
public ArrayList getDownMenuByUpMenuId(String cust_id, String cust_class, String role_code, String sys_code, String menu_id) throws SaasApplicationException {
log.LOG_INFO("進入getDownMenuByUpMenuId方法");
MenuinfoExt menuext = new MenuinfoExt();
menuext.setParam(":VMENU_ID", menu_id);
menuext.setParam(":VCUST_CLASS", cust_class);
menuext.setParam(":VSUBSYS_CODE", sys_code);
ArrayList list = menuext.selByList("SEL_MENU_ID");
return list;
}
/**
* 分配菜單權限
*
* @param inbuffer
*/
public void addRightMenuInfo(Buffers inbuffer) {
log.LOG_INFO("進入addRightMenuInfo方法...");
outBuffer = inbuffer;
int iResult = -1;
String cust_id = inbuffer.getString("SESSION_CUST_ID");
String role_code = inbuffer.getString("ROLE_CODE");
String menu_id = inbuffer.getString("MENU_ID");
String start_date = inbuffer.getString("START_DATE");
String end_date = inbuffer.getString("END_DATE");
String oper_user_id = inbuffer.getString("SESSION_USER_ID");
String remark = inbuffer.getString("REMARK");
try {
RoleRightDAO roleRight = new RoleRightDAO();
roleRight.setCust_id(cust_id);
roleRight.setEnd_date(end_date);
roleRight.setStart_date(start_date);
roleRight.setOper_user_id(oper_user_id);
roleRight.setRemark(remark);
roleRight.setMenu_id(menu_id);
roleRight.setRole_code(role_code);
iResult = addRightMenuInfo(roleRight);
}
catch (SaasApplicationException e) {
log.LOG_INFO(e.getMessage());
}
if (iResult != 0) {
this.outBuffer.setInt("RESULT_CODE", -1);
this.outBuffer.setString("RESULT_INFO", "業務處理失敗");
}
else {
this.outBuffer.setInt("RESULT_CODE", 0);
this.outBuffer.setString("RESULT_INFO", "業務處理成功!");
}
log.LOG_INFO("退出addRightMenuInfo方法...");
}
public int addRightMenuInfo(RoleRightDAO roleRight) throws SaasApplicationException {
String menu_id = roleRight.getMenu_id();
StringTokenizer st = new StringTokenizer(menu_id, "|");
while (st.hasMoreTokens()) {
String id = st.nextToken();
RoleRightExt menuExt = new RoleRightExt();
menuExt.setParam(":VCUST_ID", roleRight.getCust_id());
menuExt.setParam(":VROLE_CODE", roleRight.getRole_code());
menuExt.setParam(":VMENU_ID", id);
menuExt.setParam(":VSTART_DATE", roleRight.getStart_date());
menuExt.setParam(":VEND_DATE", roleRight.getEnd_date());
menuExt.setParam(":VOPER_USER_ID", roleRight.getOper_user_id());
menuExt.setParam(":VREMARK", roleRight.getRemark());
String up_menu_id = getUpMenuId(id);
if (up_menu_id != "" && !up_menu_id.equals(null)) {
boolean upRight = getUpRightInfo(roleRight.getEnd_date(), roleRight.getCust_id(), up_menu_id);
if (!upRight) {
RoleRightExt upMenuExt = new RoleRightExt();
upMenuExt.setParam(":VCUST_ID", roleRight.getCust_id());
upMenuExt.setParam(":VROLE_CODE", roleRight.getRole_code());
upMenuExt.setParam(":VMENU_ID", up_menu_id);
upMenuExt.setParam(":VSTART_DATE", roleRight.getStart_date());
upMenuExt.setParam(":VEND_DATE", roleRight.getEnd_date());
upMenuExt.setParam(":VOPER_USER_ID", roleRight.getOper_user_id());
upMenuExt.setParam(":VREMARK", roleRight.getRemark());
tradeQuery.executeBy(upMenuExt.insBy("INS_BY_ALL"));
}
}
boolean saveOrUpdate = getUpRightInfo(roleRight.getEnd_date(), roleRight.getCust_id(), id);
if (saveOrUpdate) {
RoleRightExt delExt = new RoleRightExt();
delExt.setParam(":VCUST_ID", roleRight.getCust_id());
delExt.setParam(":VROLE_CODE", roleRight.getRole_code());
delExt.setParam(":VMENU_ID", id);
tradeQuery.executeBy(delExt.insBy("DEL_BY_CODE"));
}
tradeQuery.executeBy(menuExt.insBy("INS_BY_ALL"));
}
return 0;
}
/**
* 取出上級菜單ID
*/
public String getUpMenuId(String menu_id) throws SaasApplicationException {
String up_id = "";
MenuinfoExt menuext = new MenuinfoExt();
menuext.setParam(":VMENU_ID", menu_id);
ArrayList list = menuext.selByList("SEL_BY_PK");
if (list != null && list.size() > 0) {
HashMap map = (HashMap) list.get(0);
if (map.get("up_menu_id") != null) {
up_id = map.get("up_menu_id").toString();
}
}
return up_id;
}
/**
* @param role_code
* @param cust_id
* @param menu_id
* @return 判斷上級菜單權限是否存在
* @throws SaasApplicationException
*/
public boolean getUpRightInfo(String role_code, String cust_id, String menu_id) throws SaasApplicationException {
boolean result = false;
ArrayList roleList = new ArrayList();
RoleRightExt rightExt = new RoleRightExt();
rightExt.setParam(":VCUST_ID", cust_id);
rightExt.setParam(":VROLE_CODE", role_code);
rightExt.setParam(":VMENU_ID", menu_id);
roleList = rightExt.selByList("SEL_BY_MENU");
if (roleList != null && roleList.size() > 0) {
result = true;
}
return result;
}
/**
* 回收菜單權限
*
* @param inbuffer
*/
public void delRightMenuInfo(Buffers inbuffer) {
log.LOG_INFO("進入delRightMenuInfo方法...");
outBuffer = inbuffer;
int iResult = -1;
String cust_id = inbuffer.getString("SESSION_CUST_ID");
String role_code = inbuffer.getString("ROLE_CODE");
String menu_id = inbuffer.getString("SUB_CODE");
try {
RoleRightDAO roleRight = new RoleRightDAO();
roleRight.setCust_id(cust_id);
roleRight.setMenu_id(menu_id);
roleRight.setRole_code(role_code);
iResult = delRightMenuInfo(roleRight);
}
catch (SaasApplicationException e) {
log.LOG_INFO(e.getMessage());
}
if (iResult != 0) {
this.outBuffer.setInt("RESULT_CODE", -1);
this.outBuffer.setString("RESULT_INFO", "業務處理失敗");
}
else {
this.outBuffer.setInt("RESULT_CODE", 0);
this.outBuffer.setString("RESULT_INFO", "業務處理成功!");
}
log.LOG_INFO("退出delRightMenuInfo方法...");
}
public int delRightMenuInfo(RoleRightDAO roleRight) throws SaasApplicationException {
RoleRightExt menuExt = new RoleRightExt();
menuExt.setParam(":VCUST_ID", roleRight.getCust_id());
menuExt.setParam(":VSUB_CODE", roleRight.getMenu_id());
menuExt.setParam(":VROLE_CODE", roleRight.getRole_code());
tradeQuery.executeBy(menuExt.insBy("DEL_RIGHT_BY_CODE"));
return 0;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -