提交 01520bf3 作者: zgz

资讯分页列表(根据标签分类分组)

上级 65d82936
...@@ -210,6 +210,20 @@ public class InformationController { ...@@ -210,6 +210,20 @@ public class InformationController {
return Result.OK(pageList); return Result.OK(pageList);
} }
/**
* 资讯分页列表(根据标签分类分组)
*/
@PostMapping("/subjectPageListGroupByLabel")
public Result<?> subjectPageListGroupByLabel(@RequestBody InfoDataSearchCondition searchCondition) {
if (StringUtils.isEmpty(searchCondition.getSubjectId())) {
return Result.FAIL("专题id/专题分类id不能为空");
}
UserVo userVo = UserUtil.getLoginUser();
List<HashMap> pageList = informationService.subjectPageListGroupByLabel(userVo, searchCondition);
return Result.OK(pageList);
}
/** /**
* 保存为数据集 * 保存为数据集
* *
......
...@@ -1822,6 +1822,13 @@ public class EsService { ...@@ -1822,6 +1822,13 @@ public class EsService {
boolQuery.must(nestedBoolQueryBuilder); boolQuery.must(nestedBoolQueryBuilder);
} }
} }
if (searchCondition.getLabelMark() != null) {
BoolQueryBuilder nestedBoolQueryBuilder = QueryBuilders.boolQuery();
MatchPhraseQueryBuilder relationNameQuery = QueryBuilders.matchPhraseQuery("labels.labelMark", searchCondition.getLabelMark());
nestedBoolQueryBuilder.should(QueryBuilders.nestedQuery("labels", relationNameQuery, ScoreMode.None));
boolQuery.must(nestedBoolQueryBuilder);
}
Integer checkStatus = searchCondition.getCheckStatus(); Integer checkStatus = searchCondition.getCheckStatus();
Integer deleteFlag = searchCondition.getDeleteFlag(); Integer deleteFlag = searchCondition.getDeleteFlag();
if (checkStatus != null) { if (checkStatus != null) {
......
...@@ -7,6 +7,7 @@ import com.zzsn.event.util.user.UserVo; ...@@ -7,6 +7,7 @@ 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 java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -36,6 +37,10 @@ public interface InformationService { ...@@ -36,6 +37,10 @@ public interface InformationService {
* @date 2024/5/6 * @date 2024/5/6
*/ */
IPage<DisplayInfo> subjectPageList(UserVo userVo, InfoDataSearchCondition subjectInfo); IPage<DisplayInfo> subjectPageList(UserVo userVo, InfoDataSearchCondition subjectInfo);
/**
* 资讯分页列表(根据标签分类分组)
*/
List<HashMap> subjectPageListGroupByLabel(UserVo userVo, InfoDataSearchCondition subjectInfo);
/** /**
* 保存数据集-研究中心 * 保存数据集-研究中心
......
...@@ -153,6 +153,76 @@ public class InformationServiceImpl implements InformationService { ...@@ -153,6 +153,76 @@ public class InformationServiceImpl implements InformationService {
return page; return page;
} }
@Override
public List<HashMap> subjectPageListGroupByLabel(UserVo userVo, InfoDataSearchCondition searchCondition) {
List<HashMap> list = new ArrayList<>();
Integer category = searchCondition.getCategory();
List<String> subjectIdList = new ArrayList<>();
//判断是否是专题
if ("1".equals(searchCondition.getIsSubject())) {
if (StringUtils.isNotEmpty(searchCondition.getSubjectId())) {
subjectIdList.add(searchCondition.getSubjectId());
}
} else {
//该id其实是专题类别id
//查询类别id的所有明细id
String subjectTypeId = searchCondition.getSubjectId();
List<String> typeIds = subjectTypeService.belowIdList(subjectTypeId, category);
if (category == 1) {
subjectIdList = subjectTypeMapService.selectSubjectByTypeIds(typeIds);
} else if (category == 2) {
subjectIdList = subjectTypeMapService.selectEventByTypeIds(typeIds);
}
}
if (CollectionUtils.isEmpty(subjectIdList)) {
return list;
}
try {
IPage<SpecialInformation> specialInformationIPage = esService.pageListByCondition(searchCondition, subjectIdList);
long total = specialInformationIPage.getTotal();
if (total > 0) {
List<DisplayInfo> dataList = new ArrayList<>();
List<LabelModelVo> labelModelVos = commonService.subjectModelBindLabels(subjectIdList);
Map<String, List<LabelModelVo>> modelMap = labelModelVos.stream().collect(Collectors.groupingBy(LabelModelVo::getSubjectId));
List<SpecialInformation> records = specialInformationIPage.getRecords();
for (SpecialInformation specialInformation : records) {
DisplayInfo info = new DisplayInfo();
BeanUtils.copyProperties(specialInformation, info);
info.setPublishDate(EsDateUtil.esFieldDateMapping(info.getPublishDate()));
//标签处理
List<LabelModelVo> modelVoList = modelMap.get(info.getSubjectId());
formatLabel(modelVoList, info);
dataList.add(info);
}
Map<String, List<DisplayInfo>> mapList = groupedByLabelMark(dataList);
mapList.forEach((relationName, displayInfos) -> {
HashMap map = new HashMap();
map.put("relationName",relationName);
map.put("infoList",displayInfos);
list.add(map);
});
}
} catch (Exception e) {
e.printStackTrace();
}
return list;
}
public Map<String, List<DisplayInfo>> groupedByLabelMark(List<DisplayInfo> dataList) {
// 使用 Stream API 对 dataList 进行分组
Map<String, List<DisplayInfo>> groupedByLabelMark = dataList.stream()
// 将每个 DisplayInfo 对象映射到一个或多个 labelMark
.flatMap(displayInfo -> displayInfo.getLabels().stream()
// 映射每个 Label 到其 labelMark
.filter(label -> label.getRelationName() != null)
.map(label -> new AbstractMap.SimpleEntry<>(label.getRelationName(), displayInfo)))
// 根据 labelMark 进行分组
.collect(Collectors.groupingBy(AbstractMap.SimpleEntry::getKey,
// 将分组后的 DisplayInfo 对象收集到列表中
Collectors.mapping(AbstractMap.SimpleEntry::getValue, Collectors.toList())));
return groupedByLabelMark;
}
@Override @Override
public DisplayInfo queryInfo(Integer type, String index, String id) { public DisplayInfo queryInfo(Integer type, String index, String id) {
DisplayInfo info = (DisplayInfo) esOpUtil.getInfoById(index, id, DisplayInfo.class); DisplayInfo info = (DisplayInfo) esOpUtil.getInfoById(index, id, DisplayInfo.class);
......
...@@ -127,6 +127,9 @@ public class InfoDataSearchCondition { ...@@ -127,6 +127,9 @@ public class InfoDataSearchCondition {
//资讯id集合-研究中心 //资讯id集合-研究中心
private List<String> ids; private List<String> ids;
//关联标签名称
private String labelMark;
/*------资讯导出类参数-研究中心---start-------------------*/ /*------资讯导出类参数-研究中心---start-------------------*/
//导出方式(1-摘要;2-正文) //导出方式(1-摘要;2-正文)
private Integer exportType; private Integer exportType;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论