|
|
@@ -1,7 +1,9 @@
|
|
|
package com.uas.platform.b2c.common.search.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.uas.platform.b2c.common.account.dao.EnterpriseDao;
|
|
|
import com.uas.platform.b2c.common.account.model.User;
|
|
|
import com.uas.platform.b2c.common.search.dao.SearchHistoryDao;
|
|
|
import com.uas.platform.b2c.common.search.model.SearchHistory;
|
|
|
@@ -18,16 +20,24 @@ import com.uas.platform.b2c.prod.commodity.dao.GoodsDao;
|
|
|
import com.uas.platform.b2c.prod.commodity.dao.PCBDao;
|
|
|
import com.uas.platform.b2c.prod.commodity.dao.ProductDao;
|
|
|
import com.uas.platform.b2c.prod.commodity.model.Goods;
|
|
|
+import com.uas.platform.b2c.prod.commodity.model.Product;
|
|
|
import com.uas.platform.b2c.prod.product.brand.dao.BrandDao;
|
|
|
+import com.uas.platform.b2c.prod.product.brand.modal.Brand;
|
|
|
import com.uas.platform.b2c.prod.product.component.dao.ComponentDao;
|
|
|
import com.uas.platform.b2c.prod.product.component.dao.ComponentGoodsDao;
|
|
|
import com.uas.platform.b2c.prod.product.component.dao.ComponentInfoDao;
|
|
|
-import com.uas.platform.b2c.prod.product.component.modal.ComponentGoods;
|
|
|
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.trade.order.dao.OrderDetailDao;
|
|
|
+import com.uas.platform.b2c.trade.vendor.model.VendorIntroduction;
|
|
|
+import com.uas.platform.b2c.trade.vendor.service.VendorIntroductionService;
|
|
|
import com.uas.platform.core.exception.SystemException;
|
|
|
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;
|
|
|
@@ -39,12 +49,17 @@ import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Map.Entry;
|
|
|
import java.util.Set;
|
|
|
+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;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
+import org.springframework.data.jpa.domain.Specification;
|
|
|
import org.springframework.mobile.device.DeviceResolver;
|
|
|
import org.springframework.mobile.device.LiteDeviceResolver;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -91,6 +106,18 @@ public class SearcherServiceImpl implements SearcherService {
|
|
|
@Autowired
|
|
|
private OrderDetailDao orderDetailDao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private VendorIntroductionService vendorIntroductionService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private StoreInDao storeInDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private EnterpriseDao enterpriseDao;
|
|
|
+
|
|
|
+ // private StoreInService storeInService;
|
|
|
+
|
|
|
+
|
|
|
private Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
private final DeviceResolver deviceResolver = new LiteDeviceResolver();
|
|
|
|
|
|
@@ -223,67 +250,228 @@ public class SearcherServiceImpl implements SearcherService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- ModelMap map = new ModelMap();
|
|
|
+
|
|
|
Map<String,Object> results = null;
|
|
|
//Map<String, Object> results = new HashMap<>();
|
|
|
+ com.uas.platform.b2c.common.search.util.PageParams pageParams = new com.uas.platform.b2c.common.search.util.PageParams();
|
|
|
+ pageParams.setPage(page.getPage());
|
|
|
+ pageParams.setSize(page.getCount());
|
|
|
try {
|
|
|
- results = searchService.getGoodsIds(keyword, convertPageParams(page));
|
|
|
+ results = searchService.getGoodsIds(keyword, pageParams);
|
|
|
} catch (SearchException e) {
|
|
|
throwSystemException(e);
|
|
|
}
|
|
|
- //统计精准匹配到品牌的数量(便于展示唯一的品牌)
|
|
|
- ModelMap brandMap = searchBrand(keyword,null);
|
|
|
- List<Map<String, Object>> brands = (List)brandMap.get("brands");
|
|
|
- if (!CollectionUtils.isEmpty(brands)) {
|
|
|
- for (Map<String, Object> brand : brands){
|
|
|
- if (keyword.equalsIgnoreCase(brand.get("nameCn").toString()) || keyword.equalsIgnoreCase(brand.get("nameEn").toString())){
|
|
|
- map.put("brands",brand);
|
|
|
- brandDao.addSearchCount(brand.get("uuid").toString());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if ((int)results.get("total") == 0){
|
|
|
- map.put("total", results.get("total"));// 搜索结果总数
|
|
|
- map.put("page", results.get("page"));// 当前页面
|
|
|
- map.put("size", results.get("size"));// 每页个数
|
|
|
- map.put("components", new ArrayList<>());// 当前页器件内容
|
|
|
- return map;
|
|
|
- }
|
|
|
- List<Integer> componentIds = (List<Integer>)results.get("componentIds");
|
|
|
- List<Integer> goodsIds = (List<Integer>)results.get("goodsIds");
|
|
|
- List<ComponentGoods> components = new ArrayList<>();
|
|
|
- if (!CollectionUtils.isEmpty(componentIds)) {
|
|
|
- for (int i = 0 ;i < componentIds.size() ; i++){
|
|
|
- Long cid = null;
|
|
|
- if(!StringUtils.isEmpty
|
|
|
- (componentIds.get(i))) {
|
|
|
- cid = Long.valueOf(componentIds.get(i).toString());
|
|
|
- }
|
|
|
- Long gid = goodsIds.get(i) == null ? 0L : Long.valueOf(goodsIds.get(i).toString());
|
|
|
- if((cid == null) && (gid != 0L)) {
|
|
|
- Goods goods = goodsDao.findOne(gid);
|
|
|
- if(goods != null) {
|
|
|
- components.add(new ComponentGoods(goods));
|
|
|
- }
|
|
|
- }else if(cid != null){
|
|
|
- ComponentGoods componentGoods = componentGoodsDao.findByCmpIdAndGoId(cid, gid);
|
|
|
- if (componentGoods != null){
|
|
|
- components.add(componentGoods);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- map.put("components", components);// 当前页器件内容
|
|
|
- // 假如第一个结果与器件型号一致,则该型号增加一次 搜索量
|
|
|
- if (components.get(0).getCode().equals(keyword)) {
|
|
|
- componentDao.addSearchCount(components.get(0).getUuid());
|
|
|
+ ModelMap resultMap = new ModelMap();
|
|
|
+ List<Goods> goodsList = new ArrayList<>();
|
|
|
+ Map stockMap = new HashMap();
|
|
|
+ List<Product> productList = new ArrayList<>();
|
|
|
+ Map futuresMap = new HashMap();
|
|
|
+
|
|
|
+ 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 (Long goodsId : stockPage.getContent()) {
|
|
|
+ goodsList.add(goodsDao.findOne(goodsId));
|
|
|
+ }
|
|
|
+
|
|
|
+ for (Object PrId : futuresPage.getContent()) {
|
|
|
+ productList.add(productDao.findOne(Long.valueOf(PrId.toString())));
|
|
|
+ }
|
|
|
+
|
|
|
+ stockMap.put("content", goodsList);
|
|
|
+ stockMap.put("total",stockPage.getTotalElement());
|
|
|
+ stockMap.put("page",stockPage.getPage());
|
|
|
+ stockMap.put("size",stockPage.getSize());
|
|
|
+
|
|
|
+ futuresMap.put("content", productList);
|
|
|
+ futuresMap.put("total",futuresPage.getTotalElement());
|
|
|
+ futuresMap.put("page",futuresPage.getPage());
|
|
|
+ futuresMap.put("size",futuresPage.getSize());
|
|
|
+
|
|
|
+ resultMap.put("stock", stockMap); // 现货
|
|
|
+ resultMap.put("futures",futuresMap); // 期货
|
|
|
+
|
|
|
+ return resultMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ModelMap getEnterpriseBySearchKind(String keyword, PageParams page) {
|
|
|
+ ModelMap resultMap = new ModelMap();
|
|
|
+ Map<String, Object> kindsMap = null;
|
|
|
+ try {
|
|
|
+ kindsMap = searchService.getKindsAndSellers(keyword, page.getPage(), page.getCount());
|
|
|
+ } catch (SearchException e) {
|
|
|
+ throwSystemException(e);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> storeIds = ((SPage<String>) ((JSONObject)kindsMap.get("stock")).toJavaObject(SPage.class)).getContent();
|
|
|
+ List<Object> enUUs = ((SPage<Object>) ((JSONObject)kindsMap.get("futures")).toJavaObject(SPage.class)).getContent();
|
|
|
+
|
|
|
+ List<VendorIntroduction> vendorIntroductionsStocks = new ArrayList<>();
|
|
|
+ List<VendorIntroduction> vendorIntroductionsFutures = new ArrayList<>();
|
|
|
+
|
|
|
+ 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()))));
|
|
|
+ }
|
|
|
+
|
|
|
+ HashMap stock = new HashMap();
|
|
|
+ stock.put("content", vendorIntroductionsStocks);
|
|
|
+ stock.put("page",((SPage<Object>) ((JSONObject)kindsMap.get("stock")).toJavaObject(SPage.class)).getPage());
|
|
|
+ stock.put("size",((SPage<Object>) ((JSONObject)kindsMap.get("stock")).toJavaObject(SPage.class)).getSize());
|
|
|
+ stock.put("total", ((SPage<Object>) ((JSONObject)kindsMap.get("stock")).toJavaObject(SPage.class)).getTotalElement());
|
|
|
+
|
|
|
+ HashMap futures = new HashMap();
|
|
|
+ futures.put("content", vendorIntroductionsFutures);
|
|
|
+ futures.put("page",((SPage<Object>) ((JSONObject)kindsMap.get("futures")).toJavaObject(SPage.class)).getPage());
|
|
|
+ futures.put("size",((SPage<Object>) ((JSONObject)kindsMap.get("futures")).toJavaObject(SPage.class)).getSize());
|
|
|
+ futures.put("total",((SPage<Object>) ((JSONObject)kindsMap.get("futures")).toJavaObject(SPage.class)).getTotalElement());
|
|
|
+
|
|
|
+ resultMap.put("stock", stock); // 现货
|
|
|
+ resultMap.put("futures", futures); // 期货
|
|
|
+
|
|
|
+ return resultMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ModelMap getEnterpriseBySearchStore(String keyword, PageParams page, HttpServletRequest request) {
|
|
|
+ ModelMap resultMap = new ModelMap();
|
|
|
+ Map stock = new HashMap();
|
|
|
+ Map futures = new HashMap();
|
|
|
+ com.uas.sso.support.Page<VendorIntroduction> vendorIntroductionPage = vendorIntroductionService.getVendorIntroduction(page.getPage(),page.getCount(),keyword,null);
|
|
|
+ futures.put("content",vendorIntroductionPage.getContent());
|
|
|
+ futures.put("page",vendorIntroductionPage.getNumber());
|
|
|
+ futures.put("total",vendorIntroductionPage.getTotalElements());
|
|
|
+ futures.put("size",vendorIntroductionPage.getSize());
|
|
|
+
|
|
|
+ User user = (User)request.getSession().getAttribute("user");
|
|
|
+ SystemSession.setUser(user);
|
|
|
+ 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));
|
|
|
+ }
|
|
|
+
|
|
|
+ stock.put("content",vendorIntroductions);
|
|
|
+ stock.put("page",stores.getNumber());
|
|
|
+ stock.put("total",stores.getTotalElements());
|
|
|
+ stock.put("size",stores.getSize());
|
|
|
+
|
|
|
+ resultMap.put("stock", stock); // 现货
|
|
|
+ resultMap.put("futures", futures); // 期货
|
|
|
+
|
|
|
+ return resultMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Page<StoreIn> pageStoresByTypesAndKeyword(final PageInfo pageInfo, String keyword, HttpServletRequest request) {
|
|
|
+ if (!StringUtils.isEmpty(keyword)) {
|
|
|
+ // keyword 只过滤店铺名称,可以使用此方法,否则,搜索多个字段需要生成查询条件
|
|
|
+ pageInfo.filter("storeName", keyword);
|
|
|
+ }
|
|
|
+ // 添加过滤条件为店铺已开店的
|
|
|
+ pageInfo.expression(PredicateUtils.eq("status", StoreStatus.OPENED, false));
|
|
|
+
|
|
|
+ // 设置排序
|
|
|
+ pageInfo.sorting(org.springframework.data.domain.Sort.Direction.DESC, "totalReserve", "createTime");
|
|
|
+
|
|
|
+ Page<StoreIn> storeInPage = storeInDao.findAll(new Specification<StoreIn>() {
|
|
|
+ @Override
|
|
|
+ public Predicate toPredicate(Root<StoreIn> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
|
|
|
+ query.where(pageInfo.getPredicates(root, query, builder));
|
|
|
+ return null;
|
|
|
}
|
|
|
- }
|
|
|
+ }, pageInfo);
|
|
|
|
|
|
- map.put("total", results.get("total"));// 搜索结果总数
|
|
|
- map.put("page", results.get("page"));// 当前页面
|
|
|
- map.put("size", results.get("size"));// 每页个数
|
|
|
+ if (this.deviceResolver.resolveDevice(request).isMobile()) {
|
|
|
+ SystemSession.setUser((User)request.getSession().getAttribute("user"));
|
|
|
+ if (null != SystemSession.getUser() && null!= SystemSession.getUser().getUserUU()){
|
|
|
+ SearchHistory searchHistory = null;
|
|
|
+ List<SearchHistory> searchHistories = searchHistoryDao.findByKeywordAndUserUUAndUserEnuu(keyword,SystemSession.getUser().getUserUU(),SystemSession.getUser().getEnterprise() != null ?SystemSession.getUser().getEnterprise().getUu():null);
|
|
|
+ if (searchHistories.size()>0){
|
|
|
+ searchHistory = searchHistories.get(0);
|
|
|
+ }else {
|
|
|
+ searchHistory = new SearchHistory();
|
|
|
+ }
|
|
|
+ searchHistory.setKeyword(keyword);
|
|
|
+ searchHistory.setSearchTime(new Date(System.currentTimeMillis()));
|
|
|
+ searchHistory.setUserUU(SystemSession.getUser().getUserUU());
|
|
|
+ searchHistory.setUserEnuu(SystemSession.getUser().getEnterprise() != null ?SystemSession.getUser().getEnterprise().getUu():null);
|
|
|
+ searchHistory.setType(Type.SEARCH_STORE.name());
|
|
|
+ searchHistoryDao.save(searchHistory);
|
|
|
+ searchHistories = searchHistoryDao.findByUserUUAndUserEnuuOrderBySearchTimeDesc(SystemSession.getUser().getUserUU(),SystemSession.getUser().getEnterprise() != null ?SystemSession.getUser().getEnterprise().getUu():null);
|
|
|
+ if (searchHistories.size()>10){
|
|
|
+ searchHistoryDao.delete(searchHistories.subList(10,searchHistories.size()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- return map;
|
|
|
+ return storeInPage;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ModelMap getEnterpriseBySearchBrand(String keyword, PageParams page) {
|
|
|
+
|
|
|
+ ModelMap resultMap = new ModelMap();
|
|
|
+ SPage<Map<String, Object>> brandsMap = null;
|
|
|
+ try {
|
|
|
+ brandsMap = searchService.getbrandsAndSellers(keyword, page.getPage(), page.getCount());
|
|
|
+ } catch (SearchException e) {
|
|
|
+ throwSystemException(e);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (brandsMap.getTotalElement() < 1) {
|
|
|
+ resultMap.put("total", 0);
|
|
|
+ return resultMap;
|
|
|
+ } else {
|
|
|
+ if (brandsMap.getContent().get(0).containsKey("futures")) {
|
|
|
+ // 精准匹配
|
|
|
+ brandDao.addSearchCount(Long.valueOf(((List)brandsMap.getContent().get(0).get("brandIds")).get(0).toString()));
|
|
|
+ List<String> storeIds = ((SPage<String>) ((JSONObject)brandsMap.getContent().get(0).get("stock")).toJavaObject(SPage.class)).getContent();
|
|
|
+ List<Object> enUUs = ((SPage<Object>) ((JSONObject)brandsMap.getContent().get(0).get("futures")).toJavaObject(SPage.class)).getContent();
|
|
|
+
|
|
|
+ List<VendorIntroduction> vendorIntroductionsStocks = new ArrayList<>();
|
|
|
+ List<VendorIntroduction> vendorIntroductionsFutures = new ArrayList<>();
|
|
|
+
|
|
|
+ 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()))));
|
|
|
+ }
|
|
|
+
|
|
|
+ HashMap stock = new HashMap();
|
|
|
+ stock.put("content", vendorIntroductionsStocks);
|
|
|
+ stock.put("page",((SPage<Object>) ((JSONObject)brandsMap.getContent().get(0).get("stock")).toJavaObject(SPage.class)).getPage());
|
|
|
+ stock.put("size",((SPage<Object>) ((JSONObject)brandsMap.getContent().get(0).get("stock")).toJavaObject(SPage.class)).getSize());
|
|
|
+ stock.put("total",((SPage<Object>) ((JSONObject)brandsMap.getContent().get(0).get("stock")).toJavaObject(SPage.class)).getTotalElement());
|
|
|
+
|
|
|
+ HashMap futures = new HashMap();
|
|
|
+ futures.put("content", vendorIntroductionsFutures);
|
|
|
+ futures.put("page",((SPage<Object>) ((JSONObject)brandsMap.getContent().get(0).get("futures")).toJavaObject(SPage.class)).getPage());
|
|
|
+ futures.put("size",((SPage<Object>) ((JSONObject)brandsMap.getContent().get(0).get("futures")).toJavaObject(SPage.class)).getSize());
|
|
|
+ futures.put("total",((SPage<Object>) ((JSONObject)brandsMap.getContent().get(0).get("futures")).toJavaObject(SPage.class)).getTotalElement());
|
|
|
+
|
|
|
+ resultMap.put("stock", stock); // 现货
|
|
|
+ resultMap.put("futures", futures); // 期货
|
|
|
+ resultMap.put("brand", brandDao.findOne(Long.valueOf(((List)brandsMap.getContent().get(0).get("brandIds")).get(0).toString())));
|
|
|
+ return resultMap;
|
|
|
+ } else {
|
|
|
+
|
|
|
+ resultMap.put("page",brandsMap.getPage());
|
|
|
+ resultMap.put("size",brandsMap.getSize());
|
|
|
+ resultMap.put("total",brandsMap.getTotalElement());
|
|
|
+ List<Brand> brandList = new ArrayList<>();
|
|
|
+ for (Object brId : (JSONArray)brandsMap.getContent().get(0).get("brandIds")) {
|
|
|
+ brandList.add(brandDao.findOne(Long.valueOf(brId.toString())));
|
|
|
+ }
|
|
|
+ resultMap.put("content", brandList);
|
|
|
+ return resultMap;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -406,10 +594,13 @@ public class SearcherServiceImpl implements SearcherService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Map<String, Object> getSimilarKeywords(String keyword) {
|
|
|
+ public Map<String, Object> getSimilarKeywords(String keyword, String type) {
|
|
|
Map<String, Object> result = null;
|
|
|
+ if (StringUtils.isEmpty(type)) {
|
|
|
+ type = "all";
|
|
|
+ }
|
|
|
try {
|
|
|
- result = searchService.getSimilarKeywords(keyword);
|
|
|
+ result = searchService.getSimilarKeywords(keyword, type);
|
|
|
} catch (SearchException e) {
|
|
|
throwSystemException(e);
|
|
|
}
|
|
|
@@ -595,4 +786,5 @@ public class SearcherServiceImpl implements SearcherService {
|
|
|
map.put("size", results.get("size"));// 每页个数
|
|
|
return map;
|
|
|
}
|
|
|
+
|
|
|
}
|