提交 1820fab7 作者: 925993793@qq.com

【fix】导出时数据查询bug修改

上级 b3c4febe
...@@ -360,7 +360,7 @@ public class FileController { ...@@ -360,7 +360,7 @@ public class FileController {
fetchFields = new String[]{"id", "title", "content", "origin", "publishDate", "sourceAddress"}; fetchFields = new String[]{"id", "title", "content", "origin", "publishDate", "sourceAddress"};
} }
searchCondition.setFetchFields(fetchFields); searchCondition.setFetchFields(fetchFields);
List<SpecialInformation> informationList = esService.informationList(searchCondition); List<SpecialInformation> informationList = informationService.informationAllList(searchCondition);
Map<String, Object> map = formatDocData(informationList, null, exportType); Map<String, Object> map = formatDocData(informationList, null, exportType);
Template template = FreeMarkerConfiguration.get().getTemplate("EVENT_DATA_REPORT.ftl", "UTF-8"); Template template = FreeMarkerConfiguration.get().getTemplate("EVENT_DATA_REPORT.ftl", "UTF-8");
bos = new ByteArrayOutputStream(); bos = new ByteArrayOutputStream();
...@@ -433,7 +433,7 @@ public class FileController { ...@@ -433,7 +433,7 @@ public class FileController {
SXSSFWorkbook workbook = new SXSSFWorkbook(); SXSSFWorkbook workbook = new SXSSFWorkbook();
for (int i = 1; ; i++) { for (int i = 1; ; i++) {
searchCondition.setPageNo(i); searchCondition.setPageNo(i);
List<SpecialInformation> informationList = esService.informationList(searchCondition); List<SpecialInformation> informationList = informationService.informationAllList(searchCondition);
log.info("本次循环-{},数据量为-{}", i, informationList.size()); log.info("本次循环-{},数据量为-{}", i, informationList.size());
if (CollectionUtils.isEmpty(informationList)) { if (CollectionUtils.isEmpty(informationList)) {
break; break;
......
...@@ -8,10 +8,7 @@ import com.zzsn.event.entity.InfoSource; ...@@ -8,10 +8,7 @@ import com.zzsn.event.entity.InfoSource;
import com.zzsn.event.entity.Subject; import com.zzsn.event.entity.Subject;
import com.zzsn.event.entity.SysDictItem; import com.zzsn.event.entity.SysDictItem;
import com.zzsn.event.es.EsService; import com.zzsn.event.es.EsService;
import com.zzsn.event.service.ClbLabelService; import com.zzsn.event.service.*;
import com.zzsn.event.service.IInfoSourceService;
import com.zzsn.event.service.SubjectService;
import com.zzsn.event.service.SysDictItemService;
import com.zzsn.event.util.DateUtil; import com.zzsn.event.util.DateUtil;
import com.zzsn.event.vo.*; import com.zzsn.event.vo.*;
import com.zzsn.event.vo.es.Label; import com.zzsn.event.vo.es.Label;
...@@ -47,6 +44,8 @@ public class StatisticalAnalysisController { ...@@ -47,6 +44,8 @@ public class StatisticalAnalysisController {
private SysDictItemService sysDictItemService; private SysDictItemService sysDictItemService;
@Autowired @Autowired
private ClbLabelService clbLabelService; private ClbLabelService clbLabelService;
@Autowired
private InformationService informationService;
/** /**
* 概述分析 * 概述分析
...@@ -76,7 +75,7 @@ public class StatisticalAnalysisController { ...@@ -76,7 +75,7 @@ public class StatisticalAnalysisController {
} else { } else {
String[] fetchFields = new String[]{"id", "sid", "labels"}; String[] fetchFields = new String[]{"id", "sid", "labels"};
searchCondition.setFetchFields(fetchFields); searchCondition.setFetchFields(fetchFields);
List<SpecialInformation> specialInformationList = esService.informationList(searchCondition); List<SpecialInformation> specialInformationList = informationService.informationAllList(searchCondition);
totalCount = specialInformationList.size(); totalCount = specialInformationList.size();
Map<String, List<SpecialInformation>> map = buildMap(specialInformationList, labelMap); Map<String, List<SpecialInformation>> map = buildMap(specialInformationList, labelMap);
for (Map.Entry<String, List<SpecialInformation>> entry : map.entrySet()) { for (Map.Entry<String, List<SpecialInformation>> entry : map.entrySet()) {
...@@ -114,7 +113,7 @@ public class StatisticalAnalysisController { ...@@ -114,7 +113,7 @@ public class StatisticalAnalysisController {
} else { } else {
String[] fetchFields = new String[]{"id", "classificationType", "publishDate"}; String[] fetchFields = new String[]{"id", "classificationType", "publishDate"};
searchCondition.setFetchFields(fetchFields); searchCondition.setFetchFields(fetchFields);
List<SpecialInformation> informationList = esService.informationList(searchCondition); List<SpecialInformation> informationList = informationService.informationAllList(searchCondition);
String groupType = searchCondition.getGroupType(); String groupType = searchCondition.getGroupType();
String format = null; String format = null;
if ("year".equalsIgnoreCase(groupType)) { if ("year".equalsIgnoreCase(groupType)) {
...@@ -174,7 +173,7 @@ public class StatisticalAnalysisController { ...@@ -174,7 +173,7 @@ public class StatisticalAnalysisController {
} else { } else {
String[] fetchFields = new String[]{"id", "classificationType"}; String[] fetchFields = new String[]{"id", "classificationType"};
searchCondition.setFetchFields(fetchFields); searchCondition.setFetchFields(fetchFields);
List<SpecialInformation> informationList = esService.informationList(searchCondition); List<SpecialInformation> informationList = informationService.informationAllList(searchCondition);
Map<Integer, List<SpecialInformation>> map = informationList.stream() Map<Integer, List<SpecialInformation>> map = informationList.stream()
.collect(Collectors.groupingBy(SpecialInformation::getClassificationType)); .collect(Collectors.groupingBy(SpecialInformation::getClassificationType));
for (Map.Entry<Integer, List<SpecialInformation>> entry : map.entrySet()) { for (Map.Entry<Integer, List<SpecialInformation>> entry : map.entrySet()) {
...@@ -208,7 +207,7 @@ public class StatisticalAnalysisController { ...@@ -208,7 +207,7 @@ public class StatisticalAnalysisController {
} else { } else {
String[] fetchFields = new String[]{"id", "labels"}; String[] fetchFields = new String[]{"id", "labels"};
searchCondition.setFetchFields(fetchFields); searchCondition.setFetchFields(fetchFields);
List<SpecialInformation> specialInformationList = esService.informationList(searchCondition); List<SpecialInformation> specialInformationList = informationService.informationAllList(searchCondition);
Map<String, List<SpecialInformation>> map = buildMap(specialInformationList, labelMap); Map<String, List<SpecialInformation>> map = buildMap(specialInformationList, labelMap);
for (Map.Entry<String, List<SpecialInformation>> entry : map.entrySet()) { for (Map.Entry<String, List<SpecialInformation>> entry : map.entrySet()) {
CountVO countVO = new CountVO(); CountVO countVO = new CountVO();
...@@ -245,7 +244,7 @@ public class StatisticalAnalysisController { ...@@ -245,7 +244,7 @@ public class StatisticalAnalysisController {
} else { } else {
String[] fetchFields = new String[]{"id", "sid"}; String[] fetchFields = new String[]{"id", "sid"};
searchCondition.setFetchFields(fetchFields); searchCondition.setFetchFields(fetchFields);
List<SpecialInformation> informationList = esService.informationList(searchCondition); List<SpecialInformation> informationList = informationService.informationAllList(searchCondition);
Map<String, List<SpecialInformation>> map = informationList.stream() Map<String, List<SpecialInformation>> map = informationList.stream()
.collect(Collectors.groupingBy(SpecialInformation::getSid)); .collect(Collectors.groupingBy(SpecialInformation::getSid));
for (Map.Entry<String, List<SpecialInformation>> entry : map.entrySet()) { for (Map.Entry<String, List<SpecialInformation>> entry : map.entrySet()) {
......
...@@ -1158,27 +1158,24 @@ public class EsService { ...@@ -1158,27 +1158,24 @@ public class EsService {
} }
//默认最大数量是10000,设置为true后,显示准确数量 //默认最大数量是10000,设置为true后,显示准确数量
searchSourceBuilder.trackTotalHits(true); searchSourceBuilder.trackTotalHits(true);
//设置分页参数
Integer pageNo = searchCondition.getPageNo();
Integer pageSize = searchCondition.getPageSize();
//创建查询对象 //创建查询对象
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery(); BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
//判断ids字段是否为空,若不为空,则表示按照id勾选 //判断ids字段是否为空,若不为空,则表示按照id勾选
List<String> ids = searchCondition.getIds(); List<String> ids = searchCondition.getIds();
if (CollectionUtils.isNotEmpty(ids)) { if (CollectionUtils.isNotEmpty(ids)) {
searchSourceBuilder.size(ids.size());
boolQuery.must(QueryBuilders.termsQuery("id", ids)); boolQuery.must(QueryBuilders.termsQuery("id", ids));
List<String> sourceIdList = searchCondition.getSourceIdList(); List<String> sourceIdList = searchCondition.getSourceIdList();
if (CollectionUtils.isNotEmpty(sourceIdList)) { if (CollectionUtils.isNotEmpty(sourceIdList)) {
boolQuery.must(QueryBuilders.termsQuery("sid.keyword", sourceIdList)); boolQuery.must(QueryBuilders.termsQuery("sid.keyword", sourceIdList));
} }
} else { } else {
//设置分页参数
Integer pageNo = searchCondition.getPageNo();
Integer pageSize = searchCondition.getPageSize();
Integer num = searchCondition.getNum(); Integer num = searchCondition.getNum();
if (num != null) { if (num != null) {
pageSize = num; pageSize = num;
} }
searchSourceBuilder.size(pageSize);
searchSourceBuilder.from((pageNo - 1) * pageSize);
List<String> subjectIdList = new ArrayList<>(); List<String> subjectIdList = new ArrayList<>();
//判断是否是专题 //判断是否是专题
if ("1".equals(searchCondition.getIsSubject())) { if ("1".equals(searchCondition.getIsSubject())) {
...@@ -1199,6 +1196,8 @@ public class EsService { ...@@ -1199,6 +1196,8 @@ public class EsService {
} }
boolQuery = buildQuery(searchCondition, subjectIdList); boolQuery = buildQuery(searchCondition, subjectIdList);
} }
searchSourceBuilder.from((pageNo - 1) * pageSize);
searchSourceBuilder.size(pageSize);
searchSourceBuilder.query(boolQuery); searchSourceBuilder.query(boolQuery);
searchRequest.source(searchSourceBuilder); searchRequest.source(searchSourceBuilder);
List<SpecialInformation> dataList = new ArrayList<>(); List<SpecialInformation> dataList = new ArrayList<>();
......
...@@ -7,6 +7,7 @@ import com.zzsn.event.entity.ClbFileOperationLog; ...@@ -7,6 +7,7 @@ import com.zzsn.event.entity.ClbFileOperationLog;
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.SpecialInformation;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
...@@ -218,4 +219,13 @@ public interface InformationService { ...@@ -218,4 +219,13 @@ public interface InformationService {
* @date 2025/2/20 * @date 2025/2/20
*/ */
void supplyByCondition(String subjectId, List<String> themeIds); void supplyByCondition(String subjectId, List<String> themeIds);
/**
* 获取所有资讯列表
*
* @param searchCondition 检索条件
* @author lkg
* @date 2025/2/28
*/
List<SpecialInformation> informationAllList(InfoDataSearchCondition searchCondition);
} }
...@@ -289,40 +289,46 @@ public class InformationServiceImpl implements InformationService { ...@@ -289,40 +289,46 @@ public class InformationServiceImpl implements InformationService {
public void saveAsDataSet(InfoDataSearchCondition searchCondition) { public void saveAsDataSet(InfoDataSearchCondition searchCondition) {
String[] fetchFields = new String[]{"id", "labels"}; String[] fetchFields = new String[]{"id", "labels"};
searchCondition.setFetchFields(fetchFields); searchCondition.setFetchFields(fetchFields);
searchCondition.setPageSize(300);
Label dataSet = new Label(); Label dataSet = new Label();
String dataSetId = searchCondition.getDataSetId(); String dataSetId = searchCondition.getDataSetId();
dataSet.setRelationId(dataSetId); dataSet.setRelationId(dataSetId);
Map<String, List<SpecialInformation>> map = new HashMap<>(); Map<String, List<SpecialInformation>> map = new HashMap<>();
for (int i = 1; ; i++) { Integer num = searchCondition.getNum();
searchCondition.setPageNo(i); List<SpecialInformation> informationList = this.informationAllList(searchCondition);
List<SpecialInformation> informationList = esService.informationList(searchCondition); formatUpdateMap(map,informationList,dataSet);
log.info("保存数据集:本次循环-{},数据量为-{}", i, informationList.size()); map.forEach((k, v) -> esOpUtil.docUpdateBulk(k, v));
if (CollectionUtils.isEmpty(informationList)) { }
break;
} /**
for (SpecialInformation information : informationList) { * 格式化数据
String index = information.getDbIndex(); *
List<Label> labels = information.getLabels(); * @param map 待更新的数据map集合
if (CollectionUtils.isNotEmpty(labels)) { * @param informationList 查询到的数据集合
boolean present = labels.stream().anyMatch(label -> label.getRelationId().equals(dataSetId)); * @param dataSet 数据集标签信息
if (!present) { * @author lkg
labels.add(dataSet); * @date 2025/2/28
} */
} else { private void formatUpdateMap(Map<String, List<SpecialInformation>> map,List<SpecialInformation> informationList,Label dataSet){
for (SpecialInformation information : informationList) {
String index = information.getDbIndex();
List<Label> labels = information.getLabels();
if (CollectionUtils.isNotEmpty(labels)) {
boolean present = labels.stream().anyMatch(label -> label.getRelationId().equals(dataSet.getRelationId()));
if (!present) {
labels.add(dataSet); labels.add(dataSet);
} }
information.setLabels(labels); } else {
if (map.containsKey(index)) { labels.add(dataSet);
map.get(index).add(information); }
} else { information.setLabels(labels);
List<SpecialInformation> list = new ArrayList<>(); if (map.containsKey(index)) {
list.add(information); map.get(index).add(information);
map.put(index, list); } else {
} List<SpecialInformation> list = new ArrayList<>();
list.add(information);
map.put(index, list);
} }
} }
map.forEach((k, v) -> esOpUtil.docUpdateBulk(k, v));
} }
@Override @Override
...@@ -923,7 +929,27 @@ public class InformationServiceImpl implements InformationService { ...@@ -923,7 +929,27 @@ public class InformationServiceImpl implements InformationService {
} }
redisUtil.rpushMultipleValues(Constants.HISTORY_SUBJECT_DATE_QUEUE + subject.getSubjectCode(),redisCacheList.toArray(new String[0])); redisUtil.rpushMultipleValues(Constants.HISTORY_SUBJECT_DATE_QUEUE + subject.getSubjectCode(),redisCacheList.toArray(new String[0]));
} }
}
@Override
public List<SpecialInformation> informationAllList(InfoDataSearchCondition searchCondition) {
List<SpecialInformation> informationList = new ArrayList<>();
Integer num = searchCondition.getNum();
if (num == null) {
searchCondition.setPageSize(300);
for (int i = 1; ; i++) {
searchCondition.setPageNo(i);
List<SpecialInformation> list = esService.informationList(searchCondition);
log.info("保存数据集:本次循环-{},数据量为-{}", i, list.size());
if (CollectionUtils.isEmpty(list)) {
break;
}
informationList.addAll(list);
}
} else {
informationList = esService.informationList(searchCondition);
}
return informationList;
} }
private void formatLabel(List<LabelModelVo> labelModelVos, DisplayInfo info) { private void formatLabel(List<LabelModelVo> labelModelVos, DisplayInfo info) {
......
...@@ -71,9 +71,9 @@ public class SubjectSimpleServiceImpl implements SubjectSimpleService { ...@@ -71,9 +71,9 @@ public class SubjectSimpleServiceImpl implements SubjectSimpleService {
private ScoreModelService scoreModelService; private ScoreModelService scoreModelService;
@Autowired @Autowired
private ConfigurationMessageService configurationMessageService; private ConfigurationMessageService configurationMessageService;
@Autowired @Autowired
private EsService esService; private InformationService informationService;
@Autowired @Autowired
private EsOpUtil esOpUtil; private EsOpUtil esOpUtil;
@Autowired @Autowired
...@@ -371,7 +371,7 @@ public class SubjectSimpleServiceImpl implements SubjectSimpleService { ...@@ -371,7 +371,7 @@ public class SubjectSimpleServiceImpl implements SubjectSimpleService {
String[] fetchFields = new String[]{"id", "checkStatus"}; String[] fetchFields = new String[]{"id", "checkStatus"};
searchCondition.setFetchFields(fetchFields); searchCondition.setFetchFields(fetchFields);
Map<String, List<SpecialInformation>> updateMap = new HashMap<>(); Map<String, List<SpecialInformation>> updateMap = new HashMap<>();
List<SpecialInformation> informationList = esService.informationList(searchCondition); List<SpecialInformation> informationList = informationService.informationAllList(searchCondition);
for (SpecialInformation information : informationList) { for (SpecialInformation information : informationList) {
String index = information.getDbIndex(); String index = information.getDbIndex();
information.setCheckStatus(1); information.setCheckStatus(1);
...@@ -391,7 +391,7 @@ public class SubjectSimpleServiceImpl implements SubjectSimpleService { ...@@ -391,7 +391,7 @@ public class SubjectSimpleServiceImpl implements SubjectSimpleService {
String[] fetchFields = new String[]{"id", "checkStatus"}; String[] fetchFields = new String[]{"id", "checkStatus"};
searchCondition.setFetchFields(fetchFields); searchCondition.setFetchFields(fetchFields);
Map<String, List<SpecialInformation>> updateMap = new HashMap<>(); Map<String, List<SpecialInformation>> updateMap = new HashMap<>();
List<SpecialInformation> informationList = esService.informationList(searchCondition); List<SpecialInformation> informationList = informationService.informationAllList(searchCondition);
for (SpecialInformation information : informationList) { for (SpecialInformation information : informationList) {
String index = information.getDbIndex(); String index = information.getDbIndex();
information.setCheckStatus(0); information.setCheckStatus(0);
...@@ -411,7 +411,7 @@ public class SubjectSimpleServiceImpl implements SubjectSimpleService { ...@@ -411,7 +411,7 @@ public class SubjectSimpleServiceImpl implements SubjectSimpleService {
String[] fetchFields = new String[]{"id", "deleteFlag"}; String[] fetchFields = new String[]{"id", "deleteFlag"};
searchCondition.setFetchFields(fetchFields); searchCondition.setFetchFields(fetchFields);
Map<String, List<SpecialInformation>> updateMap = new HashMap<>(); Map<String, List<SpecialInformation>> updateMap = new HashMap<>();
List<SpecialInformation> informationList = esService.informationList(searchCondition); List<SpecialInformation> informationList = informationService.informationAllList(searchCondition);
for (SpecialInformation information : informationList) { for (SpecialInformation information : informationList) {
String index = information.getDbIndex(); String index = information.getDbIndex();
information.setDeleteFlag(1); information.setDeleteFlag(1);
......
...@@ -125,7 +125,7 @@ public class InfoDataSearchCondition { ...@@ -125,7 +125,7 @@ public class InfoDataSearchCondition {
//选择前num条数据 //选择前num条数据
private Integer num; private Integer num;
//资讯id集合-研究中心 //资讯id集合
private List<String> ids; private List<String> ids;
//关联标签名称 //关联标签名称
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论