Browse Source

新增编辑物料时联想词方法更新,输入英文匹配英文结果,输入中文匹配中文结果

git-svn-id: svn+ssh://10.10.101.21/source/platform/platform-b2b@9795 f3bf4e98-0cf0-11e4-a00c-a99a8b9d557d
hejq 8 years ago
parent
commit
b61e6e4261

+ 12 - 0
src/main/java/com/uas/platform/b2b/search/SearchController.java

@@ -431,6 +431,18 @@ public class SearchController {
 		return searchService.getSimilarKinds(keyword);
 	}
 
+	/**
+	 * 根据关键才获取品牌联想词(分类)
+	 * 
+	 * @param keyword
+	 * @return
+	 */
+	@RequestMapping(value = "/similarBrandByCode", method = RequestMethod.GET)
+	@ResponseBody
+	public List<Map<String, Object>> getSimilarBrandsByCode(String keyword) {
+		return searchService.getSimilarBrandsByCode(keyword);
+	}
+
 	/**
 	 * 类目联想词,点击返回类目信息
 	 * 

+ 8 - 0
src/main/java/com/uas/platform/b2b/search/SearchService.java

@@ -387,6 +387,14 @@ public interface SearchService {
 
 	List<Map<String, Object>> getSimilarBrands(String keyword);
 
+	/**
+	 * 分类获取品牌联想词
+	 * 
+	 * @param keyword
+	 * @return
+	 */
+	public List<Map<String, Object>> getSimilarBrandsByCode(String keyword);
+
 	/**
 	 * 类目联想词
 	 * 

+ 134 - 31
src/main/java/com/uas/platform/b2b/search/SearchServiceImpl.java

@@ -276,6 +276,16 @@ public class SearchServiceImpl implements com.uas.platform.b2b.search.SearchServ
 	 */
 	private static final int MAXPAGESIZE = 50;
 
+	/**
+	 * 匹配中文正则式
+	 */
+	private static final String CHINESE_REGEXP = "^[\u4e00-\u9fa5]*$";
+
+	/**
+	 * 匹配英文正则式
+	 */
+	private static final String ENGLISH_REGEXP = "^[A-Za-z]+$";
+
 	private ConcurrentHashMap<String, Field> sortFields = new ConcurrentHashMap<String, Field>();
 
 	private Field getPropertyField(Class<?> targetCls, String properyName) {
@@ -1024,52 +1034,145 @@ public class SearchServiceImpl implements com.uas.platform.b2b.search.SearchServ
 	}
 
 	@Override
