...
|
...
|
@@ -8,6 +8,7 @@ import javax.annotation.PostConstruct; |
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.elasticsearch.action.search.SearchType;
|
|
|
import org.elasticsearch.index.query.BoolQueryBuilder;
|
|
|
import org.elasticsearch.index.query.QueryBuilder;
|
|
|
import org.elasticsearch.index.query.QueryBuilders;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
...
|
...
|
@@ -126,12 +127,13 @@ public class ProductCountServiceImpl implements IProductCountService { |
|
|
BoolQueryBuilder mustFilter = QueryBuilders.boolQuery();
|
|
|
mustFilter.must(QueryBuilders.termQuery("status", 1));
|
|
|
mustFilter.mustNot(QueryBuilders.termQuery("attribute", 2));
|
|
|
mustFilter.must(QueryBuilders.rangeQuery("storageNum").gte(1));
|
|
|
mustFilter.must(QueryBuilders.rangeQuery("storageNum").gte(10));
|
|
|
mustFilter.must(QueryBuilders.rangeQuery("breakSizePercent").to(50));
|
|
|
mustFilter.must(QueryBuilders.termQuery("isOutlets", 2));
|
|
|
return mustFilter;
|
|
|
}
|
|
|
|
|
|
private long queryCount(BoolQueryBuilder paramFilter, BoolQueryBuilder scoreFilter) {
|
|
|
|
|
|
private long queryCount(QueryBuilder paramFilter, BoolQueryBuilder scoreFilter) {
|
|
|
BoolQueryBuilder filter = new BoolQueryBuilder();
|
|
|
filter.must(paramFilter);
|
|
|
filter.must(scoreFilter);
|
...
|
...
|
@@ -143,21 +145,30 @@ public class ProductCountServiceImpl implements IProductCountService { |
|
|
@Override
|
|
|
public BoolQueryBuilder genScoreFilter(BoolQueryBuilder paramFilter) {
|
|
|
BoolQueryBuilder scoreFilter = this.genScoreDefaultFilter();
|
|
|
if (this.queryCount(paramFilter, scoreFilter) <= 2000) {
|
|
|
long totalCount = this.queryCount(paramFilter, scoreFilter);
|
|
|
if (totalCount <= 2000) {
|
|
|
return scoreFilter;
|
|
|
}
|
|
|
// 零点那一刻命中不了,得想办法解决【比如凌晨两点再切数量】
|
|
|
long todayLastTimeSecond = DateUtil.getLastTimeSecond(new Date());
|
|
|
long oneMonthTs = 30 * 24 * 60 * 60 * 1000L;
|
|
|
long oneMonthInSecond = 30 * 24 * 60 * 60;
|
|
|
int tryCount = 1;
|
|
|
while (tryCount <= 3) {
|
|
|
scoreFilter = this.genScoreDefaultFilter();
|
|
|
scoreFilter.must(QueryBuilders.rangeQuery("firstShelveTime").from(todayLastTimeSecond - tryCount * oneMonthTs));
|
|
|
if (this.queryCount(paramFilter, scoreFilter) > 1000) {
|
|
|
scoreFilter.must(QueryBuilders.rangeQuery("firstShelveTime").from(todayLastTimeSecond - tryCount * oneMonthInSecond));
|
|
|
totalCount = this.queryCount(paramFilter, scoreFilter);
|
|
|
if(totalCount>=1000){
|
|
|
return scoreFilter;
|
|
|
}
|
|
|
tryCount++;
|
|
|
}
|
|
|
return scoreFilter;
|
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
long todayLastTimeSecond = DateUtil.getLastTimeSecond(new Date());
|
|
|
long oneMonthInSecond = 30 * 24 * 60 * 60;
|
|
|
System.out.println(todayLastTimeSecond - 1 * oneMonthInSecond);
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|