|
|
@@ -30,7 +30,7 @@ import com.uas.platform.b2c.prod.product.component.modal.ComponentInfo;
|
|
|
import com.uas.platform.b2c.prod.store.dao.StoreInDao;
|
|
|
import com.uas.platform.b2c.prod.store.model.StoreIn;
|
|
|
import com.uas.platform.b2c.prod.store.model.StoreStatus;
|
|
|
-
|
|
|
+import com.uas.platform.b2c.prod.store.model.StoreType;
|
|
|
import com.uas.platform.b2c.trade.order.dao.OrderDetailDao;
|
|
|
import com.uas.platform.b2c.trade.vendor.model.VendorIntroduction;
|
|
|
import com.uas.platform.b2c.trade.vendor.service.VendorIntroductionService;
|
|
|
@@ -39,22 +39,6 @@ import com.uas.platform.core.model.PageInfo;
|
|
|
import com.uas.platform.core.model.PageParams;
|
|
|
import com.uas.platform.core.persistence.criteria.PredicateUtils;
|
|
|
import com.uas.search.exception.SearchException;
|
|
|
-import java.io.IOException;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Iterator;
|
|
|
-import java.util.LinkedHashMap;
|
|
|
-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;
|
|
|
-import javax.persistence.criteria.Root;
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -68,6 +52,16 @@ import org.springframework.ui.ModelMap;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
+import javax.persistence.criteria.CriteriaBuilder;
|
|
|
+import javax.persistence.criteria.CriteriaQuery;
|
|
|
+import javax.persistence.criteria.Predicate;
|
|
|
+import javax.persistence.criteria.Root;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.*;
|
|
|
+import java.util.Map.Entry;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
/**
|
|
|
* 搜索索引
|
|
|
*
|
|
|
@@ -660,7 +654,7 @@ public class SearcherServiceImpl implements SearcherService {
|
|
|
}
|
|
|
try {
|
|
|
if (type.equals("store") || type.equals("all")) {
|
|
|
- List<VendorIntroduction> vendorIntroductions = vendorIntroductionService.getVendorIntroduction(1,1024*1024*1024,keyword,null).getContent();
|
|
|
+ List<VendorIntroduction> vendorIntroductions = vendorIntroductionService.getVendorIntroduction(DEFAULT_PAGE, DEFAULT_SIZE, 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())
|
|
|
));
|
|
|
if (type.equals("store")) {
|
|
|
@@ -684,6 +678,85 @@ public class SearcherServiceImpl implements SearcherService {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取产品联想词 , 参数包括店铺信息
|
|
|
+ *
|
|
|
+ * @param keyword 关键词
|
|
|
+ * @param type 搜索类型
|
|
|
+ * @param storeTypes 店铺类型 1个或多个 多个以, 隔开
|
|
|
+ * @return 联想词结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> getSimilarKeywordsWithStoreTypes(String keyword, String type, String storeTypes) {
|
|
|
+ Map<String, Object> result = null;
|
|
|
+ if (StringUtils.isEmpty(type)) {
|
|
|
+ type = "all";
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ if ("store".equals(type) || "all".equals(type)) {
|
|
|
+ PageInfo pageInfo = new PageInfo(DEFAULT_PAGE, DEFAULT_SIZE);
|
|
|
+ List<StoreIn> stores = getStorePageByStoreTypes(pageInfo,keyword,storeTypes).getContent();
|
|
|
+ List<Object> resultMap = FastjsonUtils.fromJsonArray(JSON.toJSONString(stores.stream().map(StoreIn::getStoreName).map(en -> {Map s = new HashMap ();s.put("name", en);return s;}).collect(Collectors.toList())
|
|
|
+ ));
|
|
|
+ if ("store".equals(type)) {
|
|
|
+ result= new HashMap<>();
|
|
|
+ result.put("result",resultMap);
|
|
|
+ } else {
|
|
|
+ result = searchService.getSimilarKeywordsWithStoreTypes(keyword, type, storeTypes);
|
|
|
+ result.put("store", resultMap);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ result = searchService.getSimilarKeywordsWithStoreTypes(keyword, type, storeTypes);
|
|
|
+ }
|
|
|
+ } catch (SearchException e) {
|
|
|
+ throwSystemException(e);
|
|
|
+ }
|
|
|
+ for (Entry<String, Object> entry : result.entrySet()) {
|
|
|
+ if (((List) entry.getValue()).size() > 8) {
|
|
|
+ entry.setValue(((List) entry.getValue()).subList(0, 8));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据关键词和店铺类型获取店铺信息
|
|
|
+ *
|
|
|
+ * @param pageInfo 分页参数
|
|
|
+ * @param keyword 关键词
|
|
|
+ * @param storeTypes 店铺类型 多个时 以,隔开
|
|
|
+ * @return 店铺分页信息
|
|
|
+ */
|
|
|
+ public Page<StoreIn> getStorePageByStoreTypes(PageInfo pageInfo, String keyword, String storeTypes) {
|
|
|
+ if (StringUtils.hasText(keyword)){
|
|
|
+ pageInfo.expression(PredicateUtils.like("storeName", keyword, false));
|
|
|
+ }
|
|
|
+ if (StringUtils.hasText(storeTypes)){
|
|
|
+ List<StoreType> storeTypeList = new ArrayList<>();
|
|
|
+ if (storeTypes.contains(StoreType.AGENCY.toString())) {
|
|
|
+ storeTypeList.add(StoreType.AGENCY);
|
|
|
+ }
|
|
|
+ if (storeTypes.contains(StoreType.DISTRIBUTION.toString())) {
|
|
|
+ storeTypeList.add(StoreType.DISTRIBUTION);
|
|
|
+ }
|
|
|
+ if (storeTypes.contains(StoreType.ORIGINAL_FACTORY.toString())) {
|
|
|
+ storeTypeList.add(StoreType.ORIGINAL_FACTORY);
|
|
|
+ }
|
|
|
+ if (storeTypes.contains(StoreType.CONSIGNMENT.toString())) {
|
|
|
+ storeTypeList.add(StoreType.CONSIGNMENT);
|
|
|
+ }
|
|
|
+ pageInfo.expression(PredicateUtils.in("type", storeTypeList, false));
|
|
|
+ }
|
|
|
+
|
|
|
+ return storeInDao.findAll(new Specification<StoreIn>() {
|
|
|
+ @Override
|
|
|
+ public Predicate toPredicate(Root<StoreIn> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
|
|
|
+ criteriaQuery.where(pageInfo.getPredicates(root, criteriaQuery, criteriaBuilder));
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }, pageInfo);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public Map<String, Object> getProductSimilarKeywords(String keyword) {
|
|
|
Map<String, Object> result = null;
|
|
|
@@ -785,7 +858,7 @@ public class SearcherServiceImpl implements SearcherService {
|
|
|
SystemSession.getUser().getEnterprise() == null ? null : SystemSession.getUser().getEnterprise().getUu() );
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
+ /**
|
|
|
* 捕获SearchException抛出SystemException
|
|
|
*
|
|
|
* @param e
|