|
|
@@ -48,384 +48,391 @@ import java.util.Map.Entry;
|
|
|
@Service
|
|
|
public class SearcherServiceImpl implements SearcherService {
|
|
|
|
|
|
- @Autowired
|
|
|
- private ComponentInfoDao componentInfoDao;
|
|
|
+ @Autowired
|
|
|
+ private ComponentInfoDao componentInfoDao;
|
|
|
|
|
|
- @Autowired
|
|
|
- private ComponentGoodsDao componentGoodsDao;
|
|
|
+ @Autowired
|
|
|
+ private ComponentGoodsDao componentGoodsDao;
|
|
|
|
|
|
- @Autowired
|
|
|
- private SearchService searchService;
|
|
|
+ @Autowired
|
|
|
+ private SearchService searchService;
|
|
|
|
|
|
- @Autowired
|
|
|
- private BrandDao brandDao;
|
|
|
+ @Autowired
|
|
|
+ private BrandDao brandDao;
|
|
|
|
|
|
- @Autowired
|
|
|
- private GoodsDao goodsDao;
|
|
|
+ @Autowired
|
|
|
+ private GoodsDao goodsDao;
|
|
|
|
|
|
- @Autowired
|
|
|
- private SearchHistoryDao searchHistoryDao;
|
|
|
+ @Autowired
|
|
|
+ private SearchHistoryDao searchHistoryDao;
|
|
|
|
|
|
- private Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
- private final DeviceResolver deviceResolver = new LiteDeviceResolver();
|
|
|
+ private Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
|
|
|
- /**
|
|
|
- * 智能搜索类目
|
|
|
- *
|
|
|
- * @param keyword
|
|
|
- * @param field
|
|
|
- * @return
|
|
|
- * @throws IOException
|
|
|
- * @throws InterruptedException
|
|
|
- */
|
|
|
- @Override
|
|
|
- public ModelMap searchKind(String keyword, String field) {
|
|
|
- ModelMap map = new ModelMap();
|
|
|
- SPage<Map<String, Object>> kinds = null;
|
|
|
- try {
|
|
|
- kinds = searchService.getKinds(keyword,1,1024*1024*1024);
|
|
|
- } catch (SearchException e) {
|
|
|
- throwSystemException(e);
|
|
|
- }
|
|
|
- map.put("total", kinds.getTotalElement());// 结果总数
|
|
|
- map.put("kinds", kinds.getContent());
|
|
|
- return map;
|
|
|
- }
|
|
|
+ private final DeviceResolver deviceResolver = new LiteDeviceResolver();
|
|
|
|
|
|
- /**
|
|
|
- * 智能搜索品牌
|
|
|
- *
|
|
|
- * @param keyword
|
|
|
- * @param field
|
|
|
- * @return
|
|
|
- * @throws IOException
|
|
|
- * @throws InterruptedException
|
|
|
- */
|
|
|
- @Override
|
|
|
- public ModelMap searchBrand(String keyword, String field) {
|
|
|
- ModelMap map = new ModelMap();
|
|
|
- SPage<Map<String, List<Integer>>> brands = null;
|
|
|
- try {
|
|
|
- brands = searchService.getBrands(keyword,1,1024*1024*1024);
|
|
|
- } catch (SearchException e) {
|
|
|
- throwSystemException(e);
|
|
|
- }
|
|
|
- map.put("brands", brands.getContent());// 结果集
|
|
|
- map.put("total", brands.getTotalElement());// 结果总数
|
|
|
- return map;
|
|
|
- }
|
|
|
+ private final int DEFAULT_PAGE = 1;
|
|
|
|
|
|
- /**
|
|
|
- * 智能搜索器件
|
|
|
- *
|
|
|
- * @param keyword
|
|
|
- * @return
|
|
|
- * @throws InterruptedException
|
|
|
- * @throws IOException
|
|
|
- */
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
- @Override
|
|
|
- public ModelMap searchComponent(String keyword, PageParams page) {
|
|
|
- ModelMap map = new ModelMap();
|
|
|
- Map<String, Object> results = new HashMap<>();
|
|
|
- try {
|
|
|
- results = searchService.getComponentIds(keyword, convertPageParams(page));
|
|
|
- } catch (SearchException e) {
|
|
|
- throwSystemException(e);
|
|
|
- }
|
|
|
- List<Long> componentIds = (List<Long>) results.get("componentIds");
|
|
|
- if (!CollectionUtils.isEmpty(componentIds)) {
|
|
|
- List<ComponentInfo> components = componentInfoDao
|
|
|
- .findByIdsInOrder(componentIds.toArray(new Long[componentIds.size()]));
|
|
|
- map.put("components", components);// 当前页器件内容
|
|
|
- }
|
|
|
- map.put("total", results.get("total"));// 搜索结果总数
|
|
|
- map.put("page", results.get("page"));// 当前页面
|
|
|
- map.put("size", results.get("size"));// 每页个数
|
|
|
- return map;
|
|
|
- }
|
|
|
- /**
|
|
|
- * 智能搜索批次
|
|
|
- *
|
|
|
- * @param keyword
|
|
|
- * @param page
|
|
|
- * @return
|
|
|
- * @throws InterruptedException
|
|
|
- * @throws IOException
|
|
|
- */
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
- @Override
|
|
|
- public ModelMap searchComponentGoods(String keyword, PageParams page , HttpServletRequest request) {
|
|
|
- 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);
|
|
|
- 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()));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- ModelMap map = new ModelMap();
|
|
|
- Map<String,Object> results = null;
|
|
|
- //Map<String, Object> results = new HashMap<>();
|
|
|
- try {
|
|
|
- results = searchService.getGoodsIds(keyword, convertPageParams(page));
|
|
|
- } 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);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- 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);// 当前页器件内容
|
|
|
- }
|
|
|
+ private final int DEFAULT_SIZE = 1024 * 1024 * 1024;
|
|
|
|
|
|
- map.put("total", results.get("total"));// 搜索结果总数
|
|
|
- map.put("page", results.get("page"));// 当前页面
|
|
|
- map.put("size", results.get("size"));// 每页个数
|
|
|
+ /**
|
|
|
+ * 智能搜索类目
|
|
|
+ *
|
|
|
+ * @param keyword
|
|
|
+ * @param field
|
|
|
+ * @return
|
|
|
+ * @throws IOException
|
|
|
+ * @throws InterruptedException
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ModelMap searchKind(String keyword, String field) {
|
|
|
+ ModelMap map = new ModelMap();
|
|
|
+ SPage<Map<String, Object>> kinds = null;
|
|
|
+ try {
|
|
|
+ kinds = searchService.getKinds(keyword, DEFAULT_PAGE, DEFAULT_SIZE);
|
|
|
+ } catch (SearchException e) {
|
|
|
+ throwSystemException(e);
|
|
|
+ }
|
|
|
+ map.put("total", kinds.getTotalElement());// 结果总数
|
|
|
+ map.put("kinds", kinds.getContent());
|
|
|
+ return map;
|
|
|
+ }
|
|
|
|
|
|
- return map;
|
|
|
- }
|
|
|
- /**
|
|
|
- * 批次搜索数量统计
|
|
|
- *
|
|
|
- * @param keyword
|
|
|
- * @param page
|
|
|
- * @return
|
|
|
- * @throws InterruptedException
|
|
|
- * @throws IOException
|
|
|
- */
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
- @Override
|
|
|
- public ModelMap searchComponentGoodsNums(String keyword, PageParams page) {
|
|
|
- ModelMap map = new ModelMap();
|
|
|
- Map<String, Object> results = null;
|
|
|
- //Map<String, Object> results = new HashMap<>();
|
|
|
- try {
|
|
|
- results = searchService.getGoodsIds(keyword, convertPageParams(page));
|
|
|
- } catch (SearchException e) {
|
|
|
- throwSystemException(e);
|
|
|
- }
|
|
|
- map.put("total", results.get("total"));// 搜索结果总数
|
|
|
- return map;
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * 智能搜索品牌
|
|
|
+ *
|
|
|
+ * @param keyword
|
|
|
+ * @param field
|
|
|
+ * @return
|
|
|
+ * @throws IOException
|
|
|
+ * @throws InterruptedException
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ModelMap searchBrand(String keyword, String field) {
|
|
|
+ ModelMap map = new ModelMap();
|
|
|
+ SPage<Map<String, List<Integer>>> brands = null;
|
|
|
+ try {
|
|
|
+ brands = searchService.getBrands(keyword, DEFAULT_PAGE, DEFAULT_SIZE);
|
|
|
+ } catch (SearchException e) {
|
|
|
+ throwSystemException(e);
|
|
|
+ }
|
|
|
+ map.put("brands", brands.getContent());// 结果集
|
|
|
+ map.put("total", brands.getTotalElement());// 结果总数
|
|
|
+ return map;
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * 智能搜索器件
|
|
|
+ *
|
|
|
+ * @param keyword
|
|
|
+ * @return
|
|
|
+ * @throws InterruptedException
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ @Override
|
|
|
+ public ModelMap searchComponent(String keyword, PageParams page) {
|
|
|
+ ModelMap map = new ModelMap();
|
|
|
+ Map<String, Object> results = new HashMap<>();
|
|
|
+ try {
|
|
|
+ results = searchService.getComponentIds(keyword, convertPageParams(page));
|
|
|
+ } catch (SearchException e) {
|
|
|
+ throwSystemException(e);
|
|
|
+ }
|
|
|
+ List<Long> componentIds = (List<Long>) results.get("componentIds");
|
|
|
+ if (!CollectionUtils.isEmpty(componentIds)) {
|
|
|
+ List<ComponentInfo> components = componentInfoDao
|
|
|
+ .findByIdsInOrder(componentIds.toArray(new Long[componentIds.size()]));
|
|
|
+ map.put("components", components);// 当前页器件内容
|
|
|
+ }
|
|
|
+ map.put("total", results.get("total"));// 搜索结果总数
|
|
|
+ map.put("page", results.get("page"));// 当前页面
|
|
|
+ map.put("size", results.get("size"));// 每页个数
|
|
|
+ return map;
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * 智能搜索批次
|
|
|
+ *
|
|
|
+ * @param keyword
|
|
|
+ * @param page
|
|
|
+ * @return
|
|
|
+ * @throws InterruptedException
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ @Override
|
|
|
+ public ModelMap searchComponentGoods(String keyword, PageParams page, HttpServletRequest request) {
|
|
|
+ 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);
|
|
|
+ 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()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ModelMap map = new ModelMap();
|
|
|
+ Map<String, Object> results = null;
|
|
|
+ //Map<String, Object> results = new HashMap<>();
|
|
|
+ try {
|
|
|
+ results = searchService.getGoodsIds(keyword, convertPageParams(page));
|
|
|
+ } 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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);// 当前页器件内容
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
- * 获取器件搜索的类目统计
|
|
|
- *
|
|
|
- * @param keyword
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- public List<Map<String, Object>> getKindsBySearchComponent(String keyword, String brandId) {
|
|
|
- List<Map<String, Object>> kinds = new ArrayList<>();
|
|
|
- try {
|
|
|
- kinds = searchService.getKindsBySearchComponent(keyword, brandId);
|
|
|
- } catch (SearchException e) {
|
|
|
- throwSystemException(e);
|
|
|
- }
|
|
|
- return kinds;
|
|
|
- }
|
|
|
+ map.put("total", results.get("total"));// 搜索结果总数
|
|
|
+ map.put("page", results.get("page"));// 当前页面
|
|
|
+ map.put("size", results.get("size"));// 每页个数
|
|
|
|
|
|
- /**
|
|
|
- * 获取器件搜索的品牌统计列表
|
|
|
- *
|
|
|
- * @param keyword
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- public List<Map<String, Object>> getBrandsBySearchComponent(String keyword, String kindId) {
|
|
|
- List<Map<String, Object>> brands = new ArrayList<>();
|
|
|
- try {
|
|
|
- brands = searchService.getBrandsBySearchComponent(keyword, kindId);
|
|
|
- } catch (SearchException e) {
|
|
|
- throwSystemException(e);
|
|
|
- }
|
|
|
- return brands;
|
|
|
- }
|
|
|
- /**
|
|
|
- * 批次搜索结构的类目,器件,店铺类型,货币类型统计
|
|
|
- *
|
|
|
- * @param keyword
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- public List<Map<String, Object>> getCollectlistBySearchComponentGoods(String keyword, String collectList, String paramJSON , HttpServletRequest request) {
|
|
|
- List<Map<String, Object>> collectResult = new ArrayList<>();
|
|
|
- JSONObject jsonObject = FastjsonUtils.parseObject(paramJSON);
|
|
|
- Set<Entry<String,Object>> paramEntry = jsonObject.entrySet();
|
|
|
- Map<com.uas.platform.b2c.common.search.util.PageParams.FilterField,Object> param= new LinkedHashMap<>();
|
|
|
- for (Entry<String, Object> entry : paramEntry) {
|
|
|
- param.put(FilterField.valueOf(entry.getKey().toUpperCase()), entry.getValue());
|
|
|
- }
|
|
|
- try {
|
|
|
- collectResult = searchService.collectBySearchGoods(keyword, CollectField.valueOf(collectList.toUpperCase()),param);
|
|
|
- } catch (SearchException e) {
|
|
|
- throwSystemException(e);
|
|
|
- }
|
|
|
- if ("goods_brand".equals(collectList)) {
|
|
|
- if (this.deviceResolver.resolveDevice(request).isMobile()) {
|
|
|
- for (Map<String, Object> m : collectResult) {
|
|
|
- m.put("logoUrl", brandDao.findOne(Long.parseLong(m.get("br_id").toString())).getLogoUrl());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return collectResult;
|
|
|
- }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
|
|
|
- @Override
|
|
|
- public Map<String,Object> getSimilarKeywords(String keyword) {
|
|
|
- Map<String,Object> result = null;
|
|
|
- try {
|
|
|
- result = searchService.getSimilarKeywords(keyword);
|
|
|
- } 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 keyword
|
|
|
+ * @param page
|
|
|
+ * @return
|
|
|
+ * @throws InterruptedException
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ @Override
|
|
|
+ public ModelMap searchComponentGoodsNums(String keyword, PageParams page) {
|
|
|
+ ModelMap map = new ModelMap();
|
|
|
+ Map<String, Object> results = null;
|
|
|
+ //Map<String, Object> results = new HashMap<>();
|
|
|
+ try {
|
|
|
+ results = searchService.getGoodsIds(keyword, convertPageParams(page));
|
|
|
+ } catch (SearchException e) {
|
|
|
+ throwSystemException(e);
|
|
|
+ }
|
|
|
+ map.put("total", results.get("total"));// 搜索结果总数
|
|
|
+ return map;
|
|
|
+ }
|
|
|
|
|
|
- @Override
|
|
|
- public List<Map<String, Object>> getSimilarComponents(String componentCode) {
|
|
|
- List<Map<String, Object>> components = new ArrayList<>();
|
|
|
- try {
|
|
|
- components = searchService.getSimilarComponents(componentCode);
|
|
|
- } catch (SearchException e) {
|
|
|
- throwSystemException(e);
|
|
|
- }
|
|
|
- return components;
|
|
|
- }
|
|
|
|
|
|
- /**
|
|
|
- * 把平台中PageParams对象转化为搜索API封装的PageParams对象
|
|
|
- *
|
|
|
- * @param params
|
|
|
- * @return
|
|
|
- */
|
|
|
- private com.uas.platform.b2c.common.search.util.PageParams convertPageParams(PageParams params) {
|
|
|
- PageInfo pageinfo = null;
|
|
|
- if (null == params.getSorting() || "".equals(params.getSorting()) || "{}".equals(params.getSorting()) || JSON.parseObject(params.getSorting()).size() == 0){
|
|
|
- pageinfo = new PageInfo();
|
|
|
- } else {
|
|
|
- pageinfo = new PageInfo(params);
|
|
|
- }
|
|
|
- com.uas.platform.b2c.common.search.util.PageParams pageParams = new com.uas.platform.b2c.common.search.util.PageParams();
|
|
|
- pageParams.setPage(params.getPage());
|
|
|
- pageParams.setSize(params.getCount());
|
|
|
- if (!StringUtils.isEmpty(params.getFilter())) {
|
|
|
- JSONObject jsonObject = FastjsonUtils.parseObject(params.getFilter());
|
|
|
- Set<Entry<String, Object>> entrySet = jsonObject.entrySet();
|
|
|
- for (Entry<String, Object> entry : entrySet) {
|
|
|
- pageParams.filter(FilterField.valueOf(entry.getKey().toUpperCase()), entry.getValue());
|
|
|
- }
|
|
|
- }
|
|
|
- if (!StringUtils.isEmpty(pageinfo.getSort())){
|
|
|
- //com.alibaba.fastjson.JSONObject sort = FastjsonUtils.parseObject(params.getSorting());
|
|
|
- Iterator<org.springframework.data.domain.Sort.Order> iterator = pageinfo.getSort().iterator();
|
|
|
- com.uas.platform.b2c.common.search.util.Sort sort = new com.uas.platform.b2c.common.search.util.Sort();
|
|
|
- Sort newSort = null;
|
|
|
- while (iterator.hasNext()){
|
|
|
- org.springframework.data.domain.Sort.Order order = iterator.next();
|
|
|
- boolean reverse= false;
|
|
|
- if ( "DESC".equals( order.getDirection().toString())){
|
|
|
- reverse = true;
|
|
|
- }
|
|
|
- newSort= new Sort( Sort.Field.valueOf(order.getProperty()),reverse);
|
|
|
- }
|
|
|
- pageParams.setSort(newSort);
|
|
|
- }
|
|
|
- return pageParams;
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * 获取器件搜索的类目统计
|
|
|
+ *
|
|
|
+ * @param keyword
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<Map<String, Object>> getKindsBySearchComponent(String keyword, String brandId) {
|
|
|
+ List<Map<String, Object>> kinds = new ArrayList<>();
|
|
|
+ try {
|
|
|
+ kinds = searchService.getKindsBySearchComponent(keyword, brandId);
|
|
|
+ } catch (SearchException e) {
|
|
|
+ throwSystemException(e);
|
|
|
+ }
|
|
|
+ return kinds;
|
|
|
+ }
|
|
|
|
|
|
- @Override
|
|
|
- public List<Map<String, Object>> getSimilarKinds(String kindName) {
|
|
|
- List<Map<String, Object>> kinds = new ArrayList<>();
|
|
|
- try {
|
|
|
- kinds = searchService.getSimilarKinds(kindName);
|
|
|
- } catch (SearchException e) {
|
|
|
- throwSystemException(e);
|
|
|
- }
|
|
|
- return kinds;
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * 获取器件搜索的品牌统计列表
|
|
|
+ *
|
|
|
+ * @param keyword
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<Map<String, Object>> getBrandsBySearchComponent(String keyword, String kindId) {
|
|
|
+ List<Map<String, Object>> brands = new ArrayList<>();
|
|
|
+ try {
|
|
|
+ brands = searchService.getBrandsBySearchComponent(keyword, kindId);
|
|
|
+ } catch (SearchException e) {
|
|
|
+ throwSystemException(e);
|
|
|
+ }
|
|
|
+ return brands;
|
|
|
+ }
|
|
|
|
|
|
- @Override
|
|
|
- public List<Map<String, Object>> getSimilarLeafKinds(String kindName) {
|
|
|
- return searchService.getSimilarLeafKinds(kindName);
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * 批次搜索结构的类目,器件,店铺类型,货币类型统计
|
|
|
+ *
|
|
|
+ * @param keyword
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<Map<String, Object>> getCollectlistBySearchComponentGoods(String keyword, String collectList, String paramJSON, HttpServletRequest request) {
|
|
|
+ List<Map<String, Object>> collectResult = new ArrayList<>();
|
|
|
+ JSONObject jsonObject = FastjsonUtils.parseObject(paramJSON);
|
|
|
+ Set<Entry<String, Object>> paramEntry = jsonObject.entrySet();
|
|
|
+ Map<com.uas.platform.b2c.common.search.util.PageParams.FilterField, Object> param = new LinkedHashMap<>();
|
|
|
+ for (Entry<String, Object> entry : paramEntry) {
|
|
|
+ param.put(FilterField.valueOf(entry.getKey().toUpperCase()), entry.getValue());
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ collectResult = searchService.collectBySearchGoods(keyword, CollectField.valueOf(collectList.toUpperCase()), param);
|
|
|
+ } catch (SearchException e) {
|
|
|
+ throwSystemException(e);
|
|
|
+ }
|
|
|
+ if ("goods_brand".equals(collectList)) {
|
|
|
+ if (this.deviceResolver.resolveDevice(request).isMobile()) {
|
|
|
+ for (Map<String, Object> m : collectResult) {
|
|
|
+ m.put("logoUrl", brandDao.findOne(Long.parseLong(m.get("br_id").toString())).getLogoUrl());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return collectResult;
|
|
|
+ }
|
|
|
|
|
|
- @Override
|
|
|
- public List<Map<String, Object>> getSimilarBrands(String brandName) {
|
|
|
- List<Map<String, Object>> brands = new ArrayList<Map<String, Object>>();
|
|
|
- try {
|
|
|
- brands = searchService.getSimilarBrands(brandName);
|
|
|
- } catch (SearchException e) {
|
|
|
- throwSystemException(e);
|
|
|
- }
|
|
|
- return brands;
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> getSimilarKeywords(String keyword) {
|
|
|
+ Map<String, Object> result = null;
|
|
|
+ try {
|
|
|
+ result = searchService.getSimilarKeywords(keyword);
|
|
|
+ } 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;
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
- * 捕获SearchException抛出SystemException
|
|
|
- *
|
|
|
- * @param e
|
|
|
- * @return
|
|
|
- */
|
|
|
- private void throwSystemException(SearchException e) {
|
|
|
- logger.error(e.getMessage(), e);
|
|
|
- throw new SystemException(e.getMessage());
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ public List<Map<String, Object>> getSimilarComponents(String componentCode) {
|
|
|
+ List<Map<String, Object>> components = new ArrayList<>();
|
|
|
+ try {
|
|
|
+ components = searchService.getSimilarComponents(componentCode);
|
|
|
+ } catch (SearchException e) {
|
|
|
+ throwSystemException(e);
|
|
|
+ }
|
|
|
+ return components;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 把平台中PageParams对象转化为搜索API封装的PageParams对象
|
|
|
+ *
|
|
|
+ * @param params
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private com.uas.platform.b2c.common.search.util.PageParams convertPageParams(PageParams params) {
|
|
|
+ PageInfo pageinfo = null;
|
|
|
+ if (null == params.getSorting() || "".equals(params.getSorting()) || "{}".equals(params.getSorting()) || JSON.parseObject(params.getSorting()).size() == 0) {
|
|
|
+ pageinfo = new PageInfo();
|
|
|
+ } else {
|
|
|
+ pageinfo = new PageInfo(params);
|
|
|
+ }
|
|
|
+ com.uas.platform.b2c.common.search.util.PageParams pageParams = new com.uas.platform.b2c.common.search.util.PageParams();
|
|
|
+ pageParams.setPage(params.getPage());
|
|
|
+ pageParams.setSize(params.getCount());
|
|
|
+ if (!StringUtils.isEmpty(params.getFilter())) {
|
|
|
+ JSONObject jsonObject = FastjsonUtils.parseObject(params.getFilter());
|
|
|
+ Set<Entry<String, Object>> entrySet = jsonObject.entrySet();
|
|
|
+ for (Entry<String, Object> entry : entrySet) {
|
|
|
+ pageParams.filter(FilterField.valueOf(entry.getKey().toUpperCase()), entry.getValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(pageinfo.getSort())) {
|
|
|
+ //com.alibaba.fastjson.JSONObject sort = FastjsonUtils.parseObject(params.getSorting());
|
|
|
+ Iterator<org.springframework.data.domain.Sort.Order> iterator = pageinfo.getSort().iterator();
|
|
|
+ com.uas.platform.b2c.common.search.util.Sort sort = new com.uas.platform.b2c.common.search.util.Sort();
|
|
|
+ Sort newSort = null;
|
|
|
+ while (iterator.hasNext()) {
|
|
|
+ org.springframework.data.domain.Sort.Order order = iterator.next();
|
|
|
+ boolean reverse = false;
|
|
|
+ if ("DESC".equals(order.getDirection().toString())) {
|
|
|
+ reverse = true;
|
|
|
+ }
|
|
|
+ newSort = new Sort(Sort.Field.valueOf(order.getProperty()), reverse);
|
|
|
+ }
|
|
|
+ pageParams.setSort(newSort);
|
|
|
+ }
|
|
|
+ return pageParams;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Map<String, Object>> getSimilarKinds(String kindName) {
|
|
|
+ List<Map<String, Object>> kinds = new ArrayList<>();
|
|
|
+ try {
|
|
|
+ kinds = searchService.getSimilarKinds(kindName);
|
|
|
+ } catch (SearchException e) {
|
|
|
+ throwSystemException(e);
|
|
|
+ }
|
|
|
+ return kinds;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Map<String, Object>> getSimilarLeafKinds(String kindName) {
|
|
|
+ return searchService.getSimilarLeafKinds(kindName);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Map<String, Object>> getSimilarBrands(String brandName) {
|
|
|
+ List<Map<String, Object>> brands = new ArrayList<Map<String, Object>>();
|
|
|
+ try {
|
|
|
+ brands = searchService.getSimilarBrands(brandName);
|
|
|
+ } catch (SearchException e) {
|
|
|
+ throwSystemException(e);
|
|
|
+ }
|
|
|
+ return brands;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 捕获SearchException抛出SystemException
|
|
|
+ *
|
|
|
+ * @param e
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private void throwSystemException(SearchException e) {
|
|
|
+ logger.error(e.getMessage(), e);
|
|
|
+ throw new SystemException(e.getMessage());
|
|
|
+ }
|
|
|
}
|