ReducePriceSceneService.java 2.58 KB
package com.yoho.search.service.scene;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yoho.search.base.utils.DateUtil;
import com.yoho.search.base.utils.SearchPageIdDefine;
import com.yoho.search.common.utils.SearchApiResultUtils;
import com.yoho.search.core.es.agg.IAggregation;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.common.SearchRequestParams;
import com.yoho.search.service.scene.common.AbstractSceneService;
import com.yoho.search.service.scene.list.ProductListSwitchService;
import com.yoho.search.service.scene.aggregations.SceneSelectionsService;

@Service
public class ReducePriceSceneService extends AbstractSceneService {

	private static final Logger logger = LoggerFactory.getLogger(ReducePriceSceneService.class);

	@Autowired
	private ProductListSwitchService sceneProductListService;
	@Autowired
	private SceneSelectionsService sceneSelectionsService;

	@Override
	public String pageId() {
		return SearchPageIdDefine.PAGE_ID_REDUCE_PRICE;
	}

	@Override
	public void addParamsToParamMap(Map<String, String> paramMap) {
		super.addDefaultParamsToParamMap(paramMap);
		// 默认打折
		paramMap.put(SearchRequestParams.PARAM_SEARCH_ISDISCOUNT, "Y");
		// 默认一周降价
		long end = DateUtil.getLastTimeSecond(new Date());
		long begin = DateUtil.getFirstTimeSecond(DateUtil.addDay(new Date(), -7));
		paramMap.put(SearchRequestParams.PARAM_SEARCH_PRICE_UPDATE_TIME, begin + "," + end);
	}
	
	@Override
	public SearchApiResult productList(Map<String, String> paramMap) {
		try {
			// 1、添加默认参数
			this.addParamsToParamMap(paramMap);
			// 2、返回商品列表
			return sceneProductListService.productList(paramMap);
		} catch (Exception e) {
			logger.error("[func=NewArrivalProductList][params=" + paramMap + "]", e);
			return SearchApiResultUtils.errorSearchApiResult("NewArrivalProductList", paramMap, e);
		}
	}

	@Override
	public SearchApiResult aggregations(Map<String, String> paramMap) {
		try {
			// 1、添加默认参数
			this.addParamsToParamMap(paramMap);
			// 2、返回聚合结果
			List<IAggregation> aggregation = sceneSelectionsService.getReducePriceAggregations(paramMap);
			return sceneSelectionsService.aggregations(paramMap, aggregation);
		} catch (Exception e) {
			logger.error("[func=NewArrivalAggregations][params=" + paramMap + "]", e);
			return SearchApiResultUtils.errorSearchApiResult("NewArrivalAggregations", paramMap, e);
		}
	}

}