Commit b11a0192 authored by zhangyong's avatar zhangyong

1

parent 0dc47a17
......@@ -13,6 +13,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.fastjson.JSONObject;
import com.egolm.common.GsonUtil;
import com.egolm.common.StringUtil;
import com.egolm.common.bean.Rjx;
import com.egolm.common.jdbc.Page;
......@@ -147,29 +148,26 @@ public class GoodsController {
return Rjx.jsonOk().set("list", listMap).set("page",page).toJson();
}
@ApiOperation("统一搜索(未完成,要弄搜索引擎)")
@ApiOperation("统一搜索(支持品牌,分类,关键字,仓库等)")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name = "orgNO", dataType = "String", required = true, value = "区域编号", defaultValue = "SHBS"),
@ApiImplicitParam(paramType = "query", name = "shopNO", dataType = "String", required = false, value = "店铺编号", defaultValue = "00029997"),
@ApiImplicitParam(paramType = "query", name = "queryStr", dataType = "String", required = false, value = "搜索内容()", defaultValue = "%"),
@ApiImplicitParam(paramType = "query", name = "index", dataType = "String", required = false, value = "第几页", defaultValue = "1"),
@ApiImplicitParam(paramType = "query", name = "limit", dataType = "String", required = false, value = "每页数量", defaultValue = "20"),
@ApiImplicitParam(paramType = "query", name = "langID", dataType = "String", required = false, value = "语言", defaultValue = "936"),
@ApiImplicitParam(paramType = "query", dataType = "String", required = true, value = "JSON参数", defaultValue = "{\"topCategoryNO\":\"01\",\"upCategoryNO\":\"\",\"categoryID\":[\"\"],\"brandID\":[\"\"],\"agentID\":\"\",\"warehouseNO\":\"\",\"scopeTypeID\":\"1\",\"districtID\":\"\",\"keyword\":\"*\",\"index\":1,\"userNO\":\"00034\",\"shopNO\":\"167728271\"}"),
})
@RequestMapping(value = "/searchGoods",method=RequestMethod.GET)
@RequestMapping(value = "/searchGoods",method=RequestMethod.POST)
public String searchGoods(HttpServletRequest request, HttpServletResponse response) {
List<Map<String,Object>> listMap;
Map<String,Object> params=new HashMap<>();
params.put("orgNO", request.getParameter("orgNO"));
params.put("shopNO", request.getParameter("shopNO")==null?"":request.getParameter("shopNO"));
params.put("queryStr", request.getParameter("queryStr")==null?"%":request.getParameter("queryStr"));
Page page=new Page();
page.setIndex(Long.valueOf(request.getParameter("index")==null?"1":request.getParameter("index")));
page.setLimit(Long.valueOf(request.getParameter("limit")==null?"10":request.getParameter("limit")));
page.setLimitKey("GoodsID desc");
listMap=goodsService.GetCategoryGoods(params,page);
return Rjx.jsonOk().set("list", listMap).set("page",page).toJson();
String reqJson = ServletUtil.readReqJson(request);
System.out.println("searchGoods-------"+reqJson);
Map<String, Object> argsMap = new HashMap<String,Object>();
try {
argsMap = GsonUtil.toMap(reqJson);
if(!argsMap.containsKey("index") || !argsMap.containsKey("limit") || !argsMap.containsKey("userNO") || !argsMap.containsKey("shopNO") || !argsMap.containsKey("orgNO")) {
return Rjx.jsonErr().setCode(-100).setMessage("参数缺失").set("errorMsg", "index,limit,userNO,shopNO,orgNO为必填项").toJson();
}
} catch (Exception e) {
e.printStackTrace();
return Rjx.jsonErr().setCode(-100).setMessage("查询参数格式错误").toJson();
}
return goodsService.searchGoods(argsMap);
}
......
......@@ -14,7 +14,7 @@ public interface GoodsService {
public List<Map<String,Object>> GetCategoryGoods (Map<String,Object> map, Page page);
List<Map<String, Object>> searchGoods(Map<String, Object> map, Page page);
String searchGoods(Map<String, Object> map);
List<Map<String, Object>> hotSearchKey(Map<String, Object> map, Page page);
......
package com.egolm.shop.service.impl;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
......@@ -14,6 +16,7 @@ import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSONObject;
import com.egolm.common.DateUtil;
import com.egolm.common.StringUtil;
import com.egolm.common.Util;
import com.egolm.common.bean.Rjx;
import com.egolm.common.jdbc.JdbcTemplate;
import com.egolm.common.jdbc.Page;
......@@ -22,6 +25,7 @@ import com.egolm.shop.pojo.TCustomer;
import com.egolm.shop.pojo.TShop;
import com.egolm.shop.service.CommonService;
import com.egolm.shop.service.GoodsService;
import com.egolm.shop.service.SolrGoodsService;
import com.egolm.shop.service.UserService;
import com.egolm.shop.util.ShopContstrant;
@Service
......@@ -35,8 +39,9 @@ public class GoodsServiceImpl implements GoodsService {
@Autowired
private CommonService commonService;
@Autowired
private SolrGoodsService solrGoodsService;
/**
* 获取当前用户历史购买的商品同分类(三级)下的三个月内购买数量最多的商品Top 20,
* 未登录时获取当前区域三个月内购买数量最多的商品Top 20
......@@ -166,24 +171,200 @@ public class GoodsServiceImpl implements GoodsService {
}
/**
* 搜索
* 统一搜索
* <p>Title: searchGoods</p>
* <p>Description: </p>
* @param map
* @param page
* @return
* @see com.egolm.shop.service.GoodsService#searchGoods(java.util.Map, com.egolm.common.jdbc.Page)
* {"topCategoryNO":"01","upCategoryNO":"","categoryID":[""],"brandID":[""],"agentID":"","warehouseNO":"","scopeTypeID":"1","districtID":"","keyword":"*","index":1,"limit":10,"userNO":"00034","orgNO":"XIAN","shopNO":"167728271"}
*/
@Override
public List<Map<String, Object>> searchGoods(Map<String, Object> map, Page page) {
String orgNO=(String) map.get("orgNO");
String shopNO=(String) map.get("shopNO");
String queryStr=(String) map.get("queryStr");
String sql=" ";
jdbcTemplate.setDialect(new SqlServerDialect());
return jdbcTemplate.limit(sql,page);
public String searchGoods(Map<String, Object> map) {
try {
String userNO=(String) map.get("userNO");
String orgNO=(String) map.get("orgNO");
String shopNO=(String) map.get("shopNO");
List<String> queryParams=new ArrayList<String>(); //搜索引擎查询参数
String districtID = ""; //店铺区域
if(StringUtil.isNotBlank(map.get("districtID"))) {
districtID = map.get("districtID")+"";
}
if(StringUtil.isEmpty(districtID)){
TCustomer customer = userService.getCustomer(userNO, shopNO);
if(customer != null && customer.getTshops() != null && customer.getTshops().size()>0) {
TShop tshop = customer.getTshops().get(0);
districtID = tshop.getsDistrictID();
}
}
queryParams.add("sDistrictID:"+districtID);
Page page = new Page();
page.setIndex(Util.objTo(map.get("index"), Long .class));
page.setLimit(Util.objTo(map.get("limit"), Long.class));
page.setLimitKey(" nGoodsID");
//分类
if(StringUtil.isNotBlank(map.get("categoryID"))){
//支持多分类筛选
List <String> cList=(List<String>) map.get("categoryID");
if(cList.size()>0){
String distractCategory="";
for(String category :cList){
if(StringUtil.isNotBlank(category)){
distractCategory +="sCategoryNO:"+category+" OR ";
}
}
if(distractCategory.length()>3){
queryParams.add(distractCategory.substring(0, distractCategory.length()-3));
}
}
}
//品牌
if(StringUtil.isNotBlank(map.get("brandID"))){
//支持多品牌筛选
List <String> bList=(List<String>) map.get("brandID");
if(bList.size()>0){
String distractBrand="";
for(String brand :bList){
if(StringUtil.isNotBlank(brand)){
distractBrand +="sBrandID:"+brand+" OR ";
}
}
if(distractBrand.length()>3){
queryParams.add(distractBrand.substring(0, distractBrand.length()-3));
}
}
}
if(StringUtil.isNotBlank(map.get("agentID"))){
queryParams.add("nAgentID:"+map.get("agentID"));
}
if(StringUtil.isNotEmpty(map.get("warehouseNO"))){
queryParams.add("sWarehouseNO:"+map.get("warehouseNO"));
}
if(StringUtil.isNotEmpty(map.get("scopeTypeID"))){
queryParams.add("sScopeTypeID:"+map.get("scopeTypeID"));
}
if(StringUtil.isNotEmpty(map.get("upCategoryDesc"))){
queryParams.add("sUpCategoryDesc:"+map.get("upCategoryDesc"));
}
if(StringUtil.isNotEmpty(map.get("topCategoryDesc"))){
queryParams.add("sTopCategoryDesc:"+map.get("topCategoryDesc"));
}
if(StringUtil.isNotEmpty(map.get("upCategoryNO"))){
queryParams.add("sUpCategoryNO:"+map.get("upCategoryNO"));
}
if(StringUtil.isNotEmpty(map.get("topCategoryNO"))){
queryParams.add("sTopCategoryNO:"+map.get("topCategoryNO"));
}
//查询礼品
if(StringUtil.isNotEmpty(map.get("tag"))&&512==Util.objTo(map.get("tag"),Integer.class)){
queryParams.add("nGoodsTypeID:1");
queryParams.add("sOrgNO:china");
}else{
queryParams.add("sOrgNO:"+orgNO+" OR sOrgNO:china");
}
//搜索,全场商品,分类商品,品牌商品,只显示已上架的
queryParams.add("nOnShelves:1");
//精选商品
if(StringUtil.isNotEmpty(map.get("choiceness"))){
queryParams.add("nChoiceness:"+map.get("choiceness"));
}
String key = (String)map.get("keyword");
key = StringUtil.isBlank(key) ? "*" : key;
if(!"*".equals(key)){
try{
insertSearchLog(key, "",""+map.get("shopNO"));
}catch(Exception e){
e.printStackTrace();
}
}
String orderKey = (String)map.get("orderBy");
String orderSc = (String)map.get("orderbyparms");
orderSc = orderSc == null ? "DESC" : orderSc;
List<String> queryOrders = new ArrayList<String>();
if(StringUtil.isBlank(orderKey)) {
if(key.equals("*")) {
queryOrders.add("nStockQty:DESC");
queryOrders.add("sBrandID:ASC");
queryOrders.add("sGoodsDesc:ASC");
}
} else {
if(orderKey.equals("choiceness")) {
queryOrders.add("nChoiceness:DESC");
}
if(orderKey.equals("time")) {
queryOrders.add("dCreateDate:" + orderSc);
} else if(orderKey.equals("price")) {
queryOrders.add("nRealSalePrice:" + orderSc);
} else if(orderKey.equals("sale")) {
queryOrders.add("nTotalSaleQty:" + orderSc);
}
}
String[] paramsArray = queryParams.toArray(new String[queryParams.size()]);
String[] groupByArray = new String[]{"sCategoryDesc", "sTopCategoryDesc", "sUpCategoryDesc","sBrand","sAgentName","sWarehouseName"};
String[] facetPivotFields = new String[]{"sCategoryNO,sCategoryDesc", "sUpCategoryNO,sUpCategoryDesc", "sTopCategoryNO,sTopCategoryDesc", "sBrandID,sBrand", "nAgentID,sAgentName", "sWarehouseNO,sWarehouseName"};
logger.info("商品检索:" + Rjx.json().set("page", page).set("queryKey", key).set("keywords", paramsArray).set("groupsNames", groupByArray));
Map<String,Object> goodsReturnMap=(Map<String, Object>) solrGoodsService.query(page, key, paramsArray, groupByArray, facetPivotFields);
List<Map<String,Object>> goodsList=(List<Map<String, Object>>) goodsReturnMap.get("datas");
Map<String,Object> group=(Map<String, Object>) goodsReturnMap.get("groups");
List<String> goodsBrandList=(List<String>)group.get("sBrand");
List<String>goodsCategoryList=(List<String>) group.get("sCategoryDesc");
List<String>upCategoryList=(List<String>) group.get("sUpCategoryDesc");
List<String>topCategoryList=(List<String>) group.get("sTopCategoryDesc");
List<String> goodsAgentList=(List<String>) group.get("sAgentName");
List<String> goodsHouseList=(List<String>) group.get("sWarehouseName");
if(goodsBrandList == null) {
goodsBrandList = new ArrayList<String>();
}
if(goodsCategoryList == null) {
goodsCategoryList = new ArrayList<String>();
}
if(upCategoryList == null) {
upCategoryList = new ArrayList<String>();
}
if(topCategoryList == null) {
topCategoryList = new ArrayList<String>();
}
if(goodsAgentList == null) {
goodsAgentList = new ArrayList<String>();
}
if(goodsHouseList == null) {
goodsHouseList = new ArrayList<String>();
}
Collections.sort(goodsBrandList);
Util.replaceKey(goodsList, ":", true,"nGoodsID:goodsID","sGoodsName:goodsName","sGoodsDesc:goodsDesc","sAgentName:agentName","sAgentContractNO:contractNO","sCategoryDesc:categoryName","sCategoryNO:categoryID","sBrand:brandName","sBrandID:brandID","sMainBarcode:barcode","sSpec:spec","nMinSaleQty:minSaleQty","nSaleUnits:saleUnits","sUnit:agentUnit","sURL:imgPath","nAgentID:agentID","nRetailPrice:normalSalePrice","sRetailPriceUnit:goodsUnit","sWarehouseNO:warehouseNO","sWarehouseName:warehouseName","nCaseUnits:caseUnits");
Rjx rjx = Rjx.jsonOk();
rjx.set("goodsList",goodsList);
rjx.set("page", goodsReturnMap.get("page"));
rjx.set("brandList",goodsBrandList);
rjx.set("categoryList", goodsCategoryList );
rjx.set("upCategoryList", upCategoryList );
rjx.set("topCategoryList", topCategoryList );
rjx.set("agentList",goodsAgentList);
rjx.set("warehouseList", goodsHouseList);
rjx.set("g", goodsReturnMap.get("pivots"));
return rjx.toJson();
} catch (Exception e) {
e.printStackTrace();
}
return Rjx.jsonErr().setCode(-100).setMessage("搜索失败").toJson();
}
......@@ -326,4 +507,10 @@ public class GoodsServiceImpl implements GoodsService {
}
return Rjx.jsonErr().setCode(-1).setMessage("操作失败").toJson();
}
private void insertSearchLog(String key, String typeID, String ShopNO){
String sql = "insert into tShopSearchLog (sShopNO, sKeyword, sOriginalKeyWord, sTypeID, dLastUpdateTime) values (?, ?, ?, ?, ?)";
jdbcTemplate.update(sql, new Object[]{ShopNO, key, key, typeID, new Date()});
}
}
......@@ -67,6 +67,7 @@ public class SolrGoodsServiceImpl implements SolrGoodsService {
String[] limitKeys = page.getLimitKey();
if(limitKeys != null) {
for(String key : limitKeys) {
System.out.println("key---"+key);
String[] kv = key.split(" ", 2);
ORDER sc = kv[1] == null || kv[1].trim().length() == 0 || kv[1].equalsIgnoreCase("asc") ? ORDER.asc : ORDER.desc;
solrQuery.addSort(kv[0], sc);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment