|
|
@@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
|
import com.alibaba.druid.util.StringUtils;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.uas.search.console.core.util.ContextUtils;
|
|
|
import com.uas.search.console.dao.ComponentSimpleInfoDao;
|
|
|
@@ -24,6 +25,8 @@ import com.uas.search.console.model.KindSimpleInfo;
|
|
|
import com.uas.search.console.service.InnerSearchService;
|
|
|
import com.uas.search.model.PageParams;
|
|
|
import com.uas.search.model.PageParams.FilterField;
|
|
|
+import com.uas.search.model.Sort;
|
|
|
+import com.uas.search.model.Sort.Field;
|
|
|
import com.uas.search.service.SearchService;
|
|
|
|
|
|
/**
|
|
|
@@ -178,7 +181,7 @@ public class SearchController {
|
|
|
|
|
|
@RequestMapping("/goodsIds")
|
|
|
@ResponseBody
|
|
|
- public Map<String, Object> getGoodsIds(String keyword, Integer page, Integer size, String filters) {
|
|
|
+ public Map<String, Object> getGoodsIds(String keyword, Integer page, Integer size, String filters, String sort) {
|
|
|
PageParams pageParams = new PageParams();
|
|
|
if (page != null) {
|
|
|
pageParams.setPage(page);
|
|
|
@@ -196,6 +199,21 @@ public class SearchController {
|
|
|
}
|
|
|
}
|
|
|
pageParams.setFilters(filtersMap);
|
|
|
+ if (!StringUtils.isEmpty(sort)) {
|
|
|
+ JSONArray jsonArray = JSONObject.parseArray(sort);
|
|
|
+ List<Sort> sorts = new ArrayList<>();
|
|
|
+ for (Object object : jsonArray) {
|
|
|
+ if (object instanceof JSONObject) {
|
|
|
+ JSONObject jsonObject = (JSONObject) object;
|
|
|
+ Field field = Field.valueOf(jsonObject.getString("field"));
|
|
|
+ boolean reverse = jsonObject.getBooleanValue("reverse");
|
|
|
+ sorts.add(new Sort(field, reverse));
|
|
|
+ } else {
|
|
|
+ throw new IllegalArgumentException("排序参数并非json格式");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ pageParams.setSort(sorts);
|
|
|
+ }
|
|
|
return searchService.getGoodsIds(keyword, pageParams);
|
|
|
}
|
|
|
|