@ -0,0 +1,57 @@
|
||||
package com.fr.design.mainframe.alphafine.cell.model; |
||||
|
||||
import com.fr.design.mainframe.alphafine.CellType; |
||||
import com.fr.json.JSONException; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.log.FineLoggerFactory; |
||||
|
||||
import java.awt.Desktop; |
||||
import java.io.IOException; |
||||
import java.net.URI; |
||||
import java.net.URISyntaxException; |
||||
|
||||
/** |
||||
* Created by alexsung on 2018/7/30. |
||||
*/ |
||||
public class BottomModel extends AlphaCellModel { |
||||
/** |
||||
* 找不到答案?去论坛提问 |
||||
*/ |
||||
public String getGoToWeb() { |
||||
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_Internet_Forum"); |
||||
} |
||||
|
||||
public BottomModel(String name, String content) { |
||||
super(name, content, CellType.BOTTOM); |
||||
} |
||||
|
||||
public BottomModel() { |
||||
super(null, null, CellType.BOTTOM); |
||||
} |
||||
|
||||
@Override |
||||
public JSONObject ModelToJson() throws JSONException { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public String getStoreInformation() { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public boolean hasAction() { |
||||
return true; |
||||
} |
||||
|
||||
@Override |
||||
public void doAction() { |
||||
try { |
||||
Desktop.getDesktop().browse(new URI("http://bbs.fanruan.com/post_newthread_ajax.php?action=newthread&fid=39")); |
||||
} catch (IOException e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage()); |
||||
} catch (URISyntaxException e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage()); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,95 @@
|
||||
package com.fr.design.mainframe.alphafine.cell.model; |
||||
|
||||
import com.fr.design.mainframe.alphafine.AlphaFineConstants; |
||||
import com.fr.design.mainframe.alphafine.AlphaFineHelper; |
||||
import com.fr.design.mainframe.alphafine.CellType; |
||||
import com.fr.general.http.HttpClient; |
||||
import com.fr.json.JSONException; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import org.apache.commons.codec.digest.DigestUtils; |
||||
|
||||
|
||||
import java.awt.Desktop; |
||||
import java.io.IOException; |
||||
import java.net.URI; |
||||
import java.net.URISyntaxException; |
||||
|
||||
/** |
||||
* Created by alex.sung on 2018/8/3. |
||||
*/ |
||||
public class RobotModel extends AlphaCellModel { |
||||
|
||||
private String title; |
||||
private String content; |
||||
|
||||
//热门问题列表的list不需要渲染图标,所以这里需要区分一下
|
||||
private boolean isHotItemModel = false; |
||||
|
||||
public boolean isHotItemModel() { |
||||
return isHotItemModel; |
||||
} |
||||
|
||||
public void setHotItemModel(boolean hotItemModel) { |
||||
isHotItemModel = hotItemModel; |
||||
} |
||||
|
||||
public String getTitle() { |
||||
return title; |
||||
} |
||||
|
||||
public void setTitle(String title) { |
||||
this.title = title; |
||||
} |
||||
|
||||
public static String getContent(String titleStr) { |
||||
String result; |
||||
String token = DigestUtils.md5Hex(AlphaFineConstants.ALPHA_ROBOT_SEARCH_TOKEN + titleStr); |
||||
String url = "http://robot.finereport.com/openapi/reply.php?action=search&msg=" + titleStr + "&token=" + token; |
||||
HttpClient httpClient = new HttpClient(url); |
||||
httpClient.asGet(); |
||||
result = httpClient.getResponseText(); |
||||
AlphaFineHelper.checkCancel(); |
||||
try { |
||||
JSONObject jsonObject = new JSONObject(result); |
||||
return jsonObject.optString("msg"); |
||||
} catch (JSONException e) { |
||||
FineLoggerFactory.getLogger().error("get robotmodel content error: " + e.getMessage()); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public RobotModel(String title, String content) { |
||||
super(title, content, CellType.ROBOT); |
||||
this.title = title; |
||||
} |
||||
|
||||
@Override |
||||
public JSONObject ModelToJson() throws JSONException { |
||||
JSONObject object = JSONObject.create(); |
||||
try { |
||||
JSONObject modelObject = JSONObject.create(); |
||||
modelObject.put("title", getTitle()).put("content", getContent()).put("searchCount", getSearchCount()); |
||||
object.put("result", modelObject).put("cellType", getType().getTypeValue()); |
||||
} catch (JSONException e) { |
||||
FineLoggerFactory.getLogger().error("RobotModel: " + e.getMessage()); |
||||
} |
||||
return object; |
||||
} |
||||
|
||||
@Override |
||||
public String getStoreInformation() { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public void doAction() { |
||||
try { |
||||
Desktop.getDesktop().browse(new URI("http://robot.finereport.com?send=" + super.getName())); |
||||
} catch (IOException e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage()); |
||||
} catch (URISyntaxException e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage()); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,39 @@
|
||||
package com.fr.design.mainframe.alphafine.cell.render; |
||||
|
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.mainframe.alphafine.AlphaFineConstants; |
||||
import com.fr.design.mainframe.alphafine.cell.model.BottomModel; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.Component; |
||||
import java.awt.BorderLayout; |
||||
import java.awt.Dimension; |
||||
|
||||
/** |
||||
* Created by alex.sung on 2018/8/3. |
||||
*/ |
||||
public class BottomCellRender implements ListCellRenderer<Object> { |
||||
@Override |
||||
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) { |
||||
|
||||
UILabel goToWebLabel = new UILabel(); |
||||
BottomModel bottomModel = (BottomModel) value; |
||||
JPanel panel = new JPanel(new BorderLayout()); |
||||
panel.setBackground(null); |
||||
panel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0)); |
||||
|
||||
JPanel line = new JPanel(); |
||||
line.setPreferredSize(new Dimension(200, 1)); |
||||
line.setBackground(AlphaFineConstants.GRAY); |
||||
panel.add(line, BorderLayout.NORTH); |
||||
|
||||
goToWebLabel.setFont(AlphaFineConstants.MEDIUM_FONT); |
||||
goToWebLabel.setText(bottomModel.getGoToWeb()); |
||||
goToWebLabel.setForeground(AlphaFineConstants.BLUE); |
||||
goToWebLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10)); |
||||
panel.add(goToWebLabel, BorderLayout.EAST); |
||||
|
||||
panel.setPreferredSize(new Dimension(list.getFixedCellWidth(), AlphaFineConstants.CELL_TITLE_HEIGHT)); |
||||
return panel; |
||||
} |
||||
} |
@ -0,0 +1,36 @@
|
||||
package com.fr.design.mainframe.alphafine.preview; |
||||
|
||||
import com.bulenkov.iconloader.IconLoader; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.mainframe.alphafine.AlphaFineConstants; |
||||
|
||||
import javax.swing.JPanel; |
||||
import java.awt.Color; |
||||
import java.awt.Graphics; |
||||
|
||||
/** |
||||
* @Author alex.sung |
||||
* created by 2018.08.15 |
||||
*/ |
||||
public class ContainsCirclePane extends JPanel { |
||||
|
||||
public ContainsCirclePane(int pngIndex) { |
||||
UILabel iconLabel = new UILabel(IconLoader.getIcon(AlphaFineConstants.IMAGE_URL + "alphafine_hot" + pngIndex + ".png")); |
||||
iconLabel.setPreferredSize(AlphaFineConstants.HOT_ICON_LABEL_SIZE); |
||||
iconLabel.setOpaque(true); |
||||
iconLabel.setBackground(Color.WHITE); |
||||
add(iconLabel); |
||||
} |
||||
|
||||
@Override |
||||
public void paintComponent(Graphics g) { |
||||
super.paintComponent(g); |
||||
int height = AlphaFineConstants.HOT_ICON_LABEL_HEIGHT; |
||||
setBackground(Color.white); |
||||
int x0 = getSize().width / 2; |
||||
int y0 = height / 2 + 23; |
||||
int r = height / 2 + 9; |
||||
g.setColor(AlphaFineConstants.LIGHT_GRAY); |
||||
g.drawOval(x0 - r, y0 - r, r * 2, r * 2); |
||||
} |
||||
} |
@ -0,0 +1,41 @@
|
||||
package com.fr.design.mainframe.alphafine.preview; |
||||
|
||||
|
||||
import com.fr.design.gui.itextarea.UITextArea; |
||||
import com.fr.design.mainframe.alphafine.AlphaFineConstants; |
||||
|
||||
import javax.swing.BorderFactory; |
||||
import javax.swing.JEditorPane; |
||||
import javax.swing.JPanel; |
||||
import javax.swing.JScrollPane; |
||||
import javax.swing.text.html.HTMLEditorKit; |
||||
import java.awt.BorderLayout; |
||||
import java.awt.Color; |
||||
import java.awt.Dimension; |
||||
|
||||
|
||||
/** |
||||
* Created by alex.sung on 2018/8/3. |
||||
*/ |
||||
public class RobotPreviewPane extends JPanel { |
||||
|
||||
public RobotPreviewPane(String title, String content) { |
||||
this.setLayout(new BorderLayout()); |
||||
this.setBackground(Color.WHITE); |
||||
this.setPreferredSize(new Dimension(AlphaFineConstants.RIGHT_WIDTH, AlphaFineConstants.CONTENT_HEIGHT)); |
||||
UITextArea titleArea = new UITextArea(title); |
||||
titleArea.setBorder(null); |
||||
titleArea.setEditable(false); |
||||
titleArea.setForeground(AlphaFineConstants.BLUE); |
||||
titleArea.setFont(AlphaFineConstants.LARGE_FONT); |
||||
add(titleArea, BorderLayout.NORTH); |
||||
|
||||
JEditorPane editorPane = new JEditorPane(); |
||||
editorPane.setEditorKit(new HTMLEditorKit()); |
||||
editorPane.setText(content); |
||||
editorPane.setEditable(false); |
||||
JScrollPane jScrollPane = new JScrollPane(editorPane); |
||||
jScrollPane.setBorder(BorderFactory.createMatteBorder(5, 10, 0, 10, Color.white)); |
||||
add(jScrollPane, BorderLayout.CENTER); |
||||
} |
||||
} |
@ -0,0 +1,84 @@
|
||||
package com.fr.design.mainframe.alphafine.search.manager.impl; |
||||
|
||||
import com.fr.design.DesignerEnvManager; |
||||
import com.fr.design.mainframe.alphafine.AlphaFineConstants; |
||||
import com.fr.design.mainframe.alphafine.AlphaFineHelper; |
||||
import com.fr.design.mainframe.alphafine.cell.model.RobotModel; |
||||
import com.fr.design.mainframe.alphafine.model.SearchResult; |
||||
import com.fr.general.http.HttpClient; |
||||
import com.fr.json.JSONArray; |
||||
import com.fr.json.JSONException; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.json.JSONTokener; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.stable.StringUtils; |
||||
import org.apache.commons.codec.digest.DigestUtils; |
||||
|
||||
/** |
||||
* @author alex.sung created on 2018/7/23. |
||||
*/ |
||||
public class ComplementAdviceManager { |
||||
|
||||
public static int count = 0; |
||||
|
||||
private static ComplementAdviceManager instance; |
||||
private SearchResult allModelList; |
||||
|
||||
public static ComplementAdviceManager getInstance() { |
||||
if (instance == null) { |
||||
synchronized (ComplementAdviceManager.class) { |
||||
if (instance == null) { |
||||
instance = new ComplementAdviceManager(); |
||||
} |
||||
} |
||||
} |
||||
return instance; |
||||
} |
||||
|
||||
/** |
||||
* 从接口中获取补全建议结果 |
||||
* @param searchText |
||||
* @return |
||||
*/ |
||||
public synchronized SearchResult getAllSearchResult(String[] searchText) { |
||||
allModelList = new SearchResult(); |
||||
if (DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().isNeedIntelligentCustomerService()) { |
||||
SearchResult searchResult = new SearchResult(); |
||||
for (int j = 0; j < searchText.length; j++) { |
||||
String result; |
||||
String token = DigestUtils.md5Hex(AlphaFineConstants.ALPHA_ROBOT_SEARCH_TOKEN + searchText[j]); |
||||
String url = AlphaFineConstants.COMPLEMENT_ADVICE_SEARCH_URL_PREFIX + "msg=" + searchText[j] + "&token=" + token; |
||||
HttpClient httpClient = new HttpClient(url); |
||||
httpClient.asGet(); |
||||
result = httpClient.getResponseText(); |
||||
AlphaFineHelper.checkCancel(); |
||||
try { |
||||
Object json = new JSONTokener(result).nextValue(); |
||||
if (json instanceof JSONArray) { |
||||
JSONArray jsonArray = new JSONArray(result); |
||||
for (int i = 0; i < jsonArray.length(); i++) { |
||||
AlphaFineHelper.checkCancel(); |
||||
JSONObject jsonObject = jsonArray.optJSONObject(i); |
||||
|
||||
String temp = jsonObject.optString("keywords"); |
||||
if (!StringUtils.isEmpty(temp)) { |
||||
RobotModel robotModel = new RobotModel(temp, null); |
||||
if (!AlphaFineHelper.getFilterResult().contains(robotModel) && !allModelList.contains(robotModel)) { |
||||
allModelList.add(robotModel); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} catch (JSONException e) { |
||||
FineLoggerFactory.getLogger().error("complement advice search error: " + e.getMessage()); |
||||
} |
||||
} |
||||
if (searchResult.isEmpty()) { |
||||
return allModelList; |
||||
} else { |
||||
allModelList.addAll(searchResult); |
||||
} |
||||
} |
||||
return allModelList; |
||||
} |
||||
} |
@ -0,0 +1,153 @@
|
||||
package com.fr.design.mainframe.alphafine.search.manager.impl; |
||||
|
||||
import com.fr.design.mainframe.alphafine.AlphaFineConstants; |
||||
import com.fr.design.mainframe.alphafine.AlphaFineHelper; |
||||
import com.fr.design.mainframe.alphafine.cell.model.MoreModel; |
||||
import com.fr.design.mainframe.alphafine.cell.model.RobotModel; |
||||
import com.fr.design.mainframe.alphafine.model.SearchResult; |
||||
import com.fr.general.Inter; |
||||
import com.fr.general.http.HttpClient; |
||||
import com.fr.json.JSONArray; |
||||
import com.fr.json.JSONException; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.Arrays; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
|
||||
/** |
||||
* Created by alex.sung on 2018/8/3. |
||||
*/ |
||||
public class HotIssuesManager { |
||||
private static HotIssuesManager instance; |
||||
private static final int HOT_ITEM_NUM = 6; |
||||
private static final int HOT_SUB_ITEM_NUM = 4; |
||||
|
||||
public static HotIssuesManager getInstance() { |
||||
if (instance == null) { |
||||
synchronized (HotIssuesManager.class) { |
||||
if (instance == null) { |
||||
instance = new HotIssuesManager(); |
||||
} |
||||
} |
||||
} |
||||
return instance; |
||||
} |
||||
|
||||
String[][] data = new String[HOT_ITEM_NUM][]; |
||||
Map<String, List> map = new HashMap<>(); |
||||
|
||||
/** |
||||
* 将子标题下的数据塞入modeList |
||||
* @param getStr |
||||
* @return |
||||
*/ |
||||
public SearchResult getTitleSearchResult(String getStr) { |
||||
SearchResult modeList = new SearchResult(); |
||||
modeList.add(0, new MoreModel(com.fr.design.i18n.Toolkit.i18nText((getStr)))); |
||||
|
||||
List<String> issueList = map.get(getStr); |
||||
for (int i = 0; i < issueList.size(); i++) { |
||||
RobotModel robotModel = new RobotModel(issueList.get(i), null); |
||||
robotModel.setHotItemModel(true); |
||||
modeList.add(robotModel); |
||||
} |
||||
return modeList; |
||||
} |
||||
|
||||
/** |
||||
* 从热门问题接口获取热门问题 |
||||
* @return |
||||
*/ |
||||
public String[][] getHotIssues() { |
||||
String result; |
||||
HttpClient httpClient = new HttpClient(AlphaFineConstants.ALPHA_HOT_SEARCH); |
||||
httpClient.asGet(); |
||||
if (!httpClient.isServerAlive()) { |
||||
return null; |
||||
} |
||||
result = httpClient.getResponseText(); |
||||
AlphaFineHelper.checkCancel(); |
||||
try { |
||||
JSONArray jsonArray = new JSONArray(result); |
||||
for (int i = 0; i < HOT_ITEM_NUM; i++) { |
||||
AlphaFineHelper.checkCancel(); |
||||
JSONObject jsonObject = jsonArray.optJSONObject(i); |
||||
data[i] = getTitleStrings(jsonObject); |
||||
} |
||||
|
||||
} catch (JSONException e) { |
||||
FineLoggerFactory.getLogger().error("hotissues search error: " + e.getMessage()); |
||||
} |
||||
return data; |
||||
} |
||||
|
||||
/** |
||||
* 根据子标题获取该标题下数据 |
||||
* @param jsonObject |
||||
* @return |
||||
*/ |
||||
private String[] getTitleStrings(JSONObject jsonObject) { |
||||
String[] temp = getSubTitleFromCloud(jsonObject.optJSONObject("data")); |
||||
String[] temp1 = new String[1]; |
||||
temp1[0] = jsonObject.optString("type"); |
||||
int strLen1 = temp.length; |
||||
int strLen2 = temp1.length; |
||||
|
||||
temp1 = Arrays.copyOf(temp1, strLen2 + strLen1); |
||||
System.arraycopy(temp, 0, temp1, strLen2, strLen1); |
||||
|
||||
getIssueStrings(jsonObject.optJSONObject("data")); |
||||
|
||||
return temp1; |
||||
} |
||||
|
||||
/** |
||||
* 获取子标题和子标题下的问题列表 |
||||
* @param data |
||||
* @return |
||||
*/ |
||||
private String[] getIssueStrings(JSONObject data) { |
||||
try { |
||||
for (int j = 0; j < HOT_SUB_ITEM_NUM; j++) { |
||||
String temp = data.getString("item" + (j + 1)); |
||||
JSONArray jsonArray = data.getJSONArray("itemData" + (j + 1)); |
||||
List<String> tempList = new ArrayList<>(); |
||||
for (int i = 0; i < jsonArray.length(); i++) { |
||||
tempList.add(jsonArray.optJSONObject(i).optString("text")); |
||||
} |
||||
map.put(temp, tempList); |
||||
} |
||||
|
||||
} catch (JSONException e) { |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
/** |
||||
* 获取问题列表 |
||||
* @param data |
||||
* @return |
||||
*/ |
||||
private String[] getSubTitleFromCloud(JSONObject data) { |
||||
ArrayList<String> list = new ArrayList<>(); |
||||
for (int i = 0; i < HOT_SUB_ITEM_NUM; i++) { |
||||
String temp = null; |
||||
try { |
||||
temp = data.getString("item" + (i + 1)); |
||||
} catch (JSONException e) { |
||||
} |
||||
if (!StringUtils.isEmpty(temp)) { |
||||
list.add(temp); |
||||
} |
||||
} |
||||
String[] strings = new String[list.size()]; |
||||
list.toArray(strings); |
||||
return strings; |
||||
} |
||||
} |
@ -0,0 +1,81 @@
|
||||
package com.fr.design.mainframe.alphafine.search.manager.impl; |
||||
|
||||
import com.fr.stable.StringUtils; |
||||
|
||||
import com.fr.third.ibm.icu.text.BreakIterator; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import java.util.regex.Matcher; |
||||
import java.util.regex.Pattern; |
||||
|
||||
/** |
||||
* Created by alex.sung on 2018/8/3. |
||||
*/ |
||||
public class SegmentationManager { |
||||
private static SegmentationManager segmentationManager = null; |
||||
private static final int MAX_CHINESE_CHARACTERS_NUM = 4; |
||||
|
||||
public static SegmentationManager getInstance() { |
||||
if (segmentationManager == null) { |
||||
segmentationManager = new SegmentationManager(); |
||||
return segmentationManager; |
||||
} else { |
||||
return segmentationManager; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 判断是否需要分词 |
||||
* |
||||
* @param searchText |
||||
* @return |
||||
*/ |
||||
public boolean isNeedSegmentation(String searchText) { |
||||
int count = 0; |
||||
String reg = "[\\u4e00-\\u9fa5]"; |
||||
Pattern p = Pattern.compile(reg); |
||||
Matcher m = p.matcher(searchText); |
||||
while (m.find()) { |
||||
for (int i = 0; i <= m.groupCount(); i++) { |
||||
count = count + 1; |
||||
} |
||||
} |
||||
if (count >= MAX_CHINESE_CHARACTERS_NUM) { |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
/** |
||||
* 对字符串进行分词 |
||||
* @param searchText |
||||
* @return |
||||
*/ |
||||
public String[] startSegmentation(String searchText) { |
||||
String regEx = "[`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~!@#¥%……&*()——+|{}【】';:”“’。,、?]"; |
||||
Pattern p = Pattern.compile(regEx); |
||||
Matcher m = p.matcher(searchText); |
||||
searchText = m.replaceAll("").trim().replaceAll(" ", ""); |
||||
if (searchText.length() == 0) { |
||||
return null; |
||||
} |
||||
if(!isNeedSegmentation(searchText)){ |
||||
return new String[]{searchText}; |
||||
} |
||||
List<String> result = new ArrayList<>(); |
||||
BreakIterator itor = BreakIterator.getWordInstance(); |
||||
itor.setText(searchText); |
||||
int start = itor.first(); |
||||
for (int end = itor.next(); |
||||
end != BreakIterator.DONE; |
||||
start = end, end = itor.next()) { |
||||
String temp = searchText.substring(start, end); |
||||
if (!StringUtils.isEmpty(temp)) { |
||||
result.add(temp); |
||||
} |
||||
} |
||||
String[] strings = new String[result.size()]; |
||||
result.toArray(strings); |
||||
return strings; |
||||
} |
||||
} |
@ -0,0 +1,101 @@
|
||||
package com.fr.design.mainframe.alphafine.search.manager.impl; |
||||
|
||||
import com.fr.design.DesignerEnvManager; |
||||
import com.fr.design.mainframe.alphafine.AlphaFineConstants; |
||||
import com.fr.design.mainframe.alphafine.AlphaFineHelper; |
||||
import com.fr.design.mainframe.alphafine.CellType; |
||||
import com.fr.design.mainframe.alphafine.cell.model.MoreModel; |
||||
import com.fr.design.mainframe.alphafine.cell.model.RobotModel; |
||||
import com.fr.design.mainframe.alphafine.model.SearchResult; |
||||
import com.fr.design.mainframe.alphafine.search.manager.fun.AlphaFineSearchProvider; |
||||
import com.fr.general.http.HttpClient; |
||||
import com.fr.json.JSONArray; |
||||
import com.fr.json.JSONException; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.json.JSONTokener; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import org.apache.commons.codec.digest.DigestUtils; |
||||
|
||||
/** |
||||
* Created by alex.sung on 2018/8/3. |
||||
*/ |
||||
public class SimilarSearchManeger implements AlphaFineSearchProvider { |
||||
private static SimilarSearchManeger instance; |
||||
private SearchResult lessModelList; |
||||
private SearchResult moreModelList = new SearchResult(); |
||||
|
||||
public static SimilarSearchManeger getInstance() { |
||||
if (instance == null) { |
||||
synchronized (SimilarSearchManeger.class) { |
||||
if (instance == null) { |
||||
instance = new SimilarSearchManeger(); |
||||
} |
||||
} |
||||
} |
||||
return instance; |
||||
} |
||||
|
||||
@Override |
||||
public synchronized SearchResult getLessSearchResult(String[] searchText) { |
||||
lessModelList = new SearchResult(); |
||||
if (DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().isNeedIntelligentCustomerService()) { |
||||
SearchResult allModelList = new SearchResult(); |
||||
for (int j = 0; j < searchText.length; j++) { |
||||
String result; |
||||
String token = DigestUtils.md5Hex(AlphaFineConstants.ALPHA_ROBOT_SEARCH_TOKEN + searchText[j]); |
||||
String url = AlphaFineConstants.SIMILAR_SEARCH_URL_PREFIX + "msg=" + searchText[j] + "&token=" + token; |
||||
HttpClient httpClient = new HttpClient(url); |
||||
httpClient.asGet(); |
||||
result = httpClient.getResponseText(); |
||||
AlphaFineHelper.checkCancel(); |
||||
try { |
||||
Object json = new JSONTokener(result).nextValue(); |
||||
if (json instanceof JSONArray) { |
||||
JSONArray jsonArray = new JSONArray(result); |
||||
if (jsonArray.length() != 0) { |
||||
for (int i = 0; i < jsonArray.length(); i++) { |
||||
JSONObject jsonObject = jsonArray.optJSONObject(i); |
||||
String title = jsonObject.optString("title"); |
||||
RobotModel robotModel = new RobotModel(title, null); |
||||
if (!AlphaFineHelper.getFilterResult().contains(robotModel) && !allModelList.contains(robotModel)) { |
||||
allModelList.add(robotModel); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} catch (JSONException e) { |
||||
FineLoggerFactory.getLogger().error("similar search error: " + e.getMessage()); |
||||
} |
||||
} |
||||
moreModelList.clear(); |
||||
if (allModelList.isEmpty()) { |
||||
return lessModelList; |
||||
} else if (allModelList.size() < AlphaFineConstants.SHOW_SIZE + 1) { |
||||
lessModelList.add(0, new MoreModel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_Relation_Item"))); |
||||
lessModelList.addAll(allModelList); |
||||
} else { |
||||
lessModelList.add(0, new MoreModel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_Relation_Item"), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_ShowAll"), true, CellType.ROBOT)); |
||||
lessModelList.addAll(allModelList.subList(0, AlphaFineConstants.SHOW_SIZE)); |
||||
moreModelList.addAll(allModelList.subList(AlphaFineConstants.SHOW_SIZE, allModelList.size())); |
||||
} |
||||
} |
||||
return lessModelList; |
||||
} |
||||
|
||||
@Override |
||||
public SearchResult getMoreSearchResult(String searchText) { |
||||
return moreModelList; |
||||
} |
||||
|
||||
/** |
||||
* 根据json信息获取RobotModel |
||||
* |
||||
* @param object |
||||
* @return |
||||
*/ |
||||
public static RobotModel getModelFromCloud(JSONObject object) { |
||||
String name = object.optString("title"); |
||||
String content = object.optString("content"); |
||||
return new RobotModel(name, content); |
||||
} |
||||
} |
After Width: | Height: | Size: 248 B |
After Width: | Height: | Size: 303 B |
After Width: | Height: | Size: 372 B |
After Width: | Height: | Size: 618 B |
After Width: | Height: | Size: 789 B |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 1.0 KiB |
After Width: | Height: | Size: 2.0 KiB |
After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 4.0 KiB |
After Width: | Height: | Size: 634 B |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 3.5 KiB |
After Width: | Height: | Size: 506 B |
After Width: | Height: | Size: 828 B |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 279 B |
After Width: | Height: | Size: 15 KiB |
After Width: | Height: | Size: 488 B |