Authored by hugufei

去除service的警告

package com.yoho.search.restapi;
import com.alibaba.fastjson.JSONObject;
import com.yoho.search.dal.model.Brand;
import com.yoho.search.dal.service.BrandService;
import com.yoho.search.service.BrandSearchService;
import com.yoho.search.utils.ISearchConstans;
import com.yoho.search.utils.JsonUtil;
import com.yoho.search.utils.ParamUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -15,12 +14,12 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;
import com.yoho.search.dal.model.Brand;
import com.yoho.search.dal.service.BrandService;
import com.yoho.search.service.BrandSearchService;
import com.yoho.search.utils.JsonUtil;
@Controller
public class BrandController {
... ... @@ -34,7 +33,7 @@ public class BrandController {
@RequestMapping(value = "/brand/{brandId}")
@ResponseBody
public Map brand(@PathVariable Short brandId, HttpServletRequest request) {
public Map<String,Object> brand(@PathVariable Short brandId, HttpServletRequest request) {
try {
Brand brand = brandService.getById(brandId);
JSONObject json = new JSONObject();
... ... @@ -52,7 +51,7 @@ public class BrandController {
@RequestMapping(value = "/brand/{start}/{size}")
@ResponseBody
public Map brand(@PathVariable Integer start, @PathVariable Integer size, HttpServletRequest request) {
public Map<String,Object> brand(@PathVariable Integer start, @PathVariable Integer size, HttpServletRequest request) {
try {
List<Brand> brands = brandService.getBrandPageLists(start, size);
JSONObject json = new JSONObject();
... ... @@ -62,13 +61,12 @@ public class BrandController {
return errorReturn("list", null, e.getMessage());
}
}
@SuppressWarnings("unchecked")
@RequestMapping(method = RequestMethod.GET, value = "/brand/list")
@ResponseBody
public Map list(HttpServletRequest request) {
public Map<String,Object> list(HttpServletRequest request) {
Map<String, Object> paramMap = request.getParameterMap();
try {
Map<String, Object> jsonMap = brandSearchService.listNew();
return jsonMap;
... ... @@ -76,8 +74,8 @@ public class BrandController {
return errorReturn("list", paramMap, e.getMessage());
}
}
private Map errorReturn(final String funName, final Map<String, Object> paramMap, final String errorMessage) {
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);
... ...
package com.yoho.search.restapi;
import com.yoho.search.service.TblProductService;
import com.yoho.search.utils.ISearchConstans;
import com.yoho.search.utils.ParamUtils;
import java.util.HashMap;
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.*;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
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.Map;
import com.yoho.search.service.TblProductService;
import com.yoho.search.utils.ParamUtils;
@Controller
public class TblProductController {
... ... @@ -25,7 +29,7 @@ public class TblProductController {
@SuppressWarnings("unchecked")
@RequestMapping(method = RequestMethod.GET, value = "/tblproduct/search")
@ResponseBody
public Map search(HttpServletRequest request) {
public Map<String,Object> search(HttpServletRequest request) {
Map<String, Object> paramMap = request.getParameterMap();
try {
Map<String, Object> jsonMap = tblProductService.search(ParamUtils.transParamType(paramMap));
... ... @@ -42,7 +46,7 @@ public class TblProductController {
@RequestMapping(method = RequestMethod.POST, value = "/tblproduct/update/{product_skn}")
@ResponseBody
public Map updateIndex(@PathVariable String product_skn, @RequestBody String json, HttpServletRequest request) {
public Map<String,Object> updateIndex(@PathVariable String product_skn, @RequestBody String json, HttpServletRequest request) {
try{
tblProductService.update(product_skn, json);
return getResultMap(200, product_skn, "update tblproduct product_skn=" + product_skn + " success");
... ...
package com.yoho.search.service;
import com.yoho.search.index.Index;
import com.yoho.search.index.IndexClient;
import com.yoho.search.index.SearchCallback;
import com.yoho.search.index.service.IndexService;
import com.yoho.search.dal.model.SearchParam;
import com.yoho.search.dal.model.SearchResult;
import com.yoho.search.utils.ConvertUtils;
import com.yoho.search.utils.PriceRangeUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.elasticsearch.index.query.BoolFilterBuilder;
import org.elasticsearch.index.query.FilterBuilders;
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
... ... @@ -17,7 +16,13 @@ import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
import com.yoho.search.dal.model.SearchParam;
import com.yoho.search.dal.model.SearchResult;
import com.yoho.search.index.Index;
import com.yoho.search.index.IndexClient;
import com.yoho.search.index.SearchCallback;
import com.yoho.search.index.service.IndexService;
import com.yoho.search.utils.PriceRangeUtils;
/**
* Created by YOHO on 15-11-2.
... ... @@ -25,147 +30,149 @@ import java.util.*;
@Service
public class SearchBaseService {
@Autowired
private IndexService indexService;
/**
* 执行检索
*
* @param indexName
* @param searchParam
* @return SearchResult 返回检索结果
*/
public SearchResult doSearch(final String indexName, final SearchParam searchParam) {
SearchResult searchResult = null;
Index firstIndex = indexService.getIndex(indexName);
if (firstIndex != null) {
searchResult = indexService.execute(new SearchCallback<SearchResult>() {
@Override
public SearchResult execute(IndexClient indexClient) {
return indexClient.search(indexName, searchParam);
}
}, firstIndex);
}
return searchResult;
}
@Autowired
private IndexService indexService;
/**
* 执行检索
*
* @param indexName
* @param searchParam
* @return SearchResult 返回检索结果
*/
public SearchResult doSearch(final String indexName, final SearchParam searchParam) {
SearchResult searchResult = null;
Index firstIndex = indexService.getIndex(indexName);
if (firstIndex != null) {
searchResult = indexService.execute(new SearchCallback<SearchResult>() {
@Override
public SearchResult execute(IndexClient indexClient) {
return indexClient.search(indexName, searchParam);
}
}, firstIndex);
}
return searchResult;
}
//构造通用的检索条件
public BoolFilterBuilder buildFilter(BoolFilterBuilder boolFilterBuilder, Map<String, String> paramMap) {
String key;
String field;
for (Map.Entry<String, String> entry : paramMap.entrySet()) {
if (entry.getKey().startsWith("filter_")) {
key = entry.getKey();
field = key.substring(7, key.length());
String value = entry.getValue();
if (value.contains(",")) {
String[] values = value.split(",");
boolFilterBuilder.must(FilterBuilders.termsFilter(field, values));
} else {
boolFilterBuilder.must(FilterBuilders.termFilter(field, value));
}
} else if (entry.getKey().startsWith("not_filter_")) {
key = entry.getKey();
field = key.substring(11, key.length());
String value = entry.getValue();
if (value.contains(",")) {
String[] values = value.split(",");
boolFilterBuilder.mustNot(FilterBuilders.termsFilter(field, values));
} else {
boolFilterBuilder.mustNot(FilterBuilders.termFilter(field, value));
}
} else if (entry.getKey().startsWith("range_gte_")) {
key = entry.getKey();
field = key.substring(10, key.length());
boolFilterBuilder.must(FilterBuilders.rangeFilter(field).gte(entry.getValue()));
} else if (entry.getKey().startsWith("range_lte_")) {
key = entry.getKey();
field = key.substring(10, key.length());
boolFilterBuilder.must(FilterBuilders.rangeFilter(field).lte(entry.getValue()));
} else if (entry.getKey().startsWith("range_gt_")) {
key = entry.getKey();
field = key.substring(9, key.length());
boolFilterBuilder.must(FilterBuilders.rangeFilter(field).gt(entry.getValue()));
} else if (entry.getKey().startsWith("range_lt_")) {
key = entry.getKey();
field = key.substring(9, key.length());
boolFilterBuilder.must(FilterBuilders.rangeFilter(field).lt(entry.getValue()));
}
}
return boolFilterBuilder;
}
// 构造通用的检索条件
public BoolFilterBuilder buildFilter(BoolFilterBuilder boolFilterBuilder, Map<String, String> paramMap) {
String key;
String field;
for (Map.Entry<String, String> entry : paramMap.entrySet()) {
if (entry.getKey().startsWith("filter_")) {
key = entry.getKey();
field = key.substring(7, key.length());
String value = entry.getValue();
if (value.contains(",")) {
String[] values = value.split(",");
boolFilterBuilder.must(FilterBuilders.termsFilter(field, values));
} else {
boolFilterBuilder.must(FilterBuilders.termFilter(field, value));
}
} else if (entry.getKey().startsWith("not_filter_")) {
key = entry.getKey();
field = key.substring(11, key.length());
String value = entry.getValue();
if (value.contains(",")) {
String[] values = value.split(",");
boolFilterBuilder.mustNot(FilterBuilders.termsFilter(field, values));
} else {
boolFilterBuilder.mustNot(FilterBuilders.termFilter(field, value));
}
} else if (entry.getKey().startsWith("range_gte_")) {
key = entry.getKey();
field = key.substring(10, key.length());
boolFilterBuilder.must(FilterBuilders.rangeFilter(field).gte(entry.getValue()));
} else if (entry.getKey().startsWith("range_lte_")) {
key = entry.getKey();
field = key.substring(10, key.length());
boolFilterBuilder.must(FilterBuilders.rangeFilter(field).lte(entry.getValue()));
} else if (entry.getKey().startsWith("range_gt_")) {
key = entry.getKey();
field = key.substring(9, key.length());
boolFilterBuilder.must(FilterBuilders.rangeFilter(field).gt(entry.getValue()));
} else if (entry.getKey().startsWith("range_lt_")) {
key = entry.getKey();
field = key.substring(9, key.length());
boolFilterBuilder.must(FilterBuilders.rangeFilter(field).lt(entry.getValue()));
}
}
return boolFilterBuilder;
}
public List<AbstractAggregationBuilder> buildAggregations(Map<String, String> paramMap) {
List<AbstractAggregationBuilder> list = new ArrayList<AbstractAggregationBuilder>();
String key;
String field;
for (Map.Entry<String, String> entry : paramMap.entrySet()) {
if (entry.getKey().startsWith("agg_")) {
key = entry.getKey();
field = key.substring(4, key.length());
if ("goods_price".equals(field)) {
list.add(AggregationBuilders.terms(field + "Agg").field(field).size(10000).order(Terms.Order.term(true)));
} else {
list.add(AggregationBuilders.terms(field + "Agg").field(field).size(1000));
}
}
}
return list;
}
public List<AbstractAggregationBuilder> buildAggregations(Map<String, String> paramMap) {
List<AbstractAggregationBuilder> list = new ArrayList<AbstractAggregationBuilder>();
String key;
String field;
for (Map.Entry<String, String> entry : paramMap.entrySet()) {
if (entry.getKey().startsWith("agg_")) {
key = entry.getKey();
field = key.substring(4, key.length());
if ("goods_price".equals(field)) {
list.add(AggregationBuilders.terms(field + "Agg").field(field).size(10000).order(Terms.Order.term(true)));
} else {
list.add(AggregationBuilders.terms(field + "Agg").field(field).size(1000));
}
}
}
return list;
}
public List<Map<String, Object>> buildFilterResponseMap(MultiBucketsAggregation aggregation, String fieldName) {
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
Map<String, Object> map;
Iterator<? extends MultiBucketsAggregation.Bucket> itSizeAgg = aggregation.getBuckets().iterator();
while (itSizeAgg.hasNext()) {
MultiBucketsAggregation.Bucket lt = itSizeAgg.next();
map = new HashMap<String, Object>();
map.put(fieldName, lt.getKey());
list.add(map);
}
return list;
}
public List<Map<String, Object>> buildFilterResponseMap(MultiBucketsAggregation aggregation, String fieldName) {
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
Map<String, Object> map;
Iterator<? extends MultiBucketsAggregation.Bucket> itSizeAgg = aggregation.getBuckets().iterator();
while (itSizeAgg.hasNext()) {
MultiBucketsAggregation.Bucket lt = itSizeAgg.next();
map = new HashMap<String, Object>();
map.put(fieldName, lt.getKey());
list.add(map);
}
return list;
}
public Map<String, Object> getPriceResponseMap(MultiBucketsAggregation aggregation) {
Map<String, Object> priceMap = new LinkedHashMap<String, Object>();
if (aggregation.getBuckets().isEmpty()) return priceMap;
Iterator<? extends MultiBucketsAggregation.Bucket> itPriceAgg = aggregation.getBuckets().iterator();
int size = aggregation.getBuckets().size();
float[] prePrice = new float[size];
int i = 0;
while (itPriceAgg.hasNext()) {
prePrice[i] = Float.parseFloat(itPriceAgg.next().getKey());
i++;
}
float maxPrice = prePrice[i - 1];
List<Integer> intervals = PriceRangeUtils.getPriceInterval(prePrice, maxPrice);
size = intervals.size();
int j = 0;
for (j = 0; j < size - 1; j++) {
if (j > 0) {
priceMap.put((intervals.get(j) + 1) + "," + intervals.get(j + 1), "¥" + (intervals.get(j) + 1) + "-" + intervals.get(j + 1));
} else {
priceMap.put(intervals.get(j) + "," + intervals.get(j + 1), "¥" + intervals.get(j) + "-" + intervals.get(j + 1));
}
}
priceMap.put((intervals.get(j) + 1) + ",99999", "¥" + intervals.get(j) + "以上");
return priceMap;
}
public Map<String, Object> getPriceResponseMap(MultiBucketsAggregation aggregation) {
Map<String, Object> priceMap = new LinkedHashMap<String, Object>();
if (aggregation.getBuckets().isEmpty())
return priceMap;
Iterator<? extends MultiBucketsAggregation.Bucket> itPriceAgg = aggregation.getBuckets().iterator();
int size = aggregation.getBuckets().size();
float[] prePrice = new float[size];
int i = 0;
while (itPriceAgg.hasNext()) {
prePrice[i] = Float.parseFloat(itPriceAgg.next().getKey());
i++;
}
float maxPrice = prePrice[i - 1];
List<Integer> intervals = PriceRangeUtils.getPriceInterval(prePrice, maxPrice);
size = intervals.size();
int j = 0;
for (j = 0; j < size - 1; j++) {
if (j > 0) {
priceMap.put((intervals.get(j) + 1) + "," + intervals.get(j + 1), "¥" + (intervals.get(j) + 1) + "-" + intervals.get(j + 1));
} else {
priceMap.put(intervals.get(j) + "," + intervals.get(j + 1), "¥" + intervals.get(j) + "-" + intervals.get(j + 1));
}
}
priceMap.put((intervals.get(j) + 1) + ",99999", "¥" + intervals.get(j) + "以上");
return priceMap;
}
public Map<String, Object> getGenderResponseMap(MultiBucketsAggregation aggregation) {
Map<String, Object> genderMap = new LinkedHashMap<String, Object>();
Iterator<? extends MultiBucketsAggregation.Bucket> itGenderAgg = aggregation.getBuckets().iterator();
while (itGenderAgg.hasNext()) {
MultiBucketsAggregation.Bucket ltGender = itGenderAgg.next();
String genderId = ltGender.getKey();
if ("1".equals(genderId)) {
genderMap.put("1,3", "BOYS");
} else if ("2".equals(genderId)) {
genderMap.put("2,3", "GIRLS");
} else {
genderMap.put("1,3", "BOYS");
genderMap.put("2,3", "GIRLS");
}
}
return genderMap;
}
public Map<String, Object> getGenderResponseMap(MultiBucketsAggregation aggregation) {
Map<String, Object> genderMap = new LinkedHashMap<String, Object>();
Iterator<? extends MultiBucketsAggregation.Bucket> itGenderAgg = aggregation.getBuckets().iterator();
while (itGenderAgg.hasNext()) {
MultiBucketsAggregation.Bucket ltGender = itGenderAgg.next();
String genderId = ltGender.getKey();
if ("1".equals(genderId)) {
genderMap.put("1,3", "BOYS");
} else if ("2".equals(genderId)) {
genderMap.put("2,3", "GIRLS");
} else {
genderMap.put("1,3", "BOYS");
genderMap.put("2,3", "GIRLS");
}
}
return genderMap;
}
}
... ...
This diff could not be displayed because it is too large.
package com.yoho.search.service;
import com.yoho.search.index.service.IndexService;
import com.yoho.search.dal.model.SearchParam;
import com.yoho.search.dal.model.SearchResult;
import com.yoho.search.utils.ISearchConstans;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.elasticsearch.index.query.BoolFilterBuilder;
import org.elasticsearch.index.query.FilterBuilders;
... ... @@ -15,10 +16,10 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import com.yoho.search.dal.model.SearchParam;
import com.yoho.search.dal.model.SearchResult;
import com.yoho.search.index.service.IndexService;
import com.yoho.search.utils.ISearchConstans;
/**
* Created by zhuzhu on 15-11-19.
... ... @@ -98,7 +99,7 @@ public class TblProductService extends SearchBaseService {
return jsonMap;
}
private Map buildFilterResult(Map<String, Aggregation> aggregationMap) {
private Map<String, Object> buildFilterResult(Map<String, Aggregation> aggregationMap) {
Map<String, Object> map = new HashMap<String, Object>();
String key;
String field;
... ...