|
|
package com.yoho.search.restapi;
|
|
|
|
|
|
import com.yoho.search.service.SearchService;
|
|
|
import com.yoho.search.utils.JsonUtil;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Iterator;
|
|
|
import java.util.Map;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Iterator;
|
|
|
import java.util.Map;
|
|
|
import com.yoho.search.service.SearchService;
|
|
|
import com.yoho.search.service.SearchSortSizeService;
|
|
|
import com.yoho.search.utils.JsonUtil;
|
|
|
import com.yoho.search.vo.SearchApiResult;
|
|
|
import com.yoho.search.vo.SizeSortReqBO;
|
|
|
|
|
|
/**
|
|
|
* 搜索web端
|
...
|
...
|
@@ -22,179 +28,220 @@ import java.util.Map; |
|
|
@RequestMapping("/")
|
|
|
public class SearchController {
|
|
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(SearchController.class);
|
|
|
private static Logger logger = LoggerFactory.getLogger(SearchController.class);
|
|
|
|
|
|
@Autowired
|
|
|
SearchService searchService;
|
|
|
|
|
|
SearchService searchService;
|
|
|
@Autowired
|
|
|
SearchSortSizeService searchSortSizeService;
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
@RequestMapping(method = RequestMethod.GET, value = "/search")
|
|
|
@ResponseBody
|
|
|
public Map searchNew(HttpServletRequest request) {
|
|
|
@ResponseBody
|
|
|
public Map<String, Object> searchNew(HttpServletRequest request) {
|
|
|
Map<String, Object> paramMap = request.getParameterMap();
|
|
|
try {
|
|
|
Map<String, Object> jsonMap = searchService.searchNew(transParamType(paramMap));
|
|
|
return jsonMap;
|
|
|
} catch (Exception e) {
|
|
|
return errorReturn("searchNew", paramMap, e.getMessage());
|
|
|
return errorReturn("searchNew", paramMap, e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
@RequestMapping(method = RequestMethod.GET, value = "/discount")
|
|
|
@ResponseBody
|
|
|
public Map<String, Object> discount(HttpServletRequest request) {
|
|
|
Map<String, Object> paramMap = request.getParameterMap();
|
|
|
try {
|
|
|
Map<String, Object> jsonMap = searchService.discount(transParamType(paramMap));
|
|
|
return jsonMap;
|
|
|
} catch (Exception e) {
|
|
|
return errorReturn("discount", paramMap, e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
@RequestMapping(method = RequestMethod.GET, value = "/recent")
|
|
|
@ResponseBody
|
|
|
public Map<String, Object> recent(HttpServletRequest request) {
|
|
|
Map<String, Object> paramMap = request.getParameterMap();
|
|
|
try {
|
|
|
Map<String, Object> jsonMap = searchService.recentShelveDay(transParamType(paramMap));
|
|
|
return jsonMap;
|
|
|
} catch (Exception e) {
|
|
|
return errorReturn("recent", paramMap, e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
@RequestMapping(method = RequestMethod.GET, value = "/count")
|
|
|
@ResponseBody
|
|
|
public long searchCount(HttpServletRequest request) {
|
|
|
Map<String, Object> paramMap = request.getParameterMap();
|
|
|
try {
|
|
|
long count = searchService.searchCount(transParamType(paramMap));
|
|
|
return count;
|
|
|
} catch (Exception e) {
|
|
|
logger.error("[※查询]失败:" + e.getMessage());
|
|
|
Map<String, Object> rtnMap = new HashMap<String, Object>();
|
|
|
rtnMap.put("code", 400);
|
|
|
rtnMap.put("status", "error");
|
|
|
rtnMap.put("errmsg", e.getMessage());
|
|
|
return 0;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
@RequestMapping(method = RequestMethod.GET, value = "/suggest")
|
|
|
@ResponseBody
|
|
|
public Map<String, Object> suggest(HttpServletRequest request) {
|
|
|
Map<String, Object> paramMap = request.getParameterMap();
|
|
|
try {
|
|
|
Map<String, Object> jsonMap = searchService.suggest(transParamType(paramMap));
|
|
|
return jsonMap;
|
|
|
} catch (Exception e) {
|
|
|
return errorReturn("suggest", paramMap, e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
@RequestMapping(method = RequestMethod.GET, value = "/discount")
|
|
|
@ResponseBody
|
|
|
public Map discount(HttpServletRequest request) {
|
|
|
Map<String, Object> paramMap = request.getParameterMap();
|
|
|
try {
|
|
|
Map<String, Object> jsonMap = searchService.discount(transParamType(paramMap));
|
|
|
return jsonMap;
|
|
|
} catch (Exception e) {
|
|
|
return errorReturn("discount", paramMap, e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
@RequestMapping(method = RequestMethod.GET, value = "/recent")
|
|
|
@ResponseBody
|
|
|
public Map recent(HttpServletRequest request) {
|
|
|
Map<String, Object> paramMap = request.getParameterMap();
|
|
|
try {
|
|
|
Map<String, Object> jsonMap = searchService.recentShelveDay(transParamType(paramMap));
|
|
|
return jsonMap;
|
|
|
} catch (Exception e) {
|
|
|
return errorReturn("recent", paramMap, e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
@RequestMapping(method = RequestMethod.GET, value = "/count")
|
|
|
@ResponseBody
|
|
|
public long searchCount(HttpServletRequest request) {
|
|
|
Map<String, Object> paramMap = request.getParameterMap();
|
|
|
try {
|
|
|
long count = searchService.searchCount(transParamType(paramMap));
|
|
|
return count;
|
|
|
} catch (Exception e) {
|
|
|
logger.error("[※查询]失败:"+ e.getMessage());
|
|
|
Map<String, Object> rtnMap = new HashMap<String, Object>();
|
|
|
rtnMap.put("code", 400);
|
|
|
rtnMap.put("status", "error");
|
|
|
rtnMap.put("errmsg", e.getMessage());
|
|
|
return 0;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
@RequestMapping(method = RequestMethod.GET, value = "/suggest")
|
|
|
@ResponseBody
|
|
|
public Map suggest(HttpServletRequest request) {
|
|
|
Map<String, Object> paramMap = request.getParameterMap();
|
|
|
try {
|
|
|
Map<String, Object> jsonMap = searchService.suggest(transParamType(paramMap));
|
|
|
return jsonMap;
|
|
|
} catch (Exception e) {
|
|
|
return errorReturn("suggest", paramMap, e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
@RequestMapping(method = RequestMethod.GET, value = "/sortgroup")
|
|
|
@ResponseBody
|
|
|
public Map sortGroup(HttpServletRequest request) {
|
|
|
@ResponseBody
|
|
|
public Map<String, Object> sortGroup(HttpServletRequest request) {
|
|
|
Map<String, Object> paramMap = request.getParameterMap();
|
|
|
try {
|
|
|
Map<String, Object> jsonMap = searchService.sortGroup(transParamType(paramMap));
|
|
|
return jsonMap;
|
|
|
} catch (Exception e) {
|
|
|
return errorReturn("sortGroup", paramMap, e.getMessage());
|
|
|
return errorReturn("sortGroup", paramMap, e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
@RequestMapping(method = RequestMethod.GET, value = "/brands")
|
|
|
@ResponseBody
|
|
|
public Map brands(HttpServletRequest request) {
|
|
|
@ResponseBody
|
|
|
public Map<String, Object> brands(HttpServletRequest request) {
|
|
|
Map<String, Object> paramMap = request.getParameterMap();
|
|
|
try {
|
|
|
Map<String, Object> jsonMap = searchService.brands(transParamType(paramMap));
|
|
|
return jsonMap;
|
|
|
} catch (Exception e) {
|
|
|
return errorReturn("brands", paramMap, e.getMessage());
|
|
|
return errorReturn("brands", paramMap, e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
@RequestMapping(method = RequestMethod.GET, value = "/group_brands")
|
|
|
@ResponseBody
|
|
|
public Map groupBrands(HttpServletRequest request) {
|
|
|
Map<String, Object> paramMap = request.getParameterMap();
|
|
|
try {
|
|
|
Map<String, Object> jsonMap = searchService.groupBrands(transParamType(paramMap));
|
|
|
return jsonMap;
|
|
|
} catch (Exception e) {
|
|
|
return errorReturn("groupBrands", paramMap, e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
@RequestMapping(method = RequestMethod.GET, value = "/new-shelve")
|
|
|
@ResponseBody
|
|
|
public Map newShelveProduct(HttpServletRequest request) {
|
|
|
Map<String, Object> paramMap = request.getParameterMap();
|
|
|
try {
|
|
|
Map<String, Object> jsonMap = searchService.newShelveProduct(transParamType(paramMap));
|
|
|
return jsonMap;
|
|
|
} catch (Exception e) {
|
|
|
return errorReturn("newShelveProduct", paramMap, e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
@RequestMapping(method = RequestMethod.GET, value = "/new_product")
|
|
|
@ResponseBody
|
|
|
public Map newProduct(HttpServletRequest request) {
|
|
|
Map<String, Object> paramMap = request.getParameterMap();
|
|
|
try {
|
|
|
Map<String, Object> jsonMap = searchService.newProduct(transParamType(paramMap));
|
|
|
return jsonMap;
|
|
|
} catch (Exception e) {
|
|
|
return errorReturn("newProduct", paramMap, e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
@RequestMapping(method = RequestMethod.GET, value = "/shops")
|
|
|
@ResponseBody
|
|
|
public Map shops(HttpServletRequest request) {
|
|
|
Map<String, Object> paramMap = request.getParameterMap();
|
|
|
try {
|
|
|
Map<String, Object> jsonMap = searchService.shops(transParamType(paramMap));
|
|
|
return jsonMap;
|
|
|
} catch (Exception e) {
|
|
|
return errorReturn("shops", paramMap, e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private Map errorReturn(final String funName, final Map<String, Object> paramMap, final String errorMessage) {
|
|
|
logger.error("[※查询]失败:[func={}][param={}][message={}]", funName, JsonUtil.toJson(paramMap), errorMessage);
|
|
|
Map<String, Object> rtnMap = new HashMap<String, Object>();
|
|
|
rtnMap.put("code", 400);
|
|
|
rtnMap.put("status", "error");
|
|
|
rtnMap.put("errmsg", errorMessage);
|
|
|
return rtnMap; //new ModelAndView(ISearchConstans.JSON_VIEW_NAME, rtnMap);
|
|
|
}
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
@RequestMapping(method = RequestMethod.GET, value = "/group_brands")
|
|
|
@ResponseBody
|
|
|
public Map<String, Object> groupBrands(HttpServletRequest request) {
|
|
|
Map<String, Object> paramMap = request.getParameterMap();
|
|
|
try {
|
|
|
Map<String, Object> jsonMap = searchService.groupBrands(transParamType(paramMap));
|
|
|
return jsonMap;
|
|
|
} catch (Exception e) {
|
|
|
return errorReturn("groupBrands", paramMap, e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
@RequestMapping(method = RequestMethod.GET, value = "/new-shelve")
|
|
|
@ResponseBody
|
|
|
public Map<String, Object> newShelveProduct(HttpServletRequest request) {
|
|
|
Map<String, Object> paramMap = request.getParameterMap();
|
|
|
try {
|
|
|
Map<String, Object> jsonMap = searchService.newShelveProduct(transParamType(paramMap));
|
|
|
return jsonMap;
|
|
|
} catch (Exception e) {
|
|
|
return errorReturn("newShelveProduct", paramMap, e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
@RequestMapping(method = RequestMethod.GET, value = "/new_product")
|
|
|
@ResponseBody
|
|
|
public Map<String, Object> newProduct(HttpServletRequest request) {
|
|
|
Map<String, Object> paramMap = request.getParameterMap();
|
|
|
try {
|
|
|
Map<String, Object> jsonMap = searchService.newProduct(transParamType(paramMap));
|
|
|
return jsonMap;
|
|
|
} catch (Exception e) {
|
|
|
return errorReturn("newProduct", paramMap, e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
@RequestMapping(method = RequestMethod.GET, value = "/shops")
|
|
|
@ResponseBody
|
|
|
public Map<String, Object> shops(HttpServletRequest request) {
|
|
|
Map<String, Object> paramMap = request.getParameterMap();
|
|
|
try {
|
|
|
Map<String, Object> jsonMap = searchService.shops(transParamType(paramMap));
|
|
|
return jsonMap;
|
|
|
} catch (Exception e) {
|
|
|
return errorReturn("shops", paramMap, e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private Map<String, Object> errorReturn(final String funName, final Map<String, Object> paramMap, final String errorMessage) {
|
|
|
logger.error("[※查询]失败:[func={}][param={}][message={}]", funName, JsonUtil.toJson(paramMap), errorMessage);
|
|
|
Map<String, Object> rtnMap = new HashMap<String, Object>();
|
|
|
rtnMap.put("code", 400);
|
|
|
rtnMap.put("status", "error");
|
|
|
rtnMap.put("errmsg", errorMessage);
|
|
|
return rtnMap; // new ModelAndView(ISearchConstans.JSON_VIEW_NAME,
|
|
|
// rtnMap);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 将HttpServletRequest中被锁定的ParameterMap转化为普通的HashMap
|
|
|
* */
|
|
|
public static Map<String, String> transParamType(Map<String, Object> paramMap){
|
|
|
Map<String, String> rtnMap = new HashMap<String, String>();
|
|
|
Iterator<String> itKeys = paramMap.keySet().iterator();
|
|
|
while(itKeys.hasNext()){
|
|
|
String key = itKeys.next();
|
|
|
String val = ((String[])paramMap.get(key))[0];
|
|
|
rtnMap.put(key, val);
|
|
|
}
|
|
|
return rtnMap;
|
|
|
public static Map<String, String> transParamType(Map<String, Object> paramMap) {
|
|
|
Map<String, String> rtnMap = new HashMap<String, String>();
|
|
|
Iterator<String> itKeys = paramMap.keySet().iterator();
|
|
|
while (itKeys.hasNext()) {
|
|
|
String key = itKeys.next();
|
|
|
String val = ((String[]) paramMap.get(key))[0];
|
|
|
rtnMap.put(key, val);
|
|
|
}
|
|
|
return rtnMap;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取分类,以及分类下的型号
|
|
|
*
|
|
|
* @param request
|
|
|
* @return
|
|
|
*/
|
|
|
@RequestMapping(method = RequestMethod.GET, value = "/sort_sizes")
|
|
|
@ResponseBody
|
|
|
public SearchApiResult sort_sizes(@ModelAttribute SizeSortReqBO sizeSortReqBO) {
|
|
|
return searchSortSizeService.sortSizes(sizeSortReqBO);
|
|
|
}
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
@RequestMapping(method = RequestMethod.GET, value = "/sort_size_products")
|
|
|
@ResponseBody
|
|
|
public Map<String, Object> sort_size_products(HttpServletRequest request) {
|
|
|
Map<String, Object> paramMap = request.getParameterMap();
|
|
|
try {
|
|
|
Map<String, Object> jsonMap = searchSortSizeService.sortSizeProducts(transParamType(paramMap));
|
|
|
return jsonMap;
|
|
|
} catch (Exception e) {
|
|
|
return errorReturn("sort_size_products", paramMap, e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
@RequestMapping(method = RequestMethod.GET, value = "/group_shops")
|
|
|
@ResponseBody
|
|
|
public Map<String, Object> groupShops(HttpServletRequest request) {
|
|
|
Map<String, Object> paramMap = request.getParameterMap();
|
|
|
try {
|
|
|
Map<String, Object> jsonMap = searchService.groupShops(transParamType(paramMap));
|
|
|
return jsonMap;
|
|
|
} catch (Exception e) {
|
|
|
return errorReturn("groupShops", paramMap, e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
} |
...
|
...
|
|