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 | 209 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 205 insertions(+), 4 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 b8a46a6..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 @@ -4,6 +4,7 @@ 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; @@ -12,6 +13,9 @@ 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.poi.bo.WriteExcelOption; import com.vci.starter.poi.util.ExcelUtil; @@ -26,6 +30,7 @@ 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; @@ -39,6 +44,7 @@ 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.*; @@ -126,7 +132,7 @@ dataGrid.setData(portalVIVOS); dataGrid.setTotal(pagePortalVIArrayByPageInfoResult.total); }else{ - dataGrid = new DataGrid<>("娌掓湁鏌ヨ鍒版暟鎹�"); + dataGrid = new DataGrid<>(); } } catch (PLException e) { e.printStackTrace(); @@ -162,6 +168,9 @@ } 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; } @@ -352,6 +361,21 @@ 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));//閰嶇疆鏂囨湰 @@ -360,7 +384,7 @@ } String attributeStr=""; try { - List<OsAttributeVO> osAttributeVOList=osAttributeService.getOsAttributeVOSByBtName(portalVIDTO.getTypeName(),portalVIDTO.getTypeFlag()); + 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[]{})); @@ -420,6 +444,152 @@ 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); + //浠巈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 瑕佸啓鍏ョ殑鏁版嵁 @@ -473,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+"锛屾湭璁剧疆"); } @@ -818,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; } @@ -882,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; } @@ -950,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; } @@ -1091,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