SearchNewController.java 3.1 KB
package com.yoho.search.restapi;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yoho.search.common.downgrade.aop.DownGradeAble;
import com.yoho.search.common.utils.HttpServletRequestUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.service.IDiscountService;
import com.yoho.search.service.service.IProductCountService;
import com.yoho.search.service.service.IRecentService;
import com.yoho.search.service.service.SearchProductsServiceNew;
import com.yoho.search.service.service.impl.SearchSortGroupService;

@Controller
public class SearchNewController {

	@Autowired
	private SearchSortGroupService searchSortGroupService;
	@Autowired
	private IRecentService recentService;
	@Autowired
	private IDiscountService discountService;
	@Autowired
	private SearchProductsServiceNew searchProductsServiceNew;
	@Autowired
	private IProductCountService productCountService;

	/**
	 * 搜索商品列表以及聚合结果的接口
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping(method = RequestMethod.GET, value = "/search")
	@ResponseBody
	public SearchApiResult searchProductsNew(HttpServletRequest request) {
		Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
		return searchProductsServiceNew.searchProductsNew(paramMap);
	}
	
	/**
	 * 对分类进行分组查询
	 *
	 * @param request
	 * @return
	 */
	@DownGradeAble(key = "sortgroup")
	@RequestMapping(method = RequestMethod.GET, value = "/sortgroup")
	@ResponseBody
	public SearchApiResult sortGroup(HttpServletRequest request) {
		Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
		return searchSortGroupService.sortGroup(paramMap);
	}

	/**
	 * 获取按上架日期聚合的结果
	 *
	 * @param request
	 * @return
	 */
	@DownGradeAble(key = "recent")
	@RequestMapping(method = RequestMethod.GET, value = "/recent")
	@ResponseBody
	public SearchApiResult recent(HttpServletRequest request) {
		Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
		return recentService.recent(paramMap);
	}

	/**
	 * 获取按折扣聚合的结果
	 *
	 * @param request
	 * @return
	 */
	@DownGradeAble(key = "discount")
	@RequestMapping(method = RequestMethod.GET, value = "/discount")
	@ResponseBody
	public SearchApiResult discount(HttpServletRequest request) {
		Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
		return discountService.discount(paramMap);
	}

	/**
	 * 根据关键字查询获取商品数量[目前好像没在调]
	 *
	 * @return
	 */
	@RequestMapping(method = RequestMethod.GET, value = "/count")
	@ResponseBody
	public long countByQuery(HttpServletRequest request) {
		Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
		return productCountService.countByQuery(paramMap);
	}
	

}