概念标签返回数据调整

This commit is contained in:
sunflower2014 2025-06-17 18:34:46 +08:00
parent 8ec45e21fe
commit fed8358c80
11 changed files with 184 additions and 72 deletions

View File

@ -34,7 +34,8 @@ redis:
password: Xgf_redis
elasticsearch:
scheme: http
# 111.13.176.3
# 111.13.176.3 部署地址
# 10.127.2.194 本地测试地址
host: 10.127.2.194
port: 9200
enable: true

View File

@ -1 +1,5 @@
alter table tag add level tinyint after name;
alter table tag add level tinyint after name;
alter table tag add column parent_name varchar(200);
update tag t inner join tag x on t.parent_id = x.id
set t.parent_name = x.name
where t.level = 2;

View File

@ -114,8 +114,11 @@ public interface NewsMapper {
"</if>" +
" left join news_tags on news.newsinfo_id = news_tags.newsinfo_id " +
"<where>" +
"<if test=\"tags != null and tags.isEmpty()\">" +
" and 1 = 2 " +
"</if>" +
"<if test=\"keyword != null and !keyword.isEmpty()\">" +
"news.title like concat('%', #{keyword}, '%') " +
" and news.title like concat('%', #{keyword}, '%') " +
"</if>" +
"<if test=\"column != null and !column.isEmpty()\">" +
"and news_column_rel.column_id in (${column}) " +
@ -171,8 +174,11 @@ public interface NewsMapper {
"left join news_tags on news.newsinfo_id = news_tags.newsinfo_id " +
"</if>" +
"<where>" +
"<if test=\"tags != null and tags.isEmpty()\">" +
" and 1 = 2 " +
"</if>" +
"<if test=\"keyword != null and !keyword.isEmpty()\">" +
"news.title like concat('%', #{keyword}, '%') " +
" and news.title like concat('%', #{keyword}, '%') " +
"</if>" +
"<if test=\"column != null and !column.isEmpty()\">" +
"and news_column_rel.column_id in (${column}) " +

View File

@ -19,6 +19,7 @@ public interface TagMapper {
@Results({
@Result(column = "id", property = "id", id = true),
@Result(column = "parent_id", property = "parentId"),
@Result(column = "parent_name", property = "parentName"),
@Result(column = "name", property = "name"),
@Result(column = "create_time", property = "createTime", javaType = Date.class, jdbcType = JdbcType.TIMESTAMP),
@Result(column = "update_time", property = "updateTime", javaType = Date.class, jdbcType = JdbcType.TIMESTAMP)

View File

@ -88,10 +88,17 @@ public class Industry {
this.updateTime = updateTime;
}
public String getDisplayName() {
public String getName() {
if (ObjectUtils.isEmpty(this.getSecondaryName())) {
return this.getPrimaryName();
}
return this.getSecondaryName();
}
public String getDisplayName() {
if (ObjectUtils.isEmpty(this.getSecondaryName())) {
return this.getPrimaryName();
}
return this.getPrimaryName()+ "-" +this.getSecondaryName();
}
}

View File

@ -2,6 +2,8 @@ package com.jinrui.reference.core.model.entity;
import java.util.Date;
import org.springframework.util.ObjectUtils;
/**
* 标签
*/
@ -17,6 +19,8 @@ public class Tag {
* 上级标签ID
*/
private Long parentId;
private String parentName;
/**
* 标签名称
@ -72,4 +76,20 @@ public class Tag {
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
public String getParentName() {
return parentName;
}
public void setParentName(String parentName) {
this.parentName = parentName;
}
public String getDisplayName() {
if (ObjectUtils.isEmpty(this.getParentName())) {
return this.getName();
}
return this.getParentName()+ "-" +this.getName();
}
}

View File

@ -47,7 +47,7 @@ public class IndustryHierarchyVO {
public IndustryHierarchyVO(Industry industry) {
this.id = industry.getId();
this.name = industry.getDisplayName();
this.name = industry.getName();
}
public Long getId() {

View File

@ -6,7 +6,7 @@ public class NewsDetailTagItem {
private Long id;
private String name;
public Long getId() {
return id;
}
@ -22,4 +22,14 @@ public class NewsDetailTagItem {
public void setName(String name) {
this.name = name;
}
public String getParentName() {
return parentName;
}
public void setParentName(String parentName) {
this.parentName = parentName;
}
private String parentName;
}

View File

@ -42,7 +42,7 @@ public class NewsInfoDetailVO {
/**
* 数据来源名称或标识
*/
private NewsDetailTag sourcename;
private NewsDetailTag tag;
/**
* H5富文本
@ -172,12 +172,12 @@ public class NewsInfoDetailVO {
this.updateTime = updateTime;
}
public NewsDetailTag getSourcename() {
return sourcename;
public NewsDetailTag getTag() {
return tag;
}
public void setSourcename(NewsDetailTag sourcename) {
this.sourcename = sourcename;
public void setTag(NewsDetailTag tag) {
this.tag = tag;
}
public Long getNewsId() {

View File

@ -2,7 +2,6 @@ package com.jinrui.reference.core.service;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@ -19,6 +18,7 @@ import org.springframework.util.StringUtils;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.jinrui.reference.core.mapper.IndustryMapper;
import com.jinrui.reference.core.mapper.NewsMapper;
import com.jinrui.reference.core.mapper.NewsTagsMapper;
import com.jinrui.reference.core.mapper.TagMapper;
import com.jinrui.reference.core.model.dto.news.SaveDraftTag;
import com.jinrui.reference.core.model.entity.Industry;
@ -26,6 +26,7 @@ import com.jinrui.reference.core.model.entity.News;
import com.jinrui.reference.core.model.entity.NewsIndustryRel;
import com.jinrui.reference.core.model.entity.NewsInfo;
import com.jinrui.reference.core.model.entity.NewsTagRel;
import com.jinrui.reference.core.model.entity.NewsTags;
import com.jinrui.reference.core.model.entity.Tag;
import com.jinrui.reference.core.model.vo.PageObject;
import com.jinrui.reference.core.model.vo.ResultObject;
@ -62,17 +63,28 @@ public class NewsInfoService {
private final TagMapper tagMapper;
private final IndustryMapper industryMapper;
private final NewsMapper newsMapper;
private final NewsTagsMapper newsTagsMapper;
public NewsInfoService(ElasticsearchClient elasticsearchClient,
ObjectMapper objectMapper,
TagMapper tagMapper,
IndustryMapper industryMapper,
NewsMapper newsMapper) {
NewsMapper newsMapper,
NewsTagsMapper newsTagsMapper) {
this.elasticsearchClient = elasticsearchClient;
this.objectMapper = objectMapper;
this.tagMapper = tagMapper;
this.industryMapper = industryMapper;
this.newsMapper = newsMapper;
this.newsTagsMapper = newsTagsMapper;
NewsTags newsTags = newsTagsMapper.getNewsTagsByNewsId("102694660");
for (String conceptLabel: newsTags.getConceptLabel()) {
System.out.println("+++++++++++++++++++++conceptLabel++++++++++++++++++++++" + conceptLabel);
}
for (String industryLabel: newsTags.getIndustryLabel()) {
System.out.println("+++++++++++++++++++++industryLabel++++++++++++++++++++++" + industryLabel);
}
}
public ResultObject<Void> publish(String id, long editorId) {
@ -98,33 +110,7 @@ public class NewsInfoService {
relNews.setStatus(1);
relNews.setEditorId(editorId);
newsMapper.saveNews(relNews);
String industry = newsInfo.getIndustry();
if (!ObjectUtils.isEmpty(industry)) {
List<Industry> industries = industryMapper.queryAll();
for (Industry industryItem: industries) {
if (industry.equals(industryItem.getPrimaryName()) || industryItem.equals(industryItem.getSecondaryName())) {
industryMapper.saveNewsIndustryRel(relNews.getId(), industryItem.getId());
break;
}
}
}
String sourcename = newsInfo.getSourcename();
if (!ObjectUtils.isEmpty(sourcename)) {
boolean isFound = false;
List<Tag> matchedTags = tagMapper.queryTag(1L, sourcename, null, "create_time", null);
for (Tag tag: matchedTags) {
if (tag.getName().equals(sourcename)) {
tagMapper.saveNewsTagRel(relNews.getId(), tag.getId());
isFound = true;
break;
}
}
if (!isFound) {
tagMapper.saveTag(1L, sourcename);
}
}
saveNewsRel(id, relNews.getId());
}
NewsInfo publishedNewsInfo = new NewsInfo();
@ -139,6 +125,54 @@ public class NewsInfoService {
return ResultObject.success();
}
private void saveNewsRel(String newsInfoId, Long newsId) {
NewsTags newsTags = newsTagsMapper.getNewsTagsByNewsId(newsInfoId);
if (newsTags == null) {
return;
}
if (!ObjectUtils.isEmpty(newsTags.getIndustryLabel())) {
List<Industry> industries = industryMapper.queryAll();
for (String industryLabel: newsTags.getIndustryLabel()) {
for (Industry industry: industries) {
if (industryLabel.equals(industry.getDisplayName())) {
industryMapper.saveNewsIndustryRel(newsId, industry.getId());
break;
}
}
}
}
String sourcename = newsTags.getSource();
if (!ObjectUtils.isEmpty(sourcename)) {
boolean isFound = false;
List<Tag> matchedTags = tagMapper.queryTag(1L, sourcename, null, "create_time", null);
for (Tag tag: matchedTags) {
if (tag.getName().equals(sourcename)) {
tagMapper.saveNewsTagRel(newsId, tag.getId());
isFound = true;
break;
}
}
if (!isFound) {
tagMapper.saveTag(1L, sourcename);
}
}
List<String> conceptLabels = newsTags.getConceptLabel();
if (!ObjectUtils.isEmpty(conceptLabels)) {
List<Tag> tags = tagMapper.queryAll().stream().filter(e -> !ObjectUtils.isEmpty(e.getParentName())).collect(Collectors.toList());
for (String conceptLabel: conceptLabels) {
for (Tag tag:tags) {
if (conceptLabel.equals(tag.getDisplayName())) {
tagMapper.saveNewsTagRel(newsId, tag.getId());
break;
}
}
}
}
}
public ResultObject<NewsInfoDetailVO> detail(String id) {
@ -158,34 +192,62 @@ public class NewsInfoService {
if (newsInfo.getStatus() == null ||newsInfo.getStatus() == 1) {
for (Tag tag: allTags) {
if (tag.getName().equals(newsInfo.getSourcename())) {
NewsDetailTag newsDetailTag = new NewsDetailTag();
NewsDetailTagItem sourceTagItem = new NewsDetailTagItem();
newsDetailTag.setSource(sourceTagItem);
sourceTagItem.setId(tag.getId());
sourceTagItem.setName(tag.getName());
newsInfoDetailVO.setSourcename(newsDetailTag);
NewsTags newsTags = newsTagsMapper.getNewsTagsByNewsId(id);
if (newsTags != null) {
NewsDetailTag newsDetailTag = new NewsDetailTag();
for (Tag tag: allTags) {
if (tag.getName().equals(newsTags.getSource())) {
NewsDetailTagItem sourceTagItem = new NewsDetailTagItem();
sourceTagItem.setId(tag.getId());
sourceTagItem.setName(tag.getName());
newsDetailTag.setSource(sourceTagItem);
}
}
}
String industryStr = newsInfo.getIndustry();
for (Industry industry: allIndustrys) {
if (Objects.equals(industry.getDisplayName(), industryStr)) {
NewsDetailIndustry newsDetailIndustry = new NewsDetailIndustry();
newsDetailIndustry.setId(newsDetailIndustry.getId());
newsDetailIndustry.setPrimaryName(newsDetailIndustry.getPrimaryName());
newsDetailIndustry.setSecondaryName(newsDetailIndustry.getSecondaryName());
newsInfoDetailVO.setIndustry(Arrays.asList(newsDetailIndustry));
List<String> conceptLabels = newsTags.getConceptLabel();
if (!ObjectUtils.isEmpty(conceptLabels)) {
List<Tag> levelTwoTags = allTags.stream().filter(e -> !ObjectUtils.isEmpty(e.getParentName())).collect(Collectors.toList());
List<NewsDetailTagItem> fieldArr = new ArrayList<>();
for (String conceptLabel: conceptLabels) {
for (Tag tag: levelTwoTags) {
if (Objects.equals(conceptLabel, tag.getDisplayName())) {
NewsDetailTagItem conceptTagItem = new NewsDetailTagItem();
conceptTagItem.setId(tag.getId());
conceptTagItem.setName(tag.getName());
conceptTagItem.setParentName(tag.getParentName());
fieldArr.add(conceptTagItem);
break;
}
}
}
newsDetailTag.setFieldArr(fieldArr);
}
newsInfoDetailVO.setTag(newsDetailTag);
List<String> industryLabels = newsTags.getIndustryLabel();
if (!ObjectUtils.isEmpty(industryLabels)) {
List<NewsDetailIndustry> industries = new ArrayList<>();
for (String industryLabel: industryLabels) {
for (Industry industry: allIndustrys) {
if (Objects.equals(industry.getDisplayName(), industryLabel)) {
NewsDetailIndustry newsDetailIndustry = new NewsDetailIndustry();
newsDetailIndustry.setId(newsDetailIndustry.getId());
newsDetailIndustry.setPrimaryName(newsDetailIndustry.getPrimaryName());
newsDetailIndustry.setSecondaryName(newsDetailIndustry.getSecondaryName());
industries.add(newsDetailIndustry);
break;
}
}
}
newsInfoDetailVO.setIndustry(industries);
}
}
} else {
Map<Long, Industry> industryMap = allIndustrys.stream().collect(Collectors.toMap(Industry::getId, Function.identity()));
List<NewsTagRel> tagRelList = tagMapper.getNewsTagRelList(newsInfo.getNewsId());
NewsDetailTag newsDetailTag = new NewsDetailTag();
newsInfoDetailVO.setSourcename(newsDetailTag);
newsInfoDetailVO.setTag(newsDetailTag);
if (!CollectionUtils.isEmpty(tagRelList)) {
List<NewsDetailTagItem> arr = new ArrayList<>();
@ -229,7 +291,7 @@ public class NewsInfoService {
}
}
public ResultObject<Void> save(SaveNewsInfoDTO saveNewsDTO) {
public ResultObject<Void> save(SaveNewsInfoDTO saveNewsDTO) {
String id = saveNewsDTO.getId();
if (ObjectUtils.isEmpty(id)) {
return saveNewsInfo(saveNewsDTO);
@ -313,7 +375,7 @@ public class NewsInfoService {
if (!ObjectUtils.isEmpty(industries)) {
List<Industry> allIndustry = industryMapper.queryAll();
Map<Long, Industry> industryMap = allIndustry.stream().collect(Collectors.toMap(Industry::getId, Function.identity()));
String industry = industries.stream().map(e -> industryMap.get(e)).map(Industry::getDisplayName).collect(Collectors.joining(";"));
String industry = industries.stream().map(e -> industryMap.get(e)).map(Industry::getName).collect(Collectors.joining(";"));
newsInfo.setIndustry(industry);
}

View File

@ -4,7 +4,6 @@ import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
@ -24,7 +23,6 @@ import org.springframework.util.StringUtils;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.jinrui.reference.core.mapper.ColumnMapper;
import com.jinrui.reference.core.mapper.IndustryMapper;
@ -211,11 +209,13 @@ public class NewsService {
for (DraftIndustryRel rel: industryRelList) {
Long industryId = rel.getIndustryId();
Industry industry = industryMap.get(industryId);
NewsDetailIndustry newsDetailIndustry = new NewsDetailIndustry();
newsDetailIndustry.setId(industryId);
newsDetailIndustry.setPrimaryName(industry.getPrimaryName());
newsDetailIndustry.setSecondaryName(industry.getSecondaryName());
newsIndustryList.add(newsDetailIndustry);
if (industry != null) {
NewsDetailIndustry newsDetailIndustry = new NewsDetailIndustry();
newsDetailIndustry.setId(industryId);
newsDetailIndustry.setPrimaryName(industry.getPrimaryName());
newsDetailIndustry.setSecondaryName(industry.getSecondaryName());
newsIndustryList.add(newsDetailIndustry);
}
}
}
@ -304,6 +304,7 @@ public class NewsService {
NewsDetailTagItem tagItem = new NewsDetailTagItem();
tagItem.setId(tagId);
tagItem.setName(tag.getName());
tagItem.setParentName(tag.getParentName());
if (parentId != null && parentId == 1) {
newsDetailTag.setSource(tagItem);
} else {
@ -463,7 +464,7 @@ public class NewsService {
if (!ObjectUtils.isEmpty(industries)) {
List<Industry> allIndustry = industryMapper.queryAll();
Map<Long, Industry> industryMap = allIndustry.stream().collect(Collectors.toMap(Industry::getId, Function.identity()));
String industry = industries.stream().map(e -> industryMap.get(e)).map(Industry::getDisplayName).collect(Collectors.joining(";"));
String industry = industries.stream().map(e -> industryMap.get(e)).map(Industry::getName).collect(Collectors.joining(";"));
newsInfo.setIndustry(industry);
}
@ -913,7 +914,7 @@ public class NewsService {
private List<Long> getMatchTags(String tagParam) {
if (ObjectUtils.isEmpty(tagParam)) {
return Collections.emptyList();
return null;
}
String[] tags = StringUtils.trimWhitespace(tagParam).split("\\s+");
List<Tag> levelOneTags = tagMapper.queryTag(6L, null, null, "create_time", null);