Browse Source
Merge in DESIGN/design from ~FLY.LI/design:feature/x to feature/x * commit '846fbfe832223f95762d93736935c85d6eef2323': 取消对JStreamWork的修改 REPORT-55243:完善注释 修改方法名 REPORT-55243:删除不必要的代码 REPORT-55243:cptx的保存和另存为编译合并到Jtemplate中 REPORT-55243:将JStreamWork合并到JWorkBook及JTemplate的流程中 设置之后需要刷新一下面板,决定是否显示计算属性入口 REPORT-55243:删除错误注释,修改不合理代码 REPORT-55243:删除getPath的重写 & 兼容cptx的打开流程 REPORT-55243:如果修改了报表引擎属性,则返回布尔值,以判断是否需要重新预编译 REPORT-55243:改变报表引擎属性后,需要改变一下JTemplate的保存状态 将旧的面板换成新的面板 REPORT-55243:将JStreamBook换成JWorkBook REPORT-55243:将预编译流程,改变报表引擎属性功能,判断是否开启了新引擎的功能都统一到了这个工具类中 REPORT-55243:重新设计报表引擎面板 将JStreamWork类中相关方法合并到JWorkBook中,这些方法根据报表引擎属性的设置进行了不同的处理 REPORT-55243:将JStreamWork中的相关方法合并到该类里面 & 将预编译流程合并到cpt保存流程中 & cptx的另存为cpt文件的流程处理research/11.0
Fly.Li
3 years ago
8 changed files with 507 additions and 26 deletions
@ -0,0 +1,216 @@
|
||||
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; |
||||
import com.fr.general.ComparatorUtils; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.main.TemplateWorkBook; |
||||
import com.fr.main.impl.WorkBook; |
||||
import com.fr.nx.app.designer.cptx.io.DesignReadWritableProvider; |
||||
import com.fr.nx.app.designer.monitor.DesignerMetricRecorder; |
||||
import com.fr.nx.app.designer.toolbar.TransformResult; |
||||
import com.fr.nx.app.designer.toolbar.TransformResultInfo; |
||||
import com.fr.nx.compile.CompileStatus; |
||||
import com.fr.nx.compile.ReportCompiler; |
||||
import com.fr.nx.compile.adapter.LegacyWorkBookAdapter; |
||||
import com.fr.nx.compile.util.ReportCompileUtils; |
||||
import com.fr.nx.cptx.CptxIOManager; |
||||
import com.fr.nx.cptx.cache.CptxTemplatePool; |
||||
import com.fr.nx.cptx.entry.CptxTemplate; |
||||
import com.fr.nx.cptx.io.handle.CptxTemplateHandle; |
||||
import com.fr.nx.cptx.monitor.CompileMonitorHandler; |
||||
import com.fr.nx.cptx.utils.CptxFileUtils; |
||||
import com.fr.nx.data.layer.LayerItem; |
||||
import com.fr.nx.data.layer.LayerProps; |
||||
import com.fr.nx.template.compile.CompiledReport; |
||||
import com.fr.report.report.Report; |
||||
import com.fr.report.stable.LayerReportAttr; |
||||
import com.fr.report.worksheet.WorkSheet; |
||||
|
||||
import java.io.OutputStream; |
||||
|
||||
|
||||
public class CptCompileUtil { |
||||
public static void compile(JTemplate jtemplate) { |
||||
if (jtemplate == null || jtemplate.getEditingFILE() == null) { |
||||
return; |
||||
} |
||||
FILE file = jtemplate.getEditingFILE(); |
||||
String path = file.getPath(); |
||||
WorkBook workbook = (WorkBook) jtemplate.getTarget(); |
||||
/* |
||||
* 如果是cpt并且引擎设置正确,执行预编译,如果是cptx文件也执行预编译。在JStreamWork中,保存和另存为流程都进行了重新编译。 |
||||
* 但是由于之前的DefaultTemplateResource.saveTemplate的原因导致JStreamWork::saveFile()不能执行--cptx的保存不能进行预编译, |
||||
* 应该是流程的误改动,这里改回来,保存时仍然执行预编译。 |
||||
* */ |
||||
if (!isNewEngine(workbook, path)){ |
||||
return; |
||||
} |
||||
TransformResultInfo resultInfo = compile0(workbook, file); |
||||
unSupportLog(resultInfo); |
||||
|
||||
} |
||||
|
||||
private static TransformResultInfo compile0(WorkBook workbook, FILE file) { |
||||
if (!(file instanceof FileNodeFILE)) { |
||||
try { |
||||
OutputStream outputStream = file.asOutputStream(); |
||||
workbook.export(outputStream); |
||||
return TransformResultInfo.generateResult(TransformResult.SUCCESS).saved(true); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||
return TransformResultInfo.generateResult(TransformResult.FAILED).saved(false); |
||||
} |
||||
} |
||||
boolean saved; |
||||
CompiledReport report = null; |
||||
CompileStatus compileStatus = CompileStatus.SUCCEED; |
||||
if (workbook == null || file == null) { |
||||
return TransformResultInfo |
||||
.generateResult(TransformResult.FAILED, "work and file must not be null") |
||||
.saved(false); |
||||
} |
||||
String failMessage = null; |
||||
// 编译
|
||||
ReportCompiler compiler; |
||||
try { |
||||
compiler = new ReportCompiler(new LegacyWorkBookAdapter(workbook)); |
||||
long startTime = System.currentTimeMillis(); |
||||
compiler.compile(); |
||||
report = compiler.getCompiledReport(); |
||||
// 折叠树埋点
|
||||
LayerProps props = ReportCompileUtils.getLayerProps(report); |
||||
LayerItem[] items; |
||||
if (props != null && (items = props.getLayerItems()) != null) { |
||||
CompileMonitorHandler.submitTreeCompileFocusPoint( |
||||
startTime, file.getPath(), items.length, |
||||
props.getExpandLayer(), true |
||||
); |
||||
} |
||||
compileStatus = compiler.getStatus(); |
||||
failMessage = compiler.getFailMessage(); |
||||
long endTime = System.currentTimeMillis(); |
||||
CompileMonitorHandler.submitCompileMessage(startTime, endTime, file.getPath(), ""); |
||||
if (compileStatus != CompileStatus.SUCCEED) { |
||||
DesignerMetricRecorder.submitUnSupportTransform( |
||||
TransformResult.UNSUPPORT, |
||||
workbook.getTemplateID(), |
||||
file.getName(), |
||||
compileStatus == CompileStatus.FAILED_UNSUPPORT ? failMessage : null |
||||
); |
||||
} |
||||
} catch (Exception exception) { |
||||
String templateID = workbook.getTemplateID(); |
||||
String fileName = file.getName(); |
||||
DesignerMetricRecorder.submitFailedTransform(TransformResult.FAILED, templateID, fileName, exception); |
||||
FineLoggerFactory.getLogger().error(exception.getMessage(), exception); |
||||
} |
||||
|
||||
// 构建编译结果,当前的 cptx template 是未经反序列化钩子处理过的 cptx 模版对象,不能直接用于模版预览
|
||||
CptxTemplate template = CptxIOManager.createCptxTemplate(workbook, report, compileStatus, failMessage); |
||||
// 保存
|
||||
DesignReadWritableProvider cptx = new DesignReadWritableProvider(file); |
||||
CptxTemplateHandle handle = CptxIOManager.create(template, cptx); |
||||
try { |
||||
saved = handle.save(); |
||||
} catch (Exception exception) { |
||||
// 存储cptx格式报错或者失败
|
||||
FineLoggerFactory.getLogger().error(exception.getMessage(), exception); |
||||
DesignerMetricRecorder.submitFailedTransform(TransformResult.FAILED, workbook.getTemplateID(), file.getName(), exception); |
||||
return TransformResultInfo.generateResult(TransformResult.FAILED, failMessage).saved(false); |
||||
} |
||||
// 读取可 web 预览模版并缓存
|
||||
try { |
||||
CptxTemplate previewCptxTemplate = CptxIOManager.open(cptx).getTemplate(); |
||||
CptxTemplatePool.getInstance().addCptxTemplate(CptxFileUtils.getFormatPath(file.getPath()), previewCptxTemplate); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||
} |
||||
if (report == null) { |
||||
// 编译报错或者失败
|
||||
return TransformResultInfo.generateResult(TransformResult.FAILED, failMessage).saved(saved); |
||||
} |
||||
return TransformResultInfo.generateResult(TransformResult.parse(compileStatus), failMessage).saved(saved); |
||||
} |
||||
|
||||
private static boolean needDoAfterCompile(TransformResult result) { |
||||
return ComparatorUtils.equals(TransformResult.SUCCESS, result) |
||||
|| ComparatorUtils.equals(TransformResult.UNSUPPORT, result); |
||||
} |
||||
|
||||
/* |
||||
* 该另存为流程会改变文件内容,现在作为兼容的流程,以后可以随时删除该流程 |
||||
* */ |
||||
public static boolean hasChanged(String oldName, JTemplate jTemplate){ |
||||
FILE editingFILE = jTemplate.getEditingFILE(); |
||||
String path = editingFILE.getPath(); |
||||
//只有在旧文件是cptx文件并且新文件是cpt文件时才会改变报表引擎属性
|
||||
boolean isChange = oldName.endsWith(".cptx") && path.endsWith(".cpt"); |
||||
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(); |
||||
workSheet.setLayerReportAttr(layerReportAttr); |
||||
} |
||||
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; |
||||
} |
||||
} |
||||
|
||||
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){ |
||||
TransformResult result = transformResultInfo.getResult(); |
||||
//这里只打印模板转换不支持的信息,没有打印模板转换失败的信息
|
||||
if (result.equals(TransformResult.UNSUPPORT)){ |
||||
FineLoggerFactory.getLogger().error(transformResultInfo.getTransformLog()); |
||||
} |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,211 @@
|
||||
package com.fr.design.report; |
||||
|
||||
import com.fr.design.beans.BasicBeanPane; |
||||
import com.fr.design.dialog.FineJOptionPane; |
||||
import com.fr.design.editor.editor.IntegerEditor; |
||||
import com.fr.design.gui.ibutton.UIRadioButton; |
||||
import com.fr.design.gui.icheckbox.UICheckBox; |
||||
import com.fr.design.gui.ilable.FRExplainLabel; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.layout.FRGUIPaneFactory; |
||||
import com.fr.design.layout.TableLayout; |
||||
import com.fr.design.layout.TableLayoutHelper; |
||||
import com.fr.design.mainframe.DesignerContext; |
||||
import com.fr.locale.InterProviderFactory; |
||||
import com.fr.report.core.ReportUtils; |
||||
import com.fr.report.stable.LayerReportAttr; |
||||
import com.fr.report.worksheet.WorkSheet; |
||||
|
||||
import javax.swing.BorderFactory; |
||||
import javax.swing.ButtonGroup; |
||||
import javax.swing.JOptionPane; |
||||
import javax.swing.JPanel; |
||||
import javax.swing.JRadioButton; |
||||
import java.awt.CardLayout; |
||||
import java.awt.Component; |
||||
import java.awt.Dimension; |
||||
import java.awt.event.ActionEvent; |
||||
import java.awt.event.ActionListener; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author fly.li |
||||
* @version 10.0 |
||||
* Created on 2021/08/22 |
||||
*/ |
||||
public class LayerReportEnginePane extends BasicBeanPane<LayerReportAttr> { |
||||
private static final int LABEL_HEIGHT = 55; |
||||
private UICheckBox isClientPaging; |
||||
private UICheckBox isShowDataNumber; |
||||
private UICheckBox isPageQueryBox; |
||||
private IntegerEditor countPerPageEditor; |
||||
private WorkSheet worksheet; |
||||
private List<JRadioButton> radioButtons = new ArrayList<>(2); |
||||
|
||||
public LayerReportEnginePane(WorkSheet worksheet) { |
||||
this.worksheet = worksheet; |
||||
this.initComponents(); |
||||
} |
||||
|
||||
public LayerReportEnginePane() { |
||||
this(null); |
||||
} |
||||
|
||||
protected void initComponents() { |
||||
this.setLayout(FRGUIPaneFactory.createBorderLayout()); |
||||
JPanel outlayerReportPane = FRGUIPaneFactory.createTitledBorderPane(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Report_Engine_Attribute")); |
||||
JPanel layerReportPane = FRGUIPaneFactory.createY_AXISBoxInnerContainer_M_Pane(); |
||||
this.add(outlayerReportPane); |
||||
outlayerReportPane.add(layerReportPane); |
||||
|
||||
JPanel isClientPagingPanle = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); |
||||
isClientPaging = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Enable_Client_Page")); |
||||
isClientPaging.addActionListener(new ActionListener(){ |
||||
|
||||
@Override |
||||
public void actionPerformed(ActionEvent e) { |
||||
if (isClientPaging.isSelected()){ |
||||
isPageQueryBox.setEnabled(true); |
||||
}else{ |
||||
isPageQueryBox.setEnabled(false); |
||||
} |
||||
|
||||
} |
||||
}); |
||||
isClientPaging.setSelected(false); |
||||
isClientPagingPanle.add(isClientPaging); |
||||
layerReportPane.add(isClientPagingPanle); |
||||
UIRadioButton lineEngine = new UIRadioButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_New_Engine"), false); |
||||
UIRadioButton newEngine = new UIRadioButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Line_Engine"), false); |
||||
|
||||
ButtonGroup buttonGroup = new ButtonGroup(); |
||||
buttonGroup.add(newEngine); |
||||
buttonGroup.add(lineEngine); |
||||
radioButtons.add(lineEngine); |
||||
radioButtons.add(newEngine); |
||||
|
||||
double p = TableLayout.PREFERRED; |
||||
double[] rowSize = {p}; |
||||
double[] columnSize = {p, p, p, p, p}; |
||||
Component[][] components = new Component[][]{ |
||||
new Component[] { |
||||
new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Page_Engine_Select")), |
||||
lineEngine, |
||||
newEngine |
||||
} |
||||
}; |
||||
JPanel pagingEngineRadioPanel = TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); |
||||
layerReportPane.add(pagingEngineRadioPanel); |
||||
|
||||
JPanel infoPane = FRGUIPaneFactory.createTitledBorderPane(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Attention")); |
||||
FRExplainLabel label = new FRExplainLabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Layer_Report_Warnning_Info")); |
||||
label.setPreferredSize(new Dimension(label.getPreferredSize().width, LABEL_HEIGHT)); |
||||
infoPane.add(label); |
||||
layerReportPane.add(infoPane); |
||||
|
||||
JPanel isShowDataNumberPanle = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); |
||||
isShowDataNumber = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Show_Data_Total_Number")); |
||||
isShowDataNumber.setSelected(false); |
||||
isShowDataNumberPanle.add(isShowDataNumber); |
||||
layerReportPane.add(isShowDataNumberPanle); |
||||
|
||||
JPanel isPageQueryBoxPanle = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); |
||||
isPageQueryBox = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Fixed_Line_Paging")); |
||||
isPageQueryBox.setSelected(false); |
||||
isPageQueryBox.setEnabled(false); |
||||
isPageQueryBoxPanle.add(isPageQueryBox); |
||||
layerReportPane.add(isPageQueryBoxPanle); |
||||
isPageQueryBox.addActionListener(new ActionListener() { |
||||
public void actionPerformed(ActionEvent arg0) { |
||||
if (isPageQueryBox.isSelected()) { |
||||
countPerPageEditor.setEnabled(true); |
||||
} else { |
||||
countPerPageEditor.setEnabled(false); |
||||
} |
||||
} |
||||
}); |
||||
|
||||
JPanel pageQueryPane = createPageQueryPane(); |
||||
layerReportPane.add(pageQueryPane); |
||||
|
||||
} |
||||
|
||||
private JPanel createPageQueryPane() { |
||||
double p = TableLayout.PREFERRED; |
||||
double rowSize[] = {p, p}; |
||||
double columnSize[] = {p, p}; |
||||
countPerPageEditor = new IntegerEditor(new Integer(30)); |
||||
countPerPageEditor.setPreferredSize(new Dimension(120,20)); |
||||
countPerPageEditor.setEnabled(false); |
||||
Component[][] components = {{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_LayerPageReport_Count_PerPage") + ":"), countPerPageEditor}}; |
||||
JPanel pageQueryPane = TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); |
||||
pageQueryPane.setBorder(BorderFactory.createEmptyBorder(5, 15, 0, 0)); |
||||
return pageQueryPane; |
||||
} |
||||
|
||||
@Override |
||||
protected String title4PopupWindow() { |
||||
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Report_Engine_Attribute"); |
||||
} |
||||
|
||||
@Override |
||||
public void populateBean(LayerReportAttr ob) { |
||||
if (ob == null){ |
||||
setDefaultAttr(); |
||||
return; |
||||
} |
||||
isClientPaging.setSelected(ob.isClientPaging()); |
||||
isShowDataNumber.setSelected(ob.isShowDataNumber()); |
||||
countPerPageEditor.setValue(new Integer(ob.getCountPerPage())); |
||||
if (ob.isPageQuery()) { |
||||
isPageQueryBox.setSelected(true); |
||||
countPerPageEditor.setEnabled(true); |
||||
} else { |
||||
isPageQueryBox.setSelected(false); |
||||
countPerPageEditor.setEnabled(false); |
||||
} |
||||
radioButtons.get(0).setSelected(ob.isNewEngine()); |
||||
radioButtons.get(1).setSelected(!ob.isNewEngine()); |
||||
} |
||||
|
||||
@Override |
||||
public LayerReportAttr updateBean() { |
||||
//这里注意一下怎么更新的,后续可能存在判断为空的调用,从而对老引擎造成影响。
|
||||
LayerReportAttr attr = new LayerReportAttr(); |
||||
attr.setPageQuery(isPageQueryBox.isSelected()); |
||||
attr.setCountPerPage(Math.min(500, ((Integer)countPerPageEditor.getValue()).intValue())); |
||||
attr.setClientPaging(isClientPaging.isSelected()); |
||||
attr.setShowDataNumber(isShowDataNumber.isSelected()); |
||||
for (int i = 0; i < radioButtons.size(); i++){ |
||||
if (radioButtons.get(i).isSelected()){ |
||||
attr.setNewEngine((i == 0)); |
||||
} |
||||
} |
||||
return attr; |
||||
} |
||||
|
||||
@Override |
||||
public void checkValid() throws Exception { |
||||
if (isClientPaging.isSelected()) { |
||||
if (!ReportUtils.isLayerReportUsable(worksheet)) { |
||||
int value = FineJOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_After_Changed_Some_Attributes_Are_Different") + "?", |
||||
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Confirm"), JOptionPane.YES_NO_OPTION); |
||||
if (value != JOptionPane.YES_OPTION) { |
||||
isClientPaging.setSelected(false); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
public void setDefaultAttr(){ |
||||
isClientPaging.setSelected(false); |
||||
isShowDataNumber.setSelected(false); |
||||
countPerPageEditor.setValue(new Integer(30)); |
||||
countPerPageEditor.setEnabled(false); |
||||
isPageQueryBox.setSelected(false); |
||||
isPageQueryBox.setEnabled(false); |
||||
radioButtons.get(0).setSelected(false); |
||||
radioButtons.get(1).setSelected(false); |
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue