From 3f0af2a666cff2405a0173030feaa58bf51d7dc8 Mon Sep 17 00:00:00 2001 From: "fly.li" Date: Fri, 3 Sep 2021 17:14:49 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-55243=EF=BC=9Acptx=E7=9A=84=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=E5=92=8C=E5=8F=A6=E5=AD=98=E4=B8=BA=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E5=90=88=E5=B9=B6=E5=88=B0Jtemplate=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/design/mainframe/JTemplate.java | 28 +++++--- .../nx/app/designer/utils/CptCompileUtil.java | 71 +++++++++++++------ 2 files changed, 67 insertions(+), 32 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java b/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java index 695130aad..f99bceed9 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java @@ -1465,20 +1465,26 @@ public abstract class JTemplate> public abstract String route(); public String getTemplateName() { - boolean isNewEngine = CptCompileUtil.isNewEngine(this.getTarget()); - if (isNewEngine) { - return getEditingFILE().getName() + getSuffix(); - }else { - return getEditingFILE().getName(); - } + return getEditingFILE().getName() + getSuffix(); } + public boolean isNewEngineMode(){ + return CptCompileUtil.isNewEngine(this.getTarget(),getEditingFILE().getPath()) || getEditingFILE().getPath().endsWith(".cptx"); + } private String getSuffix() { - CptxMetadata metadata = CptxFileUtils.getMetadata(this.getEditingFILE().getPath()); + if (!CptCompileUtil.isNewEngine(this.getTarget(), getEditingFILE().getPath())){ + return StringUtils.EMPTY; + } + String path = this.getEditingFILE().getPath(); + CptxMetadata metadata = CptxFileUtils.getMetadata(path); + //是否是兼容模式,兼容模式下,设置了新引擎的cpt和cptx的后缀不同 if (metadata != null && metadata.isForceCpt()) { - //返回分页引擎未生效 - return InterProviderFactory.getProvider().getLocText("Fine-Plugin_Engine_Paging_Engine_Not_Work"); + if (path.endsWith(".cptx")){ + return InterProviderFactory.getProvider().getLocText("Fine-Plugin_Engine_Compatibility_Mode"); + } else if (path.endsWith(".cpt")){ + return InterProviderFactory.getProvider().getLocText("Fine-Plugin_Engine_Paging_Engine_Not_Work"); + } } return StringUtils.EMPTY; } @@ -1681,9 +1687,9 @@ public abstract class JTemplate> } if (!result) { //在这里改变报表引擎属性 - boolean ischanged = CptCompileUtil.changeFrEngineAttr(oldName, this); + boolean ischanged = CptCompileUtil.haveChanged(oldName, this); if (ischanged){ - //如果改变了属性,则需要重新预编译,因此设置jTemplate的保存状态为false + //如果cptx另存为cpt/cptx的另存为/cpt另存为,则需要重新预编译,因此设置jTemplate的保存状态为false。 this.saved = false; } result = this.saveRealFile(); diff --git a/designer-base/src/main/java/com/fr/nx/app/designer/utils/CptCompileUtil.java b/designer-base/src/main/java/com/fr/nx/app/designer/utils/CptCompileUtil.java index 1d76a71d1..92856148a 100644 --- a/designer-base/src/main/java/com/fr/nx/app/designer/utils/CptCompileUtil.java +++ b/designer-base/src/main/java/com/fr/nx/app/designer/utils/CptCompileUtil.java @@ -1,5 +1,6 @@ package com.fr.nx.app.designer.utils; +import com.fr.base.extension.FileExtension; import com.fr.design.mainframe.JTemplate; import com.fr.file.FILE; import com.fr.file.FileNodeFILE; @@ -39,8 +40,12 @@ public class CptCompileUtil { FILE file = jtemplate.getEditingFILE(); String path = file.getPath(); WorkBook workbook = (WorkBook) jtemplate.getTarget(); - //如果是cpt并且引擎设置正确,执行预编译。cptx文件不执行预编译 - if (!(path.endsWith(".cpt") && isNewEngine(workbook))){ + /* + * 如果是cpt并且引擎设置正确,执行预编译,如果是cptx文件也执行预编译。在JStreamWork中,保存和另存为流程都进行了重新编译。 + * 但是由于之前的DefaultTemplateResource.saveTemplate的原因导致JStreamWork::saveFile()不能执行--cptx的保存不能进行预编译, + * 应该是流程的误改动,这里改回来,保存时仍然执行预编译。 + * */ + if (!isNewEngine(workbook, path)){ return; } TransformResultInfo resultInfo = compile0(workbook, file); @@ -48,7 +53,7 @@ public class CptCompileUtil { } - public static TransformResultInfo compile0(WorkBook workbook, FILE file) { + private static TransformResultInfo compile0(WorkBook workbook, FILE file) { if (!(file instanceof FileNodeFILE)) { try { OutputStream outputStream = file.asOutputStream(); @@ -138,14 +143,28 @@ public class CptCompileUtil { /* * 该另存为流程会改变文件内容,现在作为兼容的流程,以后可以随时删除该流程 * */ - public static boolean changeFrEngineAttr(String oldName, JTemplate jTemplate){ + public static boolean haveChanged(String oldName, JTemplate jTemplate){ FILE editingFILE = jTemplate.getEditingFILE(); String path = editingFILE.getPath(); //只有在旧文件是cptx文件并且新文件是cpt文件时才会改变报表引擎属性 boolean isChange = oldName.endsWith(".cptx") && path.endsWith(".cpt"); - if (isChange){ - WorkBook target = (WorkBook)jTemplate.getTarget(); - WorkSheet workSheet = (WorkSheet)target.getReport(0); + if (isChange && !changeFrEngineAttr(jTemplate)){ + isChange = false; + } + //合并JStreamWork中另存为流程,cptx的另存为也需要重新预编译 + return (isChange || isSaveAs(jTemplate, oldName, path)); + } + + //cptx和设置了新引擎的cpt的另存也需要进行预编译 + private static boolean isSaveAs(JTemplate jTemplate, String oldName, String newName){ + return isNewEngine(jTemplate.getTarget(), newName) && ((FileExtension.CPTX.matchExtension(oldName) && FileExtension.CPTX.matchExtension(newName)) || (FileExtension.CPT.matchExtension(oldName) && FileExtension.CPT.matchExtension(newName))); + } + + private static boolean changeFrEngineAttr(JTemplate jTemplate){ + WorkSheet workSheet = gainWorkSheet(jTemplate); + if (workSheet == null){ + return false; + }else { LayerReportAttr layerReportAttr = workSheet.getLayerReportAttr(); if (layerReportAttr == null){ layerReportAttr = new LayerReportAttr(); @@ -153,26 +172,36 @@ public class CptCompileUtil { } layerReportAttr.setClientPaging(true); layerReportAttr.setNewEngine(true); + return true; + } + } + + + public static boolean isNewEngine(Object workBook, String fileName){ + WorkSheet workSheet = gainWorkSheet(workBook); + LayerReportAttr layerReportAttr = gainLayerReportAttr(workSheet); + return isNewEngine(layerReportAttr, fileName); + } + + private static LayerReportAttr gainLayerReportAttr(WorkSheet workSheet){ + if (workSheet != null){ + LayerReportAttr layerReportAttr = workSheet.getLayerReportAttr(); + return layerReportAttr; + } else { + return null; } - return isChange; } - public static boolean isNewEngine(Object workBook){ + private static WorkSheet gainWorkSheet(Object workBook){ if (workBook == null || !(workBook instanceof TemplateWorkBook)){ - return false; + return null; } Report report = ((TemplateWorkBook) workBook).getReport(0); - if (report instanceof WorkSheet){ - WorkSheet workSheet = (WorkSheet) report; - LayerReportAttr layerReportAttr = workSheet.getLayerReportAttr(); - if (layerReportAttr!= null && layerReportAttr.isClientPaging() && layerReportAttr.isNewEngine()){ - return true; - }else{ - return false; - } - }else { - return false; - } + return report instanceof WorkSheet ? (WorkSheet)report : null; + } + + private static boolean isNewEngine(LayerReportAttr layerReportAttr, String fileName){ + return (layerReportAttr!= null && layerReportAttr.isClientPaging() && layerReportAttr.isNewEngine()) || FileExtension.CPTX.matchExtension(fileName); } private static void unSupportLog(TransformResultInfo transformResultInfo){