Merge branch 'master' of gitee.com:beijing_hongye_huicheng/lilishop
This commit is contained in:
@@ -15,6 +15,17 @@
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.junit.vintage</groupId>
|
||||
<artifactId>junit-vintage-engine</artifactId>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-core</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
|
||||
@@ -30,7 +30,7 @@ import java.io.Serializable;
|
||||
public class LimitInterceptor {
|
||||
private RedisTemplate<String, Serializable> redisTemplate;
|
||||
|
||||
private DefaultRedisScript<Number> limitScript;
|
||||
private DefaultRedisScript<Long> limitScript;
|
||||
|
||||
@Autowired
|
||||
public void setRedisTemplate(RedisTemplate redisTemplate) {
|
||||
@@ -38,7 +38,7 @@ public class LimitInterceptor {
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setLimitScript(DefaultRedisScript<Number> limitScript) {
|
||||
public void setLimitScript(DefaultRedisScript<Long> limitScript) {
|
||||
this.limitScript = limitScript;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,10 +33,10 @@ public class LuaScript {
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public DefaultRedisScript<Number> limitScript() {
|
||||
DefaultRedisScript<Number> redisScript = new DefaultRedisScript<>();
|
||||
public DefaultRedisScript<Long> limitScript() {
|
||||
DefaultRedisScript<Long> redisScript = new DefaultRedisScript<>();
|
||||
redisScript.setScriptSource(new ResourceScriptSource(new ClassPathResource("script/limit.lua")));
|
||||
redisScript.setResultType(Number.class);
|
||||
redisScript.setResultType(Long.class);
|
||||
return redisScript;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,9 @@ import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.cors.CorsConfigurationSource;
|
||||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* SecurityBean
|
||||
*
|
||||
@@ -19,8 +22,7 @@ public class SecurityBean {
|
||||
|
||||
@Bean
|
||||
public BCryptPasswordEncoder passwordEncoder() {
|
||||
BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
|
||||
return bCryptPasswordEncoder;
|
||||
return new BCryptPasswordEncoder();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -33,7 +35,8 @@ public class SecurityBean {
|
||||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||
CorsConfiguration config = new CorsConfiguration();
|
||||
config.setAllowCredentials(true);
|
||||
config.addAllowedOrigin(CorsConfiguration.ALL);
|
||||
// config.addAllowedOrigin(CorsConfiguration.ALL);
|
||||
config.setAllowedOriginPatterns(Collections.singletonList(CorsConfiguration.ALL));
|
||||
config.addAllowedHeader(CorsConfiguration.ALL);
|
||||
config.addAllowedMethod(CorsConfiguration.ALL);
|
||||
source.registerCorsConfiguration("/**", config);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package cn.lili.elasticsearch.config;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.auth.AuthScope;
|
||||
@@ -30,10 +29,10 @@ import java.util.List;
|
||||
**/
|
||||
@Slf4j
|
||||
@Configuration
|
||||
@RequiredArgsConstructor(onConstructor_ = @Autowired)
|
||||
public class ElasticsearchConfig extends AbstractElasticsearchConfiguration {
|
||||
|
||||
private final ElasticsearchProperties elasticsearchProperties;
|
||||
@Autowired
|
||||
private ElasticsearchProperties elasticsearchProperties;
|
||||
|
||||
private RestHighLevelClient client;
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ import java.util.List;
|
||||
**/
|
||||
@Data
|
||||
@Builder
|
||||
@Component
|
||||
@Component("elasticsearchProperties")
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@ConfigurationProperties(prefix = "lili.data.elasticsearch")
|
||||
|
||||
@@ -5,6 +5,7 @@ import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -15,7 +16,9 @@ import java.util.List;
|
||||
*/
|
||||
@Data
|
||||
@ApiModel(value = "商品参数分组")
|
||||
public class GoodsParamsDTO {
|
||||
public class GoodsParamsDTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 4892783539320159200L;
|
||||
|
||||
@TableField(value = "group_id")
|
||||
@ApiModelProperty(value = "分组id")
|
||||
|
||||
@@ -4,8 +4,7 @@ import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.Max;
|
||||
import javax.validation.constraints.Min;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 商品参数项
|
||||
@@ -16,7 +15,9 @@ import javax.validation.constraints.Min;
|
||||
*/
|
||||
@Data
|
||||
@ApiModel(value = "商品参数列表")
|
||||
public class GoodsParamsItemDTO {
|
||||
public class GoodsParamsItemDTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -8823775607604091035L;
|
||||
|
||||
@ApiModelProperty(value = "参数ID")
|
||||
private String paramId;
|
||||
@@ -32,4 +33,7 @@ public class GoodsParamsItemDTO {
|
||||
|
||||
@ApiModelProperty(value = "是否必填,0 不显示 1 显示")
|
||||
private Integer required = 0;
|
||||
|
||||
@ApiModelProperty(value = "排序")
|
||||
private Integer sort;
|
||||
}
|
||||
|
||||
@@ -8,14 +8,10 @@ import cn.hutool.json.JSONUtil;
|
||||
import cn.lili.cache.Cache;
|
||||
import cn.lili.common.enums.ResultCode;
|
||||
import cn.lili.common.exception.ServiceException;
|
||||
import cn.lili.rocketmq.RocketmqSendCallbackBuilder;
|
||||
import cn.lili.rocketmq.tags.GoodsTagsEnum;
|
||||
import cn.lili.common.security.context.UserContext;
|
||||
import cn.lili.mybatis.util.PageUtil;
|
||||
import cn.lili.common.properties.RocketmqCustomProperties;
|
||||
import cn.lili.common.security.context.UserContext;
|
||||
import cn.lili.modules.goods.entity.dos.Goods;
|
||||
import cn.lili.modules.goods.entity.dos.GoodsSku;
|
||||
import cn.lili.modules.goods.entity.dto.GoodsParamsDTO;
|
||||
import cn.lili.modules.goods.entity.dto.GoodsSearchParams;
|
||||
import cn.lili.modules.goods.entity.dto.GoodsSkuStockDTO;
|
||||
import cn.lili.modules.goods.entity.enums.GoodsAuthEnum;
|
||||
@@ -36,6 +32,9 @@ import cn.lili.modules.member.service.MemberEvaluationService;
|
||||
import cn.lili.modules.search.entity.dos.EsGoodsAttribute;
|
||||
import cn.lili.modules.search.entity.dos.EsGoodsIndex;
|
||||
import cn.lili.modules.search.service.EsGoodsIndexService;
|
||||
import cn.lili.mybatis.util.PageUtil;
|
||||
import cn.lili.rocketmq.RocketmqSendCallbackBuilder;
|
||||
import cn.lili.rocketmq.tags.GoodsTagsEnum;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
@@ -486,41 +485,9 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
||||
* @param goods 商品信息
|
||||
*/
|
||||
private void generateEsCheck(Goods goods) {
|
||||
//如果商品通过审核&&并且已上架
|
||||
List<GoodsSku> goodsSkuList = this.list(new LambdaQueryWrapper<GoodsSku>().eq(GoodsSku::getGoodsId, goods.getId()));
|
||||
if (goods.getIsAuth().equals(GoodsAuthEnum.PASS.name())
|
||||
&& goods.getMarketEnable().equals(GoodsStatusEnum.UPPER.name())
|
||||
&& Boolean.FALSE.equals(goods.getDeleteFlag())) {
|
||||
List<EsGoodsIndex> goodsIndices = new ArrayList<>();
|
||||
for (GoodsSku goodsSku : goodsSkuList) {
|
||||
EsGoodsIndex esGoodsOld = goodsIndexService.findById(goodsSku.getId());
|
||||
EsGoodsIndex goodsIndex = new EsGoodsIndex(goodsSku);
|
||||
if (goods.getParams() != null && !goods.getParams().isEmpty()) {
|
||||
List<GoodsParamsDTO> goodsParamDTOS = JSONUtil.toList(goods.getParams(), GoodsParamsDTO.class);
|
||||
goodsIndex = new EsGoodsIndex(goodsSku, goodsParamDTOS);
|
||||
}
|
||||
//如果商品库存不为0,并且es中有数据
|
||||
if (goodsSku.getQuantity() > 0 && esGoodsOld == null) {
|
||||
goodsIndices.add(goodsIndex);
|
||||
} else if (goodsSku.getQuantity() > 0 && esGoodsOld != null) {
|
||||
goodsIndexService.updateIndex(goodsIndex);
|
||||
}
|
||||
}
|
||||
if (!goodsIndices.isEmpty()) {
|
||||
String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.GENERATOR_GOODS_INDEX.name();
|
||||
//发送mq消息
|
||||
rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(goodsIndices), RocketmqSendCallbackBuilder.commonCallback());
|
||||
}
|
||||
}
|
||||
//如果商品状态值不支持es搜索,那么将商品信息做下架处理
|
||||
else {
|
||||
for (GoodsSku goodsSku : goodsSkuList) {
|
||||
EsGoodsIndex esGoodsOld = goodsIndexService.findById(goodsSku.getId());
|
||||
if (esGoodsOld != null) {
|
||||
goodsIndexService.deleteIndexById(goodsSku.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.GENERATOR_GOODS_INDEX.name();
|
||||
//发送mq消息
|
||||
rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(goods), RocketmqSendCallbackBuilder.commonCallback());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,6 +9,7 @@ import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 商品属性索引
|
||||
*
|
||||
* @author paulG
|
||||
* @since 2020/10/14
|
||||
**/
|
||||
@@ -47,11 +48,19 @@ public class EsGoodsAttribute implements Serializable {
|
||||
@Field(type = FieldType.Text)
|
||||
private String value;
|
||||
|
||||
public EsGoodsAttribute(Integer type,String nameId,String name,String valueId,String value){
|
||||
this.type=type;
|
||||
this.nameId=nameId;
|
||||
this.name=name;
|
||||
this.valueId=valueId;
|
||||
this.value=value;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@Field(type = FieldType.Integer)
|
||||
private Integer sort;
|
||||
|
||||
public EsGoodsAttribute(Integer type, String nameId, String name, String valueId, String value, Integer sort) {
|
||||
this.type = type;
|
||||
this.nameId = nameId;
|
||||
this.name = name;
|
||||
this.valueId = valueId;
|
||||
this.value = value;
|
||||
this.sort = sort;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ import java.util.Map;
|
||||
* @author paulG
|
||||
**/
|
||||
@Data
|
||||
@Document(indexName = "#{elasticsearchProperties.indexPrefix}_" + EsSuffix.GOODS_INDEX_NAME)
|
||||
@Document(indexName = "#{@elasticsearchProperties.indexPrefix}_" + EsSuffix.GOODS_INDEX_NAME)
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
public class EsGoodsIndex implements Serializable {
|
||||
@@ -300,6 +300,7 @@ public class EsGoodsIndex implements Serializable {
|
||||
attribute.setType(1);
|
||||
attribute.setName(goodsParam.getParamName());
|
||||
attribute.setValue(goodsParam.getParamValue());
|
||||
attribute.setSort(goodsParam.getSort());
|
||||
attributes.add(attribute);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import cn.lili.modules.search.entity.dos.EsGoodsIndex;
|
||||
import cn.lili.modules.search.entity.dos.EsGoodsRelatedInfo;
|
||||
import cn.lili.modules.search.entity.dto.EsGoodsSearchDTO;
|
||||
import cn.lili.modules.search.entity.dto.HotWordsDTO;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.elasticsearch.core.SearchPage;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -24,7 +24,7 @@ public interface EsGoodsSearchService {
|
||||
* @param pageVo 分页参数
|
||||
* @return 搜索结果
|
||||
*/
|
||||
Page<EsGoodsIndex> searchGoods(EsGoodsSearchDTO searchDTO, PageVO pageVo);
|
||||
SearchPage<EsGoodsIndex> searchGoods(EsGoodsSearchDTO searchDTO, PageVO pageVo);
|
||||
|
||||
/**
|
||||
* 获取热门关键词
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package cn.lili.modules.search.serviceimpl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.text.CharSequenceUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
@@ -30,14 +28,13 @@ import cn.lili.modules.search.service.EsGoodsSearchService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.assertj.core.util.IterableUtil;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.client.RequestOptions;
|
||||
import org.elasticsearch.client.indices.AnalyzeRequest;
|
||||
import org.elasticsearch.client.indices.AnalyzeResponse;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
import org.mybatis.spring.MyBatisSystemException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.elasticsearch.core.SearchHit;
|
||||
import org.springframework.data.elasticsearch.core.SearchPage;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
@@ -234,14 +231,16 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
|
||||
*/
|
||||
@Override
|
||||
public void updateEsGoodsIndexAllByList(BasePromotion promotion, String key) {
|
||||
List<EsGoodsIndex> goodsIndices;
|
||||
List<EsGoodsIndex> goodsIndices = new ArrayList<>();
|
||||
//如果storeId不为空,则表示是店铺活动
|
||||
if (promotion.getStoreId() != null) {
|
||||
EsGoodsSearchDTO searchDTO = new EsGoodsSearchDTO();
|
||||
searchDTO.setStoreId(promotion.getStoreId());
|
||||
//查询出店铺商品
|
||||
Page<EsGoodsIndex> esGoodsIndices = goodsSearchService.searchGoods(searchDTO, null);
|
||||
goodsIndices = esGoodsIndices.getContent();
|
||||
SearchPage<EsGoodsIndex> esGoodsIndices = goodsSearchService.searchGoods(searchDTO, null);
|
||||
for (SearchHit<EsGoodsIndex> searchHit : esGoodsIndices.getContent()) {
|
||||
goodsIndices.add(searchHit.getContent());
|
||||
}
|
||||
} else {
|
||||
//否则是平台活动
|
||||
Iterable<EsGoodsIndex> all = goodsIndexRepository.findAll();
|
||||
@@ -494,16 +493,16 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
|
||||
}
|
||||
}
|
||||
|
||||
public List<EsGoodsIndex> searchList(String index) {
|
||||
SearchResponse searchResponse = search(index);
|
||||
SearchHit[] hits = searchResponse.getHits().getHits();
|
||||
List<EsGoodsIndex> goodsIndices = new ArrayList<>();
|
||||
Arrays.stream(hits).forEach(hit -> {
|
||||
Map<String, Object> sourceAsMap = hit.getSourceAsMap();
|
||||
EsGoodsIndex person = BeanUtil.mapToBean(sourceAsMap, EsGoodsIndex.class, false, CopyOptions.create());
|
||||
goodsIndices.add(person);
|
||||
});
|
||||
return goodsIndices;
|
||||
}
|
||||
// public List<EsGoodsIndex> searchList(String index) {
|
||||
// SearchResponse searchResponse = search(index);
|
||||
// SearchHit[] hits = searchResponse.getHits().getHits();
|
||||
// List<EsGoodsIndex> goodsIndices = new ArrayList<>();
|
||||
// Arrays.stream(hits).forEach(hit -> {
|
||||
// Map<String, Object> sourceAsMap = hit.getSourceAsMap();
|
||||
// EsGoodsIndex person = BeanUtil.mapToBean(sourceAsMap, EsGoodsIndex.class, false, CopyOptions.create());
|
||||
// goodsIndices.add(person);
|
||||
// });
|
||||
// return goodsIndices;
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.text.CharSequenceUtil;
|
||||
import cn.lili.cache.Cache;
|
||||
import cn.lili.cache.CachePrefix;
|
||||
import cn.lili.common.utils.StringUtils;
|
||||
import cn.lili.common.vo.PageVO;
|
||||
import cn.lili.modules.goods.entity.dos.Brand;
|
||||
import cn.lili.modules.goods.entity.dos.Category;
|
||||
@@ -28,21 +27,19 @@ import org.elasticsearch.index.query.Operator;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder;
|
||||
import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders;
|
||||
import org.elasticsearch.search.aggregations.Aggregation;
|
||||
import org.elasticsearch.search.aggregations.AggregationBuilder;
|
||||
import org.elasticsearch.search.aggregations.AggregationBuilders;
|
||||
import org.elasticsearch.search.aggregations.Aggregations;
|
||||
import org.elasticsearch.search.aggregations.*;
|
||||
import org.elasticsearch.search.aggregations.bucket.nested.ParsedNested;
|
||||
import org.elasticsearch.search.aggregations.bucket.terms.ParsedStringTerms;
|
||||
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
|
||||
import org.elasticsearch.search.sort.SortBuilders;
|
||||
import org.elasticsearch.search.sort.SortOrder;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
|
||||
import org.springframework.data.elasticsearch.core.SearchHitSupport;
|
||||
import org.springframework.data.elasticsearch.core.SearchHits;
|
||||
import org.springframework.data.elasticsearch.core.SearchPage;
|
||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
||||
import org.springframework.data.redis.core.DefaultTypedTuple;
|
||||
@@ -63,6 +60,7 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService {
|
||||
private static final String ATTR_PATH = "attrList";
|
||||
private static final String ATTR_VALUE = "attrList.value";
|
||||
private static final String ATTR_NAME = "attrList.name";
|
||||
private static final String ATTR_SORT = "attrList.sort";
|
||||
private static final String ATTR_NAME_KEY = "nameList";
|
||||
private static final String ATTR_VALUE_KEY = "valueList";
|
||||
|
||||
@@ -90,15 +88,15 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService {
|
||||
private Cache cache;
|
||||
|
||||
@Override
|
||||
public Page<EsGoodsIndex> searchGoods(EsGoodsSearchDTO searchDTO, PageVO pageVo) {
|
||||
public SearchPage<EsGoodsIndex> searchGoods(EsGoodsSearchDTO searchDTO, PageVO pageVo) {
|
||||
if (CharSequenceUtil.isNotEmpty(searchDTO.getKeyword())) {
|
||||
cache.incrementScore(CachePrefix.HOT_WORD.getPrefix(), searchDTO.getKeyword());
|
||||
}
|
||||
NativeSearchQueryBuilder searchQueryBuilder = createSearchQueryBuilder(searchDTO, pageVo, true);
|
||||
NativeSearchQuery searchQuery = searchQueryBuilder.build();
|
||||
log.info("searchGoods DSL:{}", searchQuery.getQuery());
|
||||
|
||||
return goodsIndexRepository.search(searchQuery);
|
||||
SearchHits<EsGoodsIndex> search = restTemplate.search(searchQuery, EsGoodsIndex.class);
|
||||
return SearchHitSupport.searchPageFor(search, searchQuery.getPageable());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -106,11 +104,11 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService {
|
||||
List<String> hotWords = new ArrayList<>();
|
||||
// redis 排序中,下标从0开始,所以这里需要 -1 处理
|
||||
count = count - 1;
|
||||
Set<DefaultTypedTuple> set = cache.reverseRangeWithScores(CachePrefix.HOT_WORD.getPrefix(), count);
|
||||
Set<DefaultTypedTuple<Object>> set = cache.reverseRangeWithScores(CachePrefix.HOT_WORD.getPrefix(), count);
|
||||
if (set == null || set.isEmpty()) {
|
||||
return new ArrayList<String>();
|
||||
return new ArrayList<>();
|
||||
}
|
||||
for (DefaultTypedTuple defaultTypedTuple : set) {
|
||||
for (DefaultTypedTuple<Object> defaultTypedTuple : set) {
|
||||
hotWords.add(Objects.requireNonNull(defaultTypedTuple.getValue()).toString());
|
||||
}
|
||||
return hotWords;
|
||||
@@ -130,7 +128,8 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService {
|
||||
builder.addAggregation(AggregationBuilders.terms("brandAgg").field("brandId").size(Integer.MAX_VALUE));
|
||||
//参数
|
||||
AggregationBuilder valuesBuilder = AggregationBuilders.terms("valueAgg").field(ATTR_VALUE);
|
||||
AggregationBuilder paramsNameBuilder = AggregationBuilders.terms("nameAgg").field(ATTR_NAME).subAggregation(valuesBuilder);
|
||||
AggregationBuilder sortBuilder = AggregationBuilders.sum("sortAgg").field(ATTR_SORT);
|
||||
AggregationBuilder paramsNameBuilder = AggregationBuilders.terms("nameAgg").field(ATTR_NAME).subAggregation(sortBuilder).order(BucketOrder.aggregation("sortAgg",false)).subAggregation(valuesBuilder);
|
||||
builder.addAggregation(AggregationBuilders.nested("attrAgg", ATTR_PATH).subAggregation(paramsNameBuilder));
|
||||
NativeSearchQuery searchQuery = builder.build();
|
||||
SearchHits<EsGoodsIndex> search = restTemplate.search(searchQuery, EsGoodsIndex.class);
|
||||
@@ -278,7 +277,7 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService {
|
||||
private NativeSearchQueryBuilder createSearchQueryBuilder(EsGoodsSearchDTO searchDTO, PageVO pageVo, boolean isAggregation) {
|
||||
NativeSearchQueryBuilder nativeSearchQueryBuilder = new NativeSearchQueryBuilder();
|
||||
if (pageVo != null) {
|
||||
Integer pageNumber = pageVo.getPageNumber() - 1;
|
||||
int pageNumber = pageVo.getPageNumber() - 1;
|
||||
if (pageNumber < 0) {
|
||||
pageNumber = 0;
|
||||
}
|
||||
@@ -303,7 +302,7 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService {
|
||||
|
||||
|
||||
//关键字检索
|
||||
if (StringUtils.isEmpty(searchDTO.getKeyword())) {
|
||||
if (CharSequenceUtil.isEmpty(searchDTO.getKeyword())) {
|
||||
nativeSearchQueryBuilder.withQuery(QueryBuilders.matchAllQuery());
|
||||
} else {
|
||||
this.keywordSearch(filterBuilder, queryBuilder, searchDTO.getKeyword(), isAggregation);
|
||||
@@ -331,10 +330,10 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService {
|
||||
/**
|
||||
* 查询属性处理
|
||||
*
|
||||
* @param filterBuilder
|
||||
* @param queryBuilder
|
||||
* @param searchDTO
|
||||
* @param isAggregation
|
||||
* @param filterBuilder 过滤构造器
|
||||
* @param queryBuilder 查询构造器
|
||||
* @param searchDTO 查询参数
|
||||
* @param isAggregation 是否为聚合查询
|
||||
*/
|
||||
private void commonSearch(BoolQueryBuilder filterBuilder, BoolQueryBuilder queryBuilder, EsGoodsSearchDTO searchDTO, boolean isAggregation) {
|
||||
//品牌判定
|
||||
@@ -423,10 +422,10 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService {
|
||||
/**
|
||||
* 关键字查询处理
|
||||
*
|
||||
* @param filterBuilder
|
||||
* @param queryBuilder
|
||||
* @param keyword
|
||||
* @param isAggregation
|
||||
* @param filterBuilder 过滤构造器
|
||||
* @param queryBuilder 查询构造器
|
||||
* @param keyword 关键字
|
||||
* @param isAggregation 是否为聚合查询
|
||||
*/
|
||||
private void keywordSearch(BoolQueryBuilder filterBuilder, BoolQueryBuilder queryBuilder, String keyword, boolean isAggregation) {
|
||||
List<FunctionScoreQueryBuilder.FilterFunctionBuilder> filterFunctionBuilders = new ArrayList<>();
|
||||
|
||||
@@ -4,10 +4,10 @@ import cn.lili.modules.order.order.entity.dos.OrderItem;
|
||||
import cn.lili.modules.order.order.service.OrderItemService;
|
||||
import cn.lili.modules.statistics.serviceimpl.OrderStatisticsDataServiceImpl;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -20,7 +20,7 @@ import java.util.List;
|
||||
* @since 2020-06-13 12:17
|
||||
*/
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest
|
||||
public class RedisLimiterHelperTest {
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cn.lili.test.script;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
@@ -12,7 +12,7 @@ import org.springframework.data.redis.core.script.DefaultRedisScript;
|
||||
import org.springframework.scripting.support.ResourceScriptSource;
|
||||
import org.springframework.test.annotation.Rollback;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -27,7 +27,7 @@ import java.util.List;
|
||||
* @since
|
||||
* 2020-02-22 20:26
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Rollback()
|
||||
|
||||
Reference in New Issue
Block a user