package com.vci.server.framework.delegate; import java.util.ArrayList; import java.util.List; import org.apache.commons.lang3.StringUtils; import org.hibernate.Session; import com.vci.common.exception.VciException; import com.vci.common.log.ServerWithLog4j; import com.vci.common.utility.ObjectUtility; import com.vci.corba.common.VCIError; import com.vci.corba.framework.data.FunctionInfo; import com.vci.corba.common.data.UserEntityInfo; import com.vci.server.base.delegate.BaseDelegate; import com.vci.server.base.persistence.dao.HibernateSessionFactory; import com.vci.server.framework.funcmng.function.Function; import com.vci.server.framework.funcmng.function.FunctionService; /** *

Title:模块处理

*

Description: 后台处理方法的引用

*

Copyright: Copyright {c} 2012

*

Company: VCI

* @author xf * @time 2012-5-15 * @version 1.0 */ public class FunctionDelegate extends BaseDelegate { private FunctionService service = null; public FunctionDelegate(UserEntityInfo userEntityInfo) { super(userEntityInfo); service = new FunctionService(userEntity); } public FunctionDelegate() { service = new FunctionService(); } public String saveModule(FunctionInfo info) throws VCIError { String res = ""; if (StringUtils.isBlank(info.id)) { String id = ObjectUtility.getNewObjectID36(); info.id = id; } try{ res = service.saveModule(changeFuncInfoToEntity(info)); }catch (Exception e) { //e.printStackTrace(); ServerWithLog4j.logger.error(e); throw new VCIError("0", new String[0]); } return res; } public String updateModule(FunctionInfo info) throws VCIError { String res = ""; try{ res = service.updateModule(changeFuncInfoToEntity(info)); }catch (Exception e) { //e.printStackTrace(); ServerWithLog4j.logger.error(e); throw new VCIError("0", new String[0]); } return res; } public String deleteModule(String id) throws VCIError { String res = ""; try{ res = service.deleteModule(id); }catch (Exception e) { //e.printStackTrace(); ServerWithLog4j.logger.error(e); throw new VCIError("0", new String[0]); } return res; } // public FunctionInfo[] getModuleListByParentId(String parentId,boolean isAll) throws VCIError { // List functions = null; // try{ // List list = service.getModuleListByParentId(parentId,isAll); // functions = new ArrayList(); // List filterFunctionNOs = new SpecialRoleDelegate().getFilterFunctionNOs(); // if(list.size() > 0){ // for(int i = 0;i < list.size() ;i++){ // Function function = list.get(i); // if(isAll || !filterFunctionNOs.contains(function.getModuleNo() + "")){ // functions.add(changeFuncEntityToInfo(list.get(i))); // } // } // } // }catch (Exception e) { // e.printStackTrace(); // throw new VCIError("0", new String[0]); // } // return functions.toArray(new FunctionInfo[0]); // } public FunctionInfo[] getModuleListByParentId(String parentId,boolean isAll) throws VCIError { FunctionInfo[] functions = null; try{ List list = service.getModuleListByParentId(parentId,isAll); functions = new FunctionInfo[list.size()]; if(list.size() > 0){ for(int i = 0;i < list.size() ;i++){ functions[i] = changeFuncEntityToInfo(list.get(i)); } } }catch (Exception e) { //e.printStackTrace(); ServerWithLog4j.logger.error(e); throw new VCIError("0", new String[0]); } return functions; } /** * 根据父节点ID获取其所有的子节点模块 * * @param parentId * @param isAll * @return * @throws VCIError */ public FunctionInfo[] getChildrenFunctionsByParentId(String parentId, boolean isAll) throws VCIError { FunctionInfo[] functions = null; try{ List list = service.getChildrenFunctionsByParentId(parentId, isAll); functions = new FunctionInfo[list.size()]; if(list.size() > 0){ for(int i = 0;i < list.size() ;i++){ functions[i] = changeFuncEntityToInfo(list.get(i)); } } }catch (Exception e) { //e.printStackTrace(); ServerWithLog4j.logger.error(e); throw new VCIError("120701", new String[0]); } return functions; } public FunctionInfo[] getModuleListByParentIdForBS(String parentId,boolean isAll) throws VCIError { FunctionInfo[] functions = null; try{ List list = service.getModuleListByParentIdForBS(parentId,isAll); functions = new FunctionInfo[list.size()]; if(list.size() > 0){ for(int i = 0;i < list.size() ;i++){ functions[i] = changeFuncEntityToInfo(list.get(i)); } } }catch (Exception e) { //e.printStackTrace(); ServerWithLog4j.logger.error(e); throw new VCIError("0", new String[0]); } return functions; } public FunctionInfo[] getModuleListByParentIdForCS(String parentId,boolean isAll) throws VCIError { FunctionInfo[] functions = null; try{ List list = service.getModuleListByParentIdForCS(parentId,isAll); functions = new FunctionInfo[list.size()]; if(list.size() > 0){ for(int i = 0;i < list.size() ;i++){ functions[i] = changeFuncEntityToInfo(list.get(i)); } } }catch (Exception e) { //e.printStackTrace(); ServerWithLog4j.logger.error(e); throw new VCIError("0", new String[0]); } return functions; } public FunctionInfo[] getModuleListByRoleRight(String parentId,String userName) throws VCIError { FunctionInfo[] functions = null; try{ List list = service.getModuleListByRoleRight(parentId,userName); functions = new FunctionInfo[list.size()]; if(list.size() > 0){ for(int i = 0;i < list.size() ;i++){ functions[i] = changeFuncEntityToInfo(list.get(i)); } } }catch (Exception e) { //e.printStackTrace(); ServerWithLog4j.logger.error(e); throw new VCIError("0", new String[0]); } return functions; } public FunctionInfo[] getModuleListByRoleRightForBS(String parentId,String userName) throws VCIError { FunctionInfo[] functions = null; try{ List list = service.getModuleListByRoleRightForBS(parentId,userName); functions = new FunctionInfo[list.size()]; if(list.size() > 0){ for(int i = 0;i < list.size() ;i++){ functions[i] = changeFuncEntityToInfo(list.get(i)); } } }catch (Exception e) { //e.printStackTrace(); ServerWithLog4j.logger.error(e); throw new VCIError("0", new String[0]); } return functions; } public FunctionInfo getModuleByClass(String classPath) throws VCIError { FunctionInfo function = null; try{ Function fun = service.getModuleByClass(classPath); function = changeFuncEntityToInfo(fun); }catch (Exception e) { //e.printStackTrace(); ServerWithLog4j.logger.error(e); throw new VCIError("200006", new String[0]); } return function; } /** * *

根据模块funcOid信息查询出模块对象的信息

* * @author xchao * @time 2014-6-6 * @param funcOid * @return * @throws VciException */ public FunctionInfo getFunctionObjectById(String funcOid) throws VCIError{ FunctionInfo function = new FunctionInfo(); try{ Function fun = service.getFunctionObjectById(funcOid); if(fun != null){ function = changeFuncEntityToInfo(fun); } }catch (Exception e) { //e.printStackTrace(); ServerWithLog4j.logger.error(e); throw new VCIError("200006", new String[0]); } return function; } public FunctionInfo getModuleByName(String moduleName) throws VCIError { FunctionInfo function = null; try{ Function fun = service.getModuleByName(moduleName); function = changeFuncEntityToInfo(fun); }catch (Exception e) { //e.printStackTrace(); ServerWithLog4j.logger.error(e); throw new VCIError("200006", new String[0]); } return function; } // public int getAutoModuleNo() throws VCIError { // int res = 0; // try { // res = service.getAutoModuleNo(); // } catch (Exception e) { // //e.printStackTrace(); // ServerWithLog4j.logger.error(e); // throw new VCIError("110100", new String[0]); // } // return res; // } public int checkChildObject(String moduleId) throws VCIError { int res = 0; try{ res = service.checkChildObject(moduleId); }catch (Exception e) { //e.printStackTrace(); ServerWithLog4j.logger.error(e); throw new VCIError("0", new String[0]); } return res; } /** *

Description: corba对象和实体类之间的转换

* *@author xf *@time 2012-5-15 *@return PlFunctionEntity * @param info * @return */ public Function changeFuncInfoToEntity(FunctionInfo info) throws VCIError{ Function entity = new Function(); try { entity.setId(info.id); //entity.setLayer(info.layer); entity.setName(info.name); entity.setParentId(info.parentId); entity.setResourceC(info.resourceC); entity.setSuffixC(info.suffixC); entity.setDesc(info.desc); entity.setResourceB(info.resourceB); entity.setSuffixB(info.suffixB); entity.setSequence(info.seq); //entity.setModuleNo(info.moduleNo); entity.setImage(info.image); entity.setIsValid(info.isValid); entity.setAliasName(info.aliasName); entity.setResourceDotNet(info.resourceDotNet); entity.setResourceMobile(info.resourceMobile); } catch(Exception e) { //e.printStackTrace(); ServerWithLog4j.logger.error(e); throw new VCIError("110004", new String[0]);//类型转换失败 } return entity; } /** *

Description: 实体类转换成corba对象

* *@author xf *@time 2012-5-15 *@return FunctionInfo * @param entity * @return */ public FunctionInfo changeFuncEntityToInfo(Function entity) throws VCIError { FunctionInfo info = new FunctionInfo(); try { info.id = entity.getId() == null ?"" : entity.getId(); //info.layer = entity.getLayer(); info.name = entity.getName() == null ?"" : entity.getName(); info.parentId = entity.getParentId() == null ?"" : entity.getParentId(); info.desc = entity.getDesc() == null ?"" : entity.getDesc(); info.suffixC = entity.getSuffixC() == null ?"" : entity.getSuffixC(); info.resourceC = entity.getResourceC() == null ?"" : entity.getResourceC(); info.resourceB = entity.getResourceB() == null ?"" : entity.getResourceB(); info.suffixB = entity.getSuffixB() == null ?"" : entity.getSuffixB(); info.seq = entity.getSequence(); info.image = entity.getImage() == null ? "" : entity.getImage(); info.isValid = entity.getIsValid(); info.aliasName = entity.getAliasName() == null ? "" : entity.getAliasName(); info.resourceDotNet = entity.getResourceDotNet() == null ? "" : entity.getResourceDotNet(); info.resourceMobile = entity.getResourceMobile() == null ? "" : entity.getResourceMobile(); } catch(Exception e) { //e.printStackTrace(); ServerWithLog4j.logger.error(e); throw new VCIError("110004", new String[0]);//类型转换失败 } return info; } /** * flag:nonsys删除非系统模块 * flag:business删除业务模块 * @throws VCIError */ public boolean deleteModules(String flag) throws VCIError { try{ String conditionSql = null; if(flag.equalsIgnoreCase("nonsys")){ conditionSql = "where plmoduleno not like '1%'"; }else if(flag.equalsIgnoreCase("business")){ conditionSql = "where plmoduleno like '5%' or plmoduleno like '6%' or plmoduleno like '7%' or plmoduleno like '8%' or plmoduleno like '9%'"; } if(conditionSql == null){ return true; } String delFuncOperation = "delete from plfuncoperation where plfuncoid in (select ploid from plfunction " + conditionSql + " )"; String delRoleRight = "delete from plroleright where plfuncoid in (select ploid from plfunction " + conditionSql + " )"; String delFunction = "delete from plfunction " + conditionSql; Session session = HibernateSessionFactory.getSession(); session.createSQLQuery(delFuncOperation).executeUpdate(); session.createSQLQuery(delRoleRight).executeUpdate(); session.createSQLQuery(delFunction).executeUpdate(); }catch(Throwable e){ //e.printStackTrace(); ServerWithLog4j.logger.error(e); throw new VCIError("110006", new String[0]); } return true; } /** * * 查询"功能模块管理"整个树结构并导出sql * add by caill start 2015.12.8 * */ public String[][] getAllDatas(int size) throws VCIError { String[][] res = new String[size][23]; try{ res = service.getAllDatas(size); }catch (Exception e) { //e.printStackTrace(); ServerWithLog4j.logger.error(e); throw new VCIError(); } return res; } /** * * 获取所有操作类型数量 * add by caill start 2015.12.8 * */ public int getAllModelManagementNum() throws VCIError { int res = 0; try{ res = service.getAllModelManagementNum(); }catch (Exception e) { //e.printStackTrace(); ServerWithLog4j.logger.error(e); throw new VCIError(); } return res; } //add by caill end /** * * 查询"功能模块管理"整个树结构并导出 * add by caill start * */ public String[][] checkLevel() throws VCIError { String[][] res = new String[3000][23]; try{ res = service.checkLevel(); }catch (Exception e) { ///e.printStackTrace(); ServerWithLog4j.logger.error(e); throw new VCIError("0", new String[0]); } return res; } //add by caill end /** * 导入“功能模块管理”数据 * add by caill start * */ public boolean importModules(FunctionInfo info) throws VCIError { String res = ""; if (StringUtils.isBlank(info.id)) { String id = ObjectUtility.getNewObjectID36(); info.id = id; } try{ res = service.importModules(changeFuncInfoToEntity(info)); }catch (Exception e) { //e.printStackTrace(); ServerWithLog4j.logger.error(e); throw new VCIError("0", new String[0]); } return true; } /** * 查询“功能模块管理”第一级数据 * add by caill * */ public boolean firstLevel(String plName) throws VCIError { return service.firstLevel(plName); } /** * 覆盖“功能模块管理”第一级重名的数据 * add by caill * */ public String changeFirstLevel(FunctionInfo functionInfo,String plName) throws VCIError { return service.changeFirstLevel(changeFuncInfoToEntity(functionInfo), plName); } /** * 查询“功能模块管理”第二级数据 * add by caill * */ public boolean secondLevel(String plName,String fParentId) throws VCIError { return service.secondLevel(plName,fParentId); } /** * 覆盖“功能模块管理”第二级重名的数据 * add by caill * */ public String changeSecondLevel(FunctionInfo functionInfo,String plName,String fParentId) throws VCIError { return service.changeSecondLevel(changeFuncInfoToEntity(functionInfo), plName,fParentId); } }