Browse Source

Merge remote-tracking branch 'origin/feature/10.0' into feature/10.0

research/11.0
Bryant 5 years ago
parent
commit
fa09775565
  1. 19
      designer-base/src/main/java/com/fr/design/gui/ispinner/UISpinner.java
  2. 28
      designer-base/src/main/java/com/fr/design/gui/ispinner/UnsignedIntUISpinner.java
  3. 107
      designer-base/src/main/java/com/fr/design/report/WatermarkPane.java
  4. 8
      designer-chart/src/main/java/com/fr/design/ChartTypeInterfaceManager.java
  5. 2
      designer-chart/src/main/java/com/fr/design/chart/ChartTypePane.java
  6. 12
      designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/ChartTypePane.java
  7. 2
      designer-chart/src/main/java/com/fr/extended/chart/ExtendedTypePane.java
  8. 7
      designer-chart/src/main/java/com/fr/van/chart/heatmap/designer/HeatMapIndependentVanChartInterface.java
  9. 644
      designer-realize/src/main/java/com/fr/design/mainframe/InformationCollector.java
  10. 9
      designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/StartupMessageCollector.java

19
designer-base/src/main/java/com/fr/design/gui/ispinner/UISpinner.java

@ -39,6 +39,7 @@ public class UISpinner extends JPanel implements UIObserver, GlobalNameObserver
private String spinnerName = StringUtils.EMPTY;
private UIObserverListener uiObserverListener;
private GlobalNameListener globalNameListener = null;
private boolean lessMinValue = false;
public UISpinner(double minValue, double maxValue, double dierta) {
@ -93,6 +94,18 @@ public class UISpinner extends JPanel implements UIObserver, GlobalNameObserver
return textField;
}
public UIButton getNextButton() {
return nextButton;
}
public boolean isLessMinValue() {
return lessMinValue;
}
public void resetLessMinValue() {
lessMinValue = false;
}
public void setValue(double value) {
setValue(value, true);
}
@ -109,7 +122,8 @@ public class UISpinner extends JPanel implements UIObserver, GlobalNameObserver
if (globalNameListener != null && shouldResponseNameListener()) {
globalNameListener.setGlobalName(spinnerName);
}
value = value < minValue ? minValue : value;
lessMinValue = value < minValue;
value = lessMinValue ? minValue : value;
value = value > maxValue ? maxValue : value;
if (CommonUtils.equals(value, this.value)) {
return;
@ -131,7 +145,8 @@ public class UISpinner extends JPanel implements UIObserver, GlobalNameObserver
if (globalNameListener != null && shouldResponseNameListener()) {
globalNameListener.setGlobalName(spinnerName);
}
value = value < minValue ? minValue : value;
lessMinValue = value < minValue;
value = lessMinValue ? minValue : value;
value = value > maxValue ? maxValue : value;
if (CommonUtils.equals(value, this.value)) {

28
designer-base/src/main/java/com/fr/design/gui/ispinner/UnsignedIntUISpinner.java

@ -3,8 +3,6 @@ package com.fr.design.gui.ispinner;
import com.fr.design.gui.itextfield.UIIntNumberField;
import com.fr.design.gui.itextfield.UINumberField;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
/**
* Created by IntelliJ IDEA.
@ -31,7 +29,7 @@ public class UnsignedIntUISpinner extends UISpinner {
@Override
protected UINumberField initNumberField() {
final UIIntNumberField numberField = new UIIntNumberField() {
return new UIIntNumberField() {
public boolean shouldResponseChangeListener() {
return false;
}
@ -44,29 +42,5 @@ public class UnsignedIntUISpinner extends UISpinner {
};
}
};
numberField.addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
}
/**
* 失去焦点后再做范围限制不然最小值为 100 输个 1 都不让....
* @param e
*/
@Override
public void focusLost(FocusEvent e) {
double value = numberField.getValue();
if (!isOverMaxOrMinValue(value)) {
return;
}
numberField.setValue(value < minValue ? minValue : maxValue);
}
private boolean isOverMaxOrMinValue(double value) {
return value < minValue || value > maxValue;
}
});
return numberField;
}
}

107
designer-base/src/main/java/com/fr/design/report/WatermarkPane.java

