wangting
2025-01-03 6f7f3834f66b08bed7af331ce1a168d6cd89292d
Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsActionServiceImpl.java
@@ -1,27 +1,34 @@
package com.vci.web.service.impl;
import cn.hutool.core.io.FileUtil;
import com.vci.constant.FrameWorkLangCodeConstant;
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.dto.*;
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.util.ControllerUtil;
import com.vci.starter.web.util.LangBaseUtil;
import com.vci.starter.web.util.LocalFileUtil;
import com.vci.web.enumpck.ActionEnum;
import com.vci.web.enumpck.PlTypetypeEnum;
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 com.vci.web.service.OsActionServiceI;
import com.vci.starter.web.util.Lcm.Func;
import com.vci.web.util.PinyinCommon;
import com.vci.web.util.PlatformClientUtil;
import com.vci.web.util.WebUtil;
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 org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
@@ -95,6 +102,7 @@
        PLActionCls pac = new PLActionCls();
        pac.name = pLActionCls.getName();
        pac.pid = pLActionCls.getPid();
        pac.id = pLActionCls.getId();
        pac.description = pLActionCls.getDescription() == null ? "" : pLActionCls.getDescription();
        pac.creator = WebUtil.getCurrentUserId();
        pac.createTime = System.currentTimeMillis();
