Просмотр исходного кода

搜索:返回 logoUrl只有手机的时候

wangdy 8 лет назад
Родитель
Сommit
7cb4f6052b

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

@@ -238,8 +238,8 @@ public class SearcherController {
      */
     @RequestMapping(value = "/componentGoods/collect", method = RequestMethod.GET)
     @ResponseBody
-    public List<Map<String, Object>> searchCollectListByComponentGoodsSearch(String keyword, String collectList, String paramJSON) {
-        return searcherService.getCollectlistBySearchComponentGoods(keyword,collectList,paramJSON);
+    public List<Map<String, Object>> searchCollectListByComponentGoodsSearch(String keyword, String collectList, String paramJSON , HttpServletRequest request) {
+        return searcherService.getCollectlistBySearchComponentGoods(keyword,collectList,paramJSON,request);
     }
 
 

+ 2 - 1
src/main/java/com/uas/platform/b2c/common/search/service/SearcherService.java

@@ -4,6 +4,7 @@ import com.uas.platform.core.model.PageParams;
 import com.uas.search.exception.SearchException;
 import org.springframework.ui.ModelMap;
 
+import javax.servlet.http.HttpServletRequest;
 import java.io.IOException;
 import java.util.List;
 import java.util.Map;
@@ -94,7 +95,7 @@ public interface SearcherService {
 	 * @param paramJSON 参数json
 	 * @return 类目,器件,店铺类型,货币类型统计
 	 */
-	public List<Map<String, Object>> getCollectlistBySearchComponentGoods(String keyword, String collectList,String paramJSON);
+	public List<Map<String, Object>> getCollectlistBySearchComponentGoods(String keyword, String collectList, String paramJSON, HttpServletRequest request);
 
 
 	/**

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

@@ -20,11 +20,14 @@ import com.uas.search.model.Sort;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.mobile.device.DeviceResolver;
+import org.springframework.mobile.device.LiteDeviceResolver;
 import org.springframework.stereotype.Service;
 import org.springframework.ui.ModelMap;
 import org.springframework.util.CollectionUtils;
 import org.springframework.util.StringUtils;
 
+import javax.servlet.http.HttpServletRequest;
 import java.io.IOException;
 import java.util.*;
 import java.util.Map.Entry;
@@ -51,6 +54,7 @@ public class SearcherServiceImpl implements SearcherService {
 	private BrandDao brandDao;
 
 	private Logger logger = LoggerFactory.getLogger(getClass());
+	private final DeviceResolver deviceResolver = new LiteDeviceResolver();
 
 	/**
 	 * 智能搜索类目
@@ -170,7 +174,7 @@ public class SearcherServiceImpl implements SearcherService {
 		if (!CollectionUtils.isEmpty(componentIds)) {
 			for (int i = 0 ;i < componentIds.size() ; i++){
 				Long cid = Long.valueOf(componentIds.get(i).toString());
-				Long gid = goodsIds.get(i) == null ? null : Long.valueOf(goodsIds.get(i).toString());
+				Long gid = goodsIds.get(i) == null ? 0L : Long.valueOf(goodsIds.get(i).toString());
 				ComponentGoods componentGoods = componentGoodsDao.findByCmpIdAndGoId(cid, gid);
 				if (componentGoods != null){
 					components.add(componentGoods);
@@ -251,7 +255,7 @@ public class SearcherServiceImpl implements SearcherService {
 	 * @return
 	 */
 	@Override
-	public List<Map<String, Object>> getCollectlistBySearchComponentGoods(String keyword, String collectList, String paramJSON) {
+	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();
@@ -264,9 +268,11 @@ public class SearcherServiceImpl implements SearcherService {
 		} catch (SearchException e) {
 			throwSystemException(e);
 		}
-		if ("goods_brand".equals(collectList)){
-			for (Map<String,Object> m: collectResult) {
-				m.put("logoUrl",brandDao.findOne(Long.parseLong(m.get("br_id").toString())).getLogoUrl());
+		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;