|
@@ -18,18 +18,17 @@ import com.slodon.b2b2c.dao.read.goods.*;
|
|
import com.slodon.b2b2c.dao.read.member.MemberFollowProductReadMapper;
|
|
import com.slodon.b2b2c.dao.read.member.MemberFollowProductReadMapper;
|
|
import com.slodon.b2b2c.dao.read.seller.StoreInnerLabelReadMapper;
|
|
import com.slodon.b2b2c.dao.read.seller.StoreInnerLabelReadMapper;
|
|
import com.slodon.b2b2c.dao.read.seller.StoreLabelBindGoodsReadMapper;
|
|
import com.slodon.b2b2c.dao.read.seller.StoreLabelBindGoodsReadMapper;
|
|
|
|
+import com.slodon.b2b2c.enums.WebSiteConstant;
|
|
import com.slodon.b2b2c.goods.dto.GoodsRankListDTO;
|
|
import com.slodon.b2b2c.goods.dto.GoodsRankListDTO;
|
|
import com.slodon.b2b2c.goods.dto.SearchConditionDTO;
|
|
import com.slodon.b2b2c.goods.dto.SearchConditionDTO;
|
|
-import com.slodon.b2b2c.goods.example.GoodsBindAttributeValueExample;
|
|
|
|
-import com.slodon.b2b2c.goods.example.GoodsBindRankExample;
|
|
|
|
-import com.slodon.b2b2c.goods.example.GoodsExample;
|
|
|
|
-import com.slodon.b2b2c.goods.example.GoodsPromotionExample;
|
|
|
|
|
|
+import com.slodon.b2b2c.goods.example.*;
|
|
import com.slodon.b2b2c.goods.pojo.*;
|
|
import com.slodon.b2b2c.goods.pojo.*;
|
|
import com.slodon.b2b2c.member.example.MemberFollowProductExample;
|
|
import com.slodon.b2b2c.member.example.MemberFollowProductExample;
|
|
import com.slodon.b2b2c.member.pojo.Member;
|
|
import com.slodon.b2b2c.member.pojo.Member;
|
|
import com.slodon.b2b2c.member.pojo.MemberFollowProduct;
|
|
import com.slodon.b2b2c.member.pojo.MemberFollowProduct;
|
|
import com.slodon.b2b2c.model.promotion.PromotionCommonModel;
|
|
import com.slodon.b2b2c.model.promotion.PromotionCommonModel;
|
|
import com.slodon.b2b2c.model.system.SettingModel;
|
|
import com.slodon.b2b2c.model.system.SettingModel;
|
|
|
|
+import com.slodon.b2b2c.seller.example.StoreInnerLabelExample;
|
|
import com.slodon.b2b2c.seller.example.StoreLabelBindGoodsExample;
|
|
import com.slodon.b2b2c.seller.example.StoreLabelBindGoodsExample;
|
|
import com.slodon.b2b2c.seller.pojo.StoreInnerLabel;
|
|
import com.slodon.b2b2c.seller.pojo.StoreInnerLabel;
|
|
import com.slodon.b2b2c.seller.pojo.StoreLabelBindGoods;
|
|
import com.slodon.b2b2c.seller.pojo.StoreLabelBindGoods;
|
|
@@ -78,6 +77,7 @@ import javax.annotation.Resource;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
import static com.alibaba.fastjson.serializer.SerializerFeature.MapSortField;
|
|
import static com.alibaba.fastjson.serializer.SerializerFeature.MapSortField;
|
|
import static com.alibaba.fastjson.serializer.SerializerFeature.SortField;
|
|
import static com.alibaba.fastjson.serializer.SerializerFeature.SortField;
|
|
@@ -121,11 +121,15 @@ public class ESGoodsModel {
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
@SneakyThrows
|
|
@SneakyThrows
|
|
- public boolean jobCreateIndexesES(String url, Integer port, String type) {
|
|
|
|
|
|
+ public boolean jobCreateIndexesES(String url, Integer port, String type, String webSite) {
|
|
//es索引上次更新的时间
|
|
//es索引上次更新的时间
|
|
String esIndexUpdateTime = stringRedisTemplate.opsForValue().get("es_index_update_time");
|
|
String esIndexUpdateTime = stringRedisTemplate.opsForValue().get("es_index_update_time");
|
|
|
|
+ if (WebSiteConstant.MEMBER_DISTRIBUTOR.equals(webSite)) {
|
|
|
|
+ esIndexUpdateTime = stringRedisTemplate.opsForValue().get("es_index_update_time" + "_" + webSite);
|
|
|
|
+ }
|
|
|
|
|
|
GoodsExample example = new GoodsExample();
|
|
GoodsExample example = new GoodsExample();
|
|
|
|
+ example.setWebSite(webSite);
|
|
example.setState(GoodsConst.GOODS_STATE_UPPER);
|
|
example.setState(GoodsConst.GOODS_STATE_UPPER);
|
|
if ("job".equals(type)) {
|
|
if ("job".equals(type)) {
|
|
example.setUpdateTimeAfter(TimeUtil.strToDate(esIndexUpdateTime));
|
|
example.setUpdateTimeAfter(TimeUtil.strToDate(esIndexUpdateTime));
|
|
@@ -134,7 +138,7 @@ public class ESGoodsModel {
|
|
|
|
|
|
if (!CollectionUtils.isEmpty(addList)) {
|
|
if (!CollectionUtils.isEmpty(addList)) {
|
|
List<SearchProductDTO> addGoodsList = this.getSearchProductVOs(addList);
|
|
List<SearchProductDTO> addGoodsList = this.getSearchProductVOs(addList);
|
|
- BulkResponse response = this.createIndex(url, port, addGoodsList);
|
|
|
|
|
|
+ BulkResponse response = this.createIndex(url, port, addGoodsList, webSite);
|
|
if (response.hasFailures()) {
|
|
if (response.hasFailures()) {
|
|
//索引插入数据失败
|
|
//索引插入数据失败
|
|
log.error(response.buildFailureMessage());
|
|
log.error(response.buildFailureMessage());
|
|
@@ -144,11 +148,12 @@ public class ESGoodsModel {
|
|
if ("job".equals(type)) {
|
|
if ("job".equals(type)) {
|
|
//下架状态的商品,执行删除索引记录操作
|
|
//下架状态的商品,执行删除索引记录操作
|
|
example.setState(null);
|
|
example.setState(null);
|
|
|
|
+ example.setWebSite(webSite);
|
|
example.setStateNotEquals(GoodsConst.GOODS_STATE_UPPER);
|
|
example.setStateNotEquals(GoodsConst.GOODS_STATE_UPPER);
|
|
//需要删除索引记录的商品列表
|
|
//需要删除索引记录的商品列表
|
|
List<Goods> deleteList = goodsReadMapper.listByExample(example);
|
|
List<Goods> deleteList = goodsReadMapper.listByExample(example);
|
|
if (!CollectionUtils.isEmpty(deleteList)) {
|
|
if (!CollectionUtils.isEmpty(deleteList)) {
|
|
- this.deleteByQuery(url, port, deleteList);
|
|
|
|
|
|
+ this.deleteByQuery(url, port, deleteList, webSite);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -156,10 +161,16 @@ public class ESGoodsModel {
|
|
String updateTime = TimeUtil.getDateTimeString(new Date());
|
|
String updateTime = TimeUtil.getDateTimeString(new Date());
|
|
Setting setting = new Setting();
|
|
Setting setting = new Setting();
|
|
setting.setName("es_index_update_time");
|
|
setting.setName("es_index_update_time");
|
|
|
|
+ if (WebSiteConstant.MEMBER_DISTRIBUTOR.equals(webSite)) {
|
|
|
|
+ setting.setName("es_index_update_time" + "_" + webSite);
|
|
|
|
+ }
|
|
setting.setValue(updateTime);
|
|
setting.setValue(updateTime);
|
|
settingModel.updateSetting(setting);
|
|
settingModel.updateSetting(setting);
|
|
//更新redis里的配置
|
|
//更新redis里的配置
|
|
stringRedisTemplate.opsForValue().set("es_index_update_time", updateTime);
|
|
stringRedisTemplate.opsForValue().set("es_index_update_time", updateTime);
|
|
|
|
+ if (WebSiteConstant.MEMBER_DISTRIBUTOR.equals(webSite)) {
|
|
|
|
+ stringRedisTemplate.opsForValue().set("es_index_update_time" + "_" + webSite, updateTime);
|
|
|
|
+ }
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -172,6 +183,25 @@ public class ESGoodsModel {
|
|
private List<SearchProductDTO> getSearchProductVOs(List<Goods> goodsList) {
|
|
private List<SearchProductDTO> getSearchProductVOs(List<Goods> goodsList) {
|
|
List<SearchProductDTO> searchProductDTOS = new ArrayList<>();
|
|
List<SearchProductDTO> searchProductDTOS = new ArrayList<>();
|
|
SearchProductDTO searchProductDTO;
|
|
SearchProductDTO searchProductDTO;
|
|
|
|
+ GoodsCategoryExample goodsCategoryExample = new GoodsCategoryExample();
|
|
|
|
+ goodsCategoryExample.setGrade(GoodsCategoryConst.CATEGORY_GRADE_3);
|
|
|
|
+ List<GoodsCategory> categoryList = goodsCategoryReadMapper.listByExample(goodsCategoryExample);
|
|
|
|
+ List<GoodsBindAttributeValue> bindAttributeValueListAll = goodsBindAttributeValueReadMapper.listByExample(new GoodsBindAttributeValueExample());
|
|
|
|
+ List<GoodsExtend> goodsExtendList = goodsExtendModel.listByExample(new GoodsExtendExample());
|
|
|
|
+ List<StoreLabelBindGoods> labelBindGoodsListAll = storeLabelBindGoodsReadMapper.listByExample(new StoreLabelBindGoodsExample());
|
|
|
|
+ List<StoreInnerLabel> storeInnerLabelList = storeInnerLabelReadMapper.listByExample(new StoreInnerLabelExample());
|
|
|
|
+ List<GoodsRankListDTO> rankListAll = goodsBindRankReadMapper.getGoodsRankList(new GoodsBindRankExample());
|
|
|
|
+ GoodsPromotionExample promotionExample = new GoodsPromotionExample();
|
|
|
|
+ promotionExample.setIsEffective(PromotionConst.IS_EFFECTIVE_YES);
|
|
|
|
+ promotionExample.setStartTimeBefore(new Date());
|
|
|
|
+ promotionExample.setEndTimeAfter(new Date());
|
|
|
|
+ //一级活动,绑定商品
|
|
|
|
+ promotionExample.setBindType(PromotionConst.BIND_TYPE_1);
|
|
|
|
+ List<GoodsPromotion> listAll = goodsPromotionReadMapper.listByExample(promotionExample);
|
|
|
|
+ promotionExample.setBindType(PromotionConst.BIND_TYPE_2);
|
|
|
|
+ List<GoodsPromotion> secondListAll = goodsPromotionReadMapper.listByExample(promotionExample);
|
|
|
|
+ promotionExample.setBindType(PromotionConst.BIND_TYPE_3);
|
|
|
|
+ List<GoodsPromotion> thirdListAll = goodsPromotionReadMapper.listByExample(promotionExample);
|
|
for (Goods goods : goodsList) {
|
|
for (Goods goods : goodsList) {
|
|
searchProductDTO = new SearchProductDTO();
|
|
searchProductDTO = new SearchProductDTO();
|
|
searchProductDTO.setGoodsId(goods.getGoodsId().toString());
|
|
searchProductDTO.setGoodsId(goods.getGoodsId().toString());
|
|
@@ -187,8 +217,10 @@ public class ESGoodsModel {
|
|
searchProductDTO.setCategoryId3(goods.getCategoryId3().toString());
|
|
searchProductDTO.setCategoryId3(goods.getCategoryId3().toString());
|
|
searchProductDTO.setGoodsMoney(goods.getGoodsMoney());
|
|
searchProductDTO.setGoodsMoney(goods.getGoodsMoney());
|
|
searchProductDTO.setGoodsSummary(goods.getGoodsSummary());
|
|
searchProductDTO.setGoodsSummary(goods.getGoodsSummary());
|
|
- GoodsCategory goodsCategory = goodsCategoryReadMapper.getByPrimaryKey(goods.getCategoryId3());
|
|
|
|
- searchProductDTO.setCategoryName(goodsCategory.getCategoryName());
|
|
|
|
|
|
+ GoodsCategory goodsCategory = categoryList.stream().filter(category -> category.getCategoryId().equals(goods.getCategoryId3())).findFirst().orElse(null);
|
|
|
|
+ if (goodsCategory != null) {
|
|
|
|
+ searchProductDTO.setCategoryName(goodsCategory.getCategoryName());
|
|
|
|
+ }
|
|
searchProductDTO.setContent(goods.getGoodsBrief());
|
|
searchProductDTO.setContent(goods.getGoodsBrief());
|
|
searchProductDTO.setDefaultProductId(goods.getDefaultProductId());
|
|
searchProductDTO.setDefaultProductId(goods.getDefaultProductId());
|
|
|
|
|
|
@@ -199,49 +231,49 @@ public class ESGoodsModel {
|
|
searchProductDTO.setCommentsNumber(goods.getCommentNumber());
|
|
searchProductDTO.setCommentsNumber(goods.getCommentNumber());
|
|
|
|
|
|
//商品的系统属性
|
|
//商品的系统属性
|
|
- GoodsBindAttributeValueExample valueExample = new GoodsBindAttributeValueExample();
|
|
|
|
- valueExample.setGoodsId(goods.getGoodsId());
|
|
|
|
- List<GoodsBindAttributeValue> bindAttributeValueList = goodsBindAttributeValueReadMapper.listByExample(valueExample);
|
|
|
|
|
|
+ List<GoodsBindAttributeValue> bindAttributeValueList = bindAttributeValueListAll.stream().filter(bindAttributeValue -> bindAttributeValue.getGoodsId().equals(goods.getGoodsId())).collect(Collectors.toList());
|
|
if (!CollectionUtils.isEmpty(bindAttributeValueList)) {
|
|
if (!CollectionUtils.isEmpty(bindAttributeValueList)) {
|
|
StringBuffer attributeInfo = new StringBuffer();
|
|
StringBuffer attributeInfo = new StringBuffer();
|
|
bindAttributeValueList.forEach(bindAttributeValue -> {
|
|
bindAttributeValueList.forEach(bindAttributeValue -> {
|
|
attributeInfo.append(" ").append(bindAttributeValue.getAttributeValueId());
|
|
attributeInfo.append(" ").append(bindAttributeValue.getAttributeValueId());
|
|
});
|
|
});
|
|
- searchProductDTO.setAttributeInfo(attributeInfo.toString().substring(1));
|
|
|
|
|
|
+ searchProductDTO.setAttributeInfo(attributeInfo.substring(1));
|
|
}
|
|
}
|
|
|
|
|
|
searchProductDTO.setSalesNum(goods.getVirtualSales() + goods.getActualSales());
|
|
searchProductDTO.setSalesNum(goods.getVirtualSales() + goods.getActualSales());
|
|
//商品扩展信息
|
|
//商品扩展信息
|
|
- GoodsExtend goodsExtend = goodsExtendModel.getGoodsExtendByGoodsId(goods.getGoodsId());
|
|
|
|
- searchProductDTO.setClickNum(goodsExtend.getClickNumber());
|
|
|
|
- searchProductDTO.setFollowNum(goodsExtend.getFollowNumber());
|
|
|
|
|
|
+ GoodsExtend goodsExtend = goodsExtendList.stream().filter(e -> e.getGoodsId().equals(goods.getGoodsId())).findFirst().orElse(null);
|
|
|
|
+ if (goodsExtend != null) {
|
|
|
|
+ searchProductDTO.setClickNum(goodsExtend.getClickNumber());
|
|
|
|
+ searchProductDTO.setFollowNum(goodsExtend.getFollowNumber());
|
|
|
|
+ }
|
|
searchProductDTO.setStoreIsRecommend(goods.getStoreIsRecommend());
|
|
searchProductDTO.setStoreIsRecommend(goods.getStoreIsRecommend());
|
|
searchProductDTO.setIsSelf(goods.getIsSelf());
|
|
searchProductDTO.setIsSelf(goods.getIsSelf());
|
|
|
|
|
|
|
|
|
|
//查询店铺分类绑定商品表
|
|
//查询店铺分类绑定商品表
|
|
- StoreLabelBindGoodsExample bindGoodsExample = new StoreLabelBindGoodsExample();
|
|
|
|
- bindGoodsExample.setGoodsId(goods.getGoodsId());
|
|
|
|
- List<StoreLabelBindGoods> labelBindGoodsList = storeLabelBindGoodsReadMapper.listByExample(bindGoodsExample);
|
|
|
|
|
|
+ List<StoreLabelBindGoods> labelBindGoodsList = labelBindGoodsListAll.stream().filter(bindGoods -> bindGoods.getGoodsId().equals(goods.getGoodsId())).collect(Collectors.toList());
|
|
if (!CollectionUtils.isEmpty(labelBindGoodsList)) {
|
|
if (!CollectionUtils.isEmpty(labelBindGoodsList)) {
|
|
//商家内部一级分类ID
|
|
//商家内部一级分类ID
|
|
StringBuilder storeInnerLabelId1 = new StringBuilder();
|
|
StringBuilder storeInnerLabelId1 = new StringBuilder();
|
|
//商家内部二级分类ID
|
|
//商家内部二级分类ID
|
|
StringBuilder storeInnerLabelId2 = new StringBuilder();
|
|
StringBuilder storeInnerLabelId2 = new StringBuilder();
|
|
for (StoreLabelBindGoods labelBindGoods : labelBindGoodsList) {
|
|
for (StoreLabelBindGoods labelBindGoods : labelBindGoodsList) {
|
|
- StoreInnerLabel storeInnerLabel = storeInnerLabelReadMapper.getByPrimaryKey(labelBindGoods.getInnerLabelId());
|
|
|
|
- if (storeInnerLabel.getParentInnerLabelId() == 0) {
|
|
|
|
- //商品绑定的是一级内部分类
|
|
|
|
- storeInnerLabelId1.append(" ").append(storeInnerLabel.getInnerLabelId());
|
|
|
|
- } else {
|
|
|
|
- //商品绑定的是二级内部分类
|
|
|
|
- storeInnerLabelId2.append(" ").append(storeInnerLabel.getInnerLabelId());
|
|
|
|
- storeInnerLabelId1.append(" ").append(storeInnerLabel.getParentInnerLabelId());
|
|
|
|
|
|
+ StoreInnerLabel storeInnerLabel = storeInnerLabelList.stream().filter(innerLabel -> innerLabel.getInnerLabelId().equals(labelBindGoods.getInnerLabelId())).findFirst().orElse(null);
|
|
|
|
+ if (storeInnerLabel != null) {
|
|
|
|
+ if (storeInnerLabel.getParentInnerLabelId() == 0) {
|
|
|
|
+ //商品绑定的是一级内部分类
|
|
|
|
+ storeInnerLabelId1.append(" ").append(storeInnerLabel.getInnerLabelId());
|
|
|
|
+ } else {
|
|
|
|
+ //商品绑定的是二级内部分类
|
|
|
|
+ storeInnerLabelId2.append(" ").append(storeInnerLabel.getInnerLabelId());
|
|
|
|
+ storeInnerLabelId1.append(" ").append(storeInnerLabel.getParentInnerLabelId());
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- searchProductDTO.setStoreInnerLabelId1(storeInnerLabelId1.toString().substring(1));
|
|
|
|
|
|
+ searchProductDTO.setStoreInnerLabelId1(storeInnerLabelId1.substring(1));
|
|
if (!StringUtils.isEmpty(storeInnerLabelId2.toString())) {
|
|
if (!StringUtils.isEmpty(storeInnerLabelId2.toString())) {
|
|
- searchProductDTO.setStoreInnerLabelId2(storeInnerLabelId2.toString().substring(1));
|
|
|
|
|
|
+ searchProductDTO.setStoreInnerLabelId2(storeInnerLabelId2.substring(1));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
searchProductDTO.setOnlineTime(goods.getOnlineTime().getTime());
|
|
searchProductDTO.setOnlineTime(goods.getOnlineTime().getTime());
|
|
@@ -249,7 +281,7 @@ public class ESGoodsModel {
|
|
//商品排行查询
|
|
//商品排行查询
|
|
GoodsBindRankExample goodsBindRankExample = new GoodsBindRankExample();
|
|
GoodsBindRankExample goodsBindRankExample = new GoodsBindRankExample();
|
|
goodsBindRankExample.setGoodsId(goods.getGoodsId());
|
|
goodsBindRankExample.setGoodsId(goods.getGoodsId());
|
|
- List<GoodsRankListDTO> rankList = goodsBindRankReadMapper.getGoodsRankList(goodsBindRankExample);
|
|
|
|
|
|
+ List<GoodsRankListDTO> rankList = rankListAll.stream().filter(rank -> rank.getGoodsId().equals(goods.getGoodsId())).collect(Collectors.toList());
|
|
if (!CollectionUtils.isEmpty(rankList)) {
|
|
if (!CollectionUtils.isEmpty(rankList)) {
|
|
GoodsRankListDTO goodsRank = rankList.get(0);
|
|
GoodsRankListDTO goodsRank = rankList.get(0);
|
|
searchProductDTO.setRankId(goodsRank.getRankId().toString());
|
|
searchProductDTO.setRankId(goodsRank.getRankId().toString());
|
|
@@ -260,24 +292,11 @@ public class ESGoodsModel {
|
|
}
|
|
}
|
|
|
|
|
|
//商品参与的活动
|
|
//商品参与的活动
|
|
- GoodsPromotionExample promotionExample = new GoodsPromotionExample();
|
|
|
|
- promotionExample.setIsEffective(PromotionConst.IS_EFFECTIVE_YES);
|
|
|
|
- promotionExample.setStartTimeBefore(new Date());
|
|
|
|
- promotionExample.setEndTimeAfter(new Date());
|
|
|
|
- //一级活动,绑定商品
|
|
|
|
- promotionExample.setBindType(PromotionConst.BIND_TYPE_1);
|
|
|
|
- promotionExample.setGoodsId(goods.getGoodsId());
|
|
|
|
- List<GoodsPromotion> list = goodsPromotionReadMapper.listByExample(promotionExample);
|
|
|
|
|
|
+ List<GoodsPromotion> list = listAll.stream().filter(goodsPromotion -> goodsPromotion.getGoodsId().equals(goods.getGoodsId())).collect(Collectors.toList());
|
|
//二级活动,绑定店铺
|
|
//二级活动,绑定店铺
|
|
- promotionExample.setGoodsId(null);
|
|
|
|
- promotionExample.setStoreId(goods.getStoreId());
|
|
|
|
- promotionExample.setBindType(PromotionConst.BIND_TYPE_2);
|
|
|
|
- list.addAll(goodsPromotionReadMapper.listByExample(promotionExample));
|
|
|
|
|
|
+ list.addAll(secondListAll.stream().filter(goodsPromotion -> goodsPromotion.getStoreId().equals(goods.getStoreId())).collect(Collectors.toList()));
|
|
//三级活动,绑定三级分类
|
|
//三级活动,绑定三级分类
|
|
- promotionExample.setStoreId(null);
|
|
|
|
- promotionExample.setGoodsCategoryId3(goods.getCategoryId3());
|
|
|
|
- promotionExample.setBindType(PromotionConst.BIND_TYPE_3);
|
|
|
|
- list.addAll(goodsPromotionReadMapper.listByExample(promotionExample));
|
|
|
|
|
|
+ list.addAll(thirdListAll.stream().filter(goodsPromotion -> goodsPromotion.getGoodsCategoryId3().equals(goods.getCategoryId3())).collect(Collectors.toList()));
|
|
List<GoodsListVO.PromotionVO> vos = new ArrayList<>();
|
|
List<GoodsListVO.PromotionVO> vos = new ArrayList<>();
|
|
//根据活动名称过滤重复
|
|
//根据活动名称过滤重复
|
|
Set<String> set = new HashSet<>();
|
|
Set<String> set = new HashSet<>();
|
|
@@ -325,15 +344,15 @@ public class ESGoodsModel {
|
|
* @param goodsList
|
|
* @param goodsList
|
|
* @throws IOException
|
|
* @throws IOException
|
|
*/
|
|
*/
|
|
- private BulkResponse createIndex(String url, Integer port, List<SearchProductDTO> goodsList) throws IOException {
|
|
|
|
|
|
+ private BulkResponse createIndex(String url, Integer port, List<SearchProductDTO> goodsList, String webSite) throws IOException {
|
|
RestHighLevelClient client = null;
|
|
RestHighLevelClient client = null;
|
|
BulkResponse response = null;
|
|
BulkResponse response = null;
|
|
try {
|
|
try {
|
|
client = getESClient();
|
|
client = getESClient();
|
|
- boolean indexExist = client.indices().exists(new GetIndexRequest(DomainUrlUtil.ES_INDEX_NAME), RequestOptions.DEFAULT);
|
|
|
|
|
|
+ boolean indexExist = client.indices().exists(new GetIndexRequest(DomainUrlUtil.ES_INDEX_NAME + "_" + webSite), RequestOptions.DEFAULT);
|
|
if (!indexExist) {
|
|
if (!indexExist) {
|
|
//索引不存在,创建索引,设置索引分词格式
|
|
//索引不存在,创建索引,设置索引分词格式
|
|
- CreateIndexRequest createIndexRequest = new CreateIndexRequest(DomainUrlUtil.ES_INDEX_NAME);
|
|
|
|
|
|
+ CreateIndexRequest createIndexRequest = new CreateIndexRequest(DomainUrlUtil.ES_INDEX_NAME + "_" + webSite);
|
|
createIndexRequest.settings(Settings.builder()
|
|
createIndexRequest.settings(Settings.builder()
|
|
.put("index.analysis.analyzer.default.type", "ik_max_word")
|
|
.put("index.analysis.analyzer.default.type", "ik_max_word")
|
|
.put("index.analysis.analyzer.default_search.type", "ik_smart"));
|
|
.put("index.analysis.analyzer.default_search.type", "ik_smart"));
|
|
@@ -342,7 +361,7 @@ public class ESGoodsModel {
|
|
BulkRequest bulkRequest = new BulkRequest();
|
|
BulkRequest bulkRequest = new BulkRequest();
|
|
//插入数据
|
|
//插入数据
|
|
for (SearchProductDTO g : goodsList) {
|
|
for (SearchProductDTO g : goodsList) {
|
|
- bulkRequest.add(new IndexRequest(DomainUrlUtil.ES_INDEX_NAME).id(g.getGoodsId()).source(JSONObject.toJSONString(g), XContentType.JSON));
|
|
|
|
|
|
+ bulkRequest.add(new IndexRequest(DomainUrlUtil.ES_INDEX_NAME + "_" + webSite).id(g.getGoodsId()).source(JSONObject.toJSONString(g), XContentType.JSON));
|
|
}
|
|
}
|
|
response = client.bulk(bulkRequest, RequestOptions.DEFAULT);
|
|
response = client.bulk(bulkRequest, RequestOptions.DEFAULT);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
@@ -363,13 +382,13 @@ public class ESGoodsModel {
|
|
* @param goodsList
|
|
* @param goodsList
|
|
* @throws IOException
|
|
* @throws IOException
|
|
*/
|
|
*/
|
|
- private void deleteByQuery(String url, Integer port, List<Goods> goodsList) throws IOException {
|
|
|
|
|
|
+ private void deleteByQuery(String url, Integer port, List<Goods> goodsList, String webSite) throws IOException {
|
|
RestHighLevelClient client = null;
|
|
RestHighLevelClient client = null;
|
|
try {
|
|
try {
|
|
client = getESClient();
|
|
client = getESClient();
|
|
BulkRequest bulkRequest = new BulkRequest();
|
|
BulkRequest bulkRequest = new BulkRequest();
|
|
for (Goods g : goodsList) {
|
|
for (Goods g : goodsList) {
|
|
- bulkRequest.add(new DeleteRequest(DomainUrlUtil.ES_INDEX_NAME, g.getGoodsId().toString()));
|
|
|
|
|
|
+ bulkRequest.add(new DeleteRequest(DomainUrlUtil.ES_INDEX_NAME + "_" + webSite, g.getGoodsId().toString()));
|
|
}
|
|
}
|
|
client.bulk(bulkRequest, RequestOptions.DEFAULT);
|
|
client.bulk(bulkRequest, RequestOptions.DEFAULT);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
@@ -385,11 +404,12 @@ public class ESGoodsModel {
|
|
|
|
|
|
/**
|
|
/**
|
|
* 查询满足条件的商品对应的店铺id
|
|
* 查询满足条件的商品对应的店铺id
|
|
|
|
+ *
|
|
* @param categoryId 分类id
|
|
* @param categoryId 分类id
|
|
- * @param keyword 关键词
|
|
|
|
|
|
+ * @param keyword 关键词
|
|
* @return 店铺id集合
|
|
* @return 店铺id集合
|
|
*/
|
|
*/
|
|
- public Set<Long> searchStoreIdsByEs(Integer categoryId,String keyword){
|
|
|
|
|
|
+ public Set<Long> searchStoreIdsByEs(Integer categoryId, String keyword) {
|
|
Set<Long> result = new HashSet<>();//返回数据
|
|
Set<Long> result = new HashSet<>();//返回数据
|
|
RestHighLevelClient client = getESClient();//获取es客户端
|
|
RestHighLevelClient client = getESClient();//获取es客户端
|
|
SearchRequest searchRequest = new SearchRequest(DomainUrlUtil.ES_INDEX_NAME);
|
|
SearchRequest searchRequest = new SearchRequest(DomainUrlUtil.ES_INDEX_NAME);
|
|
@@ -397,24 +417,24 @@ public class ESGoodsModel {
|
|
//构造查询条件
|
|
//构造查询条件
|
|
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
|
|
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
|
|
SearchConditionDTO qc = new SearchConditionDTO();
|
|
SearchConditionDTO qc = new SearchConditionDTO();
|
|
- if (!StringUtil.isNullOrZero(categoryId)){
|
|
|
|
|
|
+ if (!StringUtil.isNullOrZero(categoryId)) {
|
|
qc.setCategoryIds(categoryId + "");
|
|
qc.setCategoryIds(categoryId + "");
|
|
boolQueryBuilder.must(this.searchIndexAssembling4cate(qc));
|
|
boolQueryBuilder.must(this.searchIndexAssembling4cate(qc));
|
|
}
|
|
}
|
|
- if (!StringUtils.isEmpty(keyword)){
|
|
|
|
|
|
+ if (!StringUtils.isEmpty(keyword)) {
|
|
qc.setKeyword(keyword);
|
|
qc.setKeyword(keyword);
|
|
boolQueryBuilder.must(this.searchIndexAssembling4keyword(qc));
|
|
boolQueryBuilder.must(this.searchIndexAssembling4keyword(qc));
|
|
}
|
|
}
|
|
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
|
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
|
searchSourceBuilder.size(0);
|
|
searchSourceBuilder.size(0);
|
|
//聚合查询,将所有符合条件的店铺id放入list
|
|
//聚合查询,将所有符合条件的店铺id放入list
|
|
- searchSourceBuilder.aggregation(AggregationBuilders.filter("query",boolQueryBuilder)
|
|
|
|
|
|
+ searchSourceBuilder.aggregation(AggregationBuilders.filter("query", boolQueryBuilder)
|
|
.subAggregation(AggregationBuilders.terms("list").field(SearchProductDTO.STORE_ID_ + ".keyword").size(1000000)));
|
|
.subAggregation(AggregationBuilders.terms("list").field(SearchProductDTO.STORE_ID_ + ".keyword").size(1000000)));
|
|
searchRequest.source(searchSourceBuilder);
|
|
searchRequest.source(searchSourceBuilder);
|
|
try {
|
|
try {
|
|
//解析查询结果,拿到店铺id list
|
|
//解析查询结果,拿到店铺id list
|
|
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
|
|
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
|
|
- ParsedFilter filter = (ParsedFilter)searchResponse.getAggregations().asList().get(0);//过滤后的结果集
|
|
|
|
|
|
+ ParsedFilter filter = (ParsedFilter) searchResponse.getAggregations().asList().get(0);//过滤后的结果集
|
|
ParsedStringTerms terms = (ParsedStringTerms) filter.getAggregations().asList().get(0);//聚合属性值id的结果集
|
|
ParsedStringTerms terms = (ParsedStringTerms) filter.getAggregations().asList().get(0);//聚合属性值id的结果集
|
|
terms.getBuckets().forEach(buckets -> {
|
|
terms.getBuckets().forEach(buckets -> {
|
|
String key = (String) buckets.getKey();
|
|
String key = (String) buckets.getKey();
|
|
@@ -440,7 +460,7 @@ public class ESGoodsModel {
|
|
* @param keyword 关键词
|
|
* @param keyword 关键词
|
|
* @return 店铺商品
|
|
* @return 店铺商品
|
|
*/
|
|
*/
|
|
- public List<SearchProductDTO> getStoreGoodsList(String storeIds,Integer categoryId,String keyword){
|
|
|
|
|
|
+ public List<SearchProductDTO> getStoreGoodsList(String storeIds, Integer categoryId, String keyword) {
|
|
List<SearchProductDTO> result = new ArrayList<>();
|
|
List<SearchProductDTO> result = new ArrayList<>();
|
|
RestHighLevelClient client = getESClient();
|
|
RestHighLevelClient client = getESClient();
|
|
SearchRequest searchRequest = new SearchRequest(DomainUrlUtil.ES_INDEX_NAME);
|
|
SearchRequest searchRequest = new SearchRequest(DomainUrlUtil.ES_INDEX_NAME);
|
|
@@ -450,14 +470,14 @@ public class ESGoodsModel {
|
|
//构造查询条件
|
|
//构造查询条件
|
|
BoolQueryBuilder storeQuery = QueryBuilders.boolQuery();
|
|
BoolQueryBuilder storeQuery = QueryBuilders.boolQuery();
|
|
for (String storeId : storeIds.split(",")) {
|
|
for (String storeId : storeIds.split(",")) {
|
|
- storeQuery.should(QueryBuilders.matchQuery(SearchProductDTO.STORE_ID_,storeId));
|
|
|
|
|
|
+ storeQuery.should(QueryBuilders.matchQuery(SearchProductDTO.STORE_ID_, storeId));
|
|
}
|
|
}
|
|
boolQueryBuilder.must(storeQuery);
|
|
boolQueryBuilder.must(storeQuery);
|
|
- if (!StringUtil.isNullOrZero(categoryId)){
|
|
|
|
|
|
+ if (!StringUtil.isNullOrZero(categoryId)) {
|
|
qc.setCategoryIds(categoryId + "");
|
|
qc.setCategoryIds(categoryId + "");
|
|
boolQueryBuilder.must(this.searchIndexAssembling4cate(qc));
|
|
boolQueryBuilder.must(this.searchIndexAssembling4cate(qc));
|
|
}
|
|
}
|
|
- if (!StringUtils.isEmpty(keyword)){
|
|
|
|
|
|
+ if (!StringUtils.isEmpty(keyword)) {
|
|
qc.setKeyword(keyword);
|
|
qc.setKeyword(keyword);
|
|
boolQueryBuilder.must(this.searchIndexAssembling4keyword(qc));
|
|
boolQueryBuilder.must(this.searchIndexAssembling4keyword(qc));
|
|
}
|
|
}
|
|
@@ -469,7 +489,7 @@ public class ESGoodsModel {
|
|
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
|
|
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
|
|
SearchHits hits = searchResponse.getHits();
|
|
SearchHits hits = searchResponse.getHits();
|
|
for (SearchHit hit : hits.getHits()) {
|
|
for (SearchHit hit : hits.getHits()) {
|
|
- result.add(JSON.parseObject(hit.getSourceAsString(),SearchProductDTO.class));
|
|
|
|
|
|
+ result.add(JSON.parseObject(hit.getSourceAsString(), SearchProductDTO.class));
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
log.error("es连接异常:", e);
|
|
log.error("es连接异常:", e);
|
|
@@ -486,6 +506,7 @@ public class ESGoodsModel {
|
|
/**
|
|
/**
|
|
* 获取默认三级分类id
|
|
* 获取默认三级分类id
|
|
* 获取规则:按条件查询前500条数据中,三级分类最多的即为默认分类
|
|
* 获取规则:按条件查询前500条数据中,三级分类最多的即为默认分类
|
|
|
|
+ *
|
|
* @param qc 查询条件
|
|
* @param qc 查询条件
|
|
* @return 默认三级分类id
|
|
* @return 默认三级分类id
|
|
*/
|
|
*/
|
|
@@ -495,7 +516,7 @@ public class ESGoodsModel {
|
|
SearchSourceBuilder searchSourceBuilder = this.getCountSearchSourceBuilder(qc);
|
|
SearchSourceBuilder searchSourceBuilder = this.getCountSearchSourceBuilder(qc);
|
|
//查询前500条符合条件的记录,聚合获取条数最多的三级分类id
|
|
//查询前500条符合条件的记录,聚合获取条数最多的三级分类id
|
|
searchSourceBuilder.size(500);
|
|
searchSourceBuilder.size(500);
|
|
- searchSourceBuilder.aggregation(AggregationBuilders.terms("list").field(SearchProductDTO.CATEGORY_ID3_+".keyword"));
|
|
|
|
|
|
+ searchSourceBuilder.aggregation(AggregationBuilders.terms("list").field(SearchProductDTO.CATEGORY_ID3_ + ".keyword"));
|
|
searchRequest.source(searchSourceBuilder);
|
|
searchRequest.source(searchSourceBuilder);
|
|
try {
|
|
try {
|
|
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
|
|
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
|