提交 b3c4febe 作者: 925993793@qq.com

【fix】已入库资讯导出逻辑修改以及其他bug修改

上级 b7bd8c2f
...@@ -7,11 +7,9 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; ...@@ -7,11 +7,9 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.obs.services.model.PutObjectResult; import com.obs.services.model.PutObjectResult;
import com.zzsn.event.config.FreeMarkerConfiguration; import com.zzsn.event.config.FreeMarkerConfiguration;
import com.zzsn.event.constant.Result; import com.zzsn.event.constant.Result;
import com.zzsn.event.entity.ClbFileOperationLog; import com.zzsn.event.entity.*;
import com.zzsn.event.entity.Event;
import com.zzsn.event.entity.FileDownloadCenter;
import com.zzsn.event.entity.Subject;
import com.zzsn.event.es.EsService; import com.zzsn.event.es.EsService;
import com.zzsn.event.exception.FileExportException;
import com.zzsn.event.service.*; import com.zzsn.event.service.*;
import com.zzsn.event.util.*; import com.zzsn.event.util.*;
import com.zzsn.event.util.user.UserUtil; import com.zzsn.event.util.user.UserUtil;
...@@ -31,6 +29,8 @@ import org.apache.poi.xssf.streaming.SXSSFWorkbook; ...@@ -31,6 +29,8 @@ import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest; import org.springframework.web.multipart.MultipartHttpServletRequest;
...@@ -75,6 +75,10 @@ public class FileController { ...@@ -75,6 +75,10 @@ public class FileController {
private CommonService commonService; private CommonService commonService;
@Autowired @Autowired
private IClbFileOperationLogService clbFileOperationLogService; private IClbFileOperationLogService clbFileOperationLogService;
@Autowired
private ISubjectTypeService subjectTypeService;
@Autowired
private ISubjectTypeMapService subjectTypeMapService;
/** /**
* 专题关联信息源采集量统计-导出excel(专题列表页) * 专题关联信息源采集量统计-导出excel(专题列表页)
...@@ -226,17 +230,23 @@ public class FileController { ...@@ -226,17 +230,23 @@ public class FileController {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} else { } else if (count < 100000){
//获取当前登录用户 //获取当前登录用户
UserVo userVo = UserUtil.getLoginUser(); UserVo userVo = UserUtil.getLoginUser();
String subjectName; String subjectName;
Integer category = searchCondition.getCategory(); Integer category = searchCondition.getCategory();
if (category == 1) { String isSubject = searchCondition.getIsSubject();
Subject subject = subjectService.getById(subjectId); if (isSubject.equals("1")) {
subjectName = subject.getSubjectName(); if (category == 1) {
Subject subject = subjectService.getById(subjectId);
subjectName = subject.getSubjectName();
} else {
Event event = eventService.getById(subjectId);
subjectName = event.getEventName();
}
} else { } else {
Event event = eventService.getById(subjectId); SubjectType subjectType = subjectTypeService.getById(subjectId);
subjectName = event.getEventName(); subjectName = subjectType.getTypeName();
} }
FileDownloadCenter fileDownloadCenter = new FileDownloadCenter(); FileDownloadCenter fileDownloadCenter = new FileDownloadCenter();
fileDownloadCenter.setRelationId(subjectId); fileDownloadCenter.setRelationId(subjectId);
...@@ -265,12 +275,17 @@ public class FileController { ...@@ -265,12 +275,17 @@ public class FileController {
} }
fileDownloadCenterService.update(updateWrapper); fileDownloadCenterService.update(updateWrapper);
}); });
} else {
throw new FileExportException("导出数据量超出100000,请联系技术人员");
} }
} else {
throw new FileExportException("数据量为0,无法导出");
} }
} }
/** /**
* 专题资讯导入模板下载-研究中心 * 专题资讯导入模板下载-研究中心
* *
...@@ -391,11 +406,30 @@ public class FileController { ...@@ -391,11 +406,30 @@ public class FileController {
byte[] bytes = null; byte[] bytes = null;
try { try {
String[] arr = new String[]{"得分", "标题", "标题译文", "摘要", "摘要译文", "正文", "正文译文", "作者", "来源", "发布时间", "网址", "专题库类型", "命中词"}; String[] arr = new String[]{"得分", "标题", "标题译文", "摘要", "摘要译文", "正文", "正文译文", "作者", "来源", "发布时间", "网址", "专题库类型", "命中词"};
List<String> subjectIds = new ArrayList<>(); List<String> headers = Arrays.asList(arr);
subjectIds.add(searchCondition.getSubjectId()); List<String> subjectIdList = new ArrayList<>();
List<LabelModelVo> labelTypeVos = commonService.subjectModelBindLabels(subjectIds); //判断是否是专题
//动态补充表头 if ("1".equals(searchCondition.getIsSubject())) {
List<String> headers = supplyHeaders(arr, labelTypeVos); if (StringUtils.isNotEmpty(searchCondition.getSubjectId())) {
subjectIdList.add(searchCondition.getSubjectId());
}
} else {
//该id其实是专题类别id
//查询类别id的所有明细id
Integer category = searchCondition.getCategory();
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);
}
}
List<LabelModelVo> labelTypeVos = commonService.subjectModelBindLabels(subjectIdList);
if (subjectIdList.size() == 1) {
//动态补充表头
headers = supplyHeaders(arr, labelTypeVos);
}
SXSSFWorkbook workbook = new SXSSFWorkbook(); SXSSFWorkbook workbook = new SXSSFWorkbook();
for (int i = 1; ; i++) { for (int i = 1; ; i++) {
searchCondition.setPageNo(i); searchCondition.setPageNo(i);
...@@ -404,7 +438,7 @@ public class FileController { ...@@ -404,7 +438,7 @@ public class FileController {
if (CollectionUtils.isEmpty(informationList)) { if (CollectionUtils.isEmpty(informationList)) {
break; break;
} }
List<List<String>> rows = formatData(informationList, labelTypeVos); List<List<String>> rows = formatData(informationList, labelTypeVos,subjectIdList);
BigExcelExportUtil.exportExcelData(workbook, i - 1, headers, rows, "sheet" + i); BigExcelExportUtil.exportExcelData(workbook, i - 1, headers, rows, "sheet" + i);
log.info("第【{}】个sheet页写入成功", i); log.info("第【{}】个sheet页写入成功", i);
} }
...@@ -429,7 +463,7 @@ public class FileController { ...@@ -429,7 +463,7 @@ public class FileController {
return headers; return headers;
} }
private List<List<String>> formatData(List<SpecialInformation> informationList, List<LabelModelVo> labelTypeVos) { private List<List<String>> formatData(List<SpecialInformation> informationList, List<LabelModelVo> labelTypeVos,List<String> subjectIdList) {
List<List<String>> list = new ArrayList<>(); List<List<String>> list = new ArrayList<>();
for (SpecialInformation info : informationList) { for (SpecialInformation info : informationList) {
List<String> data = new ArrayList<>(); List<String> data = new ArrayList<>();
...@@ -515,60 +549,60 @@ public class FileController { ...@@ -515,60 +549,60 @@ public class FileController {
} else { } else {
data.add(" "); data.add(" ");
} }
//标签处理 if (subjectIdList.size() == 1 && (CollectionUtils.isNotEmpty(labelTypeVos))) {
if (CollectionUtils.isNotEmpty(labelTypeVos)) { List<Label> relationLabels = info.getLabels();
List<Label> relationLabels = info.getLabels(); Map<String, List<Label>> map = new HashMap<>(labelTypeVos.size());
Map<String, List<Label>> map = new HashMap<>(labelTypeVos.size()); for (LabelModelVo labelTypeVo : labelTypeVos) {
for (LabelModelVo labelTypeVo : labelTypeVos) { String labelMark = labelTypeVo.getLabelMark();
String labelMark = labelTypeVo.getLabelMark(); Integer orderNo = labelTypeVo.getOrderNo();
Integer orderNo = labelTypeVo.getOrderNo(); String key = labelMark + "&&" + orderNo;
String key = labelMark + "&&" + orderNo;
List<Label> labels = new ArrayList<>();
if (CollectionUtils.isNotEmpty(relationLabels)) {
labels = relationLabels.stream()
.filter(e -> StringUtils.isNotEmpty(e.getLabelMark()) &&
(e.getLabelMark().equals(labelMark) || e.getLabelMark().contains(labelMark)))
.collect(Collectors.toList());
}
List<Label> labelList = map.get(key);
if (CollectionUtils.isEmpty(labelList)) {
map.put(key, labels);
} else {
labelList.addAll(labels);
map.put(key, labelList);
}
}
for (LabelModelVo labelTypeVo : labelTypeVos) {
String labelMark = labelTypeVo.getLabelMark();
Integer orderNo = labelTypeVo.getOrderNo();
String key = labelMark + "&&" + orderNo;
List<Label> labelList = map.get(key);
if (CollectionUtils.isEmpty(labelList)) {
List<Label> labels = new ArrayList<>(); List<Label> labels = new ArrayList<>();
map.put(key, labels); if (CollectionUtils.isNotEmpty(relationLabels)) {
labels = relationLabels.stream()
.filter(e -> StringUtils.isNotEmpty(e.getLabelMark()) &&
(e.getLabelMark().equals(labelMark) || e.getLabelMark().contains(labelMark)))
.collect(Collectors.toList());
}
List<Label> labelList = map.get(key);
if (CollectionUtils.isEmpty(labelList)) {
map.put(key, labels);
} else {
labelList.addAll(labels);
map.put(key, labelList);
}
} }
} for (LabelModelVo labelTypeVo : labelTypeVos) {
//排序,和表头对应 String labelMark = labelTypeVo.getLabelMark();
LinkedHashMap<String, List<Label>> sortMap = map.entrySet().stream() Integer orderNo = labelTypeVo.getOrderNo();
.sorted((o1, o2) -> { String key = labelMark + "&&" + orderNo;
Integer key1 = Integer.parseInt(o1.getKey().split("&&")[1]); List<Label> labelList = map.get(key);
Integer key2 = Integer.parseInt(o2.getKey().split("&&")[1]); if (CollectionUtils.isEmpty(labelList)) {
return key1.compareTo(key2); List<Label> labels = new ArrayList<>();
}) map.put(key, labels);
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue,
(oldValue, newValue) -> oldValue, LinkedHashMap::new));
for (Map.Entry<String, List<Label>> entry : sortMap.entrySet()) {
List<Label> value = entry.getValue();
if (CollectionUtils.isEmpty(value)) {
data.add(" ");
} else {
StringBuilder sb = new StringBuilder();
for (Label label : value) {
sb.append(",").append(label.getRelationName());
} }
data.add(sb.substring(1));
} }
} //排序,和表头对应
LinkedHashMap<String, List<Label>> sortMap = map.entrySet().stream()
.sorted((o1, o2) -> {
Integer key1 = Integer.parseInt(o1.getKey().split("&&")[1]);
Integer key2 = Integer.parseInt(o2.getKey().split("&&")[1]);
return key1.compareTo(key2);
})
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue,
(oldValue, newValue) -> oldValue, LinkedHashMap::new));
for (Map.Entry<String, List<Label>> entry : sortMap.entrySet()) {
List<Label> value = entry.getValue();
if (CollectionUtils.isEmpty(value)) {
data.add(" ");
} else {
StringBuilder sb = new StringBuilder();
for (Label label : value) {
sb.append(",").append(label.getRelationName());
}
data.add(sb.substring(1));
}
}
} }
list.add(data); list.add(data);
} }
......
...@@ -99,7 +99,7 @@ public class SubjectManageController { ...@@ -99,7 +99,7 @@ public class SubjectManageController {
private KafkaTemplate<String, String> kafkaTemplate; private KafkaTemplate<String, String> kafkaTemplate;
@Autowired @Autowired
private PythonUtil pythonUtil; private PythonUtil pythonUtil;
@Autowired @Autowired(required = false)
private RemoteModelService remoteModelService; private RemoteModelService remoteModelService;
@Autowired @Autowired
private ConfigurationMessageService configurationMessageService; private ConfigurationMessageService configurationMessageService;
......
...@@ -222,6 +222,9 @@ public class InformationController { ...@@ -222,6 +222,9 @@ public class InformationController {
if (StringUtils.isEmpty(searchCondition.getSubjectId())) { if (StringUtils.isEmpty(searchCondition.getSubjectId())) {
return Result.FAIL("专题id/专题分类id不能为空"); return Result.FAIL("专题id/专题分类id不能为空");
} }
if (searchCondition.getCategory() == null) {
return Result.FAIL("专题类型不能为空");
}
UserVo userVo = UserUtil.getLoginUser(); UserVo userVo = UserUtil.getLoginUser();
return informationService.subjectPageListGroupByLabel(userVo, searchCondition); return informationService.subjectPageListGroupByLabel(userVo, searchCondition);
} }
......
...@@ -1089,9 +1089,25 @@ public class EsService { ...@@ -1089,9 +1089,25 @@ public class EsService {
searchSourceBuilder.trackTotalHits(true); searchSourceBuilder.trackTotalHits(true);
searchSourceBuilder.size(0); searchSourceBuilder.size(0);
//创建查询对象 //创建查询对象
List<String> subjectIds = new ArrayList<>(); List<String> subjectIdList = new ArrayList<>();
subjectIds.add(searchCondition.getSubjectId()); //判断是否是专题
BoolQueryBuilder boolQuery = buildQuery(searchCondition, subjectIds); if ("1".equals(searchCondition.getIsSubject())) {
if (StringUtils.isNotEmpty(searchCondition.getSubjectId())) {
subjectIdList.add(searchCondition.getSubjectId());
}
} else {
//该id其实是专题类别id
//查询类别id的所有明细id
Integer category = searchCondition.getCategory();
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);
}
}
BoolQueryBuilder boolQuery = buildQuery(searchCondition, subjectIdList);
searchSourceBuilder.query(boolQuery); searchSourceBuilder.query(boolQuery);
searchRequest.source(searchSourceBuilder); searchRequest.source(searchSourceBuilder);
try { try {
...@@ -1163,9 +1179,25 @@ public class EsService { ...@@ -1163,9 +1179,25 @@ public class EsService {
} }
searchSourceBuilder.size(pageSize); searchSourceBuilder.size(pageSize);
searchSourceBuilder.from((pageNo - 1) * pageSize); searchSourceBuilder.from((pageNo - 1) * pageSize);
List<String> subjectIds = new ArrayList<>(); List<String> subjectIdList = new ArrayList<>();
subjectIds.add(searchCondition.getSubjectId()); //判断是否是专题
boolQuery = buildQuery(searchCondition, subjectIds); if ("1".equals(searchCondition.getIsSubject())) {
if (StringUtils.isNotEmpty(searchCondition.getSubjectId())) {
subjectIdList.add(searchCondition.getSubjectId());
}
} else {
//该id其实是专题类别id
//查询类别id的所有明细id
Integer category = searchCondition.getCategory();
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);
}
}
boolQuery = buildQuery(searchCondition, subjectIdList);
} }
searchSourceBuilder.query(boolQuery); searchSourceBuilder.query(boolQuery);
searchRequest.source(searchSourceBuilder); searchRequest.source(searchSourceBuilder);
......
package com.zzsn.event.exception;
import com.zzsn.event.constant.Result;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
/**
* 异常拦截
*
* @author lkg
* @date 2025/2/28
*/
@RestControllerAdvice
public class CustomExceptionHandler {
@ExceptionHandler(FileExportException.class)
public ResponseEntity<Object> handleFileExportException(FileExportException ex) {
return new ResponseEntity<>(Result.FAIL(ex.getMessage()), HttpStatus.valueOf(ex.getStatusCode()));
}
}
package com.zzsn.event.exception;
import lombok.Data;
/**
* 文件导出异常
*
* @author lkg
* @date 2025/2/28
*/
@Data
public class FileExportException extends RuntimeException{
private int statusCode = 500;
public FileExportException(String message) {
super(message);
}
}
...@@ -876,18 +876,23 @@ public class InformationServiceImpl implements InformationService { ...@@ -876,18 +876,23 @@ public class InformationServiceImpl implements InformationService {
} }
for (SpecialInformation specialInformation : informationList) { for (SpecialInformation specialInformation : informationList) {
List<Label> labels = specialInformation.getLabels(); List<Label> labels = specialInformation.getLabels();
if (labels.size() == 1) { List<Label> collect = labels.stream().filter(e -> "thematic_information_column".equals(e.getLabelMark())).collect(Collectors.toList());
removeList.add(specialInformation); if (CollectionUtils.isNotEmpty(collect)) {
} else { if (collect.size() == 1) {
List<Label> newLabels = new ArrayList<>(); removeList.add(specialInformation);
for (Label label : labels) { } else {
String labelRelationId = label.getRelationId(); List<Label> newLabels = new ArrayList<>();
if (!themeIds.contains(labelRelationId)) { for (Label label : collect) {
newLabels.add(label); String labelRelationId = label.getRelationId();
if (!themeIds.contains(labelRelationId)) {
newLabels.add(label);
}
} }
specialInformation.setLabels(newLabels);
dataList.add(specialInformation);
} }
specialInformation.setLabels(newLabels); } else {
dataList.add(specialInformation); removeList.add(specialInformation);
} }
} }
} }
......
...@@ -80,7 +80,7 @@ public class SubjectSimpleServiceImpl implements SubjectSimpleService { ...@@ -80,7 +80,7 @@ public class SubjectSimpleServiceImpl implements SubjectSimpleService {
private CodeGenerateUtil codeGenerateUtil; private CodeGenerateUtil codeGenerateUtil;
@Autowired @Autowired
private PythonUtil pythonUtil; private PythonUtil pythonUtil;
@Autowired @Autowired(required = false)
private RemoteModelService remoteModelService; private RemoteModelService remoteModelService;
@Value("${clb.subject.default.processing.advanceMonth}") @Value("${clb.subject.default.processing.advanceMonth}")
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论