Browse Source

Merge branch 'dev-mysql' into feature_release-tomysql

yangc 8 years ago
parent
commit
243fb2ae6d

+ 111 - 0
src/main/java/com/uas/platform/b2c/common/search/constant/SearchParam.java

@@ -0,0 +1,111 @@
+package com.uas.platform.b2c.common.search.constant;
+
+//
+// Source code recreated from a .class file by IntelliJ IDEA
+// (powered by Fernflower decompiler)
+//
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import com.uas.search.model.Sort;
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class SearchParam implements Serializable {
+    private static final long serialVersionUID = 1L;
+    private int page;
+    private int size;
+    private Map<FilterField, Object> filters;
+    private List<Sort> sort;
+
+    public SearchParam() {
+    }
+
+    public SearchParam(int page, int size) {
+        this.page = page;
+        this.size = size;
+    }
+
+    public int getPage() {
+        return this.page;
+    }
+
+    public void setPage(int page) {
+        this.page = page;
+    }
+
+    public int getSize() {
+        return this.size;
+    }
+
+    public void setSize(int size) {
+        this.size = size;
+    }
+
+    public Map<SearchParam.FilterField, Object> getFilters() {
+        return this.filters;
+    }
+
+    public void setFilters(Map<SearchParam.FilterField, Object> filters) {
+        this.filters = filters;
+    }
+
+    public void filter(SearchParam.FilterField key, Object value) {
+        if(this.filters == null) {
+            this.filters = new HashMap();
+        }
+
+        this.filters.put(key, value);
+    }
+
+    public void removeFilter(SearchParam.FilterField key) {
+        if(this.filters != null) {
+            this.filters.remove(key);
+        }
+
+    }
+
+    public List<Sort> getSort() {
+        return this.sort;
+    }
+
+    public void setSort(List<Sort> sort) {
+        this.sort = sort;
+    }
+
+    public String toString() {
+        return "PageParams [page=" + this.page + ", size=" + this.size + ", filters=" + this.filters + ", sort=" + this.sort + "]";
+    }
+
+    public static enum FilterField {
+        COMPONENT_KINDID,
+        COMPONENT_BRANDID,
+        COMPONENT_PROPERTIES,
+        COMPONENT_HAS_RESERVE,
+        COMPONENT_HAS_SAMPLE,
+        COMPONENT_HAS_ORIGINAL,
+        COMPONENT_HAS_INACTION_STOCK,
+        GOODS_KINDID,
+        GOODS_BRANDID,
+        GOODS_STORE_TYPE,
+        GOODS_CRNAME,
+        GOODS_MINPRICERMB,
+        GOODS_MAXPRICERMB,
+        GOODS_MINPRICEUSD,
+        GOODS_MAXPRICEUSD,
+        GOODS_STATUS,
+        ORDER_STATUS,
+        ORDER_BUYER_UU,
+        ORDER_BUYER_EN_UU,
+        ORDER_SELLER_EN_UU,
+        ORDER_MIN_TIME,
+        ORDER_MAX_TIME;
+
+        private FilterField() {
+        }
+    }
+}

+ 22 - 0
src/main/java/com/uas/platform/b2c/common/search/controller/SearcherController.java

@@ -7,6 +7,7 @@ import com.uas.platform.b2c.common.search.service.SearcherService;
 import com.uas.platform.b2c.core.support.SystemSession;
 import com.uas.platform.b2c.prod.commodity.service.GoodsService;
 import com.uas.platform.b2c.prod.commodity.service.StockInOutHistService;
+import com.uas.platform.b2c.prod.product.component.modal.ComponentInfo;
 import com.uas.platform.b2c.prod.store.model.StoreIn;
 import com.uas.platform.b2c.prod.store.service.StoreInService;
 import com.uas.platform.b2c.trade.presale.service.StoreFocusService;
@@ -211,6 +212,20 @@ public class SearcherController {
 		map = searcherService.searchComponent(w, page);
 		return map;
 	}
