提交 7abc41da 作者: 925993793@qq.com

根据需求补充接口

上级 feb81032
...@@ -13,11 +13,11 @@ import com.zzsn.event.enums.LabelTypeEnum; ...@@ -13,11 +13,11 @@ import com.zzsn.event.enums.LabelTypeEnum;
import com.zzsn.event.es.EsService; import com.zzsn.event.es.EsService;
import com.zzsn.event.service.*; import com.zzsn.event.service.*;
import com.zzsn.event.util.PythonUtil; import com.zzsn.event.util.PythonUtil;
import com.zzsn.event.util.tree.Node;
import com.zzsn.event.util.user.UserUtil; import com.zzsn.event.util.user.UserUtil;
import com.zzsn.event.util.user.UserVo; import com.zzsn.event.util.user.UserVo;
import com.zzsn.event.vo.*; import com.zzsn.event.vo.*;
import com.zzsn.event.vo.es.DisplayInfo; import com.zzsn.event.vo.es.DisplayInfo;
import com.zzsn.event.vo.es.Label;
import com.zzsn.event.vo.es.SpecialInformation; import com.zzsn.event.vo.es.SpecialInformation;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -564,8 +564,9 @@ public class InformationController { ...@@ -564,8 +564,9 @@ public class InformationController {
@PostMapping("/addToFavorites") @PostMapping("/addToFavorites")
public Result<?> addToFavorites(@RequestBody InfoDataSearchCondition searchCondition) { public Result<?> addToFavorites(@RequestBody InfoDataSearchCondition searchCondition) {
String subjectId = searchCondition.getSubjectId(); String subjectId = searchCondition.getSubjectId();
if (StringUtils.isEmpty(subjectId)) { List<String> ids = searchCondition.getIds();
return Result.FAIL("专题id不能为空"); if (StringUtils.isEmpty(subjectId) && CollectionUtils.isEmpty(ids)) {
return Result.FAIL("专题id和资讯id集合不能同时为空");
} }
informationService.addToFavorites(searchCondition); informationService.addToFavorites(searchCondition);
return Result.OK(); return Result.OK();
...@@ -581,8 +582,9 @@ public class InformationController { ...@@ -581,8 +582,9 @@ public class InformationController {
@PostMapping("/addToPend") @PostMapping("/addToPend")
public Result<?> addToPend(@RequestBody InfoDataSearchCondition searchCondition) { public Result<?> addToPend(@RequestBody InfoDataSearchCondition searchCondition) {
String subjectId = searchCondition.getSubjectId(); String subjectId = searchCondition.getSubjectId();
if (StringUtils.isEmpty(subjectId)) { List<String> ids = searchCondition.getIds();
return Result.FAIL("专题id不能为空"); if (StringUtils.isEmpty(subjectId) && CollectionUtils.isEmpty(ids)) {
return Result.FAIL("专题id和资讯id集合不能同时为空");
} }
informationService.addToPend(searchCondition); informationService.addToPend(searchCondition);
return Result.OK(); return Result.OK();
...@@ -598,8 +600,9 @@ public class InformationController { ...@@ -598,8 +600,9 @@ public class InformationController {
@PostMapping("/addToRemove") @PostMapping("/addToRemove")
public Result<?> addToRemove(@RequestBody InfoDataSearchCondition searchCondition) { public Result<?> addToRemove(@RequestBody InfoDataSearchCondition searchCondition) {
String subjectId = searchCondition.getSubjectId(); String subjectId = searchCondition.getSubjectId();
if (StringUtils.isEmpty(subjectId)) { List<String> ids = searchCondition.getIds();
return Result.FAIL("专题id不能为空"); if (StringUtils.isEmpty(subjectId) && CollectionUtils.isEmpty(ids)) {
return Result.FAIL("专题id和资讯id集合不能同时为空");
} }
informationService.addToRemove(searchCondition); informationService.addToRemove(searchCondition);
return Result.OK(); return Result.OK();
...@@ -650,5 +653,49 @@ public class InformationController { ...@@ -650,5 +653,49 @@ public class InformationController {
return Result.OK(); return Result.OK();
} }
/**
* 资讯批量打标
*
* @param searchCondition 检索条件
* @author lkg
* @date 2025/4/23
*/
@PostMapping("/markTag")
public Result<?> markTag(@RequestBody InfoDataSearchCondition searchCondition) {
String subjectId = searchCondition.getSubjectId();
List<String> ids = searchCondition.getIds();
if (StringUtils.isEmpty(subjectId) && CollectionUtils.isEmpty(ids)) {
return Result.FAIL("专题id和资讯id集合不能同时为空");
}
List<Label> markTags = searchCondition.getMarkTags();
if (CollectionUtils.isEmpty(markTags)) {
return Result.FAIL("标签不能为空");
}
informationService.markTag(searchCondition);
return Result.OK();
}
/**
* 资讯批量删除标签
*
* @param searchCondition 检索条件
* @author lkg
* @date 2025/4/23
*/
@PostMapping("/removeTag")
public Result<?> removeTag(@RequestBody InfoDataSearchCondition searchCondition) {
String subjectId = searchCondition.getSubjectId();
List<String> ids = searchCondition.getIds();
if (StringUtils.isEmpty(subjectId) && CollectionUtils.isEmpty(ids)) {
return Result.FAIL("专题id和资讯id集合不能同时为空");
}
List<Label> markTags = searchCondition.getMarkTags();
if (CollectionUtils.isEmpty(markTags)) {
return Result.FAIL("标签不能为空");
}
informationService.removeTag(searchCondition);
return Result.OK();
}
} }
...@@ -845,10 +845,10 @@ public class EsService { ...@@ -845,10 +845,10 @@ public class EsService {
break; break;
default: default:
NestedSortBuilder nestedWordSortBuilder = new NestedSortBuilder("sortField"); NestedSortBuilder nestedWordSortBuilder = new NestedSortBuilder("sortField");
nestedWordSortBuilder.setFilter(QueryBuilders.termQuery("sortField.fieldType", column)); nestedWordSortBuilder.setFilter(QueryBuilders.termsQuery("sortField.fieldType", Arrays.asList(column.split(","))));
FieldSortBuilder fieldWordSortBuilder = SortBuilders.fieldSort("sortField.fieldLong") FieldSortBuilder fieldWordSortBuilder = SortBuilders.fieldSort("sortField.fieldLong")
.order(sortOrder) .order(sortOrder)
.sortMode(SortMode.MAX) .sortMode(SortMode.SUM)
.setNestedSort(nestedWordSortBuilder); .setNestedSort(nestedWordSortBuilder);
searchSourceBuilder.sort(fieldWordSortBuilder); searchSourceBuilder.sort(fieldWordSortBuilder);
break; break;
...@@ -2225,6 +2225,19 @@ public class EsService { ...@@ -2225,6 +2225,19 @@ public class EsService {
if (maxScore != null) { if (maxScore != null) {
boolQuery.filter(QueryBuilders.rangeQuery("score").lte(maxScore)); boolQuery.filter(QueryBuilders.rangeQuery("score").lte(maxScore));
} }
//正文长度筛选
Integer minContentLength = searchCondition.getMinContentLength();
if (minContentLength != null) {
NestedQueryBuilder nestedQueryBuilder = QueryBuilders
.nestedQuery("sortField", QueryBuilders.rangeQuery("sortField.fieldLong").gte(minContentLength), ScoreMode.None);
boolQuery.filter(nestedQueryBuilder);
}
Integer maxContentLength = searchCondition.getMaxContentLength();
if (maxContentLength != null) {
NestedQueryBuilder nestedQueryBuilder = QueryBuilders
.nestedQuery("sortField", QueryBuilders.rangeQuery("sortField.fieldLong").lte(maxContentLength), ScoreMode.None);
boolQuery.filter(nestedQueryBuilder);
}
//时间过滤筛选-前端传参 //时间过滤筛选-前端传参
if (StringUtils.isNotBlank(searchCondition.getStartTime())) { if (StringUtils.isNotBlank(searchCondition.getStartTime())) {
boolQuery.filter(QueryBuilders.rangeQuery("publishDate").gte(EsDateUtil.esFieldDateFormat(searchCondition.getStartTime()))); boolQuery.filter(QueryBuilders.rangeQuery("publishDate").gte(EsDateUtil.esFieldDateFormat(searchCondition.getStartTime())));
......
...@@ -324,4 +324,22 @@ public interface InformationService { ...@@ -324,4 +324,22 @@ public interface InformationService {
* @date 2025/4/23 * @date 2025/4/23
*/ */
void charReplace(InfoDataSearchCondition searchCondition); void charReplace(InfoDataSearchCondition searchCondition);
/**
* 打标签
*
* @param searchCondition 资讯检索条件
* @author lkg
* @date 2025/4/23
*/
void markTag(InfoDataSearchCondition searchCondition);
/**
* 打标签
*
* @param searchCondition 资讯检索条件
* @author lkg
* @date 2025/4/23
*/
void removeTag(InfoDataSearchCondition searchCondition);
} }
...@@ -1274,6 +1274,52 @@ public class InformationServiceImpl implements InformationService { ...@@ -1274,6 +1274,52 @@ public class InformationServiceImpl implements InformationService {
esOpUtil.batchReplaceScript(indexArr, buildQuery, modifyFields, oldWord, newWord); esOpUtil.batchReplaceScript(indexArr, buildQuery, modifyFields, oldWord, newWord);
} }
@Override
public void markTag(InfoDataSearchCondition searchCondition) {
List<String> subjectIdList = new ArrayList<>();
subjectIdList.add(searchCondition.getSubjectId());
String minCreateTime = subjectService.getMinCreateTime(subjectIdList);
String[] indexArr = EsIndexUtil.getIndexIntervalYearStr(Constants.SUBJECT_INDEX, minCreateTime);
List<String> ids = searchCondition.getIds();
BoolQueryBuilder buildQuery;
if (CollectionUtils.isEmpty(ids)) {
buildQuery = esService.buildQuery(searchCondition, subjectIdList);
} else {
buildQuery = QueryBuilders.boolQuery().must(QueryBuilders.termsQuery("id", ids));
}
Map<String, Object> addParams = new HashMap<>();
for (Label markTag : searchCondition.getMarkTags()) {
Map<String, String> addTag = ObjectUtil.objectToMap(markTag);
addParams.put("labels",addTag);
esOpUtil.batchNestedAddScript(indexArr, buildQuery, addParams,"labels","relationId");
}
}
@Override
public void removeTag(InfoDataSearchCondition searchCondition) {
List<String> subjectIdList = new ArrayList<>();
subjectIdList.add(searchCondition.getSubjectId());
String minCreateTime = subjectService.getMinCreateTime(subjectIdList);
String[] indexArr = EsIndexUtil.getIndexIntervalYearStr(Constants.SUBJECT_INDEX, minCreateTime);
List<String> ids = searchCondition.getIds();
BoolQueryBuilder buildQuery;
if (CollectionUtils.isEmpty(ids)) {
buildQuery = esService.buildQuery(searchCondition, subjectIdList);
} else {
buildQuery = QueryBuilders.boolQuery().must(QueryBuilders.termsQuery("id", ids));
}
List<Label> markTags = searchCondition.getMarkTags();
List<String> tagIds = markTags.stream().map(Label::getRelationId).collect(Collectors.toList());
buildQuery.must(QueryBuilders.nestedQuery("labels",
QueryBuilders.termsQuery("labels.relationId", tagIds),
ScoreMode.None));
for (String tagId : tagIds) {
Map<String, Object> deleteParams = new HashMap<>();
deleteParams.put("relationId", tagId);
esOpUtil.batchNestedDeleteScript(indexArr, buildQuery, deleteParams, "labels");
}
}
private void formatLabel(List<LabelModelVo> labelModelVos, DisplayInfo info) { private void formatLabel(List<LabelModelVo> labelModelVos, DisplayInfo info) {
if (CollectionUtils.isNotEmpty(labelModelVos)) { if (CollectionUtils.isNotEmpty(labelModelVos)) {
List<Label> list = info.getLabels(); List<Label> list = info.getLabels();
......
...@@ -76,7 +76,7 @@ public class InfoDataSearchCondition { ...@@ -76,7 +76,7 @@ public class InfoDataSearchCondition {
//爬虫类型 //爬虫类型
private String crawler; private String crawler;
//组合标签查询(不同类标签之间是与的关系,同一类标签之间是或的关系),示例: "a,b;c,d;e,f" //组合标签查询(不同类标签之间是与的关系,同一类标签之间是或的关系),示例: "a1,a2;c1,c2"
private String composeSearchLabelIds; private String composeSearchLabelIds;
/**----企业类标签筛选----**/ /**----企业类标签筛选----**/
...@@ -120,6 +120,12 @@ public class InfoDataSearchCondition { ...@@ -120,6 +120,12 @@ public class InfoDataSearchCondition {
//最大得分 //最大得分
private Integer maxScore; private Integer maxScore;
//正文长度-研究中心
//最小长度
private Integer minContentLength;
//最大长度
private Integer maxContentLength;
//es查询字段数组 //es查询字段数组
private String[] fetchFields; private String[] fetchFields;
//排除字段数组 //排除字段数组
...@@ -178,4 +184,8 @@ public class InfoDataSearchCondition { ...@@ -178,4 +184,8 @@ public class InfoDataSearchCondition {
/*-----字符串替换---start-------------------*/ /*-----字符串替换---start-------------------*/
private String replaceWord; private String replaceWord;
/*------字符串替换---end-------------------*/ /*------字符串替换---end-------------------*/
/*-----打标签---start-------------------*/
private List<Label> markTags;
/*------打标签---end-------------------*/
} }
...@@ -44,6 +44,8 @@ public class DisplayInfo { ...@@ -44,6 +44,8 @@ public class DisplayInfo {
private String summaryRaw; private String summaryRaw;
//关键词 //关键词
private String keyWords; private String keyWords;
//命中词列表
private List<String> keyWordsList;
//标题 //标题
private String title; private String title;
private String titleRaw; private String titleRaw;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论