1. 文章摘要服务集成

2. 文章标签服务集成
This commit is contained in:
x ronger 2020-10-29 21:41:03 +08:00
parent fd4ad84b45
commit c7b6b8a63b
5 changed files with 46 additions and 11 deletions

View File

@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.1.RELEASE</version>
<version>2.2.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.rymcu</groupId>
@ -168,7 +168,6 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
<version>2.2.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.jodd</groupId>
@ -180,6 +179,11 @@
<artifactId>weixin-java-open</artifactId>
<version>3.7.0</version>
</dependency>
<dependency>
<groupId>com.baidu.aip</groupId>
<artifactId>java-sdk</artifactId>
<version>4.11.3</version>
</dependency>
</dependencies>
<build>

View 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;
}

View File

@ -18,11 +18,12 @@ public interface TagService extends Service<Tag> {
/**
* 保存文章标签
* @param article
* @param articleContentHtml
* @throws UnsupportedEncodingException
* @throws BaseApiException
* @return
* */
Integer saveTagArticle(Article article) throws UnsupportedEncodingException, BaseApiException;
Integer saveTagArticle(Article article, String articleContentHtml) throws UnsupportedEncodingException, BaseApiException;
/**
* 清除未使用标签

View File

@ -176,7 +176,7 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
}
}
tagService.saveTagArticle(newArticle);
tagService.saveTagArticle(newArticle, articleContentHtml);
if (defaultStatus.equals(newArticle.getArticleStatus())) {
newArticle.setArticlePermalink(domain + "/article/" + newArticle.getIdArticle());
@ -187,12 +187,11 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
}
if (StringUtils.isNotBlank(articleContentHtml)) {
Integer length = articleContentHtml.length();
if (length > MAX_PREVIEW) {
length = MAX_PREVIEW;
String previewContent = BaiDuAipUtils.getNewsSummary(newArticle.getArticleTitle(), articleContentHtml, MAX_PREVIEW);
if (previewContent.length() > MAX_PREVIEW) {
previewContent = previewContent.substring(0, MAX_PREVIEW);
}
String articlePreviewContent = articleContentHtml.substring(0, length);
newArticle.setArticlePreviewContent(Html2TextUtil.getContent(articlePreviewContent));
newArticle.setArticlePreviewContent(previewContent);
}
articleMapper.updateByPrimaryKeySelective(newArticle);
@ -326,7 +325,7 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
if (Objects.nonNull(article)) {
article.setArticleTags(tags);
articleMapper.updateArticleTags(idArticle, tags);
tagService.saveTagArticle(article);
tagService.saveTagArticle(article, "");
map.put("success", true);
} else {
map.put("success", false);

View File

@ -3,12 +3,14 @@ package com.rymcu.vertical.service.impl;
import com.rymcu.vertical.core.service.AbstractService;
import com.rymcu.vertical.dto.ArticleTagDTO;
import com.rymcu.vertical.dto.LabelModel;
import com.rymcu.vertical.dto.baidu.TagNlpDTO;
import com.rymcu.vertical.entity.Article;
import com.rymcu.vertical.entity.Tag;
import com.rymcu.vertical.entity.User;
import com.rymcu.vertical.mapper.ArticleMapper;
import com.rymcu.vertical.mapper.TagMapper;
import com.rymcu.vertical.service.TagService;
import com.rymcu.vertical.util.BaiDuAipUtils;
import com.rymcu.vertical.util.CacheUtils;
import com.rymcu.vertical.util.UserUtils;
import com.rymcu.vertical.web.api.exception.BaseApiException;
@ -38,7 +40,7 @@ public class TagServiceImpl extends AbstractService<Tag> implements TagService {
@Override
@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();
String articleTags = article.getArticleTags();
if (StringUtils.isNotBlank(articleTags)) {
@ -92,6 +94,18 @@ public class TagServiceImpl extends AbstractService<Tag> implements TagService {
}
}
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;
}