From 39e5bcf935f9ccfa3c6ff18ddfec86cb6c8304db Mon Sep 17 00:00:00 2001 From: Harrison Date: Tue, 12 May 2020 14:19:54 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-30889=20=E7=BB=84=E4=BB=B6=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E5=A4=8D=E7=94=A8=E7=9A=84=E5=9F=8B=E7=82=B9=20?= =?UTF-8?q?=E5=9F=8B=E7=82=B9=E8=BF=81=E7=A7=BB=E8=87=B3=E4=B8=BB=20jar=20?= =?UTF-8?q?=E4=B8=AD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mainframe/template/info/TemplateInfo.java | 7 ++++- .../template/info/TemplateProcessInfo.java | 17 ++++++----- .../info/TemplateInfoCollectorTest.java | 29 +++++++++++-------- .../template/info/JFormProcessInfo.java | 28 ++++++++++++++++-- .../template/info/JWorkBookProcessInfo.java | 13 ++++++--- 5 files changed, 68 insertions(+), 26 deletions(-) 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 8faa727fe7..78eddb00f4 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 @@ -10,9 +10,10 @@ import com.fr.json.JSONObject; import com.fr.stable.StringUtils; import com.fr.stable.xml.XMLPrintWriter; import com.fr.stable.xml.XMLableReader; +import com.fr.third.joda.time.DateTime; + import java.util.HashMap; import java.util.Map; -import com.fr.third.joda.time.DateTime; /** * 对应一张模版的记录 @@ -42,6 +43,7 @@ public class TemplateInfo extends AbstractPointInfo { 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 ATTR_REUSE_CMP_LIST = "reuseCmptList"; private static final String TEST_TEMPLATE_FLAG = "test_template"; @@ -148,6 +150,7 @@ public class TemplateInfo extends AbstractPointInfo { 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.attr(ATTR_REUSE_CMP_LIST, (String) processMap.get(ATTR_REUSE_CMP_LIST)); writer.end(); } @@ -179,6 +182,7 @@ public class TemplateInfo extends AbstractPointInfo { 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_REUSE_CMP_LIST, reader.getAttrAsString(ATTR_REUSE_CMP_LIST, StringUtils.EMPTY)); processMap.put(ATTR_TEMPLATE_ID, templateID); } else if (XML_CONSUMING_MAP.equals(name)) { consumingMap.put(ATTR_CREATE_TIME, reader.getAttrAsString(ATTR_CREATE_TIME, StringUtils.EMPTY)); @@ -238,6 +242,7 @@ public class TemplateInfo extends AbstractPointInfo { processMap.put(ATTR_WIDGET_COUNT, processInfo.getWidgetCount()); processMap.put(ATTR_PARA_APPLY, processInfo.useParaPane() ? 1 : 0); processMap.put(ATTR_COMPONENTS_INFO, processInfo.getComponentsInfo().toString()); + processMap.put(ATTR_REUSE_CMP_LIST, processInfo.getReuseCmpList().toString()); this.processMap = processMap; } 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 fc1defcdf8..ea484e5324 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 @@ -35,20 +35,23 @@ public abstract class TemplateProcessInfo { // 获取模板控件数 public abstract int getWidgetCount(); - + //是否是测试模板 public abstract boolean isTestTemplate(); - + //是否使用参数面板 public abstract boolean useParaPane(); - + //获取组件信息 public abstract JSONArray getComponentsInfo(); - - + + //获取重用组件数 + public abstract JSONArray getReuseCmpList(); + + public abstract void updateTemplateOperationInfo(TemplateOperate templateOption); - - + + protected boolean isTestCell(Object value, Style style) { if (value instanceof ChartCollection && isTestChartCollection((ChartCollection) value)) { return true; 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 bd25f73682..9395ef5b3d 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 @@ -6,7 +6,6 @@ import com.fr.invoke.Reflect; import com.fr.json.JSON; import com.fr.json.JSONArray; import com.fr.json.JSONFactory; -import com.fr.json.JSONObject; import com.fr.stable.ProductConstants; import com.fr.stable.StringUtils; import com.fr.third.org.apache.commons.io.FileUtils; @@ -18,6 +17,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.powermock.api.easymock.PowerMock; import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor; import org.powermock.modules.junit4.PowerMockRunner; import java.io.File; @@ -34,6 +34,7 @@ import static org.junit.Assert.assertTrue; */ @RunWith(PowerMockRunner.class) @PrepareForTest({ProductConstants.class, MarketConfig.class, DesignerEnvManager.class}) +@SuppressStaticInitializationFor({"com.fr.jvm.assist.FineAssist"}) public class TemplateInfoCollectorTest { private String filePath; private String initialFileContent; @@ -58,6 +59,7 @@ public class TemplateInfoCollectorTest { EasyMock.expect(mockProcessInfo.useParaPane()).andReturn(false).anyTimes(); EasyMock.expect(mockProcessInfo.getComponentsInfo()).andReturn(new JSONArray()).anyTimes(); EasyMock.expect(mockProcessInfo.isTestTemplate()).andReturn(true).anyTimes(); + EasyMock.expect(mockProcessInfo.getReuseCmpList()).andReturn(JSONArray.create().add("reuse-id-1")).anyTimes(); EasyMock.replay(mockProcessInfo); // 缓存 tpl.info @@ -99,10 +101,11 @@ public class TemplateInfoCollectorTest { 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,\"paraApply\":0,\"block_count\":3,\"report_type\":0,\"components_info\":\"[]\"," + - "\"templateID\":\"e5d7dbb2-d1df-43d4-b974-67acb5ecbffa\"}", + "\"templateID\":\"e5d7dbb2-d1df-43d4-b974-67acb5ecbffa\",\"reuseCmptList\":\"[\\\"reuse-id-1\\\"]\"" + + "}", JSONFactory.createJSON(JSON.OBJECT, processMap).toString()); Assert.assertEquals(71113, consumingMap.get("uid")); @@ -130,10 +133,11 @@ public class TemplateInfoCollectorTest { Map processMap = Reflect.on(templateInfo).field("processMap").get(); assertEquals(templateID, templateInfo.getTemplateID()); - + 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\"}", JSONFactory.createJSON(JSON.OBJECT, processMap).toString()); + "\"templateID\":\"e5d7dbb2-d1df-43d4-b974-67acb5ecbffa\",\"reuseCmptList\":\"[\\\"reuse-id-1\\\"]\"" + + "}", JSONFactory.createJSON(JSON.OBJECT, processMap).toString()); Map consumingMap = Reflect.on(templateInfo).field("consumingMap").get(); Assert.assertEquals(71113, consumingMap.get("uid")); @@ -151,18 +155,19 @@ public class TemplateInfoCollectorTest { String templateID = "e5d7dbb2-d1df-43d4-b974-67acb5ecbffa"; String originID = "16a988ce-8529-42f5-b17c-2ee849355071"; int timeConsume = 200; - + collector.collectInfo(templateID, originID, mockProcessInfo, timeConsume); - + // 检查是否写入成功 Reflect.on(collector).call("loadFromFile"); TemplateInfo templateInfo = getTemplateInfoByID(templateID); Map processMap = Reflect.on(templateInfo).field("processMap").get(); - - 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\"}", JSONFactory.createJSON(JSON.OBJECT, 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\",\"reuseCmptList\":\"[\\\"reuse-id-1\\\"]\"" + + "}", JSONFactory.createJSON(JSON.OBJECT, processMap).toString()); + Map consumingMap = Reflect.on(templateInfo).field("consumingMap").get(); Assert.assertEquals(71113, consumingMap.get("uid")); Assert.assertEquals("2020-05-07 17:25", consumingMap.get("create_time")); diff --git a/designer-form/src/main/java/com/fr/design/mainframe/template/info/JFormProcessInfo.java b/designer-form/src/main/java/com/fr/design/mainframe/template/info/JFormProcessInfo.java index 8496e25920..da64e78e44 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/template/info/JFormProcessInfo.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/template/info/JFormProcessInfo.java @@ -1,9 +1,12 @@ package com.fr.design.mainframe.template.info; +import com.fr.base.iofile.attr.ExtendSharableAttrMark; import com.fr.chart.chartattr.ChartCollection; import com.fr.form.FormElementCaseProvider; import com.fr.form.main.Form; import com.fr.form.main.WidgetGather; +import com.fr.form.main.WidgetUtil; +import com.fr.form.ui.AbstractBorderStyleWidget; import com.fr.form.ui.BaseChartEditor; import com.fr.form.ui.CardSwitchButton; import com.fr.form.ui.ElementCaseEditorProvider; @@ -164,7 +167,7 @@ public class JFormProcessInfo extends TemplateProcessInfo
{ public boolean useParaPane() { return this.template.getParaContainer() != null; } - + @Override public JSONArray getComponentsInfo() { JSONArray ja = new JSONArray(); @@ -174,7 +177,27 @@ public class JFormProcessInfo extends TemplateProcessInfo { this.componentProcessInfoMap.clear(); return ja; } - + + @Override + public JSONArray getReuseCmpList() { + + final JSONArray jo = JSONArray.create(); + WLayout container = this.template.getContainer(); + WidgetUtil.bfsTraversalWidget(container, new WidgetUtil.BfsWidgetGather() { + @Override + public boolean dealWith(AbstractBorderStyleWidget styleWidget) { + ExtendSharableAttrMark widgetAttrMark = styleWidget.getWidgetAttrMark(ExtendSharableAttrMark.XML_TAG); + if (widgetAttrMark != null) { + String shareId = widgetAttrMark.getShareId(); + jo.add(shareId); + return true; + } + return false; + } + }, AbstractBorderStyleWidget.class); + return jo; + } + @Override public void updateTemplateOperationInfo(TemplateOperate templateOperate) { if (ComparatorUtils.equals(ComponentCreateOperate.OPERATE_TYPE, templateOperate.getOperateType())) { @@ -184,6 +207,7 @@ public class JFormProcessInfo extends TemplateProcessInfo { addComponentRemoveInfo(templateOperate.toJSONObject()); } } + private void addComponentCreateInfo(JSONObject jsonObject) { String componentID = jsonObject.getString("componentID"); componentProcessInfoMap.put(componentID, jsonObject); 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 a058f70194..6f589b0011 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 @@ -129,15 +129,20 @@ public class JWorkBookProcessInfo extends TemplateProcessInfo { } return parameterAttr.getParameterUI() != null; } - - + + @Override public JSONArray getComponentsInfo() { return new JSONArray(); } - + + @Override + public JSONArray getReuseCmpList() { + return JSONArray.create(); + } + @Override public void updateTemplateOperationInfo(TemplateOperate templateOption) { - + } }