Browse Source

REPORT-55243:cptx的保存和另存为编译合并到Jtemplate中

research/11.0
fly.li 3 years ago
parent
commit
3f0af2a666
  1. 24
      designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java
  2. 69
      designer-base/src/main/java/com/fr/nx/app/designer/utils/CptCompileUtil.java

24
designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java

@ -1465,21 +1465,27 @@ public abstract class JTemplate<T extends BaseBook, U extends BaseUndoState<?>>
public abstract String route(); public abstract String route();
public String getTemplateName() { public String getTemplateName() {
boolean isNewEngine = CptCompileUtil.isNewEngine(this.getTarget());
if (isNewEngine) {
return getEditingFILE().getName() + getSuffix(); return getEditingFILE().getName() + getSuffix();
}else {
return getEditingFILE().getName();
}
} }
public boolean isNewEngineMode(){
return CptCompileUtil.isNewEngine(this.getTarget(),getEditingFILE().getPath()) || getEditingFILE().getPath().endsWith(".cptx");
}
private String getSuffix() { 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()) { if (metadata != null && metadata.isForceCpt()) {
//返回分页引擎未生效 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 InterProviderFactory.getProvider().getLocText("Fine-Plugin_Engine_Paging_Engine_Not_Work");
} }
}
return StringUtils.EMPTY; return StringUtils.EMPTY;
} }
@ -1681,9 +1687,9 @@ public abstract class JTemplate<T extends BaseBook, U extends BaseUndoState<?>>
} }
if (!result) { if (!result) {
//在这里改变报表引擎属性 //在这里改变报表引擎属性
boolean ischanged = CptCompileUtil.changeFrEngineAttr(oldName, this); boolean ischanged = CptCompileUtil.haveChanged(oldName, this);
if (ischanged){ if (ischanged){
//如果改变了属性,则需要重新预编译,因此设置jTemplate的保存状态为false //如果cptx另存为cpt/cptx的另存为/cpt另存为,则需要重新预编译,因此设置jTemplate的保存状态为false
this.saved = false; this.saved = false;
} }
result = this.saveRealFile(); result = this.saveRealFile();

69
designer-base/src/main/java/com/fr/nx/app/designer/utils/CptCompileUtil.java

@ -1,5 +1,6 @@
package com.fr.nx.app.designer.utils; package com.fr.nx.app.designer.utils;
import com.fr.base.extension.FileExtension;
import com.fr.design.mainframe.JTemplate; import com.fr.design.mainframe.JTemplate;
import com.fr.file.FILE; import com.fr.file.FILE;
import com.fr.file.FileNodeFILE; import com.fr.file.FileNodeFILE;
@ -39,8 +40,12 @@ public class CptCompileUtil {
FILE file = jtemplate.getEditingFILE(); FILE file = jtemplate.getEditingFILE();
String path = file.getPath(); String path = file.getPath();
WorkBook workbook = (WorkBook) jtemplate.getTarget(); 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; return;
} }
TransformResultInfo resultInfo = compile0(workbook, file); 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)) { if (!(file instanceof FileNodeFILE)) {
try { try {
OutputStream outputStream = file.asOutputStream(); 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(); FILE editingFILE = jTemplate.getEditingFILE();
String path = editingFILE.getPath(); String path = editingFILE.getPath();
//只有在旧文件是cptx文件并且新文件是cpt文件时才会改变报表引擎属性 //只有在旧文件是cptx文件并且新文件是cpt文件时才会改变报表引擎属性
boolean isChange = oldName.endsWith(".cptx") && path.endsWith(".cpt"); boolean isChange = oldName.endsWith(".cptx") && path.endsWith(".cpt");
if (isChange){ if (isChange && !changeFrEngineAttr(jTemplate)){
WorkBook target = (WorkBook)jTemplate.getTarget(); isChange = false;
WorkSheet workSheet = (WorkSheet)target.getReport(0); }
//合并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(); LayerReportAttr layerReportAttr = workSheet.getLayerReportAttr();
if (layerReportAttr == null){ if (layerReportAttr == null){
layerReportAttr = new LayerReportAttr(); layerReportAttr = new LayerReportAttr();
@ -153,26 +172,36 @@ public class CptCompileUtil {
} }
layerReportAttr.setClientPaging(true); layerReportAttr.setClientPaging(true);
layerReportAttr.setNewEngine(true); layerReportAttr.setNewEngine(true);
return true;
} }
return isChange;
} }
public static boolean isNewEngine(Object workBook){
if (workBook == null || !(workBook instanceof TemplateWorkBook)){ public static boolean isNewEngine(Object workBook, String fileName){
return false; WorkSheet workSheet = gainWorkSheet(workBook);
LayerReportAttr layerReportAttr = gainLayerReportAttr(workSheet);
return isNewEngine(layerReportAttr, fileName);
} }
Report report = ((TemplateWorkBook) workBook).getReport(0);
if (report instanceof WorkSheet){ private static LayerReportAttr gainLayerReportAttr(WorkSheet workSheet){
WorkSheet workSheet = (WorkSheet) report; if (workSheet != null){
LayerReportAttr layerReportAttr = workSheet.getLayerReportAttr(); LayerReportAttr layerReportAttr = workSheet.getLayerReportAttr();
if (layerReportAttr!= null && layerReportAttr.isClientPaging() && layerReportAttr.isNewEngine()){ return layerReportAttr;
return true; } else {
}else{ return null;
return false;
} }
}else {
return false;
} }
private static WorkSheet gainWorkSheet(Object workBook){
if (workBook == null || !(workBook instanceof TemplateWorkBook)){
return null;
}
Report report = ((TemplateWorkBook) workBook).getReport(0);
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){ private static void unSupportLog(TransformResultInfo transformResultInfo){

Loading…
Cancel
Save