From 5a05c497c710255d88b40bfdfc6e862658bb441f Mon Sep 17 00:00:00 2001 From: plough Date: Wed, 26 Apr 2017 09:28:21 +0800 Subject: [PATCH 1/6] =?UTF-8?q?REPORT-2343=20[=E4=BB=A3=E7=A0=81=E8=B4=A8?= =?UTF-8?q?=E9=87=8F]=20=E6=A8=A1=E6=9D=BF=E4=BF=A1=E6=81=AF=E6=94=B6?= =?UTF-8?q?=E9=9B=86=E7=94=A8xml=E6=96=B9=E5=BC=8F=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E4=B8=8E=E8=AF=BB=E5=8F=96,=20=E7=9B=B4=E6=8E=A5readObject?= =?UTF-8?q?=E4=B8=8D=E5=A4=AA=E5=A5=BD.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../templateinfo/TemplateInfoCollector.java | 205 ++++++++++++++---- 1 file changed, 164 insertions(+), 41 deletions(-) diff --git a/designer_base/src/com/fr/design/mainframe/templateinfo/TemplateInfoCollector.java b/designer_base/src/com/fr/design/mainframe/templateinfo/TemplateInfoCollector.java index b9b7aa194..dccff0e9c 100644 --- a/designer_base/src/com/fr/design/mainframe/templateinfo/TemplateInfoCollector.java +++ b/designer_base/src/com/fr/design/mainframe/templateinfo/TemplateInfoCollector.java @@ -6,32 +6,37 @@ import com.fr.design.DesignerEnvManager; import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.JTemplate; import com.fr.env.RemoteEnv; -import com.fr.general.ComparatorUtils; -import com.fr.general.FRLogger; -import com.fr.general.GeneralUtils; -import com.fr.general.SiteCenter; +import com.fr.general.*; import com.fr.general.http.HttpClient; +import com.fr.json.JSONArray; +import com.fr.json.JSONException; import com.fr.stable.*; -import org.json.JSONObject; +import com.fr.stable.xml.*; +import com.fr.third.javax.xml.stream.XMLStreamException; +import com.fr.json.JSONObject; import java.io.*; import java.text.SimpleDateFormat; import java.util.*; +import java.util.HashMap; +import java.util.Iterator; /** * 做模板的过程和耗时收集,辅助类 * Created by plough on 2017/2/21. */ -public class TemplateInfoCollector implements Serializable { - private static final String FILE_NAME = "tplInfo.ser"; +public class TemplateInfoCollector implements XMLReadable, XMLWriter { + private static final String FILE_NAME = "tpl.info"; private static TemplateInfoCollector instance; - private HashMap> templateInfoList; + private Map> templateInfoList; private String designerOpenDate; //设计器最近一次打开日期 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 static final int ONE_THOUSAND = 1000; static final long serialVersionUID = 2007L; + private static final String XML_DESIGNER_OPEN_DATE = "DesignerOpenDate"; + private static final String XML_TEMPLATE_INFO_LIST = "TemplateInfoList"; @SuppressWarnings("unchecked") private TemplateInfoCollector() { @@ -63,27 +68,42 @@ public class TemplateInfoCollector implements Serializable { public static TemplateInfoCollector getInstance() { if (instance == null) { - // 先尝试从文件读取 - try{ - ObjectInputStream is = new ObjectInputStream(new FileInputStream(getInfoFile())); - instance = (TemplateInfoCollector) is.readObject(); - } catch (FileNotFoundException ex) { - // 如果之前没有存储过,则创建新对象 - instance = new TemplateInfoCollector(); - } catch (InvalidClassException ex) { - // 如果 TemplateInfoCollecor 类结构有改动,则放弃之前收集的数据(下次保存时覆盖) - // 这种情况主要在开发、测试过程中遇到,正式上线后不应该出现 - FRLogger.getLogger().info(ex.getMessage()); - FRLogger.getLogger().info("use a new instance"); - instance = new TemplateInfoCollector(); - } - catch (Exception ex) { - FRLogger.getLogger().error(ex.getMessage(), ex); - } + instance = new TemplateInfoCollector(); + readXMLFile(instance, getInfoFile()); } return instance; } + private static void readXMLFile(XMLReadable xmlReadable, File xmlFile){ + if (xmlFile == null || !xmlFile.exists()) { + return; + } + String charset = EncodeConstants.ENCODING_UTF_8; + try { + String fileContent = getFileContent(xmlFile); + InputStream xmlInputStream = new ByteArrayInputStream(fileContent.getBytes(charset)); + InputStreamReader inputStreamReader = new InputStreamReader(xmlInputStream, charset); + XMLableReader xmlReader = XMLableReader.createXMLableReader(inputStreamReader); + + if (xmlReader != null) { + xmlReader.readXMLObject(xmlReadable); + } + xmlInputStream.close(); + } catch (FileNotFoundException e) { + FRContext.getLogger().error(e.getMessage()); + } catch (IOException e) { + FRContext.getLogger().error(e.getMessage()); + } catch (XMLStreamException e) { + FRContext.getLogger().error(e.getMessage()); + } + + } + + private static String getFileContent(File xmlFile) throws FileNotFoundException, UnsupportedEncodingException{ + InputStream is = new FileInputStream(xmlFile); + return IOUtils.inputStream2String(is); + } + private boolean shouldCollectInfo() { if (FRContext.getCurrentEnv() instanceof RemoteEnv) { // 远程设计不收集数据 return false; @@ -122,22 +142,40 @@ public class TemplateInfoCollector implements Serializable { */ private void saveInfo() { try { - ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream(getInfoFile())); - String log = ""; - int count = 1; - for (String key : templateInfoList.keySet()) { - String createTime = ((HashMap)templateInfoList.get(key).get("consumingMap")).get("create_time").toString(); - log += (count + ". id: " + key + " " + createTime + "\n" + templateInfoList.get(key).toString() + "\n"); - count ++; - } - FRLogger.getLogger().info("writing tplInfo: \n" + log); - os.writeObject(instance); - os.close(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + XMLTools.writeOutputStreamXML(this, out); + out.flush(); + out.close(); + String fileContent = new String(out.toByteArray(), EncodeConstants.ENCODING_UTF_8); + writeContentToFile(fileContent, getInfoFile()); } catch (Exception ex) { FRLogger.getLogger().error(ex.getMessage()); } } + /** + * 将文件内容写到输出流中 + */ + private static void writeContentToFile(String fileContent, File file){ + BufferedWriter bw = null; + try { + FileOutputStream fos = new FileOutputStream(file); + OutputStreamWriter osw = new OutputStreamWriter(fos, EncodeConstants.ENCODING_UTF_8); + bw = new BufferedWriter(osw); + bw.write(fileContent); + } catch (Exception e) { + FRContext.getLogger().error(e.getMessage()); + } finally { + if(bw != null){ + try { + bw.close(); + } catch (IOException e) { + } + } + } + + } + /** * 更新 day_count:打开设计器却未编辑模板的连续日子 */ @@ -241,10 +279,7 @@ public class TemplateInfoCollector implements Serializable { String jsonProcessMap = templateInfo.get("jsonProcessMap"); if (sendSingleTemplateInfo(consumingUrl, jsonConsumingMap) && sendSingleTemplateInfo(processUrl, jsonProcessMap)) { // 清空记录 - FRLogger.getLogger().info("successfully send " + templateInfo.get("templateID")); removeFromTemplateInfoList(templateInfo.get("templateID")); - } else { - FRLogger.getLogger().info("send template info failed, will try next time, " + templateInfo.get("templateID")); } } saveInfo(); @@ -264,7 +299,12 @@ public class TemplateInfoCollector implements Serializable { } String res = httpClient.getResponseText(); - boolean success = ComparatorUtils.equals(new JSONObject(res).get("status"), "success"); + boolean success; + try { + success = ComparatorUtils.equals(new JSONObject(res).get("status"), "success"); + } catch (Exception ex) { + success = false; + } return success; } @@ -303,7 +343,6 @@ public class TemplateInfoCollector implements Serializable { private void removeFromTemplateInfoList(String key) { templateInfoList.remove(key); - FRLogger.getLogger().info(key + " is removed..."); } @SuppressWarnings("unchecked") @@ -325,6 +364,90 @@ public class TemplateInfoCollector implements Serializable { return isTestTemplate; } + public static Map jsonToMap(JSONObject json) throws JSONException { + Map retMap = new HashMap<>(); + + if(json != JSONObject.NULL) { + retMap = toMap(json); + } + return retMap; + } + + private static Map toMap(JSONObject object) throws JSONException { + Map map = new HashMap<>(); + + Iterator keysItr = object.keys(); + while(keysItr.hasNext()) { + String key = keysItr.next(); + Object value = object.get(key); + + if(value instanceof JSONArray) { + value = toList((JSONArray) value); + } + + else if(value instanceof JSONObject) { + value = toMap((JSONObject) value); + } + map.put(key, value); + } + return map; + } + + private static List toList(JSONArray array) throws JSONException { + List list = new ArrayList<>(); + for(int i = 0; i < array.length(); i++) { + Object value = array.get(i); + if(value instanceof JSONArray) { + value = toList((JSONArray) value); + } + + else if(value instanceof JSONObject) { + value = toMap((JSONObject) value); + } + list.add(value); + } + return list; + } + + @SuppressWarnings("unchecked") + @Override + public void readXML(XMLableReader reader) { + if (reader.isChildNode()) { + try { + String name = reader.getTagName(); + if (XML_DESIGNER_OPEN_DATE.equals(name)) { + this.designerOpenDate = reader.getElementValue(); + } else if(XML_TEMPLATE_INFO_LIST.equals(name)){ + JSONObject jsonObject = new JSONObject(reader.getElementValue()); + Map map = jsonToMap(jsonObject); + for (Map.Entry entry : map.entrySet()) { + if (entry.getValue() instanceof HashMap) { + this.templateInfoList.put(entry.getKey(), (HashMap) entry.getValue()); + } + } + } + } catch (Exception ex) { + // 什么也不做,使用默认值 + } + } + } + + @Override + public void writeXML(XMLPrintWriter writer) { + writer.startTAG("TemplateInfo"); + + writer.startTAG(XML_DESIGNER_OPEN_DATE); + writer.textNode(designerOpenDate); + writer.end(); + + writer.startTAG(XML_TEMPLATE_INFO_LIST); + writer.textNode(new JSONObject(templateInfoList).toString()); + writer.end(); + + writer.end(); + } + + public static void main(String[] args) { TemplateInfoCollector tic = TemplateInfoCollector.getInstance(); tic.sendTemplateInfo(); From 8cafb6397b8b1f5b513a79bac473f2572b417175 Mon Sep 17 00:00:00 2001 From: plough Date: Thu, 27 Apr 2017 14:23:56 +0800 Subject: [PATCH 2/6] =?UTF-8?q?REPORT-2343=20[=E4=BB=A3=E7=A0=81=E8=B4=A8?= =?UTF-8?q?=E9=87=8F]=20=E6=A8=A1=E6=9D=BF=E4=BF=A1=E6=81=AF=E6=94=B6?= =?UTF-8?q?=E9=9B=86=E7=94=A8xml=E6=96=B9=E5=BC=8F=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E4=B8=8E=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../templateinfo/TemplateInfoCollector.java | 193 +++++++++++++++++- 1 file changed, 183 insertions(+), 10 deletions(-) diff --git a/designer_base/src/com/fr/design/mainframe/templateinfo/TemplateInfoCollector.java b/designer_base/src/com/fr/design/mainframe/templateinfo/TemplateInfoCollector.java index dccff0e9c..c8a25cb29 100644 --- a/designer_base/src/com/fr/design/mainframe/templateinfo/TemplateInfoCollector.java +++ b/designer_base/src/com/fr/design/mainframe/templateinfo/TemplateInfoCollector.java @@ -37,6 +37,35 @@ public class TemplateInfoCollector implements XMLReadable, XML static final long serialVersionUID = 2007L; private static final String XML_DESIGNER_OPEN_DATE = "DesignerOpenDate"; private static final String XML_TEMPLATE_INFO_LIST = "TemplateInfoList"; + private static final String XML_TEMPLATE_INFO = "TemplateInfo"; + private static final String XML_PROCESS_MAP = "ProcessMap"; + private static final String XML_CONSUMING_MAP = "ConsumingMap"; + private static final String ATTR_DAY_COUNT = "dayCount"; + private static final String ATTR_TEMPLATE_ID = "templateID"; + /* + * "process":"","float_count":0,"widget_count":1,"cell_count":0,"block_count":0,"report_type":2 + * */ + private static final String ATTR_PROCESS = "process"; + private static final String ATTR_FLOAT_COUNT = "floatCount"; + private static final String ATTR_WIDGET_COUNT = "widgetCount"; + private static final String ATTR_CELL_COUNT = "cellCount"; + private static final String ATTR_BLOCK_COUNT = "blockCount"; + private static final String ATTR_REPORT_TYPE = "reportType"; + /* + * "activitykey":"2e0ea413-fa9c241e0-9723-4354fce51e81","jar_time":"2017.04.21.10.41.10.806", + * "create_time":"2017-04-26 10:27","templateID":"0aa19027-e298-4d43-868d-45232b879d0e", + * "uuid":"476ca2cc-f789-4c5d-8e89-ef146580775c","time_consume":36,"version":"8.0", + * "username":"ueeHq6 + * */ + private static final String ATTR_ACTIVITYKEY = "activitykey"; + private static final String ATTR_JAR_TIME = "jarTime"; + private static final String ATTR_CREATE_TIME = "createTime"; + private static final String ATTR_UUID = "uuid"; + private static final String ATTR_TIME_CONSUME = "timeConsume"; + private static final String ATTR_VERSION = "version"; + private static final String ATTR_USERNAME = "username"; + + @SuppressWarnings("unchecked") private TemplateInfoCollector() { @@ -418,13 +447,14 @@ public class TemplateInfoCollector implements XMLReadable, XML if (XML_DESIGNER_OPEN_DATE.equals(name)) { this.designerOpenDate = reader.getElementValue(); } else if(XML_TEMPLATE_INFO_LIST.equals(name)){ - JSONObject jsonObject = new JSONObject(reader.getElementValue()); - Map map = jsonToMap(jsonObject); - for (Map.Entry entry : map.entrySet()) { - if (entry.getValue() instanceof HashMap) { - this.templateInfoList.put(entry.getKey(), (HashMap) entry.getValue()); - } - } +// JSONObject jsonObject = new JSONObject(reader.getElementValue()); +// Map map = jsonToMap(jsonObject); +// for (Map.Entry entry : map.entrySet()) { +// if (entry.getValue() instanceof HashMap) { +// this.templateInfoList.put(entry.getKey(), (HashMap) entry.getValue()); +// } +// } + readTemplateInfoList(reader); } } catch (Exception ex) { // 什么也不做,使用默认值 @@ -432,21 +462,164 @@ public class TemplateInfoCollector implements XMLReadable, XML } } + private void readTemplateInfoList(XMLableReader reader) { + reader.readXMLObject(new XMLReadable() { + public void readXML(XMLableReader reader) { + if (XML_TEMPLATE_INFO.equals(reader.getTagName())) { + TemplateInfo templateInfo = new TemplateInfo(); + reader.readXMLObject(templateInfo); + templateInfoList.put(templateInfo.getTemplateID(), templateInfo.getTemplateInfo()); + } + } + }); + } + @Override public void writeXML(XMLPrintWriter writer) { - writer.startTAG("TemplateInfo"); + writer.startTAG("TplInfo"); writer.startTAG(XML_DESIGNER_OPEN_DATE); writer.textNode(designerOpenDate); writer.end(); - writer.startTAG(XML_TEMPLATE_INFO_LIST); - writer.textNode(new JSONObject(templateInfoList).toString()); +// writer.startTAG(XML_TEMPLATE_INFO_LIST); +// writer.textNode(new JSONObject(templateInfoList).toString()); +// writer.end(); + writeTemplateInfoList(writer); + writer.end(); + } + private void writeTemplateInfoList(XMLPrintWriter writer){ + //启停 + writer.startTAG(XML_TEMPLATE_INFO_LIST); + for (String templateID : templateInfoList.keySet()) { + new TemplateInfo(templateInfoList.get(templateID)).writeXML(writer); + } +// for (int i = 0; i < templateInfoList.size(); i++) { +// startStop.get(i).writeXML(writer); +// } writer.end(); } + private class TemplateInfo implements XMLReadable, XMLWriter { + + private int dayCount; + private String templateID; + private HashMap processMap = new HashMap<>(); + private HashMap consumingMap = new HashMap<>(); + + @SuppressWarnings("unchecked") + public TemplateInfo(HashMap templateInfo) { + this.dayCount = (int)templateInfo.get("day_count"); + this.processMap = (HashMap) templateInfo.get("processMap"); + this.consumingMap = (HashMap) templateInfo.get("consumingMap"); + this.templateID = (String) processMap.get("templateID"); + } + + public TemplateInfo() {} + +// public int getDayCount() { +// return dayCount; +// } + public String getTemplateID() { + return templateID; + } + +// public void setStartDate(String startDate) { +// this.startDate = startDate; +// } + + public HashMap getTemplateInfo() { + HashMap templateInfo = new HashMap<>(); + templateInfo.put("processMap", processMap); + templateInfo.put("consumingMap", consumingMap); + templateInfo.put("day_count", dayCount); + return templateInfo; + } + +// public HashMap getProcessMap() { +// return processMap; +// } +// +// public HashMap getConsumingMap() { +// return consumingMap; +// } + +// public void setStopDate(String endDate) { +// this.stopDate = endDate; +// } + + public void writeXML(XMLPrintWriter writer) { + writer.startTAG(XML_TEMPLATE_INFO); + if (StringUtils.isNotEmpty(templateID)) { + writer.attr(ATTR_TEMPLATE_ID, this.templateID); + } + if (dayCount >= 0) { + writer.attr(ATTR_DAY_COUNT, this.dayCount); + } + writeProcessMap(writer); + writeConsumingMap(writer); + + writer.end(); + } + + private void writeProcessMap(XMLPrintWriter writer) { + writer.startTAG(XML_PROCESS_MAP); + writer.attr(ATTR_PROCESS, (String)processMap.get("process")); + writer.attr(ATTR_FLOAT_COUNT, (int)processMap.get("float_count")); + writer.attr(ATTR_WIDGET_COUNT, (int)processMap.get("widget_count")); + writer.attr(ATTR_CELL_COUNT, (int)processMap.get("cell_count")); + writer.attr(ATTR_BLOCK_COUNT, (int)processMap.get("block_count")); + writer.attr(ATTR_REPORT_TYPE, (int)processMap.get("report_type")); + writer.end(); + } + + private void writeConsumingMap(XMLPrintWriter writer) { + writer.startTAG(XML_CONSUMING_MAP); + writer.attr(ATTR_ACTIVITYKEY, (String)consumingMap.get("activitykey")); + writer.attr(ATTR_JAR_TIME, (String)consumingMap.get("jar_time")); + writer.attr(ATTR_CREATE_TIME, (String)consumingMap.get("create_time")); + writer.attr(ATTR_UUID, (String)consumingMap.get("uuid")); + writer.attr(ATTR_TIME_CONSUME, (long)consumingMap.get("time_consume")); + writer.attr(ATTR_VERSION, (String)consumingMap.get("version")); + writer.attr(ATTR_USERNAME, (String)consumingMap.get("username")); + writer.end(); + } + + public void readXML(XMLableReader reader) { + if (!reader.isChildNode()) { + dayCount = reader.getAttrAsInt(ATTR_DAY_COUNT, 0); + templateID = reader.getAttrAsString(ATTR_TEMPLATE_ID, StringUtils.EMPTY); + } else { + try { + String name = reader.getTagName(); + if (XML_PROCESS_MAP.equals(name)) { + processMap.put("process", reader.getAttrAsString(ATTR_PROCESS, StringUtils.EMPTY)); + processMap.put("float_count", reader.getAttrAsInt(ATTR_FLOAT_COUNT, 0)); + processMap.put("widget_count", reader.getAttrAsInt(ATTR_WIDGET_COUNT, 0)); + processMap.put("cell_count", reader.getAttrAsInt(ATTR_CELL_COUNT, 0)); + processMap.put("block_count", reader.getAttrAsInt(ATTR_BLOCK_COUNT, 0)); + processMap.put("report_type", reader.getAttrAsInt(ATTR_REPORT_TYPE, 0)); + processMap.put("templateID", templateID); + } else if(XML_CONSUMING_MAP.equals(name)){ + consumingMap.put("activitykey", reader.getAttrAsString(ATTR_ACTIVITYKEY, StringUtils.EMPTY)); + consumingMap.put("jar_time", reader.getAttrAsString(ATTR_JAR_TIME, StringUtils.EMPTY)); + consumingMap.put("create_time", reader.getAttrAsString(ATTR_CREATE_TIME, StringUtils.EMPTY)); + consumingMap.put("templateID", templateID); + consumingMap.put("uuid", reader.getAttrAsString(ATTR_UUID, StringUtils.EMPTY)); + consumingMap.put("time_consume", reader.getAttrAsLong(ATTR_TIME_CONSUME, 0)); + consumingMap.put("version", reader.getAttrAsString(ATTR_VERSION, "8.0")); + consumingMap.put("username", reader.getAttrAsString(ATTR_USERNAME, StringUtils.EMPTY)); + } + } catch (Exception ex) { + // 什么也不做,使用默认值 + } + } + } + + } + public static void main(String[] args) { TemplateInfoCollector tic = TemplateInfoCollector.getInstance(); From 4700b3dc89fb369e73a08d0ccf3b590edd4ffbea Mon Sep 17 00:00:00 2001 From: plough Date: Thu, 27 Apr 2017 15:20:06 +0800 Subject: [PATCH 3/6] =?UTF-8?q?REPORT-2343=20[=E4=BB=A3=E7=A0=81=E8=B4=A8?= =?UTF-8?q?=E9=87=8F]=3D>=E5=85=BC=E5=AE=B9=E4=B9=8B=E5=89=8D=E7=9A=84?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1=E6=B5=81=E8=AF=BB=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../templateinfo/TemplateInfoCollector.java | 58 +++++-------------- 1 file changed, 15 insertions(+), 43 deletions(-) diff --git a/designer_base/src/com/fr/design/mainframe/templateinfo/TemplateInfoCollector.java b/designer_base/src/com/fr/design/mainframe/templateinfo/TemplateInfoCollector.java index c8a25cb29..9206785dd 100644 --- a/designer_base/src/com/fr/design/mainframe/templateinfo/TemplateInfoCollector.java +++ b/designer_base/src/com/fr/design/mainframe/templateinfo/TemplateInfoCollector.java @@ -25,8 +25,9 @@ import java.util.Iterator; * 做模板的过程和耗时收集,辅助类 * Created by plough on 2017/2/21. */ -public class TemplateInfoCollector implements XMLReadable, XMLWriter { +public class TemplateInfoCollector implements Serializable, XMLReadable, XMLWriter { private static final String FILE_NAME = "tpl.info"; + private static final String OBJECT_FILE_NAME = "tplInfo.ser"; private static TemplateInfoCollector instance; private Map> templateInfoList; private String designerOpenDate; //设计器最近一次打开日期 @@ -42,21 +43,12 @@ public class TemplateInfoCollector implements XMLReadable, XML private static final String XML_CONSUMING_MAP = "ConsumingMap"; private static final String ATTR_DAY_COUNT = "dayCount"; private static final String ATTR_TEMPLATE_ID = "templateID"; - /* - * "process":"","float_count":0,"widget_count":1,"cell_count":0,"block_count":0,"report_type":2 - * */ private static final String ATTR_PROCESS = "process"; private static final String ATTR_FLOAT_COUNT = "floatCount"; private static final String ATTR_WIDGET_COUNT = "widgetCount"; private static final String ATTR_CELL_COUNT = "cellCount"; private static final String ATTR_BLOCK_COUNT = "blockCount"; private static final String ATTR_REPORT_TYPE = "reportType"; - /* - * "activitykey":"2e0ea413-fa9c241e0-9723-4354fce51e81","jar_time":"2017.04.21.10.41.10.806", - * "create_time":"2017-04-26 10:27","templateID":"0aa19027-e298-4d43-868d-45232b879d0e", - * "uuid":"476ca2cc-f789-4c5d-8e89-ef146580775c","time_consume":36,"version":"8.0", - * "username":"ueeHq6 - * */ private static final String ATTR_ACTIVITYKEY = "activitykey"; private static final String ATTR_JAR_TIME = "jarTime"; private static final String ATTR_CREATE_TIME = "createTime"; @@ -66,7 +58,6 @@ public class TemplateInfoCollector implements XMLReadable, XML private static final String ATTR_USERNAME = "username"; - @SuppressWarnings("unchecked") private TemplateInfoCollector() { templateInfoList = new HashMap<>(); @@ -95,10 +86,23 @@ public class TemplateInfoCollector implements XMLReadable, XML return new File(StableUtils.pathJoin(ProductConstants.getEnvHome(), FILE_NAME)); } + private static File getObjectInfoFile() { + return new File(StableUtils.pathJoin(ProductConstants.getEnvHome(), OBJECT_FILE_NAME)); + } + public static TemplateInfoCollector getInstance() { if (instance == null) { instance = new TemplateInfoCollector(); readXMLFile(instance, getInfoFile()); + // 兼容过渡。如果没有新文件,则从老文件读取数据。以后都是读写新的 xml 文件 + if (!getInfoFile().exists() && getObjectInfoFile().exists()) { + try { + ObjectInputStream is = new ObjectInputStream(new FileInputStream(getObjectInfoFile())); + instance = (TemplateInfoCollector) is.readObject(); + } catch (Exception ex) { + // 什么也不做,instance 使用新值 + } + } } return instance; } @@ -447,13 +451,6 @@ public class TemplateInfoCollector implements XMLReadable, XML if (XML_DESIGNER_OPEN_DATE.equals(name)) { this.designerOpenDate = reader.getElementValue(); } else if(XML_TEMPLATE_INFO_LIST.equals(name)){ -// JSONObject jsonObject = new JSONObject(reader.getElementValue()); -// Map map = jsonToMap(jsonObject); -// for (Map.Entry entry : map.entrySet()) { -// if (entry.getValue() instanceof HashMap) { -// this.templateInfoList.put(entry.getKey(), (HashMap) entry.getValue()); -// } -// } readTemplateInfoList(reader); } } catch (Exception ex) { @@ -482,9 +479,6 @@ public class TemplateInfoCollector implements XMLReadable, XML writer.textNode(designerOpenDate); writer.end(); -// writer.startTAG(XML_TEMPLATE_INFO_LIST); -// writer.textNode(new JSONObject(templateInfoList).toString()); -// writer.end(); writeTemplateInfoList(writer); writer.end(); @@ -496,9 +490,6 @@ public class TemplateInfoCollector implements XMLReadable, XML for (String templateID : templateInfoList.keySet()) { new TemplateInfo(templateInfoList.get(templateID)).writeXML(writer); } -// for (int i = 0; i < templateInfoList.size(); i++) { -// startStop.get(i).writeXML(writer); -// } writer.end(); } @@ -519,17 +510,10 @@ public class TemplateInfoCollector implements XMLReadable, XML public TemplateInfo() {} -// public int getDayCount() { -// return dayCount; -// } public String getTemplateID() { return templateID; } -// public void setStartDate(String startDate) { -// this.startDate = startDate; -// } - public HashMap getTemplateInfo() { HashMap templateInfo = new HashMap<>(); templateInfo.put("processMap", processMap); @@ -538,18 +522,6 @@ public class TemplateInfoCollector implements XMLReadable, XML return templateInfo; } -// public HashMap getProcessMap() { -// return processMap; -// } -// -// public HashMap getConsumingMap() { -// return consumingMap; -// } - -// public void setStopDate(String endDate) { -// this.stopDate = endDate; -// } - public void writeXML(XMLPrintWriter writer) { writer.startTAG(XML_TEMPLATE_INFO); if (StringUtils.isNotEmpty(templateID)) { From aa379c899448a73727f2e0cd99a6b6b0eb94fc5c Mon Sep 17 00:00:00 2001 From: plough Date: Thu, 27 Apr 2017 15:23:15 +0800 Subject: [PATCH 4/6] =?UTF-8?q?REPORT-2343=20[=E4=BB=A3=E7=A0=81=E8=B4=A8?= =?UTF-8?q?=E9=87=8F]=3D>=E5=8E=BB=E6=8E=89=E6=97=A0=E7=94=A8=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../templateinfo/TemplateInfoCollector.java | 45 ------------------- 1 file changed, 45 deletions(-) diff --git a/designer_base/src/com/fr/design/mainframe/templateinfo/TemplateInfoCollector.java b/designer_base/src/com/fr/design/mainframe/templateinfo/TemplateInfoCollector.java index 9206785dd..b5bac38d9 100644 --- a/designer_base/src/com/fr/design/mainframe/templateinfo/TemplateInfoCollector.java +++ b/designer_base/src/com/fr/design/mainframe/templateinfo/TemplateInfoCollector.java @@ -397,51 +397,6 @@ public class TemplateInfoCollector implements Serializable, XM return isTestTemplate; } - public static Map jsonToMap(JSONObject json) throws JSONException { - Map retMap = new HashMap<>(); - - if(json != JSONObject.NULL) { - retMap = toMap(json); - } - return retMap; - } - - private static Map toMap(JSONObject object) throws JSONException { - Map map = new HashMap<>(); - - Iterator keysItr = object.keys(); - while(keysItr.hasNext()) { - String key = keysItr.next(); - Object value = object.get(key); - - if(value instanceof JSONArray) { - value = toList((JSONArray) value); - } - - else if(value instanceof JSONObject) { - value = toMap((JSONObject) value); - } - map.put(key, value); - } - return map; - } - - private static List toList(JSONArray array) throws JSONException { - List list = new ArrayList<>(); - for(int i = 0; i < array.length(); i++) { - Object value = array.get(i); - if(value instanceof JSONArray) { - value = toList((JSONArray) value); - } - - else if(value instanceof JSONObject) { - value = toMap((JSONObject) value); - } - list.add(value); - } - return list; - } - @SuppressWarnings("unchecked") @Override public void readXML(XMLableReader reader) { From ef7543f1f80883d090eb49c2d95fe8d4e698116e Mon Sep 17 00:00:00 2001 From: plough Date: Thu, 27 Apr 2017 17:48:19 +0800 Subject: [PATCH 5/6] =?UTF-8?q?REPORT-2343=20[=E4=BB=A3=E7=A0=81=E8=B4=A8?= =?UTF-8?q?=E9=87=8F]=3D>=E5=A4=9A=E6=AC=A1=E5=87=BA=E7=8E=B0=E7=9A=84?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E4=B8=B2=E6=94=B9=E4=B8=BA=E5=B8=B8=E9=87=8F?= =?UTF-8?q?=EF=BC=9B=E7=BB=9F=E4=B8=80=E5=91=BD=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../templateinfo/TemplateInfoCollector.java | 174 +++++++++--------- 1 file changed, 88 insertions(+), 86 deletions(-) diff --git a/designer_base/src/com/fr/design/mainframe/templateinfo/TemplateInfoCollector.java b/designer_base/src/com/fr/design/mainframe/templateinfo/TemplateInfoCollector.java index b5bac38d9..1a06d82c3 100644 --- a/designer_base/src/com/fr/design/mainframe/templateinfo/TemplateInfoCollector.java +++ b/designer_base/src/com/fr/design/mainframe/templateinfo/TemplateInfoCollector.java @@ -39,23 +39,25 @@ public class TemplateInfoCollector implements Serializable, XM private static final String XML_DESIGNER_OPEN_DATE = "DesignerOpenDate"; private static final String XML_TEMPLATE_INFO_LIST = "TemplateInfoList"; private static final String XML_TEMPLATE_INFO = "TemplateInfo"; - private static final String XML_PROCESS_MAP = "ProcessMap"; - private static final String XML_CONSUMING_MAP = "ConsumingMap"; - private static final String ATTR_DAY_COUNT = "dayCount"; + private static final String XML_PROCESS_MAP = "processMap"; + private static final String XML_CONSUMING_MAP = "consumingMap"; + private static final String ATTR_DAY_COUNT = "day_count"; private static final String ATTR_TEMPLATE_ID = "templateID"; private static final String ATTR_PROCESS = "process"; - private static final String ATTR_FLOAT_COUNT = "floatCount"; - private static final String ATTR_WIDGET_COUNT = "widgetCount"; - private static final String ATTR_CELL_COUNT = "cellCount"; - private static final String ATTR_BLOCK_COUNT = "blockCount"; - private static final String ATTR_REPORT_TYPE = "reportType"; + private static final String ATTR_FLOAT_COUNT = "float_count"; + private static final String ATTR_WIDGET_COUNT = "widget_count"; + 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 = "jarTime"; - private static final String ATTR_CREATE_TIME = "createTime"; + 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 = "timeConsume"; + private static final String ATTR_TIME_CONSUME = "time_consume"; private static final String ATTR_VERSION = "version"; private static final String ATTR_USERNAME = "username"; + private static final String JSON_CONSUMING_MAP = "jsonConsumingMap"; + private static final String JSON_PROCESS_MAP = "jsonProcessMap"; @SuppressWarnings("unchecked") @@ -159,8 +161,8 @@ public class TemplateInfoCollector implements Serializable, XM */ @SuppressWarnings("unchecked") public String loadProcess(T t) { - HashMap processMap = (HashMap) templateInfoList.get(t.getTemplateID()).get("processMap"); - return (String)processMap.get("process"); + HashMap processMap = (HashMap) templateInfoList.get(t.getTemplateID()).get(XML_PROCESS_MAP); + return (String)processMap.get(ATTR_PROCESS); } /** @@ -216,8 +218,8 @@ public class TemplateInfoCollector implements Serializable, XM if (designerOpenFirstTime()) { for (String key : templateInfoList.keySet()) { HashMap templateInfo = templateInfoList.get(key); - int dayCount = (int)templateInfo.get("day_count") + 1; - templateInfo.put("day_count", dayCount); + int dayCount = (int)templateInfo.get(ATTR_DAY_COUNT) + 1; + templateInfo.put(ATTR_DAY_COUNT, dayCount); } setDesignerOpenDate(); } @@ -241,20 +243,20 @@ public class TemplateInfoCollector implements Serializable, XM if (inList(t)) { // 已有记录 templateInfo = templateInfoList.get(t.getTemplateID()); // 更新 conusmingMap - HashMap consumingMap = (HashMap) templateInfo.get("consumingMap"); - timeConsume += (long)consumingMap.get("time_consume"); // 加上之前的累计编辑时间 - consumingMap.put("time_consume", timeConsume); + HashMap consumingMap = (HashMap) templateInfo.get(XML_CONSUMING_MAP); + timeConsume += (long)consumingMap.get(ATTR_TIME_CONSUME); // 加上之前的累计编辑时间 + consumingMap.put(ATTR_TIME_CONSUME, timeConsume); } else { // 新增 templateInfo = new HashMap<>(); - templateInfo.put("consumingMap", getNewConsumingMap(templateID, openTime, timeConsume)); + templateInfo.put(XML_CONSUMING_MAP, getNewConsumingMap(templateID, openTime, timeConsume)); } // 直接覆盖 processMap - templateInfo.put("processMap", getProcessMap(templateID, jt)); + templateInfo.put(XML_PROCESS_MAP, getProcessMap(templateID, jt)); // 保存模板时,让 day_count 归零 - templateInfo.put("day_count", 0); + templateInfo.put(ATTR_DAY_COUNT, 0); templateInfoList.put(templateID, templateInfo); @@ -271,14 +273,14 @@ public class TemplateInfoCollector implements Serializable, XM String createTime = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(Calendar.getInstance().getTime()); String jarTime = GeneralUtils.readBuildNO(); String version = ProductConstants.VERSION; - consumingMap.put("username", username); - consumingMap.put("uuid", uuid); - consumingMap.put("activitykey", activitykey); - consumingMap.put("templateID", templateID); - consumingMap.put("create_time", createTime); - consumingMap.put("time_consume", timeConsume); - consumingMap.put("jar_time", jarTime); - consumingMap.put("version", version); + consumingMap.put(ATTR_USERNAME, username); + consumingMap.put(ATTR_UUID, uuid); + consumingMap.put(ATTR_ACTIVITYKEY, activitykey); + consumingMap.put(ATTR_TEMPLATE_ID, templateID); + consumingMap.put(ATTR_CREATE_TIME, createTime); + consumingMap.put(ATTR_TIME_CONSUME, timeConsume); + consumingMap.put(ATTR_JAR_TIME, jarTime); + consumingMap.put(ATTR_VERSION, version); return consumingMap; } @@ -286,15 +288,15 @@ public class TemplateInfoCollector implements Serializable, XM private HashMap getProcessMap(String templateID, JTemplate jt) { HashMap processMap = new HashMap<>(); - processMap.put("templateID", templateID); - processMap.put("process", jt.getProcess()); + processMap.put(ATTR_TEMPLATE_ID, templateID); + processMap.put(ATTR_PROCESS, jt.getProcess()); TemplateProcessInfo info = jt.getProcessInfo(); - processMap.put("report_type", info.getReportType()); - processMap.put("cell_count", info.getCellCount()); - processMap.put("float_count", info.getFloatCount()); - processMap.put("block_count", info.getBlockCount()); - processMap.put("widget_count", info.getWidgetCount()); + processMap.put(ATTR_REPORT_TYPE, info.getReportType()); + processMap.put(ATTR_CELL_COUNT, info.getCellCount()); + processMap.put(ATTR_FLOAT_COUNT, info.getFloatCount()); + processMap.put(ATTR_BLOCK_COUNT, info.getBlockCount()); + processMap.put(ATTR_WIDGET_COUNT, info.getWidgetCount()); return processMap; } @@ -308,11 +310,11 @@ public class TemplateInfoCollector implements Serializable, XM String processUrl = SiteCenter.getInstance().acquireUrlByKind("tempinfo.process") + "/single"; ArrayList> completeTemplatesInfo = getCompleteTemplatesInfo(); for (HashMap templateInfo : completeTemplatesInfo) { - String jsonConsumingMap = templateInfo.get("jsonConsumingMap"); - String jsonProcessMap = templateInfo.get("jsonProcessMap"); + String jsonConsumingMap = templateInfo.get(JSON_CONSUMING_MAP); + String jsonProcessMap = templateInfo.get(JSON_PROCESS_MAP); if (sendSingleTemplateInfo(consumingUrl, jsonConsumingMap) && sendSingleTemplateInfo(processUrl, jsonProcessMap)) { // 清空记录 - removeFromTemplateInfoList(templateInfo.get("templateID")); + removeFromTemplateInfoList(templateInfo.get(ATTR_TEMPLATE_ID)); } } saveInfo(); @@ -350,21 +352,21 @@ public class TemplateInfoCollector implements Serializable, XM ArrayList testTemplateKeys = new ArrayList<>(); // 保存测试模板的key for (String key : templateInfoList.keySet()) { HashMap templateInfo = templateInfoList.get(key); - if ((int)templateInfo.get("day_count") <= COMPLETE_DAY_COUNT) { // 未完成模板 + if ((int)templateInfo.get(ATTR_DAY_COUNT) <= COMPLETE_DAY_COUNT) { // 未完成模板 continue; } if (isTestTemplate(templateInfo)) { testTemplateKeys.add(key); continue; } - HashMap consumingMap = (HashMap) templateInfo.get("consumingMap"); - HashMap processMap = (HashMap) templateInfo.get("processMap"); + HashMap consumingMap = (HashMap) templateInfo.get(XML_CONSUMING_MAP); + HashMap processMap = (HashMap) templateInfo.get(XML_PROCESS_MAP); String jsonConsumingMap = new JSONObject(consumingMap).toString(); String jsonProcessMap = new JSONObject(processMap).toString(); HashMap jsonTemplateInfo = new HashMap<>(); - jsonTemplateInfo.put("jsonConsumingMap", jsonConsumingMap); - jsonTemplateInfo.put("jsonProcessMap", jsonProcessMap); - jsonTemplateInfo.put("templateID", key); + jsonTemplateInfo.put(JSON_CONSUMING_MAP, jsonConsumingMap); + jsonTemplateInfo.put(JSON_PROCESS_MAP, jsonProcessMap); + jsonTemplateInfo.put(ATTR_TEMPLATE_ID, key); completeTemplatesInfo.add(jsonTemplateInfo); } // 删除测试模板 @@ -380,12 +382,12 @@ public class TemplateInfoCollector implements Serializable, XM @SuppressWarnings("unchecked") private boolean isTestTemplate(HashMap templateInfo) { - HashMap processMap = (HashMap) templateInfo.get("processMap"); - int reportType = (int)processMap.get("report_type"); - int cellCount = (int)processMap.get("cell_count"); - int floatCount = (int)processMap.get("float_count"); - int blockCount = (int)processMap.get("block_count"); - int widgetCount = (int)processMap.get("widget_count"); + HashMap processMap = (HashMap) templateInfo.get(XML_PROCESS_MAP); + 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); boolean isTestTemplate = false; if (reportType == 0) { // 普通报表 isTestTemplate = cellCount <= VALID_CELL_COUNT && floatCount <= 1 && widgetCount <= VALID_WIDGET_COUNT; @@ -457,10 +459,10 @@ public class TemplateInfoCollector implements Serializable, XM @SuppressWarnings("unchecked") public TemplateInfo(HashMap templateInfo) { - this.dayCount = (int)templateInfo.get("day_count"); - this.processMap = (HashMap) templateInfo.get("processMap"); - this.consumingMap = (HashMap) templateInfo.get("consumingMap"); - this.templateID = (String) processMap.get("templateID"); + this.dayCount = (int)templateInfo.get(ATTR_DAY_COUNT); + this.processMap = (HashMap) templateInfo.get(XML_PROCESS_MAP); + this.consumingMap = (HashMap) templateInfo.get(XML_CONSUMING_MAP); + this.templateID = (String) processMap.get(ATTR_TEMPLATE_ID); } public TemplateInfo() {} @@ -471,9 +473,9 @@ public class TemplateInfoCollector implements Serializable, XM public HashMap getTemplateInfo() { HashMap templateInfo = new HashMap<>(); - templateInfo.put("processMap", processMap); - templateInfo.put("consumingMap", consumingMap); - templateInfo.put("day_count", dayCount); + templateInfo.put(XML_PROCESS_MAP, processMap); + templateInfo.put(XML_CONSUMING_MAP, consumingMap); + templateInfo.put(ATTR_DAY_COUNT, dayCount); return templateInfo; } @@ -493,24 +495,24 @@ public class TemplateInfoCollector implements Serializable, XM private void writeProcessMap(XMLPrintWriter writer) { writer.startTAG(XML_PROCESS_MAP); - writer.attr(ATTR_PROCESS, (String)processMap.get("process")); - writer.attr(ATTR_FLOAT_COUNT, (int)processMap.get("float_count")); - writer.attr(ATTR_WIDGET_COUNT, (int)processMap.get("widget_count")); - writer.attr(ATTR_CELL_COUNT, (int)processMap.get("cell_count")); - writer.attr(ATTR_BLOCK_COUNT, (int)processMap.get("block_count")); - writer.attr(ATTR_REPORT_TYPE, (int)processMap.get("report_type")); + writer.attr(ATTR_PROCESS, (String)processMap.get(ATTR_PROCESS)); + writer.attr(ATTR_FLOAT_COUNT, (int)processMap.get(ATTR_FLOAT_COUNT)); + writer.attr(ATTR_WIDGET_COUNT, (int)processMap.get(ATTR_WIDGET_COUNT)); + 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.end(); } private void writeConsumingMap(XMLPrintWriter writer) { writer.startTAG(XML_CONSUMING_MAP); - writer.attr(ATTR_ACTIVITYKEY, (String)consumingMap.get("activitykey")); - writer.attr(ATTR_JAR_TIME, (String)consumingMap.get("jar_time")); - writer.attr(ATTR_CREATE_TIME, (String)consumingMap.get("create_time")); - writer.attr(ATTR_UUID, (String)consumingMap.get("uuid")); - writer.attr(ATTR_TIME_CONSUME, (long)consumingMap.get("time_consume")); - writer.attr(ATTR_VERSION, (String)consumingMap.get("version")); - writer.attr(ATTR_USERNAME, (String)consumingMap.get("username")); + 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, (long)consumingMap.get(ATTR_TIME_CONSUME)); + writer.attr(ATTR_VERSION, (String)consumingMap.get(ATTR_VERSION)); + writer.attr(ATTR_USERNAME, (String)consumingMap.get(ATTR_USERNAME)); writer.end(); } @@ -522,22 +524,22 @@ public class TemplateInfoCollector implements Serializable, XM try { String name = reader.getTagName(); if (XML_PROCESS_MAP.equals(name)) { - processMap.put("process", reader.getAttrAsString(ATTR_PROCESS, StringUtils.EMPTY)); - processMap.put("float_count", reader.getAttrAsInt(ATTR_FLOAT_COUNT, 0)); - processMap.put("widget_count", reader.getAttrAsInt(ATTR_WIDGET_COUNT, 0)); - processMap.put("cell_count", reader.getAttrAsInt(ATTR_CELL_COUNT, 0)); - processMap.put("block_count", reader.getAttrAsInt(ATTR_BLOCK_COUNT, 0)); - processMap.put("report_type", reader.getAttrAsInt(ATTR_REPORT_TYPE, 0)); - processMap.put("templateID", templateID); + processMap.put(ATTR_PROCESS, reader.getAttrAsString(ATTR_PROCESS, StringUtils.EMPTY)); + processMap.put(ATTR_FLOAT_COUNT, reader.getAttrAsInt(ATTR_FLOAT_COUNT, 0)); + processMap.put(ATTR_WIDGET_COUNT, reader.getAttrAsInt(ATTR_WIDGET_COUNT, 0)); + 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_TEMPLATE_ID, templateID); } else if(XML_CONSUMING_MAP.equals(name)){ - consumingMap.put("activitykey", reader.getAttrAsString(ATTR_ACTIVITYKEY, StringUtils.EMPTY)); - consumingMap.put("jar_time", reader.getAttrAsString(ATTR_JAR_TIME, StringUtils.EMPTY)); - consumingMap.put("create_time", reader.getAttrAsString(ATTR_CREATE_TIME, StringUtils.EMPTY)); - consumingMap.put("templateID", templateID); - consumingMap.put("uuid", reader.getAttrAsString(ATTR_UUID, StringUtils.EMPTY)); - consumingMap.put("time_consume", reader.getAttrAsLong(ATTR_TIME_CONSUME, 0)); - consumingMap.put("version", reader.getAttrAsString(ATTR_VERSION, "8.0")); - consumingMap.put("username", reader.getAttrAsString(ATTR_USERNAME, StringUtils.EMPTY)); + 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_UUID, reader.getAttrAsString(ATTR_UUID, StringUtils.EMPTY)); + consumingMap.put(ATTR_TIME_CONSUME, reader.getAttrAsLong(ATTR_TIME_CONSUME, 0)); + consumingMap.put(ATTR_VERSION, reader.getAttrAsString(ATTR_VERSION, "8.0")); + consumingMap.put(ATTR_USERNAME, reader.getAttrAsString(ATTR_USERNAME, StringUtils.EMPTY)); } } catch (Exception ex) { // 什么也不做,使用默认值 From a574cb0b6de6a0c358581086c4e659707f2f8182 Mon Sep 17 00:00:00 2001 From: plough Date: Fri, 28 Apr 2017 10:10:50 +0800 Subject: [PATCH 6/6] =?UTF-8?q?REPORT-2343=20[=E4=BB=A3=E7=A0=81=E8=B4=A8?= =?UTF-8?q?=E9=87=8F]=3D>=E5=8E=BB=E6=8E=89=E5=A4=9A=E4=BD=99=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../templateinfo/TemplateInfoCollector.java | 33 +------------------ 1 file changed, 1 insertion(+), 32 deletions(-) diff --git a/designer_base/src/com/fr/design/mainframe/templateinfo/TemplateInfoCollector.java b/designer_base/src/com/fr/design/mainframe/templateinfo/TemplateInfoCollector.java index 1a06d82c3..17d785a43 100644 --- a/designer_base/src/com/fr/design/mainframe/templateinfo/TemplateInfoCollector.java +++ b/designer_base/src/com/fr/design/mainframe/templateinfo/TemplateInfoCollector.java @@ -8,8 +8,6 @@ import com.fr.design.mainframe.JTemplate; import com.fr.env.RemoteEnv; import com.fr.general.*; import com.fr.general.http.HttpClient; -import com.fr.json.JSONArray; -import com.fr.json.JSONException; import com.fr.stable.*; import com.fr.stable.xml.*; import com.fr.third.javax.xml.stream.XMLStreamException; @@ -19,7 +17,6 @@ import java.io.*; import java.text.SimpleDateFormat; import java.util.*; import java.util.HashMap; -import java.util.Iterator; /** * 做模板的过程和耗时收集,辅助类 @@ -177,40 +174,13 @@ public class TemplateInfoCollector implements Serializable, XM */ private void saveInfo() { try { - ByteArrayOutputStream out = new ByteArrayOutputStream(); + FileOutputStream out = new FileOutputStream(getInfoFile()); XMLTools.writeOutputStreamXML(this, out); - out.flush(); - out.close(); - String fileContent = new String(out.toByteArray(), EncodeConstants.ENCODING_UTF_8); - writeContentToFile(fileContent, getInfoFile()); } catch (Exception ex) { FRLogger.getLogger().error(ex.getMessage()); } } - /** - * 将文件内容写到输出流中 - */ - private static void writeContentToFile(String fileContent, File file){ - BufferedWriter bw = null; - try { - FileOutputStream fos = new FileOutputStream(file); - OutputStreamWriter osw = new OutputStreamWriter(fos, EncodeConstants.ENCODING_UTF_8); - bw = new BufferedWriter(osw); - bw.write(fileContent); - } catch (Exception e) { - FRContext.getLogger().error(e.getMessage()); - } finally { - if(bw != null){ - try { - bw.close(); - } catch (IOException e) { - } - } - } - - } - /** * 更新 day_count:打开设计器却未编辑模板的连续日子 */ @@ -258,7 +228,6 @@ public class TemplateInfoCollector implements Serializable, XM // 保存模板时,让 day_count 归零 templateInfo.put(ATTR_DAY_COUNT, 0); - templateInfoList.put(templateID, templateInfo); saveInfo(); // 每次更新之后,都同步到暂存文件中