From 77d2acb32a808368a58ebea6bfd54dc6bfe0cb87 Mon Sep 17 00:00:00 2001 From: "alex.sung" Date: Tue, 18 Sep 2018 11:47:13 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-10946=20@Sung=EF=BC=9A=E7=A6=BB=E7=BA=BF?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E4=B8=8B=EF=BC=88=E6=96=AD=E7=BD=91=EF=BC=89?= =?UTF-8?q?alphafine=E9=83=BD=E6=89=93=E4=B8=8D=E5=BC=80=E4=BA=86=20?= =?UTF-8?q?=E4=B9=8B=E5=89=8D=E7=9A=84=E6=96=AD=E7=BD=91=E6=83=85=E5=86=B5?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E8=80=A6=E5=90=88=E5=A4=AA=E4=B8=A5=E9=87=8D?= =?UTF-8?q?=E4=BA=86=EF=BC=8C=E5=89=A5=E7=A6=BB=E5=87=BA=E6=9D=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mainframe/alphafine/AlphaFineHelper.java | 20 ++++++++++++++++++ .../alphafine/component/AlphaFineDialog.java | 21 +++++++------------ .../manager/fun/AlphaFineSearchProvider.java | 2 +- .../manager/impl/ActionSearchManager.java | 2 +- .../manager/impl/DocumentSearchManager.java | 4 ++-- .../manager/impl/FileSearchManager.java | 2 +- .../manager/impl/PluginSearchManager.java | 4 ++-- .../manager/impl/RecentSearchManager.java | 2 +- .../manager/impl/RecommendSearchManager.java | 4 ++-- .../manager/impl/SimilarSearchManeger.java | 4 ++-- 10 files changed, 40 insertions(+), 25 deletions(-) diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/AlphaFineHelper.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/AlphaFineHelper.java index 763c822a9f..433710ce76 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/AlphaFineHelper.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/AlphaFineHelper.java @@ -16,11 +16,15 @@ import com.fr.design.mainframe.alphafine.search.manager.impl.RecentSearchManager import com.fr.design.mainframe.alphafine.search.manager.impl.RecommendSearchManager; import com.fr.design.mainframe.alphafine.search.manager.impl.SimilarSearchManeger; import com.fr.general.ProcessCanceledException; +import com.fr.general.http.HttpToolbox; import com.fr.json.JSONArray; import com.fr.json.JSONException; import com.fr.json.JSONObject; import com.fr.json.JSONUtils; import com.fr.stable.StringUtils; +import com.fr.third.org.apache.http.HttpStatus; +import com.fr.third.org.apache.http.StatusLine; +import com.fr.third.org.apache.http.client.methods.HttpGet; import java.util.List; @@ -30,6 +34,7 @@ import java.util.List; public class AlphaFineHelper { public static final NoResultModel NO_CONNECTION_MODEL = new NoResultModel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Connection_Failed")); private static AlphaFineDialog alphaFineDialog; + private static final String URL_FOR_TEST_NETWORK = "https://www.baidu.com"; /** * 弹出alphafine搜索面板 @@ -145,4 +150,19 @@ public class AlphaFineHelper { result.add(AlphaFineHelper.NO_CONNECTION_MODEL); return result; } + + /** + * 判断网络是否异常 + * @return + */ + public static boolean isNetworkOk(){ + HttpGet getHelp = new HttpGet(URL_FOR_TEST_NETWORK); + try { + StatusLine statusLine = HttpToolbox.getHttpClient(URL_FOR_TEST_NETWORK).execute(getHelp).getStatusLine(); + return statusLine.getStatusCode() == HttpStatus.SC_OK; + } catch (Exception ignore) { + // 网络异常 + return false; + } + } } diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java index ff61edda09..e8b7747049 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java @@ -39,7 +39,6 @@ import com.fr.form.main.Form; import com.fr.form.main.FormIO; import com.fr.general.ComparatorUtils; import com.fr.general.http.HttpClient; -import com.fr.general.http.HttpToolbox; import com.fr.io.TemplateWorkBookIO; import com.fr.io.exporter.ImageExporter; import com.fr.json.JSONException; @@ -49,7 +48,6 @@ import com.fr.main.impl.WorkBook; import com.fr.stable.CodeUtils; import com.fr.stable.StringUtils; import com.fr.stable.project.ProjectConstants; -import com.fr.third.org.apache.http.client.methods.HttpGet; import javax.imageio.ImageIO; import javax.swing.BorderFactory; @@ -247,22 +245,19 @@ public class AlphaFineDialog extends UIDialog { GridLayout gridLayout = new GridLayout(2, 3, 3, 3); JPanel panel = new JPanel(); panel.setLayout(gridLayout); - try { - HttpGet getHelp = new HttpGet(AlphaFineConstants.ALPHA_HOT_SEARCH); - HttpToolbox.getHttpClient(AlphaFineConstants.ALPHA_HOT_SEARCH).execute(getHelp).getStatusLine(); + if(AlphaFineHelper.isNetworkOk()) { if (hotData == null) { hotData = HotIssuesManager.getInstance().getHotIssues(); } for (int i = 0; i < hotData.length; i++) { panel.add(new HotIssueJpanel(hotData[i], i + 1)); } - } catch (Exception e) { + }else { hotData = null; for (int i = 0; i < AlphaFineConstants.HOT_ITEMS; i++) { panel.add(new HotIssueJpanel(new String[]{com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Connection_Failed")}, i + 1)); } } - hotPane.add(uiLabel, BorderLayout.NORTH); hotPane.add(panel, BorderLayout.CENTER); add(hotPane, BorderLayout.SOUTH); @@ -552,7 +547,7 @@ public class AlphaFineDialog extends UIDialog { } private void buildDocumentList(final String[] searchText) { - addSearchResult(DocumentSearchManager.getInstance().getLessSearchResult(getHotData(), searchText)); + addSearchResult(DocumentSearchManager.getInstance().getLessSearchResult(searchText)); } private void buildFileList(String searchStr, final String[] searchText) { @@ -560,24 +555,24 @@ public class AlphaFineDialog extends UIDialog { } private void buildActionList(final String[] searchText) { - addSearchResult(ActionSearchManager.getInstance().getLessSearchResult(getHotData(), searchText)); + addSearchResult(ActionSearchManager.getInstance().getLessSearchResult(searchText)); } private void buildPluginList(final String[] searchText) { - addSearchResult(PluginSearchManager.getInstance().getLessSearchResult(getHotData(), searchText)); + addSearchResult(PluginSearchManager.getInstance().getLessSearchResult(searchText)); } private void buildRecommendList(final String[] searchText) { - addSearchResult(RecommendSearchManager.getInstance().getLessSearchResult(getHotData(), searchText)); + addSearchResult(RecommendSearchManager.getInstance().getLessSearchResult(searchText)); } private void buildRecentList(final String[] searchText) { - addSearchResult(RecentSearchManager.getInstance().getLessSearchResult(getHotData(), searchText)); + addSearchResult(RecentSearchManager.getInstance().getLessSearchResult(searchText)); } private void buildSimilarList(final String[] searchText) { - addSearchResult(SimilarSearchManeger.getInstance().getLessSearchResult(getHotData(), searchText)); + addSearchResult(SimilarSearchManeger.getInstance().getLessSearchResult(searchText)); } private synchronized void addSearchResult(SearchResult searchResult) { diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/fun/AlphaFineSearchProvider.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/fun/AlphaFineSearchProvider.java index 154e7c858e..b75aa894c4 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/fun/AlphaFineSearchProvider.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/fun/AlphaFineSearchProvider.java @@ -12,7 +12,7 @@ public interface AlphaFineSearchProvider { * @param searchText * @return */ - SearchResult getLessSearchResult(String[][] data, String[] searchText); + SearchResult getLessSearchResult(String[] searchText); /** * 获取剩余条数 diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/ActionSearchManager.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/ActionSearchManager.java index 97bfde18d0..1c4fec0903 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/ActionSearchManager.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/ActionSearchManager.java @@ -57,7 +57,7 @@ public class ActionSearchManager implements AlphaFineSearchProvider { } @Override - public SearchResult getLessSearchResult(String[][] hotData, String[] searchText) { + public SearchResult getLessSearchResult(String[] searchText) { filterModelList = new SearchResult(); lessModelList = new SearchResult(); moreModelList = new SearchResult(); diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/DocumentSearchManager.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/DocumentSearchManager.java index 1003c0e21b..d2ba8b8b07 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/DocumentSearchManager.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/DocumentSearchManager.java @@ -51,14 +51,14 @@ public class DocumentSearchManager implements AlphaFineSearchProvider { } @Override - public SearchResult getLessSearchResult(String[][] hotData, String[] searchText) { + public SearchResult getLessSearchResult(String[] searchText) { lessModelList = new SearchResult(); moreModelList = new SearchResult(); if (DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().isContainDocument()) { if (ArrayUtils.isEmpty(searchText)) { lessModelList.add(new MoreModel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Community_Help"))); return lessModelList; - } else if (hotData == null) { + } else if (!AlphaFineHelper.isNetworkOk()) { return AlphaFineHelper.getNoConnectList(instance); } SearchResult searchResult = new SearchResult(); diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/FileSearchManager.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/FileSearchManager.java index c7972753ca..17c58998df 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/FileSearchManager.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/FileSearchManager.java @@ -96,7 +96,7 @@ public class FileSearchManager implements AlphaFineSearchProvider { } @Override - public SearchResult getLessSearchResult(String[][] hotData, String[] searchText) { + public SearchResult getLessSearchResult(String[] searchText) { return null; } diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/PluginSearchManager.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/PluginSearchManager.java index 0feff55215..293ba51e30 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/PluginSearchManager.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/PluginSearchManager.java @@ -96,7 +96,7 @@ public class PluginSearchManager implements AlphaFineSearchProvider { } @Override - public SearchResult getLessSearchResult(String[][] hotData, String[] searchText) { + public SearchResult getLessSearchResult(String[] searchText) { this.lessModelList = new SearchResult(); this.moreModelList = new SearchResult(); SearchResult searchResult = new SearchResult(); @@ -104,7 +104,7 @@ public class PluginSearchManager implements AlphaFineSearchProvider { if (ArrayUtils.isEmpty(searchText)) { lessModelList.add(new MoreModel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Plugin_Addon"))); return lessModelList; - } else if (hotData == null) { + } else if (!AlphaFineHelper.isNetworkOk()) { return AlphaFineHelper.getNoConnectList(instance); } for (int j = 0; j < searchText.length; j++) { diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/RecentSearchManager.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/RecentSearchManager.java index 38f413423a..866c2c7349 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/RecentSearchManager.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/RecentSearchManager.java @@ -72,7 +72,7 @@ public class RecentSearchManager implements AlphaFineSearchProvider { } @Override - public SearchResult getLessSearchResult(String[][] hotData, String[] searchText) { + public SearchResult getLessSearchResult(String[] searchText) { this.modelList = new SearchResult(); for (int j = 0; j < searchText.length; j++) { recentModelList = getRecentModelList(searchText[j]); diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/RecommendSearchManager.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/RecommendSearchManager.java index de527d5513..64902e0f47 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/RecommendSearchManager.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/RecommendSearchManager.java @@ -46,13 +46,13 @@ public class RecommendSearchManager implements AlphaFineSearchProvider { } @Override - public SearchResult getLessSearchResult(String[][] hotData, String[] searchText) { + public SearchResult getLessSearchResult(String[] searchText) { this.modelList = new SearchResult(); this.recommendModelList = new SearchResult(); if (DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().isContainRecommend()) { if (ArrayUtils.isEmpty(searchText)) { return new SearchResult(); - } else if(hotData == null){ + } else if(!AlphaFineHelper.isNetworkOk()){ return AlphaFineHelper.getNoConnectList(instance); } for (int j = 0; j < searchText.length; j++) { diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/SimilarSearchManeger.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/SimilarSearchManeger.java index 90d0489321..bf696529db 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/SimilarSearchManeger.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/SimilarSearchManeger.java @@ -37,12 +37,12 @@ public class SimilarSearchManeger implements AlphaFineSearchProvider { } @Override - public SearchResult getLessSearchResult(String[][] hotData, String[] searchText) { + public SearchResult getLessSearchResult(String[] searchText) { lessModelList = new SearchResult(); if (DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().isNeedIntelligentCustomerService()) { if (ArrayUtils.isEmpty(searchText)) { return new SearchResult(); - } else if (hotData == null) { + } else if (!AlphaFineHelper.isNetworkOk()) { return AlphaFineHelper.getNoConnectList(instance); } SearchResult allModelList = new SearchResult();