ludc
2024-12-05 a485f4494787001a2695863e239910c019a52246
Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsPortalVIServiceImpl.java
@@ -1,24 +1,40 @@
package com.vci.web.service.impl;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ZipUtil;
import com.vci.bo.ItemSeniorQueryBO;
import com.vci.common.utility.ObjectUtility;
import com.vci.constant.FrameWorkLangCodeConstant;
import com.vci.corba.common.PLException;
import com.vci.corba.omd.qtm.QTD;
import com.vci.corba.omd.qtm.QTInfo;
import com.vci.corba.portal.PortalService.GetPagePortalVIArrayByPageInfoResult;
import com.vci.corba.portal.data.PortalVI;
import com.vci.dto.*;
import com.vci.model.*;
import com.vci.enumpck.UI.ItemTypeEnum;
import com.vci.model.PRMDO;
import com.vci.model.PRMItemDO;
import com.vci.pagemodel.*;
import com.vci.po.PortalVIPO;
import com.vci.po.QTDPO;
import com.vci.starter.poi.bo.ReadExcelOption;
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.BaseQueryObject;
import com.vci.starter.web.pagemodel.BaseResult;
import com.vci.starter.web.pagemodel.DataGrid;
import com.vci.starter.web.util.LocalFileUtil;
import com.vci.starter.web.util.VciBaseUtil;
import com.vci.web.enumpck.ItemTypeEnum;
import com.vci.web.enumpck.PortalVIType;
import com.vci.web.enumpck.PortalVITypeFlag;
import com.vci.web.service.OsAttributeServiceI;
import com.vci.web.service.OsPortalVIServiceI;
import com.vci.web.service.OsQuereyTemplateServiceI;
import com.vci.web.util.PlatformClientUtil;
import com.vci.web.util.UITools;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -27,12 +43,16 @@
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Function;
import java.util.stream.Collectors;
/*
  * 链接类型服务
 * 表单/表格服务
 * @author xiej
 * @date 2024-08-14
*/
@@ -48,13 +68,22 @@
    @Autowired(required = false)
    @Lazy
    private OsPortalVIServiceI self;
    /**
     * 加载自身
     */
    @Autowired(required = false)
   private OsAttributeServiceI osAttributeService;
    /**
     * 平台的调用工具类
     */
    @Autowired
    private PlatformClientUtil platformClientUtil;
    /**
     * 查询模板服务
     */
    @Autowired
    private OsQuereyTemplateServiceI quereyTemplateServiceI;
    @Override
    public void clearCache() {
@@ -95,14 +124,14 @@
        }
        DataGrid<PortalVIVO> dataGrid = new DataGrid<>();
        try {
            GetPagePortalVIArrayByPageInfoResult pagePortalVIArrayByPageInfoResult= platformClientUtil.getPortalService().getPagePortalVIArrayByPageInfo(typeName,viName,viType,viTypeFlag,pageIndex,pageSize);
            GetPagePortalVIArrayByPageInfoResult pagePortalVIArrayByPageInfoResult = platformClientUtil.getPortalService().getPagePortalVIArrayByPageInfo(typeName,viName,viType,viTypeFlag,pageIndex,pageSize);
            if(pagePortalVIArrayByPageInfoResult.total>0) {
                PortalVI[] portalVIS = pagePortalVIArrayByPageInfoResult.returnValue;
                List<PortalVIVO> portalVIVOS=  portalVIDOO2VOS(Arrays.asList(portalVIS));
                List<PortalVIVO> portalVIVOS = portalVIDOO2VOS(Arrays.asList(portalVIS));
                dataGrid.setData(portalVIVOS);
                dataGrid.setTotal(pagePortalVIArrayByPageInfoResult.total);
            }else{
                dataGrid = new DataGrid<>("沒有查询到数据");
                dataGrid = new DataGrid<>();
            }
        } catch (PLException e) {
            e.printStackTrace();
@@ -119,7 +148,7 @@
     */
    @Override
    public BaseResult addSave(PortalVIDTO portalVIDTO) throws VciBaseException {
        return  savePortalVIDTO(portalVIDTO,false);
        return savePortalVIDTO(portalVIDTO,false);
    }
    /**
@@ -131,14 +160,17 @@
     */
    @Override
    public PortalVIVO getPortalVIById(String id,String viType) throws PLException {
        VciBaseUtil.alertNotNull(id,"主键为空!");
        VciBaseUtil.alertNotNull(id,"主键");
        String lableName=PortalVIType.Form.getLabel();
        if(PortalVIType.Table.getName()==viType){
            lableName=PortalVIType.Table.getLabel();
        }
        PortalVIVO portalVIVO=new PortalVIVO();
        PortalVI portalVI=  platformClientUtil.getPortalService().getPortalVIById(id);
        portalVIVO=portalVIDOO2VO(portalVI);
        PortalVIVO portalVIVO = null;
        PortalVI portalVI = platformClientUtil.getPortalService().getPortalVIById(id);
        if(portalVI==null||StringUtils.isBlank(portalVI.id)){
            throw new VciBaseException("根据主键未查询到数据");
        }
        portalVIVO = portalVIDOO2VO(portalVI);
        return portalVIVO;
    }
@@ -156,7 +188,8 @@
    @Override
    public boolean delete(DeletePortalVIDTOList portalVIDTOList) throws PLException {
        if(portalVIDTOList==null||CollectionUtils.isEmpty(portalVIDTOList.getPortalVIDTOList())){
            VciBaseUtil.alertNotNull("请选择要删除的对象!");
          //  VciBaseUtil.alertNotNull("删除的对象");
            throw new PLException("1001",new String[]{"请选择要删除的对象!}"});
        }
        try {
            for(PortalVIDTO portalVIDTO:portalVIDTOList.getPortalVIDTOList()) {
@@ -177,7 +210,13 @@
                if (formFlag) {
                    throw new Throwable(viewName + "数据已经被UI组件引用,请重新选择要删除的对象!");
                }
                UITools.getService().deletePortalVIByID(id);
                PortalVI portalVI = new PortalVI();
                portalVI.id = portalVIDTO.getId();
                portalVI.viName = portalVIDTO.getViName();
                portalVI.viType = portalVIDTO.getViType();
                portalVI.typeName = portalVIDTO.getTypeName();
                portalVI.typeFlag = portalVIDTO.getTypeFlag();
                platformClientUtil.getPortalService().deletePortalVI(portalVI);
            }
        }catch (Throwable e){
            String exceptionMessage = "删除表单时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e);
@@ -190,20 +229,26 @@
    @Override
    public boolean delete(String ids) throws PLException {
        VciBaseUtil.alertNotNull(ids,"主键");
         List<String> idsList=  VciBaseUtil.str2List(ids);
        List<PortalVI> PortalVIList= new ArrayList<>();
        DeletePortalVIDTOList portalVIDTOList=new DeletePortalVIDTOList();
        List<String> idsList =  VciBaseUtil.str2List(ids);
        List<PortalVIDTO> portalVIDTOList = new ArrayList<>();
        DeletePortalVIDTOList deletePortalVIDTOList=new DeletePortalVIDTOList();
        idsList.stream().forEach(id->{
            PortalVI portalVI= null;
            try {
                portalVI = platformClientUtil.getPortalService().getPortalVIById(id);
                PortalVIList.add(portalVI);
                PortalVIDTO portalVIDTO = new PortalVIDTO();
                portalVIDTO.setId(portalVI.id);
                portalVIDTO.setTypeFlag(portalVI.typeFlag);
                portalVIDTO.setTypeName(portalVI.typeName);
                portalVIDTO.setViName(portalVI.viName);
                portalVIDTO.setViType(portalVI.viType);
                portalVIDTOList.add(portalVIDTO);
            } catch (PLException e) {
                e.printStackTrace();
            }
        });
        portalVIDTOList.setPortalVIDTOList(portalVIO2DTOS(PortalVIList));
        return delete(portalVIDTOList);
        deletePortalVIDTOList.setPortalVIDTOList(portalVIDTOList);
        return delete(deletePortalVIDTOList);
    }
    /**
@@ -214,17 +259,28 @@
     */
    @Override
    public boolean clone(ClonePortalVIDTOList clonePortalVIDTOList) throws VciBaseException {
        if(clonePortalVIDTOList==null||CollectionUtils.isEmpty(clonePortalVIDTOList.getClonePortalVIDTOList())){
        if(clonePortalVIDTOList == null || CollectionUtils.isEmpty(clonePortalVIDTOList.getClonePortalVIDTOList())){
            throw  new VciBaseException("请选择要克隆的对象!");
        }
        try {
           String typeName=clonePortalVIDTOList.getClonePortalVIDTOList().get(0).getTypeName();
            PortalVI[] portalVIS=  platformClientUtil.getPortalService().getPortalVIArrayByTypeName(typeName);
            Map<String, PortalVIVO> PortalVIMap=new HashMap<>();
            if(!CollectionUtils.isEmpty(Arrays.asList(portalVIS))) {
                List<PortalVIVO> portalVIVOS = portalVIDOO2VOS(Arrays.asList(portalVIS));
                PortalVIMap =portalVIVOS.stream().collect(Collectors.toMap(PortalVIVO::getViName, Function.identity()));
            }
            List<PortalVI> portalVIList=new ArrayList<>();
            for (ClonePortalVIDTO clonedestObject : clonePortalVIDTOList.getClonePortalVIDTOList()) {
                String viName = clonedestObject.getViName();
                PortalVIDTO portalVIDTO = clonedestObject.getOldPortalVIDTO();
                String typeName = clonedestObject.getTypeName();
                short typeFlag = clonedestObject.getTypeFlag();
                if (viName != null) {
                    VciBaseUtil.alertNotNull(viName, "克隆名称不允许为空");
                    //throw new PLException("1001",new String[]{"请选择要删除的对象!}"});
                    if(  PortalVIMap.containsKey(viName)){
                        throw  new VciBaseException("克隆名称"+viName+"已存在,请核对!");
                    }
                    PortalVI portalVI = UITools.getService().getPortalVIById(portalVIDTO.getId());
                    portalVI.id = ObjectUtility.getNewObjectID36();
                    portalVI.viName = viName;
@@ -235,7 +291,8 @@
                    if (typeFlag == PortalVITypeFlag.BtmType.getIntVal() || typeFlag == PortalVITypeFlag.LinkType.getIntVal()) {
                        portalVI.typeFlag = typeFlag;
                    }
                    UITools.getService().savePortalVI(portalVI);
                    platformClientUtil.getPortalService().savePortalVI(portalVI);
                    portalVIList.add(portalVI);
                }
            }
        }catch (PLException e){
@@ -244,43 +301,392 @@
        return true;
    }
    @Override
    public String exportToExcel(Collection<String> idList) {
        String defaultTempFolder = LocalFileUtil.getDefaultTempFolder();
        String xfileName="export.xls";
        List<WriteExcelData> rowDataList = new ArrayList<>();
        List<WriteExcelData> qtRowDataList = new ArrayList<>();
        //VciBaseUtil.alertNotNull(idList);
        List<PortalVIDTO>  portalVIDTOList= listByIds(idList);
        final int index=0;
        String excelFileName = defaultTempFolder + File.separator + xfileName;
        File excelFile = new File(excelFileName);
        try {
            excelFile.createNewFile();
        }catch (Throwable e){
            String msg = "在创建excel文件的时候出现了错误";
            if(logger.isErrorEnabled()){
                logger.error(msg,e);
            }
            throw new VciBaseException(msg+",{0}",new String[]{excelFileName},e);
        }
        rowDataList.add(new WriteExcelData(index, 0, "业务类型名称"));
        rowDataList.add(new WriteExcelData(index, 1, "名称"));
        rowDataList.add(new WriteExcelData(index, 2, "业务类型"));
        rowDataList.add(new WriteExcelData(index, 3, "表单类型"));
        rowDataList.add(new WriteExcelData(index, 4, "配置文本"));
        rowDataList.add(new WriteExcelData(index, 5, "属性"));
        rowDataList.add(new WriteExcelData(index, 6, "查询模板名称"));
        rowDataList.add(new WriteExcelData(index, 7, "查询模板配置文本"));
        rowDataList.add(new WriteExcelData(index, 8, "查询模板业务类型"));
        qtRowDataList.add(new WriteExcelData(index, 0, "业务类型名称"));
        qtRowDataList.add(new WriteExcelData(index, 1, "链接类型名称"));
        qtRowDataList.add(new WriteExcelData(index, 2, "查询模板定义名称"));
        qtRowDataList.add(new WriteExcelData(index, 3, "属性"));
        if(!CollectionUtils.isEmpty(portalVIDTOList)){
            final int[] rowIndex = {1};
            boolean isLink=PortalVITypeFlag.LinkType.getIntVal()== portalVIDTOList.get(0).getTypeFlag()?true:false;
            try {
                BaseResult baseResult=  quereyTemplateServiceI.queryTemplateList( portalVIDTOList.get(0).getTypeName(),isLink);
                if(baseResult.isSuccess()){
                    final int[] rowIndex1 = {1};
                    Collection< QTD> qtdList=  baseResult.getData();
                    if(!CollectionUtils.isEmpty(qtdList)){
                        qtdList.stream().forEach(qtd -> {
                            qtRowDataList.add(new WriteExcelData(rowIndex1[0], 0, qtd.btmName));
                            qtRowDataList.add(new WriteExcelData(rowIndex1[0], 1, qtd.linkTypeName));
                            qtRowDataList.add(new WriteExcelData(rowIndex1[0], 2, qtd.name));
                            qtRowDataList.add(new WriteExcelData(rowIndex1[0], 3, VciBaseUtil.array2String(qtd.abNames)));
                            rowIndex1[0]++;
                        });
                    }
                }
            } catch (PLException e) {
                e.printStackTrace();
            }
            portalVIDTOList.stream().forEach(portalVIDTO -> {
                //先是名称
                rowDataList.add(new WriteExcelData(rowIndex[0], 0, portalVIDTO.getTypeName()));//业务类型名称
                rowDataList.add(new WriteExcelData(rowIndex[0], 1, portalVIDTO.getViName()));//名称
                rowDataList.add(new WriteExcelData(rowIndex[0], 2, PortalVITypeFlag.getByIntVal(portalVIDTO.getTypeFlag()).getLabel()));//业务类型
                rowDataList.add(new WriteExcelData(rowIndex[0], 3,PortalVIType.getByIntVal(portalVIDTO.getViType()).getLabel()));//表单类型
                try {
                    String prmText=UITools.getPRMText(prmDOO2VIS(portalVIDTO.getPrm(),portalVIDTO.getViType()));
                    String prmTextFileName=   ObjectUtility.getNewObjectID36() + ".txt";
                    String prmTextFileNameAllName = xfileName + "." + prmTextFileName;
                    if (portalVIDTO.getViType() == PortalVIType.Table.getIntVal()) {//如果导入的table,则需要校验表格关联的表单是否存在,如果不存在则在execl中是否存在
                        PortalVI[] pvs = platformClientUtil.getPortalService().getPortalVIArrayByTypeName(portalVIDTO.getTypeName());
                        PRMDTO prmdto=   portalVIDTO.getPrm();
                        List<PRMItemDTO> prmItemDTOS=   prmdto.getPrmItemList();
                        if (!CollectionUtils.isEmpty(Arrays.asList(pvs))) {
                            Optional.ofNullable(prmItemDTOS).orElseGet(()->new ArrayList<>()).stream().forEach(prmItemDTO -> {
                                Arrays.stream(pvs).forEach(pv -> {
                                    if (prmItemDTO.getItemInObj().equals(pv.typeName + ":" + pv.viName)) {
                                        prmItemDTO.setItemInObj(pv.id);
                                    }
                                });
                            });
                        }
                    }
                    writeDataToFile(defaultTempFolder,prmTextFileNameAllName,prmText);
                    rowDataList.add(new WriteExcelData(rowIndex[0], 4,prmTextFileName));//配置文本
                } catch (Throwable e) {
                    e.printStackTrace();
                }
                String attributeStr="";
                try {
                    List<OsAttributeVO> osAttributeVOList=osAttributeService.getOsAttributeVOSByBtName(portalVIDTO.getTypeName(),portalVIDTO.getTypeFlag(),false);
                    if(!CollectionUtils.isEmpty(osAttributeVOList)){
                      List<String> filedList= osAttributeVOList.stream().map(OsAttributeVO::getId).collect(Collectors.toList());
                        attributeStr=VciBaseUtil.array2String(filedList.toArray(new String[]{}));
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                rowDataList.add(new WriteExcelData(rowIndex[0], 5, attributeStr));//属性
              String qtName="";
                try {
                    QTInfo qt = platformClientUtil.getQTDService().getQT(portalVIDTO.getPrm().getFormQtName());
                    qtName=qt.qtName;
                    rowDataList.add(new WriteExcelData(rowIndex[0], 6,qtName));//查询模板名称
                    String qtFileName = ObjectUtility.getNewObjectID36() + ".txt";
                    String qtFileNameAllName = xfileName + "." + qtFileName;
                    writeDataToFile(defaultTempFolder,qtFileNameAllName,qt.qtText);
                    rowDataList.add(new WriteExcelData(rowIndex[0], 7, qtFileName));//查询模板配置文本
                    rowDataList.add(new WriteExcelData(rowIndex[0], 8, qt.btmName));//查询模板业务类型
                } catch (PLException e) {
                    e.printStackTrace();
                }
                rowIndex[0]++;
            });
        }
       /* String excelTemplateFileName = "/excelTemplate/dataBaseExport.xls";
        if(this.getClass().getResource(excelTemplateFileName) == null){
            throw new VciBaseException("请联系管理员,系统中缺少{0}这个模板文件",new String[]{excelTemplateFileName});
        }
        try {
            ExcelUtil.copyFileFromJar(excelTemplateFileName,excelFile);
            //这个方法会关闭文件流
        }catch (Throwable e){
            String msg = "从模板文件拷贝到目标文件出现了错误";
            if(logger.isErrorEnabled()){
                logger.error(msg,e);
            }
            throw new VciBaseException(msg+",{0}",new String[]{excelFileName},e);
        }*/
        try{
            WriteExcelOption excelOption = new WriteExcelOption();
            excelOption.addSheetDataList("portalvi",rowDataList);
            excelOption.addSheetDataList("QTD",qtRowDataList);
            ExcelUtil.writeDataToFile(excelFile,excelOption);
        }catch (Throwable e){
            String msg = "把数据写入到excel文件中出现错误";
            if(logger.isErrorEnabled()){
                logger.error(msg,e);
            }
            throw new VciBaseException(msg+",{0}",new String[]{excelFileName},e);
        }
        File zip = ZipUtil.zip(defaultTempFolder);
        FileUtil.del(defaultTempFolder + File.separator);
        //最后返回excel文件名称
        return zip.getAbsoluteFile().getAbsolutePath();
    }
    @Override
    public BaseResult importData(File file)throws Throwable{
        if (file == null) {
            return BaseResult.fail(FrameWorkLangCodeConstant.IMPORT_FAIL, new String[]{"无导入的文件"});
        }
        try {
            File unzip = ZipUtil.unzip(file);
            String filePath=unzip.getAbsolutePath() + File.separator + "export.xls";
            File btmExcel = new File(filePath);
            List<PortalVIPO> portalVIPOList=new ArrayList<>();
            List<QTDPO> QTDPOPOList=new ArrayList<>();
            try {
                ReadExcelOption PortalVIPOReadExcelOption=new ReadExcelOption();
                PortalVIPOReadExcelOption.setSheetName("portalvi");
                PortalVIPOReadExcelOption.setSheetIndex(0);
                portalVIPOList = ExcelUtil.readDataObjectFromExcel(btmExcel, PortalVIPO.class,PortalVIPOReadExcelOption);
                //从execl获取查询模板定义.
               /* ReadExcelOption QTDPOReadExcelOption=new ReadExcelOption();
                QTDPOReadExcelOption.setSheetName("QTD");
                QTDPOReadExcelOption.setSheetIndex(1);
                QTDPOPOList = ExcelUtil.readDataObjectFromExcel(btmExcel, QTDPO.class,QTDPOReadExcelOption);*/
            }catch (VciBaseException e){
                throw  new Throwable("读取execl数据出错:"+e.getMessage());
            }
            List<PortalVI> portalVIList=new ArrayList<>();
            if(!CollectionUtils.isEmpty(portalVIPOList)){
                Map<String,String>formNameMap=new HashMap<>();
                StringBuffer checkInObj=new StringBuffer();
                StringBuffer checkPortalVI=new StringBuffer();
                List<String> sjkExitsList=new ArrayList<>();
                portalVIPOList.stream().forEach(portalVIPO -> {
                    PortalVI portalVI=new PortalVI();
                    String ploid = ObjectUtility.getNewObjectID36();
                    portalVI.id=ploid;
                    portalVI.viName=portalVIPO.getViName();
                    portalVI.typeName=portalVIPO.getTypeName();
                    portalVI.viType=PortalVIType.getByLabel(portalVIPO.getViTypeText()).getIntVal();
                    portalVI.typeFlag=PortalVITypeFlag.getByLabel(portalVIPO.getTypeFlagText()).getIntVal();
                    String fileName= portalVIPO.getPrmFileName();
                    String prmStr = readLines(filePath+"."+fileName);
                    try {
                        PortalVI[] pvs = platformClientUtil.getPortalService().getPortalVIArrayByTypeName(portalVI.typeName);
                        if (portalVI.viType == PortalVIType.Table.getIntVal()) {//如果导入的table,则需要校验表格关联的表单是否存在,如果不存在则在execl中是否存在
                            formNameMap.put(portalVI.typeName + ":" + portalVI.viName, ploid);
                            PRMDO prmObj = UITools.getPRM(prmStr);
                            List<PRMItemDO> prmItemList = prmObj.getPrmItemList();
                            if (!CollectionUtils.isEmpty(prmItemList)) {
                                prmItemList.stream().forEach(prmItemDO -> {
                                    if (!CollectionUtils.isEmpty(Arrays.asList(pvs))) {
                                        Arrays.stream(pvs).forEach(pv -> {
                                            if (prmItemDO.getItemInObj().equals(portalVI.typeName + ":" + pv.viName)) {
                                                prmItemDO.setItemInObj(pv.id);
                                            }
                                        });
                                    } else {
                                        if (formNameMap.containsKey(prmItemDO.getItemInObj())) {
                                            prmItemDO.setItemInObj(formNameMap.get(prmItemDO.getItemInObj()));
                                        } else {
                                            if (!checkInObj.toString().contains(prmItemDO.getItemInObj())) {
                                                String[] split = prmItemDO.getItemInObj().split(":");
                                                checkInObj.append(split[1]).append(",");
                                            }
                                        }
                                    }
                                });
                            }
                            prmStr = UITools.getPRMText(prmObj);
                        }
                        portalVI.prm = prmStr.trim();
                        //校验表单是否存在
                        if (!CollectionUtils.isEmpty(Arrays.asList(pvs))) {
                            Arrays.stream(pvs).forEach(pv -> {
                                if (pv.viName.equals(portalVI.viName)) {
                                    checkPortalVI.append(portalVI.viName).append(",");
                                }
                            });
                        }
                        //校验属性是否正确
                        List<OsAttributeVO> osAttributeVOList = osAttributeService.getOsAttributeVOSByBtName(portalVI.typeName, portalVI.typeFlag,false);
                        if (!CollectionUtils.isEmpty(osAttributeVOList)) {
                            List<String> filedList = osAttributeVOList.stream().map(OsAttributeVO::getId).collect(Collectors.toList());
                            List<String> attributeList = VciBaseUtil.str2List(portalVIPO.getAttributeKey());
                            //数据库不存在
                            List<String> sjkExitsLists = Optional.ofNullable(attributeList).orElseGet(() -> new ArrayList<>()).stream().filter(s -> !attributeList.contains(s)).collect(Collectors.toList());
                            sjkExitsList.addAll(sjkExitsLists);
                        }
                    }catch (Throwable e){
                        e.printStackTrace();
                    }
                    portalVIList.add(portalVI);
                    if(StringUtils.isNotBlank(portalVIPO.getQtName())&&StringUtils.isNotBlank(portalVIPO.getQtNameFile())) {
                        QTInfo qt = new QTInfo();
                        String qtText = readLines(filePath + "." + portalVIPO.getQtNameFile());
                        qt.qtText=qtText;
                        qt.qtName = portalVIPO.getQtName();
                        qt.btmName=portalVIPO.getQtName();
                        QTInfo qt2 = null;
                        try {
                            qt2 = platformClientUtil.getQTDService().getQT(qt.qtName);
                            if (qt2 == null) {
                                platformClientUtil.getQTDService().saveQT(qt);
                            }
                        } catch (PLException e) {
                            e.printStackTrace();
                        }
                    }
                });
                if (checkInObj.length() > 0) {
                    throw  new Throwable( checkInObj.toString() + "表单不存在!");
                }
                if (checkPortalVI.length() > 0) {
                    throw  new Throwable( checkInObj.toString() + "名称已经存在!");
                }
                if(sjkExitsList.size()>0){
                    throw  new Throwable( checkInObj.toString() + "属性在类型中不存在!");
                }
                for (PortalVI pvi : portalVIList) {
                    platformClientUtil.getPortalService().savePortalVI(pvi);
                }
            }
        }catch (Throwable e){
          //  throw new Throwable("导入失败:"+e.getMessage());
           return BaseResult.fail("导入失败:"+e.getMessage());
        }
        return BaseResult.success("导入成功");
    }
    private String readLines(String filePath){
        StringBuffer sb=new StringBuffer();
        FileInputStream prmFile=null;
        try {
            prmFile = new FileInputStream(filePath);
            List<String>  prm= IOUtils.readLines(prmFile,"UTF-8");
            prm.stream().forEach(s -> {
                sb.append(s);
            });
        } catch (IOException e) {
            IOUtils.closeQuietly(prmFile);
            e.printStackTrace();
        }finally {
            IOUtils.closeQuietly(prmFile);
        }
        return sb.toString();
    }
    /**
     * 拷贝数据到word模板中
     * @param fileName 要写入的数据
     * @return word 文件路径
     */
    public String writeDataToFile(String defaultTempFolder,String fileName,String str){
        String tempFolder = LocalFileUtil.getDefaultTempFolder();
        //拷贝文件
        String filePath = tempFolder + File.separator + fileName;
        File file = new File(filePath);
        FileOutputStream out = null;
        try {
            file.createNewFile();
            out=  new FileOutputStream(file);
            IOUtils.write(str,out);
        }catch (Throwable e){
            IOUtils.closeQuietly(out);
            String msg = "在创建文件的时候出现了错误";
            if(logger.isErrorEnabled()){
                logger.error(msg,e);
            }
            throw new VciBaseException(msg+",{0}",new String[]{filePath},e);
        }finally {
            IOUtils.closeQuietly(out);
            //移动属性到链接类型文件夹里面去
            FileUtil.move(file, new File(defaultTempFolder),true);
            FileUtil.del(tempFolder);
        }
        return filePath;
    }
    public List<PortalVIDTO> listByIds(Collection idList){
        List<PortalVIDTO> portalVIVOList=new ArrayList<>();
        if(CollectionUtils.isEmpty(idList)){
            throw  new VciBaseException("请选择需要导出的数据");
        }
        List<PortalVI> portalVIList=new ArrayList<>();
        idList.stream().forEach(id->{
            try {
                PortalVI portalVI=  platformClientUtil.getPortalService().getPortalVIById(id.toString());
                portalVIList.add(portalVI);
            } catch (PLException e) {
                e.printStackTrace();
            }
        });
        portalVIVOList=  portalVIO2DTOS(portalVIList);
        return portalVIVOList;
    }
    private BaseResult savePortalVIDTO(PortalVIDTO portalVIDTO,boolean isEdit)  {
        boolean _isBtm=false;
        boolean flag = false;
        String labelName=PortalVIType.Form.getName();
        try {
            VciBaseUtil.alertNotNull(portalVIDTO.getViName(),"名称不能为空!");
            VciBaseUtil.alertNotNull(
                    portalVIDTO.getViName(),"名称"
                    /*,portalVIDTO.getPrm().getFormQtName(),"绑定表单"*/);
            if(portalVIDTO.getPrm()==null||portalVIDTO.getPrm().getPrmItemList()==null||portalVIDTO.getPrm().getPrmItemList().size()==0){
                throw  new Throwable(labelName+",未设置");
            }
            if(PortalVIType.Table.getIntVal()==portalVIDTO.getViType()){//如果是表格的的校验
                labelName=PortalVIType.Table.getName();
                PRMItemDTO prmItemDTO=  portalVIDTO.getPrm().getPrmItemList().get(0);
                PRMItemDTO prmItemDTO = portalVIDTO.getPrm().getPrmItemList().get(0);
                //每页显示校验
                String rtnContent = isCorrectPageNums(prmItemDTO.getItemPageSize());
                if (StringUtils.isNotBlank(rtnContent)) {
                   throw new VciBaseException(rtnContent);
                }
            }else{
            }
            labelName= PortalVIType.getByIntVal(portalVIDTO.getViType()).getLabel();
            if(!_isBtm){
                PortalVI[] portalVIS=  platformClientUtil.getPortalService().getPortalVIArrayByTypeName(portalVIDTO.getTypeName());
                PortalVI[] portalVIS = platformClientUtil.getPortalService().getPortalVIArrayByTypeName(portalVIDTO.getTypeName());
                for (int i = 0; i < portalVIS.length; i++) {
                    PortalVI portalVI=  portalVIS[i];
                   String viName= portalVI.viName;
                    PortalVI portalVI = portalVIS[i];
                   String viName = portalVI.viName;
                   if(isEdit){//如果为修改
                       try {
                           PortalVI oldPortalVI= platformClientUtil.getPortalService().getPortalVIById(portalVIDTO.getId());
                           flag=platformClientUtil.getPortalService().judgeUpdateButton(oldPortalVI.typeFlag, oldPortalVI.viName, oldPortalVI.typeName);
                           PortalVI oldPortalVI = platformClientUtil.getPortalService().getPortalVIById(portalVIDTO.getId());
                           flag = platformClientUtil.getPortalService().judgeUpdateButton(oldPortalVI.typeFlag, oldPortalVI.viName, oldPortalVI.typeName);
                           if (flag && (StringUtils.isNotBlank(portalVIDTO.getViName()))&&(!oldPortalVI.viName.equals(portalVIDTO.getViName()))) {
                               throw  new Throwable("该"+labelName+"已经被引用,不能修改名称!");
                           }
                       } catch (PLException e) {
                           throw  new Throwable("查询原有表单出现异常:"+e.getMessage());
                           throw new Throwable("查询原有表单出现异常:"+e.getMessage());
                       }
                       if (!portalVI.id.equals(portalVIDTO.getId())) {
                           if (portalVI.viName.equals(portalVIDTO.getViName())) {
@@ -297,7 +703,7 @@
            }else{
                flag=platformClientUtil.getPortalService().judgeUpdateButton(portalVIDTO.getTypeFlag(), portalVIDTO.getViName(), portalVIDTO.getTypeName());
            }
            PortalVI pvi=portalVIDTOO2VI(portalVIDTO);
            PortalVI pvi = portalVIDTOO2VI(portalVIDTO);
            if (!isEdit) {
                flag= platformClientUtil.getPortalService().savePortalVI(pvi);
            } else {
@@ -316,6 +722,7 @@
        }
        return  BaseResult.success("保存"+labelName+"成功!");
    }
    @Override
    public Map<String, PortalVIVO> selectAllPortalVIMap() throws VciBaseException {
        return null;
@@ -367,7 +774,6 @@
        return "";
    }
    /**
     * 枚举的数据对象转换为显示对象
     *
@@ -383,6 +789,7 @@
        });
        return portalVIVOS;
    }
    /**
     * 表单的数据对象转换为显示对象
     * @param portalVIDTOS 表单的对象
@@ -397,6 +804,7 @@
        });
        return portalVIS;
    }
    /**
     * 表单的数据对象转换为显示对象
     * @param PortalVIS 表单的对象
@@ -404,7 +812,7 @@
     */
    @Override
    public List<PortalVIDTO> portalVIO2DTOS(Collection<PortalVI> PortalVIS) {
        List<PortalVIDTO>PortalVIDTOS  = new ArrayList<>();
        List<PortalVIDTO> PortalVIDTOS = new ArrayList<>();
        Optional.ofNullable(PortalVIS).orElseGet(()->new ArrayList<>()).stream().forEach(PortalVI -> {
            PortalVIDTO PPortalVIDTO = portalVIO2DTO(PortalVI);
            PortalVIDTOS.add(PPortalVIDTO);
@@ -412,22 +820,20 @@
        return PortalVIDTOS;
    }
    /**
     * 表单的数据对象转换为显示对象
     * @param portalVIDTO
     * @return
     */
    @Override
    public  PortalVI portalVIDTOO2VI(PortalVIDTO portalVIDTO) {
        PortalVI portalVI=new PortalVI();
        portalVI.id=portalVIDTO.getId();
        portalVI.typeFlag= portalVIDTO.getTypeFlag();
        portalVI.typeName=portalVIDTO.getTypeName();
        portalVI.viName=portalVIDTO.getViName();
        portalVI.viType=portalVIDTO.getViType();
        short viType =portalVIDTO.getViType();
    public PortalVI portalVIDTOO2VI(PortalVIDTO portalVIDTO) {
        PortalVI portalVI = new PortalVI();
        portalVI.id = portalVIDTO.getId();
        portalVI.typeFlag = portalVIDTO.getTypeFlag();
        portalVI.typeName = portalVIDTO.getTypeName();
        portalVI.viName = portalVIDTO.getViName();
        portalVI.viType = portalVIDTO.getViType();
        short viType = portalVIDTO.getViType();
        PRMDO prmdo = prmDOO2VIS(portalVIDTO.getPrm(),viType);
        try {
            portalVI.prm=UITools.getPRMText(prmdo);
@@ -436,6 +842,7 @@
        }
        return portalVI;
    }
    /**
     * 表单的数据对象转换为显示对象
     * @param portalVI
@@ -454,6 +861,7 @@
        portalVIDTO.setPrm(prmDOO2DTOS(prmdo,viType));
        return portalVIDTO;
    }
    /**
     * 表单数据对象转换
     * @param prmdto
@@ -484,13 +892,16 @@
    @Override
    public  PortalVIVO portalVIDOO2VO(PortalVI portalVI) {
        PortalVIVO portalVIVO=new PortalVIVO();
        PortalVIVO portalVIVO = new PortalVIVO();
        portalVIVO.setId(portalVI.id);
        portalVIVO.setTypeFlagText(PortalVITypeFlag.getByIntVal(portalVI.typeFlag).getLabel());
        portalVIVO.setTypeFlag(portalVI.typeFlag);
        portalVIVO.setTypeName(portalVI.typeName);
        portalVIVO.setViName(portalVI.viName);
        portalVIVO.setViType(portalVI.viType);
        String  prm= portalVI.prm;
        portalVIVO.setViTypeText(PortalVIType.getByIntVal(portalVI.viType).getLabel());
        String prm = portalVI.prm;
        if(StringUtils.isNotBlank(prm)) {
            PRMDO prmdo = UITools.getPRM(prm);
            portalVIVO.setPrm(prmDOO2VOS(prmdo, portalVI.viType));
@@ -562,7 +973,7 @@
        prmItemDO.setItemHrefConf(prmItemDO.getItemHrefConf());//超链接配置
        prmItemDO.setItemTips(prmItemDTO.getItemTips());
        prmItemDO.setItemTrim(prmItemDTO.getItemTrim());
        prmItemDO.setItemDateFormat(prmItemDTO.getItemDateFormat());
        //prmItemDO.setItemDateFormat(prmItemDTO.getItemDateFormat());
        prmItemDO.setItemCtrlDisplyCondition(prmItemDTO.getItemCtrlDisplyCondition());////控制显示条件
        prmItemDO.setItemEditableProgram(prmItemDTO.getItemEditableProgram());
        prmItemDO.setItemEditCondition(prmItemDTO.getItemEditCondition());
@@ -593,6 +1004,15 @@
        prmItemDO.setItemHttpPathField(prmItemDTO.getItemHttpPathField());
        if(viType==PortalVIType.Table.getIntVal()) {//如果是表格
            initTableConfigDTOO2DOData(prmItemDO,prmItemDTO);
        }else{
            List<String> itemValueList=new ArrayList<>();
            List<KeyValue> keyValueList=prmItemDTO.getItemKeyValueList();
            Optional.ofNullable(keyValueList).orElseGet(()->new ArrayList<>()).stream().forEach(keyValue -> {
              String value=  keyValue.getValue()+"{"+keyValue.getKey()+"}";
                itemValueList.add(value);
            });
            prmItemDO.setItemValueList(itemValueList);
        }
        return prmItemDO;
    }
@@ -657,8 +1077,20 @@
        prmItemVO.setItemIsHttpSave(prmItemDO.getItemIsHttpSave());
        prmItemVO.setItemHttpVolumnPath(prmItemDO.getItemHttpVolumnPath());
        prmItemVO.setItemHttpPathField(prmItemDO.getItemHttpPathField());
        if(viType==PortalVIType.Table.getIntVal()) {//如果是表格
            initTableConfigDOO2VOData(prmItemVO,prmItemDO);
        }else{
          List<String> enumList=  prmItemDO.getItemValueList();
          List<KeyValue>itemKeyValueList=new ArrayList<>();
            Optional.ofNullable(enumList).orElseGet(()->new ArrayList<>()).stream().forEach(enumValue->{
             List<String> keyValueList=  VciBaseUtil.str2List(VciBaseUtil.removeComma(enumValue,"}"),"\\{");
                KeyValue keyValue=new KeyValue();
                keyValue.setKey(keyValueList.get(1));
                keyValue.setValue(keyValueList.get(0));
                itemKeyValueList.add(keyValue);
            });
            prmItemVO.setItemKeyValueList(itemKeyValueList);
        }
        return prmItemVO;
    }
@@ -725,6 +1157,17 @@
        prmItemDTO.setItemHttpPathField(prmItemDO.getItemHttpPathField());
        if(viType==PortalVIType.Table.getIntVal()) {//如果是表格
            initTableConfigDOO2VOData(prmItemDTO,prmItemDO);
        }else{
            List<String> enumList=  prmItemDO.getItemValueList();
            List<KeyValue>itemKeyValueList=new ArrayList<>();
            Optional.ofNullable(enumList).orElseGet(()->new ArrayList<>()).stream().forEach(enumValue->{
                List<String> keyValueList=  VciBaseUtil.str2List(VciBaseUtil.removeComma(enumValue,"}"),"\\{");
                KeyValue keyValue=new KeyValue();
                keyValue.setKey(keyValueList.get(1));
                keyValue.setValue(keyValueList.get(0));
                itemKeyValueList.add(keyValue);
            });
            prmItemDTO.setItemKeyValueList(itemKeyValueList);
        }
        return prmItemDTO;
    }
@@ -739,10 +1182,18 @@
        List<String> allKeyList= getRefFormVIName(prmItemDO.getItemInObj());
        List<String> itemOutFieldList =VciBaseUtil.str2List(prmItemDO.getItemOutFields());
        List<String> itemKeyFieldList =VciBaseUtil.str2List(prmItemDO.getItemKeyFields());
        List<String> itemSelectoutFieldList= allKeyList.stream().filter(s ->!itemOutFieldList.stream().map(s1 -> s1).collect(Collectors.toList()).contains(s) ).collect(Collectors.toList());
        prmItemVO.setItemSelectoutFieldList(itemSelectoutFieldList);//待选择的属性字段
        List<String> itemSelectOutFieldList= allKeyList.stream()
                .filter(s -> !itemOutFieldList.contains(s))
                .collect(Collectors.toList());
        prmItemVO.setItemSelectOutFieldList(itemSelectOutFieldList);//待选择的属性字段
        prmItemVO.setItemOutFieldList(itemOutFieldList);//需要使用的集合
        List<String> itemSearchFieldList= itemOutFieldList.stream().filter(s ->!itemKeyFieldList.stream().map(s1 -> s1).collect(Collectors.toList()).contains(s) ).collect(Collectors.toList());
        // List<String> itemSearchFieldList= itemOutFieldList.stream().filter(s ->!CollectionUtils.isEmpty(itemKeyFieldList).stream().map(s1 -> s1).collect(Collectors.toList()).contains(s) ).collect(Collectors.toList());
        List<String> itemSearchFieldList=new ArrayList<>();
        if(!CollectionUtils.isEmpty(itemKeyFieldList)){
            itemSearchFieldList= itemOutFieldList.stream().filter(s ->!itemKeyFieldList.contains(s)).collect(Collectors.toList());
        }else{
            itemSearchFieldList=itemOutFieldList;
        }
        prmItemVO.setItemSearchFieldList(itemSearchFieldList);//待搜索字段
        prmItemVO.setItemKeyFieldList(itemKeyFieldList);//搜索字段
    }
@@ -757,11 +1208,15 @@
        List<String> allKeyList= getRefFormVIName(prmItemDO.getItemInObj());
        List<String> itemOutFieldList =VciBaseUtil.str2List(prmItemDO.getItemOutFields());
        List<String> itemKeyFieldList =VciBaseUtil.str2List(prmItemDO.getItemKeyFields());
        List<String> itemSelectoutFieldList= allKeyList.stream().filter(s ->!itemOutFieldList.stream().map(s1 -> s1).collect(Collectors.toList()).contains(s) ).collect(Collectors.toList());
        prmItemDTO.setItemSelectoutFieldList(itemSelectoutFieldList);//待选择的属性字段
        List<String> itemSelectOutFieldList= allKeyList.stream().filter(s ->!itemOutFieldList.stream().map(s1 -> s1).collect(Collectors.toList()).contains(s) ).collect(Collectors.toList());
        prmItemDTO.setItemSelectoutFieldList(itemSelectOutFieldList);//待选择的属性字段
        prmItemDTO.setItemOutFieldList(itemOutFieldList);//需要使用的集合
        List<String> itemSearchFieldList= itemOutFieldList.stream().filter(s ->!itemKeyFieldList.stream().map(s1 -> s1).collect(Collectors.toList()).contains(s) ).collect(Collectors.toList());
        prmItemDTO.setItemSearchFieldList(itemSearchFieldList);//待搜索字段
        List<String> itemSearchFieldList=new ArrayList<>();
        if(!CollectionUtils.isEmpty(itemKeyFieldList)){
            itemSearchFieldList= itemOutFieldList.stream().filter(s ->!itemKeyFieldList.contains(s)).collect(Collectors.toList());
        }else{
            itemSearchFieldList=itemOutFieldList;
        } prmItemDTO.setItemSearchFieldList(itemSearchFieldList);//待搜索字段
        prmItemDTO.setItemKeyFieldList(itemKeyFieldList);//搜索字段
    }
    /**
@@ -770,28 +1225,29 @@
     * @param prmItemDO
     */
    private void initTableConfigDTOO2DOData(PRMItemDO prmItemDO,PRMItemDTO prmItemDTO){
        prmItemDO.setItemOutFields(VciBaseUtil.array2String(prmItemDTO.getItemOutFieldList().toArray(new String[]{})));//需要使用的字段
        prmItemDO.setItemKeyFields(VciBaseUtil.array2String(prmItemDTO.getItemKeyFieldList().toArray(new String[]{})));//需要搜索的字段
       List<String> newItemFieldWidthList=prmItemDTO.getItemFieldWidthList().stream().map(KeyValue::getValue).distinct().collect(Collectors.toList());
       prmItemDO.setItemFieldWidth(VciBaseUtil.array2String(newItemFieldWidthList.toArray(new String[]{}),":"));//字段宽度
       List<ItemSeniorQueryBO> itemSeniorQueryBOS=  prmItemDTO.getItemSeniorQueryBOS();
       List<String> itemSeniorQueryColsList=new ArrayList<>();
       List<String> itemSeniorQueryColsCountsList=new ArrayList<>();
       List<String> itemQuerySqlList=new ArrayList<>();
       itemSeniorQueryBOS.stream().forEach(itemSeniorQueryBO -> {
           String itemSeniorQueryCols= itemSeniorQueryBO.getItemSeniorQueryCols();
           String itemSeniorQueryColsCounts=itemSeniorQueryBO.getItemSeniorQueryColsCounts();
           String itemQuerySql=itemSeniorQueryBO.getItemQuerySql();
        prmItemDO.setItemOutFields(VciBaseUtil.array2String(prmItemDTO.getItemOutFieldList().toArray(new String[]{})));
        //需要使用的字段prmItemDO.setItemKeyFields(CollectionUtils.isEmpty(prmItemDTO.getItemKeyFieldList())?"":VciBaseUtil.array2String(prmItemDTO.getItemKeyFieldList().toArray(new String[]{})));//需要搜索的字段
        // TODO: 2024/12/5 Ludc 这儿去重用的不对,KeyValue::getValue是对宽度去重了
        List<String> newItemFieldWidthList = prmItemDTO.getItemFieldWidthList().stream().distinct().map(KeyValue::getValue).collect(Collectors.toList());
        // TODO: 2024/12/5 Ludc 分隔符要和平台统一用,而不是用:
        prmItemDO.setItemFieldWidth(VciBaseUtil.array2String(newItemFieldWidthList.toArray(new String[]{}),","));//字段宽度
        List<ItemSeniorQueryBO> itemSeniorQueryBOS = prmItemDTO.getItemSeniorQueryBOS();
        List<String> itemSeniorQueryColsList = new ArrayList<>();
        List<String> itemSeniorQueryColsCountsList=new ArrayList<>();
        List<String> itemQuerySqlList = new ArrayList<>();
        itemSeniorQueryBOS.stream().forEach(itemSeniorQueryBO -> {
           String itemSeniorQueryCols = itemSeniorQueryBO.getItemSeniorQueryCols();
           String itemSeniorQueryColsCounts = itemSeniorQueryBO.getItemSeniorQueryColsCounts();
           String itemQuerySql = itemSeniorQueryBO.getItemQuerySql();
           if(StringUtils.isNotBlank(itemSeniorQueryCols)) {
               itemSeniorQueryColsList.add(itemSeniorQueryCols);
           }
            if(StringUtils.isNotBlank(itemSeniorQueryColsCounts)) {
                itemSeniorQueryColsCountsList.add(itemSeniorQueryColsCounts);
            }
            if(StringUtils.isNotBlank(itemQuerySql)){
                itemQuerySqlList.add(itemQuerySql);
            }
           if(StringUtils.isNotBlank(itemSeniorQueryColsCounts)) {
               itemSeniorQueryColsCountsList.add(itemSeniorQueryColsCounts);
           }
           if(StringUtils.isNotBlank(itemQuerySql)){
               itemQuerySqlList.add(itemQuerySql);
           }
        });
        prmItemDO.setItemSeniorQueryCols(VciBaseUtil.array2String(itemSeniorQueryColsList.toArray(new String[]{})));
        prmItemDO.setItemSeniorQueryColsCounts(VciBaseUtil.array2String(itemSeniorQueryColsCountsList.toArray(new String[]{})));
@@ -804,12 +1260,15 @@
     */
    private List<KeyValue>  initItemFieldWidthList(String itemOutFields,String itemFieldWidth){
        List<KeyValue> keyValueList=new ArrayList<>();
        List<String>itemOutFieldList=   VciBaseUtil.str2List(itemOutFields);
        List<String>itemFieldWidthList=  VciBaseUtil.str2List(itemFieldWidth);
        List<String>itemOutFieldList = VciBaseUtil.str2List(itemOutFields);
        List<String>itemFieldWidthList =VciBaseUtil.str2List(itemFieldWidth,",");
        if(itemOutFieldList.size()>0) {
            for (int i = 0; i < itemOutFieldList.size(); i++) {
                KeyValue keyValue = new KeyValue();
                String with = itemFieldWidthList.get(i);
                String with="250";
                if(i<itemFieldWidthList.size()) {
                    with  = itemFieldWidthList.get(i);
               }
                keyValue.setKey(itemOutFieldList.get(i));
                keyValue.setValue(StringUtils.isBlank(with) ? "250" : with);
                keyValueList.add(keyValue);
@@ -850,10 +1309,10 @@
        }
        return itemSeniorQueryBOList;
    }
    private List<String> getRefFormVIName(String refFormOid){
        List<String> keyList=new ArrayList<>();
        try {
            PortalVI refFormVI = UITools.getService().getPortalVIById(refFormOid);
            PortalVIVO portalVIVO= portalVIDOO2VO(refFormVI);
            if(portalVIVO!=null&&portalVIVO.getPrm().getPrmItemList().size()>0){