package com.vci.frameworkcore.compatibility.impl; import com.vci.client.ClientSession; import com.vci.client.common.excel.ExcelDocumentUtils; import com.vci.common.exception.VciException; import com.vci.common.utility.ObjectUtility; import com.vci.corba.common.PLException; import com.vci.corba.common.data.UserEntityInfo; import com.vci.corba.framework.data.FuncOperationInfo; import com.vci.corba.framework.data.FunctionInfo; import com.vci.corba.framework.data.OperateInfo; import com.vci.frameworkcore.compatibility.SmHMSysModConfigServiceI; import com.vci.pagemodel.MenuVO; import com.vci.starter.poi.bo.SheetDataSet; import com.vci.starter.poi.bo.SheetRowData; import com.vci.starter.poi.bo.WriteExcelData; import com.vci.starter.poi.bo.WriteExcelOption; import com.vci.starter.poi.util.ExcelUtil; import com.vci.starter.web.exception.VciBaseException; import com.vci.starter.web.pagemodel.BaseResult; import com.vci.starter.web.pagemodel.SessionInfo; import com.vci.starter.web.util.LocalFileUtil; import com.vci.starter.web.util.VciBaseUtil; import com.vci.starter.web.util.WebThreadLocalUtil; import com.vci.web.util.Func; import com.vci.web.util.PlatformClientUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import javax.servlet.http.HttpServletResponse; import java.io.*; import java.util.*; /** * 首页系统模块配置添加按钮、添加操作类型等接口服务 * @author ludc * @date 2024/8/19 12:42 */ @Service public class SmHMSysModConfigServiceImpl implements SmHMSysModConfigServiceI { @Autowired private PlatformClientUtil platformClientUtil; private List fileFunctionDatas = new ArrayList(); private int count = 0; private static FunctionOperateDelegate foDelegate; { if(Func.isEmpty(foDelegate)){ foDelegate = new FunctionOperateDelegate(); } } /** * 日志 */ private Logger logger = LoggerFactory.getLogger(getClass()); /** * 添加模块 * @param menuVO * @return */ @Override public MenuVO addModule(MenuVO menuVO) throws VciBaseException { VciBaseUtil.alertNotNull(menuVO,"新增的模块对象"); try { //往数据库里插入新建模块数据 String puid = foDelegate.saveModule(menuVO); /** * 返回值:1,表示模块名称重复 * 2,表示模块标识重复 * 3, 模板别名存在重复 */ if(puid.equals("1")){ throw new VciBaseException("模块名称重复,请修改!"); }else if(puid.equals("2")){ throw new VciBaseException("模块标识重复,请修改!"); }else if(puid.equals("3")) { throw new VciBaseException("模块别名重复,请修改!"); } menuVO.setId(puid); return menuVO; } catch (Exception e) { e.printStackTrace(); String exceptionMessage = VciBaseUtil.getExceptionMessage(e); logger.error(exceptionMessage); throw new VciBaseException(exceptionMessage); } } /** * 修改模块 * @param menuVO * @return */ @Override public MenuVO updateModule(MenuVO menuVO) throws VciBaseException { VciBaseUtil.alertNotNull(menuVO,"修改的模块对象"); try { String res = ""; //更新数据库 res = foDelegate.updateMod(menuVO); /** * 返回:1表示模块名重复。 * 2表示模块标识重复。 * 3标示模块别名重复。 */ if(res.equals("1")){ throw new VciBaseException("模块名称重复,请修改!"); }else if(res.equals("2")){ throw new VciBaseException("模块标识重复,请修改!"); }else if(res.equals("3")) { throw new VciBaseException("模块别名重复,请修改!"); }/* else if (res.equals("4")) { throw new VciBaseException("模块编号重复,请修改!"); }*/ return menuVO; } catch (VciBaseException e) { e.printStackTrace(); String exceptionMessage = VciBaseUtil.getExceptionMessage(e); logger.error(exceptionMessage); throw new VciBaseException(exceptionMessage); } } /** * 删除模块 * @param menuVO * @return */ @Override public boolean delModule(MenuVO menuVO) { VciBaseUtil.alertNotNull(menuVO,"添加操作类型的列表"); String res = ""; try { String puid = ""; if("FunctionObject".equals(menuVO.getModeType())) { puid = menuVO.getId(); }else if("modelManagmentNode".equals(menuVO.getId())) { puid = "modelManagmentNode"; }else if("systemManagmentNode".equals(menuVO.getId())) { puid = "systemManagmentNode"; } if(Func.isBlank(puid)){ throw new VciBaseException("未找到要删除的模块!"); } res = foDelegate.deleteModule(puid); /** * 返回值:1表示模块在权限模块已经有授权信息,无法删除 */ if(res.equals("1")){ throw new VciBaseException("当前模块(或下级模块)已经存在授权信息,无法删除。"); } return true; } catch (Exception e) { e.printStackTrace(); String exceptionMessage = VciBaseUtil.getExceptionMessage(e); logger.error(exceptionMessage); throw new VciBaseException(exceptionMessage); } } /** * 删除模块下关联的操作类型 * @param funcOperationInfo * @return */ @Override public boolean delFuncOperation(FuncOperationInfo funcOperationInfo) { VciBaseUtil.alertNotNull(funcOperationInfo,"删除的操作类型列表"); return foDelegate.deleteFuncOperation(funcOperationInfo); } /** * 增加操作类型 * @return */ @Override public boolean addOperationType(List funcOperationInfoList) { VciBaseUtil.alertNotNull(funcOperationInfoList,"添加操作类型的列表");//将操作类型组装成需要存储的对象 List objs = new ArrayList<>(); funcOperationInfoList.stream().forEach(info -> { if(Func.isBlank(info.funcId)){ throw new VciBaseException("父id不能为空!"); } if(Func.isBlank(info.operId)){ throw new VciBaseException("未获取操作名称!"); } info.number = -1; info.isValid = true; objs.add(info); }); //执行保存 boolean res = true; try { res = this.saveFuncOperation(objs.toArray(new FuncOperationInfo[objs.size()])); } catch (Exception e) { res = false; e.printStackTrace(); String exceptionMessage = "增加操作类型失败,原因:" + VciBaseUtil.getExceptionMessage(e); logger.error(exceptionMessage); throw new VciBaseException(exceptionMessage); } return res; } /** * 删除非系统模块 * @return */ @Override public boolean delNonsysModule() { try { if(platformClientUtil.getFrameworkService().deleteModules("nonsys")){ return true; } } catch (PLException e) { e.printStackTrace(); String exceptionMessage = "删除非系统模块失败,原因:"+VciBaseUtil.getExceptionMessage(e); logger.error(exceptionMessage); throw new VciBaseException(exceptionMessage); } return false; } /** * 删除业务模块 * @return */ @Override public boolean delBusinessModule() { try { if(platformClientUtil.getFrameworkService().deleteModules("business")){ return true; } } catch (PLException e) { e.printStackTrace(); String exceptionMessage = "删除业务模块失败,原因:"+VciBaseUtil.getExceptionMessage(e); logger.error(exceptionMessage); throw new VciBaseException(exceptionMessage); } return false; } /** * 导出sql * @return */ @Override public File exportFunctionSql(HttpServletResponse response,String exportPath,boolean isFunction) throws PLException { String dir = Func.isBlank(exportPath) ? LocalFileUtil.getDefaultTempFolder():exportPath; String[][] allDatas; int size; if(isFunction){ size = (int)platformClientUtil.getFrameworkService().getAllModelManagementNum(); allDatas = this.getAllDatas(size); }else{ size = (int)platformClientUtil.getFrameworkService().getAllOperitionsNum(); allDatas = this.getAllOperitions(size); } File file = expData(dir,isFunction, allDatas); return file; } /** * 导出 * @return */ @Override public String exportModule(HttpServletResponse response) throws IOException { String defaultTempFolder = LocalFileUtil.getDefaultTempFolder(); //写excel String excelPath = defaultTempFolder + File.separator + "module.xls"; final List columns = new ArrayList(Arrays.asList("PLNAME","PLRESOURCEC","PLSUFFIXC","PLRESOURCEB", "PLSUFFIXB","PLDESC","PLISVALID","PLIMAGE","PLMODULESEQUENCE","PLALIASNAME", "PLMODULENAME","PLRESOURCEDOTNET","PLRESOURCEMOBIL","级别","别名","PLNO","PLISVALID", "PLNAME","PLUNIQUEFLAG","PLDESC","PLALIAS","PLSEQUENCE"));// 设置表单列名 //int count = transmitTreeObject.getCurrentTreeNode().getChildCount(); new File(excelPath).createNewFile(); //设置列 List excelDataList = new ArrayList<>(10000); //设置列头 for (int index = 0; index < columns.size(); index++) { excelDataList.add(new WriteExcelData(0,index, columns.get(index))); } //查询要导出的数据 String[][] firstLevel = new String[3000][23]; try { firstLevel = this.checkLevel(); } catch (VciBaseException e) { // TODO Auto-generated catch block e.printStackTrace(); } String[][] datas = new String[10000][columns.size()]; for(int i=0;i files) throws PLException, IOException { logger.info("正在收集表单数据......"); boolean isSuccess = collectionDatas(files); logger.info("正在导入表单人员信息......"); logger.info("count==="+count); boolean resBoolean = false; if(isSuccess == false){ resBoolean = importExcelData(count); } return resBoolean ? BaseResult.success("导入成功!"):BaseResult.fail("导入失败!"); } /** * 管理功能模块、业务功能模块下的叶子节点—修改操作别名接口 * @return */ @Override public boolean updateAlias(MenuVO menuVO) throws VciException { String alias = menuVO.getAlias(); if ("".equals(alias)){ throw new VciBaseException("请填写操作别名!"); } boolean isValid = menuVO.getIsValid(); String id = menuVO.getId(); return foDelegate.updateFuncOperation(id , alias, isValid); } @Override public List getSysConfTree() { return null; } @Override public boolean addSysConf() { return false; } @Override public boolean updateSysConf() { return false; } @Override public boolean delSysConf() { return false; } @Override public String exportSysConf(HttpServletResponse response) { return null; } /** * 收集表单信息。 * @param files * @return * @throws PLException * @throws IOException */ private boolean collectionDatas(LinkedList files) throws PLException, IOException{ boolean b=false; for (File f : files) { List sheetDataSets = this.getFileList(f); if (sheetDataSets != null && !sheetDataSets.isEmpty()) { for (SheetDataSet sheet : sheetDataSets) { // sheet不能为空并且必须有出表头外的一条数据 if (sheet != null && sheet.getRowData() != null && sheet.getRowData().size() > 1) { List dataSet = sheet.getRowData(); String fParentId=""; //第一级的id(第二级的parentid) boolean boo=true; boolean first=false; String[] pd=new String[100]; int jibie=2; for (int i = 0; i < dataSet.size(); i++) { Map oneData = dataSet.get(i).getData(); String id = ObjectUtility.getNewObjectID36(); FunctionInfo funObj=new FunctionInfo(); boolean onebl=false; boolean twobl=false; boolean same=false; String plName = Func.isBlank(oneData.get(0)) ? "":oneData.get(0); if(oneData.get(14).equals("1")) { try { onebl = foDelegate.firstLevel(plName); } catch (VciException e) { // TODO Auto-generated catch block e.printStackTrace(); } //如果第一级重名 if(onebl == true) {//第一级重名后覆盖第一级 fuzhi(funObj,oneData); try { fParentId = foDelegate.changeFirstLevel(funObj,plName); pd[2]=fParentId; } catch (VciException e) { // TODO Auto-generated catch block e.printStackTrace(); } funObj.id = fParentId; fileFunctionDatas.add(funObj); first=true; } else { funObj.id = id; funObj.parentId = "modelManagmentNode"; fuzhi(funObj,oneData); fileFunctionDatas.add(funObj); first=false; } b=false; } //######################### 合并 ######################### for(jibie=2;jibie<100;jibie++){ if(oneData.get(14).equals(String.valueOf(jibie))){ if(first == true && boo == true){ try { if(pd[jibie]==null){ pd[jibie]=""; } twobl=foDelegate.secondLevel(plName,pd[jibie]); } catch (VciException e) { // TODO Auto-generated catch block e.printStackTrace(); } if(twobl==true) {//重名后覆盖 fuzhi(funObj,oneData); try { fParentId=foDelegate.changeSecondLevel(funObj,plName,pd[jibie]); pd[jibie+1]=fParentId; } catch (VciException e) { // TODO Auto-generated catch block e.printStackTrace(); } //funObj.setId(fParentId); funObj.id = pd[jibie+1]; fileFunctionDatas.add(funObj); boo = true; } } else { funObj.id = id; b = false; } } } if(oneData.get(14).equals("-1")) { importExcelData(count); FuncOperationInfo foObj = new FuncOperationInfo(); int len=fileFunctionDatas.size(); //**************同一节点下不能有相同的操作类型******************** String dataOperName=oneData.get(18); String plFuncOid=fileFunctionDatas.get(len-1).id; try { same = foDelegate.selSameOper(dataOperName,plFuncOid); } catch (VciBaseException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //****************************************************** if(same == false) { foObj.id = id; foObj.funcId = fileFunctionDatas.get(len-1).id; try { OperateInfo operObj = foDelegate.fetchOperateTypeByName(oneData.get(18)); foObj.operId = operObj.id; } catch (VciException e) { // TODO Auto-generated catch block e.printStackTrace(); } foObj.number = Integer.parseInt(oneData.get(16)); foObj.operAlias = oneData.get(15); foObj.isValid = Integer.parseInt(oneData.get(17)) != 0; try { foDelegate.saveFuncOperation2(foObj); } catch (VciException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { foObj.number = Integer.parseInt(oneData.get(16)); foObj.operAlias = oneData.get(15); foObj.isValid = Integer.parseInt(oneData.get(17)) != 0; try { foDelegate.updateOperation(foObj,dataOperName,plFuncOid); } catch (VciException e) { // TODO Auto-generated catch block e.printStackTrace(); } } count=fileFunctionDatas.size(); b=true; } } } } } } return b; } /** * 导入表单数据 * @throws VciException */ private boolean importExcelData(int count) throws PLException { boolean b=false; try { b = foDelegate.importModules(fileFunctionDatas.toArray(new FunctionInfo[fileFunctionDatas.size()]),count); } catch (VciBaseException e) { // TODO Auto-generated catch block e.printStackTrace(); } return b; } /** * 获取表单数据 * @param f * @return * @throws IOException * @throws PLException * @autor caicong * @data 2014-3-11 */ private List getFileList(File f) throws PLException, IOException { // 获取表list List sheetDataSets = ExcelUtil.readDataObjectFromExcel(f); return sheetDataSets; } /** * 查询"功能模块管理"整个树结构并导出 * add by caill start * */ private String[][] checkLevel() throws VciBaseException{ String[][] res = new String[3000][23]; try{ res = platformClientUtil.getFrameworkService().checkLevel(); }catch (PLException e) { e.printStackTrace(); throw new VciBaseException(String.valueOf(e.code), e.messages); } return res; } /** * 将查询出的数据转换成sql并写入指定路径下 * @param dir * @param plDatas * @return */ private File expData(String dir,boolean isFunction/*是否是导出管理功能模块sql*/, String[][] plDatas){ new File(dir).mkdir(); File file = new File(dir + (isFunction ? "/plfuncoperation.sql":"/ploperation.sql")); try { FileWriter w = new FileWriter(file); BufferedWriter bw = new BufferedWriter(w); System.out.println("长度为:"+plDatas.length); for(int i=0;i oneData){ functionInfo.name = oneData.get(0); functionInfo.resourceC = oneData.get(1); functionInfo.suffixC = oneData.get(2); functionInfo.desc = oneData.get(5); functionInfo.resourceB = oneData.get(3); functionInfo.suffixB = oneData.get(4); functionInfo.seq = Integer.parseInt(oneData.get(8)); functionInfo.image = oneData.get(7); functionInfo.isValid = Integer.parseInt(oneData.get(6)) != 0; functionInfo.aliasName = oneData.get(9); functionInfo.resourceDotNet = oneData.get(11); functionInfo.resourceMobile = oneData.get(12); } /** * 包含保存模块方法等操作类 */ private class FunctionOperateDelegate { /** * 判断第一级数据有没有重名的 * @param plName * @return * @throws VciException */ public boolean firstLevel(String plName) throws VciException{ try{ return platformClientUtil.getFrameworkService().firstLevel(plName); }catch (PLException e) { e.printStackTrace(); throw new VciException(String.valueOf(e.code), e.messages); } } /** * 覆盖重名的第一级数据 * add by caill * */ public String changeFirstLevel(FunctionInfo functionInfo,String plName) throws VciException{ String fParentId=""; try { fParentId= platformClientUtil.getFrameworkService().changeFirstLevel(functionInfo, plName); } catch (PLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return fParentId; } /** * 判断第二级数据有没有重名的 * add by caill * */ public boolean secondLevel(String plName,String fParentId) throws VciException{ try{ return platformClientUtil.getFrameworkService().secondLevel(plName,fParentId); }catch (PLException e) { e.printStackTrace(); throw new VciException(String.valueOf(e.code), e.messages); } } /** * 覆盖重名的第二级数据 * add by caill * */ public String changeSecondLevel(FunctionInfo functionInfo,String plName,String fParentId) throws VciException{ String sParentId=""; try { sParentId= platformClientUtil.getFrameworkService().changeSecondLevel(functionInfo, plName,fParentId); } catch (PLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return sParentId; } /** * 保存模块 * @param object * @return * @throws VciException */ public String saveModule(MenuVO object) throws VciBaseException { String res = ""; try{ res = platformClientUtil.getFrameworkService().saveModule(this.check(object,"add"),this.getUserEntityInfo()); }catch (PLException e) { e.printStackTrace(); throw new VciBaseException(String.valueOf(e.code), e.messages); } return res; } /** * 修改模块 * @param object * @return * @throws VciException */ public String updateMod(MenuVO object) throws VciBaseException { String res = ""; try{ res = platformClientUtil.getFrameworkService().updateModule(this.check(object,"update"),this.getUserEntityInfo()); }catch (PLException e) { e.printStackTrace(); throw new VciBaseException(String.valueOf(e.code), e.messages); } return res; } /** * 删除模块 * @param puid * @return * @throws VciException */ public String deleteModule(String puid) throws VciBaseException{ String res = ""; try{ res = platformClientUtil.getFrameworkService().deleteModule(puid,this.getUserEntityInfo()); }catch (PLException e) { e.printStackTrace(); throw new VciBaseException(String.valueOf(e.code), e.messages); } return res; } /** * 移除模块下的操作 * @param funcOperationInfo * @return * @throws VciException */ public boolean deleteFuncOperation(FuncOperationInfo funcOperationInfo) throws VciBaseException{ boolean res = true; try{ res = platformClientUtil.getFrameworkService().deleteFuncOperation(funcOperationInfo, this.getUserEntityInfo()); }catch (PLException e) { e.printStackTrace(); throw new VciBaseException(String.valueOf(e.code), e.messages); } return res; } /** * VO转DO对象 * @return */ public FunctionInfo menuVO2FunctionInfo(MenuVO object){ FunctionInfo info = new FunctionInfo(); info.id = object.getId() == null ? "" : object.getId(); info.name = object.getName() == null ? "" : object.getName(); info.parentId = object.getParentId() == null ? "" : object.getParentId(); info.resourceC = object.getPathC() == null ? "" : object.getPathC(); //info.suffixC = object.getSuffixC() == null ? "" : object.getSuffixC(); info.resourceB = object.getPath() == null ? "" : object.getPath(); //info.suffixB = object.getSuffixB() == null ? "" : object.getSuffixB(); info.desc = object.getRemark() == null ? "" : object.getRemark(); info.seq = object.getSort(); info.image = object.getSource() == null ? "" : object.getSource(); info.isValid = object.getIsValid(); info.aliasName = object.getAlias() == null ? "" : object.getAlias(); info.resourceDotNet = object.getResourceDotNet() == null ? "" : object.getResourceDotNet(); info.resourceMobile = object.getResourceMobile() == null ? "" : object.getResourceMobile(); info.desc = object.getRemark(); return info; } /** *

Description: 页面输入的校验

* *@author xf *@time 2012-5-15 *@return FunctionObject * @return */ private FunctionInfo check(MenuVO menuVO,String type) { FunctionInfo obj = new FunctionInfo(); //获取表单输入的值 String modelName = menuVO.getName(); String csIdentity = menuVO.getPathC(); String bsIdentity = menuVO.getPath(); String aliasName = menuVO.getAlias(); String resDotNet = menuVO.getResourceDotNet(); String resMobile = menuVO.getResourceMobile(); int sequence = Func.isNotEmpty(menuVO.getSort()) ? menuVO.getSort():1; String description = menuVO.getRemark(); if(Func.isBlank(modelName)) { throw new VciBaseException("模块名不能为空!"); }else if(modelName.length() > 128) { throw new VciBaseException("模块名长度不能超过128!"); }else if(Func.isNotBlank(description) && description.length() > 255) { throw new VciBaseException("描述长度不能超过255!"); }else if(Func.isNotBlank(csIdentity) && csIdentity.length() > 255) { throw new VciBaseException("C/S标识长度不能超过255!"); } else if(Func.isNotBlank(resDotNet) && resDotNet.length() > 255) { throw new VciBaseException(".NET标识长度不能超过255!"); }else if(Func.isNotBlank(resMobile) && resMobile.length() > 255) { throw new VciBaseException("Mobile标识长度不能超过255!"); } else if (sequence < 0) { throw new VciBaseException("序号不能小于0!"); } if(type.equals("add")){ //给object对象赋值 /*String parentId = ""; if(menuVO.getModeType().equals("FunctionObject")) { parentId = menuVO.getParentId(); }else if("modelManagmentNode".equals(menuVO.getParentId())) { parentId = "modelManagmentNode"; }else if("systemManagmentNode".equals(menuVO.getParentId())) { parentId = "systemManagmentNode"; }*/ obj.parentId = menuVO.getParentId(); }else{ obj.id = menuVO.getId(); obj.parentId = menuVO.getParentId(); } obj.name = modelName; obj.resourceC = csIdentity; obj.desc = description; obj.resourceB = bsIdentity; /*obj.suffixC = ""; obj.suffixB = "";*/ obj.seq = sequence; obj.image = menuVO.getSource(); obj.isValid = Func.isNotEmpty(menuVO.getValid()) ? menuVO.getValid():false; obj.aliasName = aliasName; obj.resourceDotNet = resDotNet; obj.resourceMobile = resMobile; return obj; } /** * 获取UserEntityInfo对象 * @return */ public UserEntityInfo getUserEntityInfo(){ SessionInfo sessionInfo = WebThreadLocalUtil.getCurrentUserSessionInfoInThread(); UserEntityInfo userEntityInfo = new UserEntityInfo(sessionInfo.getUserId(), ""); return userEntityInfo; } /** * 导入模块对象 * add by caill * */ public boolean importModules(FunctionInfo[] funObject,int count) throws VciBaseException{ boolean b=false; int len = funObject.length; List funInfoList = new ArrayList(); for(int i = count ; i