NC6 功能、菜单相关查询服务类

package nc.impl.uap.bbd.func;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import nc.bs.dao.BaseDAO;
import nc.bs.framework.common.InvocationInfoProxy;
import nc.bs.framework.common.NCLocator;
import nc.bs.logging.Logger;
import nc.itf.uap.bbd.func.IFuncRegisterQueryService;
import nc.itf.uap.bbd.func.ProductSortedUtil;
import nc.jdbc.framework.SQLParameter;
import nc.jdbc.framework.processor.BeanListProcessor;
import nc.jdbc.framework.processor.ColumnListProcessor;
import nc.jdbc.framework.processor.ColumnProcessor;
import nc.pubitf.rbac.IFunctionPermissionPubService;
import nc.vo.jcom.lang.StringUtil;
import nc.vo.pub.BusinessException;
import nc.vo.sm.funcreg.BusiActiveRelationVO;
import nc.vo.sm.funcreg.BusiActiveVO;
import nc.vo.sm.funcreg.ButtonOwnerType;
import nc.vo.sm.funcreg.ButtonRegVO;
import nc.vo.sm.funcreg.FunRegisterConst;
import nc.vo.sm.funcreg.FuncRegisterVO;
import nc.vo.sm.funcreg.MenuItem;
import nc.vo.sm.funcreg.MenuItemVO;
import nc.vo.sm.funcreg.MenuRegisterVO;
import nc.vo.sm.funcreg.ModuleVO;
import nc.vo.sm.funcreg.PageVO;
import nc.vo.sm.funcreg.ParamRegVO;
import nc.vo.trade.sqlutil.IInSqlBatchCallBack;
import nc.vo.trade.sqlutil.InSqlBatchCaller;
import nc.vo.uap.rbac.util.JoinCondHelper;
import nc.vo.util.SqlWhereUtil;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;


/**
 * 功能、菜单相关查询服务
 * 
 * @author 
 * 
 */
public class FuncRegisterQueryServiceImpl implements IFuncRegisterQueryService {
 
	public String[] queryGroupAdminCanUseFunc() throws BusinessException {
		//jl+ 2010年3月24日 根据新的需求集团管理员可分配的节点为 企业动态建模 和 开发平台下的节点
		String sql = "select funcode from sm_funcregister where isenable = 'Y' and funtype in (0,1,3) " 
			+" and fun_property in ("+ getIsNodeInSql(false) + ") " 
			+" and ("+getGmFucregWherePart()+") " 
			
			+" and funcode not in (select funcode from sm_gm_func)";//对集团管理员已经有的功能进行过滤
		BaseDAO dao = new BaseDAO();
		Collection<String> resultList = (Collection<String>) dao.executeQuery(sql, new ColumnListProcessor());
		return resultList == null ? null : (String[]) resultList.toArray(new String[resultList.size()]);
	} 
	
	private String getGmFucregWherePart() throws BusinessException{
		SqlWhereUtil sw = new SqlWhereUtil();
		List<String> modules = (List<String>) new BaseDAO().executeQuery("select moduleid from sm_gm_funcreg where moduleid <> '~'",  new ColumnListProcessor());
		for (String moduleid : modules) {
			sw.or("own_module like '"+moduleid+"%'");
		}
		List<String> funcodes = (List<String>) new BaseDAO().executeQuery("select funcode from sm_gm_funcreg where funcode <> '~'",  new ColumnListProcessor());
		for (String funcode : funcodes) {
			sw.or("funcode like '"+funcode+"%'");
		}
		return sw.getSQLWhere();
	}
	
	@Override
	public FuncRegisterVO[] queryGroupAdminCanUseFuncVO() throws BusinessException{
		String[] groupAdminCanUseFuncCodes = queryGroupAdminCanUseFunc();
		
		if(ArrayUtils.isEmpty(groupAdminCanUseFuncCodes)) return null;
		
		return queryFunctionsByCodes(groupAdminCanUseFuncCodes);
	}
	
	public FuncRegisterVO[] queryAllGroupManagerAssignedFuncVO() throws BusinessException{
		IFunctionPermissionPubService funcPermPubService = NCLocator.getInstance().lookup(IFunctionPermissionPubService.class);
		
		String[] groupAdminOwnedFuncodes = funcPermPubService.queryAllGroupManagerFuncode();
		
		if(ArrayUtils.isEmpty(groupAdminOwnedFuncodes)) return null;
		
		return queryFunctionsByCodes(groupAdminOwnedFuncodes);
	}
	
	public ButtonRegVO[] queryBtnsBelongToFunc(String funcId) throws BusinessException {
		
		if (StringUtil.isEmptyWithTrim(funcId))
			return null;
		
		FuncRegisterVO vo = queryFunctionByCFunid(funcId);
		PageVO[] pages = getPages4Function(vo.getFuncode());
		
		String where = "parent_id in ('" + funcId + "'";
		if(pages != null && pages.length > 0)
		{
			for(int i = 0;i < pages.length; i++)
			{
				where += ",";
				where +=("'" + pages[i].getPk_page() + "'");
			}
		} 
		where += ")";
		
		BaseDAO dao = new BaseDAO();
		Collection<ButtonRegVO> con = dao.retrieveByClause(ButtonRegVO.class, where);
		return con == null ? null : con.toArray(new ButtonRegVO[0]);
	}
	
