package com.vci.web.service.impl; import cn.hutool.core.io.FileUtil; import com.vci.corba.common.PLException; import com.vci.corba.omd.ltm.LinkType; import com.vci.corba.omd.qtm.QTInfo; import com.vci.corba.portal.data.Constraint; import com.vci.corba.portal.data.PLAction; import com.vci.corba.portal.data.PLActionCls; import com.vci.corba.portal.data.PLActionParam; import com.vci.dto.PLActionClsDTO; import com.vci.dto.PLActionDTO; import com.vci.dto.PLActionQueryDTO; import com.vci.starter.web.pagemodel.BaseResult; import com.vci.starter.web.util.ControllerUtil; import com.vci.starter.web.util.LocalFileUtil; import com.vci.web.other.ExportActionLogBean; import com.vci.web.other.ExportBeans; import com.vci.web.other.LinkQTExportData; import com.vci.web.service.*; import com.vci.web.util.*; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.web.bind.annotation.RequestBody; import javax.servlet.http.HttpServletResponse; import java.io.*; import java.util.*; import java.util.stream.Collectors; /** * Action管理的服务实现类 * @author yuxc * @date 2024-8-16 */ @Service public class OsActionServiceImpl implements OsActionServiceI { @Autowired private PlatformClientUtil platformClientUtil; /** * 保存Action分类信息 * @param pLActionCls Action分类信息 * @return 保存结果 */ @Override public BaseResult saveActionCls(PLActionClsDTO pLActionCls) throws PLException { if (pLActionCls.getName() == null || pLActionCls.getName().trim().equals("")) { throw new PLException("500", new String[]{"分类名称不能为空!"}); } if (pLActionCls.getName().equals("未分类")) { throw new PLException("500", new String[]{"未分类节点已经存在!"}); } PLActionCls pac = new PLActionCls(); pac.id = WebUtil.getSnowflakePk(); pac.name = pLActionCls.getName(); pac.pid = pLActionCls.getPid(); pac.description = pLActionCls.getDescription() == null ? "" : pLActionCls.getDescription(); pac.creator = WebUtil.getCurrentUserId(); pac.createTime = System.currentTimeMillis(); pac.serialno = pLActionCls.getSerialno(); // 保存分类信息 String message = platformClientUtil.getUIService().creaetePLActionCls(pac); if (message.startsWith("0")) { if (message.equals("01")) { message = "分类" + pac.name + "已经存在!"; } else if (message.equals("02")) { message = "同一分类下序号不能重复!"; } else { message = "保存分类时发生异常!" + message.substring(1); } throw new PLException("500", new String[]{message}); } return BaseResult.success("分类创建成功!"); } /** * 修改Action分类信息 * @param pLActionCls Action分类信息 * @return 保存结果 */ @Override public BaseResult updateActionCls(PLActionClsDTO pLActionCls) throws PLException { if (pLActionCls.getName() == null || pLActionCls.getName().trim().equals("")) { throw new PLException("500", new String[]{"分类名称不能为空!"}); } if (pLActionCls.getName().equals("未分类")) { throw new PLException("500", new String[]{"未分类节点已经存在!"}); } if (pLActionCls.getId() == null || pLActionCls.getId().trim().equals("")) { throw new PLException("500", new String[]{"主键不能为空!"}); } PLActionCls pac = new PLActionCls(); pac.name = pLActionCls.getName(); pac.pid = pLActionCls.getPid(); pac.description = pLActionCls.getDescription() == null ? "" : pLActionCls.getDescription(); pac.creator = WebUtil.getCurrentUserId(); pac.createTime = System.currentTimeMillis(); pac.serialno = pLActionCls.getSerialno(); // 修改分类信息 String message = platformClientUtil.getUIService().editPLActionCls(pac); if (message.startsWith("0")) { if (message.equals("01")) { message = "分类" + pac.name + "已经存在!"; } else if (message.equals("02")) { message = "同一分类下序号不能重复!"; } else { message = "修改分类时发生异常!" + message.substring(1); } throw new PLException("500", new String[]{message}); } return BaseResult.success("分类修改成功!"); } /** * 获取Action分类树 * isExp 是否用户导出 true是,false否 * @return 查询结果 */ @Override public BaseResult getActionTree(boolean isExp) throws PLException { PLActionCls[] clses = platformClientUtil.getUIService().getPLActionClsArray(); PLActionClsDTO treDto = new PLActionClsDTO(); treDto.setName("Action分类"); Map> allDataMap = Arrays.stream(clses).collect(Collectors.groupingBy(pl -> pl.pid)); for (PLActionCls cls : clses) { if (StringUtils.isBlank(cls.pid)) { PLActionClsDTO parentDto = new PLActionClsDTO(); parentDto.setId(cls.id); parentDto.setName(cls.name); parentDto.setPid(cls.pid); parentDto.setDescription(cls.description); parentDto.setCreator(cls.creator); parentDto.setCreateTime(cls.createTime); parentDto.setSerialno(cls.serialno); //这里处理导出树的逻辑 if(isExp){ Constraint[] consArray = new Constraint[1]; consArray[0] = new Constraint("plactioncls", cls.id); PLAction[] plActionsByConsArray = platformClientUtil.getUIService().getPLActionsByConsArray(consArray); if(parentDto.getChilds().isEmpty() && plActionsByConsArray.length == 0){ continue; } for (PLAction plAction : plActionsByConsArray) { PLActionDTO plActionDTO = new PLActionDTO(); plActionDTO.setPlName(plAction.plCode + "/" + plAction.plName); plActionDTO.setPlCode(plAction.plCode); plActionDTO.setPlOId(plAction.plOId); parentDto.getActionChilds().add(plActionDTO); } } addClsTreeNode(parentDto, allDataMap, isExp); treDto.getChilds().add(parentDto); } } PLActionClsDTO plac = new PLActionClsDTO(); plac.setName("未分类"); if(isExp){ Constraint[] consArray = new Constraint[1]; consArray[0] = new Constraint("plactioncls", ""); PLAction[] plActionsByConsArray = platformClientUtil.getUIService().getPLActionsByConsArray(consArray); for (PLAction plAction : plActionsByConsArray) { PLActionDTO plActionDTO = new PLActionDTO(); plActionDTO.setPlName(plAction.plCode + "/" + plAction.plName); plActionDTO.setPlCode(plAction.plCode); plActionDTO.setPlOId(plAction.plOId); plac.getActionChilds().add(plActionDTO); } } treDto.getChilds().add(plac); return BaseResult.success(treDto); } /** * 获取Action表格数据 * dto 查询条件 * @return 查询结果 */ @Override public BaseResult getActionTableData(PLActionQueryDTO dto) throws PLException { Constraint[] consArray ; if(StringUtils.isNotBlank(dto.getPlactioncls())){ consArray = new Constraint[7]; consArray[6] = new Constraint("plactioncls", dto.getPlactioncls()); }else { consArray = new Constraint[6]; } consArray[0] = new Constraint("plcode", dto.getPlcode()); consArray[1] = new Constraint("plname", dto.getPlname()); consArray[2] = new Constraint("plbsurl", dto.getPlbsurl()); consArray[3] = new Constraint("plcsclass", dto.getPlcsclass()); consArray[4] = new Constraint("pltypetype", dto.getPltypetype()); consArray[5] = new Constraint("pldesc", dto.getPldesc()); PLAction[] plActionsByConsArray = platformClientUtil.getUIService().getPLActionsByConsArray(consArray); Arrays.sort(plActionsByConsArray, new Comparator() { @Override public int compare(PLAction o1, PLAction o2) { String py1 = PinyinCommon.getPingYin(o1.plCode); String py2 = PinyinCommon.getPingYin(o2.plCode); return py1.compareTo(py2); } }); return BaseResult.dataList(Arrays.asList(plActionsByConsArray)); } /** * 保存Action数据 * dto action传输对象 * @return 保存结果 */ @Override public BaseResult saveAction(PLActionDTO dto) throws PLException { if(StringUtils.isBlank(dto.getPlCode())){ throw new PLException("500", new String[]{"请输入编号"}); } PLAction[] actionsInDB= platformClientUtil.getUIService().getAllPLAction(); for(int i =0;i actionOid, HttpServletResponse response) throws PLException, IOException { String defaultTempFolder = LocalFileUtil.getDefaultTempFolder(); String vciqtmfFileName = defaultTempFolder + File.separator + "actionTemplateExp" + new Date().getTime() + ".vciamf"; HashMap exportBeans = new HashMap(); getExportBeans(actionOid, exportBeans);// 获得导出Bean同时,记录log ObjectOutputStream vciamfFileStream = null; try { File vciqtmfFile = new File(vciqtmfFileName); vciamfFileStream = new ObjectOutputStream(new FileOutputStream(vciqtmfFile)); vciamfFileStream.writeObject(exportBeans); }finally { try { if (vciamfFileStream != null) { vciamfFileStream.flush(); vciamfFileStream.close(); } } catch (Exception e) { throw new PLException("500",new String[]{"导出流关闭异常!"}); } } ControllerUtil.writeFileToResponse(response,vciqtmfFileName); FileUtil.del(defaultTempFolder + File.separator); } /** * 处理导出的对象 * @param actionOid 界面选择的action列表数据 * @param exportBeansMap 导出对象 * @return * @throws PLException */ private void getExportBeans(List actionOid, HashMap exportBeansMap) throws PLException { PLActionCls[] plActionClsArray = platformClientUtil.getUIService().getPLActionClsArray(); Map clsMap = Arrays.stream(plActionClsArray).collect(Collectors.toMap(e -> e.id, e -> e)); ExportBeans exportBeans = new ExportBeans(); for (String oid : actionOid) { PLAction plAction = platformClientUtil.getUIService().getPLActionById(oid); //有父节点则进行处理 if(StringUtils.isNotBlank(plAction.plActionCls)){ allPLActionClsParent(exportBeans, clsMap.get(plAction.plActionCls), clsMap); } exportBeans.getPLActions().put(plAction.plOId, plAction); PLActionParam[] params = platformClientUtil.getUIService().getPLActionParamArrayByActionId(plAction.plOId); if(params != null && params.length > 0){//如果参数存在 for (PLActionParam plActionParam : params) {//添加action参数 exportBeans.addPLActionParamBean(plActionParam); } } String category = clsMap.containsKey(plAction.plActionCls) ? clsMap.get(plAction.plActionCls).name : ""; exportBeans.setLogBean(new ExportActionLogBean(ExportActionLogBean.RIGHT_STATE, plAction.plCode,plAction.plName,plAction.plCSClass,plAction.plBSUrl, plAction.plTypeType,plAction.plDesc,category)); } exportBeansMap.put("exportBeans", exportBeans); } //增加父类数据 private void allPLActionClsParent(ExportBeans exportBeans, PLActionCls cls, Map clsMap) { if(cls.pid != ""){ allPLActionClsParent(exportBeans, clsMap.get(cls.pid), clsMap); } exportBeans.addPLActionClsBean(cls); } /** * 添加子节点 * @param parentDto 父节点对象 * @param allDataMap 所有分组对象 * @param isExp true为导出功能的树,false为界面分类树 */ private void addClsTreeNode(PLActionClsDTO parentDto, Map> allDataMap, Boolean isExp) throws PLException { if(allDataMap.containsKey(parentDto.id)){ for (PLActionCls cls : allDataMap.get(parentDto.id)) { PLActionClsDTO childDto = new PLActionClsDTO(); childDto.setId(cls.id); childDto.setName(cls.name); childDto.setPid(cls.pid); childDto.setDescription(cls.description); childDto.setCreator(cls.creator); childDto.setCreateTime(cls.createTime); childDto.setSerialno(cls.serialno); if(isExp){ Constraint[] consArray = new Constraint[1]; consArray[0] = new Constraint("plactioncls", cls.id); PLAction[] plActionsByConsArray = platformClientUtil.getUIService().getPLActionsByConsArray(consArray); if(parentDto.getChilds().isEmpty() && plActionsByConsArray.length == 0){ continue; } for (PLAction plAction : plActionsByConsArray) { PLActionDTO plActionDTO = new PLActionDTO(); plActionDTO.setPlName(plAction.plCode + "/" + plAction.plName); plActionDTO.setPlCode(plAction.plCode); plActionDTO.setPlOId(plAction.plOId); parentDto.getActionChilds().add(plActionDTO); } } addClsTreeNode(childDto, allDataMap, isExp); parentDto.getChilds().add(childDto); } } } }