提交 dbcd0616 作者: 925993793@qq.com

专题列表页bug修改、专题报告增加按标签分析接口

上级 31faf612
......@@ -4,8 +4,10 @@ import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.zzsn.event.constant.Constants;
import com.zzsn.event.constant.Result;
import com.zzsn.event.entity.SysDictItem;
import com.zzsn.event.service.CommonService;
import com.zzsn.event.service.SubjectService;
import com.zzsn.event.service.SysDictItemService;
import com.zzsn.event.util.DateUtil;
import com.zzsn.event.util.EsDateUtil;
import com.zzsn.event.util.EsIndexUtil;
......@@ -27,6 +29,8 @@ import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggre
import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval;
import org.elasticsearch.search.aggregations.bucket.histogram.Histogram;
import org.elasticsearch.search.aggregations.bucket.histogram.ParsedDateHistogram;
import org.elasticsearch.search.aggregations.bucket.nested.NestedAggregationBuilder;
import org.elasticsearch.search.aggregations.bucket.nested.ParsedNested;
import org.elasticsearch.search.aggregations.bucket.terms.IncludeExclude;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
......@@ -56,6 +60,8 @@ public class ReportDataController {
private SubjectService subjectService;
@Autowired
private CommonService commonService;
@Autowired
private SysDictItemService dictItemService;
/**
* 检索字段集合
......@@ -227,6 +233,57 @@ public class ReportDataController {
}
return Result.OK(list);
}
/**
* 标签分析(按标签分组)
*
* @param searchCondition 筛选条件
* @author lkg
* @date 2024/12/26
*/
@PostMapping("/labelAnalysis")
public Result<?> labelAnalysis(@RequestBody SearchCondition searchCondition) {
String composeSearchLabelIds = searchCondition.getComposeSearchLabelIds();
if (StringUtils.isBlank(composeSearchLabelIds)) {
return Result.FAIL("请选择标签");
}
List<CountVO> list = new ArrayList<>();
String[] indexArr = getIndex(searchCondition.getSubjectId());
SearchRequest searchRequest = new SearchRequest(indexArr);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.trackTotalHits(true);
searchSourceBuilder.size(0);
BoolQueryBuilder boolQuery = buildQuery(searchCondition);
searchSourceBuilder.query(boolQuery);
String[] labelIdArr = composeSearchLabelIds.replace(";", ",").split(",");
NestedAggregationBuilder nestedAggregationBuilder = AggregationBuilders.nested("labels", "labels")
.subAggregation(AggregationBuilders.terms("groupLabel")
.field("labels.relationId")
.size(labelIdArr.length)
.includeExclude(new IncludeExclude(labelIdArr, null)));
searchSourceBuilder.aggregation(nestedAggregationBuilder);
searchRequest.source(searchSourceBuilder);
try {
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
Aggregations aggregations = searchResponse.getAggregations();
ParsedNested labels = aggregations.get("labels");
Aggregations labelsAggregations = labels.getAggregations();
Terms groupTag = labelsAggregations.get("groupLabel");
List<? extends Terms.Bucket> buckets = groupTag.getBuckets();
for (Terms.Bucket bucket : buckets) {
String key = bucket.getKeyAsString();
SysDictItem byId = dictItemService.getById(key);
if (byId != null) {
CountVO countVO = new CountVO();
countVO.setName(byId.getItemText());
countVO.setValue(bucket.getDocCount());
list.add(countVO);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return Result.OK(list);
}
......
......@@ -212,13 +212,29 @@ public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, Subject> impl
List<StatisticVO> unCheckNumList = esService.subjectStatisticInfo(subjectIds, 0, null);
Map<String, StatisticVO> unCheckNumMap = unCheckNumList.stream().collect(Collectors.toMap(StatisticVO::getSubjectId, e->e));
//绑定全部信息源的专题
Map<String, Integer> infoSourceNumMap = new HashMap<>();
List<Subject> subjects = baseMapper.selectBatchIds(subjectIds);
Optional<Subject> any = subjects.stream().filter(f -> StrUtil.isNotBlank(f.getDataScope())).findAny();
if (any.isPresent()) {
int count = infoSourceService.count();
subjects.forEach(e -> {
if (StrUtil.isNotBlank(e.getDataScope()) && e.getDataScope().contains("1")) {
infoSourceNumMap.put(e.getId(), count);
}
});
}
for (String subjectId : subjectIds) {
SubjectStatisticInfo subjectStatisticInfo = new SubjectStatisticInfo();
subjectStatisticInfo.setSubjectId(subjectId);
subjectStatisticInfo.setTotalNum(totalAndLatestDateMap.get(subjectId).getCount());
subjectStatisticInfo.setLatestDataDate(totalAndLatestDateMap.get(subjectId).getPublishDate());
subjectStatisticInfo.setUnCheckNum(unCheckNumMap.get(subjectId).getCount());
subjectStatisticInfo.setBindSourceNum(sourceCountMap.get(subjectId) == null ? 0 : sourceCountMap.get(subjectId));
if (infoSourceNumMap.containsKey(subjectId)) {
subjectStatisticInfo.setBindSourceNum(infoSourceNumMap.get(subjectId));
} else {
subjectStatisticInfo.setBindSourceNum(sourceCountMap.get(subjectId) == null ? 0 : sourceCountMap.get(subjectId));
}
subjectStatisticInfo.setBindKeywordNum(keyWordsNumMap.get(subjectId) == null ? 0 : keyWordsNumMap.get(subjectId));
list.add(subjectStatisticInfo);
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论