Commit 5da4e654 authored by Quxl's avatar Quxl

x

parent 92fc93cf
......@@ -12,12 +12,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
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;
import com.egolm.common.web.ServletUtil;
import com.egolm.shop.config.XException;
import com.egolm.shop.service.GoodsService;
import com.egolm.shop.util.I18NUtils;
......@@ -162,37 +159,6 @@ public class GoodsController {
return Rjx.jsonOk().set("list", listMap).set("page",page).toJson();
}
@ApiOperation("统一搜索(支持品牌,分类,关键字,仓库等)")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name = "data", dataType = "String", required = true, value = "JSON参数", defaultValue = "{\"topCategoryNO\":\"01\",\"upCategoryNO\":\"\",\"categoryID\":[\"\"],\"brandID\":[\"\"],\"agentID\":\"\",\"warehouseNO\":\"\",\"scopeTypeID\":\"1\",\"districtID\":\"\",\"keyword\":\"*\",\"index\":1,\"limit\":10,\"userNO\":\"00034\",\"orgNO\":\"XIAN\",\"shopNO\":\"167728271\"}"),
@ApiImplicitParam(paramType = "query", name = "terminal", dataType = "String", required = true, value = "终端标识", defaultValue = "wechat"),
@ApiImplicitParam(paramType = "query", name = "langID", dataType = "String", required = true, value = "语言", defaultValue = "936"),
@ApiImplicitParam(paramType = "query", name = "sign", dataType = "String", required = true, value = "签名", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "timestamp", dataType = "String", required = true, value = "时间戳", defaultValue = "")
})
@RequestMapping(value = "/searchGoods",method=RequestMethod.POST)
public String searchGoods(HttpServletRequest request, HttpServletResponse response) {
String reqJson = request.getParameter("data");
System.out.println("searchGoods-------"+reqJson);
Map<String, Object> argsMap = new HashMap<String,Object>();
argsMap = GsonUtil.toMap(reqJson);
String langID = request.getParameter("langID");
argsMap.put("langID", langID);
try {
if(!argsMap.containsKey("index") || !argsMap.containsKey("limit") || !argsMap.containsKey("userNO") || !argsMap.containsKey("shopNO") || !argsMap.containsKey("orgNO") ) {
return Rjx.jsonErr().setCode(-100).setMessage(I18NUtils.getMessage(langID, "Msg_Parameter_empty")).set("errorMsg", "index,limit,userNO,shopNO,orgNO " +I18NUtils.getMessage(langID, "Msg_Must_enter")).toJson();
}
} catch (Exception e) {
e.printStackTrace();
return Rjx.jsonErr().setCode(-100).setMessage(I18NUtils.getMessage(langID, "Msg_QueryParam_error")).toJson();
}
return goodsService.searchGoods(argsMap);
}
@ApiOperation("商品详情")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name = "orgNo", dataType = "String", required = true),
......
package com.egolm.shop.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.egolm.common.bean.Rjx;
import com.egolm.common.jdbc.Page;
import com.egolm.shop.service.SolrGoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
@Api(tags={"搜索引擎商品相关接口"})
@Controller
@RequestMapping("solr/goods")
public class SolrGoodsController {
@Autowired
private SolrGoodsService service;
@Autowired
@Qualifier("redisTemplate")
private RedisTemplate<String, ?> redisTemplate;
@ResponseBody
@PostMapping("query")
@ApiOperation("搜索引擎商品搜索")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", dataType="long", allowMultiple=false, required=true, name="index", value="分页编号"),
@ApiImplicitParam(paramType = "query", dataType="long", allowMultiple=false, required=true, name="limit", value="分页大小"),
@ApiImplicitParam(paramType = "query", dataType="string", allowMultiple=false, required=true, name="queryKey", value="搜索关键字"),
@ApiImplicitParam(paramType = "query", dataType="string", allowMultiple=true, required=true, name="orders", value="排序关键字"),
@ApiImplicitParam(paramType = "query", dataType="string", allowMultiple=true, required=true, name="keywords", value="精确搜索条件"),
@ApiImplicitParam(paramType = "query", dataType="string", allowMultiple=true, required=true, name="facetFields", value="单字段分组字段"),
@ApiImplicitParam(paramType = "query", dataType="string", allowMultiple=true, required=true, name="facetPivotFields", value="多字段分组字段"),
@ApiImplicitParam(paramType = "query", name = "sign", dataType = "String", required = true, value = "签名", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "timestamp", dataType = "String", required = true, value = "时间戳", defaultValue = "")
})
public Object query(Long index, Long limit, String queryKey, String[] orders, String[] keywords, String[] facetFields, String[] facetPivotFields) {
Page page = new Page(index, limit, orders);
return service.query(page, queryKey, keywords, facetFields, facetPivotFields);
}
@ResponseBody
@PostMapping("updateByDistrictID")
@ApiOperation("搜索引擎按区域编号更新商品索引")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", dataType="string", allowMultiple=false, required=true, name="sDistrictID", value="区域编号"),
@ApiImplicitParam(paramType = "query", name = "sign", dataType = "String", required = true, value = "签名", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "timestamp", dataType = "String", required = true, value = "时间戳", defaultValue = "")
})
public Object updateByDistrictID(String sDistrictID) {
service.update(sDistrictID);
return Rjx.jsonOk();
}
@ResponseBody
@PostMapping("update")
@Scheduled(cron="0 0 4 * * ?")
@ApiOperation("搜索引擎更新全部商品索引")
public Object update() {
if(this.getLock().getCode() == 200) {
try {
service.update(null);
return Rjx.jsonOk();
} finally {
this.releaseLock();
}
} else {
return Rjx.jsonErr().setMessage("该任务正在运行,请不要重复执行");
}
}
public static final String SCHEDULE_LOCK_KEY = "SCHEDULE_LOCK_KEY";
public static Long SCHEDULE_LOCK_EXPIRE = 1000L*60*60;
@ResponseBody
@PostMapping("getLock")
@ApiOperation("设置搜索引擎更新索引定时任务分布式互斥锁")
public Rjx getLock() {
/*String result = redisTemplate.execute(new RedisCallback<String>() {
@Override
public String doInRedis(RedisConnection connection) throws DataAccessException {
JedisCommands commands = (JedisCommands) connection.getNativeConnection();
String uuid = UUID.randomUUID().toString();
return commands.set(SCHEDULE_LOCK_KEY, uuid, "NX", "PX", SCHEDULE_LOCK_EXPIRE);
}
});
if(result != null && result.equals("OK")) {
return Rjx.jsonOk();
} else {
return Rjx.jsonErr();
}*/
return Rjx.jsonOk().setMessage("这个注释掉了");
}
@ResponseBody
@PostMapping("releaseLock")
@ApiOperation("删除搜索引擎更新索引定时任务分布式互斥锁")
public Rjx releaseLock() {
redisTemplate.delete(SCHEDULE_LOCK_KEY);
return Rjx.jsonOk();
}
}
......@@ -14,8 +14,6 @@ public interface GoodsService {
public List<Map<String,Object>> GetCategoryGoods (Map<String,Object> map, Page page);
String searchGoods(Map<String, Object> map);
List<Map<String, Object>> hotSearchKey(Map<String, Object> map, Page page);
String goodsDetail(Map<String, Object> map);
......
package com.egolm.shop.service;
import com.egolm.common.bean.Rjx;
import com.egolm.common.jdbc.Page;
public interface SolrGoodsService {
public Rjx query(Page page, String queryKey, String[] keywords, String[] facetFields, String[] facetPivotFields);
public void update(String sDistrictID);
public void deleteByQuery(String queryKey);
public void deleteById(String[] documentIds);
}
......@@ -3,7 +3,6 @@ package com.egolm.shop.service.impl;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
......@@ -27,7 +26,6 @@ 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.I18NUtils;
@Service
......@@ -41,9 +39,6 @@ public class GoodsServiceImpl implements GoodsService {
@Autowired
private CommonService commonService;
@Autowired
private SolrGoodsService solrGoodsService;
/**
* 获取当前用户历史购买的商品同分类(三级)下的三个月内购买数量最多的商品Top 20,
* 未登录时获取当前区域三个月内购买数量最多的商品Top 20
......@@ -159,205 +154,6 @@ public class GoodsServiceImpl implements GoodsService {
return jdbcTemplate.limit(sql,page);
}
/**
* 统一搜索
* <p>Title: searchGoods</p>
* <p>Description: </p>
* @param map
* @param page
* @return
* {"topCategoryNO":"01","upCategoryNO":"","categoryID":[""],"brandID":[""],"agentID":"","warehouseNO":"","scopeTypeID":"1","districtID":"","keyword":"*","index":1,"limit":10,"userNO":"00034","orgNO":"XIAN","shopNO":"167728271"}
*/
@Override
public String searchGoods(Map<String, Object> map) {
String langID= (String) map.get("langID");
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 desc");
//分类
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(I18NUtils.getMessage(langID, "Msg_Search_failure")).toJson();
}
/**
* 商品详情
* <p>Title: goodsDetail</p>
......
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