diff --git a/admin/src/main/resources/application.yml b/admin/src/main/resources/application.yml index 5220e0e..c88a076 100644 --- a/admin/src/main/resources/application.yml +++ b/admin/src/main/resources/application.yml @@ -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 diff --git a/admin/src/main/resources/sql/20250613.sql b/admin/src/main/resources/sql/20250613.sql index c27b167..7ee46bb 100644 --- a/admin/src/main/resources/sql/20250613.sql +++ b/admin/src/main/resources/sql/20250613.sql @@ -1 +1,5 @@ -alter table tag add level tinyint after name; \ No newline at end of file +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; \ No newline at end of file diff --git a/core/src/main/java/com/jinrui/reference/core/mapper/NewsMapper.java b/core/src/main/java/com/jinrui/reference/core/mapper/NewsMapper.java index 71956f7..24437ae 100644 --- a/core/src/main/java/com/jinrui/reference/core/mapper/NewsMapper.java +++ b/core/src/main/java/com/jinrui/reference/core/mapper/NewsMapper.java @@ -114,8 +114,11 @@ public interface NewsMapper { "" + " left join news_tags on news.newsinfo_id = news_tags.newsinfo_id " + "" + + "" + + " and 1 = 2 " + + "" + "" + - "news.title like concat('%', #{keyword}, '%') " + + " and news.title like concat('%', #{keyword}, '%') " + "" + "" + "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 " + "" + "" + + "" + + " and 1 = 2 " + + "" + "" + - "news.title like concat('%', #{keyword}, '%') " + + " and news.title like concat('%', #{keyword}, '%') " + "" + "" + "and news_column_rel.column_id in (${column}) " + diff --git a/core/src/main/java/com/jinrui/reference/core/mapper/TagMapper.java b/core/src/main/java/com/jinrui/reference/core/mapper/TagMapper.java index 753c270..81cff57 100644 --- a/core/src/main/java/com/jinrui/reference/core/mapper/TagMapper.java +++ b/core/src/main/java/com/jinrui/reference/core/mapper/TagMapper.java @@ -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) diff --git a/core/src/main/java/com/jinrui/reference/core/model/entity/Industry.java b/core/src/main/java/com/jinrui/reference/core/model/entity/Industry.java index 1f43db0..723173f 100644 --- a/core/src/main/java/com/jinrui/reference/core/model/entity/Industry.java +++ b/core/src/main/java/com/jinrui/reference/core/model/entity/Industry.java @@ -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(); + } } diff --git a/core/src/main/java/com/jinrui/reference/core/model/entity/Tag.java b/core/src/main/java/com/jinrui/reference/core/model/entity/Tag.java index 9bee780..2066512 100644 --- a/core/src/main/java/com/jinrui/reference/core/model/entity/Tag.java +++ b/core/src/main/java/com/jinrui/reference/core/model/entity/Tag.java @@ -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(); + } + } diff --git a/core/src/main/java/com/jinrui/reference/core/model/vo/industry/IndustryHierarchyVO.java b/core/src/main/java/com/jinrui/reference/core/model/vo/industry/IndustryHierarchyVO.java index 58a3950..0971bca 100644 --- a/core/src/main/java/com/jinrui/reference/core/model/vo/industry/IndustryHierarchyVO.java +++ b/core/src/main/java/com/jinrui/reference/core/model/vo/industry/IndustryHierarchyVO.java @@ -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() { diff --git a/core/src/main/java/com/jinrui/reference/core/model/vo/news/NewsDetailTagItem.java b/core/src/main/java/com/jinrui/reference/core/model/vo/news/NewsDetailTagItem.java index 246c11e..982843d 100644 --- a/core/src/main/java/com/jinrui/reference/core/model/vo/news/NewsDetailTagItem.java +++ b/core/src/main/java/com/jinrui/reference/core/model/vo/news/NewsDetailTagItem.java @@ -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; } diff --git a/core/src/main/java/com/jinrui/reference/core/model/vo/newsinfo/NewsInfoDetailVO.java b/core/src/main/java/com/jinrui/reference/core/model/vo/newsinfo/NewsInfoDetailVO.java index 1e4f559..5d91661 100644 --- a/core/src/main/java/com/jinrui/reference/core/model/vo/newsinfo/NewsInfoDetailVO.java +++ b/core/src/main/java/com/jinrui/reference/core/model/vo/newsinfo/NewsInfoDetailVO.java @@ -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() { diff --git a/core/src/main/java/com/jinrui/reference/core/service/NewsInfoService.java b/core/src/main/java/com/jinrui/reference/core/service/NewsInfoService.java index 8dfb8ac..63aeac2 100644 --- a/core/src/main/java/com/jinrui/reference/core/service/NewsInfoService.java +++ b/core/src/main/java/com/jinrui/reference/core/service/NewsInfoService.java @@ -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 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 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 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 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 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 conceptLabels = newsTags.getConceptLabel(); + if (!ObjectUtils.isEmpty(conceptLabels)) { + List 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 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 conceptLabels = newsTags.getConceptLabel(); + if (!ObjectUtils.isEmpty(conceptLabels)) { + List levelTwoTags = allTags.stream().filter(e -> !ObjectUtils.isEmpty(e.getParentName())).collect(Collectors.toList()); + List 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 industryLabels = newsTags.getIndustryLabel(); + if (!ObjectUtils.isEmpty(industryLabels)) { + List 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 industryMap = allIndustrys.stream().collect(Collectors.toMap(Industry::getId, Function.identity())); List tagRelList = tagMapper.getNewsTagRelList(newsInfo.getNewsId()); NewsDetailTag newsDetailTag = new NewsDetailTag(); - newsInfoDetailVO.setSourcename(newsDetailTag); + newsInfoDetailVO.setTag(newsDetailTag); if (!CollectionUtils.isEmpty(tagRelList)) { List arr = new ArrayList<>(); @@ -229,7 +291,7 @@ public class NewsInfoService { } } - public ResultObject save(SaveNewsInfoDTO saveNewsDTO) { + public ResultObject 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 allIndustry = industryMapper.queryAll(); Map 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); } diff --git a/core/src/main/java/com/jinrui/reference/core/service/NewsService.java b/core/src/main/java/com/jinrui/reference/core/service/NewsService.java index 7044549..a37ff27 100644 --- a/core/src/main/java/com/jinrui/reference/core/service/NewsService.java +++ b/core/src/main/java/com/jinrui/reference/core/service/NewsService.java @@ -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 allIndustry = industryMapper.queryAll(); Map 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 getMatchTags(String tagParam) { if (ObjectUtils.isEmpty(tagParam)) { - return Collections.emptyList(); + return null; } String[] tags = StringUtils.trimWhitespace(tagParam).split("\\s+"); List levelOneTags = tagMapper.queryTag(6L, null, null, "create_time", null);