forked from fanruan/design
Browse Source
Merge in DESIGN/design from ~FLY.LI/design:feature/x to feature/x * commit 'e9eadf142317089a140821851b3d2e37c9d29b9a': REPORT-55243:可能存在的强转错误及方法名修改 REPORT-55243:修改整型数字为常量,修改对cpt和cptx文件后缀的判断方式 REPORT-55243:修改不合理的方法名 & 改变报表引擎属性界面对应的类名 REPORT-55243:联动修改因为报表引擎属性中标识引擎的数据类型的改变所需要修改的代码,将其中关于cpt和cptx兼容的流程部分放入一个工具类中(放在CptCompileUtil中不合适)research/11.0
Fly.Li
3 years ago
6 changed files with 112 additions and 92 deletions
@ -0,0 +1,88 @@
|
||||
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.main.TemplateWorkBook; |
||||
import com.fr.report.report.Report; |
||||
import com.fr.report.stable.LayerReportAttr; |
||||
import com.fr.report.worksheet.WorkSheet; |
||||
|
||||
/** |
||||
* @author fly.li |
||||
* @version 10.0 |
||||
* Created on 2021/09/12 |
||||
*/ |
||||
public class CptAndCptxCompatibilityUtil { |
||||
|
||||
/** |
||||
* 判断是否需要重新编译 |
||||
**/ |
||||
public static boolean needRecompile(String oldName, JTemplate jTemplate){ |
||||
FILE editingFILE = jTemplate.getEditingFILE(); |
||||
String path = editingFILE.getPath(); |
||||
//只有在旧文件是cptx文件并且新文件是cpt文件时才会改变报表引擎属性
|
||||
boolean isCptxConvertToCpt = FileExtension.CPTX.matchExtension(oldName) && FileExtension.CPT.matchExtension(path); |
||||
if (isCptxConvertToCpt && !setFrEngineAttr(jTemplate)){ |
||||
isCptxConvertToCpt = false; |
||||
} |
||||
return (isCptxConvertToCpt || isSaveAs(jTemplate, oldName, path)); |
||||
} |
||||
|
||||
/** |
||||
* 判断是不是cptx模板或者开启了的新引擎的cpt模板的另存为操作 |
||||
**/ |
||||
private static boolean isSaveAs(JTemplate jTemplate, String oldName, String newName){ |
||||
return isEngineXEnable(jTemplate.getTarget(), newName) && ((FileExtension.CPTX.matchExtension(oldName) && FileExtension.CPTX.matchExtension(newName)) || (FileExtension.CPT.matchExtension(oldName) && FileExtension.CPT.matchExtension(newName))); |
||||
} |
||||
|
||||
/** |
||||
* cptx另存为cpt需要修改报表引擎属性 |
||||
**/ |
||||
private static boolean setFrEngineAttr(JTemplate jTemplate){ |
||||
WorkSheet workSheet = gainWorkSheet(jTemplate.getTarget()); |
||||
if (workSheet == null){ |
||||
return false; |
||||
}else { |
||||
LayerReportAttr layerReportAttr = workSheet.getLayerReportAttr(); |
||||
if (layerReportAttr == null){ |
||||
layerReportAttr = new LayerReportAttr(); |
||||
workSheet.setLayerReportAttr(layerReportAttr); |
||||
} |
||||
layerReportAttr.setClientPaging(true); |
||||
layerReportAttr.setEngineState(0); |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 是否启用了新引擎的判断 |
||||
* cptx自动走新引擎(非兼容模式),cpt需要进行设置 |
||||
* */ |
||||
public static boolean isEngineXEnable(Object workBook, String fileName){ |
||||
WorkSheet workSheet = gainWorkSheet(workBook); |
||||
LayerReportAttr layerReportAttr = gainLayerReportAttr(workSheet); |
||||
return isEngineXEnable(layerReportAttr, fileName); |
||||
} |
||||
|
||||
private static LayerReportAttr gainLayerReportAttr(WorkSheet workSheet){ |
||||
if (workSheet != null){ |
||||
LayerReportAttr layerReportAttr = workSheet.getLayerReportAttr(); |
||||
return layerReportAttr; |
||||
} else { |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
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 isEngineXEnable(LayerReportAttr layerReportAttr, String fileName){ |
||||
return (layerReportAttr!= null && layerReportAttr.isClientPaging() && layerReportAttr.getEngineState() == LayerReportAttr.ENGINE_X) || FileExtension.CPTX.matchExtension(fileName); |
||||
} |
||||
} |
Loading…
Reference in new issue