From 1615c6851b507867f9090f8cafcb1a32d1dad6bc Mon Sep 17 00:00:00 2001
From: xiejun <xiejun@vci-tech.com>
Date: 星期五, 06 九月 2024 12:09:57 +0800
Subject: [PATCH] 表单表格功能添加

---
 Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsPortalVIServiceImpl.java |  475 ++++++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 402 insertions(+), 73 deletions(-)

diff --git a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsPortalVIServiceImpl.java b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsPortalVIServiceImpl.java
index 486c5bc..36e1356 100644
--- a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsPortalVIServiceImpl.java
+++ b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsPortalVIServiceImpl.java
@@ -1,26 +1,42 @@
 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.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.web.enumpck.VciFieldTypeEnum;
+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.starter.word.bo.WordMergeStartTableDataBO;
+import com.vci.starter.word.util.WordUtil;
 import com.vci.web.enumpck.ItemTypeEnum;
 import com.vci.web.enumpck.PortalVIType;
 import com.vci.web.enumpck.PortalVITypeFlag;
+import com.vci.web.other.BtmQTExportData;
+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;
@@ -28,9 +44,11 @@
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
+import org.springframework.web.multipart.MultipartFile;
 
+import java.io.*;
 import java.util.*;
-import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
 import java.util.function.Function;
 import java.util.stream.Collectors;
 
@@ -51,13 +69,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() {
 
@@ -105,7 +132,7 @@
                 dataGrid.setData(portalVIVOS);
                 dataGrid.setTotal(pagePortalVIArrayByPageInfoResult.total);
             }else{
-                dataGrid = new DataGrid<>("娌掓湁鏌ヨ鍒版暟鎹�");
+                dataGrid = new DataGrid<>();
             }
         } catch (PLException e) {
             e.printStackTrace();
@@ -134,13 +161,16 @@
      */
     @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);
+        if(portalVI==null||StringUtils.isBlank(portalVI.id)){
+            throw new VciBaseException("鏍规嵁涓婚敭鏈煡璇㈠埌鏁版嵁");
+        }
         portalVIVO=portalVIDOO2VO(portalVI);
         return portalVIVO;
     }
