Commit b7368bcb by xub

sku维度部分商品刷选

parent f6a70f9b
......@@ -4,23 +4,23 @@ import com.alibaba.fastjson.JSONObject;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.commons.util.EntityUtil;
import com.gic.commons.webapi.reponse.RestResponse;
import com.gic.goods.api.dto.ErrorCode;
import com.gic.goods.api.dto.GoodsTagDTO;
import com.gic.goods.api.service.TagApiService;
import com.gic.plug.web.vo.goods.GoodsTagVO;
import com.gic.goods.api.dto.GoodsSkuDTO;
import com.gic.goods.api.service.GoodsApiService;
import com.gic.plug.web.vo.goods.GoodsVO;
import com.gic.search.business.api.dto.DynamicSearchDTO;
import com.gic.search.business.api.dto.ESResponseQueryBatchDTO;
import com.gic.search.business.api.service.EsBusinessManageApiService;
import com.gic.search.business.api.service.EsBusinessOperaApiService;
import com.gic.search.business.api.utils.NewNodeAddUtil;
import com.gic.widget.screening.api.service.EsScreeningSearchService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.curator.shaded.com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @ClassName: GoodsTagController
......@@ -37,14 +37,72 @@ public class GoodsController {
@Autowired
private EsScreeningSearchService esScreeningSearchService;
@Autowired
private GoodsApiService goodsApiService;
/**
* @Description: 查询所有(不分页)
* @author xub
*/
@GetMapping("list-goods")
public RestResponse findList(@RequestParam(value = "currentPage", defaultValue = "1") Integer currentPage,
@RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize, Long goodsDomainId,String goodsCode) {
public RestResponse ListGoods(@RequestParam(value = "currentPage", defaultValue = "1") Integer currentPage,
@RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize, Long goodsDomainId,String search) {
ServiceResponse<ESResponseQueryBatchDTO> serviceResponse = searchES(currentPage,pageSize,goodsDomainId,search);
if (serviceResponse.isSuccess()) {
return RestResponse.success(serviceResponse.getResult());
}
return RestResponse.failure(serviceResponse.getCode(), serviceResponse.getMessage());
}
/**
* @Description: 查询所有(不分页)
* @author xub
*/
@GetMapping("list-sku")
public RestResponse ListSku(@RequestParam(value = "currentPage", defaultValue = "1") Integer currentPage,
@RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize, Long goodsDomainId,String search) {
ServiceResponse<ESResponseQueryBatchDTO> serviceResponse = searchES(currentPage,pageSize,goodsDomainId,search);
if (!serviceResponse.isSuccess()) {
return RestResponse.failure(serviceResponse.getCode(), serviceResponse.getMessage());
}
//商品信息
List<JSONObject> list = serviceResponse.getResult().getRes();
if (CollectionUtils.isEmpty(list)) {
return RestResponse.success(serviceResponse.getResult());
}
//1、获取商品信息
List<GoodsVO> goodsVOS = Lists.newArrayList();
for (JSONObject jsonObject : list) {
GoodsVO goodsVO = JSONObject.toJavaObject(jsonObject, GoodsVO.class);
goodsVOS.add(goodsVO);
}
//2、获取商品ID信息
List<Long> goodsIds = goodsVOS.stream().mapToLong(GoodsVO::getGoodsId).boxed().collect(Collectors.toList());
ServiceResponse<List<GoodsSkuDTO>> skuResponse = goodsApiService.listSkuByGoods(goodsIds);
if (!skuResponse.isSuccess()) {
return RestResponse.failure(skuResponse.getCode(), skuResponse.getMessage());
}
//3、获取sku信息 同时存储在map中
List<GoodsSkuDTO> skuDTOList = skuResponse.getResult();
if (CollectionUtils.isEmpty(skuDTOList)) {
return RestResponse.success(serviceResponse.getResult());
}
Map<Long, List<GoodsSkuDTO>> goodsIdAndskuDto = skuDTOList.stream().collect(Collectors.groupingBy(GoodsSkuDTO::getGoodsId));
//4、商品信息中包含是sku信息
for (GoodsVO goodsVO : goodsVOS) {
if (goodsIdAndskuDto.containsKey(goodsVO.getGoodsId())) {
List<GoodsVO.SkuVO> skuVOList = EntityUtil.changeEntityListByOrika(GoodsVO.SkuVO.class,goodsIdAndskuDto.get(goodsVO.getGoodsId()));
goodsVO.setSkuVOList(skuVOList);
}
}
return RestResponse.success(goodsVOS);
}
private ServiceResponse<ESResponseQueryBatchDTO> searchES( Integer currentPage,Integer pageSize, Long goodsDomainId,String search) {
DynamicSearchDTO searchDTO = new DynamicSearchDTO();
String esName = esScreeningSearchService.getCurrentEsName("goods-test-123456", "goods-search");
searchDTO.setIndexName(esName);
......@@ -54,13 +112,10 @@ public class GoodsController {
searchDTO.setBegin(currentPage);
searchDTO.setRecordNumber(pageSize);
JSONObject jsonObject = new JSONObject();
jsonObject.put("goodsCode", goodsCode);
jsonObject.put("goodsCode", search);
jsonObject.put("goodsDomainId", goodsDomainId);
searchDTO.setSearchJson(jsonObject);
ServiceResponse<ESResponseQueryBatchDTO> serviceResponse = esBusinessOperaApiService.queryDataBatch(searchDTO, false, null);
if (serviceResponse.isSuccess()) {
return RestResponse.success(serviceResponse.getResult());
}
return RestResponse.failure(serviceResponse.getCode(), serviceResponse.getMessage());
return serviceResponse;
}
}
package com.gic.plug.web.vo.goods;
import java.util.List;
/**
* @author xub
* @ClassName: GoodsSkuDTO
* @Description: sku部分商品查询
* @date 2019/9/16 下午2:01
*/
public class GoodsVO {
/**
* 商品ID
*/
private Long goodsId;
/**
* 商品名称
*/
private String goodsName;
/**
* 域ID
*/
private Long goodsDomainId;
/**
* 货号
*/
private String goodsCode;
/**
* SKU 信息
*/
private List<SkuVO> skuVOList;
public Long getGoodsId() {
return goodsId;
}
public void setGoodsId(Long goodsId) {
this.goodsId = goodsId;
}
public String getGoodsName() {
return goodsName;
}
public void setGoodsName(String goodsName) {
this.goodsName = goodsName;
}
public Long getGoodsDomainId() {
return goodsDomainId;
}
public void setGoodsDomainId(Long goodsDomainId) {
this.goodsDomainId = goodsDomainId;
}
public String getGoodsCode() {
return goodsCode;
}
public void setGoodsCode(String goodsCode) {
this.goodsCode = goodsCode;
}
public List<SkuVO> getSkuVOList() {
return skuVOList;
}
public void setSkuVOList(List<SkuVO> skuVOList) {
this.skuVOList = skuVOList;
}
public static class SkuVO {
/**
* ID
*/
private Long goodsSkuId;
/**
* sku数据
*/
private String goodsSkuInfo;
/**
* code
*/
private String goodsSkuCode;
public Long getGoodsSkuId() {
return goodsSkuId;
}
public void setGoodsSkuId(Long goodsSkuId) {
this.goodsSkuId = goodsSkuId;
}
public String getGoodsSkuInfo() {
return goodsSkuInfo;
}
public void setGoodsSkuInfo(String goodsSkuInfo) {
this.goodsSkuInfo = goodsSkuInfo;
}
public String getGoodsSkuCode() {
return goodsSkuCode;
}
public void setGoodsSkuCode(String goodsSkuCode) {
this.goodsSkuCode = goodsSkuCode;
}
}
}
\ No newline at end of file
......@@ -42,8 +42,9 @@
<dubbo:reference interface="com.gic.goods.api.service.PropertyApiService" id="propertyApiService" timeout="60000" retries="0" />
<dubbo:reference interface="com.gic.goods.api.service.BrandApiService" id="brandApiService" timeout="60000" retries="0" />
<!-- -->
<dubbo:reference id="tagApiService" interface="com.gic.goods.api.service.TagApiService" timeout="60000" retries="0" check="false"/>
<dubbo:reference id="tagApiService" interface="com.gic.goods.api.service.TagApiService" timeout="60000" retries="0" check="false" />
<dubbo:reference id="cordApiService" interface="com.gic.goods.api.service.CordApiService" timeout="60000" retries="0" check="false"/>
<dubbo:reference id="goodsApiService" interface="com.gic.goods.api.service.GoodsApiService" timeout="60000" retries="0" check="false"/>
<dubbo:reference interface="com.gic.search.business.api.service.EsBusinessOperaApiService" id="esBusinessOperaApiService" timeout="60000" retries="0" />
......
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