Browse Source

提升代码质量。。

research/10.0
alex.sung 6 years ago
parent
commit
6e95b0939a
  1. 2
      designer-realize/src/main/java/com/fr/design/mainframe/alphafine/AlphaFineConstants.java
  2. 78
      designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/RecommendSearchManager.java

2
designer-realize/src/main/java/com/fr/design/mainframe/alphafine/AlphaFineConstants.java

@ -128,4 +128,6 @@ public class AlphaFineConstants {
public static final FileExtension[] FILE_EXTENSIONS= new FileExtension[]{FileExtension.CPT, FileExtension.FRM}; public static final FileExtension[] FILE_EXTENSIONS= new FileExtension[]{FileExtension.CPT, FileExtension.FRM};
public static final int RECOMMEND_MAX_ITEM_NUM = 3;
} }

78
designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/RecommendSearchManager.java

@ -47,11 +47,9 @@ public class RecommendSearchManager implements AlphaFineSearchProvider {
@Override @Override
public SearchResult getLessSearchResult(String[] searchText) { public SearchResult getLessSearchResult(String[] searchText) {
if (ArrayUtils.isEmpty(searchText)) { if (ArrayUtils.isEmpty(searchText)) {
return new SearchResult(); return new SearchResult();
} }
this.modelList = new SearchResult(); this.modelList = new SearchResult();
this.recommendModelList = new SearchResult(); this.recommendModelList = new SearchResult();
if (DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().isContainRecommend()) { if (DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().isContainRecommend()) {
@ -61,14 +59,13 @@ public class RecommendSearchManager implements AlphaFineSearchProvider {
String result = HttpToolbox.get(AlphaFineConstants.SEARCH_API + CodeUtils.cjkEncode(searchText[j])); String result = HttpToolbox.get(AlphaFineConstants.SEARCH_API + CodeUtils.cjkEncode(searchText[j]));
AlphaFineHelper.checkCancel(); AlphaFineHelper.checkCancel();
JSONObject jsonObject = new JSONObject(result); JSONObject jsonObject = new JSONObject(result);
if (jsonObject.optString("status").equals("success")) { if ("success".equals(jsonObject.optString("status"))) {
JSONArray jsonArray = jsonObject.optJSONArray("result"); JSONArray jsonArray = jsonObject.optJSONArray("result");
if (jsonArray != null && jsonArray.length() > 0) { if (jsonArray != null && jsonArray.length() > 0) {
for (int i = 0; i < jsonArray.length(); i++) { for (int i = 0; i < jsonArray.length(); i++) {
AlphaFineHelper.checkCancel(); AlphaFineHelper.checkCancel();
AlphaCellModel alphaCellModel = CellModelHelper.getModelFromJson((JSONObject) jsonArray.get(i)); AlphaCellModel alphaCellModel = CellModelHelper.getModelFromJson((JSONObject) jsonArray.get(i));
if (alphaCellModel != null && !alreadyContain(alphaCellModel)) { if (alphaCellModel != null && !alreadyContain(alphaCellModel)) {
this.recommendModelList.add(alphaCellModel); this.recommendModelList.add(alphaCellModel);
} }
} }
@ -91,28 +88,66 @@ public class RecommendSearchManager implements AlphaFineSearchProvider {
complementAdviceModelList = ComplementAdviceManager.getInstance().getAllSearchResult(searchText); complementAdviceModelList = ComplementAdviceManager.getInstance().getAllSearchResult(searchText);
moreModelList.clear(); moreModelList.clear();
if (recommendModelList.size() > 0) { if (!recommendModelList.isEmpty()) {
if (complementAdviceModelList.size() == 0) { if (complementAdviceModelList.isEmpty()) {
if (recommendModelList.size() > AlphaFineConstants.SHOW_SIZE - 2) { getRecommendSearchResult();
} else {
getRecommendAndAdviceSearchResult();
}
} else {
if (!complementAdviceModelList.isEmpty()) {
getComplementAdviceSearchResult();
} else {
return modelList;
}
}
}
return modelList;
}
/**
* 将推荐接口获取的数据分别放入显示部分显示更多的list
*/
private void getRecommendSearchResult(){
if (recommendModelList.size() > AlphaFineConstants.RECOMMEND_MAX_ITEM_NUM) {
if (recommendModelList.size() > AlphaFineConstants.SHOW_SIZE) { if (recommendModelList.size() > AlphaFineConstants.SHOW_SIZE) {
modelList.add(0, new MoreModel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_Recommend"), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_ShowAll"), true, CellType.RECOMMEND)); modelList.add(0, new MoreModel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_Recommend"), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_ShowAll"), true, CellType.RECOMMEND));
} else { } else {
modelList.add(0, new MoreModel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_Recommend"), false)); modelList.add(0, new MoreModel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_Recommend"), false));
} }
modelList.addAll(recommendModelList.subList(0, AlphaFineConstants.SHOW_SIZE - 2)); modelList.addAll(recommendModelList.subList(0, AlphaFineConstants.RECOMMEND_MAX_ITEM_NUM));
moreModelList.addAll(recommendModelList.subList(AlphaFineConstants.SHOW_SIZE - 2, recommendModelList.size())); moreModelList.addAll(recommendModelList.subList(AlphaFineConstants.RECOMMEND_MAX_ITEM_NUM, recommendModelList.size()));
} else { } else {
modelList.add(0, new MoreModel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_Recommend"), false)); modelList.add(0, new MoreModel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_Recommend"), false));
modelList.addAll(recommendModelList); modelList.addAll(recommendModelList);
} }
}
/**
* 将补全接口获取的数据分别放入显示部分显示更多的list
*/
private void getComplementAdviceSearchResult(){
if (complementAdviceModelList.size() > AlphaFineConstants.SHOW_SIZE) {
modelList.add(0, new MoreModel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_Recommend"), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_ShowAll"), true, CellType.RECOMMEND));
modelList.addAll(complementAdviceModelList.subList(0, AlphaFineConstants.SHOW_SIZE));
moreModelList.addAll(complementAdviceModelList.subList(AlphaFineConstants.SHOW_SIZE, complementAdviceModelList.size()));
} else { } else {
modelList.add(0, new MoreModel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_Recommend"), false));
modelList.addAll(complementAdviceModelList);
}
}
/**
* 将推荐接口和补全接口获取的数据分别放入显示部分显示更多的list
*/
private void getRecommendAndAdviceSearchResult(){
if (recommendModelList.size() + complementAdviceModelList.size() > AlphaFineConstants.SHOW_SIZE) { if (recommendModelList.size() + complementAdviceModelList.size() > AlphaFineConstants.SHOW_SIZE) {
modelList.add(0, new MoreModel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_Recommend"), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_ShowAll"), true, CellType.RECOMMEND)); modelList.add(0, new MoreModel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_Recommend"), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_ShowAll"), true, CellType.RECOMMEND));
if (recommendModelList.size() > AlphaFineConstants.SHOW_SIZE - 2) { if (recommendModelList.size() > AlphaFineConstants.RECOMMEND_MAX_ITEM_NUM) {
modelList.addAll(recommendModelList.subList(0, AlphaFineConstants.SHOW_SIZE - 2)); modelList.addAll(recommendModelList.subList(0, AlphaFineConstants.RECOMMEND_MAX_ITEM_NUM));
moreModelList.addAll(recommendModelList.subList(AlphaFineConstants.SHOW_SIZE - 2, recommendModelList.size())); moreModelList.addAll(recommendModelList.subList(AlphaFineConstants.RECOMMEND_MAX_ITEM_NUM, recommendModelList.size()));
if (complementAdviceModelList.size() >= 2) { if (complementAdviceModelList.size() >= AlphaFineConstants.SHOW_SIZE - AlphaFineConstants.RECOMMEND_MAX_ITEM_NUM) {
modelList.addAll(complementAdviceModelList.subList(0, 2)); modelList.addAll(complementAdviceModelList.subList(0, 2));
moreModelList.addAll(complementAdviceModelList.subList(2, complementAdviceModelList.size())); moreModelList.addAll(complementAdviceModelList.subList(2, complementAdviceModelList.size()));
} else { } else {
@ -133,23 +168,6 @@ public class RecommendSearchManager implements AlphaFineSearchProvider {
modelList.addAll(complementAdviceModelList); modelList.addAll(complementAdviceModelList);
} }
} }
} else {
if (complementAdviceModelList.size() > 0) {
if (complementAdviceModelList.size() > AlphaFineConstants.SHOW_SIZE) {
modelList.add(0, new MoreModel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_Recommend"), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_ShowAll"), true, CellType.RECOMMEND));
modelList.addAll(complementAdviceModelList.subList(0, AlphaFineConstants.SHOW_SIZE));
moreModelList.addAll(complementAdviceModelList.subList(AlphaFineConstants.SHOW_SIZE, complementAdviceModelList.size()));
} else {
modelList.add(0, new MoreModel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_Recommend"), false));
modelList.addAll(complementAdviceModelList);
}
} else {
return modelList;
}
}
}
return modelList;
}
/** /**
* 是否已包含该model * 是否已包含该model

Loading…
Cancel
Save