HongRenDistributionController.java 2.98 KB
package com.yoho.search.restapi.others;

import com.yoho.search.common.utils.HttpServletRequestUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.base.SearchRequestParams;
import com.yoho.search.service.service.impl.SearchHongRenService;
import com.yoho.search.service.service.impl.SearchSortGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/hr")
public class HongRenDistributionController {

    @Autowired
    private SearchSortGroupService searchSortGroupService;
    @Autowired
    private SearchHongRenService searchHongRenService;
    /**
     * 对分类进行分组查询
     * @param request
     * @return
     */
    @RequestMapping(method = RequestMethod.GET, value = "/sortgroup")
    public SearchApiResult sortGroup(HttpServletRequest request) {
        Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
        if (!checkRequestParam(paramMap)) {
            return new SearchApiResult().setCode(400).setMessage("入参缺少hrShopId参数");
        }
        return searchSortGroupService.sortGroup(paramMap);
    }

    @RequestMapping(method = RequestMethod.GET, value = "/shopList")
    public SearchApiResult getShopList(HttpServletRequest request) {
        Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
        if (!checkRequestParam(paramMap)) {
            return new SearchApiResult().setCode(400).setMessage("入参缺少hrShopId参数");
        }
        return searchHongRenService.shopList(paramMap);
    }

    @RequestMapping(method = RequestMethod.GET, value = "/productList")
    public SearchApiResult productList(HttpServletRequest request) {
        Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
        if (!checkRequestParam(paramMap)) {
            return new SearchApiResult().setCode(400).setMessage("入参缺少hrShopId参数");
        }
        SearchApiResult searchApiResult = searchHongRenService.productList(paramMap);
        return searchApiResult;
    }

    @RequestMapping(method = RequestMethod.GET, value = "/productListForFuzzy")
    public SearchApiResult fuzzyProductList(HttpServletRequest request) {
        Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
        if (!checkRequestParam(paramMap)) {
            return new SearchApiResult().setCode(400).setMessage("入参缺少hrShopId参数");
        }
        SearchApiResult searchApiResult = searchHongRenService.productListForFuzzy(paramMap);
        return searchApiResult;
    }

    private boolean checkRequestParam(Map<String, String> paramMap) {
        return paramMap.containsKey(SearchRequestParams.PRODUCTINDEX_HRSHOPID);
    }


}