@ -23,6 +23,9 @@ import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.JDialog;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import java.awt.Dimension;
import java.awt.BorderLayout;
import java.awt.Color;
@ -30,6 +33,13 @@ import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.FocusAdapter;
import java.awt.Dialog;
import java.awt.FlowLayout;
/**
* Created by plough on 2018/5/15.
@ -49,6 +59,13 @@ public class WatermarkPane extends BasicPane {
private UISpinner verticalGapSpinner;
// 文字颜色
private NewColorSelectPane colorPane;
//间距超过限制消息
private UILabel message;
//横向间距最小值
public static final int HORIZONTAL_GAP_MIX = 100;
//纵向间距最小值
public static final int VERTICAL_GAP_MIX = 50;
private static final Dimension SPINNER_DIMENSION = new Dimension(75, 20);
@ -57,6 +74,7 @@ public class WatermarkPane extends BasicPane {
}
private void initComponents() {
message = new UILabel();
this.setBorder(BorderFactory.createEmptyBorder(4, 4, -5, 4));
this.setLayout(FRGUIPaneFactory.createBorderLayout());
@ -93,7 +111,7 @@ public class WatermarkPane extends BasicPane {
public WatermarkAttr update() {
WatermarkAttr watermark = new WatermarkAttr();
watermark.setText(formulaPane.getUITextField().getText());
watermark.setFontSize((int)fontSizeComboBox.getSelectedItem());
watermark.setFontSize((int) fontSizeComboBox.getSelectedItem());
watermark.setHorizontalGap((int) horizontalGapSpinner.getValue());
watermark.setVerticalGap((int) verticalGapSpinner.getValue());
watermark.setColor(colorPane.getColor());
@ -109,7 +127,7 @@ public class WatermarkPane extends BasicPane {
this.formulaPane = formulaPane;
}
protected UIScrollPane initRightPane(){
protected UIScrollPane initRightPane() {
formulaPane = new TinyFormulaPane();
fontSizeComboBox = new UIComboBox(FRFontPane.FONT_SIZES);
fontSizeComboBox.setEditable(true);
@ -117,7 +135,17 @@ public class WatermarkPane extends BasicPane {
verticalGapSpinner = new UnsignedIntUISpinner(50, Integer.MAX_VALUE, 1, 100);
horizontalGapSpinner.setPreferredSize(SPINNER_DIMENSION);
verticalGapSpinner.setPreferredSize(SPINNER_DIMENSION);
JPanel fontSizeTypePane = new JPanel(new BorderLayout(10,0));
message.setBorder(BorderFactory.createEmptyBorder(8, 5, 0, 0));
//失去焦点时要判断是否要弹出提示
horizontalGapSpinner.getTextField().addFocusListener(
createFocusListener4GapNumberField(horizontalGapSpinner, HORIZONTAL_GAP_MIX, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Horizontal_Gap_Over_Warning")));
verticalGapSpinner.getTextField().addFocusListener(createFocusListener4GapNumberField(verticalGapSpinner, VERTICAL_GAP_MIX, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Vertical_Gap_Over_Warning")));
//next 按钮 释放时也要判断是否要弹出提示
horizontalGapSpinner.getNextButton().addMouseListener(createMouseListener4GapNextButton(horizontalGapSpinner, HORIZONTAL_GAP_MIX, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Horizontal_Gap_Over_Warning")));
verticalGapSpinner.getNextButton().addMouseListener(createMouseListener4GapNextButton(verticalGapSpinner, VERTICAL_GAP_MIX, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Vertical_Gap_Over_Warning")));
JPanel fontSizeTypePane = new JPanel(new BorderLayout(10, 0));
fontSizeTypePane.add(fontSizeComboBox, BorderLayout.CENTER);
//水印间距面板
@ -144,18 +172,18 @@ public class WatermarkPane extends BasicPane {
JPanel rightContentPane = TableLayoutHelper.createCommonTableLayoutPane(new JComponent[][]{
{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Watermark_Text")), formulaPane},
{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Font_Size")), fontSizeTypePane},
{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Watermark_Gap")),watermarkGapPane },
{null,watermarkGapTipsPane },
{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Watermark_Gap")), watermarkGapPane},
{null, watermarkGapTipsPane},
{colorLabelPane, colorPane},
}, rowSize, columnSize, 10);
rightContentPane.setBorder(BorderFactory.createEmptyBorder(15, 12, 10, 12));
UIScrollPane configPane = new UIScrollPane(rightContentPane);
configPane.setBorder(GUICoreUtils.createTitledBorder(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Config"),null));
configPane.setBorder(GUICoreUtils.createTitledBorder(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Config"), null));
return configPane;
}
protected void populateFontSize(int fontSize){
protected void populateFontSize(int fontSize) {
this.fontSizeComboBox.setSelectedItem(fontSize);
this.fontSizeComboBox.addItemListener(new ItemListener() {
@Override
@ -165,7 +193,7 @@ public class WatermarkPane extends BasicPane {
});
}
protected void populateWatermarkGap(WatermarkAttr watermark){
protected void populateWatermarkGap(WatermarkAttr watermark) {
this.horizontalGapSpinner.setValue(watermark.getHorizontalGap());
this.horizontalGapSpinner.addUISpinnerFocusListenner(new FocusListener() {
@ -195,7 +223,7 @@ public class WatermarkPane extends BasicPane {
});
}
protected void paintPreviewPane(){
protected void paintPreviewPane() {
watermarkPreviewPane.repaint(update());
}
@ -235,4 +263,65 @@ public class WatermarkPane extends BasicPane {
protected String title4PopupWindow() {
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_WaterMark");
}
/**
* 创建水印间距文本段焦点监听器
*
* @return
*/
private FocusListener createFocusListener4GapNumberField(final UISpinner spinner, final int limitMinValue, final String messageStr) {
return new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
if (!spinner.isLessMinValue()) {
return;
}
spinner.resetLessMinValue();
createGapDialog(new StringBuilder(messageStr).append(limitMinValue).toString());
}
};
}
/**
* 创建水印间距微调器 NextButton 的鼠标释放监听器
*
* @param messageStr 提示消息
* @param limitMinValue 限制的最小值
* @return
*/
private MouseListener createMouseListener4GapNextButton(final UISpinner spinner, final int limitMinValue, final String messageStr) {
MouseAdapter mouseAdapter = new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent e) {
if (!spinner.isLessMinValue()) {
return;
}
spinner.resetLessMinValue();
createGapDialog(new StringBuilder(messageStr).append(limitMinValue).toString());
}
};
return mouseAdapter;
}
/**
* 创建超过水印间距限制的对话框
*
* @param messageStr 提示消息
*/
private void createGapDialog(String messageStr) {
JDialog dialog = new JDialog((Dialog) SwingUtilities.getWindowAncestor(WatermarkPane.this), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Joption_News"), true);
dialog.setSize(new Dimension(268, 118));
message.setText(messageStr);
JPanel upPane = new JPanel();
UILabel uiLabel = new UILabel(UIManager.getIcon("OptionPane.informationIcon"));
upPane.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 10));
upPane.add(uiLabel);
upPane.add(message);
dialog.add(upPane);
dialog.setResizable(false);
dialog.setLocationRelativeTo(SwingUtilities.getWindowAncestor(WatermarkPane.this));
dialog.setVisible(true);
dialog.dispose();
}
}

