Browse Source

库存数量、现货数量、呆滞库存数量、样品数量过滤

sunyj 9 years ago
parent
commit
01120e691e

+ 20 - 11
search-console/src/main/java/com/uas/search/console/controller/SearchController.java

@@ -13,6 +13,8 @@ import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.ResponseBody;
 
+import com.alibaba.druid.util.StringUtils;
+import com.alibaba.fastjson.JSONObject;
 import com.uas.search.console.core.util.ContextUtils;
 import com.uas.search.console.dao.ComponentSimpleInfoDao;
 import com.uas.search.console.model.BrandSimpleInfo;
@@ -62,25 +64,32 @@ public class SearchController {
 		return searchService.getBrands(keyword);
 	}
 
-	@RequestMapping("/componentIds/{keyword}")
+	@RequestMapping("/componentIds")
 	@ResponseBody
-	public Map<String, Object> searchComponentIds(@PathVariable String keyword) {
-		return searchService.getComponentIds(keyword, new PageParams());
+	public Map<String, Object> searchComponentIds(String keyword, Integer page, Integer size, String filters) {
+		PageParams pageParams = new PageParams();
+		if (page != null) {
+			pageParams.setPage(page);
+		}
+		if (size != null) {
+			pageParams.setSize(size);
+		}
+		Map<String, Object> filtersMap = new HashMap<>();
+		if (!StringUtils.isEmpty(filters)) {
+			filtersMap.putAll(JSONObject.parseObject(filters));
+		}
+		pageParams.setFilters(filtersMap);
+		return searchService.getComponentIds(keyword, pageParams);
 	}
 
 	@Autowired
 	private ComponentSimpleInfoDao componentDao;
 
-	@RequestMapping("/components/{keyword}")
+	@RequestMapping("/components")
 	@ResponseBody
-	public List<ComponentSimpleInfo> searchComponents(@PathVariable String keyword) {
-		PageParams pageParams = new PageParams();
-		Map<String, Object> filters = new HashMap<>();
-		// filters.put("pr_329", "HRC");
-		// filters.put("20", "Fast Blow");
-		pageParams.setFilters(filters);
+	public List<ComponentSimpleInfo> searchComponents(String keyword, Integer page, Integer size, String filters) {
 		@SuppressWarnings("unchecked")
-		List<Long> ids = (List<Long>) searchService.getComponentIds(keyword, pageParams).get("componentIds");
+		List<Long> ids = (List<Long>) searchComponentIds(keyword, page, size, filters).get("componentIds");
 		if (CollectionUtils.isEmpty(ids)) {
 			return new ArrayList<ComponentSimpleInfo>();
 		}

+ 62 - 1
search-console/src/main/java/com/uas/search/console/model/ComponentSimpleInfo.java

@@ -60,6 +60,34 @@ public class ComponentSimpleInfo implements Serializable {
 	@Column(name = "cmp_brid")
 	private Long brandid;
 
+	/**
+	 * 以下为器件的库存交易属性,由器件对应的上架商品发生变化时,更新反应到器件
+	 */
+
+	/**
+	 * 器件的库存
+	 */
+	@Column(name = "cmp_reserve")
+	private Double reserve;
+
+	/**
+	 * 样品数量汇总
+	 */
+	@Column(name = "cmp_sampleqty")
+	private Double sampleQty;
+
+	/**
+	 * 现货数量
+	 */
+	@Column(name = "cmp_originalqty")
+	private Double originalQty;
+
+	/**
+	 * 呆滞库存数量
+	 */
+	@Column(name = "cmp_inastockqty")
+	private Double inactionStockQty;
+
 	/**
 	 * 带的属性及属性的值
 	 */
@@ -108,6 +136,38 @@ public class ComponentSimpleInfo implements Serializable {
 		this.brandid = brandid;
 	}
 
+	public Double getReserve() {
+		return reserve;
+	}
+
+	public void setReserve(Double reserve) {
+		this.reserve = reserve;
+	}
+
+	public Double getSampleQty() {
+		return sampleQty;
+	}
+
+	public void setSampleQty(Double sampleQty) {
+		this.sampleQty = sampleQty;
+	}
+
+	public Double getOriginalQty() {
+		return originalQty;
+	}
+
+	public void setOriginalQty(Double originalQty) {
+		this.originalQty = originalQty;
+	}
+
+	public Double getInactionStockQty() {
+		return inactionStockQty;
+	}
+
+	public void setInactionStockQty(Double inactionStockQty) {
+		this.inactionStockQty = inactionStockQty;
+	}
+
 	public Set<PropertyValueSimpleInfo> getProperties() {
 		return properties;
 	}
@@ -136,7 +196,8 @@ public class ComponentSimpleInfo implements Serializable {
 	@Override
 	public String toString() {
 		return "ComponentSimpleInfo [id=" + id + ", uuid=" + uuid + ", code=" + code + ", kindid=" + kindid
-				+ ", brandid=" + brandid + ", properties=" + properties + "]";
+				+ ", brandid=" + brandid + ", reserve=" + reserve + ", sampleQty=" + sampleQty + ", originalQty="
+				+ originalQty + ", inactionStockQty=" + inactionStockQty + ", properties=" + properties + "]";
 	}
 
 }

+ 46 - 6
search-console/src/main/java/com/uas/search/console/service/impl/SearchServiceImpl.java

@@ -14,10 +14,12 @@ import org.apache.lucene.index.Term;
 import org.apache.lucene.search.BooleanClause;
 import org.apache.lucene.search.BooleanQuery;
 import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.NumericRangeQuery;
 import org.apache.lucene.search.PrefixQuery;
 import org.apache.lucene.search.ScoreDoc;
 import org.apache.lucene.search.TermQuery;
 import org.apache.lucene.search.TopDocs;
+import org.apache.lucene.search.BooleanClause.Occur;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
@@ -156,22 +158,60 @@ public class SearchServiceImpl implements SearchService, InnerSearchService {
 			Map<String, Object> filters = page.getFilters();
 			if (!CollectionUtils.isEmpty(filters)) {
 				// 筛选类目
-				if (!StringUtils.isEmpty(filters.get("kindId"))) {
-					String kindId = filters.get("kindId").toString();
+				if (!StringUtils.isEmpty(filters.get(com.uas.search.utils.SearchConstants.COMPONENT_KINDID_KEY))) {
+					String kindId = filters.get(com.uas.search.utils.SearchConstants.COMPONENT_KINDID_KEY).toString();
 					TermQuery kindQuery = new TermQuery(new Term(SearchConstants.COMPONENT_KINDID_FIELD, kindId));
 					booleanQuery.add(kindQuery, BooleanClause.Occur.MUST);
 				}
 
 				// 筛选品牌
-				if (!StringUtils.isEmpty(filters.get("brandId"))) {
-					String brandId = filters.get("brandId").toString();
+				if (!StringUtils.isEmpty(filters.get(com.uas.search.utils.SearchConstants.COMPONENT_BRANDID_KEY))) {
+					String brandId = filters.get(com.uas.search.utils.SearchConstants.COMPONENT_BRANDID_KEY).toString();
 					TermQuery brandQuery = new TermQuery(new Term(SearchConstants.COMPONENT_BRANDID_FIELD, brandId));
 					booleanQuery.add(brandQuery, BooleanClause.Occur.MUST);
 				}
 
+				// 库存不为0
+				if (!StringUtils.isEmpty(filters.get(com.uas.search.utils.SearchConstants.COMPONENT_RESERVE_KEY))) {
+					Boolean isReserveNotEmpty = (Boolean) filters
+							.get(com.uas.search.utils.SearchConstants.COMPONENT_RESERVE_KEY);
+					if (isReserveNotEmpty) {
+						booleanQuery.add(NumericRangeQuery.newDoubleRange(SearchConstants.COMPONENT_RESERVE_FIELD, 0.0,
+								Double.MAX_VALUE, false, true), BooleanClause.Occur.MUST);
+					}
+				}
+
+				// 现货、呆滞库存、样品数量不为0,取或的关系
+				if (!StringUtils.isEmpty(filters.get(com.uas.search.utils.SearchConstants.COMPONENT_SAMPLE_QTY_KEY))
+						|| !StringUtils
+								.isEmpty(filters.get(com.uas.search.utils.SearchConstants.COMPONENT_ORIGINAL_QTY_KEY))
+						|| !StringUtils.isEmpty(
+								filters.get(com.uas.search.utils.SearchConstants.COMPONENT_INACTION_STOCK_QTY_KEY))) {
+					BooleanQuery booleanQuery2 = new BooleanQuery();
+					if (!StringUtils
+							.isEmpty(filters.get(com.uas.search.utils.SearchConstants.COMPONENT_SAMPLE_QTY_KEY))) {
+						booleanQuery2.add(NumericRangeQuery.newDoubleRange(SearchConstants.COMPONENT_SAMPLE_QTY_FIELD,
+								0.0, Double.MAX_VALUE, false, true), BooleanClause.Occur.SHOULD);
+					}
+					if (!StringUtils
+							.isEmpty(filters.get(com.uas.search.utils.SearchConstants.COMPONENT_ORIGINAL_QTY_KEY))) {
+						booleanQuery2.add(NumericRangeQuery.newDoubleRange(SearchConstants.COMPONENT_ORIGINAL_QTY_FIELD,
+								0.0, Double.MAX_VALUE, false, true), BooleanClause.Occur.SHOULD);
+					}
+					if (!StringUtils.isEmpty(
+							filters.get(com.uas.search.utils.SearchConstants.COMPONENT_INACTION_STOCK_QTY_KEY))) {
+						booleanQuery2.add(
+								NumericRangeQuery.newDoubleRange(SearchConstants.COMPONENT_INACTION_STOCK_QTY_FIELD,
+										0.0, Double.MAX_VALUE, false, true),
+								BooleanClause.Occur.SHOULD);
+					}
+					booleanQuery.add(booleanQuery2, Occur.MUST);
+				}
+
 				// 属性过滤
-				if (!StringUtils.isEmpty(filters.get("properties"))) {
-					JSONObject proJSON = FastjsonUtils.parseObject(String.valueOf(filters.get("properties")));
+				if (!StringUtils.isEmpty(filters.get(com.uas.search.utils.SearchConstants.COMPONENT_PROPERTIES_KEY))) {
+					JSONObject proJSON = FastjsonUtils.parseObject(
+							String.valueOf(filters.get(com.uas.search.utils.SearchConstants.COMPONENT_PROPERTIES_KEY)));
 					for (String key : proJSON.keySet()) {
 						String value = String.valueOf(proJSON.get(key));
 						if (!StringUtils.isEmpty(value)) {

+ 13 - 0
search-console/src/main/java/com/uas/search/console/util/DocumentToObjectUtils.java

@@ -85,6 +85,19 @@ public class DocumentToObjectUtils {
 		component.setUuid(document.get(SearchConstants.COMPONENT_UUID_FIELD));
 		component.setKindid(Long.valueOf(document.get(SearchConstants.COMPONENT_KINDID_FIELD)));
 		component.setBrandid(Long.valueOf(document.get(SearchConstants.COMPONENT_BRANDID_FIELD)));
+		if (!StringUtils.isEmpty(document.get(SearchConstants.COMPONENT_RESERVE_FIELD))) {
+			component.setReserve(Double.valueOf(document.get(SearchConstants.COMPONENT_RESERVE_FIELD)));
+		}
+		if (!StringUtils.isEmpty(document.get(SearchConstants.COMPONENT_SAMPLE_QTY_FIELD))) {
+			component.setSampleQty(Double.valueOf(document.get(SearchConstants.COMPONENT_SAMPLE_QTY_FIELD)));
+		}
+		if (!StringUtils.isEmpty(document.get(SearchConstants.COMPONENT_ORIGINAL_QTY_FIELD))) {
+			component.setOriginalQty(Double.valueOf(document.get(SearchConstants.COMPONENT_ORIGINAL_QTY_FIELD)));
+		}
+		if (!StringUtils.isEmpty(document.get(SearchConstants.COMPONENT_INACTION_STOCK_QTY_FIELD))) {
+			component.setInactionStockQty(
+					Double.valueOf(document.get(SearchConstants.COMPONENT_INACTION_STOCK_QTY_FIELD)));
+		}
 		return component;
 	}
 

+ 18 - 5
search-console/src/main/java/com/uas/search/console/util/MergeComponentData.java

@@ -33,8 +33,8 @@ public class MergeComponentData {
 	 * 将从本地文件读取的一行字符串数据解析为器件对象
 	 * 
 	 * @param data
-	 *            格式为"CMP_ID" "CMP_BRID" "CMP_CODE" "CMP_KIID" "CMP_UUID",如1 149
-	 *            "10120-5212PC" 295 "2502600600000001"
+	 *            格式为"CMP_ID" "CMP_BRID" "CMP_CODE" "CMP_KIID" "CMP_RESERVE"
+	 *            "CMP_SAMPLEQTY" "CMP_ORIGINALQTY" "CMP_UUID" "CMP_INASTOCKQTY"
 	 * @return
 	 */
 	private static ComponentSimpleInfo parseComponent(String data) {
@@ -44,7 +44,19 @@ public class MergeComponentData {
 		component.setBrandid(Long.parseLong(strs[1]));
 		component.setCode(strs[2].substring(1, strs[2].length() - 1));
 		component.setKindid(Long.parseLong(strs[3]));
-		component.setUuid(strs[4].substring(1, strs[4].length() - 1));
+		if (!StringUtils.isEmpty(strs[4])) {
+			component.setReserve(Double.valueOf(strs[4]));
+		}
+		if (!StringUtils.isEmpty(strs[5])) {
+			component.setSampleQty(Double.valueOf(strs[5]));
+		}
+		if (!StringUtils.isEmpty(strs[6])) {
+			component.setOriginalQty(Double.valueOf(strs[6]));
+		}
+		component.setUuid(strs[7].substring(1, strs[7].length() - 1));
+		if (strs.length == 9 && !StringUtils.isEmpty(strs[8])) {
+			component.setInactionStockQty(Double.valueOf(strs[8]));
+		}
 		return component;
 	}
 
@@ -95,7 +107,8 @@ public class MergeComponentData {
 					printWriter.flush();
 					printWriter.close();
 					fileIndex++;
-					printWriter = new PrintWriter(DATA_DIR + "\\components\\ComponentWithProperty_" + fileIndex + ".txt");
+					printWriter = new PrintWriter(
+							DATA_DIR + "\\components\\ComponentWithProperty_" + fileIndex + ".txt");
 				}
 
 				ComponentSimpleInfo component = parseComponent(componentLine);
@@ -113,7 +126,7 @@ public class MergeComponentData {
 					propertyValue = parsePropertyValue(propertyValueLine);
 				}
 				component.setProperties(properties);
-				System.out.println(component);
+				// System.out.println(component);
 				printWriter.println(JSONObject.toJSONString(component));
 			}
 			printWriter.flush();

+ 16 - 0
search-console/src/main/java/com/uas/search/console/util/ObjectToDocumentUtils.java

@@ -4,6 +4,7 @@ import java.util.Set;
 
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.lucene.document.Document;
+import org.apache.lucene.document.DoubleField;
 import org.apache.lucene.document.Field.Store;
 import org.apache.lucene.document.LongField;
 import org.apache.lucene.document.StringField;
@@ -141,6 +142,21 @@ public class ObjectToDocumentUtils {
 				Store.YES));
 		document.add(new StringField(SearchConstants.COMPONENT_BRANDID_FIELD, String.valueOf(component.getBrandid()),
 				Store.YES));
+		if (component.getReserve() != null) {
+			document.add(new DoubleField(SearchConstants.COMPONENT_RESERVE_FIELD, component.getReserve(), Store.YES));
+		}
+		if (component.getSampleQty() != null) {
+			document.add(
+					new DoubleField(SearchConstants.COMPONENT_SAMPLE_QTY_FIELD, component.getSampleQty(), Store.YES));
+		}
+		if (component.getOriginalQty() != null) {
+			document.add(new DoubleField(SearchConstants.COMPONENT_ORIGINAL_QTY_FIELD, component.getOriginalQty(),
+					Store.YES));
+		}
+		if (component.getInactionStockQty() != null) {
+			document.add(new DoubleField(SearchConstants.COMPONENT_INACTION_STOCK_QTY_FIELD,
+					component.getInactionStockQty(), Store.YES));
+		}
 
 		// 属性值加入索引,索引中field的键:"pr_"前缀连接属性的id
 		Set<PropertyValueSimpleInfo> propertyValues = component.getProperties();

+ 4 - 1
search-console/src/main/java/com/uas/search/console/util/SearchConstants.java

@@ -98,10 +98,13 @@ public class SearchConstants {
 	public static final String COMPONENT_ID_FIELD = "cmp_id";
 	public static final String COMPONENT_UUID_FIELD = "cmp_uuid";
 	public static final String COMPONENT_CODE_FIELD = "cmp_code";
-	public static final String COMPONENT_RESERVE_FIELD = "cmp_reserve";
 	public static final String COMPONENT_KINDID_FIELD = "cmp_kind_id";
 	public static final String COMPONENT_KINDNAME_FIELD = "cmp_kind_name_cn";
 	public static final String COMPONENT_BRANDID_FIELD = "cmp_brand_id";
+	public static final String COMPONENT_RESERVE_FIELD = "cmp_reserve";
+	public static final String COMPONENT_SAMPLE_QTY_FIELD = "cmp_sample_qty";
+	public static final String COMPONENT_ORIGINAL_QTY_FIELD = "cmp_original_qty";
+	public static final String COMPONENT_INACTION_STOCK_QTY_FIELD = "cmp_inaction_stock_qty";
 	public static final String COMPONENT_BRANDUUID_FIELD = "cmp_brand_uuid";
 	public static final String COMPONENT_BRANDNAME_FIELD = "cmp_brand_name_cn";
 	/**

+ 5 - 4
search-console/src/main/webapp/WEB-INF/views/console.html

@@ -13,12 +13,13 @@
 				<ol>
 					<strong><li class="title">搜索</li></strong>
 					<ol>
-						<li><a target="_blank">search/kinds/电阻</a></li>
-						<li><a target="_blank">search/brands/Panasonic</a></li>
-						<li><a target="_blank">search/components/aaa</a></li>
 						<li><a target="_blank">search/kindIds/电阻</a></li>
+						<li><a target="_blank">search/kinds/电阻</a></li>
 						<li><a target="_blank">search/brandIds/Panasonic</a></li>
-						<li><a target="_blank">search/componentIds/aaa</a></li>
+						<li><a target="_blank">search/brands/Panasonic</a></li>
+						<li>search/componentIds?keyword=a&page=1&size=5&filters={"kindId":401,"brandId":45,"reserve":true,"sample_qty":true,"original_qty":true,"inaction_stock_qty":true,"properties":{"275":"92%20dB","781":"Tube"}}</li>
+						<li><a target="_blank">search/componentIds?keyword=aaa</a></li>
+						<li><a target="_blank">search/components?keyword=aaa</a></li>
 					</ol>