Browse Source

增加批次搜索接口

sunyj 8 years ago
parent
commit
07cdb7eb71

+ 87 - 19
search-api/src/main/java/com/uas/search/model/PageParams.java

@@ -1,7 +1,7 @@
 package com.uas.search.model;
 
 import java.io.Serializable;
-import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -12,24 +12,45 @@ import java.util.Map;
  */
 public class PageParams implements Serializable {
 
+	private static final long serialVersionUID = 1L;
+
 	/**
-	 * 序列号
+	 * 页码
 	 */
-	private static final long serialVersionUID = 1L;
 	private int page;
+
+	/**
+	 * 页大小
+	 */
 	private int size;
-	private Map<String, Object> filters;
 
-	public PageParams() {
+	/**
+	 * 过滤
+	 */
+	private Map<FilterField, Object> filters;
 
+	/**
+	 * 排序
+	 */
+	private List<Sort> sort;
+
+	public PageParams() {
 	}
 
-	public PageParams(int page, int size, Map<String, Object> filters) {
+	/**
+	 * @param page
+	 *            页码
+	 * @param size
+	 *            页大小
+	 */
+	public PageParams(int page, int size) {
 		this.page = page;
 		this.size = size;
-		this.filters = filters;
 	}
 
+	/**
+	 * @return 页码
+	 */
 	public int getPage() {
 		return page;
 	}
@@ -38,6 +59,9 @@ public class PageParams implements Serializable {
 		this.page = page;
 	}
 
+	/**
+	 * @return 页大小
+	 */
 	public int getSize() {
 		return size;
 	}
@@ -46,30 +70,74 @@ public class PageParams implements Serializable {
 		this.size = size;
 	}
 
-	public Map<String, Object> getFilters() {
+	/**
+	 * @return 过滤
+	 */
+	public Map<FilterField, Object> getFilters() {
 		return filters;
 	}
 
-	public void setFilters(Map<String, Object> filters) {
+	public void setFilters(Map<FilterField, Object> filters) {
 		this.filters = filters;
 	}
 
-	public void filter(String key, Object value) {
-		if (this.filters == null) {
-			this.filters = new HashMap<String, Object>();
-		}
-		this.filters.put(key, value);
+	/**
+	 * @return 排序
+	 */
+	public List<Sort> getSort() {
+		return sort;
 	}
 
-	public void removeFilter(String key) {
-		if (this.filters != null) {
-			this.filters.remove(key);
-		}
+	public void setSort(List<Sort> sort) {
+		this.sort = sort;
 	}
 
 	@Override
 	public String toString() {
-		return "PageParams [page=" + page + ", size=" + size + ", filters=" + filters + "]";
+		return "PageParams [page=" + page + ", size=" + size + ", filters=" + filters + ", sort=" + sort + "]";
 	}
 
+	/**
+	 * 过滤的字段
+	 * 
+	 * @author sunyj
+	 * @since 2017年7月8日 下午5:00:55
+	 */
+	public enum FilterField {
+
+		/**
+		 * 类目id
+		 */
+		COMPONENT_KINDID,
+
+		/**
+		 * 品牌id
+		 */
+		COMPONENT_BRANDID,
+
+		/**
+		 * 属性信息
+		 */
+		COMPONENT_PROPERTIES,
+
+		/**
+		 * 有库存
+		 */
+		COMPONENT_HAS_RESERVE,
+
+		/**
+		 * 有样品
+		 */
+		COMPONENT_HAS_SAMPLE,
+
+		/**
+		 * 有现货
+		 */
+		COMPONENT_HAS_ORIGINAL,
+
+		/**
+		 * 有呆滞库存
+		 */
+		COMPONENT_HAS_INACTION_STOCK;
+	}
 }

+ 14 - 3
search-api/src/main/java/com/uas/search/model/SPage.java

@@ -5,9 +5,6 @@ import java.util.List;
 
 public class SPage<T> implements Serializable {
 
-	/**
-	 * 
-	 */
 	private static final long serialVersionUID = 1L;
 
 	private int totalPage;
@@ -24,6 +21,20 @@ public class SPage<T> implements Serializable {
 
 	private List<T> content;
 
+	public SPage() {
+		super();
+	}
+
+	public SPage(int totalPage, long totalElement, int page, int size, boolean first, boolean last) {
+		super();
+		this.totalPage = totalPage;
+		this.totalElement = totalElement;
+		this.page = page;
+		this.size = size;
+		this.first = first;
+		this.last = last;
+	}
+
 	public int getTotalPage() {
 		return totalPage;
 	}

+ 97 - 0
search-api/src/main/java/com/uas/search/model/Sort.java

@@ -0,0 +1,97 @@
+package com.uas.search.model;
+
+import java.io.Serializable;
+
+/**
+ * 排序
+ * 
+ * @author sunyj
+ * @since 2016年11月23日 下午1:47:44
+ */
+public class Sort implements Serializable {
+
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * 排序的字段
+	 */
+	private Field field;
+
+	/**
+	 * 排序默认为升序,若为true,则进行反转
+	 */
+	private boolean reverse = false;
+
+	/**
+	 * @param field
+	 *            排序的字段
+	 * @param reverse
+	 *            如果为true,则反转默认的升序
+	 */
+	public Sort(Field field, boolean reverse) {
+		this.field = field;
+		this.reverse = reverse;
+	}
+
+	/**
+	 * @param field
+	 *            排序的字段
+	 */
+	public Sort(Field field) {
+		this.field = field;
+	}
+
+	/**
+	 * @return 排序的字段
+	 */
+	public Field getField() {
+		return field;
+	}
+
+	/**
+	 * 排序是否应该被反转
+	 * 
+	 * @return 如果为true,则反转默认的升序
+	 */
+	public boolean isReverse() {
+		return reverse;
+	}
+
+	public void setReverse(boolean reverse) {
+		this.reverse = reverse;
+	}
+
+	@Override
+	public String toString() {
+		return "Sort [field=" + field + ", reverse=" + reverse + "]";
+	}
+
+	/**
+	 * 排序的字段
+	 * 
+	 * @author sunyj
+	 * @since 2017年7月8日 下午5:12:07
+	 */
+	public enum Field {
+		/**
+		 * 批次库存
+		 */
+		GO_RESERVE,
+
+		/**
+		 * 批次价格(人民币)
+		 */
+		GO_MINPRICERMB,
+
+		/**
+		 * 批次价格(美元)
+		 */
+		GO_MINPRICEUSD,
+
+		/**
+		 * 批次搜索(由器件、品牌、类目等因素决定,不受reverse和missingValue影响)
+		 */
+		GO_SEARCH;
+	}
+
+}

+ 23 - 14
search-api/src/main/java/com/uas/search/service/SearchService.java

@@ -6,6 +6,7 @@ import java.util.Set;
 
 import com.uas.search.exception.SearchException;
 import com.uas.search.model.PageParams;
+import com.uas.search.model.SPage;
 
 /**
  * 搜索服务的接口
@@ -53,20 +54,6 @@ public interface SearchService {
 	 */
 	public List<Map<String, Object>> getBrands(String keyword) throws SearchException;
 
-	/**
-	 * 根据关键词搜索产品(关键词可能是器件、类目、品牌,甚至可能是类目、品牌的混合)
-	 * 
-	 * @param keyword
-	 * @param params
-	 *            额外条件,可能带有翻页信息,filter中可以有:类目id(Long)、品牌id(Long)、属性过滤信息(Map(
-	 *            String,Object)可能过滤多个属性,,以属性id为键,以属性值为值)、库存是否不为0(Boolean)、
-	 *            现货数量是否不为0(Boolean)、呆滞库存数量是否不为0(Boolean)、样品数量是否不为0(Boolean),
-	 *            这些信息以键值对的形式进行传递,键为com.uas.search.utils.SearchConstants中的常量
-	 * @return
-	 * @throws SearchException
-	 */
-	public Map<String, Object> getComponentIds(String keyword, PageParams params) throws SearchException;
-
 	/**
 	 * 根据产品搜索获取产品类目id的统计
 	 * 
@@ -183,4 +170,26 @@ public interface SearchService {
 	public List<Map<String, String>> getSimilarPropertyValues(Long kindId, Long propertyId, String keyword, Long topNum)
 			throws SearchException;
 
+	/**
+	 * 根据关键词搜索批次(关键词可能是器件、类目、品牌)
+	 * 
+	 * @param keyword
+	 *            关键词
+	 * @param pageParams
+	 *            翻页、过滤、排序等信息
+	 *            <p>
+	 *            关于过滤,通过键值对指定过滤条件,键为
+	 *            {@link com.uas.search.model.PageParams.FilterField},值的类型由键决定:
+	 *            </p>
+	 *            <li>COMPONENT_KINDID: Long</li>
+	 *            <li>COMPONENT_BRANDID: Long</li>
+	 *            <li>COMPONENT_PROPERTIES: 键值对,键值分别为属性id、属性值</li>
+	 *            <li>COMPONENT_HAS_RESERVE: Boolean</li>
+	 *            <li>COMPONENT_HAS_SAMPLE: Boolean</li>
+	 *            <li>COMPONENT_HAS_ORIGINAL: Boolean</li>
+	 *            <li>COMPONENT_HAS_INACTION_STOCK: Boolean</li>
+	 * @return 批次id和分页信息
+	 */
+	public SPage<Long> searchGoodIds(String keyword, PageParams pageParams);
+
 }

+ 0 - 44
search-api/src/main/java/com/uas/search/utils/SearchConstants.java

@@ -1,44 +0,0 @@
-package com.uas.search.utils;
-
-/**
- * 器件搜索时以键值对的形式传递参数,所需要用到的键
- * 
- * @author sunyj
- * @since 2016年12月7日 上午11:15:36
- */
-public class SearchConstants {
-	/**
-	 * 类目id
-	 */
-	public static final String COMPONENT_KINDID_KEY = "kindId";
-
-	/**
-	 * 品牌id
-	 */
-	public static final String COMPONENT_BRANDID_KEY = "brandId";
-
-	/**
-	 * 属性信息
-	 */
-	public static final String COMPONENT_PROPERTIES_KEY = "properties";
-
-	/**
-	 * 库存
-	 */
-	public static final String COMPONENT_RESERVE_KEY = "reserve";
-
-	/**
-	 * 样品数量
-	 */
-	public static final String COMPONENT_SAMPLE_QTY_KEY = "sample_qty";
-
-	/**
-	 * 现货数量
-	 */
-	public static final String COMPONENT_ORIGINAL_QTY_KEY = "original_qty";
-
-	/**
-	 * 呆滞库存数量
-	 */
-	public static final String COMPONENT_INACTION_STOCK_QTY_KEY = "inaction_stock_qty";
-}