diff --git a/pom.xml b/pom.xml
index bd2ce30..fd053c5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
org.springframework.boot
spring-boot-starter-parent
- 2.2.1.RELEASE
+ 2.2.6.RELEASE
com.rymcu
@@ -168,7 +168,6 @@
org.springframework.boot
spring-boot-starter-websocket
- 2.2.1.RELEASE
org.jodd
@@ -180,6 +179,11 @@
weixin-java-open
3.7.0
+
+ com.baidu.aip
+ java-sdk
+ 4.11.3
+
diff --git a/src/main/java/com/rymcu/vertical/dto/baidu/TagNlpDTO.java b/src/main/java/com/rymcu/vertical/dto/baidu/TagNlpDTO.java
new file mode 100644
index 0000000..2dcd19d
--- /dev/null
+++ b/src/main/java/com/rymcu/vertical/dto/baidu/TagNlpDTO.java
@@ -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;
+
+}
diff --git a/src/main/java/com/rymcu/vertical/service/TagService.java b/src/main/java/com/rymcu/vertical/service/TagService.java
index 6664bbb..9dc4300 100644
--- a/src/main/java/com/rymcu/vertical/service/TagService.java
+++ b/src/main/java/com/rymcu/vertical/service/TagService.java
@@ -18,11 +18,12 @@ public interface TagService extends Service {
/**
* 保存文章标签
* @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;
/**
* 清除未使用标签
diff --git a/src/main/java/com/rymcu/vertical/service/impl/ArticleServiceImpl.java b/src/main/java/com/rymcu/vertical/service/impl/ArticleServiceImpl.java
index 5589d9f..756bb39 100644
--- a/src/main/java/com/rymcu/vertical/service/impl/ArticleServiceImpl.java
+++ b/src/main/java/com/rymcu/vertical/service/impl/ArticleServiceImpl.java
@@ -176,7 +176,7 @@ public class ArticleServiceImpl extends AbstractService 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 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 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);
diff --git a/src/main/java/com/rymcu/vertical/service/impl/TagServiceImpl.java b/src/main/java/com/rymcu/vertical/service/impl/TagServiceImpl.java
index 6c1b3e3..2b9b65f 100644
--- a/src/main/java/com/rymcu/vertical/service/impl/TagServiceImpl.java
+++ b/src/main/java/com/rymcu/vertical/service/impl/TagServiceImpl.java
@@ -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 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 implements TagService {
}
}
return 1;
+ } else {
+ if (StringUtils.isNotBlank(articleContentHtml)) {
+ List 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;
}