⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 righttreemenu.java

📁 java阿里巴巴代码
💻 JAVA
字号:
package com.saas.biz.rightMgr;

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.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-2
 */
public class RightTreeMenu {
	
	
	Dbtable tradeQuery;
	
	
	commMethodMgr comm;
	
	
	Logger log;
	
	
	Buffers inBuffer;
	
	
	Buffers outBuffer;
	
	
	ArrayList queryResult = new ArrayList();
	
	
	
	public RightTreeMenu() {

		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_class, String sys_code, String iconImg) throws SaasApplicationException {

		log.LOG_INFO("进入getJSONCheckBoxTreeData方法" + cust_class + "===" + sys_code);
		JSONArray array = new JSONArray();
		String json = "";
		ArrayList list = getMenuInfoByClass(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_class, id));
				TreeNode node = isLeaf(cust_class, 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 cust_class
	 * @param menu_id
	 * @return 检测菜单是否分配
	 * @throws SaasApplicationException
	 */
	public boolean checkSendMenu(String cust_class, String menu_id) throws SaasApplicationException {

		boolean check = false;
		RightinfoExt rightExt = new RightinfoExt();
		rightExt.setParam(":VCUST_CLASS", cust_class);
		rightExt.setParam(":VMENU_ID", menu_id);
		ArrayList list = rightExt.selByList("SEL_BY_MENU");
		if (list != null && list.size() > 0) {
			check = true;
		}
		return check;
	}
	
	
	
	/**
	 * @param cust_id
	 * @param up_org_id
	 * @return 取出一级权限菜单
	 * @throws SaasApplicationException
	 */
	public ArrayList getMenuInfoByClass(String sys_code, String menu_class) throws SaasApplicationException {

		log.LOG_INFO("进入getMenuInfoByClass方法");
		ArrayList list = new ArrayList();
		MenuinfoExt orgExt = new MenuinfoExt();
		orgExt.setParam(":VSUBSYS_CODE", sys_code);
		orgExt.setParam(":VMENU_CLASS", menu_class);
		list = orgExt.selByList("SEL_BY_CLASS_JSON");
		return list;
	}
	
	
	
	/**
	 * @param cust_id
	 * @param root_id
	 * @param nextList
	 * @return children
	 * @throws SaasApplicationException
	 */
	public JSONArray getChildrenNodes(String cust_class, 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();
				tree.setId(id);
				tree.setText(text);
				tree.setChecked(checkSendMenu(cust_class, id));
				tree.setDepth(depth);
				TreeNode node = isLeaf(cust_class, 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_class, String sys_code, int depth, String up_id) throws SaasApplicationException {

		log.LOG_INFO("进入isLeaf方法");
		depth = depth + 1;
		ArrayList nextList = getDownMenuByUpMenuId(sys_code, up_id);
		TreeNode node = new TreeNode();
		if (nextList != null && nextList.size() > 0) {
			node.setLeaf(false);
			JSONArray children = getChildrenNodes(cust_class, sys_code, depth, nextList);
			node.setChildren(children);
		}
		return node;
	}
	
	
	
	/**
	 * @param sys_code
	 * @param menu_class
	 * @return 取出下级菜单
	 * @throws SaasApplicationException
	 */
	public ArrayList getDownMenuByUpMenuId(String sys_code, String menu_id) throws SaasApplicationException {

		log.LOG_INFO("进入getDownMenuByUpMenuId方法");
		ArrayList list = new ArrayList();
		MenuinfoExt orgExt = new MenuinfoExt();
		orgExt.setParam(":VSUBSYS_CODE", sys_code);
		orgExt.setParam(":VMENU_ID", menu_id);
		list = orgExt.selByList("SEL_BY_UP_JSON");
		return list;
	}
	
	
	
	/**
	 * 分配菜单权限
	 * 
	 * @param inbuffer
	 */
	public void addRightMenuInfo(Buffers inbuffer) {

		log.LOG_INFO("进入addRightMenuInfo方法...");
		outBuffer = inbuffer;
		int iResult = -1;
		String menu_id = inbuffer.getString("MENU_ID");
		String cust_class = inbuffer.getString("CUST_CLASS");
		String start_date = inbuffer.getString("START_DATE");
		String end_date = inbuffer.getString("END_DATE");
		try {
			iResult = addRightMenuInfo(menu_id, cust_class, start_date, end_date);
		}
		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(String menu_id, String cust_class, String start_date, String end_date) throws SaasApplicationException {

		StringTokenizer st = new StringTokenizer(menu_id, "|");
		while (st.hasMoreTokens()) {
			String id = st.nextToken();
			RightinfoExt menuExt = new RightinfoExt();
			menuExt.setParam(":VMENU_ID", id);
			menuExt.setParam(":VCUST_CLASS", cust_class);
			menuExt.setParam(":VSTART_DATE", start_date);
			menuExt.setParam(":VEND_DATE", end_date);
			String upMenuId = getUpMenuId(id);
			if (!checkSendMenu(cust_class, id)) {
				tradeQuery.executeBy(menuExt.insBy("INS_BY_ALL"));
			}
			if (upMenuId != null && !upMenuId.equals("")) {
				if (!checkSendMenu(cust_class, upMenuId)) {
					RightinfoExt upExt = new RightinfoExt();
					upExt.setParam(":VMENU_ID", upMenuId);
					upExt.setParam(":VCUST_CLASS", cust_class);
					upExt.setParam(":VSTART_DATE", start_date);
					upExt.setParam(":VEND_DATE", end_date);
					tradeQuery.executeBy(upExt.insBy("INS_BY_ALL"));
				}
			}
		}
		return 0;
	}
	
	
	
	/**
	 * @param menu_id
	 * @return 取出上级菜单ID
	 * @throws SaasApplicationException
	 */
	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 inbuffer
	 */
	public void delRightMenuInfo(Buffers inbuffer) {

		log.LOG_INFO("进入delRightMenuInfo方法...");
		outBuffer = inbuffer;
		int iResult = -1;
		String menu_id = inbuffer.getString("MENU_ID");
		String cust_class = inbuffer.getString("CUST_CLASS");
		String sub_code = inbuffer.getString("SUB_CODE");
		try {
			iResult = delRightMenuInfo(menu_id, cust_class, sub_code);
		}
		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(String menu_id, String cust_class, String sub_code) throws SaasApplicationException {

		RightinfoExt menuExt = new RightinfoExt();
		menuExt.setParam(":VSUB_CODE", sub_code);
		menuExt.setParam(":VCUST_CLASS", cust_class);
		tradeQuery.executeBy(menuExt.insBy("DEL_RIGHT_BY_MENU"));
		return 0;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -