CouponSceneService.java 2.21 KB
package com.yoho.search.service.scene;

import com.yoho.search.base.utils.SearchPageIdDefine;
import com.yoho.search.common.utils.SearchApiResultUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.scene.list.ProductListSwitchService;
import com.yoho.search.service.scene.common.AbstractSceneService;
import com.yoho.search.service.scene.brandshop.RecommendBrandsService;
import com.yoho.search.service.scene.aggregations.SceneSelectionsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class CouponSceneService extends AbstractSceneService {

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

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

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

	@Override
	public void addParamsToParamMap(Map<String, String> paramMap) {
		super.addDefaultParamsToParamMap(paramMap);
		super.filterNotNormalToMap(paramMap);
	}

	@Override
	public SearchApiResult productList(Map<String, String> paramMap) {
		try {
			// 1、添加默认参数
			this.addParamsToParamMap(paramMap);
			// 2、返回商品列表
			return sceneProductListService.productList(paramMap);
		} catch (Exception e) {
			logger.error("[func=CouponProductList][params=" + paramMap + "]", e);
			return SearchApiResultUtils.errorSearchApiResult("CouponProductList", paramMap, e);
		}
	}

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