✨ 1. 文章摘要服务集成
2. 文章标签服务集成
This commit is contained in:
parent
fd4ad84b45
commit
c7b6b8a63b
8
pom.xml
8
pom.xml
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-parent</artifactId>
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
<version>2.2.1.RELEASE</version>
|
<version>2.2.6.RELEASE</version>
|
||||||
<relativePath/> <!-- lookup parent from repository -->
|
<relativePath/> <!-- lookup parent from repository -->
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>com.rymcu</groupId>
|
<groupId>com.rymcu</groupId>
|
||||||
@ -168,7 +168,6 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-websocket</artifactId>
|
<artifactId>spring-boot-starter-websocket</artifactId>
|
||||||
<version>2.2.1.RELEASE</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jodd</groupId>
|
<groupId>org.jodd</groupId>
|
||||||
@ -180,6 +179,11 @@
|
|||||||
<artifactId>weixin-java-open</artifactId>
|
<artifactId>weixin-java-open</artifactId>
|
||||||
<version>3.7.0</version>
|
<version>3.7.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baidu.aip</groupId>
|
||||||
|
<artifactId>java-sdk</artifactId>
|
||||||
|
<version>4.11.3</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
17
src/main/java/com/rymcu/vertical/dto/baidu/TagNlpDTO.java
Normal file
17
src/main/java/com/rymcu/vertical/dto/baidu/TagNlpDTO.java
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package com.rymcu.vertical.dto.baidu;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ronger
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class TagNlpDTO {
|
||||||
|
|
||||||
|
private BigDecimal score;
|
||||||
|
|
||||||
|
private String tag;
|
||||||
|
|
||||||
|
}
|
@ -18,11 +18,12 @@ public interface TagService extends Service<Tag> {
|
|||||||
/**
|
/**
|
||||||
* 保存文章标签
|
* 保存文章标签
|
||||||
* @param article
|
* @param article
|
||||||
|
* @param articleContentHtml
|
||||||
* @throws UnsupportedEncodingException
|
* @throws UnsupportedEncodingException
|
||||||
* @throws BaseApiException
|
* @throws BaseApiException
|
||||||
* @return
|
* @return
|
||||||
* */
|
* */
|
||||||
Integer saveTagArticle(Article article) throws UnsupportedEncodingException, BaseApiException;
|
Integer saveTagArticle(Article article, String articleContentHtml) throws UnsupportedEncodingException, BaseApiException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 清除未使用标签
|
* 清除未使用标签
|
||||||
|
@ -176,7 +176,7 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tagService.saveTagArticle(newArticle);
|
tagService.saveTagArticle(newArticle, articleContentHtml);
|
||||||
|
|
||||||
if (defaultStatus.equals(newArticle.getArticleStatus())) {
|
if (defaultStatus.equals(newArticle.getArticleStatus())) {
|
||||||
newArticle.setArticlePermalink(domain + "/article/" + newArticle.getIdArticle());
|
newArticle.setArticlePermalink(domain + "/article/" + newArticle.getIdArticle());
|
||||||
@ -187,12 +187,11 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (StringUtils.isNotBlank(articleContentHtml)) {
|
if (StringUtils.isNotBlank(articleContentHtml)) {
|
||||||
Integer length = articleContentHtml.length();
|
String previewContent = BaiDuAipUtils.getNewsSummary(newArticle.getArticleTitle(), articleContentHtml, MAX_PREVIEW);
|
||||||
if (length > MAX_PREVIEW) {
|
if (previewContent.length() > MAX_PREVIEW) {
|
||||||
length = MAX_PREVIEW;
|
previewContent = previewContent.substring(0, MAX_PREVIEW);
|
||||||
}
|
}
|
||||||
String articlePreviewContent = articleContentHtml.substring(0, length);
|
newArticle.setArticlePreviewContent(previewContent);
|
||||||
newArticle.setArticlePreviewContent(Html2TextUtil.getContent(articlePreviewContent));
|
|
||||||
}
|
}
|
||||||
articleMapper.updateByPrimaryKeySelective(newArticle);
|
articleMapper.updateByPrimaryKeySelective(newArticle);
|
||||||
|
|
||||||
@ -326,7 +325,7 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
|
|||||||
if (Objects.nonNull(article)) {
|
if (Objects.nonNull(article)) {
|
||||||
article.setArticleTags(tags);
|
article.setArticleTags(tags);
|
||||||
articleMapper.updateArticleTags(idArticle, tags);
|
articleMapper.updateArticleTags(idArticle, tags);
|
||||||
tagService.saveTagArticle(article);
|
tagService.saveTagArticle(article, "");
|
||||||
map.put("success", true);
|
map.put("success", true);
|
||||||
} else {
|
} else {
|
||||||
map.put("success", false);
|
map.put("success", false);
|
||||||
|
@ -3,12 +3,14 @@ package com.rymcu.vertical.service.impl;
|
|||||||
import com.rymcu.vertical.core.service.AbstractService;
|
import com.rymcu.vertical.core.service.AbstractService;
|
||||||
import com.rymcu.vertical.dto.ArticleTagDTO;
|
import com.rymcu.vertical.dto.ArticleTagDTO;
|
||||||
import com.rymcu.vertical.dto.LabelModel;
|
import com.rymcu.vertical.dto.LabelModel;
|
||||||
|
import com.rymcu.vertical.dto.baidu.TagNlpDTO;
|
||||||
import com.rymcu.vertical.entity.Article;
|
import com.rymcu.vertical.entity.Article;
|
||||||
import com.rymcu.vertical.entity.Tag;
|
import com.rymcu.vertical.entity.Tag;
|
||||||
import com.rymcu.vertical.entity.User;
|
import com.rymcu.vertical.entity.User;
|
||||||
import com.rymcu.vertical.mapper.ArticleMapper;
|
import com.rymcu.vertical.mapper.ArticleMapper;
|
||||||
import com.rymcu.vertical.mapper.TagMapper;
|
import com.rymcu.vertical.mapper.TagMapper;
|
||||||
import com.rymcu.vertical.service.TagService;
|
import com.rymcu.vertical.service.TagService;
|
||||||
|
import com.rymcu.vertical.util.BaiDuAipUtils;
|
||||||
import com.rymcu.vertical.util.CacheUtils;
|
import com.rymcu.vertical.util.CacheUtils;
|
||||||
import com.rymcu.vertical.util.UserUtils;
|
import com.rymcu.vertical.util.UserUtils;
|
||||||
import com.rymcu.vertical.web.api.exception.BaseApiException;
|
import com.rymcu.vertical.web.api.exception.BaseApiException;
|
||||||
@ -38,7 +40,7 @@ public class TagServiceImpl extends AbstractService<Tag> implements TagService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = {UnsupportedEncodingException.class, BaseApiException.class})
|
@Transactional(rollbackFor = {UnsupportedEncodingException.class, BaseApiException.class})
|
||||||
public Integer saveTagArticle(Article article) throws UnsupportedEncodingException, BaseApiException {
|
public Integer saveTagArticle(Article article, String articleContentHtml) throws UnsupportedEncodingException, BaseApiException {
|
||||||
User user = UserUtils.getCurrentUserByToken();
|
User user = UserUtils.getCurrentUserByToken();
|
||||||
String articleTags = article.getArticleTags();
|
String articleTags = article.getArticleTags();
|
||||||
if (StringUtils.isNotBlank(articleTags)) {
|
if (StringUtils.isNotBlank(articleTags)) {
|
||||||
@ -92,6 +94,18 @@ public class TagServiceImpl extends AbstractService<Tag> implements TagService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
|
} else {
|
||||||
|
if (StringUtils.isNotBlank(articleContentHtml)) {
|
||||||
|
List<TagNlpDTO> list = BaiDuAipUtils.getKeywords(article.getArticleTitle(), articleContentHtml);
|
||||||
|
if (list.size() > 0) {
|
||||||
|
StringBuffer tags = new StringBuffer();
|
||||||
|
for (TagNlpDTO tagNlpDTO : list) {
|
||||||
|
tags.append(tagNlpDTO.getTag()).append(",");
|
||||||
|
}
|
||||||
|
article.setArticleTags(tags.toString());
|
||||||
|
saveTagArticle(article, articleContentHtml);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user