SearchNewController.java 2.89 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.utils.HttpServletRequestUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.scene.general.DiscountService;
import com.yoho.search.service.scene.general.ProductCountService;
import com.yoho.search.service.scene.general.RecentService;
import com.yoho.search.service.scene.general.SearchService;
import com.yoho.search.service.scene.general.SortGroupService;

@Controller
public class SearchNewController {

	@Autowired
	private SortGroupService sortGroupService;
	@Autowired
	private RecentService recentService;
	@Autowired
	private DiscountService discountService;
	@Autowired
	private SearchService searchService;
	@Autowired
	private ProductCountService productCountService;

	/**
	 * 搜索商品列表以及聚合结果的接口
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping(method = RequestMethod.GET, value = "/search")
	@ResponseBody
	public SearchApiResult searchProductsNew(HttpServletRequest request) {
		Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
		return searchService.searchProductsNew(paramMap);
	}

	/**
	 * 对分类进行分组查询
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping(method = RequestMethod.GET, value = "/sortgroup")
	@ResponseBody
	public SearchApiResult sortGroup(HttpServletRequest request) {
		Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
		return sortGroupService.sortGroup(paramMap);
	}

	/**
	 * 获取按上架日期聚合的结果
	 *
	 * @param request
	 * @return
	 */
	@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
	 */
	@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);
	}

}