Browse Source

Merge remote-tracking branch 'origin/release-201819-wangcz' into release-201819-wangcz

yujia 7 years ago
parent
commit
da478edc94

+ 0 - 6
src/main/java/com/uas/platform/b2c/common/search/rpc/service/Impl/SearchServiceImpl.java

@@ -299,12 +299,6 @@ public class SearchServiceImpl implements SearchService{
             case KIND:
                 result = restTemplate.getForObject(sysConf.getSearchUrl() + SearchUrl.SIMILAR_KIND_URL, String.class, map);
                 break;
-            case STORE:
-                // 店铺(供应商)联想词
-                List<String> ens = enterpriseDao.findEnNameByName(keyword);
-                result = JSON.toJSONString(ens.stream().map(en -> {Map s = new HashMap ();s.put("name", en);return s;}).collect(Collectors.toList())
-                            );
-                break;
             default:
                 result = restTemplate.getForObject(sysConf.getSearchUrl() + SearchUrl.SIMILAR_KEYWORD_URL, String.class, map);
                 break;

+ 38 - 15
src/main/java/com/uas/platform/b2c/common/search/service/impl/SearcherServiceImpl.java

@@ -49,6 +49,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
+import java.util.stream.Collectors;
 import javax.persistence.criteria.CriteriaBuilder;
 import javax.persistence.criteria.CriteriaQuery;
 import javax.persistence.criteria.Predicate;
@@ -265,16 +266,21 @@ public class SearcherServiceImpl implements SearcherService {
 
         SPage<Long> stockPage = (SPage<Long>) ((JSONObject)results.get("stock")).toJavaObject(SPage.class);
         SPage<Long> futuresPage = (SPage<Long>) ((JSONObject)results.get("futures")).toJavaObject(SPage.class);
-        for (Object goodsId : stockPage.getContent()) {
-            goodsList.add(goodsDao.findOne(Long.valueOf(goodsId.toString())));
+        if (!CollectionUtils.isEmpty(stockPage.getContent())) {
+            for (Object goodsId : stockPage.getContent()) {
+                goodsList.add(goodsDao.findOne(Long.valueOf(goodsId.toString())));
+            }
         }
 
-        for (Object PrId : futuresPage.getContent()) {
-            Product product = productDao.findOne(Long.valueOf(PrId.toString()));
-            product.setEnName(enterpriseDao.findByUu(product.getEnUU()).getEnName());
-            productList.add(product);
+        if (!CollectionUtils.isEmpty(futuresPage.getContent())) {
+            for (Object PrId : futuresPage.getContent()) {
+                Product product = productDao.findOne(Long.valueOf(PrId.toString()));
+                product.setEnName(enterpriseDao.findByUu(product.getEnUU()).getEnName());
+                productList.add(product);
+            }
         }
 
+
         stockMap.put("content", goodsList);
         stockMap.put("total",stockPage.getTotalElement());
         stockMap.put("page",stockPage.getPage());
@@ -307,12 +313,16 @@ public class SearcherServiceImpl implements SearcherService {
         List<VendorIntroduction> vendorIntroductionsStocks = new ArrayList<>();
         List<VendorIntroduction> vendorIntroductionsFutures = new ArrayList<>();
 
-        for (String storeId : storeIds) {
-            vendorIntroductionsStocks.add(VendorIntroduction.convertFromStoreIn(storeInDao.findByUuid(storeId)));
+        if (!CollectionUtils.isEmpty(storeIds)) {
+            for (String storeId : storeIds) {
+                vendorIntroductionsStocks.add(VendorIntroduction.convertFromStoreIn(storeInDao.findByUuid(storeId)));
+            }
         }
 
-        for (Object enuu : enUUs) {
-            vendorIntroductionsFutures.add(VendorIntroduction.convertFromEnterprise(enterpriseDao.findByUu(Long.valueOf(enuu.toString()))));
+        if (!CollectionUtils.isEmpty(enUUs)) {
+            for (Object enuu : enUUs) {
+                vendorIntroductionsFutures.add(VendorIntroduction.convertFromEnterprise(enterpriseDao.findByUu(Long.valueOf(enuu.toString()))));
+            }
         }
 
         HashMap stock = new HashMap();
@@ -349,6 +359,7 @@ public class SearcherServiceImpl implements SearcherService {
         PageInfo pageInfo = new PageInfo(page);
         Page<StoreIn> stores = pageStoresByTypesAndKeyword(pageInfo, keyword, request);
         List<VendorIntroduction> vendorIntroductions = new ArrayList<>();
+
         for (StoreIn storeIn : stores) {
             vendorIntroductions.add(VendorIntroduction.convertFromStoreIn(storeIn));
         }
@@ -433,12 +444,16 @@ public class SearcherServiceImpl implements SearcherService {
                 List<VendorIntroduction> vendorIntroductionsStocks = new ArrayList<>();
                 List<VendorIntroduction> vendorIntroductionsFutures = new ArrayList<>();
 
-                for (String storeId : storeIds) {
-                    vendorIntroductionsStocks.add(VendorIntroduction.convertFromStoreIn(storeInDao.findByUuid(storeId)));
+                if (!CollectionUtils.isEmpty(storeIds)) {
+                    for (String storeId : storeIds) {
+                        vendorIntroductionsStocks.add(VendorIntroduction.convertFromStoreIn(storeInDao.findByUuid(storeId)));
+                    }
                 }
 
-                for (Object enuu : enUUs) {
-                    vendorIntroductionsFutures.add(VendorIntroduction.convertFromEnterprise(enterpriseDao.findByUu(Long.valueOf(enuu.toString()))));
+                if (!CollectionUtils.isEmpty(enUUs)) {
+                    for (Object enuu : enUUs) {
+                        vendorIntroductionsFutures.add(VendorIntroduction.convertFromEnterprise(enterpriseDao.findByUu(Long.valueOf(enuu.toString()))));
+                    }
                 }
 
                 HashMap stock = new HashMap();
@@ -598,7 +613,15 @@ public class SearcherServiceImpl implements SearcherService {
             type = "all";
         }
         try {
-            result = searchService.getSimilarKeywords(keyword, type);
+            if (type.equals("store")) {
+                List<VendorIntroduction> vendorIntroductions = vendorIntroductionService.getVendorIntroduction(1,1024*1024*1024,keyword,null).getContent();
+                List<Object> resultMap = FastjsonUtils.fromJsonArray(JSON.toJSONString(vendorIntroductions.stream().map(VendorIntroduction::getEnName).map(en -> {Map s = new HashMap ();s.put("name", en);return s;}).collect(Collectors.toList())
+                ));
+                result= new HashMap<>();
+                result.put("result",resultMap);
+            } else {
+                result = searchService.getSimilarKeywords(keyword, type);
+            }
         } catch (SearchException e) {
             throwSystemException(e);
         }