+	/**
+	 * 分页按首字母搜索器件
+	 *
+	 * @param w 关键词
+	 * @param page 分页参数
+	 * @return
+	 * @throws InterruptedException
+	 * @throws IOException
+	 */
+	@RequestMapping(value = "/component/first", method = RequestMethod.GET)
+	@ResponseBody
+	public Page<ComponentInfo> searchComponentByFirst(String w, PageParams page) {
+		return searcherService.searchComponentByFirst(w, page);
+	}
 
 	/**
 	 * 器件搜索结果的类目统计
@@ -358,4 +373,11 @@ public class SearcherController {
 			return searchHistoryDao.findByUserUUAndUserEnuuOrderBySearchTimeDesc(SystemSession.getUser().getUserUU(),SystemSession.getUser().getEnterprise() != null ?SystemSession.getUser().getEnterprise().getUu():null);
 		}
 	}
+
+	@RequestMapping(value = "/searchHistory", method = RequestMethod.DELETE)
+	@ResponseBody
+	public int deleteSearchHistory(HttpServletRequest request){
+		SystemSession.setUser((User)request.getSession().getAttribute("user"));
+		return searcherService.deleteSearchHistoryByuserUUAndenUU();
+	}
 }

+ 14 - 0
src/main/java/com/uas/platform/b2c/common/search/dao/SearchHistoryDao.java

@@ -3,7 +3,11 @@ package com.uas.platform.b2c.common.search.dao;
 import com.uas.platform.b2c.common.search.model.SearchHistory;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.jpa.repository.Modifying;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
 import org.springframework.stereotype.Repository;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.util.List;
 
@@ -16,4 +20,14 @@ public interface SearchHistoryDao extends JpaSpecificationExecutor<SearchHistory
     List<SearchHistory> findByUserUUAndUserEnuuOrderBySearchTimeDesc(Long userUU,Long userEnuu);
 
     List<SearchHistory> findByKeywordAndUserUUAndUserEnuu(String keyword,Long userUU,Long userEnuu);
+
+    /**
+     * 根据用户企业删除搜索记录
+     * @param userUU
+     * @param userEnuu
+     */
+    @Transactional
+    @Modifying
+    @Query(value = "delete from SearchHistory s where s.userUU =:userUU and s.userEnuu = :enUU")
+    int deleteByUserUUAndUserEnuu(@Param("userUU") Long userUU, @Param("enUU") Long userEnuu);
 }

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

@@ -1,6 +1,7 @@
 package com.uas.platform.b2c.common.search.rpc.service.Impl;
 
 
+import com.alibaba.fastjson.JSONArray;
 import com.uas.platform.b2c.common.search.constant.SearchUrl;
 import com.uas.platform.b2c.common.search.rpc.service.SearchService;
 import com.uas.platform.b2c.core.config.SysConf;
@@ -91,14 +92,14 @@ public class SearchServiceImpl implements SearchService{
     }
 
     @Override
