提交 b3b7b61e 作者: 925993793@qq.com

增加批量删除标签的接口

上级 0ab2861d
......@@ -249,7 +249,7 @@ public class InformationController {
}
/**
* 保存为数据集
* 保存为数据集(实为打标签)
*
* @param searchCondition 筛选条件
* @author lkg
......@@ -265,7 +265,27 @@ public class InformationController {
return Result.FAIL("专题id不能为空");
}
CompletableFuture.runAsync(() -> informationService.saveAsDataSet(searchCondition));
return Result.OK("数据集保存中。。。");
return Result.OK("数据集保存中,请稍后查看");
}
/**
* 批量删除标签
*
* @param searchCondition 筛选条件
* @author lkg
* @date 2024/5/6
*/
@PostMapping("/batchDeleteLabel")
public Result<?> batchDeleteLabel(@RequestBody InfoDataSearchCondition searchCondition) {
String dataSetId = searchCondition.getRemoveRelationId();
if (StringUtils.isEmpty(dataSetId)) {
return Result.FAIL("待删除标签id不能为空");
}
if (StringUtils.isEmpty(searchCondition.getSubjectId())) {
return Result.FAIL("专题id不能为空");
}
CompletableFuture.runAsync(() -> informationService.removeLabels(searchCondition));
return Result.OK("标签删除中,请稍后查看");
}
......
......@@ -39,6 +39,7 @@ public interface InformationService {
* @date 2024/5/6
*/
IPage<DisplayInfo> subjectPageList(InfoDataSearchCondition subjectInfo);
/**
* 专题库资讯分页列表
*
......@@ -47,6 +48,7 @@ public interface InformationService {
* @date 2024/5/6
*/
IPage<SpecialInformation> subjectPageListForDataDetail(InfoDataSearchCondition subjectInfo);
/**
* 资讯分页列表(根据标签分类分组)
*/
......@@ -62,6 +64,15 @@ public interface InformationService {
void saveAsDataSet(InfoDataSearchCondition searchCondition);
/**
* 批量删除标签
*
* @param searchCondition 筛选条件
* @author lkg
* @date 2025/4/10
*/
void removeLabels(InfoDataSearchCondition searchCondition);
/**
* 资讯详情
*
* @param type 类别(1-采集库;2-专题库)
......@@ -131,7 +142,7 @@ public interface InformationService {
* @author lkg
* @date 2025/3/31
*/
void modifyLabel(DataBindLabelFrom dataBindLabelFrom,List<DictVO> boundList);
void modifyLabel(DataBindLabelFrom dataBindLabelFrom, List<DictVO> boundList);
/**
* 审核
......@@ -207,6 +218,7 @@ public interface InformationService {
/**
* 批量导入数据到发布库
*
* @author lkg
* @date 2025/2/5
*/
......@@ -214,6 +226,7 @@ public interface InformationService {
/**
* 批量导入数据到发布库-研究中心
*
* @author lkg
* @date 2025/2/5
*/
......@@ -228,6 +241,7 @@ public interface InformationService {
* @date 2025/2/20
*/
void removeByCondition(String subjectId, List<String> themeIds);
/**
* 新增专题下的数据-研究中心
*
......
......@@ -225,7 +225,7 @@ public class InformationServiceImpl implements InformationService {
List<LabelModelVo> modelVoList = modelMap.get(info.getSubjectId());
formatLabel(modelVoList, info);
try{
try {
//多个主题的保留分数最高的
List<Label> listLabel = info.getLabels();
// 使用流操作找到score最大的Label
......@@ -235,33 +235,33 @@ public class InformationServiceImpl implements InformationService {
.max(Comparator.comparingDouble(Label::getStatus));
List<Label> maxLabelList = maxLabel.map(Collections::singletonList).orElse(Collections.emptyList());
info.setLabels(maxLabelList);
}catch (Exception e){
log.error("处理得分最高标签异常",e);
} catch (Exception e) {
log.error("处理得分最高标签异常", e);
}
dataList.add(info);
}
Map<String, List<DisplayInfo>> mapList = groupedByLabelMark(dataList,searchCondition);
Map<String, List<DisplayInfo>> mapList = groupedByLabelMark(dataList, searchCondition);
mapList.forEach((relationName, displayInfos) -> {
List<DisplayInfo> listN = new ArrayList<>();
Integer num = 0;
for (DisplayInfo obj : displayInfos) {
DisplayInfo copy = new DisplayInfo();
BeanUtils.copyProperties(obj,copy);
BeanUtils.copyProperties(obj, copy);
num++;
copy.setIndex(num + ".");
// copy.setTitle(StringUtils.isNotEmpty(copy.getTitle())?copy.getTitle() + "。":"");
listN.add(copy);
}
HashMap map = new HashMap();
map.put("relationName",relationName);
map.put("infoList",listN);
map.put("relationName", relationName);
map.put("infoList", listN);
list.add(map);
});
}else{
} else {
//不加标签获取列表数据
searchCondition.setLabelMark(null);
//中外智库专栏-数据需排序
if(StringUtils.isNotBlank(searchCondition.getSubjectId()) && searchCondition.getSubjectId().equals(subjectId)){
if (StringUtils.isNotBlank(searchCondition.getSubjectId()) && searchCondition.getSubjectId().equals(subjectId)) {
searchCondition.setColumn("yqgzzk");
}
specialInformationIPage = esService.pageListByCondition(searchCondition, subjectIdList);
......@@ -285,30 +285,30 @@ public class InformationServiceImpl implements InformationService {
dataList.add(info);
}
//中外智库专栏-数据需过滤
if(StringUtils.isNotBlank(searchCondition.getSubjectId()) && searchCondition.getSubjectId().equals(subjectId)){
if (StringUtils.isNotBlank(searchCondition.getSubjectId()) && searchCondition.getSubjectId().equals(subjectId)) {
ArrayList<DisplayInfo> saveList = new ArrayList<>(list.size());
List<String> titles = new ArrayList<>(list.size());
for(DisplayInfo s: dataList){
for (DisplayInfo s : dataList) {
String title = s.getTitle().trim();
int tem = 0;
for(String t:titles){
for (String t : titles) {
double simforcatl = SimilarityUtil.simforcatl(title, t);
if(simforcatl>0.83){
log.info("getArticleNode 获取文章列表中标题为[{}],和标题为[{}],的相似度大于80%过滤后者",title,t);
tem=1;
if (simforcatl > 0.83) {
log.info("getArticleNode 获取文章列表中标题为[{}],和标题为[{}],的相似度大于80%过滤后者", title, t);
tem = 1;
break;
}
}
if(tem==0){
if (tem == 0) {
titles.add(title);
}else{
} else {
continue;
}
saveList.add(s);
}
for(DisplayInfo info: saveList){
if(StringUtils.isNotBlank(info.getSubtitle())){
info.setTitle(info.getSubtitle()+info.getTitle());
for (DisplayInfo info : saveList) {
if (StringUtils.isNotBlank(info.getSubtitle())) {
info.setTitle(info.getSubtitle() + info.getTitle());
}
}
return Result.OK(saveList);
......@@ -322,7 +322,7 @@ public class InformationServiceImpl implements InformationService {
return Result.OK(list);
}
public Map<String, List<DisplayInfo>> groupedByLabelMark(List<DisplayInfo> dataList,InfoDataSearchCondition searchCondition) {
public Map<String, List<DisplayInfo>> groupedByLabelMark(List<DisplayInfo> dataList, InfoDataSearchCondition searchCondition) {
// 使用 Stream API 对 dataList 进行分组
Map<String, List<DisplayInfo>> groupedByLabelMark = dataList.stream()
// 将每个 DisplayInfo 对象映射到一个或多个 labelMark
......@@ -341,6 +341,7 @@ public class InformationServiceImpl implements InformationService {
Collectors.mapping(AbstractMap.SimpleEntry::getValue, Collectors.toList())));
return groupedByLabelMark;
}
@Override
public DisplayInfo queryInfo(Integer type, String index, String id) {
DisplayInfo info = (DisplayInfo) esOpUtil.getInfoById(index, id, DisplayInfo.class);
......@@ -389,7 +390,24 @@ public class InformationServiceImpl implements InformationService {
dataSet.setRelationId(dataSetId);
Map<String, List<SpecialInformation>> map = new HashMap<>();
List<SpecialInformation> informationList = this.informationAllList(searchCondition);
formatUpdateMap(map,informationList,dataSet);
formatUpdateMap(map, informationList, dataSet);
map.forEach((k, v) -> esOpUtil.docUpdateBulk(k, v));
}
@Override
public void removeLabels(InfoDataSearchCondition searchCondition) {
String[] fetchFields = new String[]{"id", "labels"};
searchCondition.setFetchFields(fetchFields);
List<Label> removeLabels = new ArrayList<>();
String removeRelationId = searchCondition.getRemoveRelationId();
for (String relationId : removeRelationId.split(",")) {
Label dataSet = new Label();
dataSet.setRelationId(relationId);
removeLabels.add(dataSet);
}
Map<String, List<SpecialInformation>> map = new HashMap<>();
List<SpecialInformation> informationList = this.informationAllList(searchCondition);
formatUpdateMap(map, informationList, removeLabels);
map.forEach((k, v) -> esOpUtil.docUpdateBulk(k, v));
}
......@@ -402,7 +420,7 @@ public class InformationServiceImpl implements InformationService {
* @author lkg
* @date 2025/2/28
*/
private void formatUpdateMap(Map<String, List<SpecialInformation>> map,List<SpecialInformation> informationList,Label dataSet){
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();
......@@ -425,6 +443,30 @@ public class InformationServiceImpl implements InformationService {
}
}
private void formatUpdateMap(Map<String, List<SpecialInformation>> map, List<SpecialInformation> informationList, List<Label> removeLabels) {
for (SpecialInformation information : informationList) {
String index = information.getDbIndex();
List<Label> newLabels = new ArrayList<>();
List<Label> labels = information.getLabels();
if (CollectionUtils.isNotEmpty(labels)) {
for (Label label : labels) {
boolean present = removeLabels.stream().anyMatch(e -> e.getRelationId().equals(label.getRelationId()));
if (!present) {
newLabels.add(label);
}
}
}
information.setLabels(newLabels);
if (map.containsKey(index)) {
map.get(index).add(information);
} else {
List<SpecialInformation> list = new ArrayList<>();
list.add(information);
map.put(index, list);
}
}
}
@Override
public List<List<String>> statisticsExportList(String subjectId, String startDate, String endDate) {
List<String> subjectIdList = new ArrayList<>();
......@@ -610,7 +652,7 @@ public class InformationServiceImpl implements InformationService {
}
@Override
public void modifyLabel(DataBindLabelFrom dataBindLabelFrom,List<DictVO> boundList) {
public void modifyLabel(DataBindLabelFrom dataBindLabelFrom, List<DictVO> boundList) {
DisplayInfo info = (DisplayInfo) esOpUtil.getInfoById(dataBindLabelFrom.getIndex(), dataBindLabelFrom.getId(), DisplayInfo.class);
if (info != null) {
List<Label> newLabels = new ArrayList<>();
......@@ -1039,7 +1081,7 @@ public class InformationServiceImpl implements InformationService {
}
if (CollectionUtils.isNotEmpty(dataList)) {
Map<String, List<SpecialInformation>> updateMap = removeList.stream().collect(Collectors.groupingBy(SpecialInformation::getDbIndex));
updateMap.forEach((k, v) -> esOpUtil.docUpdateBulk(k,v));
updateMap.forEach((k, v) -> esOpUtil.docUpdateBulk(k, v));
}
//python 去重接口
pythonUtil.clearDuplicateHistory(themeIds);
......@@ -1055,15 +1097,15 @@ public class InformationServiceImpl implements InformationService {
if (CollectionUtils.isNotEmpty(dateList)) {
List<String> redisCacheList = new ArrayList<>();
for (String date : dateList) {
if(themeIds != null && !themeIds.isEmpty()){
if (themeIds != null && !themeIds.isEmpty()) {
//2025-01-21:123,123,123
String dateStr = date + ":" + StringUtils.join(",", themeIds);
redisCacheList.add(dateStr);
}else{
} else {
redisCacheList.add(date);
}
}
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]));
}
}
......
......@@ -97,6 +97,10 @@ public class InfoDataSearchCondition {
//数据集id,保存数据集时使用-研究中心
private String dataSetId;
//待删除的标签id(多个用逗号隔开)-研究中心
private String removeRelationId;
//关键词信息;推荐信息源时使用-研究中心
private List<String> wordsList;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论