| | |
| | | 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.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; |
| | |
| | | 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 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.*; |
| | |
| | | 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));//é
ç½®ææ¬ |
| | | |
| | |
| | | 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); |
| | | 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 è¦åå
¥çæ°æ® |