| | |
| | | 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.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.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.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; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | 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; |
| | | |
| | |
| | | @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() { |
| | | |
| | |
| | | */ |
| | | @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(); |
| | |
| | | @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()) { |
| | |
| | | short typeFlag = clonedestObject.getTypeFlag(); |
| | | if (viName != null) { |
| | | VciBaseUtil.alertNotNull(viName, "å
éåç§°ä¸å
许为空"); |
| | | //throw new PLException("1001",new String[]{"è¯·éæ©è¦å é¤ç对象ï¼}"}); |
| | | if( PortalVIMap.containsKey(viName)){ |
| | | throw new VciBaseException("å
éåç§°"+viName+"å·²åå¨ï¼è¯·æ ¸å¯¹ï¼"); |
| | | } |
| | |
| | | |
| | | @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 = "å¨å建excelæä»¶çæ¶ååºç°äºé误"; |
| | | 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; |
| | | 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()); |
| | | 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); |
| | | //æåè¿åexcelæä»¶åç§° |
| | | return zip.getAbsoluteFile().getAbsolutePath(); |
| | | } |
| | | |
| | | public List<PortalVIVO> listByIds(Collection idList){ |
| | | List<PortalVIVO> portalVIVOList=new ArrayList<>(); |
| | | /** |
| | | * æ·è´æ°æ®å°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("è¯·éæ©éè¦å¯¼åºçæ°æ®"); |
| | | } |
| | |
| | | e.printStackTrace(); |
| | | } |
| | | }); |
| | | portalVIVOList= portalVIDOO2VOS(portalVIList); |
| | | portalVIVOList= portalVIO2DTOS(portalVIList); |
| | | return portalVIVOList; |
| | | } |
| | | private BaseResult savePortalVIDTO(PortalVIDTO portalVIDTO,boolean isEdit) { |
| | |
| | | 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);//æç´¢å段 |
| | | } |
| | | /** |
| | |
| | | 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); |