8
designer-chart/src/main/java/com/fr/design/ChartTypeInterfaceManager.java

@ -165,7 +165,7 @@ public class ChartTypeInterfaceManager implements ExtraChartDesignClassManagerPr
ChartWidgetOption[] child = new ChartWidgetOption[chartIDs.length];
int index = 0;
for (String chartID : chartIDs) {
ChartProvider[] rowChart = ChartTypeManager.getInstance().getChartTypes(chartID);
ChartProvider[] rowChart = ChartTypeManager.getInstance().getCharts(chartID);
if (ArrayUtils.isEmpty(rowChart) && !ChartTypeManager.innerChart(chartID)) {
continue;
}
@ -364,7 +364,7 @@ public class ChartTypeInterfaceManager implements ExtraChartDesignClassManagerPr
try {
//兼容 图表类型选择界面会调到这边
ChartProvider[] charts = ChartTypeManager.getInstanceWithCheck().getChartTypes(chartID);
ChartProvider[] charts = ChartTypeManager.getInstanceWithCheck().getCharts(chartID);
result = new String[charts.length];
for (int i = 0; i < charts.length; i++) {
//Chart && AbstractChart
@ -403,7 +403,7 @@ public class ChartTypeInterfaceManager implements ExtraChartDesignClassManagerPr
//兼容
private String[] getCompatibleSubName(String chartID, ChartTypeUIProvider provider) {
ChartProvider[] chartProviders = ChartTypeManager.getInstanceWithCheck().getChartTypes(chartID);
ChartProvider[] chartProviders = ChartTypeManager.getInstanceWithCheck().getCharts(chartID);
if (chartProviders.length == 1) {
return new String[]{getName(chartID)};
@ -453,7 +453,7 @@ public class ChartTypeInterfaceManager implements ExtraChartDesignClassManagerPr
try {
ChartProvider chartProvider = ChartTypeManager.getInstanceWithCheck().getChartTypes(chartID)[0];
ChartProvider chartProvider = ChartTypeManager.getInstanceWithCheck().getCharts(chartID)[0];
if (chartProvider instanceof Chart) {
//AbstractExtendedChartUIProvider
result = ((Chart) chartProvider).getChartName();

2
designer-chart/src/main/java/com/fr/design/chart/ChartTypePane.java

@ -126,7 +126,7 @@ public class ChartTypePane extends ChartCommonWizardPane {
ChartProvider chart4Update = cc.getSelectedChartProvider();
if (chart4Update == null) {
String plotID = this.chartIDs[mainTypeList.getSelectedIndex()];
ChartProvider chart = ChartTypeManager.getInstance().getChartTypes(plotID)[iconViewList.getSelectedIndex()];
ChartProvider chart = ChartTypeManager.getInstance().getCharts(plotID)[iconViewList.getSelectedIndex()];
try {
chart4Update = (ChartProvider) chart.clone();
cc.addChart(chart4Update);

12
designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/ChartTypePane.java

@ -19,15 +19,15 @@ import com.fr.log.FineLoggerFactory;
import com.fr.stable.StringUtils;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
/**
* 图表 属性表, 类型选择 界面.
@ -124,7 +124,8 @@ public class ChartTypePane extends AbstractChartAttrPane{
String lastPlotID = chart.getID();
try{
ChartProvider newDefaultChart = (ChartProvider) ((AbstractChartTypePane) getSelectedPane()).getDefaultChart().clone();
AbstractChartTypePane selectedPane = (AbstractChartTypePane) getSelectedPane();
ChartProvider newDefaultChart =(ChartProvider) ChartTypeManager.getInstanceWithCheck().getCharts(selectedPane.getPlotID())[0].clone();
if (!ComparatorUtils.equals(chart.getClass(), newDefaultChart.getClass())) {
//vanChart 和 chart 之间切换
//不同chart之间切换
@ -135,7 +136,6 @@ public class ChartTypePane extends AbstractChartAttrPane{
}catch (CloneNotSupportedException e){
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
//这一步会替换plot
((AbstractChartTypePane)getSelectedPane()).updateBean(chart);

2
designer-chart/src/main/java/com/fr/extended/chart/ExtendedTypePane.java

@ -67,7 +67,7 @@ public class ExtendedTypePane<T extends AbstractChart> extends AbstractChartType
@Override
public ChartProvider getDefaultChart() {
return ChartTypeManager.getInstance().getChartTypes(getPlotID())[0];
return ChartTypeManager.getInstance().getCharts(getPlotID())[0];
}
@Override

7
designer-chart/src/main/java/com/fr/van/chart/heatmap/designer/HeatMapIndependentVanChartInterface.java

@ -38,6 +38,13 @@ public class HeatMapIndependentVanChartInterface extends MapIndependentVanChartI
return Toolkit.i18nText("Fine-Design_Chart_New_HeatMap");
}
@Override
public String[] getSubName() {
return new String[]{
Toolkit.i18nText("Fine-Design_Chart_New_HeatMap"),
};
}
@Override
public String[] getDemoImagePath() {
return new String[]{

644
designer-realize/src/main/java/com/fr/design/mainframe/InformationCollector.java

@ -30,6 +30,7 @@ import com.fr.stable.xml.XMLTools;
import com.fr.stable.xml.XMLWriter;
import com.fr.stable.xml.XMLableReader;
import com.fr.third.javax.xml.stream.XMLStreamException;
import com.sun.management.OperatingSystemMXBean;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
@ -43,11 +44,14 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.lang.management.ManagementFactory;
import java.nio.charset.StandardCharsets;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
@ -58,309 +62,339 @@ import java.util.concurrent.TimeUnit;
*/
public class InformationCollector implements XMLReadable, XMLWriter {
// 24小时上传一次
private static final long DELTA = 24 * 3600 * 1000L;
private static final long SEND_DELAY = 300 * 1000L;
private static final String FILE_NAME = "fr.info";
private static final String XML_START_STOP_LIST = "StartStopList";
private static final String XML_START_STOP = "StartStop";
private static final String XML_LAST_TIME = "LastTime";
private static final String ATTR_START = "start";
private static final String ATTR_STOP = "stop";
private static final String XML_JAR = "JarInfo";
private static final String XML_VERSION = "Version";
private static final String XML_USERNAME = "Username";
private static final String XML_UUID = "UUID";
private static final String XML_KEY = "ActiveKey";
private static final String XML_OS = "OS";
private static InformationCollector collector;
//启动时间与关闭时间列表
private List<StartStopTime> startStop = new ArrayList<StartStopTime>();
//上一次的发送时间
private String lastTime;
private StartStopTime current = new StartStopTime();
public static InformationCollector getInstance() {
if (collector == null) {
collector = new InformationCollector();
readEncodeXMLFile(collector, collector.getInfoFile());
}
return collector;
}
private static void readEncodeXMLFile(XMLReadable xmlReadable, File xmlFile) {
if (xmlFile == null || !xmlFile.exists()) {
return;
}
String charset = EncodeConstants.ENCODING_UTF_8;
try {
String decodeContent = getDecodeFileContent(xmlFile);
InputStream xmlInputStream = new ByteArrayInputStream(decodeContent.getBytes(charset));
InputStreamReader inputStreamReader = new InputStreamReader(xmlInputStream, charset);
XMLableReader xmlReader = XMLableReader.createXMLableReader(inputStreamReader);
if (xmlReader != null) {
xmlReader.readXMLObject(xmlReadable);
}
xmlInputStream.close();
} catch (FileNotFoundException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
} catch (IOException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
} catch (XMLStreamException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
private static String getDecodeFileContent(File xmlFile) throws FileNotFoundException, UnsupportedEncodingException {
InputStream encodeInputStream = new FileInputStream(xmlFile);
String encodeContent = IOUtils.inputStream2String(encodeInputStream);
return DesUtils.getDecString(encodeContent);
}
private long getLastTimeMillis() {
if (StringUtils.isEmpty(this.lastTime)) {
return 0;
}
try {
return DateUtils.string2Date(this.lastTime, true).getTime();
} catch (Exception e) {
return -1;
}
}
private JSONObject getJSONContentAsByte() {
JSONObject content = new JSONObject();
JSONArray startStopArray = new JSONArray();
for (int i = 0; i < startStop.size(); i++) {
JSONObject jo = new JSONObject();
jo.put(ATTR_START, startStop.get(i).getStartDate());
jo.put(ATTR_STOP, startStop.get(i).getStopDate());
startStopArray.put(jo);
DesignerEnvManager envManager = DesignerEnvManager.getEnvManager();
content.put(XML_START_STOP, startStopArray);
content.put(XML_UUID, envManager.getUUID());
content.put(XML_JAR, GeneralUtils.readBuildNO());
content.put(XML_VERSION, ProductConstants.RELEASE_VERSION);
content.put(XML_USERNAME, MarketConfig.getInstance().getBbsUsername());
content.put(XML_KEY, envManager.getActivationKey());
content.put(XML_OS, System.getProperty("os.name"));
}
return content;
}
private void sendUserInfo() {
long currentTime = new Date().getTime();
long lastTime = getLastTimeMillis();
if (currentTime - lastTime <= DELTA) {
return;
}
JSONObject content = getJSONContentAsByte();
String url = CloudCenter.getInstance().acquireUrlByKind("user.info.v10");
boolean success = false;
try {
HashMap<String, Object> para = new HashMap<>();
para.put("token", SiteCenterToken.generateToken());
para.put("content", content);
String res = HttpToolbox.post(url, para);
success = ComparatorUtils.equals(new JSONObject(res).get("status"), "success");
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
if (success) {
this.reset();
}
}
/**
* 收集开始使用时间发送信息
*/
public void collectStartTime() {
this.current.setStartDate(dateToString());
sendUserInfoInOtherThread();
}
private void sendUserInfoInOtherThread() {
if (!DesignerEnvManager.getEnvManager().isJoinProductImprove() || !FRContext.isChineseEnv()) {
return;
}
ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("InformationCollector"));
service.schedule(new Runnable() {
@Override
public void run() {
sendUserInfo();
FocusPointMessageUploader.getInstance().sendToCloudCenter();
TemplateInfoCollector.getInstance().sendTemplateInfo();
ErrorInfoUploader.getInstance().sendErrorInfo();
}
}, SEND_DELAY, TimeUnit.MILLISECONDS);
}
/**
* 收集结束使用时间
*/
public void collectStopTime() {
this.current.setStopDate(dateToString());
}
private String dateToString() {
DateFormat df = FRContext.getDefaultValues().getDateTimeFormat();
return df.format(new Date());
}
private void reset() {
this.startStop.clear();
this.lastTime = dateToString();
}
private File getInfoFile() {
return new File(StableUtils.pathJoin(ProductConstants.getEnvHome(), FILE_NAME));
}
/**
* 保存xml文件
*/
public void saveXMLFile() {
File xmlFile = this.getInfoFile();
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
XMLTools.writeOutputStreamXML(this, out);
out.flush();
out.close();
String fileContent = new String(out.toByteArray(), EncodeConstants.ENCODING_UTF_8);
String encodeCotent = DesUtils.getEncString(fileContent);
writeEncodeContentToFile(encodeCotent, xmlFile);
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
/**
* 将文件内容写到输出流中
*/
private static void writeEncodeContentToFile(String fileContent, File file) {
try (FileOutputStream fos = new FileOutputStream(file);
OutputStreamWriter osw = new OutputStreamWriter(fos, EncodeConstants.ENCODING_UTF_8);
BufferedWriter bw = new BufferedWriter(osw)) {
bw.write(fileContent);
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
@Override
public void writeXML(XMLPrintWriter writer) {
startStop.add(current);
writer.startTAG("Info");
//启停信息
writeStartStopList(writer);
//上一次更新的时间
writeTag(XML_LAST_TIME, this.lastTime, writer);
writer.end();
}
private void writeStartStopList(XMLPrintWriter writer) {
//启停
writer.startTAG(XML_START_STOP_LIST);
for (int i = 0; i < startStop.size(); i++) {
startStop.get(i).writeXML(writer);
}
writer.end();
}
private void writeTag(String tag, String content, XMLPrintWriter writer) {
if (StringUtils.isEmpty(content)) {
return;
}
writer.startTAG(tag);
writer.textNode(content);
writer.end();
}
@Override
public void readXML(XMLableReader reader) {
if (reader.isChildNode()) {
String name = reader.getTagName();
if (XML_START_STOP_LIST.equals(name)) {
readStartStopList(reader);
} else if (XML_LAST_TIME.equals(name)) {
readLastTime(reader);
}
}
}
private void readLastTime(XMLableReader reader) {
String tmpVal;
if (StringUtils.isNotBlank(tmpVal = reader.getElementValue())) {
this.lastTime = tmpVal;
}
}
private void readStartStopList(XMLableReader reader) {
startStop.clear();
reader.readXMLObject(new XMLReadable() {
public void readXML(XMLableReader reader) {
if (XML_START_STOP.equals(reader.getTagName())) {
StartStopTime startStopTime = new StartStopTime();
reader.readXMLObject(startStopTime);
startStop.add(startStopTime);
}
}
});
}
private class StartStopTime implements XMLReadable, XMLWriter {
private String startDate;
private String stopDate;
public String getStartDate() {
return startDate;
}
public void setStartDate(String startDate) {
this.startDate = startDate;
}
public String getStopDate() {
return stopDate;
}
public void setStopDate(String endDate) {
this.stopDate = endDate;
}
public void writeXML(XMLPrintWriter writer) {
writer.startTAG(XML_START_STOP);
if (StringUtils.isNotEmpty(startDate)) {
writer.attr(ATTR_START, this.startDate);
}
if (StringUtils.isNotEmpty(stopDate)) {
writer.attr(ATTR_STOP, this.stopDate);
}
writer.end();
}
public void readXML(XMLableReader reader) {
this.startDate = reader.getAttrAsString(ATTR_START, StringUtils.EMPTY);
this.stopDate = reader.getAttrAsString(ATTR_STOP, StringUtils.EMPTY);
}
}
/**
* 24小时上传一次
*/
private static final long DELTA = 24 * 3600 * 1000L;
private static final long SEND_DELAY = 300 * 1000L;
private static final int BYTE_TO_MB = 1024 * 1024;
private static final String FILE_NAME = "fr.info";
private static final String XML_START_STOP_LIST = "StartStopList";
private static final String XML_START_STOP = "StartStop";
private static final String XML_LAST_TIME = "LastTime";
private static final String ATTR_START = "start";
private static final String ATTR_STOP = "stop";
private static final String XML_JAR = "JarInfo";
private static final String XML_VERSION = "Version";
private static final String XML_USERNAME = "Username";
private static final String XML_UUID = "UUID";
private static final String XML_KEY = "ActiveKey";
private static final String XML_OS = "OS";
private static final String XML_ARCH = "arch";
private static final String XML_AVAILABLE_PROCESSORS = "cpu";
private static final String XML_PHYSICAL_MEMORY = "systemMemory";
private static InformationCollector collector;
/**
* 启动时间与关闭时间列表
*/
private List<StartStopTime> startStop = new ArrayList<StartStopTime>();
/**
* 上一次的发送时间
*/
private String lastTime;
private StartStopTime current = new StartStopTime();
public static InformationCollector getInstance() {
if (collector == null) {
collector = new InformationCollector();
readEncodeXMLFile(collector, collector.getInfoFile());
}
return collector;
}
private static void readEncodeXMLFile(XMLReadable xmlReadable, File xmlFile) {
if (xmlFile == null || !xmlFile.exists()) {
return;
}
String charset = EncodeConstants.ENCODING_UTF_8;
try {
String decodeContent = getDecodeFileContent(xmlFile);
InputStream xmlInputStream = new ByteArrayInputStream(decodeContent.getBytes(charset));
InputStreamReader inputStreamReader = new InputStreamReader(xmlInputStream, charset);
XMLableReader xmlReader = XMLableReader.createXMLableReader(inputStreamReader);
if (xmlReader != null) {
xmlReader.readXMLObject(xmlReadable);
}
xmlInputStream.close();
} catch (FileNotFoundException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
} catch (IOException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
} catch (XMLStreamException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
private static String getDecodeFileContent(File xmlFile) throws FileNotFoundException, UnsupportedEncodingException {
InputStream encodeInputStream = new FileInputStream(xmlFile);
String encodeContent = IOUtils.inputStream2String(encodeInputStream);
return DesUtils.getDecString(encodeContent);
}
private long getLastTimeMillis() {
if (StringUtils.isEmpty(this.lastTime)) {
return 0;
}
try {
return Objects.requireNonNull(DateUtils.string2Date(this.lastTime, true)).getTime();
} catch (Exception e) {
return -1;
}
}
private JSONObject getJSONContentAsByte() {
JSONObject content = new JSONObject();
JSONArray startStopArray = new JSONArray();
for (StartStopTime startStopTime : startStop) {
JSONObject jo = new JSONObject();
jo.put(ATTR_START, startStopTime.getStartDate());
jo.put(ATTR_STOP, startStopTime.getStopDate());
startStopArray.put(jo);
}
DesignerEnvManager envManager = DesignerEnvManager.getEnvManager();
content.put(XML_START_STOP, startStopArray);
content.put(XML_UUID, envManager.getUUID());
content.put(XML_JAR, GeneralUtils.readBuildNO());
content.put(XML_VERSION, ProductConstants.RELEASE_VERSION);
content.put(XML_USERNAME, MarketConfig.getInstance().getBbsUsername());
content.put(XML_KEY, envManager.getActivationKey());
content.put(XML_OS, System.getProperty("os.name"));
content.put(XML_ARCH, System.getProperty("os.arch"));
content.put(XML_AVAILABLE_PROCESSORS, Runtime.getRuntime().availableProcessors());
content.put(XML_PHYSICAL_MEMORY, getTotalPhysicalMemorySize());
return content;
}
/**
* 获取物理内存单位GB
*
* @return 物理内存
*/
private static long getTotalPhysicalMemorySize() {
OperatingSystemMXBean bean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
return bean.getTotalPhysicalMemorySize() / BYTE_TO_MB;
}
private void sendUserInfo() {
long currentTime = System.currentTimeMillis();
long lastTime = getLastTimeMillis();
if (currentTime - lastTime <= DELTA) {
return;
}
JSONObject content = getJSONContentAsByte();
String url = CloudCenter.getInstance().acquireUrlByKind("user.info.v10");
boolean success = false;
try {
HashMap<String, Object> para = new HashMap<>();
para.put("token", SiteCenterToken.generateToken());
para.put("content", content);
String res = HttpToolbox.post(url, para);
success = ComparatorUtils.equals(new JSONObject(res).get("status"), "success");
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
if (success) {
this.reset();
}
}
/**
* 收集开始使用时间发送信息
*/
public void collectStartTime() {
this.current.setStartDate(dateToString());
sendUserInfoInOtherThread();
}
private void sendUserInfoInOtherThread() {
if (!DesignerEnvManager.getEnvManager().isJoinProductImprove() || !FRContext.isChineseEnv()) {
return;
}
ScheduledExecutorService service = Executors
.newSingleThreadScheduledExecutor(new NamedThreadFactory("InformationCollector"));
service.schedule(new Runnable() {
@Override
public void run() {
sendUserInfo();
FocusPointMessageUploader.getInstance().sendToCloudCenter();
TemplateInfoCollector.getInstance().sendTemplateInfo();
ErrorInfoUploader.getInstance().sendErrorInfo();
}
}, SEND_DELAY, TimeUnit.MILLISECONDS);
service.shutdown();
}
/**
* 收集结束使用时间
*/
public void collectStopTime() {
this.current.setStopDate(dateToString());
}
private String dateToString() {
DateFormat df = FRContext.getDefaultValues().getDateTimeFormat();
return df.format(new Date());
}
private void reset() {
this.startStop.clear();
this.lastTime = dateToString();
}
private File getInfoFile() {
return new File(StableUtils.pathJoin(ProductConstants.getEnvHome(), FILE_NAME));
}
/**
* 保存xml文件
*/
public void saveXMLFile() {
File xmlFile = this.getInfoFile();
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
XMLTools.writeOutputStreamXML(this, out);
out.flush();
out.close();
String fileContent = new String(out.toByteArray(), StandardCharsets.UTF_8);
String encodeCotent = DesUtils.getEncString(fileContent);
writeEncodeContentToFile(encodeCotent, xmlFile);
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
/**
* 将文件内容写到输出流中
*/
private static void writeEncodeContentToFile(String fileContent, File file) {
try (FileOutputStream fos = new FileOutputStream(file);
OutputStreamWriter osw = new OutputStreamWriter(fos, StandardCharsets.UTF_8);
BufferedWriter bw = new BufferedWriter(osw)) {
bw.write(fileContent);
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
@Override
public void writeXML(XMLPrintWriter writer) {
startStop.add(current);
writer.startTAG("Info");
//启停信息
writeStartStopList(writer);
//上一次更新的时间
writeTag(XML_LAST_TIME, this.lastTime, writer);
writer.end();
}
private void writeStartStopList(XMLPrintWriter writer) {
//启停
writer.startTAG(XML_START_STOP_LIST);
for (StartStopTime startStopTime : startStop) {
startStopTime.writeXML(writer);
}
writer.end();
}
private void writeTag(String tag, String content, XMLPrintWriter writer) {
if (StringUtils.isEmpty(content)) {
return;
}
writer.startTAG(tag);
writer.textNode(content);
writer.end();
}
@Override
public void readXML(XMLableReader reader) {
if (reader.isChildNode()) {
String name = reader.getTagName();
if (XML_START_STOP_LIST.equals(name)) {
readStartStopList(reader);
} else if (XML_LAST_TIME.equals(name)) {
readLastTime(reader);
}
}
}
private void readLastTime(XMLableReader reader) {
String tmpVal;
if (StringUtils.isNotBlank(tmpVal = reader.getElementValue())) {
this.lastTime = tmpVal;
}
}
private void readStartStopList(XMLableReader reader) {
startStop.clear();
reader.readXMLObject(new XMLReadable() {
@Override
public void readXML(XMLableReader reader) {
if (XML_START_STOP.equals(reader.getTagName())) {
StartStopTime startStopTime = new StartStopTime();
reader.readXMLObject(startStopTime);
startStop.add(startStopTime);
}
}
});
}
private class StartStopTime implements XMLReadable, XMLWriter {
private String startDate;
private String stopDate;
public String getStartDate() {
return startDate;
}
public void setStartDate(String startDate) {
this.startDate = startDate;
}
public String getStopDate() {
return stopDate;
}
public void setStopDate(String endDate) {
this.stopDate = endDate;
}
@Override
public void writeXML(XMLPrintWriter writer) {
writer.startTAG(XML_START_STOP);
if (StringUtils.isNotEmpty(startDate)) {
writer.attr(ATTR_START, this.startDate);
}
if (StringUtils.isNotEmpty(stopDate)) {
writer.attr(ATTR_STOP, this.stopDate);
}
writer.end();
}
@Override
public void readXML(XMLableReader reader) {
this.startDate = reader.getAttrAsString(ATTR_START, StringUtils.EMPTY);
this.stopDate = reader.getAttrAsString(ATTR_STOP, StringUtils.EMPTY);
}
}
}

9
designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/StartupMessageCollector.java

@ -8,6 +8,7 @@ import com.fr.event.EventDispatcher;
import com.fr.event.Listener;
import com.fr.general.CloudCenter;
import com.fr.general.ComparatorUtils;
import com.fr.general.GeneralUtils;
import com.fr.general.http.HttpToolbox;
import com.fr.json.JSONObject;
import com.fr.log.FineLoggerFactory;
@ -30,14 +31,15 @@ public class StartupMessageCollector {
private static final String XML_STARTUP_TIME = "t";
private static final String XML_STARTUP_LOG = "startupLog";
private static final String XML_STARTUP_Memory = "designerMemory";
private static final String XML_STARTUP_MEMORY = "designerMemory";
private static final String XML_STARTUP_COST = "cost";
private static final String XML_UUID = "UUID";
private static final String XML_BUILD_NO = "buildNO";
private static final String STARTUP_URL_KEY = "user.info.v10.startup";
private static final String LOG_TYPE = "single";
private static final int BYTE_TO_MB = 1024 * 1024;
public static final StartupMessageCollector INSTANCE = new StartupMessageCollector();
private static final StartupMessageCollector INSTANCE = new StartupMessageCollector();
private StartupMessageCollector() {
}
@ -67,10 +69,11 @@ public class StartupMessageCollector {
}
JSONObject json = JSONObject.create()
.put(XML_UUID, DesignerEnvManager.getEnvManager().getUUID())
.put(XML_BUILD_NO, GeneralUtils.readBuildNO())
.put(XML_STARTUP_TIME, FineRuntime.getAppStartTime() + FineRuntime.getStartingTime())
.put(XML_STARTUP_COST, FineRuntime.getStartingTime())
.put(XML_STARTUP_LOG, profile)
.put(XML_STARTUP_Memory, Runtime.getRuntime().totalMemory() / BYTE_TO_MB);
.put(XML_STARTUP_MEMORY, Runtime.getRuntime().maxMemory() / BYTE_TO_MB);
sendInfo(json, url + LOG_TYPE);
}
});

Loading…
Cancel
Save