From 42d9b9229f1a7142b5c1bbf5e40ee4141c9a6293 Mon Sep 17 00:00:00 2001 From: kerry Date: Fri, 8 May 2020 13:44:18 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-30031=E3=80=90=E8=AE=BE=E8=AE=A1?= =?UTF-8?q?=E5=99=A8=E5=9F=8B=E7=82=B9=E3=80=91=E6=A8=A1=E6=9D=BF=E8=80=97?= =?UTF-8?q?=E6=97=B6=E5=92=8C=E6=A8=A1=E6=9D=BF=E5=88=B6=E4=BD=9C=E5=9F=8B?= =?UTF-8?q?=E7=82=B9=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/design/mainframe/JTemplate.java | 14 +- .../burying/point/AbstractPointInfo.java | 9 +- .../mainframe/template/info/TemplateInfo.java | 107 ++++++------- .../template/info/TemplateInfoCollector.java | 113 ++++++++++--- .../template/info/TemplateProcessInfo.java | 44 ++++++ .../info/TemplateInfoCollectorTest.java | 129 +++++++++------ .../template/info/TemplateInfoTest.java | 88 ++++++----- .../template/info/TemplateInfoTestHelper.java | 18 ++- .../design/mainframe/template/info/tpl.info | 44 +++--- .../designer/beans/models/SelectionModel.java | 4 + .../design/form/util/FormDesignerUtils.java | 24 ++- .../java/com/fr/design/mainframe/JForm.java | 21 +++ .../fr/design/mainframe/ToolBarButton.java | 8 +- .../template/info/ComponentProcessInfo.java | 73 +++++++++ .../template/info/JFormProcessInfo.java | 148 +++++++++++++++++ .../info/ComponentProcessInfoTest.java | 39 +++++ .../template/info/JFormProcessInfoTest.java | 149 ++++++++++++++++++ .../fr/design/mainframe/JPolyWorkBook.java | 12 ++ .../info/JPolyWorkBookProcessInfo.java | 77 +++++++++ .../template/info/JWorkBookProcessInfo.java | 83 ++++++++-- .../info/JWorkBookProcessInfoTest.java | 49 ++++++ 21 files changed, 1036 insertions(+), 217 deletions(-) create mode 100644 designer-form/src/main/java/com/fr/design/mainframe/template/info/ComponentProcessInfo.java create mode 100644 designer-form/src/test/java/com/fr/design/mainframe/template/info/ComponentProcessInfoTest.java create mode 100644 designer-form/src/test/java/com/fr/design/mainframe/template/info/JFormProcessInfoTest.java create mode 100644 designer-realize/src/main/java/com/fr/design/mainframe/template/info/JPolyWorkBookProcessInfo.java create mode 100644 designer-realize/src/test/java/com.fr/design/mainframe/template/info/JWorkBookProcessInfoTest.java 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 29c1dcb53..03248efb1 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 @@ -97,7 +97,7 @@ public abstract class JTemplate> private static short currentIndex = 0;// 此变量用于多次新建模板时,让名字不重复 private DesignModelAdapter designModel; private PreviewProvider previewType; - private TimeConsumeTimer consumeTimer = new TimeConsumeTimer(); + protected TimeConsumeTimer consumeTimer = new TimeConsumeTimer(); public int resolution = ScreenResolution.getScreenResolution(); public JTemplate() { @@ -266,7 +266,7 @@ public abstract class JTemplate> try { this.template = JTemplateFactory.asIOFile(this.editingFILE); setTarget(this.template); - + // 先移除旧的。 removeCenterPane(); // 加入新的 @@ -275,19 +275,19 @@ public abstract class JTemplate> FineLoggerFactory.getLogger().error(e.getMessage(), e); } } - + private void addCenterPane() { - + this.centerPane = createCenterPane(); this.add(centerPane, BorderLayout.CENTER); } - + private void removeCenterPane() { - + JComponent centerPane = this.centerPane; this.remove(centerPane); } - + /** * 刷新容器 */ diff --git a/designer-base/src/main/java/com/fr/design/mainframe/burying/point/AbstractPointInfo.java b/designer-base/src/main/java/com/fr/design/mainframe/burying/point/AbstractPointInfo.java index 6646bfd09..93ff42690 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/burying/point/AbstractPointInfo.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/burying/point/AbstractPointInfo.java @@ -11,6 +11,9 @@ public abstract class AbstractPointInfo implements BasePointInfo { protected int idleDayCount; // 到现在为止,埋点闲置的天数 + //是否是测试模板 + protected boolean isTestTemplate; + @Override public void resetIdleDayCount() { this.idleDayCount = 0; @@ -38,10 +41,14 @@ public abstract class AbstractPointInfo implements BasePointInfo { } } + public void setTestTemplate(boolean testTemplate) { + isTestTemplate = testTemplate; + } + /** * 是否为测试模板 */ - protected abstract boolean isTestTemplate(); + public abstract boolean isTestTemplate(); /** * 是否已经制作完成 diff --git a/designer-base/src/main/java/com/fr/design/mainframe/template/info/TemplateInfo.java b/designer-base/src/main/java/com/fr/design/mainframe/template/info/TemplateInfo.java index e233bc6e5..efd245bab 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/template/info/TemplateInfo.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/template/info/TemplateInfo.java @@ -4,9 +4,7 @@ import com.fr.config.MarketConfig; import com.fr.design.DesignerEnvManager; import com.fr.design.mainframe.burying.point.AbstractPointInfo; import com.fr.general.CloudCenter; -import com.fr.general.GeneralUtils; import com.fr.json.JSONObject; -import com.fr.stable.ProductConstants; import com.fr.stable.StringUtils; import com.fr.stable.xml.XMLPrintWriter; import com.fr.stable.xml.XMLableReader; @@ -22,6 +20,7 @@ import java.util.Map; */ public class TemplateInfo extends AbstractPointInfo { static final String XML_TAG = "TemplateInfo"; + private static final String SIMPLE_DATE_PATTRN = "yyyy-MM-dd HH:mm"; private static final String CONSUMING_URL = CloudCenter.getInstance().acquireUrlByKind("tempinfo.consuming") + "/single"; private static final String PROCESS_URL = CloudCenter.getInstance().acquireUrlByKind("tempinfo.process") + "/single"; @@ -37,18 +36,17 @@ public class TemplateInfo extends AbstractPointInfo { private static final String ATTR_CELL_COUNT = "cell_count"; private static final String ATTR_BLOCK_COUNT = "block_count"; private static final String ATTR_REPORT_TYPE = "report_type"; - private static final String ATTR_ACTIVITYKEY = "activitykey"; - private static final String ATTR_JAR_TIME = "jar_time"; private static final String ATTR_CREATE_TIME = "create_time"; private static final String ATTR_UUID = "uuid"; - private static final String ATTR_TIME_CONSUME = "time_consume"; - private static final String ATTR_ORIGIN_TIME = "originTime"; - private static final String ATTR_VERSION = "version"; - private static final String ATTR_USERNAME = "username"; + private static final String ATTR_UID = "uid"; + private static final String ATTR_SAVE_RECORD = "saveRecord"; + private static final String ATTR_PARA_APPLY = "paraApply"; + private static final String ATTR_COMPONENTS_INFO = "components_info"; + + private static final String TEST_TEMPLATE_FLAG = "test_template"; private static final int VALID_CELL_COUNT = 5; // 有效报表模板的格子数 private static final int VALID_WIDGET_COUNT = 5; // 有效报表模板的控件数 - private static final int COMPLETE_DAY_COUNT = 15; // 判断模板是否完成的天数 private String templateID = StringUtils.EMPTY; private String originID = StringUtils.EMPTY; @@ -76,28 +74,25 @@ public class TemplateInfo extends AbstractPointInfo { } public static TemplateInfo newInstance(String templateID) { - return newInstance(templateID, StringUtils.EMPTY, 0); + return newInstance(templateID, StringUtils.EMPTY, StringUtils.EMPTY, StringUtils.EMPTY); + } + + public static TemplateInfo newInstance(String templateID, String originID, String saveRecord) { + String createTime = new SimpleDateFormat(SIMPLE_DATE_PATTRN).format(Calendar.getInstance().getTime()); + return newInstance(templateID, originID, saveRecord, createTime); } - public static TemplateInfo newInstance(String templateID, String originID, int originTime) { + public static TemplateInfo newInstance(String templateID, String originID, String saveRecord, String createTime) { HashMap consumingMap = new HashMap<>(); - String username = MarketConfig.getInstance().getBbsUsername(); String uuid = DesignerEnvManager.getEnvManager().getUUID(); - String activitykey = DesignerEnvManager.getEnvManager().getActivationKey(); - String createTime = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(Calendar.getInstance().getTime()); - String jarTime = GeneralUtils.readBuildNO(); - String version = ProductConstants.VERSION; - consumingMap.put(ATTR_USERNAME, username); + MarketConfig config = MarketConfig.getInstance(); consumingMap.put(ATTR_UUID, uuid); - consumingMap.put(ATTR_ACTIVITYKEY, activitykey); consumingMap.put(ATTR_TEMPLATE_ID, templateID); consumingMap.put(ATTR_ORIGIN_ID, originID); consumingMap.put(ATTR_CREATE_TIME, createTime); - consumingMap.put(ATTR_TIME_CONSUME, originTime); // timeConsume 在原来模版的基础上累加 - consumingMap.put(ATTR_ORIGIN_TIME, originTime); - consumingMap.put(ATTR_JAR_TIME, jarTime); - consumingMap.put(ATTR_VERSION, version); + consumingMap.put(ATTR_UID, config.getBBSAttr().getBbsUid()); + consumingMap.put(ATTR_SAVE_RECORD, saveRecord); TemplateInfo templateInfo = new TemplateInfo(templateID, originID); templateInfo.consumingMap = consumingMap; @@ -109,14 +104,21 @@ public class TemplateInfo extends AbstractPointInfo { return templateID; } - String getOriginID() { - return originID; + public String getTemplateInfoID() { + return templateID + "_" + getSaveTime(); } - int getTimeConsume() { - return (int) consumingMap.get(ATTR_TIME_CONSUME); + public long getSaveTime() { + String save_record = (String) consumingMap.get(ATTR_SAVE_RECORD); + JSONObject jo = new JSONObject(save_record); + return jo.optLong("time"); } + public String getTemplateCreateTime() { + return (String) consumingMap.get(ATTR_CREATE_TIME); + } + + @Override public void writeXML(XMLPrintWriter writer) { writer.startTAG(XML_TAG); @@ -129,6 +131,7 @@ public class TemplateInfo extends AbstractPointInfo { if (idleDayCount >= 0) { writer.attr(ATTR_DAY_COUNT, this.idleDayCount); } + writer.attr(TEST_TEMPLATE_FLAG, this.isTestTemplate); writeProcessMap(writer); writeConsumingMap(writer); @@ -143,19 +146,17 @@ public class TemplateInfo extends AbstractPointInfo { writer.attr(ATTR_CELL_COUNT, (int) processMap.get(ATTR_CELL_COUNT)); writer.attr(ATTR_BLOCK_COUNT, (int) processMap.get(ATTR_BLOCK_COUNT)); writer.attr(ATTR_REPORT_TYPE, (int) processMap.get(ATTR_REPORT_TYPE)); + writer.attr(ATTR_PARA_APPLY, (int) processMap.get(ATTR_PARA_APPLY)); + writer.attr(ATTR_COMPONENTS_INFO, (String) processMap.get(ATTR_COMPONENTS_INFO)); writer.end(); } private void writeConsumingMap(XMLPrintWriter writer) { writer.startTAG(XML_CONSUMING_MAP); - writer.attr(ATTR_ACTIVITYKEY, (String) consumingMap.get(ATTR_ACTIVITYKEY)); - writer.attr(ATTR_JAR_TIME, (String) consumingMap.get(ATTR_JAR_TIME)); writer.attr(ATTR_CREATE_TIME, (String) consumingMap.get(ATTR_CREATE_TIME)); writer.attr(ATTR_UUID, (String) consumingMap.get(ATTR_UUID)); - writer.attr(ATTR_TIME_CONSUME, (int) consumingMap.get(ATTR_TIME_CONSUME)); - writer.attr(ATTR_ORIGIN_TIME, (int) consumingMap.get(ATTR_ORIGIN_TIME)); - writer.attr(ATTR_VERSION, (String) consumingMap.get(ATTR_VERSION)); - writer.attr(ATTR_USERNAME, (String) consumingMap.get(ATTR_USERNAME)); + writer.attr(ATTR_UID, (int) consumingMap.get(ATTR_UID)); + writer.attr(ATTR_SAVE_RECORD, (String) consumingMap.get(ATTR_SAVE_RECORD)); writer.end(); } @@ -163,6 +164,7 @@ public class TemplateInfo extends AbstractPointInfo { public void readXML(XMLableReader reader) { if (!reader.isChildNode()) { idleDayCount = reader.getAttrAsInt(ATTR_DAY_COUNT, 0); + isTestTemplate = reader.getAttrAsBoolean(TEST_TEMPLATE_FLAG, false); templateID = reader.getAttrAsString(ATTR_TEMPLATE_ID, StringUtils.EMPTY); originID = reader.getAttrAsString(ATTR_ORIGIN_ID, StringUtils.EMPTY); } else { @@ -175,18 +177,16 @@ public class TemplateInfo extends AbstractPointInfo { processMap.put(ATTR_CELL_COUNT, reader.getAttrAsInt(ATTR_CELL_COUNT, 0)); processMap.put(ATTR_BLOCK_COUNT, reader.getAttrAsInt(ATTR_BLOCK_COUNT, 0)); processMap.put(ATTR_REPORT_TYPE, reader.getAttrAsInt(ATTR_REPORT_TYPE, 0)); + processMap.put(ATTR_PARA_APPLY, reader.getAttrAsInt(ATTR_PARA_APPLY, 0)); + processMap.put(ATTR_COMPONENTS_INFO, reader.getAttrAsString(ATTR_COMPONENTS_INFO, StringUtils.EMPTY)); processMap.put(ATTR_TEMPLATE_ID, templateID); } else if (XML_CONSUMING_MAP.equals(name)) { - consumingMap.put(ATTR_ACTIVITYKEY, reader.getAttrAsString(ATTR_ACTIVITYKEY, StringUtils.EMPTY)); - consumingMap.put(ATTR_JAR_TIME, reader.getAttrAsString(ATTR_JAR_TIME, StringUtils.EMPTY)); consumingMap.put(ATTR_CREATE_TIME, reader.getAttrAsString(ATTR_CREATE_TIME, StringUtils.EMPTY)); consumingMap.put(ATTR_TEMPLATE_ID, templateID); consumingMap.put(ATTR_ORIGIN_ID, originID); consumingMap.put(ATTR_UUID, reader.getAttrAsString(ATTR_UUID, StringUtils.EMPTY)); - consumingMap.put(ATTR_TIME_CONSUME, reader.getAttrAsInt(ATTR_TIME_CONSUME, 0)); - consumingMap.put(ATTR_ORIGIN_TIME, reader.getAttrAsInt(ATTR_ORIGIN_TIME, 0)); - consumingMap.put(ATTR_VERSION, reader.getAttrAsString(ATTR_VERSION, "8.0")); - consumingMap.put(ATTR_USERNAME, reader.getAttrAsString(ATTR_USERNAME, StringUtils.EMPTY)); + consumingMap.put(ATTR_UID, reader.getAttrAsInt(ATTR_UID, 0)); + consumingMap.put(ATTR_SAVE_RECORD, reader.getAttrAsString(ATTR_SAVE_RECORD, StringUtils.EMPTY)); } } catch (Exception ex) { // 什么也不做,使用默认值 @@ -195,17 +195,8 @@ public class TemplateInfo extends AbstractPointInfo { } @Override - protected boolean isTestTemplate() { - if (!isComplete()) { - return false; - } - - int reportType = (int) processMap.get(ATTR_REPORT_TYPE); - int cellCount = (int) processMap.get(ATTR_CELL_COUNT); - int floatCount = (int) processMap.get(ATTR_FLOAT_COUNT); - int blockCount = (int) processMap.get(ATTR_BLOCK_COUNT); - int widgetCount = (int) processMap.get(ATTR_WIDGET_COUNT); - return isTestTemplate(reportType, cellCount, floatCount, blockCount, widgetCount); + public boolean isTestTemplate() { + return isTestTemplate; } public static boolean isTestTemplate(int reportType, int cellCount, int floatCount, int blockCount, int widgetCount) { @@ -222,25 +213,17 @@ public class TemplateInfo extends AbstractPointInfo { @Override protected boolean isComplete() { - // 条件 1. 超过15天未编辑 - // 条件 2. 设计器在这段未编辑的时间内启动超过 X 次(目前定的 X = 3)。即"设计器最近 X 次启动的时间跨度" < "未编辑时间"; - - return idleDayCount > COMPLETE_DAY_COUNT - && DesignerOpenHistory.getInstance().isOpenEnoughTimesInPeriod(idleDayCount); + return true; } @Override public Map getSendInfo() { Map sendMap = new HashMap<>(); sendMap.put(CONSUMING_URL, new JSONObject(consumingMap).toString()); - sendMap.put(PROCESS_URL, new JSONObject(processMap).toString()); + sendMap.put(PROCESS_URL, new JSONObject(processMap).toString()); return sendMap; } - void addTimeConsume(int timeConsume) { - timeConsume += (int) consumingMap.get(ATTR_TIME_CONSUME); // 加上之前的累计编辑时间 - consumingMap.put(ATTR_TIME_CONSUME, timeConsume); - } void updateProcessMap(TemplateProcessInfo processInfo) { HashMap processMap = new HashMap<>(); @@ -253,11 +236,13 @@ public class TemplateInfo extends AbstractPointInfo { processMap.put(ATTR_FLOAT_COUNT, processInfo.getFloatCount()); processMap.put(ATTR_BLOCK_COUNT, processInfo.getBlockCount()); processMap.put(ATTR_WIDGET_COUNT, processInfo.getWidgetCount()); - + processMap.put(ATTR_PARA_APPLY, processInfo.useParaPane() ? 1 : 0); + processMap.put(ATTR_COMPONENTS_INFO, processInfo.getComponentsInfo().toString()); this.processMap = processMap; } + int getIdleDayCount() { return this.idleDayCount; } -} \ No newline at end of file +} diff --git a/designer-base/src/main/java/com/fr/design/mainframe/template/info/TemplateInfoCollector.java b/designer-base/src/main/java/com/fr/design/mainframe/template/info/TemplateInfoCollector.java index 8c4e7f18d..bdc853796 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/template/info/TemplateInfoCollector.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/template/info/TemplateInfoCollector.java @@ -1,6 +1,8 @@ package com.fr.design.mainframe.template.info; import com.fr.design.mainframe.burying.point.AbstractPointCollector; +import com.fr.design.mainframe.burying.point.AbstractPointInfo; +import com.fr.json.JSONObject; import com.fr.stable.ProductConstants; import com.fr.stable.StableUtils; import com.fr.stable.StringUtils; @@ -8,6 +10,10 @@ import com.fr.stable.xml.XMLPrintWriter; import com.fr.stable.xml.XMLableReader; import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; /** * 做模板的过程和耗时收集,辅助类 @@ -19,8 +25,11 @@ public class TemplateInfoCollector extends AbstractPointCollector private static final String XML_FILE_NAME = "tpl.info"; private static TemplateInfoCollector instance; private DesignerOpenHistory designerOpenHistory; + //记录指定模板最新的模板耗时信息ID + private Map latestTemplateInfo; private TemplateInfoCollector() { + super(); } public static TemplateInfoCollector getInstance() { @@ -34,7 +43,7 @@ public class TemplateInfoCollector extends AbstractPointCollector * 根据模板ID是否在收集列表中,判断是否需要收集当前模板的信息 */ public boolean contains(String templateID) { - return StringUtils.isNotEmpty(templateID) && pointInfoMap.containsKey(templateID); + return StringUtils.isNotEmpty(templateID) && latestTemplateInfo.containsKey(templateID); } /** @@ -51,27 +60,43 @@ public class TemplateInfoCollector extends AbstractPointCollector if (!shouldCollectInfo()) { return; } + long saveTime = System.currentTimeMillis(); - TemplateInfo templateInfo; - if (this.contains(templateID)) { - templateInfo = pointInfoMap.get(templateID); - } else { - int originTime = this.contains(originID) ? pointInfoMap.get(originID).getTimeConsume() : 0; - templateInfo = TemplateInfo.newInstance(templateID, originID, originTime); - pointInfoMap.put(templateID, templateInfo); - } + TemplateInfo templateInfo = createTemplateInfo(templateID, originID, saveTime, timeConsume); + + pointInfoMap.put(templateInfo.getTemplateInfoID(), templateInfo); + + //更新下此模板最新保存记录 + updateLatestTemplateInfo(templateID, saveTime); - // 收集制作耗时 - templateInfo.addTimeConsume(timeConsume); // 收集模版基本信息 templateInfo.updateProcessMap(processInfo); + //设置是否是测试模板 + templateInfo.setTestTemplate(processInfo.isTestTemplate()); // 刷新闲置日计数器 templateInfo.resetIdleDayCount(); + // 每次更新之后,都同步到暂存文件中 saveInfo(); } + private TemplateInfo createTemplateInfo(String templateID, String originID, long saveTime, int timeConsume){ + JSONObject saveRecord = new JSONObject(); + saveRecord.put("time", saveTime); + saveRecord.put("consume", timeConsume); + if (this.contains(templateID)){ + return TemplateInfo.newInstance(templateID, originID, saveRecord.toString(), getTemplateCreateTime(templateID)); + } + return TemplateInfo.newInstance(templateID, originID, saveRecord.toString()); + } + + private String getTemplateCreateTime(String templateID) { + long latestSaveTime = latestTemplateInfo.get(templateID); + TemplateInfo latestTemplateInfo = pointInfoMap.get(templateID + "_" + latestSaveTime); + return latestTemplateInfo.getTemplateCreateTime(); + } + /** * 获取缓存文件存放路径 */ @@ -80,15 +105,6 @@ public class TemplateInfoCollector extends AbstractPointCollector return new File(StableUtils.pathJoin(ProductConstants.getEnvHome(), XML_FILE_NAME)); } - TemplateInfo getOrCreateTemplateInfoByID(String templateID) { - if (pointInfoMap.containsKey(templateID)) { - return pointInfoMap.get(templateID); - } - TemplateInfo templateInfo = TemplateInfo.newInstance(templateID); - pointInfoMap.put(templateID, templateInfo); - return templateInfo; - } - /** * 更新 day_count:打开设计器却未编辑模板的连续日子 */ @@ -104,6 +120,20 @@ public class TemplateInfoCollector extends AbstractPointCollector designerOpenHistory.update(); } + private void updateLatestTemplateInfo(TemplateInfo templateInfo) { + String templateID = templateInfo.getTemplateID(); + if (latestTemplateInfo.containsKey(templateID)) { + long latestSaveTime = latestTemplateInfo.get(templateID); + updateLatestTemplateInfo(templateID, Math.max(latestSaveTime, templateInfo.getSaveTime())); + } else { + updateLatestTemplateInfo(templateID, templateInfo.getSaveTime()); + } + } + + private void updateLatestTemplateInfo(String templateID, long saveTime) { + latestTemplateInfo.put(templateID, saveTime); + } + @Override public void readXML(XMLableReader reader) { if (reader.isChildNode()) { @@ -116,7 +146,8 @@ public class TemplateInfoCollector extends AbstractPointCollector reader.readXMLObject(designerOpenHistory); } else if (TemplateInfo.XML_TAG.equals(name)) { TemplateInfo templateInfo = TemplateInfo.newInstanceByRead(reader); - pointInfoMap.put(templateInfo.getTemplateID(), templateInfo); + updateLatestTemplateInfo(templateInfo); + pointInfoMap.put(templateInfo.getTemplateInfoID(), templateInfo); } } catch (Exception ex) { // 什么也不做,使用默认值 @@ -138,4 +169,44 @@ public class TemplateInfoCollector extends AbstractPointCollector writer.end(); } + + + @Override + public void sendPointInfo() { + addIdleDayCount(); + List removeList = new ArrayList<>(); + List sendList = new ArrayList<>(); + for (String latestTemplateInfokey : latestTemplateInfo.keySet()) { + AbstractPointInfo pointInfo = pointInfoMap.get(latestTemplateInfokey + "_" + latestTemplateInfo.get(latestTemplateInfokey)); + if (pointInfo.isTestTemplate()) { + continue; + } + for (String key : pointInfoMap.keySet()) { + if (key.startsWith(latestTemplateInfokey)) { + sendList.add(key); + } + } + } + // 发送记录 + for (String key : sendList) { + if (SendHelper.sendPointInfo(pointInfoMap.get(key))) { + removeList.add(key); + } + } + + // 清空记录 + for (String key : removeList) { + pointInfoMap.remove(key); + } + + saveInfo(); + } + + + @Override + protected void loadFromFile() { + latestTemplateInfo = new ConcurrentHashMap<>(); + super.loadFromFile(); + } + } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/template/info/TemplateProcessInfo.java b/designer-base/src/main/java/com/fr/design/mainframe/template/info/TemplateProcessInfo.java index 427d48c73..e5872ae1d 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/template/info/TemplateProcessInfo.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/template/info/TemplateProcessInfo.java @@ -1,6 +1,10 @@ package com.fr.design.mainframe.template.info; +import com.fr.base.Style; import com.fr.base.io.BaseBook; +import com.fr.chart.chartattr.ChartCollection; +import com.fr.chartx.attr.ChartProvider; +import com.fr.json.JSONArray; /** * Created by plough on 2017/3/17. @@ -19,12 +23,52 @@ public abstract class TemplateProcessInfo { // 获取模板类型。0 代表普通报表,1 代表聚合报表,2 代表表单 public abstract int getReportType(); + // 获取模板格子数 public abstract int getCellCount(); + // 获取模板悬浮元素个数 public abstract int getFloatCount(); + // 获取模板聚合块个数 public abstract int getBlockCount(); + // 获取模板控件数 public abstract int getWidgetCount(); + + //是否是测试模板 + public abstract boolean isTestTemplate(); + + //是否使用参数面板 + public abstract boolean useParaPane(); + + //获取组件信息 + public abstract JSONArray getComponentsInfo(); + + + + protected boolean isTestCell(Object value, Style style) { + if (value instanceof ChartCollection && isTestChartCollection((ChartCollection) value)) { + return true; + } + if (value == null && Style.getInstance().equals(style)) { + return true; + } + return false; + } + + protected boolean isTestChartCollection(ChartCollection chartCollection) { + int chartCount = chartCollection.getChartCount(); + if (chartCount == 0) { + return true; + } + for (int i = 0; i < chartCount; i++) { + ChartProvider chart = chartCollection.getChart(i, ChartProvider.class); + if (chart.isTestChart()) { + return true; + } + } + return false; + } + } diff --git a/designer-base/src/test/java/com/fr/design/mainframe/template/info/TemplateInfoCollectorTest.java b/designer-base/src/test/java/com/fr/design/mainframe/template/info/TemplateInfoCollectorTest.java index 3235473c6..73109f340 100644 --- a/designer-base/src/test/java/com/fr/design/mainframe/template/info/TemplateInfoCollectorTest.java +++ b/designer-base/src/test/java/com/fr/design/mainframe/template/info/TemplateInfoCollectorTest.java @@ -1,14 +1,16 @@ package com.fr.design.mainframe.template.info; import com.fr.config.MarketConfig; -import com.fr.general.GeneralUtils; +import com.fr.design.DesignerEnvManager; import com.fr.invoke.Reflect; +import com.fr.json.JSONArray; import com.fr.json.JSONObject; import com.fr.stable.ProductConstants; import com.fr.stable.StringUtils; import com.fr.third.org.apache.commons.io.FileUtils; import org.easymock.EasyMock; import org.junit.After; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -29,7 +31,7 @@ import static org.junit.Assert.assertTrue; * Created by plough on 2019/4/18. */ @RunWith(PowerMockRunner.class) -@PrepareForTest({ProductConstants.class, MarketConfig.class, ProductConstants.class, GeneralUtils.class}) +@PrepareForTest({ProductConstants.class, MarketConfig.class, DesignerEnvManager.class}) public class TemplateInfoCollectorTest { private String filePath; private String initialFileContent; @@ -51,6 +53,9 @@ public class TemplateInfoCollectorTest { EasyMock.expect(mockProcessInfo.getFloatCount()).andReturn(1).anyTimes(); EasyMock.expect(mockProcessInfo.getReportType()).andReturn(0).anyTimes(); EasyMock.expect(mockProcessInfo.getWidgetCount()).andReturn(0).anyTimes(); + EasyMock.expect(mockProcessInfo.useParaPane()).andReturn(false).anyTimes(); + EasyMock.expect(mockProcessInfo.getComponentsInfo()).andReturn(new JSONArray()).anyTimes(); + EasyMock.expect(mockProcessInfo.isTestTemplate()).andReturn(true).anyTimes(); EasyMock.replay(mockProcessInfo); // 缓存 tpl.info @@ -72,36 +77,36 @@ public class TemplateInfoCollectorTest { assertEquals(",,", DesignerOpenHistory.getInstance().toString()); TemplateInfoCollector collector = TemplateInfoCollector.getInstance(); - assertEquals(7, ((Map) Reflect.on(collector).field("pointInfoMap").get()).size()); - assertEquals("2019-04-08,2019-04-03,2019-03-29", DesignerOpenHistory.getInstance().toString()); + assertEquals("2020-05-07,2020-05-06,2020-04-30", DesignerOpenHistory.getInstance().toString()); } @Test - public void testCollectInfo() { + public void testCollectInfo() throws Exception { + setUpMockForNewInstance(); TemplateInfoCollector collector = TemplateInfoCollector.getInstance(); - String templateID = "16a988ce-8529-42f5-b17c-2ee849355071"; + String templateID = "e5d7dbb2-d1df-43d4-b974-67acb5ecbffa"; int timeConsume = 200; collector.collectInfo(templateID, StringUtils.EMPTY, mockProcessInfo, timeConsume); // 检查是否写入成功 Reflect.on(collector).call("loadFromFile"); - TemplateInfo templateInfo = collector.getOrCreateTemplateInfoByID(templateID); + TemplateInfo templateInfo = getTemplateInfoByID(templateID); Map consumingMap = Reflect.on(templateInfo).field("consumingMap").get(); Map processMap = Reflect.on(templateInfo).field("processMap").get(); assertJsonStringEquals("{\"process\":\"\",\"float_count\":1,\"widget_count\":0," + - "\"cell_count\":13,\"block_count\":3,\"report_type\":0," + - "\"templateID\":\"16a988ce-8529-42f5-b17c-2ee849355071\"}", new JSONObject(processMap).toString()); - - assertJsonStringEquals("{\"activitykey\":\"2e0ea413-fa9c241e0-9723-4354fce51e81\"," + - "\"jar_time\":\"不是安装版本\",\"create_time\":\"2019-03-26 16:13\"," + - "\"templateID\":\"16a988ce-8529-42f5-b17c-2ee849355071\",\"originID\":\"\"," + - "\"uuid\":\"476ca2cc-f789-4c5d-8e89-ef146580775c\",\"time_consume\":329,\"originTime\":0," + - "\"version\":\"10.0\",\"username\":\"plough\"}", new JSONObject(consumingMap).toString()); + "\"cell_count\":13,\"paraApply\":0,\"block_count\":3,\"report_type\":0,\"components_info\":\"[]\"," + + "\"templateID\":\"e5d7dbb2-d1df-43d4-b974-67acb5ecbffa\"}", + new JSONObject(processMap).toString()); + + Assert.assertEquals(71113, consumingMap.get("uid")); + Assert.assertEquals("2020-05-07 17:25", consumingMap.get("create_time")); + Assert.assertEquals("e5d7dbb2-d1df-43d4-b974-67acb5ecbffa", consumingMap.get("templateID")); + Assert.assertEquals("6b6699ff-ec63-43b0-9deb-b580a5f10411", consumingMap.get("uuid")); } @Test @@ -110,7 +115,7 @@ public class TemplateInfoCollectorTest { TemplateInfoCollector collector = TemplateInfoCollector.getInstance(); - String templateID = "73a97777-8jnk-47cd-b57c-2ee89991279796"; + String templateID = "e5d7dbb2-d1df-43d4-b974-67acb5ecbffa"; int timeConsume = 200; collector.collectInfo(templateID, StringUtils.EMPTY, mockProcessInfo, timeConsume); @@ -119,20 +124,20 @@ public class TemplateInfoCollectorTest { Reflect.on(collector).call("loadFromFile"); assertTrue(collector.contains(templateID)); - TemplateInfo templateInfo = collector.getOrCreateTemplateInfoByID(templateID); + TemplateInfo templateInfo = getTemplateInfoByID(templateID); Map processMap = Reflect.on(templateInfo).field("processMap").get(); assertEquals(templateID, templateInfo.getTemplateID()); assertJsonStringEquals("{\"process\":\"\",\"float_count\":1,\"widget_count\":0," + - "\"cell_count\":13,\"block_count\":3,\"report_type\":0," + - "\"templateID\":\"73a97777-8jnk-47cd-b57c-2ee89991279796\"}", new JSONObject(processMap).toString()); + "\"cell_count\":13,\"paraApply\":0,\"block_count\":3,\"report_type\":0,\"components_info\":\"[]\"," + + "\"templateID\":\"e5d7dbb2-d1df-43d4-b974-67acb5ecbffa\"}", new JSONObject(processMap).toString()); Map consumingMap = Reflect.on(templateInfo).field("consumingMap").get(); - assertEquals(templateID, consumingMap.get("templateID")); - assertEquals(StringUtils.EMPTY, consumingMap.get("originID")); - assertEquals(200, consumingMap.get("time_consume")); - assertEquals(0, consumingMap.get("originTime")); + Assert.assertEquals(71113, consumingMap.get("uid")); + Assert.assertEquals("2020-05-07 17:25", consumingMap.get("create_time")); + Assert.assertEquals("e5d7dbb2-d1df-43d4-b974-67acb5ecbffa", consumingMap.get("templateID")); + Assert.assertEquals("6b6699ff-ec63-43b0-9deb-b580a5f10411", consumingMap.get("uuid")); } @Test @@ -141,7 +146,7 @@ public class TemplateInfoCollectorTest { TemplateInfoCollector collector = TemplateInfoCollector.getInstance(); - String templateID = "423238d4-5223-22vj-vlsj-42jc49245iw3"; + String templateID = "e5d7dbb2-d1df-43d4-b974-67acb5ecbffa"; String originID = "16a988ce-8529-42f5-b17c-2ee849355071"; int timeConsume = 200; @@ -149,18 +154,19 @@ public class TemplateInfoCollectorTest { // 检查是否写入成功 Reflect.on(collector).call("loadFromFile"); - TemplateInfo templateInfo = collector.getOrCreateTemplateInfoByID(templateID); + TemplateInfo templateInfo = getTemplateInfoByID(templateID); Map processMap = Reflect.on(templateInfo).field("processMap").get(); - assertJsonStringEquals("{\"process\":\"\",\"float_count\":1,\"widget_count\":0," + - "\"cell_count\":13,\"block_count\":3,\"report_type\":0," + - "\"templateID\":\"423238d4-5223-22vj-vlsj-42jc49245iw3\"}", new JSONObject(processMap).toString()); + assertJsonStringEquals("{\"process\":\"\",\"float_count\":1,\"widget_count\":0,\"cell_count\":13," + + "\"paraApply\":0,\"block_count\":3,\"report_type\":0,\"components_info\":\"[]\"," + + "\"templateID\":\"e5d7dbb2-d1df-43d4-b974-67acb5ecbffa\"}", new JSONObject(processMap).toString()); Map consumingMap = Reflect.on(templateInfo).field("consumingMap").get(); - assertEquals(templateID, consumingMap.get("templateID")); - assertEquals(originID, consumingMap.get("originID")); - assertEquals(329, consumingMap.get("time_consume")); - assertEquals(129, consumingMap.get("originTime")); + Assert.assertEquals(71113, consumingMap.get("uid")); + Assert.assertEquals("2020-05-07 17:25", consumingMap.get("create_time")); + Assert.assertEquals("e5d7dbb2-d1df-43d4-b974-67acb5ecbffa", consumingMap.get("templateID")); + Assert.assertEquals("6b6699ff-ec63-43b0-9deb-b580a5f10411", consumingMap.get("uuid")); + Assert.assertEquals("16a988ce-8529-42f5-b17c-2ee849355071", consumingMap.get("originID")); } @Test @@ -169,36 +175,71 @@ public class TemplateInfoCollectorTest { TemplateInfoCollector collector = TemplateInfoCollector.getInstance(); - String templateID = "423238d4-5223-22vj-vlsj-42jc49245iw3"; + String templateID = "e5d7dbb2-d1df-43d4-b974-67acb5ecbffa"; String originID = "3kha8jcs-31xw-42f5-h2ww-2ee84935312z"; int timeConsume = 200; collector.collectInfo(templateID, originID, mockProcessInfo, timeConsume); - TemplateInfo templateInfo = collector.getOrCreateTemplateInfoByID(templateID); + TemplateInfo templateInfo = getTemplateInfoByID(templateID); assertEquals(templateID, templateInfo.getTemplateID()); - assertEquals(originID, templateInfo.getOriginID()); Map consumingMap = Reflect.on(templateInfo).field("consumingMap").get(); - assertEquals(templateID, consumingMap.get("templateID")); - assertEquals(originID, consumingMap.get("originID")); - assertEquals(200, consumingMap.get("time_consume")); - assertEquals(0, consumingMap.get("originTime")); + Assert.assertEquals(71113, consumingMap.get("uid")); + Assert.assertEquals("2020-05-07 17:25", consumingMap.get("create_time")); + Assert.assertEquals("e5d7dbb2-d1df-43d4-b974-67acb5ecbffa", consumingMap.get("templateID")); + Assert.assertEquals("6b6699ff-ec63-43b0-9deb-b580a5f10411", consumingMap.get("uuid")); + Assert.assertEquals("3kha8jcs-31xw-42f5-h2ww-2ee84935312z", consumingMap.get("originID")); } @Test public void testAddIdleDateCount() { - String templateID = "16a988ce-8529-42f5-b17c-2ee849355071"; + String templateID = "e5d7dbb2-d1df-43d4-b974-67acb5ecbffa"; TemplateInfoCollector collecter = TemplateInfoCollector.getInstance(); - TemplateInfo templateInfo = collecter.getOrCreateTemplateInfoByID(templateID); + TemplateInfo templateInfo = getTemplateInfoByID(templateID); - assertEquals(9, templateInfo.getIdleDayCount()); + assertEquals(0, templateInfo.getIdleDayCount()); Reflect.on(collecter).call("addIdleDayCount"); - assertEquals(10, templateInfo.getIdleDayCount()); + assertEquals(1, templateInfo.getIdleDayCount()); // 同一天内多次调用无效 Reflect.on(collecter).call("addIdleDayCount"); - assertEquals(10, templateInfo.getIdleDayCount()); + assertEquals(1, templateInfo.getIdleDayCount()); + } + + @Test + public void testContains() { + TemplateInfoCollector collector = TemplateInfoCollector.getInstance(); + String templateID1 = "e5d7dbb2-d1df-43d4-b974-67acb5ecbffa"; + Assert.assertTrue(collector.contains(templateID1)); + String templateID2 = "e5d7dbb2-d1df-43d4-b974-67acb5ecbffb"; + Assert.assertFalse(collector.contains(templateID2)); + } + + @Test + public void testGetTemplateCreateTime() throws Exception { + setUpMockForNewInstance(); + TemplateInfoCollector collector = TemplateInfoCollector.getInstance(); + String templateID = "e5d7dbb2-d1df-43d4-b974-67acb5ecbffa"; + String createTime = Reflect.on(collector).call("getTemplateCreateTime", templateID).get(); + Assert.assertEquals("2020-05-07 17:25", createTime); + + templateID = "2521d03c-b238-41a5-9a1d-2498efff3a97"; + createTime = Reflect.on(collector).call("getTemplateCreateTime", templateID).get(); + Assert.assertEquals("2020-05-07 17:45", createTime); + } + + + private TemplateInfo getTemplateInfoByID(String templateID) { + TemplateInfoCollector collector = TemplateInfoCollector.getInstance(); + Map latestTemplateInfo = Reflect.on(collector).field("latestTemplateInfo").get(); + Map pointInfoMap = Reflect.on(collector).field("pointInfoMap").get(); + if (latestTemplateInfo.containsKey(templateID)) { + long latestSaveTime = latestTemplateInfo.get(templateID); + return pointInfoMap.get(templateID + "_" + latestSaveTime); + } else { + return TemplateInfo.newInstance(templateID); + } } } diff --git a/designer-base/src/test/java/com/fr/design/mainframe/template/info/TemplateInfoTest.java b/designer-base/src/test/java/com/fr/design/mainframe/template/info/TemplateInfoTest.java index 7f0ddd0bc..cf2fff3be 100644 --- a/designer-base/src/test/java/com/fr/design/mainframe/template/info/TemplateInfoTest.java +++ b/designer-base/src/test/java/com/fr/design/mainframe/template/info/TemplateInfoTest.java @@ -1,13 +1,13 @@ package com.fr.design.mainframe.template.info; import com.fr.config.MarketConfig; -import com.fr.general.GeneralUtils; +import com.fr.design.DesignerEnvManager; import com.fr.invoke.Reflect; import com.fr.json.JSONObject; -import com.fr.stable.ProductConstants; import com.fr.stable.StringUtils; import com.fr.stable.xml.XMLableReader; import com.fr.third.javax.xml.stream.XMLStreamException; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -25,17 +25,17 @@ import static org.junit.Assert.assertEquals; * Created by plough on 2019/4/19. */ @RunWith(PowerMockRunner.class) -@PrepareForTest({MarketConfig.class, ProductConstants.class, GeneralUtils.class}) +@PrepareForTest({MarketConfig.class, DesignerEnvManager.class}) public class TemplateInfoTest { - private static final String NORMAL_INFO = "\n" + - "\n" + - "\n" + + private static final String NORMAL_INFO = "\n" + + "\n" + + "\n" + ""; - private static final String SAVE_AS_INFO = "\n" + - "\n" + - "\n" + + private static final String SAVE_AS_INFO = "\n" + + "\n" + + "\n" + ""; private TemplateInfo templateInfo; @@ -56,15 +56,14 @@ public class TemplateInfoTest { assertEquals(templateID, templateInfo.getTemplateID()); assertEquals(StringUtils.EMPTY, Reflect.on(templateInfo).field("originID").get()); assertEquals(0, (int) Reflect.on(templateInfo).field("idleDayCount").get()); + assertEquals(false, templateInfo.isTestTemplate()); Map consumingMap = Reflect.on(templateInfo).field("consumingMap").get(); assertEquals(templateID, consumingMap.get("templateID")); - assertEquals(0, consumingMap.get("originTime")); assertEquals(StringUtils.EMPTY, consumingMap.get("originID")); - assertEquals(0, consumingMap.get("time_consume")); - assertEquals("不是安装版本", consumingMap.get("jar_time")); - assertEquals("plough", consumingMap.get("username")); - assertEquals("10.0", consumingMap.get("version")); + assertEquals("6b6699ff-ec63-43b0-9deb-b580a5f10411", consumingMap.get("uuid")); + assertEquals(71113, consumingMap.get("uid")); + assertEquals(StringUtils.EMPTY, consumingMap.get("saveRecord")); } @Test @@ -73,26 +72,27 @@ public class TemplateInfoTest { String templateID = "24121212-u2c8-ncd2-82nx-8ud0i8138888"; String originID = "24avc8n2-1iq8-iuj2-wx24-8yy0i8132302"; - int originTime = 100; - TemplateInfo templateInfo = TemplateInfo.newInstance(templateID, originID, originTime); + String saveRecord = "{\"time\";:1588843629000,\"consume\":81}"; + String createTime = "2020-05-07 17:25"; + TemplateInfo templateInfo = TemplateInfo.newInstance(templateID, originID, saveRecord, createTime); assertEquals(templateID, templateInfo.getTemplateID()); assertEquals(originID, Reflect.on(templateInfo).field("originID").get()); assertEquals(0, (int) Reflect.on(templateInfo).field("idleDayCount").get()); + assertEquals(false, templateInfo.isTestTemplate()); Map consumingMap = Reflect.on(templateInfo).field("consumingMap").get(); assertEquals(templateID, consumingMap.get("templateID")); - assertEquals(originTime, consumingMap.get("originTime")); assertEquals(originID, consumingMap.get("originID")); - assertEquals(originTime, consumingMap.get("time_consume")); - assertEquals("不是安装版本", consumingMap.get("jar_time")); - assertEquals("plough", consumingMap.get("username")); - assertEquals("10.0", consumingMap.get("version")); + assertEquals("6b6699ff-ec63-43b0-9deb-b580a5f10411", consumingMap.get("uuid")); + assertEquals(71113, consumingMap.get("uid")); + assertEquals(saveRecord, consumingMap.get("saveRecord")); + assertEquals(createTime, consumingMap.get("create_time")); } @Test public void testGetTemplateID() { - assertEquals("16a988ce-8529-42f5-b17c-2ee849355071", templateInfo.getTemplateID()); - assertEquals("49avd2c4-1104-92j2-wx24-3dd0k2136080", templateInfoSaveAs.getTemplateID()); + assertEquals("aac1139e-018b-4481-867a-a18fc6d6f3e6", templateInfo.getTemplateID()); + assertEquals("2521d03c-b238-41a5-9a1d-2498efff3a97", templateInfoSaveAs.getTemplateID()); } @Test @@ -102,19 +102,21 @@ public class TemplateInfoTest { Map processMap = Reflect.on(templateInfo).field("processMap").get(); Map consumingMap1 = Reflect.on(templateInfoSaveAs).field("consumingMap").get(); Map processMap1 = Reflect.on(templateInfoSaveAs).field("processMap").get(); - assertJsonStringEquals("{\"activitykey\":\"2e0ea413-fa9c241e0-9723-4354fce51e81\",\"jar_time\":\"不是安装版本\"," + - "\"create_time\":\"2019-03-26 16:13\",\"templateID\":\"16a988ce-8529-42f5-b17c-2ee849355071\",\"originID\":\"\"," + - "\"uuid\":\"476ca2cc-f789-4c5d-8e89-ef146580775c\",\"time_consume\":129,\"originTime\":0,\"version\":\"10.0\"," + - "\"username\":\"plough\"}", new JSONObject(consumingMap).toString()); - - assertJsonStringEquals("{\"activitykey\":\"2e0ea413-fa9c241e0-9723-4354fce51e81\",\"jar_time\":\"不是安装版本\"," + - "\"create_time\":\"2019-03-26 16:13\",\"templateID\":\"49avd2c4-1104-92j2-wx24-3dd0k2136080\",\"originID\":\"16a988ce-8529-42f5-b17c-2ee849355071\"," + - "\"uuid\":\"476ca2cc-f789-4c5d-8e89-ef146580775c\",\"time_consume\":429,\"originTime\":129,\"version\":\"10.0\"," + - "\"username\":\"plough\"}", new JSONObject(consumingMap1).toString()); - assertJsonStringEquals("{\"process\":\"\",\"float_count\":0,\"widget_count\":0,\"cell_count\":1," + - "\"block_count\":0,\"report_type\":0,\"templateID\":\"16a988ce-8529-42f5-b17c-2ee849355071\"}", new JSONObject(processMap).toString()); - assertJsonStringEquals("{\"process\":\"\",\"float_count\":0,\"widget_count\":0,\"cell_count\":1," + - "\"block_count\":0,\"report_type\":0,\"templateID\":\"49avd2c4-1104-92j2-wx24-3dd0k2136080\"}", new JSONObject(processMap1).toString()); + assertJsonStringEquals("{\"uid\":71113,\"originID\":\"\",\"create_time\":\"2020-05-07 17:28\"," + + "\"saveRecord\":\"{\\\"time\\\":1588843693000,\\\"consume\\\":4}\"," + + "\"templateID\":\"aac1139e-018b-4481-867a-a18fc6d6f3e6\"," + + "\"uuid\":\"6b6699ff-ec63-43b0-9deb-b580a5f10411\"}", new JSONObject(consumingMap).toString()); + + assertJsonStringEquals("{\"uid\":71113,\"originID\":\"aac1139e-018b-4481-867a-a18fc6d6f3e6\"," + + "\"create_time\":\"2020-05-07 17:45\",\"saveRecord\":\"{\\\"time\\\":1588844751000,\\\"consume\\\":1058}\"," + + "\"templateID\":\"2521d03c-b238-41a5-9a1d-2498efff3a97\"," + + "\"uuid\":\"6b6699ff-ec63-43b0-9deb-b580a5f10411\"}", new JSONObject(consumingMap1).toString()); + assertJsonStringEquals("{\"process\":\"\",\"float_count\":0,\"widget_count\":0,\"cell_count\":3," + + "\"paraApply\":0,\"block_count\":0,\"report_type\":0,\"components_info\":\"[]\"," + + "\"templateID\":\"aac1139e-018b-4481-867a-a18fc6d6f3e6\"}", new JSONObject(processMap).toString()); + assertJsonStringEquals("{\"process\":\"\",\"float_count\":0,\"widget_count\":0,\"cell_count\":3," + + "\"paraApply\":0,\"block_count\":0,\"report_type\":0,\"components_info\":\"[]\"," + + "\"templateID\":\"2521d03c-b238-41a5-9a1d-2498efff3a97\"}", new JSONObject(processMap1).toString()); } private TemplateInfo createTemplateInfo(String xmlContent) throws XMLStreamException { @@ -122,4 +124,18 @@ public class TemplateInfoTest { XMLableReader xmlReader = XMLableReader.createXMLableReader(sr); return TemplateInfo.newInstanceByRead(xmlReader); } + + @Test + public void testGetSaveTime(){ + Map consumingMap = Reflect.on(templateInfo).field("consumingMap").get(); + String saveRecord = (String) consumingMap.get("saveRecord"); + JSONObject object = new JSONObject(saveRecord); + Assert.assertEquals(1588843693000L, object.optLong("time")); + } + + @Test + public void testGetTemplateCreateTime(){ + Map consumingMap = Reflect.on(templateInfo).field("consumingMap").get(); + Assert.assertEquals("2020-05-07 17:28", (String)consumingMap.get("create_time")); + } } diff --git a/designer-base/src/test/java/com/fr/design/mainframe/template/info/TemplateInfoTestHelper.java b/designer-base/src/test/java/com/fr/design/mainframe/template/info/TemplateInfoTestHelper.java index be2b58989..8ba027872 100644 --- a/designer-base/src/test/java/com/fr/design/mainframe/template/info/TemplateInfoTestHelper.java +++ b/designer-base/src/test/java/com/fr/design/mainframe/template/info/TemplateInfoTestHelper.java @@ -1,10 +1,10 @@ package com.fr.design.mainframe.template.info; +import com.fr.config.BBSAttr; import com.fr.config.MarketConfig; +import com.fr.design.DesignerEnvManager; import com.fr.general.ComparatorUtils; -import com.fr.general.GeneralUtils; import com.fr.json.JSONObject; -import com.fr.stable.ProductConstants; import org.easymock.EasyMock; import org.powermock.api.easymock.PowerMock; @@ -33,17 +33,21 @@ class TemplateInfoTestHelper { static void setUpMockForNewInstance() throws Exception { MarketConfig mockMarketConfig = EasyMock.mock(MarketConfig.class); - EasyMock.expect(mockMarketConfig.getBbsUsername()).andReturn("plough").anyTimes(); + BBSAttr bbsAttr = EasyMock.mock(BBSAttr.class); + EasyMock.expect(bbsAttr.getBbsUid()).andReturn(71113).anyTimes(); + EasyMock.expect(mockMarketConfig.getBBSAttr()).andReturn(bbsAttr).anyTimes(); PowerMock.mockStatic(MarketConfig.class); EasyMock.expect(MarketConfig.getInstance()).andReturn(mockMarketConfig).anyTimes(); - PowerMock.mockStatic(GeneralUtils.class); - EasyMock.expect(GeneralUtils.readBuildNO()).andReturn("不是安装版本").anyTimes(); + PowerMock.mockStatic(DesignerEnvManager.class); + DesignerEnvManager envManager = EasyMock.mock( DesignerEnvManager.class); + EasyMock.expect(envManager.getUUID()).andReturn("6b6699ff-ec63-43b0-9deb-b580a5f10411").anyTimes(); + EasyMock.expect(envManager.isJoinProductImprove()).andReturn(true).anyTimes(); + EasyMock.expect(DesignerEnvManager.getEnvManager()).andReturn(envManager).anyTimes(); + EasyMock.replay(mockMarketConfig, bbsAttr, envManager); - setFinalStatic(ProductConstants.class.getDeclaredField("VERSION"), "10.0"); - EasyMock.replay(mockMarketConfig); PowerMock.replayAll(); } } diff --git a/designer-base/src/test/resources/com/fr/design/mainframe/template/info/tpl.info b/designer-base/src/test/resources/com/fr/design/mainframe/template/info/tpl.info index eae77630f..ff65b74e9 100644 --- a/designer-base/src/test/resources/com/fr/design/mainframe/template/info/tpl.info +++ b/designer-base/src/test/resources/com/fr/design/mainframe/template/info/tpl.info @@ -1,35 +1,35 @@ - + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + diff --git a/designer-form/src/main/java/com/fr/design/designer/beans/models/SelectionModel.java b/designer-form/src/main/java/com/fr/design/designer/beans/models/SelectionModel.java index 052ae0539..33312483e 100644 --- a/designer-form/src/main/java/com/fr/design/designer/beans/models/SelectionModel.java +++ b/designer-form/src/main/java/com/fr/design/designer/beans/models/SelectionModel.java @@ -10,6 +10,7 @@ import com.fr.design.designer.creator.*; import com.fr.design.designer.creator.cardlayout.XWCardLayout; import com.fr.design.designer.creator.cardlayout.XWCardMainBorderLayout; import com.fr.design.designer.creator.cardlayout.XWTabFitLayout; +import com.fr.design.form.util.FormDesignerUtils; import com.fr.design.form.util.XCreatorConstants; import com.fr.design.mainframe.FormDesigner; import com.fr.design.mainframe.FormSelection; @@ -261,8 +262,11 @@ public class SelectionModel { creator.removeAll(); // 清除被选中的组件 selection.reset(); + FormDesignerUtils.removeWidgetProcessInfo(creator.toData()); } + + setSelectedCreator(isInPara ? designer.getParaComponent() : designer.getRootComponent()); // 触发事件 designer.getEditListenerTable().fireCreatorModified(DesignerEvent.CREATOR_DELETED); diff --git a/designer-form/src/main/java/com/fr/design/form/util/FormDesignerUtils.java b/designer-form/src/main/java/com/fr/design/form/util/FormDesignerUtils.java index d976816f5..532f04c16 100644 --- a/designer-form/src/main/java/com/fr/design/form/util/FormDesignerUtils.java +++ b/designer-form/src/main/java/com/fr/design/form/util/FormDesignerUtils.java @@ -1,8 +1,14 @@ package com.fr.design.form.util; +import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.mainframe.FormDesigner; +import com.fr.design.mainframe.JForm; +import com.fr.design.mainframe.JTemplate; +import com.fr.form.ui.Widget; import com.fr.form.ui.container.WFitLayout; +import java.util.UUID; + public class FormDesignerUtils { /** * body布局是否设置了手机重布局 @@ -25,4 +31,20 @@ public class FormDesignerUtils { return root.getBodyLayoutType() == com.fr.form.ui.container.WBodyLayoutType.ABSOLUTE; } -} \ No newline at end of file + + public static void addWidgetProcessInfo(Widget widget) { + JTemplate jTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); + if (jTemplate instanceof JForm) { + widget.setWidgetID(UUID.randomUUID().toString()); + ((JForm) jTemplate).addWidgetProcessInfo(widget); + } + } + + public static void removeWidgetProcessInfo(Widget widget) { + JTemplate jTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); + if (jTemplate instanceof JForm) { + ((JForm) jTemplate).removeWidgetProcessInfo(widget); + } + } + +} diff --git a/designer-form/src/main/java/com/fr/design/mainframe/JForm.java b/designer-form/src/main/java/com/fr/design/mainframe/JForm.java index 5502274bc..ac237848a 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/JForm.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/JForm.java @@ -133,6 +133,13 @@ public class JForm extends JTemplate implements BaseJForm implements BaseJForm { + + private static final String REGEX = "^" + com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Title") + "\\d+$"; + + private static final Pattern PATTERN = Pattern.compile(REGEX); + + private Map componentProcessInfoMap = new ConcurrentHashMap(); + public JFormProcessInfo(Form form) { super(form); } @@ -20,14 +43,17 @@ public class JFormProcessInfo extends TemplateProcessInfo
{ public int getCellCount() { return 0; } + // 获取模板悬浮元素个数 public int getFloatCount() { return 0; } + // 获取模板聚合块个数 public int getBlockCount() { return 0; } + // 获取模板控件数 public int getWidgetCount() { int widgetCount = 0; @@ -37,4 +63,126 @@ public class JFormProcessInfo extends TemplateProcessInfo { } return widgetCount; } + + @Override + public boolean isTestTemplate() { + Iterator it = this.template.getTableDataNameIterator(); + if (!it.hasNext() || getWidgetCount() <= 1 || + hasEmptyParaPane() || hasTestAbsolutePane() + || hasTestTabLayout() || hasTestECReport() || hasTestChart()) { + return true; + } + return false; + } + + private boolean hasTestECReport() { + ElementCaseEditorProvider[] elementCaseEditorProviders = this.template.getElementCases(); + for (ElementCaseEditorProvider elementCaseEditorProvider : elementCaseEditorProviders) { + FormElementCaseProvider elementCase = elementCaseEditorProvider.getElementCase(); + Iterator it = elementCase.cellIterator(); + if (!it.hasNext()) { + return true; + } + while (it.hasNext()) { + DefaultTemplateCellElement ce = (DefaultTemplateCellElement) it.next(); + Object value = ce.getValue(); + if (isTestCell(value, ce.getStyle())) { + return true; + } + } + + } + return false; + } + + private boolean hasTestChart() { + final boolean[] hasTestChart = {false}; + Form.traversalWidget(this.template.getContainer(), new WidgetGather() { + @Override + public void dealWith(Widget widget) { + ChartCollection chartCollection = (ChartCollection) ((BaseChartEditor) widget).getChartCollection(); + if (isTestChartCollection(chartCollection)) { + hasTestChart[0] = true; + } + } + + @Override + public boolean dealWithAllCards() { + return true; + } + }, BaseChartEditor.class); + return hasTestChart[0]; + } + + + private boolean hasTestTabLayout() { + final boolean[] hasTestTabLayout = {false}; + Form.traversalWidget(this.template.getContainer(), new WidgetGather() { + @Override + public void dealWith(Widget widget) { + String title = ((CardSwitchButton) widget).getText(); + Matcher matcher = PATTERN.matcher(title); + if (matcher.find()) { + hasTestTabLayout[0] = true; + } + } + + @Override + public boolean dealWithAllCards() { + return true; + } + }, CardSwitchButton.class); + return hasTestTabLayout[0]; + } + + private boolean hasTestAbsolutePane() { + final boolean[] hasTestAbsolutePane = {false}; + Form.traversalWidget(this.template.getContainer(), new WidgetGather() { + @Override + public void dealWith(Widget widget) { + if (((WAbsoluteLayout) widget).getWidgetCount() == 0) { + hasTestAbsolutePane[0] = true; + } + } + + @Override + public boolean dealWithAllCards() { + return true; + } + }, WAbsoluteLayout.class); + return hasTestAbsolutePane[0]; + } + + private boolean hasEmptyParaPane() { + WLayout paraContainer = this.template.getParaContainer(); + return paraContainer != null && paraContainer.getWidgetCount() == 0; + } + + @Override + public boolean useParaPane() { + return this.template.getParaContainer() != null; + } + + @Override + public JSONArray getComponentsInfo() { + JSONArray ja = new JSONArray(); + for (ComponentProcessInfo value : componentProcessInfoMap.values()) { + ja.put(value.toJSONObject()); + } + this.componentProcessInfoMap.clear(); + return ja; + } + + public void addComponentCreateInfo(Widget widget) { + componentProcessInfoMap.put(widget.getWidgetID(), new ComponentProcessInfo(widget, System.currentTimeMillis())); + } + + public void addComponentRemoveInfo(Widget widget) { + ComponentProcessInfo info = componentProcessInfoMap.get(widget.getWidgetID()); + if (info == null) { + info = new ComponentProcessInfo(widget); + componentProcessInfoMap.put(widget.getWidgetID(), info); + } + info.updateDeleteTime(System.currentTimeMillis()); + } } diff --git a/designer-form/src/test/java/com/fr/design/mainframe/template/info/ComponentProcessInfoTest.java b/designer-form/src/test/java/com/fr/design/mainframe/template/info/ComponentProcessInfoTest.java new file mode 100644 index 000000000..abed86959 --- /dev/null +++ b/designer-form/src/test/java/com/fr/design/mainframe/template/info/ComponentProcessInfoTest.java @@ -0,0 +1,39 @@ +package com.fr.design.mainframe.template.info; + +import com.fr.form.ui.ChartEditor; +import com.fr.form.ui.ElementCaseEditor; +import com.fr.form.ui.FreeButton; +import com.fr.form.ui.Widget; +import com.fr.form.ui.container.WAbsoluteLayout; +import com.fr.form.ui.container.WCardLayout; +import com.fr.json.JSONObject; +import org.junit.Assert; +import org.junit.Test; + +/** + * Created by kerry on 2020-05-08 + */ +public class ComponentProcessInfoTest { + @Test + public void testToJSONObject() { + Widget button = new FreeButton(); + button.setWidgetName("button1"); + button.setWidgetID("xxxxxxx"); + ComponentProcessInfo info = new ComponentProcessInfo(button); + JSONObject jo = info.toJSONObject(); + Assert.assertEquals("xxxxxxx", jo.optString("componentID")); + Assert.assertEquals("button1", jo.optString("componentName")); + Assert.assertEquals("Widget", jo.optString("componentType")); + Assert.assertEquals("0", jo.optString("createTime")); + Assert.assertEquals("0", jo.optString("deleteTime")); + } + + @Test + public void testComponentType() { + Assert.assertEquals(ComponentProcessInfo.ComponentType.Widget, ComponentProcessInfo.ComponentType.parseType(new FreeButton())); + Assert.assertEquals(ComponentProcessInfo.ComponentType.Report, ComponentProcessInfo.ComponentType.parseType(new ElementCaseEditor())); + Assert.assertEquals(ComponentProcessInfo.ComponentType.Chart, ComponentProcessInfo.ComponentType.parseType(new ChartEditor())); + Assert.assertEquals(ComponentProcessInfo.ComponentType.Absolute, ComponentProcessInfo.ComponentType.parseType(new WAbsoluteLayout())); + Assert.assertEquals(ComponentProcessInfo.ComponentType.TabLayout, ComponentProcessInfo.ComponentType.parseType(new WCardLayout())); + } +} diff --git a/designer-form/src/test/java/com/fr/design/mainframe/template/info/JFormProcessInfoTest.java b/designer-form/src/test/java/com/fr/design/mainframe/template/info/JFormProcessInfoTest.java new file mode 100644 index 000000000..ee366cc7d --- /dev/null +++ b/designer-form/src/test/java/com/fr/design/mainframe/template/info/JFormProcessInfoTest.java @@ -0,0 +1,149 @@ +package com.fr.design.mainframe.template.info; + +import com.fr.chart.chartattr.ChartCollection; +import com.fr.form.main.Form; +import com.fr.form.ui.CardSwitchButton; +import com.fr.form.ui.ChartEditor; +import com.fr.form.ui.ElementCaseEditor; +import com.fr.form.ui.FreeButton; +import com.fr.form.ui.container.WAbsoluteLayout; +import com.fr.form.ui.container.WBorderLayout; +import com.fr.form.ui.container.WCardLayout; +import com.fr.form.ui.container.WFitLayout; +import com.fr.form.ui.container.WParameterLayout; +import com.fr.form.ui.container.cardlayout.WCardTagLayout; +import com.fr.invoke.Reflect; +import com.fr.json.JSONArray; +import com.fr.plugin.chart.vanchart.VanChart; +import com.fr.report.cell.DefaultTemplateCellElement; +import com.fr.report.worksheet.FormElementCase; +import org.junit.Assert; +import org.junit.Test; + +/** + * Created by kerry on 2020-05-08 + */ +public class JFormProcessInfoTest { + @Test + public void testHasTestECReport() { + Form form = new Form(); + WFitLayout wFitLayout = new WFitLayout(); + ElementCaseEditor editor = new ElementCaseEditor(); + FormElementCase elementCase = new FormElementCase(); + editor.setElementCase(elementCase); + wFitLayout.addWidget(editor); + form.setContainer(wFitLayout); + JFormProcessInfo jFormProcessInfo = new JFormProcessInfo(form); + boolean result1 = Reflect.on(jFormProcessInfo).call("hasTestECReport").get(); + Assert.assertTrue(result1); + + elementCase.addCellElement(new DefaultTemplateCellElement()); + boolean result2 = Reflect.on(jFormProcessInfo).call("hasTestECReport").get(); + Assert.assertTrue(result2); + } + + @Test + public void testHasTestChart() { + Form form = new Form(); + WFitLayout wFitLayout = new WFitLayout(); + ChartEditor editor = new ChartEditor(); + ChartCollection collection = new ChartCollection(); + editor.resetChangeChartCollection(collection); + wFitLayout.addWidget(editor); + form.setContainer(wFitLayout); + JFormProcessInfo jFormProcessInfo = new JFormProcessInfo(form); + boolean result1 = Reflect.on(jFormProcessInfo).call("hasTestChart").get(); + Assert.assertTrue(result1); + + collection.addChart(new VanChart()); + boolean result2 = Reflect.on(jFormProcessInfo).call("hasTestChart").get(); + Assert.assertTrue(result2); + + } + + @Test + public void testHasTestTabLayout() { + Form form = new Form(); + WFitLayout wFitLayout = new WFitLayout(); + WCardLayout editor = new WCardLayout(); + wFitLayout.addWidget(editor); + form.setContainer(wFitLayout); + JFormProcessInfo jFormProcessInfo = new JFormProcessInfo(form); + boolean result1 = Reflect.on(jFormProcessInfo).call("hasTestTabLayout").get(); + Assert.assertFalse(result1); + + WCardTagLayout tagLayout = new WCardTagLayout(); + CardSwitchButton button = new CardSwitchButton(); + button.setText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Title") + "0"); + tagLayout.addWidget(button); + editor.addWidget(tagLayout); + boolean result2 = Reflect.on(jFormProcessInfo).call("hasTestTabLayout").get(); + Assert.assertTrue(result2); + + button.setText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Title") + "test"); + boolean result3 = Reflect.on(jFormProcessInfo).call("hasTestTabLayout").get(); + Assert.assertFalse(result3); + + } + + @Test + public void testHasTestAbsolutePane() { + Form form = new Form(); + WFitLayout wFitLayout = new WFitLayout(); + WAbsoluteLayout editor = new WAbsoluteLayout(); + wFitLayout.addWidget(editor); + form.setContainer(wFitLayout); + JFormProcessInfo jFormProcessInfo = new JFormProcessInfo(form); + boolean result1 = Reflect.on(jFormProcessInfo).call("hasTestAbsolutePane").get(); + Assert.assertTrue(result1); + + editor.addWidget(new FreeButton()); + boolean result2 = Reflect.on(jFormProcessInfo).call("hasTestAbsolutePane").get(); + Assert.assertFalse(result2); + } + + @Test + public void testHasEmptyParaPane() { + Form form = new Form(); + WBorderLayout borderLayout = new WBorderLayout(); + form.setContainer(borderLayout); + JFormProcessInfo jFormProcessInfo = new JFormProcessInfo(form); + boolean result1 = Reflect.on(jFormProcessInfo).call("hasEmptyParaPane").get(); + Assert.assertFalse(result1); + + borderLayout.addNorth(new WParameterLayout()); + boolean result2 = Reflect.on(jFormProcessInfo).call("hasEmptyParaPane").get(); + Assert.assertTrue(result2); + } + + @Test + public void testUseParaPane() { + Form form = new Form(); + WBorderLayout borderLayout = new WBorderLayout(); + form.setContainer(borderLayout); + JFormProcessInfo jFormProcessInfo = new JFormProcessInfo(form); + Assert.assertFalse(jFormProcessInfo.useParaPane()); + + borderLayout.addNorth(new WParameterLayout()); + Assert.assertTrue(jFormProcessInfo.useParaPane()); + + } + + @Test + public void testGetComponentsInfo() { + Form form = new Form(); + JFormProcessInfo jFormProcessInfo = new JFormProcessInfo(form); + FreeButton button1 = new FreeButton(); + FreeButton button2 = new FreeButton(); + button1.setWidgetID("xxxx1"); + button2.setWidgetID("xxxx2"); + jFormProcessInfo.addComponentCreateInfo(button1); + jFormProcessInfo.addComponentRemoveInfo(button2); + JSONArray ja = jFormProcessInfo.getComponentsInfo(); + Assert.assertEquals(2, ja.size()); + + + ja = jFormProcessInfo.getComponentsInfo(); + Assert.assertEquals(0, ja.size()); + } +} diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/JPolyWorkBook.java b/designer-realize/src/main/java/com/fr/design/mainframe/JPolyWorkBook.java index b68e49e16..48ddb6a05 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/JPolyWorkBook.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/JPolyWorkBook.java @@ -3,6 +3,8 @@ */ package com.fr.design.mainframe; +import com.fr.design.mainframe.template.info.JPolyWorkBookProcessInfo; +import com.fr.design.mainframe.template.info.TemplateProcessInfo; import com.fr.file.FILEChooserPane; import com.fr.main.impl.WorkBook; import com.fr.report.poly.PolyWorkSheet; @@ -49,4 +51,14 @@ public class JPolyWorkBook extends JWorkBook { protected void addExtraChooseFILEFilter(FILEChooserPane fileChooser) { } + + + @Override + public TemplateProcessInfo getProcessInfo() { + if (processInfo == null) { + processInfo = new JPolyWorkBookProcessInfo(template); + } + return processInfo; + } + } diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/template/info/JPolyWorkBookProcessInfo.java b/designer-realize/src/main/java/com/fr/design/mainframe/template/info/JPolyWorkBookProcessInfo.java new file mode 100644 index 000000000..ec5d05c7f --- /dev/null +++ b/designer-realize/src/main/java/com/fr/design/mainframe/template/info/JPolyWorkBookProcessInfo.java @@ -0,0 +1,77 @@ +package com.fr.design.mainframe.template.info; + +import com.fr.chart.chartattr.ChartCollection; +import com.fr.main.impl.WorkBook; +import com.fr.report.block.Block; +import com.fr.report.poly.PolyChartBlock; +import com.fr.report.poly.PolyWorkSheet; +import com.fr.report.report.Report; + +import java.util.Iterator; + +/** + * Created by kerry on 2020-05-06 + */ +public class JPolyWorkBookProcessInfo extends JWorkBookProcessInfo { + public JPolyWorkBookProcessInfo(WorkBook template) { + super(template); + } + + @Override + public int getReportType() { + return 1; + } + + @Override + public int getCellCount() { + return 0; + } + + @Override + public int getFloatCount() { + return 0; + } + + @Override + public int getBlockCount() { + int blockCount = 0; + if (!template.isElementCaseBook()) { // 如果是聚合报表 + for (int i = 0; i < template.getReportCount(); i++) { + Report report = template.getReport(i); + // 考虑多个sheet下 包含WorkSheet的情况 需要判断下 + if (report instanceof PolyWorkSheet) { + PolyWorkSheet r = (PolyWorkSheet) report; + blockCount += r.getBlockCount(); + } + } + } + return blockCount; + } + + + @Override + public boolean isTestTemplate() { + Iterator it = this.template.getTableDataNameIterator(); + if (!it.hasNext() || getBlockCount() <= 1 || isTestECReport() || isTestChartBlock()) { + return true; + } + return false; + } + + + private boolean isTestChartBlock() { + int count = this.template.getReportCount(); + for (int m = 0; m < count; m++) { + PolyWorkSheet report = (PolyWorkSheet) this.template.getReport(m); + int blockCount = report.getBlockCount(); + for (int i = 0; i < blockCount; i++) { + Block block = report.getBlock(i); + if (block instanceof PolyChartBlock && isTestChartCollection((ChartCollection) ((PolyChartBlock) block).getChartCollection())) { + return true; + } + } + } + return false; + } + +} diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/template/info/JWorkBookProcessInfo.java b/designer-realize/src/main/java/com/fr/design/mainframe/template/info/JWorkBookProcessInfo.java index 85266b7cd..a4b86b189 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/template/info/JWorkBookProcessInfo.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/template/info/JWorkBookProcessInfo.java @@ -1,10 +1,15 @@ package com.fr.design.mainframe.template.info; + +import com.fr.base.Style; import com.fr.base.parameter.ParameterUI; +import com.fr.chart.chartattr.ChartCollection; +import com.fr.json.JSONArray; import com.fr.main.impl.WorkBook; import com.fr.main.parameter.ReportParameterAttr; +import com.fr.report.cell.TemplateCellElement; import com.fr.report.cellcase.CellCase; -import com.fr.report.poly.PolyWorkSheet; +import com.fr.report.elementcase.TemplateElementCase; import com.fr.report.report.Report; import com.fr.report.worksheet.WorkSheet; @@ -34,7 +39,7 @@ public class JWorkBookProcessInfo extends TemplateProcessInfo { for (int j = 0; j < cc.getRowCount(); j++) { Iterator iter = cc.getRow(j); while (iter.hasNext()) { - cellCount ++; + cellCount++; iter.next(); } } @@ -42,6 +47,7 @@ public class JWorkBookProcessInfo extends TemplateProcessInfo { } return cellCount; } + // 获取模板悬浮元素个数 public int getFloatCount() { int chartCount = 0; @@ -50,28 +56,19 @@ public class JWorkBookProcessInfo extends TemplateProcessInfo { WorkSheet r = (WorkSheet) template.getReport(i); Iterator fiter = r.getBlock().floatIterator(); while (fiter.hasNext()) { - chartCount ++; + chartCount++; fiter.next(); } } } return chartCount; } + // 获取模板聚合块个数 public int getBlockCount() { - int blockCount = 0; - if (!template.isElementCaseBook()) { // 如果是聚合报表 - for (int i = 0; i < template.getReportCount(); i++) { - Report report = template.getReport(i); - // 考虑多个sheet下 包含WorkSheet的情况 需要判断下 - if (report instanceof PolyWorkSheet) { - PolyWorkSheet r = (PolyWorkSheet) report; - blockCount += r.getBlockCount(); - } - } - } - return blockCount; + return 0; } + // 获取模板控件数 public int getWidgetCount() { ReportParameterAttr attr = template.getReportParameterAttr(); @@ -82,4 +79,60 @@ public class JWorkBookProcessInfo extends TemplateProcessInfo { ParameterUI pui = attr.getParameterUI(); return pui == null ? 0 : (pui.getAllWidgets().length - 1); } + + @Override + public boolean isTestTemplate() { + Iterator it = this.template.getTableDataNameIterator(); + if (!it.hasNext() || isTestECReport() || getCellCount() <= 5) { + return true; + } + return false; + } + + protected boolean isTestECReport() { + int count = this.template.getReportCount(); + for (int m = 0; m < count; m++) { + Report report = this.template.getReport(m); + Iterator iterator = report.iteratorOfElementCase(); + while (iterator.hasNext()) { + TemplateElementCase templateElementCase = (TemplateElementCase) iterator.next(); + int columnLength = templateElementCase.getColumnCount(); + int rowLength = templateElementCase.getRowCount(); + for (int i = 0; i < columnLength; i++) { + for (int j = 0; j < rowLength; j++) { + TemplateCellElement templateCellElement = templateElementCase.getTemplateCellElement(i, j); + Object value = templateCellElement.getValue(); + if (isTestCell(value, templateCellElement.getStyle())) { + return true; + } + + } + } + } + } + return false; + } + + protected boolean isTestCell(Object value, Style style) { + if (value instanceof ChartCollection && isTestChartCollection((ChartCollection) value)) { + return true; + } + return false; + } + + + @Override + public boolean useParaPane() { + ReportParameterAttr parameterAttr = this.template.getReportParameterAttr(); + if (parameterAttr == null) { + return false; + } + return parameterAttr.getParameterUI() != null; + } + + + @Override + public JSONArray getComponentsInfo() { + return new JSONArray(); + } } diff --git a/designer-realize/src/test/java/com.fr/design/mainframe/template/info/JWorkBookProcessInfoTest.java b/designer-realize/src/test/java/com.fr/design/mainframe/template/info/JWorkBookProcessInfoTest.java new file mode 100644 index 000000000..2629fc462 --- /dev/null +++ b/designer-realize/src/test/java/com.fr/design/mainframe/template/info/JWorkBookProcessInfoTest.java @@ -0,0 +1,49 @@ +package com.fr.design.mainframe.template.info; + +import com.fr.base.Style; +import com.fr.chart.chartattr.ChartCollection; +import com.fr.form.main.parameter.FormParameterUI; +import com.fr.invoke.Reflect; +import com.fr.json.JSONArray; +import com.fr.main.impl.WorkBook; +import com.fr.main.parameter.ReportParameterAttr; +import com.fr.plugin.chart.vanchart.VanChart; +import org.junit.Assert; +import org.junit.Test; + +/** + * Created by kerry on 2020-05-08 + */ +public class JWorkBookProcessInfoTest { + + @Test + public void testIsTestCell() { + ChartCollection chartCollection = new ChartCollection(); + chartCollection.addChart(new VanChart()); + JWorkBookProcessInfo processInfo = new JWorkBookProcessInfo(new WorkBook()); + boolean result = Reflect.on(processInfo).call("isTestCell", chartCollection, Style.getInstance()).get(); + Assert.assertTrue(result); + } + + + @Test + public void testUseParaPane(){ + WorkBook workBook = new WorkBook(); + JWorkBookProcessInfo processInfo = new JWorkBookProcessInfo(workBook); + Assert.assertFalse(processInfo.useParaPane()); + + ReportParameterAttr attr = new ReportParameterAttr(); + workBook.setReportParameterAttr(attr); + Assert.assertFalse(processInfo.useParaPane()); + + attr.setParameterUI(new FormParameterUI()); + Assert.assertTrue(processInfo.useParaPane()); + } + + @Test + public void testGetComponentsInfo() { + JWorkBookProcessInfo processInfo = new JWorkBookProcessInfo(new WorkBook()); + JSONArray ja = processInfo.getComponentsInfo(); + Assert.assertEquals(0, ja.size()); + } +}