	public ButtonRegVO[] queryBtnsBelongToFuncAndRelated2BusiActive(String funcId) throws BusinessException {
		if (StringUtil.isEmptyWithTrim(funcId))
			return null;
		List<String> ownerIDList = buildOwnerIDList(funcId);
		InSqlBatchCaller caller = new InSqlBatchCaller((ArrayList<String>) ownerIDList);
		List<ButtonRegVO> result = new ArrayList<ButtonRegVO>();
		try {
			result = (List<ButtonRegVO>) caller.execute(new IInSqlBatchCallBack() {
			List<ButtonRegVO> list = new ArrayList<ButtonRegVO>();
				@Override
				public Object doWithInSql(String inSql) throws BusinessException, SQLException {
					BaseDAO dao = new BaseDAO();
					String whereSQL = "parent_id in " + inSql + " and pk_btn in (select pk_butn from sm_busiactive_btn)";
					Collection<ButtonRegVO> buttonRegVOs = dao.retrieveByClause(ButtonRegVO.class,whereSQL);
					list.addAll(buttonRegVOs);
					return list;
				}
			});
		} catch (SQLException e) {
			Logger.debug(e.getMessage());
			throw new BusinessException(e.getMessage());
		}
		return (ButtonRegVO[]) result.toArray(new ButtonRegVO[result.size()]);
	}
	private List<String> buildOwnerIDList(String funcId) throws BusinessException {
		FuncRegisterVO vo = queryFunctionByCFunid(funcId);
		PageVO[] pages = getPages4Function(vo.getFuncode());
		List<String> result = new ArrayList<String>();
		result.add(vo.getCfunid());
		int iLen = ArrayUtils.getLength(pages);
		for (int i = 0; i < iLen; i++) {
			result.add(pages[i].getPk_page());
		}
		return result;
	}
//	public boolean queryIsNeedButtonLogByFunCode(String fun_code) throws BusinessException {
//
//		if (StringUtil.isEmptyWithTrim(fun_code))
//			return false;
//		FuncRegisterVO vo = queryFunctionByCode(fun_code);
//		if (vo == null)
//			return false;
//		UFBoolean isneedbuttonlog = vo.getIsneedbuttonlog();
//		return isneedbuttonlog == null ? false : isneedbuttonlog.booleanValue();
//	} 

	public String[][] queryParameter(String funcCode) throws BusinessException {
		
		JoinCondHelper helper = new JoinCondHelper(new ParamRegVO());
		helper.appendTable("sm_funcregister", "func");
		helper.appendTable("sm_paramregister", "param");
		String cond = "func.cfunid = param.parentid and func.funcode = ?";
		helper.appendJoinCond(cond);
		SQLParameter param = new SQLParameter();
		param.addParam(funcCode);
		BaseDAO dao = new BaseDAO();
		List<ParamRegVO> list = (List<ParamRegVO>) dao.executeQuery(helper.getSQLScript(), param,
															new BeanListProcessor(ParamRegVO.class));
		ParamRegVO[] paramRegVOs = (ParamRegVO[]) list.toArray(new ParamRegVO[list.size()]);
		String[][] strParams = null;
		if (paramRegVOs != null) {
			strParams = new String[paramRegVOs.length][2];
			for (int i = 0; i < paramRegVOs.length; i++) {
				strParams[i][0] = paramRegVOs[i].getParamname();
				strParams[i][1] = paramRegVOs[i].getParamvalue();
			}
		}
		return strParams;
	}
	
	public FuncRegisterVO[] queryAllCanManagedFuncNode(String pk_org, int funType) throws BusinessException {
		
		// 查询当前集团下所启用模块下的功能节点 
		SqlWhereUtil swu = new SqlWhereUtil();
		swu.s("isenable = 'Y'").and("fun_property in (" + getIsNodeInSql(false) + ")");
		if (!StringUtil.isEmptyWithTrim(pk_org)) {
			swu.and("own_module in (select funccode from sm_createcorp where pk_org ='" + pk_org + "')");
		}
		switch (funType) {
		case FunRegisterConst.FUNC_TYPE_ALL_EXCLUDESYSTEM:
			swu.and("funtype in (0,1,3)");
			break;
		case FunRegisterConst.FUNC_TYPE_ALL:
			break;
		default:
			swu.and("funtype = " + funType);
			break;
		}
		//添加集团属性过滤条件
		if(!"0001".equals(pk_org)){
			swu.and(" (pk_group = '" + pk_org + "' or isnull(pk_group,'~') = '~' ) ");
		}
		final BaseDAO dao = new BaseDAO();
		Collection<FuncRegisterVO> resultList = (Collection<FuncRegisterVO>) dao.retrieveByClause(FuncRegisterVO.class,
																				swu.getSQLWhere());
		if (resultList == null || resultList.size() == 0) {
			return null;
		}
		FuncRegisterVO[] voArray = resultList.toArray(new FuncRegisterVO[0]);
		return voArray;
		
	}

	public List<PageVO> queryAllPageVO() throws BusinessException {
		BaseDAO dao = new BaseDAO();
		String where = " parentid in(select cfunid from sm_funcregister)";
		List<PageVO> result = (List<PageVO>) dao.retrieveByClause(PageVO.class, where);
		return result;
	}