-    public SPage<Map<String, List<Integer>>> getBrands(String keyword, Integer page, Integer size) throws SearchException {
+    public SPage<Map<String, Object>> getBrands(String keyword, Integer page, Integer size) throws SearchException {
         Map<String, Object> map = initSearchMap(keyword, page, size);
         String str = restTemplate.getForObject(sysConf.getSearchUrl() + SearchUrl.BRAND_INFO_URL, String.class, map);
         if(StringUtils.isEmpty(str)) {
             return null;
         }else {
             try {
-                SPage<Map<String, List<Integer>>> sPage = FastjsonUtils.fromJson(str, SPage.class);
+                SPage<Map<String, Object>> sPage = FastjsonUtils.fromJson(str, SPage.class);
                 return sPage;
             }catch (Exception e) {
                 e.printStackTrace();

+ 1 - 1
src/main/java/com/uas/platform/b2c/common/search/rpc/service/SearchService.java

@@ -21,7 +21,7 @@ public interface SearchService {
 
     SPage<Long> getBrandIds(String keyword, Integer page, Integer size) throws SearchException;
 
-    SPage<Map<String, List<Integer>>> getBrands(String keyword, Integer page, Integer size) throws SearchException;
+    SPage<Map<String, Object>> getBrands(String keyword, Integer page, Integer size) throws SearchException;
 
     Map<String, Object> getComponentIds(String keyword, PageParams var2) throws SearchException;
 

+ 14 - 0
src/main/java/com/uas/platform/b2c/common/search/service/SearcherService.java

@@ -1,7 +1,9 @@
 package com.uas.platform.b2c.common.search.service;
 
+import com.uas.platform.b2c.prod.product.component.modal.ComponentInfo;
 import com.uas.platform.core.model.PageParams;
 import com.uas.search.exception.SearchException;
+import org.springframework.data.domain.Page;
 import org.springframework.ui.ModelMap;
 
 import javax.servlet.http.HttpServletRequest;
@@ -49,6 +51,17 @@ public interface SearcherService {
 	 * @throws IOException
 	 */
 	public ModelMap searchComponent(String keyword, PageParams page);
+
+	/**
+	 * 首字母搜索器件
+	 *
+	 * @param keyword 关键词
+	 * @param page 分页参数
+	 * @return total, 搜索结果总数; page, 页码; size, 每页个数; components, 搜索结果集
+	 * @throws InterruptedException
+	 * @throws IOException
+	 */
+	public Page<ComponentInfo> searchComponentByFirst(String keyword, PageParams page);
 	/**
 	 * 智能搜索批次
 	 *
@@ -139,4 +152,5 @@ public interface SearcherService {
 	 */
 	public List<Map<String, Object>> getSimilarBrands(String brandName);
 
+	public int deleteSearchHistoryByuserUUAndenUU();
 }

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

@@ -2,6 +2,7 @@ package com.uas.platform.b2c.common.search.service.impl;
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
+import com.uas.platform.b2c.common.search.constant.SearchParam;
 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;
@@ -27,6 +28,8 @@ import com.uas.platform.b2c.common.search.util.Sort;
 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.mobile.device.DeviceResolver;
 import org.springframework.mobile.device.LiteDeviceResolver;
 import org.springframework.stereotype.Service;
@@ -48,27 +51,26 @@ 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());
+	private final DeviceResolver deviceResolver = new LiteDeviceResolver();
 
     private final int DEFAULT_PAGE = 1;
 
@@ -109,7 +111,7 @@ public class SearcherServiceImpl implements SearcherService {
     @Override
     public ModelMap searchBrand(String keyword, String field) {
         ModelMap map = new ModelMap();
-        SPage<Map<String, List<Integer>>> brands = null;
+        SPage<Map<String, Object>> brands = null;
         try {
             brands = searchService.getBrands(keyword, DEFAULT_PAGE, DEFAULT_SIZE);
         } catch (SearchException e) {
@@ -120,119 +122,134 @@ public class SearcherServiceImpl implements SearcherService {
         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
+	 * @return
+	 * @throws InterruptedException
+	 * @throws IOException
+	 */
+	@SuppressWarnings("unchecked")
+	@Override
+	public Page<ComponentInfo> searchComponentByFirst(String keyword, PageParams page) {
+		Pageable pageable = new PageInfo(page);
+		return componentInfoDao.findByFirst(keyword,pageable);
+	}
 
-    /**
-     * 智能搜索批次
-     *
-     * @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
+	 * @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);// 当前页器件内容
+		}
 
         map.put("total", results.get("total"));// 搜索结果总数
         map.put("page", results.get("page"));// 当前页面
@@ -425,14 +442,20 @@ public class SearcherServiceImpl implements SearcherService {
         return brands;
     }
 
-    /**
-     * 捕获SearchException抛出SystemException
-     *
-     * @param e
-     * @return
-     */
-    private void throwSystemException(SearchException e) {
-        logger.error(e.getMessage(), e);
-        throw new SystemException(e.getMessage());
-    }
+	@Override
+	public int deleteSearchHistoryByuserUUAndenUU() {
+		return searchHistoryDao.deleteByUserUUAndUserEnuu(SystemSession.getUser().getUserUU(),
+				SystemSession.getUser().getEnterprise() == null ? null : SystemSession.getUser().getEnterprise().getUu() );
+	}
+
+	/**
+	 * 捕获SearchException抛出SystemException
+	 *
+	 * @param e
+	 * @return
+	 */
+	private void throwSystemException(SearchException e) {
+		logger.error(e.getMessage(), e);
+		throw new SystemException(e.getMessage());
+	}
 }

+ 13 - 0
src/main/java/com/uas/platform/b2c/prod/product/brand/api/BrandController.java

@@ -110,6 +110,19 @@ public class BrandController {
 		return brandService.getBrandInfoPage(info, keyword);
 	}
 
+	/**
+	 * 查找所有详细有效品牌信息
+	 * @param keyword 关键词
+	 * @param params
+	 *            分页信息
+	 * @return 品牌简易信息
+	 */
+	@RequestMapping(value = "/Brand/ByPage", method = RequestMethod.GET)
+	public Map<String,Object> getBrandPage(PageParams params, String keyword) {
+		PageInfo info = new PageInfo(params);
+		return brandService.getBrandPage(info, keyword);
+	}
+
 	/**
 	 * 查找所有简单有效品牌信息,并按首字母过滤
 	 * @param keyword 关键词

+ 15 - 15
src/main/java/com/uas/platform/b2c/prod/product/brand/dao/BrandDao.java

@@ -73,21 +73,6 @@ public interface BrandDao extends JpaSpecificationExecutor<Brand>, JpaRepository
 	@Query("select b from Brand b where upper(b.nameCn)=upper(:nameCn)")
 	public List<Brand> findByUpperNameCn(@Param("nameCn") String nameCn);
 
-	/**
-	 * 分页根据首字母获取品牌信息
-	 * @param initals
-	 * @return
-	 */
-	@Query(value = "select b from Brand b  where b.inital in :initals and (b.nameEn like %:keyword% or b.nameCn like %:keyword%)")
-	public Page<Brand> findInInitalsPage(@Param("initals") String[] initals ,@Param("keyword") String keyword, Pageable pageable);
-
-	/**
-	 * 获取搜索量最高的2个品牌
-	 * @return
-	 */
-	@Query(nativeQuery = true , value = "select b from product$brand b order by br_search_count desc LIMIT 2)")
-	public List<Brand> findMostSearchBrands();
-
 	/**
 	 * 器件点击次数加一
 	 * @param uuid
@@ -97,4 +82,19 @@ public interface BrandDao extends JpaSpecificationExecutor<Brand>, JpaRepository
 	@Transactional
 	@Query( nativeQuery = true, value = "update product$brand b set b.br_visit_count = ifnull(b.br_visit_count, 0) + 1 where b.br_uuid = :uuid")
 	public void addVisitCount(@Param("uuid") String uuid);
+
+    /**
+     * 获取搜索量最高的2个品牌
+     * @return
+     */
+    @Query(nativeQuery = true , value = "select b from product$brand b order by br_search_count desc LIMIT 2)")
+    public List<Brand> findMostSearchBrands();
+
+    /**
+     * 分页根据首字母获取品牌信息
+     * @param initals
+     * @return
+     */
+    @Query(value = "select b from Brand b  where b.inital in :initals")
+	public Page<Brand> findInInitalsPage(@Param("initals") String[] initals , Pageable pageable);
 }

+ 8 - 0
src/main/java/com/uas/platform/b2c/prod/product/brand/service/BrandService.java

@@ -83,6 +83,14 @@ public interface BrandService {
 	 */
 	public Page<BrandInfo> getBrandInfoPage(PageInfo pageInfo, String keyword);
 
+	/**
+	 * 获取Brand分页数据
+	 * @param keyword 关键词
+	 * @param pageInfo 分页信息
+	 * @return 品牌简易信息
+	 */
+	public Map<String,Object> getBrandPage(PageInfo pageInfo, String keyword);
+
 	/**
 	 * 获取BrandInfo分页数据
 	 * @param keyword 关键词

+ 29 - 1
src/main/java/com/uas/platform/b2c/prod/product/brand/service/impl/BrandServiceImpl.java

@@ -1,5 +1,6 @@
 package com.uas.platform.b2c.prod.product.brand.service.impl;
 
+import com.uas.platform.b2c.common.search.rpc.service.SearchService;
 import com.uas.platform.b2c.core.utils.PinyinUtils;
 import com.uas.platform.b2c.prod.product.brand.dao.BrandDao;
 import com.uas.platform.b2c.prod.product.brand.dao.BrandInfoDao;
@@ -17,6 +18,8 @@ import com.uas.platform.core.persistence.criteria.CriterionExpression;
 import com.uas.platform.core.persistence.criteria.CriterionExpression.Operator;
 import com.uas.platform.core.persistence.criteria.LogicalExpression;
 import com.uas.platform.core.persistence.criteria.SimpleExpression;
+import com.uas.search.exception.SearchException;
+import com.uas.platform.b2c.common.search.util.SPage;
 import org.apache.commons.collections.CollectionUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -50,6 +53,9 @@ public class BrandServiceImpl implements BrandService {
 	@Autowired
 	private JdbcTemplate jdbcTemplate;
 
+	@Autowired
+	private SearchService searchService;
+
 	@Autowired
 	private BrandMostSimpleInfoDao brandMostSimpleInfoDao;
 
@@ -136,7 +142,11 @@ public class BrandServiceImpl implements BrandService {
 	@Override
 	public Page<Brand> getInitialSimpleInfoByFirst(String key , PageParams params ,String keyword) {
 		Pageable pageable = new PageInfo(params);
-		return brandDao.findInInitalsPage(new String[]{key},keyword, pageable);
+		if ("0~9".equals(key)) {
+			return brandDao.findInInitalsPage(new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}, pageable);
+		}else {
+			return brandDao.findInInitalsPage(new String[]{key}, pageable);
+		}
 	}
 
 	// 判断一个字符串是否含有中文
@@ -199,6 +209,24 @@ public class BrandServiceImpl implements BrandService {
 		}, pageInfo);
 	}
 
+	@Override
+	public Map<String,Object> getBrandPage(final PageInfo pageInfo, String keyword) {
+		SPage<Map<String, Object>> brands = null;
+		try {
+			brands = searchService.getBrands(keyword,pageInfo.getPageNumber(),pageInfo.getPageSize());
+		} catch (SearchException e) {}
+		List<Map<String, Object>> brandPage = brands.getContent();
+		List<Brand> brandList = new ArrayList<>();
+		for (Map<String, Object> a : brandPage){
+			brandList.add(brandDao.findOne(Long.parseLong(a.get("id").toString())));
+		}
+		Map<String,Object> map = new HashMap<>();
+		map.put("content",brandList);
+		map.put("totalPages",brands.getTotalPage());
+		map.put("totalElements",brands.getTotalElement());
+		return map;
+	}
+
 	@Override
 	public Brand findByUuid(String uuid) {
 		// 这个因为是接口错误的话直接返回

+ 3 - 0
src/main/java/com/uas/platform/b2c/prod/product/component/dao/ComponentInfoDao.java

@@ -88,4 +88,7 @@ public interface ComponentInfoDao extends JpaSpecificationExecutor<ComponentInfo
 	 */
 	@Query(nativeQuery = true, value = "select * from product$component where cmp_id in :batchids")
 	public List<ComponentInfo> findByBatchids(@Param("batchids") List<Long> batchids);
+
+	@Query("select c from ComponentInfo c where c.code like :q%")
+	public Page<ComponentInfo> findByFirst(@Param("q") String keyword,Pageable pageable);
 }

+ 3 - 3
src/main/java/com/uas/platform/b2c/prod/product/component/service/impl/ComponentGoodsServiceImpl.java

@@ -53,9 +53,9 @@ public class ComponentGoodsServiceImpl implements ComponentGoodsService {
 			if(filter.get("properties") != null) {
 				String property = filter.get("properties").toString();
 				PageParams pageParams = new PageParams(info.getPageNumber(), info.getPageSize());
-				pageParams.filter(FilterField.COMPONENT_PROPERTIES, property);
-				pageParams.filter(FilterField.COMPONENT_KINDID, filter.get("kindid"));
-				pageParams.filter(FilterField.COMPONENT_BRANDID, filter.get("brandid"));
+				pageParams.filter(PageParams.FilterField.COMPONENT_PROPERTIES, property);
+				pageParams.filter(PageParams.FilterField.COMPONENT_KINDID, filter.get("kindid"));
+				pageParams.filter(PageParams.FilterField.COMPONENT_BRANDID, filter.get("brandid"));
 				filter.remove("properties");
 				filter.remove("kindid");
 				filter.remove("brandid");

+ 3 - 3
src/main/java/com/uas/platform/b2c/prod/product/component/service/impl/ComponentServiceImpl.java

@@ -192,9 +192,9 @@ public class ComponentServiceImpl implements ComponentService {
 			if (filter.get("properties") != null) {
 				String property = filter.get("properties").toString();
 				PageParams pageParams = new PageParams(info.getPageNumber(), info.getPageSize());
-				pageParams.filter(FilterField.COMPONENT_PROPERTIES, property);
-				pageParams.filter(FilterField.COMPONENT_KINDID, filter.get("kindid"));
-				pageParams.filter(FilterField.COMPONENT_BRANDID, filter.get("brandid"));
+				pageParams.filter(PageParams.FilterField.COMPONENT_PROPERTIES, property);
+				pageParams.filter(PageParams.FilterField.COMPONENT_KINDID, filter.get("kindid"));
+				pageParams.filter(PageParams.FilterField.COMPONENT_BRANDID, filter.get("brandid"));
 //				pageParams.filter("code", filter.get("code"));
 				filter.remove("properties");
 				filter.remove("kindid");