From b0cbc811c669d5fd1092b9c75c6e521f2c8a4fa9 Mon Sep 17 00:00:00 2001 From: richie Date: Mon, 19 Nov 2018 10:00:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A8=E6=80=81=E5=B1=95=E7=A4=BAsheet?= =?UTF-8?q?=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 5 + build.xml | 130 ++++++++++++++++++ lib/report/.gitkeep | 0 plugin.xml | 18 +++ pom.xml | 18 +++ readme.md | 21 +++ .../control/SheetControlActorBridge.java | 23 ++++ .../control/actor/SheetControlActor.java | 76 ++++++++++ src/main/resources/.gitkeep | 0 9 files changed, 291 insertions(+) create mode 100644 .gitignore create mode 100644 build.xml create mode 100644 lib/report/.gitkeep create mode 100644 plugin.xml create mode 100644 pom.xml create mode 100644 readme.md create mode 100644 src/main/java/com/fr/plugin/control/SheetControlActorBridge.java create mode 100644 src/main/java/com/fr/plugin/control/actor/SheetControlActor.java create mode 100644 src/main/resources/.gitkeep diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d91e065 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +*.iml +.idea/ +lib/report/*.jar +.DS_Store +.classpath \ No newline at end of file diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..0a18718 --- /dev/null +++ b/build.xml @@ -0,0 +1,130 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lib/report/.gitkeep b/lib/report/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/plugin.xml b/plugin.xml new file mode 100644 index 0000000..5527648 --- /dev/null +++ b/plugin.xml @@ -0,0 +1,18 @@ + + com.fr.plugin.preview.sheet.control + + yes + 1.0 + 10.0 + 2018-10-09 + author + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..896013a --- /dev/null +++ b/pom.xml @@ -0,0 +1,18 @@ + + + 4.0.0 + + + com.fr.plugin + starter + 10.0 + + jar + demo-dynamic-sheet + + + ${project.basedir}/../webroot/WEB-INF/plugins/plugin-com.fr.plugin.preview.sheet.control-1.0/classes + + \ No newline at end of file diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..c32f3b9 --- /dev/null +++ b/readme.md @@ -0,0 +1,21 @@ +# 动态显示sheet示例 + +给多sheet模板添加参数,形如 + +``` +/decision/view/report?viewlet=WorkBook6.cpt&op=write&SHEETNOTSHOW=0 +``` + +如果这个模板有sheet1、sheet2、sheet3三个sheet,就只会展示出来sheet2和sheet3 + +该参数也可以传sheet的名字 + +``` +/decision/view/report?viewlet=WorkBook6.cpt&op=write&SHEETNOTSHOW=sheet1 +``` + +效果一样 + +## 注意事项 + +如果需要更加灵活的控制sheet展示,比如可以只展示允许的sheet,需要自行对代码做二次开发。 \ No newline at end of file diff --git a/src/main/java/com/fr/plugin/control/SheetControlActorBridge.java b/src/main/java/com/fr/plugin/control/SheetControlActorBridge.java new file mode 100644 index 0000000..4c7b8fe --- /dev/null +++ b/src/main/java/com/fr/plugin/control/SheetControlActorBridge.java @@ -0,0 +1,23 @@ +package com.fr.plugin.control; + +import com.fr.plugin.control.actor.SheetControlActor; +import com.fr.report.fun.impl.AbstractActorProvider; +import com.fr.report.stable.fun.Actor; + +/** + * @author richie + * @date 2015-03-21 + * @since 8.0 + */ +public class SheetControlActorBridge extends AbstractActorProvider { + + @Override + public int currentAPILevel() { + return CURRENT_LEVEL; + } + + @Override + public Actor[] createActor() { + return new Actor[]{new SheetControlActor()}; + } +} \ No newline at end of file diff --git a/src/main/java/com/fr/plugin/control/actor/SheetControlActor.java b/src/main/java/com/fr/plugin/control/actor/SheetControlActor.java new file mode 100644 index 0000000..68bec69 --- /dev/null +++ b/src/main/java/com/fr/plugin/control/actor/SheetControlActor.java @@ -0,0 +1,76 @@ +package com.fr.plugin.control.actor; + +import com.fr.general.ComparatorUtils; +import com.fr.general.GeneralUtils; +import com.fr.intelli.record.Focus; +import com.fr.intelli.record.Original; +import com.fr.json.JSON; +import com.fr.json.JSONArray; +import com.fr.json.JSONFactory; +import com.fr.main.TemplateWorkBook; +import com.fr.main.workbook.ResultWorkBook; +import com.fr.record.analyzer.EnableMetrics; +import com.fr.report.core.sheet.SheetSequenceExecutor; +import com.fr.stable.WriteActor; +import com.fr.stable.web.Repository; +import com.fr.web.RTypeService; +import com.fr.web.RepositoryHelper; +import com.fr.web.core.ReportSession; + +import java.util.Map; + +/** + * @author richie + * @date 2015-03-21 + * @since 8.0 + */ +@EnableMetrics +public class SheetControlActor extends WriteActor { + + private static final String SHEET_INDEX_NOT_BE_SHOW_PARA_NAME = "SHEETNOTSHOW"; + + @Override + public ResultWorkBook executeWorkBook(TemplateWorkBook workBook, Map parameterMap) { + if (parameterMap.containsKey(SHEET_INDEX_NOT_BE_SHOW_PARA_NAME)) { + removeUnnecessary(workBook, parameterMap); + } + return new SheetSequenceExecutor(workBook, parameterMap).execute(this); + } + + @Focus(id = "com.fr.plugin.preview.sheet.control", text = "", source = Original.PLUGIN) + private void removeUnnecessary(TemplateWorkBook workBook, Map parameterMap) { + Number index = GeneralUtils.objectToNumber(parameterMap.get(SHEET_INDEX_NOT_BE_SHOW_PARA_NAME), true); + if (index != null) { + workBook.removeReport(index.intValue()); + } else { + workBook.removeReport(GeneralUtils.objectToString(parameterMap.get(SHEET_INDEX_NOT_BE_SHOW_PARA_NAME))); + } + } + + public JSONArray processMultipleSheet(Repository repository) { + Map map = repository.getReportParameterMap(); + int sheetIndex = -1; + String sheetName = null; + if (map.containsKey(SHEET_INDEX_NOT_BE_SHOW_PARA_NAME)) { + Number index = GeneralUtils.objectToNumber(map.get(SHEET_INDEX_NOT_BE_SHOW_PARA_NAME), true); + if (index != null) { + sheetIndex = index.intValue(); + } else { + sheetName = GeneralUtils.objectToString(map.get(SHEET_INDEX_NOT_BE_SHOW_PARA_NAME)); + } + } + JSONArray ja = JSONFactory.createJSON(JSON.ARRAY); + int reportCount = getReportCountInRepo(repository); + for (int i = 0; i < reportCount; i++) { + ReportSession sessionIDInfo = (ReportSession) RepositoryHelper.getSessionIDInfor(repository); + String title = sessionIDInfo.getReportName(i); + if (i == sheetIndex || ComparatorUtils.equals(sheetName, title)) { + continue; + } + RTypeService.executeSheetName(repository, title, ja, i); + } + return ja; + } + + +} \ No newline at end of file diff --git a/src/main/resources/.gitkeep b/src/main/resources/.gitkeep new file mode 100644 index 0000000..e69de29