提交 2a3aea33 作者: 925993793@qq.com

专题资讯列表和专题报告数据接口条件统一

上级 da59cb28
package com.zzsn.event.controller.reportData; package com.zzsn.event.controller.reportData;
import cn.hutool.core.net.URLDecoder;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.google.common.base.Charsets;
import com.zzsn.event.constant.Constants; import com.zzsn.event.constant.Constants;
import com.zzsn.event.constant.Result; import com.zzsn.event.constant.Result;
import com.zzsn.event.entity.SysDictItem; import com.zzsn.event.entity.SysDictItem;
...@@ -14,6 +19,7 @@ import com.zzsn.event.util.EsIndexUtil; ...@@ -14,6 +19,7 @@ import com.zzsn.event.util.EsIndexUtil;
import com.zzsn.event.util.FieldUtil; import com.zzsn.event.util.FieldUtil;
import com.zzsn.event.vo.CountVO; import com.zzsn.event.vo.CountVO;
import com.zzsn.event.vo.es.Label; import com.zzsn.event.vo.es.Label;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.lucene.search.join.ScoreMode; import org.apache.lucene.search.join.ScoreMode;
import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchRequest;
...@@ -50,6 +56,7 @@ import java.util.stream.Collectors; ...@@ -50,6 +56,7 @@ import java.util.stream.Collectors;
* @author lkg * @author lkg
* @date 2025/4/9 * @date 2025/4/9
*/ */
@Slf4j
@RestController @RestController
@RequestMapping("/report/data/api") @RequestMapping("/report/data/api")
public class ReportDataController { public class ReportDataController {
...@@ -341,22 +348,6 @@ public class ReportDataController { ...@@ -341,22 +348,6 @@ public class ReportDataController {
searchSourceBuilder.sort("publishDate", SortOrder.DESC); searchSourceBuilder.sort("publishDate", SortOrder.DESC);
break; break;
} }
//审核状态
Integer status = searchCondition.getStatus();
if (status != null) {
if (status == 1) {
searchCondition.setCheckStatus(1);
} else if (status == 2) {
searchCondition.setCheckStatus(0);
searchCondition.setDeleteFlag(0);
} else if (status == 3) {
searchCondition.setCheckStatus(3);
} else if (status == 4) {
searchCondition.setDeleteFlag(1);
} else if (status == 5) {
searchCondition.setIsFreeCheck(1);
}
}
//构建es查询条件 //构建es查询条件
BoolQueryBuilder boolQuery = buildQuery(searchCondition); BoolQueryBuilder boolQuery = buildQuery(searchCondition);
searchSourceBuilder.query(boolQuery); searchSourceBuilder.query(boolQuery);
...@@ -395,6 +386,27 @@ public class ReportDataController { ...@@ -395,6 +386,27 @@ public class ReportDataController {
boolQuery.must(QueryBuilders.matchPhraseQuery(searchScope, searchWord)); boolQuery.must(QueryBuilders.matchPhraseQuery(searchScope, searchWord));
} }
} }
//高级查询数据处理
BoolQueryBuilder superQuery = buildSuperQuery(searchCondition.getSuperQueryMatchType(), searchCondition.getSuperQueryParams());
if (superQuery != null) {
boolQuery.must(superQuery);
}
//审核状态
Integer status = searchCondition.getAuditStatus();
if (status != null) {
if (status == 1) {
searchCondition.setCheckStatus(1);
} else if (status == 2) {
searchCondition.setCheckStatus(0);
searchCondition.setDeleteFlag(0);
} else if (status == 3) {
searchCondition.setCheckStatus(3);
} else if (status == 4) {
searchCondition.setDeleteFlag(1);
} else if (status == 5) {
searchCondition.setIsFreeCheck(1);
}
}
Integer checkStatus = searchCondition.getCheckStatus(); Integer checkStatus = searchCondition.getCheckStatus();
Integer deleteFlag = searchCondition.getDeleteFlag(); Integer deleteFlag = searchCondition.getDeleteFlag();
if (checkStatus != null) { if (checkStatus != null) {
...@@ -509,4 +521,133 @@ public class ReportDataController { ...@@ -509,4 +521,133 @@ public class ReportDataController {
String minDate = subjectService.getMinCreateTime(subjectIdList); String minDate = subjectService.getMinCreateTime(subjectIdList);
return EsIndexUtil.getIndexIntervalYearStr(Constants.SUBJECT_INDEX, minDate); return EsIndexUtil.getIndexIntervalYearStr(Constants.SUBJECT_INDEX, minDate);
} }
/**
* 高级检索条件封装
*
* @param superQueryMatchType 规则
* @param superQueryParams 条件(url转码后的json)
* @author lkg
* @date 2025/3/13
*/
private BoolQueryBuilder buildSuperQuery(String superQueryMatchType, String superQueryParams) {
if (StringUtils.isNotEmpty(superQueryParams)) {
try {
BoolQueryBuilder superBuilder = QueryBuilders.boolQuery();
String params = URLDecoder.decode(superQueryParams, Charsets.UTF_8);
JSONArray array = JSON.parseArray(params);
for (int i = 0; i < array.size(); i++) {
JSONObject item = array.getJSONObject(i);
BoolQueryBuilder builder2 = QueryBuilders.boolQuery();
String type = item.getString("type");
String rule = item.getString("rule");
String field = item.getString("field");
String val = item.getString("val");
if ("date".equals(type)) { //日期类型处理
if ("eq".equals(rule)) {
builder2.must(QueryBuilders.rangeQuery(field).from(val + "T00:00:00").to(val + "T23:59:59"));
}
if ("ne".equals(rule)) {
builder2.mustNot(QueryBuilders.rangeQuery(field).from(val + "T00:00:00").to(val + "T23:59:59"));
} else if ("gt".equals(rule)) {
builder2.must(QueryBuilders.rangeQuery(field).from((val + "T23:59:59")));
} else if ("ge".equals(rule)) {
builder2.must(QueryBuilders.rangeQuery(field).from((val + "T00:00:00")));
} else if ("lt".equals(rule)) {
builder2.must(QueryBuilders.rangeQuery(field).to((val + "T00:00:00")));
} else if ("le".equals(rule)) {
builder2.must(QueryBuilders.rangeQuery(field).to((val + "T23:59:59")));
}
} else if ("list".equals(type)) { //列表(数组)类查询
if ("eq".equals(rule)) {
builder2.must(QueryBuilders.termQuery(field + ".keyword", val));
} else if ("ne".equals(rule)) {
builder2.mustNot(QueryBuilders.termQuery(field + ".keyword", val));
} else if ("in".equals(rule)) {
builder2.must(QueryBuilders.termsQuery(field + ".keyword", val.split(" |\\+|,|,|;|;")));
} else if ("not_in".equals(rule)) {
builder2.mustNot(QueryBuilders.termsQuery(field + ".keyword", val.split(" |\\+|,|,|;|;")));
} else if ("keyWordsGroup".equals(rule)) {
if (StringUtils.isNotEmpty(val)) {
BoolQueryBuilder wordAllBoolQuery = QueryBuilders.boolQuery();
String[] andWords = val.split("\\+");
for (String words : andWords) {
String replace = words.replace("(", "").replace(")", "");
BoolQueryBuilder wordOrBoolQuery = QueryBuilders.boolQuery();
for (String word : replace.split("\\|")) {
wordOrBoolQuery.should(QueryBuilders.termQuery(field + ".keyword", word));
}
wordAllBoolQuery.must(wordOrBoolQuery);
}
builder2.must(wordAllBoolQuery);
}
}
} else if ("string".equals(type)) { //文本类查询
if ("fullText".equals(field)) {
BoolQueryBuilder fullTextBoolQuery = multiMatchQuery(val);
if ("like".equals(rule)) {
builder2.must(fullTextBoolQuery);
} else if ("not_like".equals(rule)) {
builder2.mustNot(fullTextBoolQuery);
} else if ("keyWordsGroup".equals(rule)) {
BoolQueryBuilder wordAllBoolQuery = QueryBuilders.boolQuery();
String[] andWords = val.split("\\+");
for (String words : andWords) {
String replace = words.replace("(", "").replace(")", "");
BoolQueryBuilder wordOrBoolQuery = QueryBuilders.boolQuery();
for (String word : replace.split("\\|")) {
wordOrBoolQuery.should(multiMatchQuery(word));
}
wordAllBoolQuery.must(wordOrBoolQuery);
}
builder2.must(wordAllBoolQuery);
}
} else if ("eq".equals(rule)) {
builder2.must(QueryBuilders.termQuery(field + ".keyword", val));
} else if ("ne".equals(rule)) {
builder2.mustNot(QueryBuilders.termQuery(field + ".keyword", val));
} else if ("in".equals(rule)) {
builder2.must(QueryBuilders.termsQuery(field + ".keyword", val.split(" |\\+|,|,|;|;")));
} else if ("not_in".equals(rule)) {
builder2.mustNot(QueryBuilders.termsQuery(field + ".keyword", val.split(" |\\+|,|,|;|;")));
} else if ("like".equals(rule)) {
builder2.must(QueryBuilders.matchPhrasePrefixQuery(field, val));
} else if ("not_like".equals(rule)) {
builder2.mustNot(QueryBuilders.matchPhrasePrefixQuery(field, val));
} else if ("keyWordsGroup".equals(rule)) {
BoolQueryBuilder wordAllBoolQuery = QueryBuilders.boolQuery();
String[] andWords = val.split("\\+");
for (String words : andWords) {
String replace = words.replace("(", "").replace(")", "");
BoolQueryBuilder wordOrBoolQuery = QueryBuilders.boolQuery();
for (String word : replace.split("\\|")) {
wordOrBoolQuery.should(QueryBuilders.matchPhraseQuery(field, word));
}
wordAllBoolQuery.must(wordOrBoolQuery);
}
builder2.must(wordAllBoolQuery);
}
}
if ("or".equals(superQueryMatchType)) {
superBuilder.should(builder2);
} else {
superBuilder.must(builder2);
}
}
return superBuilder;
} catch (Exception e) {
log.error("高级查询条件封装失败,e:{},params:{}", e.getMessage(), superQueryParams);
}
}
return null;
}
private BoolQueryBuilder multiMatchQuery(String word) {
BoolQueryBuilder fullTextBoolQuery = QueryBuilders.boolQuery();
String[] fullTextFields = new String[]{"title", "summary", "content"};
for (String fullTextField : fullTextFields) {
fullTextBoolQuery.should(QueryBuilders.matchPhraseQuery(fullTextField, word));
}
return fullTextBoolQuery;
}
} }
...@@ -22,6 +22,13 @@ public class SearchCondition { ...@@ -22,6 +22,13 @@ public class SearchCondition {
@FieldDescription(value = "搜索词") @FieldDescription(value = "搜索词")
private String searchWord; private String searchWord;
/*------高级查询条件---start-------------------*/
//规则
private String superQueryMatchType;
//条件(url转码后的json)
private String superQueryParams;
/*------高级查询条件---end-------------------*/
//开始时间 //开始时间
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
...@@ -36,14 +43,15 @@ public class SearchCondition { ...@@ -36,14 +43,15 @@ public class SearchCondition {
@FieldDescription(value = "专题库类型") @FieldDescription(value = "专题库类型")
private List<Integer> classificationType; private List<Integer> classificationType;
/**原创性(0-非原创;1-原创;2-疑似)*/ /**
* 原创性(0-非原创;1-原创;2-疑似)
*/
@FieldDescription(value = "原创性") @FieldDescription(value = "原创性")
private String originality; private String originality;
//审核状态(1-通过;2-未审核;3-暂定;4-删除;5-免审核) //审核状态(null-全部;1-通过;2-未审核;3-暂定;4-删除;5-免审核)
@FieldDescription(value = "审核状态") @FieldDescription(value = "审核状态")
private Integer status; private Integer auditStatus;
//审核操作(0:未审核 1:审核通过 2:审核未通过 3:暂定 默认值为0) //审核操作(0:未审核 1:审核通过 2:审核未通过 3:暂定 默认值为0)
private Integer checkStatus; private Integer checkStatus;
//删除标记(1:删除;0:未删除) //删除标记(1:删除;0:未删除)
...@@ -59,14 +67,18 @@ public class SearchCondition { ...@@ -59,14 +67,18 @@ public class SearchCondition {
@FieldDescription(value = "组合标签查询") @FieldDescription(value = "组合标签查询")
private String composeSearchLabelIds; private String composeSearchLabelIds;
/**----企业类标签筛选----**/ /**
* ----企业类标签筛选----
**/
//企业类标签id集合 //企业类标签id集合
@FieldDescription(value = "企业类标签id集合") @FieldDescription(value = "企业类标签id集合")
private List<String> enterpriseLabelTypeIds; private List<String> enterpriseLabelTypeIds;
//企业信用代码集合 //企业信用代码集合
@FieldDescription(value = "企业信用代码集合") @FieldDescription(value = "企业信用代码集合")
private List<String> socialCreditCodeList; private List<String> socialCreditCodeList;
/**----企业类标签id集合----**/ /**
* ----企业类标签id集合----
**/
//专题关联标签值id集合 //专题关联标签值id集合
@FieldDescription(value = "专题关联标签值id集合") @FieldDescription(value = "专题关联标签值id集合")
private List<String> labelIds; private List<String> labelIds;
......
...@@ -2132,7 +2132,18 @@ public class EsService { ...@@ -2132,7 +2132,18 @@ public class EsService {
if (CollectionUtils.isNotEmpty(searchWordList)) { if (CollectionUtils.isNotEmpty(searchWordList)) {
handlerSearchWordList(boolQuery, searchWordList); handlerSearchWordList(boolQuery, searchWordList);
} else {//平台 搜索词方式 } else {//平台 搜索词方式
if (StringUtils.isNotEmpty(searchCondition.getSearch())) { String searchScope = searchCondition.getSearchScope();
String searchWord = searchCondition.getSearchWord();
if (StringUtils.isNotEmpty(searchWord)) {
if ("all".equalsIgnoreCase(searchScope)) {
MultiMatchQueryBuilder multiMatchQuery = QueryBuilders.multiMatchQuery(searchWord, "title", "content", "origin");
multiMatchQuery.type(MultiMatchQueryBuilder.Type.PHRASE);
boolQuery.must(multiMatchQuery);
} else {
boolQuery.must(QueryBuilders.matchPhraseQuery(searchScope, searchWord));
}
}
/*if (StringUtils.isNotEmpty(searchCondition.getSearch())) {
boolQuery.must(QueryBuilders.multiMatchQuery(searchCondition.getSearch(), "title", "content")); boolQuery.must(QueryBuilders.multiMatchQuery(searchCondition.getSearch(), "title", "content"));
} }
if (StringUtils.isNotEmpty(searchCondition.getContent())) { if (StringUtils.isNotEmpty(searchCondition.getContent())) {
...@@ -2149,7 +2160,7 @@ public class EsService { ...@@ -2149,7 +2160,7 @@ public class EsService {
MatchPhraseQueryBuilder relationNameQuery = QueryBuilders.matchPhraseQuery("labels.relationName", searchCondition.getLabelName()); MatchPhraseQueryBuilder relationNameQuery = QueryBuilders.matchPhraseQuery("labels.relationName", searchCondition.getLabelName());
nestedBoolQueryBuilder.should(QueryBuilders.nestedQuery("labels", relationNameQuery, ScoreMode.None)); nestedBoolQueryBuilder.should(QueryBuilders.nestedQuery("labels", relationNameQuery, ScoreMode.None));
boolQuery.must(nestedBoolQueryBuilder); boolQuery.must(nestedBoolQueryBuilder);
} }*/
} }
if (searchCondition.getLabelMark() != null) { if (searchCondition.getLabelMark() != null) {
BoolQueryBuilder nestedBoolQueryBuilder = QueryBuilders.boolQuery(); BoolQueryBuilder nestedBoolQueryBuilder = QueryBuilders.boolQuery();
...@@ -2174,6 +2185,22 @@ public class EsService { ...@@ -2174,6 +2185,22 @@ public class EsService {
boolQuery.must(QueryBuilders.termQuery("deleteFlag", 1)); boolQuery.must(QueryBuilders.termQuery("deleteFlag", 1));
} }
} else { } else {
//审核状态-平台(null-全部;1-通过;2-未审核;3-暂定;4-删除;5-免审核)
Integer auditStatus = searchCondition.getAuditStatus();
if (auditStatus != null) {
if (auditStatus == 1) {
searchCondition.setCheckStatus(1);
} else if (auditStatus == 2) {
searchCondition.setCheckStatus(0);
searchCondition.setDeleteFlag(0);
} else if (auditStatus == 3) {
searchCondition.setCheckStatus(3);
} else if (auditStatus == 4) {
searchCondition.setDeleteFlag(1);
} else if (auditStatus == 5) {
searchCondition.setIsFreeCheck(1);
}
}
Integer checkStatus = searchCondition.getCheckStatus(); Integer checkStatus = searchCondition.getCheckStatus();
Integer deleteFlag = searchCondition.getDeleteFlag(); Integer deleteFlag = searchCondition.getDeleteFlag();
if (checkStatus != null) { if (checkStatus != null) {
......
...@@ -25,12 +25,18 @@ public class InfoDataSearchCondition { ...@@ -25,12 +25,18 @@ public class InfoDataSearchCondition {
//内容 //内容
private String content; private String content;
//发布时间
private String publishDate;
//来源 //来源
private String origin; private String origin;
//搜索范围(all、title、content、origin)
private String searchScope;
//搜索词
private String searchWord;
//发布时间
private String publishDate;
//开始时间 //开始时间
private String startTime; private String startTime;
...@@ -50,15 +56,15 @@ public class InfoDataSearchCondition { ...@@ -50,15 +56,15 @@ public class InfoDataSearchCondition {
/**原创性(0-非原创;1-原创;2-疑似)*/ /**原创性(0-非原创;1-原创;2-疑似)*/
private String originality; private String originality;
//资讯状态-研究中心(0-全部;1-模型推荐;2-精选;3-待定;4-移除),和checkStatus、deleteFlag、isFreeCheck互斥 //资讯状态-研究中心(0-全部;1-模型推荐;2-精选;3-待定;4-移除),和auditStatus互斥
private Integer status; private Integer status;
//平台-审核状态(null-全部;1-通过;2-未审核;3-暂定;4-删除;5-免审核)
private Integer auditStatus;
//审核操作(0:未审核 1:审核通过 2:审核未通过 3:暂定 默认值为0) //审核操作(0:未审核 1:审核通过 2:审核未通过 3:暂定 默认值为0)
private Integer checkStatus; private Integer checkStatus;
//删除标记(1:删除;0:未删除) //删除标记(1:删除;0:未删除)
private Integer deleteFlag; private Integer deleteFlag;
//是否免审核(1-是;0-否) //是否免审核(1-是;0-否)
private Integer isFreeCheck; private Integer isFreeCheck;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论