	public List<ButtonRegVO> queryAllHasPowerButtonRegVO() throws BusinessException {
		BaseDAO dao = new BaseDAO();
		String funcNodeStr = " parent_id in(select cfunid from sm_funcregister where isbuttonpower='Y')";
		String pageStr = " parent_id in(select cfunid from sm_pageregister where isbuttonpower='Y')";
		List<ButtonRegVO> funcNodeBtnVOs = (List<ButtonRegVO>) dao.retrieveByClause(ButtonRegVO.class, funcNodeStr);
		List<ButtonRegVO> pageBtnVOs = (List<ButtonRegVO>) dao.retrieveByClause(ButtonRegVO.class, pageStr);
		List<ButtonRegVO> result = new ArrayList<ButtonRegVO>();
		if (funcNodeBtnVOs != null) {
			result.addAll(funcNodeBtnVOs);
		}
		if (pageBtnVOs != null) {
			result.addAll(pageBtnVOs);
		}
		return result;
	}
	public List<FuncRegisterVO> getFunNodeOfModule(String moduleid) throws BusinessException {
		boolean isAll = false;
		if (StringUtil.isEmptyWithTrim(moduleid))
			isAll = true;

		BaseDAO dao = new BaseDAO();
		String sql = null;
		if (!isAll)
			sql = "select * from sm_funcregister where own_module='" + moduleid + "'";
		else
			sql = "select * from sm_funcregister";
		List<FuncRegisterVO> funcList = (List<FuncRegisterVO>) dao.executeQuery(sql, new BeanListProcessor(
				FuncRegisterVO.class));

		return funcList;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List[] getFunctionInfoOfModule(String moduleid) throws BusinessException {
		//获取当前所属集团
		String pk_group = InvocationInfoProxy.getInstance().getGroupId();
		String condition = "";
		if(!"0001".equals(pk_group)){
			condition = "  and (pk_group = '"+ pk_group +"' or isnull(pk_group,'~') = '~' )";
		}
		boolean isAll = false;
		if (StringUtil.isEmptyWithTrim(moduleid))
			isAll = true;

		BaseDAO dao = new BaseDAO();
		String sql = null;
		if (!isAll)
			sql = "select * from sm_funcregister where own_module='" + moduleid
					+ "' " + condition + "  order by isfunctype desc, funcode";
		else
			sql = "select * from sm_funcregister where 1=1 " + condition + " order by isfunctype desc, funcode";
		List<FuncRegisterVO> funcList = (List<FuncRegisterVO>) dao.executeQuery(sql, new BeanListProcessor(
				FuncRegisterVO.class));

		if (!isAll)
			sql = "select * from sm_pageregister where parentid in (select cfunid from sm_funcregister where own_module='"
					+ moduleid + "' " + condition + " ) order by parentid,pagecode";
		else
			sql = "select * from sm_pageregister where parentid in (select cfunid from sm_funcregister where 1=1 " +condition+ " ) order by parentid,pagecode";
		List<PageVO> list = (List<PageVO>) dao.executeQuery(sql, new BeanListProcessor(PageVO.class));

		if (!isAll)
			sql = "select * from sm_busiactivereg where (ownertype = 0 and parent_id in (select cfunid from sm_funcregister where own_module='"
					+ moduleid
					+ "' " + condition + " )) or (ownertype = 1 and parent_id in (select page.pk_page from sm_pageregister as page, sm_funcregister as func"
					+ " where page.parentid=func.cfunid and own_module='" + moduleid + "' " +condition+ " )) order by parent_id,code";
		else
			sql = "select * from sm_busiactivereg where (ownertype = 0 and parent_id in (select cfunid from sm_funcregister where 1=1 " +condition+ ")) or (ownertype = 1 and parent_id in (select page.pk_page from sm_pageregister as page, sm_funcregister as func"
				+ " where page.parentid=func.cfunid " +condition+ " )) order by parent_id,code";
		List<BusiActiveVO> activeList = (List<BusiActiveVO>) dao.executeQuery(sql, new BeanListProcessor(
				BusiActiveVO.class));

		if (!isAll) 
			sql = "select * from dap_dapsystem where (productscope <> 1 or productscope is null) and moduleid='" + moduleid + "'";
		else
			sql = "select * from dap_dapsystem where (productscope <> 1 or productscope is null) and isnull(isncinnermodule,'Y')='Y'";
		List<ModuleVO> moduleList = (List<ModuleVO>) dao.executeQuery(sql, new BeanListProcessor(ModuleVO.class));
		ModuleVO[] modulSorted = ProductSortedUtil.modulSorted(moduleList.toArray(new ModuleVO[0]));
		List[] result = new List[4]; 
		result[0] = funcList;
		result[1] = list;
		result[2] = activeList;
		result[3] = Arrays.asList(modulSorted);
		return result;
	}
	
	/**
	 * 获取所属模块下的所有功能节点信息
	 * @param moduleid
	 * @return
	 * @throws BusinessException
	 */
	@SuppressWarnings("unchecked")
	public List[] getAllFunctionInfoOfModule(String moduleid) throws BusinessException {
		boolean isAll = false;
		if (StringUtil.isEmptyWithTrim(moduleid))
			isAll = true;

		BaseDAO dao = new BaseDAO();
		String sql = null;
		if (!isAll)
			sql = "select * from sm_funcregister where own_module='" + moduleid
					+ "' order by isfunctype desc, funcode";
		else
			sql = "select * from sm_funcregister order by isfunctype desc, funcode";
		List<FuncRegisterVO> funcList = (List<FuncRegisterVO>) dao.executeQuery(sql, new BeanListProcessor(
				FuncRegisterVO.class));

		if (!isAll)
			sql = "select * from sm_pageregister where parentid in (select cfunid from sm_funcregister where own_module='"
					+ moduleid + "') order by parentid,pagecode";
		else
			sql = "select * from sm_pageregister order by parentid,pagecode";
		List<PageVO> list = (List<PageVO>) dao.executeQuery(sql, new BeanListProcessor(PageVO.class));

		if (!isAll)
			sql = "select * from sm_busiactivereg where (ownertype = 0 and parent_id in (select cfunid from sm_funcregister where own_module='"
					+ moduleid
					+ "')) or (ownertype = 1 and parent_id in (select page.pk_page from sm_pageregister as page, sm_funcregister as func"
					+ " where page.parentid=func.cfunid and own_module='" + moduleid + "')) order by parent_id,code";
		else
			sql = "select * from sm_busiactivereg order by parent_id,code";
		List<BusiActiveVO> activeList = (List<BusiActiveVO>) dao.executeQuery(sql, new BeanListProcessor(
				BusiActiveVO.class));

		if (!isAll) 
			sql = "select * from dap_dapsystem where (productscope <> 1 or productscope is null) and moduleid='" + moduleid + "' order by moduleid";
		else
			sql = "select * from dap_dapsystem where (productscope <> 1 or productscope is null) and isnull(isncinnermodule,'Y')='Y' order by moduleid";
		List<ModuleVO> moduleList = (List<ModuleVO>) dao.executeQuery(sql, new BeanListProcessor(ModuleVO.class));

		List[] result = new List[4]; 
		result[0] = funcList;
		result[1] = list;
		result[2] = activeList;
		result[3] = moduleList;
		return result;
	}
	
	
	
	
	public ButtonRegVO[] getButtonRegVOs(String parentId, ButtonOwnerType owner) throws BusinessException {

		if (StringUtil.isEmptyWithTrim(parentId))
			return null;
		String sql = "select * from sm_butnregister where parent_id=? and btnownertype=?";
		BaseDAO dao = new BaseDAO();
		SQLParameter param = new SQLParameter();
		param.addParam(parentId);
		param.addParam(ButtonOwnerType.getButtonOwnerTypeIndex(owner));
		List<ButtonRegVO> list = (List<ButtonRegVO>) dao.executeQuery(sql, param, new BeanListProcessor(
				ButtonRegVO.class));
		return list == null ? null : list.toArray(new ButtonRegVO[0]);
	}

	public ParamRegVO[] getParamRegVOs(String parentId) throws BusinessException {

		if (StringUtil.isEmptyWithTrim(parentId))
			return null;  

		String sql = "select * from sm_paramregister where parentid=?";
		BaseDAO dao = new BaseDAO();
		SQLParameter param = new SQLParameter();
		param.addParam(parentId);
		List<ParamRegVO> list = (List<ParamRegVO>) dao
				.executeQuery(sql, param, new BeanListProcessor(ParamRegVO.class));
		return list == null ? null : list.toArray(new ParamRegVO[0]);
	}

	@SuppressWarnings("unchecked")
	@Override
	public BusiActiveRelationVO[] getBusiActiveRelBtn(String pk_busiactive) throws BusinessException {

		if (StringUtil.isEmptyWithTrim(pk_busiactive))
			return null;
		String sql = "select * from sm_busiactive_btn where pk_busiactive=? and pk_butn in (select pk_btn from sm_butnregister)";
		BaseDAO dao = new BaseDAO(); 
		SQLParameter param = new SQLParameter();
		param.addParam(pk_busiactive);
		List<BusiActiveRelationVO> list =  (List<BusiActiveRelationVO>) dao.executeQuery(sql, param,
				new BeanListProcessor(BusiActiveRelationVO.class));
		return list == null ? null : list.toArray(new BusiActiveRelationVO[0]);
	}
	@Override
	public MenuRegisterVO[] getAllMenuRegVO(boolean isLazyLoad) throws BusinessException {

		BaseDAO dao = new BaseDAO();
		String condition = "1=1 order by isdefault desc,menucode";
		Collection<MenuRegisterVO> con = dao.retrieveByClause(MenuRegisterVO.class, condition);
		if (con == null || con.isEmpty())
			return null;
		if (isLazyLoad)
			return con.toArray(new MenuRegisterVO[0]);
		
		String[] menupks = new String[con.size()];
		HashMap<String, MenuRegisterVO> menuRegMap = new HashMap<String, MenuRegisterVO>();
		int i = 0;
		for (Iterator<MenuRegisterVO> iter = con.iterator(); iter.hasNext();) {
			MenuRegisterVO vo = iter.next();
			menupks[i] = vo.getPk_menu();
			menuRegMap.put(menupks[i], vo);
		}
		
		HashMap<String, List<MenuItemVO>> menuItemMap = new HashMap<String, List<MenuItemVO>>();
		MenuItemVO[] menuitemvos = queryMenuItemVOsByMenuPks(menupks);
		if (menuitemvos != null && menuitemvos.length > 0) {
			for(MenuItemVO itemvo : menuitemvos) {
				if (menuItemMap.get(itemvo.getPk_menu()) == null) {
					ArrayList<MenuItemVO> itemlist = new ArrayList<MenuItemVO>();
					itemlist.add(itemvo);
					menuItemMap.put(itemvo.getPk_menu(), itemlist);
				} else {
					menuItemMap.get(itemvo.getPk_menu()).add(itemvo);
				}
			}
		}
		
		Iterator itemKeyit = menuRegMap.keySet().iterator();
		while(itemKeyit.hasNext()) {
			String itemkey = (String) itemKeyit.next();
			
			if (menuItemMap.get(itemkey) != null && menuItemMap.get(itemkey).size() > 0) {
				menuRegMap.get(itemkey).setMenuitems(menuItemMap.get(itemkey).toArray(new MenuItemVO[0]));
			}
		}
		
		if (menuRegMap.values() != null && menuRegMap.values().size() > 0)
			return menuRegMap.values().toArray(new MenuRegisterVO[0]);
		
		///
//		for (Iterator<MenuRegisterVO> iter = con.iterator(); iter.hasNext();) {
//			MenuRegisterVO vo = iter.next();
//			String pkMenu = vo.getPk_menu();
//			String sql = "pk_menu='" + pkMenu + "' order by menuitemcode";
//			Collection<MenuItemVO> itemcon = dao.retrieveByClause(MenuItemVO.class, sql);
//			if (itemcon != null && !itemcon.isEmpty())
//				vo.setMenuitems(itemcon.toArray(new MenuItemVO[0]));
//		}
		return null;
	}
	
	@SuppressWarnings("unchecked")
	private MenuItemVO[] queryMenuItemVOsByMenuPks(String[] pks)
			throws BusinessException {
		InSqlBatchCaller caller = new InSqlBatchCaller(pks);
		List<MenuItemVO> voList = new ArrayList<MenuItemVO>();
		try {
			voList = (List<MenuItemVO>) caller.execute(new IInSqlBatchCallBack(){
				List<MenuItemVO> result = new ArrayList<MenuItemVO>();
				@Override
				public Object doWithInSql(String inSql) throws BusinessException,
						SQLException {
					String condition = " pk_menu in " + inSql;
					Collection<MenuItemVO> c = new BaseDAO().retrieveByClause(MenuItemVO.class, condition);
					if(c != null && c.size() > 0)
						result.addAll(c);
					return result;
				}
			});
		} catch (SQLException e) {
			nc.bs.logging.Logger.debug(e.getMessage());
		}
		return ProductSortedUtil.sortMenuItems(voList.toArray(new MenuItemVO[0]));
	}
	
	@Override
	public MenuItemVO[] getAllMenuItems(String pk_menu) throws BusinessException {

		if (StringUtil.isEmptyWithTrim(pk_menu))
			return null; 
		//获取当前集团管理员所属集团
		String pk_group = InvocationInfoProxy.getInstance().getGroupId();
		String condition = "";
		if(!StringUtil.isEmpty(pk_group))
			condition = "  and (funcode in (select funcode from sm_funcregister where pk_group = '"+pk_group+"' or isnull(pk_group,'~') = '~' ) or funcode is null or funcode = '~')";
		BaseDAO dao = new BaseDAO();
		//String con = "pk_menu='" + pk_menu + "' order by menuitemcode";
		String con = "pk_menu='" + pk_menu + "' " +condition;
		Collection<MenuItemVO> itemcon = dao.retrieveByClause(MenuItemVO.class, con);
		return ProductSortedUtil.sortMenuItems(itemcon.toArray(new MenuItemVO[0]));
	}
	
	public MenuItemVO[] getAllMenuItemsExcludeOrg(String pk_menu) throws BusinessException {

		if (StringUtil.isEmptyWithTrim(pk_menu))
			return null; 

		BaseDAO dao = new BaseDAO();
		String con = "pk_menu='" + pk_menu + "'";
		Collection<MenuItemVO> itemcon = dao.retrieveByClause(MenuItemVO.class, con);
		return ProductSortedUtil.sortMenuItems(itemcon.toArray(new MenuItemVO[0]));
	}

	@Override
	public MenuItemVO[] queryMenuItemsWhere(String where) throws BusinessException {
		if(StringUtils.isEmpty(where)) {
			return null;
		}
		BaseDAO dao = new BaseDAO();
		Collection<MenuItemVO> con = dao.retrieveByClause(MenuItemVO.class, where);
		if(CollectionUtils.isEmpty(con)){
			return new MenuItemVO[0];
		}
		return ProductSortedUtil.sortMenuItems(con.toArray(new MenuItemVO[0]));
	}

	@Override
	public MenuRegisterVO getEnabledMenuVO(boolean isLazyLoad) throws BusinessException {

		BaseDAO dao = new BaseDAO();
		//获取当前所属集团
		String pk_group = InvocationInfoProxy.getInstance().getGroupId();
		String condition = "isenable='Y'";
		Collection<MenuRegisterVO> con = dao.retrieveByClause(MenuRegisterVO.class, condition);
		if (con == null || con.isEmpty())
			return null;
		MenuRegisterVO vo = con.iterator().next();
		if (!isLazyLoad) {
			condition = "pk_menu='" + vo.getPk_menu() + "'";
			Collection<MenuItemVO> conx = dao.retrieveByClause(MenuItemVO.class, condition);
			if (conx != null && !conx.isEmpty())
				vo.setMenuitems(ProductSortedUtil.sortMenuItems(conx.toArray(new MenuItemVO[0])));
		}
		return vo;
	}

	@Override
	public BusiActiveVO[] getBusiactives4Function(String funcode, boolean includeOfPages) throws BusinessException {

		if (StringUtil.isEmptyWithTrim(funcode))
			return null;

		BaseDAO dao = new BaseDAO();
		Collection<FuncRegisterVO> fcon = dao.retrieveByClause(FuncRegisterVO.class, "funcode='" + funcode + "'");
		if (fcon == null || fcon.isEmpty())
			return null;
		String cfunid = fcon.iterator().next().getCfunid();
		if (!includeOfPages) {
			Collection<BusiActiveVO> con = dao.retrieveByClause(BusiActiveVO.class, "parent_id='" + cfunid
					+ "' and ownertype=0");
			return (con == null || con.isEmpty()) ? null : con.toArray(new BusiActiveVO[0]);
		} else {
			String sql = "SELECT * FROM sm_busiactivereg "
					+ "         WHERE parent_id IN "
					+ "         ("
					+ "         	(SELECT cfunid FROM sm_funcregister WHERE funcode =?) "
					+ "         	UNION "
					+ "         	(SELECT pk_page FROM sm_pageregister WHERE parentid = (SELECT cfunid FROM sm_funcregister WHERE funcode =?))"
					+ "         ) order by code";
			SQLParameter parameter = new SQLParameter();
			parameter.addParam(funcode);
			parameter.addParam(funcode);
			List<BusiActiveVO> list = (List<BusiActiveVO>) dao.executeQuery(sql, parameter, new BeanListProcessor(
					BusiActiveVO.class));
			return list == null ? null : list.toArray(new BusiActiveVO[0]);
		}
	}

	@Override
	public BusiActiveVO[] getBusiactives4Page(String pk_page) throws BusinessException {

		if (StringUtil.isEmptyWithTrim(pk_page))
			return null;

		BaseDAO dao = new BaseDAO();
		Collection<BusiActiveVO> con = dao.retrieveByClause(BusiActiveVO.class, "parent_id='" + pk_page
				+ "' and ownertype=1 order by code");
		return (con == null || con.isEmpty()) ? null : con.toArray(new BusiActiveVO[0]);
	} 

	@Override
	public PageVO[] getPages4Function(String funcode) throws BusinessException {

		if (StringUtil.isEmptyWithTrim(funcode))
			return null;

		BaseDAO dao = new BaseDAO();
		FuncRegisterVO vo = queryFunctionByCode(funcode);
		String cfunid = vo.getCfunid();
		Collection<PageVO> con = dao.retrieveByClause(PageVO.class, "parentid='" + cfunid + "' order by pagecode");
		return (con == null || con.isEmpty()) ? null : con.toArray(new PageVO[0]);
	}

	@Override
	public FuncRegisterVO queryFunctionByCode(String funcode) throws BusinessException {

		if (StringUtil.isEmptyWithTrim(funcode))
			return null;

		
		Collection<FuncRegisterVO> con = new BaseDAO()
				.retrieveByClause(FuncRegisterVO.class, "funcode='" + funcode + "'");
		return (con == null||con.isEmpty()) ? null : con.toArray(new FuncRegisterVO[0])[0];
	}  

	@Override 
	public FuncRegisterVO queryFunctionByCFunid(String cfunid) throws BusinessException {

		if (StringUtil.isEmptyWithTrim(cfunid))
			return null;
		return (FuncRegisterVO) new BaseDAO().retrieveByPK(FuncRegisterVO.class, cfunid);
	}

	@Override
	public MenuItemVO[] queryMenuItemsByFuncode(String funcode) throws BusinessException {

		if (StringUtil.isEmptyWithTrim(funcode))
			return null;
		BaseDAO dao = new BaseDAO();
		MenuRegisterVO menu = getEnabledMenuVO(true);
		String condition = MenuItemVO.FUNCODE + "=? and " + MenuItemVO.PK_MENU + "=?";
		SQLParameter parameter = new SQLParameter();
		parameter.addParam(funcode);
		parameter.addParam(menu.getPk_menu());
		Collection<MenuItemVO> con = dao.retrieveByClause(MenuItemVO.class, condition, parameter);
		return con == null ? null : con.toArray(new MenuItemVO[0]);
	}
	
	@Override
	public String queryOrgtypeCode4Funcode(String funcode) throws BusinessException {

		if(StringUtil.isEmptyWithTrim(funcode))
			return null;
		
		String sql = "select orgtypecode from sm_funcregister where funcode=?";
		SQLParameter param = new SQLParameter();
		param.addParam(funcode);
		String orgtypecode = (String) new BaseDAO().executeQuery(sql, param, new ColumnProcessor("orgtypecode"));
		return orgtypecode;
	}
	
	@Override
	public FuncRegisterVO[] queryAllNCFunction(boolean isIncludeDisable) throws BusinessException {
		
		BaseDAO dao = new BaseDAO();
		//获取当前集团属性
		String pk_group = InvocationInfoProxy.getInstance().getGroupId();
		Collection<FuncRegisterVO> con = null;
		if(isIncludeDisable)
			if("0001".equals(pk_group)){
				con = dao.retrieveAll(FuncRegisterVO.class);
			}else{
				String sqlcondition = "  ( pk_group = '"+pk_group+"' or isnull(pk_group,'~') = '~' ) ";
				con = dao.retrieveByClause(FuncRegisterVO.class, sqlcondition);
			}
		else { 
//			String condition = "isenable is null or isenable='Y'";
			//String condition = "isnull(isenable, 'Y')='Y'";
			String condition = "";
			//添加集团属性条件
			if("0001".equals(pk_group)){
				condition = "isnull(isenable, 'Y')='Y'";
			}else{
				condition = " isnull(isenable, 'Y')='Y' and ( pk_group = '"+pk_group+"' or isnull(pk_group,'~') = '~' ) ";
			}
			con = dao.retrieveByClause(FuncRegisterVO.class, condition);
		}
		return con == null ? null : con.toArray(new FuncRegisterVO[0]);
	}

	@Override
	public FuncRegisterVO[] queryFunctionWhere(String where) throws BusinessException {
		
		if(StringUtil.isEmptyWithTrim(where))
			return null;
		BaseDAO dao = new BaseDAO();
		Collection<FuncRegisterVO> con = dao.retrieveByClause(FuncRegisterVO.class, where);
		return con == null ? null : con.toArray(new FuncRegisterVO[0]);
	}

	/**
	 * modified by hanyw1 ------2012-11-8
	 */
	@SuppressWarnings("unchecked")
	@Override
	public FuncRegisterVO[] queryFunctionsByCodes(String[] funcode) throws BusinessException {
		
		if(funcode == null || funcode.length == 0)
			return null;
		
		try{
			InSqlBatchCaller caller = new InSqlBatchCaller(funcode);
			List<FuncRegisterVO> resultList = (List<FuncRegisterVO>) caller.execute(new IInSqlBatchCallBack() {
				List<FuncRegisterVO> resultList = new ArrayList<FuncRegisterVO>();
				@Override
				public Object doWithInSql(String inSql) throws BusinessException,SQLException {
					String condition = "funcode in "+inSql;
					BaseDAO dao = new BaseDAO();
					List<FuncRegisterVO> funcVOList = (List<FuncRegisterVO>) dao.retrieveByClause(FuncRegisterVO.class, condition);
					
					if(CollectionUtils.isNotEmpty(funcVOList))
						resultList.addAll(funcVOList);
					
					return resultList;
				}
			});
			
			return CollectionUtils.isEmpty(resultList) ? null : resultList.toArray(new FuncRegisterVO[0]);
		}catch(Exception ex){
			throw new BusinessException(ex);
		}
	} 
	
	@Override
	public MenuItem[] queryAllMenuItem(boolean isLoadDisable) throws BusinessException {
		
		MenuRegisterVO menuvo = getEnabledMenuVO(false);
		MenuItemVO[] itemvos = menuvo.getMenuitems();
		FuncRegisterVO[] funcvos = queryAllNCFunction(isLoadDisable);
		
		if(funcvos == null || funcvos.length == 0 || itemvos == null || itemvos.length == 0)
			return null;
		
		Map<String, FuncRegisterVO> funcodeMap = new HashMap<String, FuncRegisterVO>();
		for(FuncRegisterVO funcvo : funcvos)
			funcodeMap.put(funcvo.getFuncode(), funcvo);
		List<MenuItem> list = new ArrayList<MenuItem>();
		for(MenuItemVO itemvo : itemvos)
		{
			String funcode = itemvo.getFuncode();
			if(itemvo.getIsmenutype() != null && itemvo.getIsmenutype().booleanValue())
				list.add(MenuItem.convertFrom(itemvo, null));
			else if(funcodeMap.containsKey(funcode))
				list.add(MenuItem.convertFrom(itemvo, funcodeMap.get(funcode)));
		}
		
		return list.toArray(new MenuItem[0]);
	}  
	
	private String getIsNodeInSql(boolean containInexeNode) {
		// 取出可执行功能节点,虚功能节点,可执行功能帧以及轻量级WEB节点
		StringBuilder builder = new StringBuilder();
		builder.append(FunRegisterConst.EXECUTABLE_FUNC_NODE).append(",");
//		builder.append(FunRegisterConst.EXECUTABLE_FUNC_FRAME).append(",");
		builder.append(FunRegisterConst.LFW_FUNC_NODE).append(",");
		builder.append(FunRegisterConst.ATTACH_FUNC_NODE);


		if (containInexeNode) {
			builder.append(",").append(FunRegisterConst.INEXECUTABLE_FUNC_NODE);
		}
		return builder.toString();
	}
	@Override
	public MenuItemVO queryMenuItemByMenucode(String menuitemcode) throws BusinessException {

		if(StringUtil.isEmptyWithTrim(menuitemcode))
			return null;
		MenuRegisterVO menuvo = getEnabledMenuVO(true);
		String enablePkMenu = menuvo.getPk_menu();
		String where = "menuitemcode=? and pk_menu=?";
		SQLParameter param = new SQLParameter();
		param.addParam(menuitemcode);
		param.addParam(enablePkMenu);
		BaseDAO dao = new BaseDAO();
		Collection<MenuItemVO> coll = dao.retrieveByClause(MenuItemVO.class, where, param);
		return coll == null || coll.isEmpty() ? null : coll.iterator().next();
	}
	
	public MenuItemVO queryMenuItemByMenucodeAndPkMenu(String menucode,String pk_menu) throws BusinessException{
		if(StringUtil.isEmptyWithTrim(menucode) && StringUtil.isEmptyWithTrim(pk_menu))
			return null;
		MenuRegisterVO menuvo = getEnabledMenuVO(true);
		String where = "menuitemcode=? and pk_menu=?";
		SQLParameter param = new SQLParameter();
		param.addParam(menucode);
		param.addParam(pk_menu);
		BaseDAO dao = new BaseDAO();
		Collection<MenuItemVO> coll = dao.retrieveByClause(MenuItemVO.class, where, param);
		return coll == null || coll.isEmpty() ? null : coll.iterator().next();
	}
	
	
	@Override 
	public MenuItemVO queryMenuItemByPk(String pk_menuitem) throws BusinessException {
		
		if(StringUtil.isEmptyWithTrim(pk_menuitem))
			return null;
		
		BaseDAO dao = new BaseDAO();
		return (MenuItemVO) dao.retrieveByPK(MenuItemVO.class, pk_menuitem);
	}
	
	@Override
	public String[] queryAllCanManagedFuncCode(String pk_org, int funType) throws BusinessException {

		FuncRegisterVO[] funcvos = queryAllCanManagedFuncNode(pk_org, funType);
		if(funcvos == null || funcvos.length == 0)
			return null;
		String[] funcodes = new String[funcvos.length];
		for(int i = 0;i < funcvos.length; i++)
			funcodes[i] = funcvos[i].getFuncode();
		return funcodes;
	}
	
	@Override
	public List<ButtonRegVO> queryButtonRegVOsInBusiActives(List<String> busiPks) throws BusinessException {
		InSqlBatchCaller caller = new InSqlBatchCaller((ArrayList<String>) busiPks);
		List<ButtonRegVO> butnButtonRegVOs = new ArrayList<ButtonRegVO>();
		try {
			butnButtonRegVOs = (List<ButtonRegVO>) caller.execute(new IInSqlBatchCallBack() {
				List<ButtonRegVO> result = new ArrayList<ButtonRegVO>();
				@Override
				public Object doWithInSql(String inSql) throws BusinessException, SQLException {
					
					String sql = "select btn.* from SM_BUTNREGISTER btn,SM_BUSIACTIVE_BTN busi_btn,SM_BUSIACTIVEREG busi where btn.pk_btn = busi_btn.pk_butn and busi_btn.pk_busiactive = busi.pk_busiactive  and busi.busi_pk in " + inSql;
					BaseDAO dao = new BaseDAO();
					List<ButtonRegVO> btnRegVOs = (List<ButtonRegVO>) dao.executeQuery(sql,new BeanListProcessor(ButtonRegVO.class));
					result.addAll(btnRegVOs);
					return result;
				}
			});
		} catch (SQLException e) {
			Logger.debug(e.getMessage());
			throw new BusinessException(e.getMessage());
		}
		return butnButtonRegVOs;
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public ButtonRegVO[] getButnRegVOsByPKArray(String[] buttonPKs)	throws BusinessException {
		if(ArrayUtils.isEmpty(buttonPKs)) return null;
		
		InSqlBatchCaller caller = new InSqlBatchCaller(buttonPKs);
		try {
			List<ButtonRegVO> butnVOList = (List<ButtonRegVO>) caller.execute(new IInSqlBatchCallBack(){
				
				List<ButtonRegVO> buttonRegList = new ArrayList<ButtonRegVO>();
				
				@Override
				public Object doWithInSql(String inSql) throws BusinessException,
						SQLException {
					String condition = " pk_btn in "+inSql;
					
					BaseDAO dao = new BaseDAO();
					
					Collection<ButtonRegVO> butnRegColl = dao.retrieveByClause(ButtonRegVO.class, condition);
					
					buttonRegList.addAll(butnRegColl);
					
					return buttonRegList;
				}
				
			});
			
			return CollectionUtils.isEmpty(butnVOList) ? null : butnVOList.toArray(new ButtonRegVO[0]);
		} catch (SQLException e) {
			throw new BusinessException(e.getMessage());
		}		
	}
	
	@Override
	public BusiActiveVO queryBusiActiveByPk(String pk_busiactive) throws BusinessException {
		
		if(StringUtil.isEmptyWithTrim(pk_busiactive))
			return null;
		
		BaseDAO dao = new BaseDAO();
		return (BusiActiveVO) dao.retrieveByPK(BusiActiveVO.class, pk_busiactive);
	}	
	
	@SuppressWarnings("unchecked")
	public BusiActiveVO[] queryBusiActiveByPKArray(String[] busiactivePKs)	throws BusinessException {
		if(ArrayUtils.isEmpty(busiactivePKs)) return null;
		
		InSqlBatchCaller caller = new InSqlBatchCaller(busiactivePKs);
		try {
			List<BusiActiveVO> busiVOList = (List<BusiActiveVO>) caller.execute(new IInSqlBatchCallBack(){
				
				List<BusiActiveVO> busiactiveList = new ArrayList<BusiActiveVO>();
				
				@Override
				public Object doWithInSql(String inSql) throws BusinessException,
						SQLException {
					String condition = BusiActiveVO.PK_BUSIACTIVE + " in "+inSql;
					
					BaseDAO dao = new BaseDAO();
					
					Collection<BusiActiveVO> butnRegColl = dao.retrieveByClause(BusiActiveVO.class, condition);
					
					busiactiveList.addAll(butnRegColl);
					
					return busiactiveList;
				}
				
			});
			
			return CollectionUtils.isEmpty(busiVOList) ? null : busiVOList.toArray(new BusiActiveVO[0]);
		} catch (SQLException e) {
			throw new BusinessException(e.getMessage());
		}		
	}	
	
	@SuppressWarnings("unchecked")
	public MenuItemVO[] queryDefaultMenuItem() throws BusinessException{
		
		List<MenuItemVO> menuItemlist = new ArrayList<MenuItemVO>();
		String condition = "isdefault='Y'";
		Collection<MenuRegisterVO> con = new BaseDAO().retrieveByClause(MenuRegisterVO.class, condition);
		if (con == null || con.isEmpty())
			return null;
		MenuRegisterVO[] menuRegisterVOs = con.toArray(new MenuRegisterVO[0]);
		for(MenuRegisterVO menuRegisterVO : menuRegisterVOs){
			String pk_menu = menuRegisterVO.getPk_menu();
			MenuItemVO[] menuItemVOs = getAllMenuItems(pk_menu);
			for(MenuItemVO menuItemVO : menuItemVOs){
				menuItemlist.add(menuItemVO);
			}
		}
		return menuItemlist.toArray(new MenuItemVO[0]);
	}

}

调用:

IFuncRegisterQueryService qry =(IFuncRegisterQueryService) NCLocator.getInstance().lookup(IFuncRegisterQueryService.class);
FuncRegisterVO function = qry.queryFunctionByCode("10140CBA");
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值