@@ -124,14 +132,15 @@
        PLActionCls[] clses = platformClientUtil.getUIService().getPLActionClsArray();
        PLActionClsDTO treDto = new PLActionClsDTO();
        treDto.setName("Action分类");
        treDto.setId("root");
        Map<String, List<PLActionCls>> allDataMap = Arrays.stream(clses).collect(Collectors.groupingBy(pl -> pl.pid));
        for (PLActionCls cls : clses) {
            if (StringUtils.isBlank(cls.pid)) {
            if (StringUtils.isBlank(cls.pid) || cls.pid.equals("root")) {
                PLActionClsDTO parentDto = new PLActionClsDTO();
                parentDto.setId(cls.id);
                parentDto.setName(cls.name);
                parentDto.setPid(cls.pid);
                parentDto.setPid("root");
                parentDto.setDescription(cls.description);
                parentDto.setCreator(cls.creator);
                parentDto.setCreateTime(cls.createTime);
@@ -181,9 +190,10 @@
    @Override
    public BaseResult getActionTableData(PLActionQueryDTO dto) throws PLException {
        Constraint[] consArray ;
        if(StringUtils.isNotBlank(dto.getPlactioncls())){
        //这儿要用!=null控制,查询未分类节点的时候传的""
        if(dto.getPlactioncls() != null){
            consArray = new Constraint[7];
            consArray[6] = new Constraint("plactioncls", dto.getPlactioncls());
            consArray[6] = new Constraint("plactioncls", dto.getPlactioncls().equals("root") ? "": dto.getPlactioncls());
        }else {
            consArray = new Constraint[6];
        }
@@ -231,6 +241,7 @@
        plAction.plModifyUser = WebUtil.getCurrentUserId();
        plAction.plActionCls = StringUtils.defaultString(dto.getPlActionCls());
        plAction.plTypeType = StringUtils.defaultString(dto.getPlTypeType());
        plAction.plImage = StringUtils.defaultString(dto.getPlImage());
        boolean b = platformClientUtil.getUIService().savePLAction(plAction);
        if(!b){
            throw new PLException("500", new String[]{"保存失败!!"});
@@ -264,6 +275,7 @@
        plAction.plModifyUser = WebUtil.getCurrentUserId();
        plAction.plActionCls = StringUtils.defaultString(dto.getPlActionCls());
        plAction.plTypeType = StringUtils.defaultString(dto.getPlTypeType());
        plAction.plImage = StringUtils.defaultString(dto.getPlImage());
        boolean b = platformClientUtil.getUIService().updatePLAction(plAction);
        if(!b){
            throw new PLException("500", new String[]{"修改失败!!"});
@@ -289,6 +301,7 @@
        plAction.plModifyUser = WebUtil.getCurrentUserId();
        plAction.plActionCls = StringUtils.defaultString(dto.getPlActionCls());
        plAction.plTypeType = StringUtils.defaultString(dto.getPlTypeType());
        plAction.plImage = StringUtils.defaultString(dto.getPlImage());
        boolean b = platformClientUtil.getUIService().deletePLAction(plAction);
        if(!b){
            throw new PLException("500", new String[]{"删除失败!!"});
@@ -302,7 +315,7 @@
    @Override
    public void exportBeans(List<String> actionOid, HttpServletResponse response) throws PLException, IOException {
        String defaultTempFolder = LocalFileUtil.getDefaultTempFolder();
        String vciqtmfFileName = defaultTempFolder + File.separator + "actionTemplateExp" + new Date().getTime() + ".vciamf";
        String vciqtmfFileName = defaultTempFolder + File.separator + "VCIACTIONMODELFILE" + new Date().getTime() + ".vciamf";
        HashMap exportBeans = new HashMap<String, Object>();
        getExportBeans(actionOid, exportBeans);// 获得导出Bean同时,记录log
@@ -325,6 +338,603 @@
        FileUtil.del(defaultTempFolder + File.separator);
    }
    @Override
    public BaseResult impData(MultipartFile file) throws IOException, PLException {
        // 导入的对象
        ExportBeans exportBeans = null;
        if (file == null) {
            return BaseResult.fail(FrameWorkLangCodeConstant.IMPORT_FAIL, new String[]{"无导入的文件"});
        }
        if (!file.getOriginalFilename().endsWith(".vciamf")) {
            throw new VciBaseException("仅能上传.vciqtf格式文件,请重新上传!");
        }
        HashMap map;
        try {
            ObjectInputStream obj = new ObjectInputStream(file.getInputStream());
            map = (HashMap) obj.readObject();
        } catch (ClassNotFoundException e) {
            return BaseResult.fail("导入对象未获取成功!!导入对象版本号不同!");
        }
        //最终的持久化
        ArrayList<PLActionCls> pLActionClsList = new ArrayList<>();
        // 更换actionId后,可以从此导航中获得原来的id
        HashMap<String /* newId */, String /* oldId */> actionIdNav = new HashMap<String /* newId */, String /* oldId */>();
        // 更换actionClsId后,可以从此导航中获得原来的id
        HashMap<String /* newId */, String /* oldId */> actionClsIdNav = new HashMap<String /* newId */, String /* oldId */>();
        //保存所有父分类,用id主key
        HashMap<String/*id*/,PLActionCls> actionClses = new HashMap<String/*id*/,PLActionCls>();
        // 存储符合条件的PLAction
        ArrayList<PLAction> optionPLActionList = new ArrayList<>();
        // 存储符合条件的PLActionCls
        ArrayList<PLActionCls> optionPLActionClsList =  new ArrayList<>();
        // 库中的所有Action分类对象
        PLActionCls[] pLActionClses = null;
        exportBeans = (ExportBeans) map.get("exportBeans");
        // 添加导入的数据
        addImportData(exportBeans, pLActionClsList, actionIdNav, actionClsIdNav, optionPLActionClsList, pLActionClses, optionPLActionList);
        // 将PLActionCls 、PLAction 对应的set集合转换成数组(匹配原addExportTreeNode方法)
        PLActionCls[] newPLActionClsArray = new PLActionCls[optionPLActionClsList.size()];
        PLAction[] newPLActionArray = new PLAction[optionPLActionList.size()];
        optionPLActionClsList.toArray(newPLActionClsArray);
        optionPLActionList.toArray(newPLActionArray);
        //清楚分类id
        actionClses.clear();
        //保存所有分类id
        for (int i = 0; i < newPLActionClsArray.length; i++) {
            actionClses.put(newPLActionClsArray[i].id,newPLActionClsArray[i]);
        }
        //保存所有存在action的分类(子分类存在action也保存)
        HashSet<PLActionCls> pLActionClss =new HashSet<PLActionCls> ();
        for (int i = 0; i < newPLActionArray.length; i++) {
            //缓存该分类的所有父分类
            saveParentCls(newPLActionArray[i].plActionCls,pLActionClss,actionClses);
        }
        PLActionCls[] actionClslist = new PLActionCls[pLActionClss.size()];
        pLActionClss.toArray(actionClslist);
        PLActionClsDTO treDto = new PLActionClsDTO();
        treDto.setName("Action分类");
        Map<String, List<PLAction>> plActionMap = Arrays.stream(newPLActionArray).collect(Collectors.groupingBy(e -> e.plActionCls));
        Map<String, List<PLActionCls>> plActionClsMap = pLActionClss.stream().collect(Collectors.groupingBy(e -> e.pid));
        Map<String, List<PLActionCls>> allCls = Arrays.stream(platformClientUtil.getUIService().getPLActionClsArray()).collect(Collectors.groupingBy(e -> e.name));
        // 添加子节点(源树节点)
        for (Map.Entry<String, PLActionCls> entry : exportBeans.getPLActionClsBeans().entrySet()) {
            if (StringUtils.isBlank(entry.getValue().pid)) {
                PLActionClsDTO parentDto = new PLActionClsDTO();
                parentDto.setId(entry.getValue().id);
                parentDto.setName(entry.getValue().name);
                parentDto.setPid(entry.getValue().pid);
                parentDto.setDescription(entry.getValue().description);
                parentDto.setCreator(entry.getValue().creator);
                parentDto.setCreateTime(entry.getValue().createTime);
                parentDto.setSerialno(entry.getValue().serialno);
                addExportTreeNode(plActionClsMap, plActionMap, parentDto, allCls, exportBeans);
                treDto.getChilds().add(parentDto);
            }
        }
        PLActionClsDTO noDto = new PLActionClsDTO();
        noDto.setName("未分类");
        if(plActionMap.containsKey("")){
            for (PLAction plAction : plActionMap.get("")) {
                PLActionClsDTO childPrentDto = new PLActionClsDTO();
                if (plAction.plName.endsWith("@#修改$%")) {
                    childPrentDto.setName(plAction.plCode + "/" + plAction.plName.replace("@#修改$%", "【修改完成】"));
                    plAction.plName = plAction.plName.replace("@#修改$%", "");
                    platformClientUtil.getUIService().updatePLAction(plAction);
                }else
                if (plAction.plName.endsWith("@#存在在未分类中$%")) {
                    childPrentDto.setName(plAction.plCode + "/" + plAction.plName.replace("@#存在在未分类中$%", "【action存在在未分类中,修改完成】"));
                    plAction.plName = plAction.plName.replace("@#存在在未分类中$%", "");
                    platformClientUtil.getUIService().updatePLAction(plAction);
//                    plAction.plName = plAction.plName.replace("@#存在在未分类中$%", "【action存在在未分类中,修改Action并按导入文件创建action分类】");
                }
                else {
                    childPrentDto.setName(plAction.plCode + "/" + "【新增完成】");
//                    plAction.plName += "【新增】";
                    platformClientUtil.getUIService().savePLAction(plAction);
                }
                dealParam(exportBeans, plAction);
                childPrentDto.setId(plAction.plOId);
                childPrentDto.setPid(plAction.plActionCls);
                noDto.getChilds().add(childPrentDto);
            }
        }
        treDto.getChilds().add(noDto);
        return BaseResult.success(treDto);
    }
    /**
     * 导出Action
     * @param plActionExpDTO 导出属性设置对象
     */
    @Override
    public void exportAction(PLActionExpDTO plActionExpDTO, HttpServletResponse response) throws PLException, IOException {
        String defaultTempFolder = LocalFileUtil.getDefaultTempFolder();
        String excelPath = defaultTempFolder + File.separator + plActionExpDTO.getFileName() + ".xls";
        try {
            new File(excelPath).createNewFile();
        } catch (Throwable e) {
            throw new VciBaseException(LangBaseUtil.getErrorMsg(e), new String[]{excelPath}, e);
        }
        isValidPageForamt(plActionExpDTO);
        //设置列
        List<WriteExcelData> excelDataList = new ArrayList<>();
        //设置列头
        for (int index = 0; index < plActionExpDTO.getColumnName().size(); index++) {
            excelDataList.add(new WriteExcelData(0,index, plActionExpDTO.getColumnName().get(index)));
        }
        PLAction[] allPLAction ;
        if(plActionExpDTO.getDataType().equals(ActionEnum.EXP_ALL.getValue()) ||
                plActionExpDTO.getDataType().equals(ActionEnum.EXP_PAGE.getValue())){
            allPLAction = platformClientUtil.getUIService().getAllPLAction();
        }else{
            allPLAction = new PLAction[plActionExpDTO.getChooseDataOid().size()];
            for (int i = 0; i < plActionExpDTO.getChooseDataOid().size(); i++) {
                allPLAction[i] = platformClientUtil.getUIService().getPLActionById(plActionExpDTO.getChooseDataOid().get(i));
            }
        }
        if(Func.isEmpty(allPLAction)){
            excelDataList.add(new WriteExcelData(1,1, "根据属性名称未查询到属性信息,请刷新后尝试重新导出!"));
        }else{
            for (int i = 0; i < allPLAction.length; i++) {
                PLAction action = allPLAction[i];
                List<String> columnName = plActionExpDTO.getColumnName();
                for (int index = 0; index < columnName.size(); index++) {
                    switch (columnName.get(index)){
                        case "编号":
                            excelDataList.add(new WriteExcelData(i+1,index, action.plCode));
                            break;
                        case "类路径":
                            excelDataList.add(new WriteExcelData(i+1,index, action.plBSUrl));
                            break;
                        case "链接地址":
                            excelDataList.add(new WriteExcelData(i+1,index, action.plCSClass));
                            break;
                        case "描述":
                            excelDataList.add(new WriteExcelData(i+1,index, action.plDesc));
                            break;
                        case "类型":
                            excelDataList.add(new WriteExcelData(i+1,index, action.plTypeType.equals(PlTypetypeEnum.BUSINESS.getValue()) ?
                                    PlTypetypeEnum.BUSINESS.getText() : PlTypetypeEnum.LINK.getText()));
                            break;
                        case "名称":
                            excelDataList.add(new WriteExcelData(i+1,index, action.plName));
                            break;
                    }
                }
            }
        }
        WriteExcelOption excelOption = new WriteExcelOption(excelDataList);
        ExcelUtil.writeDataToFile(excelPath, excelOption);
        ControllerUtil.writeFileToResponse(response,excelPath);
        FileUtil.del(defaultTempFolder + File.separator);
    }
    /**
     * 保存Action参数数据
     * dto action传输对象
     * @return 保存结果
     */
    @Override
    public BaseResult savePLActionParam(PLActionParamDTO dto) throws PLException {
        if(dto.getName() == null || dto.getName().equals("")) {
            throw new PLException("500",new String[]{"参数名称不能为空"});
        }
        PLActionParam param = new PLActionParam();
        param.oid = "";
        param.name = dto.getName();
        param.defaultValue = dto.getDefaultValue();
        param.description = dto.getDescription();
        param.action = dto.getAction();
        String message = platformClientUtil.getUIService().createPLActionParam(param);
        if(message.startsWith("0")) {
            if(message.equals("01")) {
                throw new PLException("500",new String[]{"参数名已经存在!"});
            } else {
                throw new PLException("500",new String[]{"添加按钮参数时发生异常:" + message.substring(1)});
            }
        }
        return BaseResult.success();
    }
    @Override
    public BaseResult updatePLActionParam(PLActionParamDTO dto) throws PLException {
        if(dto.getName() == null || dto.getName().equals("")) {
            throw new PLException("500",new String[]{"参数名称不能为空"});
        }
        PLActionParam param = new PLActionParam();
        param.oid = dto.getOid();
        param.name = dto.getName();
        param.defaultValue = dto.getDefaultValue();
        param.description = dto.getDescription();
        param.action = dto.getAction();
        String message = platformClientUtil.getUIService().editPLActionParam(param);
        if(message.startsWith("0")) {
            if(message.equals("01")) {
                throw new PLException("500",new String[]{"参数名已经存在!"});
            } else {
                throw new PLException("500",new String[]{"添加按钮参数时发生异常:" + message.substring(1)});
            }
        }
        return BaseResult.success();
    }
    /**
     * 删除Action参数数据
     * oid 参数主键
     * @return 保存结果
     */
    @Override
    public BaseResult deletePLActionParam(String oid) throws PLException {
        if(StringUtils.isBlank(oid)){
            throw new PLException("500", new String[]{"参数主键不能为空"});
        }
        String message = platformClientUtil.getUIService().deletePLActionParam(oid);
        if (message.startsWith("0")) {
            throw new PLException("500", new String[]{"删除按钮参数时发生异常:" + message.substring(1)});
        }
        return BaseResult.success();
    }
    /**
     * 查询Action参数列表数据
     * actionOid 参数主键
     * @return 保存结果
     */
    @Override
    public BaseResult getPLActionParam(String actionOid) throws PLException {
        if (StringUtils.isBlank(actionOid)){
            throw new PLException("500", new String[]{"Action主键不能为空!"});
        }
        PLActionParam[] paramArrays = platformClientUtil.getUIService().getPLActionParamArrayByActionId(actionOid);
        List<PLActionParamDTO> dtos = new ArrayList<>();
        for (PLActionParam paramArray : paramArrays) {
            PLActionParamDTO dto = new PLActionParamDTO();
            dto.setAction(paramArray.action);
            dto.setOid(paramArray.oid);
            dto.setName(paramArray.name);
            dto.setDescription(paramArray.description);
            dto.setDefaultValue(paramArray.defaultValue);
            dtos.add(dto);
        }
        return BaseResult.dataList(dtos);
    }
    /**
     * 删除分类
     * @param dto 分类对象
     * @return 处理结果
     * @throws PLException
     */
    @Override
    public BaseResult deleteActionCls(PLActionClsDTO dto) throws PLException {
        PLActionCls[] clses = platformClientUtil.getUIService().getPLActionClsArray();
        // 将所有分类父分类保存
        HashSet<String> clsPids = new HashSet<String>();
        for (PLActionCls plActionCls : clses) {
            clsPids.add(plActionCls.pid);
        }
        if (dto.getName().equals("未分类")) {
            throw new PLException("500", new String[]{"未分类不能删除!"});
        }
        if (clsPids.contains(dto.getId())) {
            throw new PLException("500", new String[]{"该分类下存在子分类不能删除!\n请删除此分类下的子分类!"});
        }
        // 执行删除操作
        PLActionCls actionCls = new PLActionCls();
        actionCls.id = dto.getId();
        actionCls.name = dto.getName();
        String message = platformClientUtil.getUIService().deletePLActionCls(actionCls);
        if (message.startsWith("0")) {
            throw new PLException("500", new String[]{"删除分类失败!" + message.substring(1)});
        }
        return BaseResult.success("分类删除成功!" + message.substring(1));
    }
    public boolean isValidPageForamt(PLActionExpDTO plActionExpDTO) throws PLException {
        boolean res = false;
        if(plActionExpDTO.getDataType().equals(ActionEnum.EXP_ALL.getValue()) ||
                plActionExpDTO.getDataType().equals(ActionEnum.EXP_CHOOSE.getValue())) {
            res = true;
            return res;
        }
        if(StringUtils.isBlank(plActionExpDTO.getPageNum())){
            throw new PLException("500", new String[]{"页码不能为空"});
        } else{
            int pageCount = 1;//这里固定由于界面没有翻页功能
            String[] pages = plActionExpDTO.getPageNum().split("-");
            // 用dobule接收输入的数据,防止输入超大值(大于Integer.MAX_VALUE)
            // 转换成Integer,进行比较,及在提示内容中去掉double类型数据可能会出现的小数点
            if(pages.length == 1){
                double pageD = Double.parseDouble(pages[0]);
                if(pageD > Integer.MAX_VALUE){
                    throw new PLException("500", new String[]{"起始页码 " + String.valueOf(pageD) + " 不得大于 " + Integer.MAX_VALUE});
                }else{
                    int page = (int)pageD;
                    if(page > pageCount){
                        throw new PLException("500", new String[]{"输入的页码 " + page + " 不得大于总页数 " + pageCount});
                    } else if(page > Integer.MAX_VALUE){
                        throw new PLException("500", new String[]{"输入的页码 " + page + " 不得大于 " + Integer.MAX_VALUE});
                    } else {
                        res = true;
                    }
                }
            } else{
                double pageStartD = Double.parseDouble(pages[0]);
                double pageEndD = Double.parseDouble(pages[1]);
                if(pageStartD > Integer.MAX_VALUE){
                    throw new PLException("500", new String[]{"起始页码 " + pageStartD + " 不得大于 " + Integer.MAX_VALUE});
                } else if(pageEndD > Integer.MAX_VALUE){
                    throw new PLException("500", new String[]{"结束页码 " + pageEndD + " 不得大于 " + Integer.MAX_VALUE});
                } else{
                    int pageStart = (int)pageStartD;
                    int pageEnd = (int)pageEndD;
                    if(pageStart > pageCount){
                        throw new PLException("500", new String[]{"起始页码 " + pageStart + " 不得大于总页数 " + pageCount});
                    } else if(pageEnd > pageCount){
                        throw new PLException("500", new String[]{"结束页码 " + pageEnd + " 不得大于总页数 " + pageCount});
                    } else if(pageStart > pageEnd){
                        throw new PLException("500", new String[]{"起始页码 " + pageStart + " 不得大于结束页码 " + pageEnd});
                    } else{
                        res = true;
                    }
                }
            }
        }
        return res;
    }
    /**
     * 处理参数列表
     * @param exportBeans 导入数据集合
     * @param plAction action对象
     * @throws PLException
     */
    private void dealParam(ExportBeans exportBeans, PLAction plAction) throws PLException {
        PLActionParam[] plActionParamArrayByActionId = exportBeans.getPLActionParamArrayByActionId(plAction.plOId);
        PLActionParam[] paramArray = platformClientUtil.getUIService().getPLActionParamArrayByActionId(plAction.plOId);
        Map<String, List<PLActionParam>> params = Arrays.stream(paramArray).collect(Collectors.groupingBy(e -> e.oid));
        if(plActionParamArrayByActionId == null){
            return;
        }
        for (PLActionParam param : plActionParamArrayByActionId) {
            if(params.containsKey(param)){
                platformClientUtil.getUIService().editPLActionParam(param);
            }else {
                platformClientUtil.getUIService().createPLActionParam(param);
            }
        }
    }
    private void addExportTreeNode(Map<String, List<PLActionCls>> pLActionClses, Map<String, List<PLAction>> plActions,
                                   PLActionClsDTO parentDto,Map<String, List<PLActionCls>> allCls, ExportBeans exportBeans) throws PLException {
        //处理当前节点下的action
        if(plActions.containsKey(parentDto.getId())){
            for (PLAction plAction : plActions.get(parentDto.getId())) {
                PLActionClsDTO childPrentDto = new PLActionClsDTO();
                childPrentDto.setId(plAction.plOId);
                if (plAction.plName.endsWith("@#修改$%")) {
                    childPrentDto.setName(plAction.plCode + "/" + plAction.plName.replace("@#修改$%", "【修改成功】"));
//                    plAction.plName = plAction.plName.replace("@#修改$%", "【修改】");
                    plAction.plName = plAction.plName.replace("@#修改$%", "");
                    platformClientUtil.getUIService().updatePLAction(plAction);
                }else
                if (plAction.plName.endsWith("@#存在在未分类中$%")) {
                    childPrentDto.setName(plAction.plCode + "/" + plAction.plName.replace("@#存在在未分类中$%", "【action存在在未分类中,修改Action成功】"));
//                    plAction.plName = plAction.plName.replace("@#存在在未分类中$%", "【action存在在未分类中,修改Action并按导入文件创建action分类】");
                    plAction.plName = plAction.plName.replace("@#存在在未分类中$%", "");
                    platformClientUtil.getUIService().updatePLAction(plAction);
                }
                else {
                    childPrentDto.setName(plAction.plCode + "/" + plAction.plName.replace("@#新增%", "【新增成功】"));
//                    plAction.plName += "【新增】";
                    platformClientUtil.getUIService().savePLAction(plAction);
                }
                dealParam(exportBeans, plAction);
                childPrentDto.setPid(plAction.plActionCls);
                parentDto.getChilds().add(childPrentDto);
            }
        }
        if(pLActionClses.containsKey(parentDto.getId())){
            List<PLActionCls> plActionCls = pLActionClses.get(parentDto.getId());
            for (PLActionCls plActionCl : plActionCls) {
                PLActionClsDTO childParentDto = new PLActionClsDTO();
                childParentDto.setId(plActionCl.id);
                if(allCls.containsKey(childParentDto.getName())){
                    childParentDto.setName(plActionCl.name);
                }else {
                    childParentDto.setName(plActionCl.name + "【新增完成】");
                    platformClientUtil.getUIService().creaetePLActionCls(plActionCl);
                }
                childParentDto.setPid(plActionCl.pid);
                childParentDto.setDescription(plActionCl.description);
                childParentDto.setCreator(plActionCl.creator);
                childParentDto.setCreateTime(plActionCl.createTime);
                childParentDto.setSerialno(plActionCl.serialno);
                addExportTreeNode(pLActionClses, plActions, childParentDto, allCls, exportBeans);
                parentDto.getChilds().add(childParentDto);
            }
        }
    }
    /**
     * 保存所有父分类
     * @param plActionCls
     * @param pLActionClsList
     */
    private void saveParentCls(String plActionCls, HashSet<PLActionCls> pLActionClsList,
                               HashMap<String/*id*/,PLActionCls> actionClses) {
        if(actionClses.containsKey(plActionCls)){
            PLActionCls pCls = actionClses.get(plActionCls);
            pLActionClsList.add(pCls);
            saveParentCls(pCls.pid, pLActionClsList, actionClses);
        }
    }
    private void addImportData(ExportBeans exportBeans, ArrayList<PLActionCls> pLActionClsList, HashMap<String /* newId */,
            String /* oldId */> actionIdNav,HashMap<String /* newId */, String /* oldId */> actionClsIdNav,
            ArrayList<PLActionCls> optionPLActionClsList, PLActionCls[] pLActionClses, ArrayList<PLAction> plActionList)
            throws PLException {
        HashMap<String, PLAction> pLActionBeans = exportBeans.getPLActions();
        if (pLActionBeans == null) {
            throw new VciBaseException("导入对象未获取成功!!");
        }
        //数据库中没有存在的数据对象,需要进行保存
//        ArrayList<PLAction> plActionList = new ArrayList<>();
        PLAction[] allPLAction = platformClientUtil.getUIService().getAllPLAction();
        Map<String, PLAction> allPLActionMap = Arrays.stream(allPLAction).collect(Collectors.toMap(e -> e.plOId, e -> e));
        Set<Map.Entry<String, PLAction>> plActions = pLActionBeans.entrySet();
        for (Map.Entry<String, PLAction> entry : plActions) {
            PLAction plAction = entry.getValue();
            PLAction plActionInDB =allPLActionMap.get(plAction.plOId);
            if (plActionInDB != null) {
                if( plActionInDB.plActionCls != ""){
                    plAction.plActionCls = plActionInDB.plActionCls;
                    // plAction.plOId = newId;
                    plAction.plName += "@#修改$%";
                    plActionList.add(plAction);
                    continue;
                }else{
                    plAction.plName += "@#存在在未分类中$%";
                }
            }
            // 将该实例acion存入到plActionList中
            plActionList.add(plAction);
            // 定义list存储当前action到数据库action的路径上的所有PLActionCls对象
            List<PLActionCls> plActionClsList = new ArrayList<PLActionCls>();
            // 获得库中的最近的PLActionCls对象
            String pId = WebUtil.getSnowflakePk();
            String oId = WebUtil.getSnowflakePk();
            PLActionCls pLActionCls = getParentPLActionClsInDBById(plAction,
                    pId, plActionClsList, actionClsIdNav, exportBeans, optionPLActionClsList, pLActionClses);
            changePLActionOID(plAction, oId, pId, actionIdNav);
            if (plActionClsList.size() == 1) {
                // 删除"未分类"分类对象
                PLActionCls plActionCls = plActionClsList.get(plActionClsList
                        .size() - 1);
                if(pLActionCls != null){
                    plAction.plActionCls = pLActionCls.id;
                    if(plActionCls.name.equals("未分类")){
                        plAction.plActionCls = "";
                    }
                    plActionClsList.remove(plActionClsList.size() - 1);
                }else{
                    if(plActionCls.name.equals("未分类")){
                        plActionClsList.remove(plActionClsList.size() - 1);
                    }else{
                        plActionCls.pid = "";
                    }
                }
            }
            if (plActionClsList.size() >= 2) {
                PLActionCls plActionCls2 = plActionClsList.get(plActionClsList
                        .size() - 2);
                PLActionCls plActionCls1 = plActionClsList.get(plActionClsList
                        .size() - 1);
                if (pLActionCls != null) {
                    // 将导入对象与“库中的最近的PLActionCls对 象”name相同的对象
                    // 的下一个PLActionCls对象父id改为库中“最近”PLActionCls对象id
                    plActionClsList.remove(plActionClsList.size() - 1);
                    plActionCls2.pid = pLActionCls.id;
                }else{
                    if(plActionCls1.name.equals("未分类")){
                        plActionClsList.remove(plActionClsList.size() - 1);
                        plActionCls2.pid = "";
                    }else{
                        plActionCls1.pid = "";
                    }
                }
            }
            // 增加到整体list中用来最终持久化
            pLActionClsList.addAll(plActionClsList);
        }
    }
    private void changePLActionOID(PLAction plAction, String oId, String pId, HashMap<String /* newId */, String /* oldId */> actionIdNav) {
        actionIdNav.put(oId, plAction.plOId);
        plAction.plOId = oId;
        plAction.plActionCls = pId;
    }
    /***
     * 获得库中的PLActionCls对象,用来嫁接导入来的树
     *
     * @param
     * @param plActionClsList
     * @return
     */
    private PLActionCls getParentPLActionClsInDBById(Object plActionClsIdObj,
                                                     String newPLActionClsId, List<PLActionCls> plActionClsList,
                                                     HashMap<String /* newId */, String /* oldId */> actionClsIdNav,ExportBeans exportBeans,
                                                     ArrayList<PLActionCls> optionPLActionClsList, PLActionCls[] pLActionClses) {
        String pId = null;
        if (plActionClsIdObj instanceof PLAction) {
            pId = ((PLAction) plActionClsIdObj).plActionCls;
            if(pId.equals("")){
                PLActionCls noneCls = new PLActionCls("", "未分类", "", "", "", 0, (short)0);
                plActionClsList.add(noneCls);
                return noneCls;
            }
        }
        if (plActionClsIdObj instanceof PLActionCls) {
            pId = ((PLActionCls) plActionClsIdObj).pid;
            pId = actionClsIdNav.get(pId);
            if(pId.equals("")){
                pId = "null";
            }
        }
        PLActionCls plActionCls = exportBeans.getPLActionClsBeanById(pId);// 从导入对象中获得父分类
        PLActionCls tempPLActionCls = null;
        if (plActionCls != null) {// plActionCls为空 证明父节点为根节点
            plActionClsList.add(plActionCls);
            if(optionPLActionClsList.contains(plActionCls)){
                return plActionCls ;
            }
            for (PLActionCls Cls : pLActionClses) {
                if ((plActionCls.id.equals("") && plActionCls.name.trim()
                        .equals("未分类"))
                        || plActionCls.name.trim().equals(Cls.name.trim())) {
                    tempPLActionCls = Cls;
                }
            }
            plActionCls.id = newPLActionClsId; // 修改父分类id
        } else {
            return null;
        }
        if (tempPLActionCls == null) {
            String newClsId = WebUtil.getSnowflakePk();
            actionClsIdNav.put(newClsId, plActionCls.pid);
            plActionCls.pid = newClsId;
            return getParentPLActionClsInDBById(plActionCls, newClsId,
                    plActionClsList, actionClsIdNav, exportBeans, optionPLActionClsList, pLActionClses);
        }
        return tempPLActionCls;
    }
    /**
     * 处理导出的对象
     * @param actionOid 界面选择的action列表数据