@@ -159,7 +189,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()) {
@@ -235,6 +266,7 @@
                 short typeFlag = clonedestObject.getTypeFlag();
                 if (viName != null) {
                     VciBaseUtil.alertNotNull(viName, "鍏嬮殕鍚嶇О涓嶅厑璁镐负绌�");
+                    //throw new PLException("1001",new String[]{"璇烽�夋嫨瑕佸垹闄ょ殑瀵硅薄锛亇"});
                     if(  PortalVIMap.containsKey(viName)){
                         throw  new VciBaseException("鍏嬮殕鍚嶇О"+viName+"宸插瓨鍦紝璇锋牳瀵癸紒");
                     }
@@ -260,77 +292,336 @@
 
     @Override
     public String exportToExcel(Collection<String> idList) {
-        /*List<PortalVIVO>  portalVIVOList= listByIds(idList);
+        String defaultTempFolder = LocalFileUtil.getDefaultTempFolder();
+        String xfileName="export.xls";
         List<WriteExcelData> rowDataList = new ArrayList<>();
-        final int[] index = {0};
-        if(!CollectionUtils.isEmpty(portalVIVOList)) {
-            portalVIVOList.stream().forEach(PortalVIVO -> {
-                //鍏堟槸鍚嶇О
-                int rowIndex = index[0];
-                WriteExcelData idED = new WriteExcelData(rowIndex, 0, btmId);
-                idED.setMerged(true);
-                if (attributeVOS.size() > 0) {
-                    idED.setRowTo(rowIndex + attributeVOS.size() - 1 + 3);
-                }
-                rowDataList.add(idED);
+        List<WriteExcelData> qtRowDataList = new ArrayList<>();
+        //VciBaseUtil.alertNotNull(idList);
+        List<PortalVIDTO>  portalVIDTOList= listByIds(idList);
+        final int index=0;
 
-                WriteExcelData nameED = new WriteExcelData(rowIndex, 1, btmTypeVO.getName());
-                nameED.setMerged(true);
-                if (attributeVOS.size() > 0) {
-                    nameED.setRowTo(rowIndex + attributeVOS.size() - 1 + 3);
-                }
-                rowDataList.add(nameED);
+        String excelFileName = defaultTempFolder + File.separator + xfileName;
+        File excelFile = new File(excelFileName);
+        try {
+            excelFile.createNewFile();
+        }catch (Throwable e){
+            String msg = "鍦ㄥ垱寤篹xcel鏂囦欢鐨勬椂鍊欏嚭鐜颁簡閿欒";
+            if(logger.isErrorEnabled()){
+                logger.error(msg,e);
+            }
+            throw new VciBaseException(msg+",{0}",new String[]{excelFileName},e);
+        }
 
-                rowDataList.add(new WriteExcelData(rowIndex, 2, "id"));
-                rowDataList.add(new WriteExcelData(rowIndex, 3, "缂栧彿"));
-                rowDataList.add(new WriteExcelData(rowIndex, 4, "瀛楃涓�"));
-                rowDataList.add(new WriteExcelData(rowIndex, 5, "鏄�"));
-                rowDataList.add(new WriteExcelData(rowIndex, 6, "50"));
-                rowIndex++;
-                rowDataList.add(new WriteExcelData(rowIndex, 2, "name"));
-                rowDataList.add(new WriteExcelData(rowIndex, 3, "鍚嶇О"));
-                rowDataList.add(new WriteExcelData(rowIndex, 4, "瀛楃涓�"));
-                rowDataList.add(new WriteExcelData(rowIndex, 5, "鏄�"));
-                rowDataList.add(new WriteExcelData(rowIndex, 6, "50"));
-                rowIndex++;
-                rowDataList.add(new WriteExcelData(rowIndex, 2, "description"));
-                rowDataList.add(new WriteExcelData(rowIndex, 3, "鎻忚堪"));
-                rowDataList.add(new WriteExcelData(rowIndex, 4, "瀛楃涓�"));
-                rowDataList.add(new WriteExcelData(rowIndex, 5, "鏄�"));
-                rowDataList.add(new WriteExcelData(rowIndex, 6, "150"));
-                //澶勭悊灞炴��
-                rowIndex++;
-                for (int i = 0; i < attributeVOS.size(); i++) {
-                    OsBtmTypeAttributeVO attributeVO = attributeVOS.get(i);
-                    //鍏堟槸灞炴�х殑鑻辨枃鍚嶇О
-                    rowDataList.add(new WriteExcelData(rowIndex, 2, attributeVO.getId()));
-                    //鐒跺悗灞炴�х殑涓枃鍚嶇О
-                    rowDataList.add(new WriteExcelData(rowIndex, 3, attributeVO.getName()));
-                    //灞炴�х殑绫诲瀷
-                    rowDataList.add(new WriteExcelData(rowIndex, 4, VciFieldTypeEnum.getTextByValue(attributeVO.getAttributeDataType())));
-                    //鏄惁鍙互涓虹┖
-                    rowDataList.add(new WriteExcelData(rowIndex, 5, attributeVO.isNullableFlag() ? "鏄�" : "鍚�"));
-                    //灞炴�ч暱搴�
-                    String length = attributeVO.getAttributeLength()==null?"":attributeVO.getAttributeLength() + "" ;
-                    if (attributeVO.getPrecisionLength() != null) {
-                        length = length + "(" + attributeVO.getPrecisionLength() + "," + attributeVO.getScaleLength() == null ? "2" : (attributeVO.getScaleLength() + "") + ")" ;
+
+        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]++;
+                        });
+
                     }
-                    rowDataList.add(new WriteExcelData(rowIndex, 6, length));
-                    //澶囨敞
-                    rowDataList.add(new WriteExcelData(rowIndex, 7, attributeVO.getDescription() == null ? "" : attributeVO.getDescription()));
-                    rowIndex++;
+                }
+            } 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()) {//濡傛灉瀵煎叆鐨則able锛屽垯闇�瑕佹牎楠岃〃鏍煎叧鑱旂殑琛ㄥ崟鏄惁瀛樺湪锛屽鏋滀笉瀛樺湪鍒欏湪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();
                 }
 
-                index[0] = rowIndex;
+                rowIndex[0]++;
             });
         }
-*/
 
-        return null;
+
+       /* 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);
+        //鏈�鍚庤繑鍥瀍xcel鏂囦欢鍚嶇О
+        return zip.getAbsoluteFile().getAbsolutePath();
     }
 
-    public List<PortalVIVO> listByIds(Collection idList){
-        List<PortalVIVO> portalVIVOList=new ArrayList<>();
+    @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);
+                //浠巈xecl鑾峰彇鏌ヨ妯℃澘瀹氫箟.
+               /* 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()) {//濡傛灉瀵煎叆鐨則able锛屽垯闇�瑕佹牎楠岃〃鏍煎叧鑱旂殑琛ㄥ崟鏄惁瀛樺湪锛屽鏋滀笉瀛樺湪鍒欏湪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();
+    }
+    /**
+     * 鎷疯礉鏁版嵁鍒皐ord妯℃澘涓�
+     * @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("璇烽�夋嫨闇�瑕佸鍑虹殑鏁版嵁");
         }
@@ -343,7 +634,7 @@
                 e.printStackTrace();
             }
         });
-        portalVIVOList=  portalVIDOO2VOS(portalVIList);
+        portalVIVOList=  portalVIO2DTOS(portalVIList);
         return portalVIVOList;
     }
     private BaseResult savePortalVIDTO(PortalVIDTO portalVIDTO,boolean isEdit)  {
@@ -352,7 +643,7 @@
         boolean flag = false;
         String labelName=PortalVIType.Form.getName();
         try {
-            VciBaseUtil.alertNotNull(portalVIDTO.getViName(),"鍚嶇О涓嶈兘涓虹┖锛�");
+            VciBaseUtil.alertNotNull(portalVIDTO.getViName(),"鍚嶇О");
             if(portalVIDTO.getPrm()==null||portalVIDTO.getPrm().getPrmItemList()==null||portalVIDTO.getPrm().getPrmItemList().size()==0){
                 throw  new Throwable(labelName+"锛屾湭璁剧疆");
             }
@@ -697,6 +988,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;
     }
@@ -761,8 +1061,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;
     }
@@ -829,6 +1141,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;
     }
@@ -870,8 +1193,12 @@
         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);//鎼滅储瀛楁
     }
     /**
@@ -915,11 +1242,14 @@
     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>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);
@@ -963,7 +1293,6 @@
     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){

--
Gitblit v1.9.3