-	public List<Map<String, Object>> getSimilarKinds(String keyword) {
-		List<String> kindList = similarKinds(keyword);
-		List<Kind> contents = new ArrayList<>();
-		for (String kind : kindList) {
-			List<Kind> temps = kindDao.findByNameCn(kind);
-			if (!CollectionUtils.isEmpty(temps)) {
-				contents.add(temps.get(0));
-			} else { // 中文品牌找不到,找英文的
-				temps = kindDao.findByNameEn(kind);
+	public List<Map<String, Object>> getSimilarBrandsByCode(String keyword) {
+		List<String> brandList = similarBrandsByCode(keyword);
+		List<Brand> contents = new ArrayList<>();
+		List<Map<String, Object>> brands = new ArrayList<>();
+		for (String brand : brandList) {
+			if (keyword.matches(CHINESE_REGEXP)) {
+				List<Brand> temps = brandDao.findByNameCn(brand);
+				if (!CollectionUtils.isEmpty(temps)) {
+					contents.add(temps.get(0));
+				}
+			} else {
+				List<Brand> temps = brandDao.findByNameEn(brand);
 				if (!CollectionUtils.isEmpty(temps)) {
 					contents.add(temps.get(0));
 				}
 			}
 		}
-		List<Map<String, Object>> brands = new ArrayList<>();
-		for (Kind kind : contents) {
+		for (Brand brand : contents) {
 			Map<String, Object> temp = new HashMap<>();
-			temp.put("kindCn", kind.getNameCn());
-			temp.put("kindEn", kind.getNameEn());
+			if (keyword.matches(CHINESE_REGEXP)) {
+				temp.put("brandName", brand.getNameCn());
+			} else {
+				temp.put("brandName", brand.getNameEn());
+			}
 			brands.add(temp);
 		}
 		return brands;
 	}
 
-	private List<String> similarKinds(String keyword) {
-		SPage<String> kindCns = searchService.similar(keyword, Table_name.PRODUCT$KIND, SIMILAR_NUM, "ki_name_cn");
-		// 相似的类目中文名数量足够,直接返回
-		List<String> kindCnList = kindCns.getContent();
-		if (kindCnList != null && kindCnList.size() == SIMILAR_NUM) {
-			return kindCnList;
+	private List<String> similarBrandsByCode(String keyword) {
+		List<String> result = new ArrayList<>();
+		if (keyword.matches(CHINESE_REGEXP)) {
+			SPage<String> brandCns = searchService.similar(keyword, Table_name.PRODUCT$BRAND, SIMILAR_NUM,
+					"br_name_cn");
+			// 相似的品牌中文名数量足够,直接返回
+			List<String> brandCnList = brandCns.getContent();
+			if (brandCnList != null && brandCnList.size() == SIMILAR_NUM) {
+				return brandCnList;
+			}
+			result = brandCnList;
+		} else if (keyword.matches(ENGLISH_REGEXP)) {
+			SPage<String> brandEns = searchService.similar(keyword, Table_name.PRODUCT$BRAND, SIMILAR_NUM,
+					"br_name_en");
+			List<String> brandEnList = brandEns.getContent();
+			if (brandEnList != null && brandEnList.size() == SIMILAR_NUM) {
+				return brandEnList;
+			}
+			result = brandEnList;
+		} else {
+			SPage<String> brandCns = searchService.similar(keyword, Table_name.PRODUCT$BRAND, SIMILAR_NUM,
+					"br_name_cn");
+			// 相似的品牌中文名数量足够,直接返回
+			List<String> brandCnList = brandCns.getContent();
+			if (brandCnList != null && brandCnList.size() == SIMILAR_NUM) {
+				return brandCnList;
+			}
+			result = brandCnList;
+			// 获取相似品牌英文名
+			SPage<String> brandEns = searchService.similar(keyword, Table_name.PRODUCT$BRAND, SIMILAR_NUM,
+					"br_name_en");
+			List<String> brandEnList = brandEns.getContent();
+			if (!CollectionUtils.isEmpty(brandEnList)) {
+				result.addAll(brandEnList);
+				// 如果总的数量超出SIMILAR_NUM,去除多余的元素
+				if (result.size() > SIMILAR_NUM) {
+					removeElements(result, SIMILAR_NUM);
+					return result;
+				}
+			}
 		}
+		return result;
+	}
 
-		List<String> result = kindCnList;
-		if (result == null) {
-			result = new ArrayList<>();
+	@Override
+	public List<Map<String, Object>> getSimilarKinds(String keyword) {
+		List<String> kindList = similarKinds(keyword);
+		List<Kind> contents = new ArrayList<>();
+		List<Map<String, Object>> kinds = new ArrayList<>();
+		for (String kind : kindList) {
+			if (keyword.matches(ENGLISH_REGEXP)) {
+				List<Kind> temps = kindDao.findByNameEn(kind);
+				if (!CollectionUtils.isEmpty(temps)) {
+					contents.add(temps.get(0));
+				}
+			} else {
+				List<Kind> temps = kindDao.findByNameCn(kind);
+				if (!CollectionUtils.isEmpty(temps)) {
+					contents.add(temps.get(0));
+				}
+			}
 		}
+		for (Kind kind : contents) {
+			Map<String, Object> temp = new HashMap<>();
+			if (keyword.matches(ENGLISH_REGEXP)) {
+				temp.put("kindName", kind.getNameEn());
+			} else {
+				temp.put("kindName", kind.getNameCn());
+			}
+			kinds.add(temp);
+		}
+		return kinds;
+	}
 
-		// 获取相似类目英文名
-		SPage<String> brandEns = searchService.similar(keyword, Table_name.PRODUCT$KIND, SIMILAR_NUM, "ki_name_en");
-		List<String> brandEnList = brandEns.getContent();
-		if (!CollectionUtils.isEmpty(brandEnList)) {
-			result.addAll(brandEnList);
-			// 如果总的数量超出SIMILAR_NUM,去除多余的元素
-			if (result.size() > SIMILAR_NUM) {
-				removeElements(result, SIMILAR_NUM);
-				return result;
+	private List<String> similarKinds(String keyword) {
+		List<String> result = new ArrayList<>();
+		if (keyword.matches(CHINESE_REGEXP)) {
+			SPage<String> kindCns = searchService.similar(keyword, Table_name.PRODUCT$KIND, SIMILAR_NUM, "ki_name");
+			// 相似的类目中文名数量足够,直接返回
+			List<String> kindCnList = kindCns.getContent();
+			if (kindCnList != null && kindCnList.size() == SIMILAR_NUM) {
+				return kindCnList;
+			}
+			result = kindCnList;
+		} else if (keyword.matches(ENGLISH_REGEXP)) {
+			SPage<String> kindEns = searchService.similar(keyword, Table_name.PRODUCT$KIND, SIMILAR_NUM, "ki_name_en");
+			// 相似的类目中文名数量足够,直接返回
+			List<String> kindEnList = kindEns.getContent();
+			if (kindEnList != null && kindEnList.size() == SIMILAR_NUM) {
+				return kindEnList;
+			}
+			result = kindEnList;
+		} else {
+			SPage<String> kindCns = searchService.similar(keyword, Table_name.PRODUCT$KIND, SIMILAR_NUM, "ki_name");
+			// 相似的类目中文名数量足够,直接返回
+			List<String> kindCnList = kindCns.getContent();
+			if (kindCnList != null && kindCnList.size() == SIMILAR_NUM) {
+				return kindCnList;
+			}
+			result = kindCnList;
+			// 获取相似类目英文名
+			SPage<String> kindEns = searchService.similar(keyword, Table_name.PRODUCT$KIND, SIMILAR_NUM, "ki_name_en");
+			List<String> kindEnList = kindEns.getContent();
+			if (!CollectionUtils.isEmpty(kindEnList)) {
+				result.addAll(kindEnList);
+				// 如果总的数量超出SIMILAR_NUM,去除多余的元素
+				if (result.size() > SIMILAR_NUM) {
+					removeElements(result, SIMILAR_NUM);
+					return result;
+				}
 			}
 		}
 		return result;

+ 16 - 16
src/main/webapp/resources/js/index/app.js

@@ -10659,17 +10659,17 @@ define([ 'toaster', 'charts', 'ngTable', 'common/services', 'common/directives',
 	    
         // 设置类目
         $scope.onAssociateKindClick = function(kind, prodInfo) {
-        	$scope.prodInfo.kind = kind.kindCn;
+        	$scope.prodInfo.kind = kind.kindName;
         }
         
         // 设置名称
         $scope.onAssociateTitleClick = function(kind, prodInfo) {
-        	$scope.prodInfo.title = kind.kindCn;
+        	$scope.prodInfo.title = kind.kindName;
         }
         
         $scope.getSimilarBrands = function(value) {
         	if(value) {
-        		return Products.getSimilarBrand({keyword: value}).$promise.then(function(data) {
+        		return Products.getSimilarBrandByCode({keyword: value}).$promise.then(function(data) {
         			return data.map(function(item) {
         				return item;
         			});
@@ -10679,12 +10679,12 @@ define([ 'toaster', 'charts', 'ngTable', 'common/services', 'common/directives',
         
         // 设置导入品牌
         $scope.onAssociateBrandClick = function(brand, prodInfo) {
-        	$scope.prodInfo.brand = brand.brandEn;
+        	$scope.prodInfo.brand = brand.brandName;
         }
         
         // 设置标准品牌
         $scope.onAssociatePBrandClick = function(brand, prodInfo) {
-        	$scope.prodInfo.pbranden = brand.brandEn;
+        	$scope.prodInfo.pbranden = brand.brandName;
         }
         
         $scope.getSimilarComponents = function(value) {
@@ -10919,12 +10919,12 @@ define([ 'toaster', 'charts', 'ngTable', 'common/services', 'common/directives',
         };
 	    
         $scope.onAssociateKindClick = function(kind, prodInfo) {
-        	$scope.prodInfo.title = kind.kindCn;
+        	$scope.prodInfo.title = kind.kindName;
         }
         
         $scope.getSimilarBrands = function(value) {
         	if(value) {
-        		return Products.getSimilarBrand({keyword: value}).$promise.then(function(data) {
+        		return Products.getSimilarBrandByCode({keyword: value}).$promise.then(function(data) {
         			return data.map(function(item) {
         				return item;
         			});
@@ -10933,7 +10933,7 @@ define([ 'toaster', 'charts', 'ngTable', 'common/services', 'common/directives',
         }
         
         $scope.onAssociateBrandClick = function(brand, prodInfo) {
-        	$scope.prodInfo.brand = brand.brandEn;
+        	$scope.prodInfo.brand = brand.brandName;
         }
         
         $scope.getSimilarComponents = function(value) {
@@ -17767,12 +17767,12 @@ define([ 'toaster', 'charts', 'ngTable', 'common/services', 'common/directives',
         };
 	    
         $scope.onAssociateKindClick = function(kind, prodInfo) {
-        	$scope.prodInfo.title = kind.kindCn;
+        	$scope.prodInfo.title = kind.kindName;
         }
         
         $scope.getSimilarBrands = function(value) {
         	if(value) {
-        		return Products.getSimilarBrand({keyword: value}).$promise.then(function(data) {
+        		return Products.getSimilarBrandByCode({keyword: value}).$promise.then(function(data) {
         			return data.map(function(item) {
         				return item;
         			});
@@ -17781,7 +17781,7 @@ define([ 'toaster', 'charts', 'ngTable', 'common/services', 'common/directives',
         }
         
         $scope.onAssociateBrandClick = function(brand, prodInfo) {
-        	$scope.prodInfo.brand = brand.brandEn;
+        	$scope.prodInfo.brand = brand.brandName;
         }
         
         $scope.getSimilarComponents = function(value) {
@@ -17944,17 +17944,17 @@ define([ 'toaster', 'charts', 'ngTable', 'common/services', 'common/directives',
 	    
         // 设置类目
         $scope.onAssociateKindClick = function(kind, prodInfo) {
-        	$scope.prodInfo.kind = kind.kindCn;
+        	$scope.prodInfo.kind = kind.kindName;
         }
         
         // 设置名称
         $scope.onAssociateTitleClick = function(kind, prodInfo) {
-        	$scope.prodInfo.title = kind.kindCn;
+        	$scope.prodInfo.title = kind.kindName;
         }
         
         $scope.getSimilarBrands = function(value) {
         	if(value) {
-        		return Products.getSimilarBrand({keyword: value}).$promise.then(function(data) {
+        		return Products.getSimilarBrandByCode({keyword: value}).$promise.then(function(data) {
         			return data.map(function(item) {
         				return item;
         			});
@@ -17964,12 +17964,12 @@ define([ 'toaster', 'charts', 'ngTable', 'common/services', 'common/directives',
         
         // 设置导入品牌
         $scope.onAssociateBrandClick = function(brand, prodInfo) {
-        	$scope.prodInfo.brand = brand.brandEn;
+        	$scope.prodInfo.brand = brand.brandName;
         }
         
         // 设置标准品牌
         $scope.onAssociatePBrandClick = function(brand, prodInfo) {
-        	$scope.prodInfo.pbranden = brand.brandEn;
+        	$scope.prodInfo.pbranden = brand.brandName;
         }
         
         $scope.getSimilarComponents = function(value) {

+ 7 - 1
src/main/webapp/resources/js/index/services/Product.js

@@ -126,7 +126,13 @@ define([ 'ngResource'], function() {
 				url: 'search/similarComponents',
 				method: 'GET',
 				isArray: true
-			}
+			},
+			getSimilarBrandByCode: {
+				url: 'search/similarBrandByCode',
+				method: 'GET',
+				isArray: true
+					
+			},
 		});
 	}]).factory('PurcProduct', ['$resource', function($resource) {
 		return $resource('purcProduct', {}, {

+ 2 - 2
src/main/webapp/resources/tpl/index/baseInfo/newProdInfo.html

@@ -111,7 +111,7 @@
                 <div class="col-md-4">
                 	<input type="text"  ng-model="prodInfo.title" style="cursor: pointer;" required="true"
                 		ng-change="getSimilarKinds(prodInfo.title)" name="title" ng-focus="onFocus('title')"
-                		typeahead="kind.kindCn for kind in getSimilarKinds($viewValue)"
+                		typeahead="kind.kindName for kind in getSimilarKinds($viewValue)"
 						autocomplete="off" typeahead-on-select="onAssociateKindClick($item, prodInfo)"
 						spellcheck="false">
                 </div>
@@ -129,7 +129,7 @@
                 <div class="col-md-4">
                 	<input type="text"  ng-model="prodInfo.brand" style="cursor: pointer;" required="true"
                 		ng-change="getSimilarBrands(prodInfo.brand)" name="brand" ng-focus="onFocus('brand')"
-                		typeahead="brand.brandEn for brand in getSimilarBrands($viewValue)"
+                		typeahead="brand.brandName for brand in getSimilarBrands($viewValue)"
 						autocomplete="off" typeahead-on-select="onAssociateBrandClick($item, prodInfo)"
 						spellcheck="false">
                 </div>

+ 4 - 4
src/main/webapp/resources/tpl/index/baseInfo/productDetail.html

@@ -132,7 +132,7 @@
                 <div class="col-md-4">
                     <input type="text"  ng-model="prodInfo.title" style="cursor: pointer;" required="true"
                 		ng-change="getSimilarKinds(prodInfo.title)" name="title" ng-focus="onFocus('title')"
-                		typeahead="kind.kindCn for kind in getSimilarKinds($viewValue)"
+                		typeahead="kind.kindName for kind in getSimilarKinds($viewValue)"
 						autocomplete="off" typeahead-on-select="onAssociateTitleClick($item, prodInfo)"
 						spellcheck="false" ng-class="{'readonly-pointer': !prodInfo.$editing}"  ng-readonly="!prodInfo.$editing || !editstatus">
                 </div>
@@ -150,7 +150,7 @@
                 <div class="col-md-4">
                     <input type="text"  ng-model="prodInfo.brand" style="cursor: pointer;" required="true"
                 		ng-change="getSimilarBrands(prodInfo.brand)" name="brand" ng-focus="onFocus('brand')"
-                		typeahead="brand.brandEn for brand in getSimilarBrands($viewValue)"
+                		typeahead="brand.brandName for brand in getSimilarBrands($viewValue)"
 						autocomplete="off" typeahead-on-select="onAssociateBrandClick($item, prodInfo)"
 						spellcheck="false" ng-class="{'readonly-pointer': !prodInfo.$editing}"  ng-readonly="!prodInfo.$editing || !editstatus">
                 </div>
@@ -191,7 +191,7 @@
                 <div class="col-md-4"> 
                 	<input type="text"  ng-model="prodInfo.kind" style="cursor: pointer;" required="true"
                 		ng-change="getSimilarKinds(prodInfo.kind)" name="kind" ng-focus="onFocus('kind')"
-                		typeahead="kind.kindCn for kind in getSimilarKinds($viewValue)"
+                		typeahead="kind.kindName for kind in getSimilarKinds($viewValue)"
 						autocomplete="off" typeahead-on-select="onAssociateKindClick($item, prodInfo)"
 						spellcheck="false" ng-class="{'readonly-pointer': !prodInfo.$editing}"  ng-readonly="!prodInfo.$editing">
                 </div>
@@ -199,7 +199,7 @@
                 <div class="col-md-4">
                 	 <input type="text"  ng-model="prodInfo.pbranden" style="cursor: pointer;" required="true"
                 		ng-change="getSimilarBrands(prodInfo.pbranden)" name="pbranden" ng-focus="onFocus('pbranden')"
-                		typeahead="brand.brandEn for brand in getSimilarBrands($viewValue)"
+                		typeahead="brand.brandName for brand in getSimilarBrands($viewValue)"
 						autocomplete="off" typeahead-on-select="onAssociatePBrandClick($item, prodInfo)"
 						spellcheck="false" ng-class="{'readonly-pointer': !prodInfo.$editing}"  ng-readonly="!prodInfo.$editing">
                 </div>

+ 2 - 2
src/main/webapp/resources/tpl/index/purc/newProdInfo.html

@@ -108,7 +108,7 @@
                 <div class="col-md-4">
                 	<input type="text"  ng-model="prodInfo.title" style="cursor: pointer;" required="true"
                 		ng-change="getSimilarKinds(prodInfo.title)" name="title" ng-focus="onFocus('title')"
-                		typeahead="kind.kindCn for kind in getSimilarKinds($viewValue)"
+                		typeahead="kind.kindName for kind in getSimilarKinds($viewValue)"
 						autocomplete="off" typeahead-on-select="onAssociateKindClick($item, prodInfo)"
 						spellcheck="false">
 				</div>
@@ -126,7 +126,7 @@
                 <div class="col-md-4">
                     <input type="text"  ng-model="prodInfo.brand" style="cursor: pointer;" required="true"
                 		ng-change="getSimilarBrands(prodInfo.brand)" name="title" ng-focus="onFocus('brand')"
-                		typeahead="brand.brandEn for brand in getSimilarBrands($viewValue)"
+                		typeahead="brand.brandName for brand in getSimilarBrands($viewValue)"
 						autocomplete="off" typeahead-on-select="onAssociateBrandClick($item, prodInfo)"
 						spellcheck="false">
                 </div>

+ 4 - 4
src/main/webapp/resources/tpl/index/purc/productDetail.html

@@ -132,7 +132,7 @@
                 <div class="col-md-4">
                 	<input type="text"  ng-model="prodInfo.title" style="cursor: pointer;" required="true"
                 		ng-change="getSimilarKinds(prodInfo.title)" name="title" ng-focus="onFocus('title')"
-                		typeahead="kind.kindCn for kind in getSimilarKinds($viewValue)"
+                		typeahead="kind.kindName for kind in getSimilarKinds($viewValue)"
 						autocomplete="off" typeahead-on-select="onAssociateTitleClick($item, prodInfo)"
 						spellcheck="false" ng-class="{'readonly-pointer': !prodInfo.$editing}"  ng-readonly="!prodInfo.$editing || !editstatus">
                 </div>
@@ -150,7 +150,7 @@
                 <div class="col-md-4">
                 	<input type="text"  ng-model="prodInfo.brand" style="cursor: pointer;" required="true"
                 		ng-change="getSimilarBrands(prodInfo.brand)" name="brand" ng-focus="onFocus('brand')"
-                		typeahead="brand.brandEn for brand in getSimilarBrands($viewValue)"
+                		typeahead="brand.brandName for brand in getSimilarBrands($viewValue)"
 						autocomplete="off" typeahead-on-select="onAssociateBrandClick($item, prodInfo)"
 						spellcheck="false" ng-class="{'readonly-pointer': !prodInfo.$editing}"  ng-readonly="!prodInfo.$editing || !editstatus">
                 </div>
@@ -191,7 +191,7 @@
                 <div class="col-md-4"> 
                 	<input type="text"  ng-model="prodInfo.kind" style="cursor: pointer;" required="true"
                 		ng-change="getSimilarKinds(prodInfo.kind)" name="kind" ng-focus="onFocus('kind')"
-                		typeahead="kind.kindCn for kind in getSimilarKinds($viewValue)"
+                		typeahead="kind.kindName for kind in getSimilarKinds($viewValue)"
 						autocomplete="off" typeahead-on-select="onAssociateKindClick($item, prodInfo)"
 						spellcheck="false" ng-class="{'readonly-pointer': !prodInfo.$editing}"  ng-readonly="!prodInfo.$editing">
                 </div>
@@ -199,7 +199,7 @@
                 <div class="col-md-4">
                 	 <input type="text"  ng-model="prodInfo.pbranden" style="cursor: pointer;" required="true"
                 		ng-change="getSimilarBrands(prodInfo.pbranden)" name="pbranden" ng-focus="onFocus('pbranden')"
-                		typeahead="brand.brandEn for brand in getSimilarBrands($viewValue)"
+                		typeahead="brand.brandName for brand in getSimilarBrands($viewValue)"
 						autocomplete="off" typeahead-on-select="onAssociateBrandClick($item, prodInfo)"
 						spellcheck="false" ng-class="{'readonly-pointer': !prodInfo.$editing}"  ng-readonly="!prodInfo.$editing">
                 </div>